@blockcerts/blockcerts-verifier 1.52.0 → 1.52.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ie11.js +2 -2
- package/dist/main.js +2 -2
- package/package.json +3 -3
package/dist/main.js
CHANGED
|
@@ -117,7 +117,7 @@ const ae=(e,t)=>`${e}--${t}`,se=["html","svg"];function le(e){se.forEach((t=>{co
|
|
|
117
117
|
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
118
118
|
Code distributed by Google as part of the polymer project is also
|
|
119
119
|
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
120
|
-
*/const me=e=>t=>class extends t{connectedCallback(){super.connectedCallback&&super.connectedCallback(),this._storeUnsubscribe=e.subscribe((()=>this.stateChanged(e.getState()))),this.stateChanged(e.getState())}disconnectedCallback(){this._storeUnsubscribe(),super.disconnectedCallback&&super.disconnectedCallback()}stateChanged(e){}};function ve(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ie(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function we(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ie(Object(n),!0).forEach((function(t){ve(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function be(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}var Be="function"==typeof Symbol&&Symbol.observable||"@@observable",Ee=function(){return Math.random().toString(36).substring(7).split("").join(".")},Ce={INIT:"@@redux/INIT"+Ee(),REPLACE:"@@redux/REPLACE"+Ee(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Ee()}};function Se(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function xe(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(be(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(be(1));return n(xe)(e,t)}if("function"!=typeof e)throw new Error(be(2));var i=e,o=t,a=[],s=a,l=!1;function u(){s===a&&(s=a.slice())}function A(){if(l)throw new Error(be(3));return o}function c(e){if("function"!=typeof e)throw new Error(be(4));if(l)throw new Error(be(5));var t=!0;return u(),s.push(e),function(){if(t){if(l)throw new Error(be(6));t=!1,u();var n=s.indexOf(e);s.splice(n,1),a=null}}}function h(e){if(!Se(e))throw new Error(be(7));if(void 0===e.type)throw new Error(be(8));if(l)throw new Error(be(9));try{l=!0,o=i(o,e)}finally{l=!1}for(var t=a=s,n=0;n<t.length;n++){(0,t[n])()}return e}function f(e){if("function"!=typeof e)throw new Error(be(10));i=e,h({type:Ce.REPLACE})}function d(){var e,t=c;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(be(11));function n(){e.next&&e.next(A())}return n(),{unsubscribe:t(n)}}})[Be]=function(){return this},e}return h({type:Ce.INIT}),(r={dispatch:h,subscribe:c,getState:A,replaceReducer:f})[Be]=d,r}function Qe(e,t){return function(){return t(e.apply(this,arguments))}}function ke(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function _e(e){return function(t){var n=t.dispatch,r=t.getState;return function(t){return function(i){return"function"==typeof i?i(n,r,e):t(i)}}}}var Ne=_e();function De(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}function Fe(e,t){Object.defineProperty(this,"kind",{value:e,enumerable:!0}),t&&t.length&&Object.defineProperty(this,"path",{value:t,enumerable:!0})}Ne.withExtraArgument=_e,De((function e(t,n,r){e.super_.call(this,"E",t),Object.defineProperty(this,"lhs",{value:n,enumerable:!0}),Object.defineProperty(this,"rhs",{value:r,enumerable:!0})}),Fe),De((function e(t,n){e.super_.call(this,"N",t),Object.defineProperty(this,"rhs",{value:n,enumerable:!0})}),Fe),De((function e(t,n){e.super_.call(this,"D",t),Object.defineProperty(this,"lhs",{value:n,enumerable:!0})}),Fe),De((function e(t,n,r){e.super_.call(this,"A",t),Object.defineProperty(this,"index",{value:n,enumerable:!0}),Object.defineProperty(this,"item",{value:r,enumerable:!0})}),Fe);const Pe="AUTO_VERIFY",Ue="INITIALIZE",Me="UPDATE_CERTIFICATE_DEFINITION",Le="RESET_CERTIFICATE_DEFINITION",Te="UPDATE_CERTIFICATE_URL",Re="VALIDATE_URL_INPUT",Oe="CLEAR_VERIFIED_STEPS",He="STEP_VERIFIED",Ke="UPDATE_PARENT_STEP_STATUS",je="UPDATE_VERIFICATION_STATUS",Ge="UPDATE_FINAL_STEP",qe="SET_ERROR_MESSAGE",Ve="SHOW_VERIFICATION_MODAL",ze="UPDATE_IS_GENERATING_PDF";const Je={get:(e,t)=>{const n=t in e?e[t]:null;return n||console.warn("the service does not exist",t),n}};var Ye;!function(e){e.TEXT_HTML="text/html",e.IMAGE_PNG="image/png",e.IMAGE_JPEG="image/jpeg",e.IMAGE_GIF="image/gif",e.IMAGE_BMP="image/bmp",e.APPLICATION_PDF="application/pdf"}(Ye||(Ye={}));const Xe=["text","image","signature","variable"];function We(e){const t=(new DOMParser).parseFromString(e,Ye.TEXT_HTML);return t.body.childElementCount===t.body.querySelectorAll(Xe.map((e=>`section[class*="${e}"]`)).join(", ")).length}const Ze="?format=json";var $e=function(e,t){return $e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},$e(e,t)};function et(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}$e(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var tt=function(){return tt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},tt.apply(this,arguments)};function nt(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))}function rt(e){const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}}var it="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ot(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var at={exports:{}};!function(e){function t(n){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(at);var st=ot(at.exports),lt=Uint8Array,ut=Uint16Array,At=Uint32Array,ct=new lt([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ht=new lt([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ft=new lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),dt=function(e,t){for(var n=new ut(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new At(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return[n,i]},pt=dt(ct,2),gt=pt[0],yt=pt[1];gt[28]=258,yt[258]=28;for(var mt=dt(ht,0),vt=mt[0],It=mt[1],wt=new ut(32768),bt=0;bt<32768;++bt){var Bt=(43690&bt)>>>1|(21845&bt)<<1;Bt=(61680&(Bt=(52428&Bt)>>>2|(13107&Bt)<<2))>>>4|(3855&Bt)<<4,wt[bt]=((65280&Bt)>>>8|(255&Bt)<<8)>>>1}var Et=function(e,t,n){for(var r=e.length,i=0,o=new ut(t);i<r;++i)++o[e[i]-1];var a,s=new ut(t);for(i=0;i<t;++i)s[i]=s[i-1]+o[i-1]<<1;if(n){a=new ut(1<<t);var l=15-t;for(i=0;i<r;++i)if(e[i])for(var u=i<<4|e[i],A=t-e[i],c=s[e[i]-1]++<<A,h=c|(1<<A)-1;c<=h;++c)a[wt[c]>>>l]=u}else for(a=new ut(r),i=0;i<r;++i)a[i]=wt[s[e[i]-1]++]>>>15-e[i];return a},Ct=new lt(288);for(bt=0;bt<144;++bt)Ct[bt]=8;for(bt=144;bt<256;++bt)Ct[bt]=9;for(bt=256;bt<280;++bt)Ct[bt]=7;for(bt=280;bt<288;++bt)Ct[bt]=8;var St=new lt(32);for(bt=0;bt<32;++bt)St[bt]=5;var xt=Et(Ct,9,0),Qt=Et(Ct,9,1),kt=Et(St,5,0),_t=Et(St,5,1),Nt=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Dt=function(e,t,n){var r=t/8>>0;return(e[r]|e[r+1]<<8)>>>(7&t)&n},Ft=function(e,t){var n=t/8>>0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>>(7&t)},Pt=function(e){return(e/8>>0)+(7&e&&1)},Ut=function(e,t,n){(null==t||t<0)&&(t=0),(null==n||n>e.length)&&(n=e.length);var r=new(e instanceof ut?ut:e instanceof At?At:lt)(n-t);return r.set(e.subarray(t,n)),r},Mt=function(e,t,n){n<<=7&t;var r=t/8>>0;e[r]|=n,e[r+1]|=n>>>8},Lt=function(e,t,n){n<<=7&t;var r=t/8>>0;e[r]|=n,e[r+1]|=n>>>8,e[r+2]|=n>>>16},Tt=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,o=n.slice();if(!i)return[new lt(0),0];if(1==i){var a=new lt(n[0].s+1);return a[n[0].s]=1,[a,1]}n.sort((function(e,t){return e.f-t.f})),n.push({s:-1,f:25001});var s=n[0],l=n[1],u=0,A=1,c=2;for(n[0]={s:-1,f:s.f+l.f,l:s,r:l};A!=i-1;)s=n[n[u].f<n[c].f?u++:c++],l=n[u!=A&&n[u].f<n[c].f?u++:c++],n[A++]={s:-1,f:s.f+l.f,l:s,r:l};var h=o[0].s;for(r=1;r<i;++r)o[r].s>h&&(h=o[r].s);var f=new ut(h+1),d=Rt(n[A-1],f,0);if(d>t){r=0;var p=0,g=d-t,y=1<<g;for(o.sort((function(e,t){return f[t.s]-f[e.s]||e.f-t.f}));r<i;++r){var m=o[r].s;if(!(f[m]>t))break;p+=y-(1<<d-f[m]),f[m]=t}for(p>>>=g;p>0;){var v=o[r].s;f[v]<t?p-=1<<t-f[v]++-1:++r}for(;r>=0&&p;--r){var I=o[r].s;f[I]==t&&(--f[I],++p)}d=t}return[new lt(f),d]},Rt=function(e,t,n){return-1==e.s?Math.max(Rt(e.l,t,n+1),Rt(e.r,t,n+1)):t[e.s]=n},Ot=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new ut(++t),r=0,i=e[0],o=1,a=function(e){n[r++]=e},s=1;s<=t;++s)if(e[s]==i&&s!=t)++o;else{if(!i&&o>2){for(;o>138;o-=138)a(32754);o>2&&(a(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(a(i),--o;o>6;o-=6)a(8304);o>2&&(a(o-3<<5|8208),o=0)}for(;o--;)a(i);o=1,i=e[s]}return[n.subarray(0,r),t]},Ht=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},Kt=function(e,t,n){var r=n.length,i=Pt(t+2);e[i]=255&r,e[i+1]=r>>>8,e[i+2]=255^e[i],e[i+3]=255^e[i+1];for(var o=0;o<r;++o)e[i+o+4]=n[o];return 8*(i+4+r)},jt=function(e,t,n,r,i,o,a,s,l,u,A){Mt(t,A++,n),++i[256];for(var c=Tt(i,15),h=c[0],f=c[1],d=Tt(o,15),p=d[0],g=d[1],y=Ot(h),m=y[0],v=y[1],I=Ot(p),w=I[0],b=I[1],B=new ut(19),E=0;E<m.length;++E)B[31&m[E]]++;for(E=0;E<w.length;++E)B[31&w[E]]++;for(var C=Tt(B,7),S=C[0],x=C[1],Q=19;Q>4&&!S[ft[Q-1]];--Q);var k,_,N,D,F=u+5<<3,P=Ht(i,Ct)+Ht(o,St)+a,U=Ht(i,h)+Ht(o,p)+a+14+3*Q+Ht(B,S)+(2*B[16]+3*B[17]+7*B[18]);if(F<=P&&F<=U)return Kt(t,A,e.subarray(l,l+u));if(Mt(t,A,1+(U<P)),A+=2,U<P){k=Et(h,f,0),_=h,N=Et(p,g,0),D=p;var M=Et(S,x,0);Mt(t,A,v-257),Mt(t,A+5,b-1),Mt(t,A+10,Q-4),A+=14;for(E=0;E<Q;++E)Mt(t,A+3*E,S[ft[E]]);A+=3*Q;for(var L=[m,w],T=0;T<2;++T){var R=L[T];for(E=0;E<R.length;++E){var O=31&R[E];Mt(t,A,M[O]),A+=S[O],O>15&&(Mt(t,A,R[E]>>>5&127),A+=R[E]>>>12)}}}else k=xt,_=Ct,N=kt,D=St;for(E=0;E<s;++E)if(r[E]>255){O=r[E]>>>18&31;Lt(t,A,k[O+257]),A+=_[O+257],O>7&&(Mt(t,A,r[E]>>>23&31),A+=ct[O]);var H=31&r[E];Lt(t,A,N[H]),A+=D[H],H>3&&(Lt(t,A,r[E]>>>5&8191),A+=ht[H])}else Lt(t,A,k[r[E]]),A+=_[r[E]];return Lt(t,A,k[256]),A+_[256]},Gt=new At([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),qt=new lt(0),Vt=function(e,t,n,r,i){return function(e,t,n,r,i,o){var a=e.length,s=new lt(r+a+5*(1+Math.floor(a/7e3))+i),l=s.subarray(r,s.length-i),u=0;if(!t||a<8)for(var A=0;A<=a;A+=65535){var c=A+65535;c<a?u=Kt(l,u,e.subarray(A,c)):(l[A]=o,u=Kt(l,u,e.subarray(A,a)))}else{for(var h=Gt[t-1],f=h>>>13,d=8191&h,p=(1<<n)-1,g=new ut(32768),y=new ut(p+1),m=Math.ceil(n/3),v=2*m,I=function(t){return(e[t]^e[t+1]<<m^e[t+2]<<v)&p},w=new At(25e3),b=new ut(288),B=new ut(32),E=0,C=0,S=(A=0,0),x=0,Q=0;A<a;++A){var k=I(A),_=32767&A,N=y[k];if(g[_]=N,y[k]=_,x<=A){var D=a-A;if((E>7e3||S>24576)&&D>423){u=jt(e,l,0,w,b,B,C,S,Q,A-Q,u),S=E=C=0,Q=A;for(var F=0;F<286;++F)b[F]=0;for(F=0;F<30;++F)B[F]=0}var P=2,U=0,M=d,L=_-N&32767;if(D>2&&k==I(A-L))for(var T=Math.min(f,D)-1,R=Math.min(32767,A),O=Math.min(258,D);L<=R&&--M&&_!=N;){if(e[A+P]==e[A+P-L]){for(var H=0;H<O&&e[A+H]==e[A+H-L];++H);if(H>P){if(P=H,U=L,H>T)break;var K=Math.min(L,H-2),j=0;for(F=0;F<K;++F){var G=A-L+F+32768&32767,q=G-g[G]+32768&32767;q>j&&(j=q,N=G)}}}L+=(_=N)-(N=g[_])+32768&32767}if(U){w[S++]=268435456|yt[P]<<18|It[U];var V=31&yt[P],z=31&It[U];C+=ct[V]+ht[z],++b[257+V],++B[z],x=A+P,++E}else w[S++]=e[A],++b[e[A]]}}u=jt(e,l,o,w,b,B,C,S,Q,A-Q,u),o||(u=Kt(l,u,qt))}return Ut(s,0,r+Pt(u)+i)}(e,null==t.level?6:t.level,null==t.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+t.mem,n,r,!i)};function zt(e,t){void 0===t&&(t={});var n=function(){var e=1,t=0;return{p:function(n){for(var r=e,i=t,o=n.length,a=0;a!=o;){for(var s=Math.min(a+5552,o);a<s;++a)i+=r+=n[a];r%=65521,i%=65521}e=r,t=i},d:function(){return(e>>>8<<16|(255&t)<<8|t>>>8)+2*((255&e)<<23)}}}();n.p(e);var r=Vt(e,t,2,4);return function(e,t){var n=t.level,r=0==n?0:n<6?1:9==n?3:2;e[0]=120,e[1]=r<<6|(r?32-2*r:1)}(r,t),function(e,t,n){for(;n;++t)e[t]=n,n>>>=8}(r,r.length-4,n.d()),r}function Jt(e,t){return function(e,t,n){var r=e.length,i=!t||n,o=!n||n.i;n||(n={}),t||(t=new lt(3*r));var a=function(e){var n=t.length;if(e>n){var r=new lt(Math.max(2*n,e));r.set(t),t=r}},s=n.f||0,l=n.p||0,u=n.b||0,A=n.l,c=n.d,h=n.m,f=n.n,d=8*r;do{if(!A){n.f=s=Dt(e,l,1);var p=Dt(e,l+1,3);if(l+=3,!p){var g=e[(x=Pt(l)+4)-4]|e[x-3]<<8,y=x+g;if(y>r){if(o)throw"unexpected EOF";break}i&&a(u+g),t.set(e.subarray(x,y),u),n.b=u+=g,n.p=l=8*y;continue}if(1==p)A=Qt,c=_t,h=9,f=5;else{if(2!=p)throw"invalid block type";var m=Dt(e,l,31)+257,v=Dt(e,l+10,15)+4,I=m+Dt(e,l+5,31)+1;l+=14;for(var w=new lt(I),b=new lt(19),B=0;B<v;++B)b[ft[B]]=Dt(e,l+3*B,7);l+=3*v;var E=Nt(b),C=(1<<E)-1;if(!o&&l+I*(E+7)>d)break;var S=Et(b,E,1);for(B=0;B<I;){var x,Q=S[Dt(e,l,C)];if(l+=15&Q,(x=Q>>>4)<16)w[B++]=x;else{var k=0,_=0;for(16==x?(_=3+Dt(e,l,3),l+=2,k=w[B-1]):17==x?(_=3+Dt(e,l,7),l+=3):18==x&&(_=11+Dt(e,l,127),l+=7);_--;)w[B++]=k}}var N=w.subarray(0,m),D=w.subarray(m);h=Nt(N),f=Nt(D),A=Et(N,h,1),c=Et(D,f,1)}if(l>d)throw"unexpected EOF"}i&&a(u+131072);for(var F=(1<<h)-1,P=(1<<f)-1,U=h+f+18;o||l+U<d;){var M=(k=A[Ft(e,l)&F])>>>4;if((l+=15&k)>d)throw"unexpected EOF";if(!k)throw"invalid length/literal";if(M<256)t[u++]=M;else{if(256==M){A=null;break}var L=M-254;if(M>264){var T=ct[B=M-257];L=Dt(e,l,(1<<T)-1)+gt[B],l+=T}var R=c[Ft(e,l)&P],O=R>>>4;if(!R)throw"invalid distance";if(l+=15&R,D=vt[O],O>3&&(T=ht[O],D+=Ft(e,l)&(1<<T)-1,l+=T),l>d)throw"unexpected EOF";i&&a(u+131072);for(var H=u+L;u<H;u+=4)t[u]=t[u-D],t[u+1]=t[u+1-D],t[u+2]=t[u+2-D],t[u+3]=t[u+3-D];u=H}}n.l=A,n.p=l,n.b=u,A&&(s=1,n.m=h,n.d=c,n.n=f)}while(!s);return u==t.length?t:Ut(t,0,u)}((function(e){if(8!=(15&e[0])||e[0]>>>4>7||(e[0]<<8|e[1])%31)throw"invalid zlib data";if(32&e[1])throw"invalid zlib data: preset dictionaries not supported"}(e),e.subarray(2,-4)),t)}
|
|
120
|
+
*/const me=e=>t=>class extends t{connectedCallback(){this.__storeUnsubscribe=e.subscribe((()=>this._stateChanged(e.getState()))),this._stateChanged(e.getState()),super.connectedCallback&&super.connectedCallback()}disconnectedCallback(){this.__storeUnsubscribe(),super.disconnectedCallback&&super.disconnectedCallback()}_stateChanged(e){throw new Error("_stateChanged() not implemented")}};function ve(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ie(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function we(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ie(Object(n),!0).forEach((function(t){ve(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function be(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}var Be="function"==typeof Symbol&&Symbol.observable||"@@observable",Ee=function(){return Math.random().toString(36).substring(7).split("").join(".")},Ce={INIT:"@@redux/INIT"+Ee(),REPLACE:"@@redux/REPLACE"+Ee(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Ee()}};function Se(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function xe(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(be(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(be(1));return n(xe)(e,t)}if("function"!=typeof e)throw new Error(be(2));var i=e,o=t,a=[],s=a,l=!1;function u(){s===a&&(s=a.slice())}function A(){if(l)throw new Error(be(3));return o}function c(e){if("function"!=typeof e)throw new Error(be(4));if(l)throw new Error(be(5));var t=!0;return u(),s.push(e),function(){if(t){if(l)throw new Error(be(6));t=!1,u();var n=s.indexOf(e);s.splice(n,1),a=null}}}function h(e){if(!Se(e))throw new Error(be(7));if(void 0===e.type)throw new Error(be(8));if(l)throw new Error(be(9));try{l=!0,o=i(o,e)}finally{l=!1}for(var t=a=s,n=0;n<t.length;n++){(0,t[n])()}return e}function f(e){if("function"!=typeof e)throw new Error(be(10));i=e,h({type:Ce.REPLACE})}function d(){var e,t=c;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(be(11));function n(){e.next&&e.next(A())}return n(),{unsubscribe:t(n)}}})[Be]=function(){return this},e}return h({type:Ce.INIT}),(r={dispatch:h,subscribe:c,getState:A,replaceReducer:f})[Be]=d,r}function Qe(e,t){return function(){return t(e.apply(this,arguments))}}function ke(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function _e(e){return function(t){var n=t.dispatch,r=t.getState;return function(t){return function(i){return"function"==typeof i?i(n,r,e):t(i)}}}}var Ne=_e();function De(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}function Fe(e,t){Object.defineProperty(this,"kind",{value:e,enumerable:!0}),t&&t.length&&Object.defineProperty(this,"path",{value:t,enumerable:!0})}Ne.withExtraArgument=_e,De((function e(t,n,r){e.super_.call(this,"E",t),Object.defineProperty(this,"lhs",{value:n,enumerable:!0}),Object.defineProperty(this,"rhs",{value:r,enumerable:!0})}),Fe),De((function e(t,n){e.super_.call(this,"N",t),Object.defineProperty(this,"rhs",{value:n,enumerable:!0})}),Fe),De((function e(t,n){e.super_.call(this,"D",t),Object.defineProperty(this,"lhs",{value:n,enumerable:!0})}),Fe),De((function e(t,n,r){e.super_.call(this,"A",t),Object.defineProperty(this,"index",{value:n,enumerable:!0}),Object.defineProperty(this,"item",{value:r,enumerable:!0})}),Fe);const Pe="AUTO_VERIFY",Ue="INITIALIZE",Me="UPDATE_CERTIFICATE_DEFINITION",Le="RESET_CERTIFICATE_DEFINITION",Te="UPDATE_CERTIFICATE_URL",Re="VALIDATE_URL_INPUT",Oe="CLEAR_VERIFIED_STEPS",He="STEP_VERIFIED",Ke="UPDATE_PARENT_STEP_STATUS",je="UPDATE_VERIFICATION_STATUS",Ge="UPDATE_FINAL_STEP",qe="SET_ERROR_MESSAGE",Ve="SHOW_VERIFICATION_MODAL",ze="UPDATE_IS_GENERATING_PDF";const Je={get:(e,t)=>{const n=t in e?e[t]:null;return n||console.warn("the service does not exist",t),n}};var Ye;!function(e){e.TEXT_HTML="text/html",e.IMAGE_PNG="image/png",e.IMAGE_JPEG="image/jpeg",e.IMAGE_GIF="image/gif",e.IMAGE_BMP="image/bmp",e.APPLICATION_PDF="application/pdf"}(Ye||(Ye={}));const Xe=["text","image","signature","variable"];function We(e){const t=(new DOMParser).parseFromString(e,Ye.TEXT_HTML);return t.body.childElementCount===t.body.querySelectorAll(Xe.map((e=>`section[class*="${e}"]`)).join(", ")).length}const Ze="?format=json";var $e=function(e,t){return $e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},$e(e,t)};function et(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}$e(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var tt=function(){return tt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},tt.apply(this,arguments)};function nt(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))}function rt(e){const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}}var it="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ot(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var at={exports:{}};!function(e){function t(n){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(at);var st=ot(at.exports),lt=Uint8Array,ut=Uint16Array,At=Uint32Array,ct=new lt([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ht=new lt([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ft=new lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),dt=function(e,t){for(var n=new ut(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new At(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return[n,i]},pt=dt(ct,2),gt=pt[0],yt=pt[1];gt[28]=258,yt[258]=28;for(var mt=dt(ht,0),vt=mt[0],It=mt[1],wt=new ut(32768),bt=0;bt<32768;++bt){var Bt=(43690&bt)>>>1|(21845&bt)<<1;Bt=(61680&(Bt=(52428&Bt)>>>2|(13107&Bt)<<2))>>>4|(3855&Bt)<<4,wt[bt]=((65280&Bt)>>>8|(255&Bt)<<8)>>>1}var Et=function(e,t,n){for(var r=e.length,i=0,o=new ut(t);i<r;++i)++o[e[i]-1];var a,s=new ut(t);for(i=0;i<t;++i)s[i]=s[i-1]+o[i-1]<<1;if(n){a=new ut(1<<t);var l=15-t;for(i=0;i<r;++i)if(e[i])for(var u=i<<4|e[i],A=t-e[i],c=s[e[i]-1]++<<A,h=c|(1<<A)-1;c<=h;++c)a[wt[c]>>>l]=u}else for(a=new ut(r),i=0;i<r;++i)a[i]=wt[s[e[i]-1]++]>>>15-e[i];return a},Ct=new lt(288);for(bt=0;bt<144;++bt)Ct[bt]=8;for(bt=144;bt<256;++bt)Ct[bt]=9;for(bt=256;bt<280;++bt)Ct[bt]=7;for(bt=280;bt<288;++bt)Ct[bt]=8;var St=new lt(32);for(bt=0;bt<32;++bt)St[bt]=5;var xt=Et(Ct,9,0),Qt=Et(Ct,9,1),kt=Et(St,5,0),_t=Et(St,5,1),Nt=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Dt=function(e,t,n){var r=t/8>>0;return(e[r]|e[r+1]<<8)>>>(7&t)&n},Ft=function(e,t){var n=t/8>>0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>>(7&t)},Pt=function(e){return(e/8>>0)+(7&e&&1)},Ut=function(e,t,n){(null==t||t<0)&&(t=0),(null==n||n>e.length)&&(n=e.length);var r=new(e instanceof ut?ut:e instanceof At?At:lt)(n-t);return r.set(e.subarray(t,n)),r},Mt=function(e,t,n){n<<=7&t;var r=t/8>>0;e[r]|=n,e[r+1]|=n>>>8},Lt=function(e,t,n){n<<=7&t;var r=t/8>>0;e[r]|=n,e[r+1]|=n>>>8,e[r+2]|=n>>>16},Tt=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,o=n.slice();if(!i)return[new lt(0),0];if(1==i){var a=new lt(n[0].s+1);return a[n[0].s]=1,[a,1]}n.sort((function(e,t){return e.f-t.f})),n.push({s:-1,f:25001});var s=n[0],l=n[1],u=0,A=1,c=2;for(n[0]={s:-1,f:s.f+l.f,l:s,r:l};A!=i-1;)s=n[n[u].f<n[c].f?u++:c++],l=n[u!=A&&n[u].f<n[c].f?u++:c++],n[A++]={s:-1,f:s.f+l.f,l:s,r:l};var h=o[0].s;for(r=1;r<i;++r)o[r].s>h&&(h=o[r].s);var f=new ut(h+1),d=Rt(n[A-1],f,0);if(d>t){r=0;var p=0,g=d-t,y=1<<g;for(o.sort((function(e,t){return f[t.s]-f[e.s]||e.f-t.f}));r<i;++r){var m=o[r].s;if(!(f[m]>t))break;p+=y-(1<<d-f[m]),f[m]=t}for(p>>>=g;p>0;){var v=o[r].s;f[v]<t?p-=1<<t-f[v]++-1:++r}for(;r>=0&&p;--r){var I=o[r].s;f[I]==t&&(--f[I],++p)}d=t}return[new lt(f),d]},Rt=function(e,t,n){return-1==e.s?Math.max(Rt(e.l,t,n+1),Rt(e.r,t,n+1)):t[e.s]=n},Ot=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new ut(++t),r=0,i=e[0],o=1,a=function(e){n[r++]=e},s=1;s<=t;++s)if(e[s]==i&&s!=t)++o;else{if(!i&&o>2){for(;o>138;o-=138)a(32754);o>2&&(a(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(a(i),--o;o>6;o-=6)a(8304);o>2&&(a(o-3<<5|8208),o=0)}for(;o--;)a(i);o=1,i=e[s]}return[n.subarray(0,r),t]},Ht=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},Kt=function(e,t,n){var r=n.length,i=Pt(t+2);e[i]=255&r,e[i+1]=r>>>8,e[i+2]=255^e[i],e[i+3]=255^e[i+1];for(var o=0;o<r;++o)e[i+o+4]=n[o];return 8*(i+4+r)},jt=function(e,t,n,r,i,o,a,s,l,u,A){Mt(t,A++,n),++i[256];for(var c=Tt(i,15),h=c[0],f=c[1],d=Tt(o,15),p=d[0],g=d[1],y=Ot(h),m=y[0],v=y[1],I=Ot(p),w=I[0],b=I[1],B=new ut(19),E=0;E<m.length;++E)B[31&m[E]]++;for(E=0;E<w.length;++E)B[31&w[E]]++;for(var C=Tt(B,7),S=C[0],x=C[1],Q=19;Q>4&&!S[ft[Q-1]];--Q);var k,_,N,D,F=u+5<<3,P=Ht(i,Ct)+Ht(o,St)+a,U=Ht(i,h)+Ht(o,p)+a+14+3*Q+Ht(B,S)+(2*B[16]+3*B[17]+7*B[18]);if(F<=P&&F<=U)return Kt(t,A,e.subarray(l,l+u));if(Mt(t,A,1+(U<P)),A+=2,U<P){k=Et(h,f,0),_=h,N=Et(p,g,0),D=p;var M=Et(S,x,0);Mt(t,A,v-257),Mt(t,A+5,b-1),Mt(t,A+10,Q-4),A+=14;for(E=0;E<Q;++E)Mt(t,A+3*E,S[ft[E]]);A+=3*Q;for(var L=[m,w],T=0;T<2;++T){var R=L[T];for(E=0;E<R.length;++E){var O=31&R[E];Mt(t,A,M[O]),A+=S[O],O>15&&(Mt(t,A,R[E]>>>5&127),A+=R[E]>>>12)}}}else k=xt,_=Ct,N=kt,D=St;for(E=0;E<s;++E)if(r[E]>255){O=r[E]>>>18&31;Lt(t,A,k[O+257]),A+=_[O+257],O>7&&(Mt(t,A,r[E]>>>23&31),A+=ct[O]);var H=31&r[E];Lt(t,A,N[H]),A+=D[H],H>3&&(Lt(t,A,r[E]>>>5&8191),A+=ht[H])}else Lt(t,A,k[r[E]]),A+=_[r[E]];return Lt(t,A,k[256]),A+_[256]},Gt=new At([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),qt=new lt(0),Vt=function(e,t,n,r,i){return function(e,t,n,r,i,o){var a=e.length,s=new lt(r+a+5*(1+Math.floor(a/7e3))+i),l=s.subarray(r,s.length-i),u=0;if(!t||a<8)for(var A=0;A<=a;A+=65535){var c=A+65535;c<a?u=Kt(l,u,e.subarray(A,c)):(l[A]=o,u=Kt(l,u,e.subarray(A,a)))}else{for(var h=Gt[t-1],f=h>>>13,d=8191&h,p=(1<<n)-1,g=new ut(32768),y=new ut(p+1),m=Math.ceil(n/3),v=2*m,I=function(t){return(e[t]^e[t+1]<<m^e[t+2]<<v)&p},w=new At(25e3),b=new ut(288),B=new ut(32),E=0,C=0,S=(A=0,0),x=0,Q=0;A<a;++A){var k=I(A),_=32767&A,N=y[k];if(g[_]=N,y[k]=_,x<=A){var D=a-A;if((E>7e3||S>24576)&&D>423){u=jt(e,l,0,w,b,B,C,S,Q,A-Q,u),S=E=C=0,Q=A;for(var F=0;F<286;++F)b[F]=0;for(F=0;F<30;++F)B[F]=0}var P=2,U=0,M=d,L=_-N&32767;if(D>2&&k==I(A-L))for(var T=Math.min(f,D)-1,R=Math.min(32767,A),O=Math.min(258,D);L<=R&&--M&&_!=N;){if(e[A+P]==e[A+P-L]){for(var H=0;H<O&&e[A+H]==e[A+H-L];++H);if(H>P){if(P=H,U=L,H>T)break;var K=Math.min(L,H-2),j=0;for(F=0;F<K;++F){var G=A-L+F+32768&32767,q=G-g[G]+32768&32767;q>j&&(j=q,N=G)}}}L+=(_=N)-(N=g[_])+32768&32767}if(U){w[S++]=268435456|yt[P]<<18|It[U];var V=31&yt[P],z=31&It[U];C+=ct[V]+ht[z],++b[257+V],++B[z],x=A+P,++E}else w[S++]=e[A],++b[e[A]]}}u=jt(e,l,o,w,b,B,C,S,Q,A-Q,u),o||(u=Kt(l,u,qt))}return Ut(s,0,r+Pt(u)+i)}(e,null==t.level?6:t.level,null==t.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+t.mem,n,r,!i)};function zt(e,t){void 0===t&&(t={});var n=function(){var e=1,t=0;return{p:function(n){for(var r=e,i=t,o=n.length,a=0;a!=o;){for(var s=Math.min(a+5552,o);a<s;++a)i+=r+=n[a];r%=65521,i%=65521}e=r,t=i},d:function(){return(e>>>8<<16|(255&t)<<8|t>>>8)+2*((255&e)<<23)}}}();n.p(e);var r=Vt(e,t,2,4);return function(e,t){var n=t.level,r=0==n?0:n<6?1:9==n?3:2;e[0]=120,e[1]=r<<6|(r?32-2*r:1)}(r,t),function(e,t,n){for(;n;++t)e[t]=n,n>>>=8}(r,r.length-4,n.d()),r}function Jt(e,t){return function(e,t,n){var r=e.length,i=!t||n,o=!n||n.i;n||(n={}),t||(t=new lt(3*r));var a=function(e){var n=t.length;if(e>n){var r=new lt(Math.max(2*n,e));r.set(t),t=r}},s=n.f||0,l=n.p||0,u=n.b||0,A=n.l,c=n.d,h=n.m,f=n.n,d=8*r;do{if(!A){n.f=s=Dt(e,l,1);var p=Dt(e,l+1,3);if(l+=3,!p){var g=e[(x=Pt(l)+4)-4]|e[x-3]<<8,y=x+g;if(y>r){if(o)throw"unexpected EOF";break}i&&a(u+g),t.set(e.subarray(x,y),u),n.b=u+=g,n.p=l=8*y;continue}if(1==p)A=Qt,c=_t,h=9,f=5;else{if(2!=p)throw"invalid block type";var m=Dt(e,l,31)+257,v=Dt(e,l+10,15)+4,I=m+Dt(e,l+5,31)+1;l+=14;for(var w=new lt(I),b=new lt(19),B=0;B<v;++B)b[ft[B]]=Dt(e,l+3*B,7);l+=3*v;var E=Nt(b),C=(1<<E)-1;if(!o&&l+I*(E+7)>d)break;var S=Et(b,E,1);for(B=0;B<I;){var x,Q=S[Dt(e,l,C)];if(l+=15&Q,(x=Q>>>4)<16)w[B++]=x;else{var k=0,_=0;for(16==x?(_=3+Dt(e,l,3),l+=2,k=w[B-1]):17==x?(_=3+Dt(e,l,7),l+=3):18==x&&(_=11+Dt(e,l,127),l+=7);_--;)w[B++]=k}}var N=w.subarray(0,m),D=w.subarray(m);h=Nt(N),f=Nt(D),A=Et(N,h,1),c=Et(D,f,1)}if(l>d)throw"unexpected EOF"}i&&a(u+131072);for(var F=(1<<h)-1,P=(1<<f)-1,U=h+f+18;o||l+U<d;){var M=(k=A[Ft(e,l)&F])>>>4;if((l+=15&k)>d)throw"unexpected EOF";if(!k)throw"invalid length/literal";if(M<256)t[u++]=M;else{if(256==M){A=null;break}var L=M-254;if(M>264){var T=ct[B=M-257];L=Dt(e,l,(1<<T)-1)+gt[B],l+=T}var R=c[Ft(e,l)&P],O=R>>>4;if(!R)throw"invalid distance";if(l+=15&R,D=vt[O],O>3&&(T=ht[O],D+=Ft(e,l)&(1<<T)-1,l+=T),l>d)throw"unexpected EOF";i&&a(u+131072);for(var H=u+L;u<H;u+=4)t[u]=t[u-D],t[u+1]=t[u+1-D],t[u+2]=t[u+2-D],t[u+3]=t[u+3-D];u=H}}n.l=A,n.p=l,n.b=u,A&&(s=1,n.m=h,n.d=c,n.n=f)}while(!s);return u==t.length?t:Ut(t,0,u)}((function(e){if(8!=(15&e[0])||e[0]>>>4>7||(e[0]<<8|e[1])%31)throw"invalid zlib data";if(32&e[1])throw"invalid zlib data: preset dictionaries not supported"}(e),e.subarray(2,-4)),t)}
|
|
121
121
|
/** @license
|
|
122
122
|
*
|
|
123
123
|
* jsPDF - PDF Document creation from JavaScript
|
|
@@ -634,7 +634,7 @@ var LN=class{constructor({term:e,date:t,maxTimestampDelta:n=1/0}={}){if(void 0==
|
|
|
634
634
|
/*!
|
|
635
635
|
* Copyright (c) 2010-2018 Digital Bazaar, Inc. All rights reserved.
|
|
636
636
|
*/
|
|
637
|
-
const zN={};var JN=zN;const YN=oN;Object.assign(zN,YN);const XN=class{async add(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}={}){if(!t)throw new TypeError('"options.suite" is required.');if(!n)throw new TypeError('"options.purpose" is required.');r=r?mN(r):vN,void 0===i?i=wN:!1===i&&(i=void 0);const o={...e};delete o.proof;const a=await t.createProof({document:o,purpose:n,documentLoader:r,expansionMap:i});return yN.addValue(e,"proof",a),e}async verify(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}={}){if(!t)throw new TypeError('"options.suite" is required.');if(!n)throw new TypeError('"options.purpose" is required.');const o=Array.isArray(t)?t:[t];if(0===o.length)throw new TypeError("At least one suite is required.");r=r?mN(r):vN,void 0===i?i=wN:!1===i&&(i=void 0);try{e={...e};const{proofSet:t,document:a}=await async function({document:e}){let t;if(t=yN.getValues(e,"proof"),delete e.proof,0===t.length)throw new Error("No matching proofs found in the given document.");const n=e["@context"]||gN.SECURITY_CONTEXT_URL;return t=t.map((e=>({"@context":n,...e}))),{proofSet:t,document:e}}({document:e,documentLoader:r,expansionMap:i});e=a;const s=await async function({document:e,suites:t,proofSet:n,purpose:r,documentLoader:i,expansionMap:o}){const a=Array.isArray(r)?r:[r],s=new Map,l=new Map,u=new Map;if(await Promise.all(a.map((r=>async function({purposeToProofs:e,proofToSuite:t,purpose:n,proofSet:r,suites:i,suiteMatchQueue:o,document:a,documentLoader:s,expansionMap:l}){for(const u of r){if(!await n.match(u,{document:a,documentLoader:s,expansionMap:l}))continue;let r=!1;for(const e of i){let n=o.get(e);n||o.set(e,n=new Map);let i=n.get(u);if(i||(i=e.matchProof({proof:u,document:a,documentLoader:s,expansionMap:l}),n.set(u,i)),await i){r=!0,t.set(u,e);break}}if(r){const t=e.get(n);t?t.push(u):e.set(n,[u])}}}({purposeToProofs:s,proofToSuite:l,purpose:r,proofSet:n,suites:t,suiteMatchQueue:u,document:e,documentLoader:i,expansionMap:o})))),s.size<a.length)return[];const A=new Map;return await Promise.all([...l.entries()].map((async([t,n])=>{let r;try{let a;const s={validate:async(e,{verificationMethod:t})=>(a=t,{valid:!0})},{verified:l,verificationMethod:u,error:A}=await n.verifyProof({proof:t,document:e,purpose:s,documentLoader:i,expansionMap:o});a||(a=u),r={proof:t,verified:l,verificationMethod:a,error:A}}catch(e){r={proof:t,verified:!1,error:e}}r.error&&bN(r.error),A.set(t,r)}))),await Promise.all([...s.entries()].map((async([t,n])=>{for(const r of n){const n=A.get(r);if(!n.verified)continue;const{verificationMethod:a}=n,s=l.get(r);let u;try{u=await t.validate(r,{document:e,suite:s,verificationMethod:a,documentLoader:i,expansionMap:o})}catch(e){u={valid:!1,error:e}}n.purposeResult?Array.isArray(n.purposeResult)?n.purposeResult.push(u):n.purposeResult=[n.purposeResult,u]:n.purposeResult=u,u.valid||(bN(u.error),n.error||(n.verified=!1,n.error=u.error))}}))),[...A.values()]}({document:e,suites:o,proofSet:t,purpose:n,documentLoader:r,expansionMap:i});if(0===s.length){const e=new Error("Did not verify any proofs; insufficient proofs matched the acceptable suite(s) and required purpose(s).");throw e.name="NotFoundError",e}const l=s.some((e=>e.verified));if(!l){const e=[].concat(...s.filter((e=>e.error)).map((e=>e.error))),t={verified:l,results:s};return e.length>0&&(t.error=e),t}return{verified:l,results:s}}catch(e){return bN(e),{verified:!1,error:e}}}},WN=EN;function ZN(e){const t=Object.keys(jl).map((e=>jl[e])).find((t=>t.signatureValue===e));return t}function $N(e,t){const n=e.findIndex((e=>e===t));n>-1&&e.splice(n,1)}zN.sign=async function(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i,addSuiteContext:o=!0}={}){if("object"!=typeof e)throw new TypeError('The "document" parameter must be an object.');t.ensureSuiteContext({document:e,addSuiteContext:o});try{return await(new XN).add(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i})}catch(e){if(!r&&"jsonld.InvalidUrl"===e.name){const{details:{url:t}}=e,n=new Error(`A URL "${t}" could not be fetched; you need to pass "documentLoader" or resolve the URL before calling "sign".`);throw n.cause=e,n}throw e}},zN.verify=async function(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}={}){if("object"!=typeof e)throw new TypeError('The "document" parameter must be an object.');const o=await(new XN).verify(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}),{error:a}=o;if(a)if(r||"jsonld.InvalidUrl"!==a.name)o.error=new WN(a);else{const{details:{url:e}}=a,t=new Error(`A URL "${e}" could not be fetched; you need to pass "documentLoader" or resolve the URL before calling "verify".`);o.error=new WN(t)}return o},zN.suites=MN.suites,zN.purposes=VN.purposes,Object.assign(zN,AN);var eD={"@context":{id:"@id",type:"@type",bc:"https://w3id.org/blockcerts#",obi:"https://w3id.org/openbadges#",cp:"https://w3id.org/chainpoint#",schema:"http://schema.org/",sec:"https://w3id.org/security#",xsd:"http://www.w3.org/2001/XMLSchema#",MerkleProof2017:"sec:MerkleProof2017",RecipientProfile:"bc:RecipientProfile",SignatureLine:"bc:SignatureLine",MerkleProofVerification2017:"bc:MerkleProofVerification2017",recipientProfile:"bc:recipientProfile",signatureLines:"bc:signatureLines",introductionUrl:{"@id":"bc:introductionUrl","@type":"@id"},subtitle:"bc:subtitle",jobTitle:"schema:jobTitle",creator:{"@id":"dc:creator","@type":"@id"},expires:{"@id":"sec:expiration","@type":"xsd:dateTime"},revoked:{"@id":"sec:expiration","@type":"xsd:dateTime"},CryptographicKey:"sec:Key",signature:"sec:signature",verification:"bc:verification",publicKeys:"bc:publicKeys",ChainpointSHA256v2:"cp:ChainpointSHA256v2",BTCOpReturn:"cp:BTCOpReturn",targetHash:"cp:targetHash",merkleRoot:"cp:merkleRoot",proof:"cp:proof",anchors:"cp:anchors",sourceId:"cp:sourceId",right:"cp:right",left:"cp:left"},"obi:validation":[{"obi:validatesType":"RecipientProfile","obi:validationSchema":"https://w3id.org/blockcerts/schema/2.0-alpha/recipientSchema.json"},{"obi:validatesType":"SignatureLine","obi:validationSchema":"https://w3id.org/blockcerts/schema/2.0-alpha/signatureLineSchema.json"},{"obi:validatesType":"MerkleProof2017","obi:validationSchema":"https://w3id.org/blockcerts/schema/2.0-alpha/merkleProof2017Schema.json"}]},tD={"@context":{id:"@id",type:"@type",bc:"https://w3id.org/blockcerts#",cp:"https://w3id.org/chainpoint#",schema:"http://schema.org/",sec:"https://w3id.org/security#",xsd:"http://www.w3.org/2001/XMLSchema#",MerkleProof2019:"sec:MerkleProof2019",BlockcertsCredential:"bc:BlockcertsCredential",introductionUrl:{"@id":"bc:introductionUrl","@type":"@id"},CryptographicKey:"sec:Key",domain:"sec:domain",nonce:"sec:nonce",proofValue:"sec:proofValue",assertionMethod:{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},proofPurpose:{"@id":"sec:proofPurpose","@type":"@vocab"},verificationMethod:{"@id":"sec:verificationMethod","@type":"@id"},created:{"@id":"bc:created","@type":"xsd:dateTime"},name:{"@id":"schema:name"}}},nD={"@context":{id:"@id",type:"@type",bc:"https://w3id.org/blockcerts#",cp:"https://w3id.org/chainpoint#",vc:"https://www.w3.org/2018/credentials/v1",schema:"https://schema.org/",sec:"https://w3id.org/security#",xsd:"http://www.w3.org/2001/XMLSchema#",MerkleProof2019:"sec:MerkleProof2019",BlockcertsCredential:"bc:BlockcertsCredential",introductionUrl:{"@id":"bc:introductionUrl","@type":"@id"},metadata:"bc:metadata",display:{"@id":"bc:display","@context":{id:"@id",type:"@type",contentMediaType:{"@id":"bc:contentMediaType","@type":"@id"},contentEncoding:{"@id":"bc:contentEncoding","@type":"@id"},content:{"@id":"bc:content","@type":"@id"}}},CryptographicKey:"sec:Key",domain:"sec:domain",nonce:"sec:nonce",proofValue:"sec:proofValue",assertionMethod:{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"},proofPurpose:{"@id":"sec:proofPurpose","@type":"@vocab"},verificationMethod:{"@id":"sec:verificationMethod","@type":"@id"},created:{"@id":"https://purl.org/dc/terms/created","@type":"xsd:dateTime"},challenge:"sec:challenge",expires:{"@id":"sec:expiration","@type":"xsd:dateTime"},name:{"@id":"schema:name"},description:{"@id":"schema:description"},email:{"@id":"schema:email"},publicKey:{"@id":"sec:publicKey","@type":"@id"},url:{"@id":"schema:url","@type":"@id"},image:{"@id":"schema:image","@type":"@id"}}};function rD(e){e=e.trim();const t=[];for(let n=0;n<e.length;n+=2)t.push(parseInt(e.substring(n,n+2),16));return t}jh["https://w3id.org/blockcerts/schema/2.0-alpha/context.json"]=eD,jh["https://www.blockcerts.org/schema/2.0-alpha/context.json"]=eD,jh["https://www.blockcerts.org/schema/3.0-alpha/context.json"]=tD,jh["https://w3id.org/blockcerts/schema/3.0-alpha/context.json"]=tD,jh["https://w3id.org/blockcerts/v3.0-alpha"]=tD,jh["https://www.blockcerts.org/schema/3.0-beta/context.json"]=nD,jh["https://w3id.org/blockcerts/schema/3.0-beta/context.json"]=nD,jh["https://w3id.org/blockcerts/v3.0-beta"]=nD,jh["https://w3id.org/security/suites/ed25519-2020/v1"]={"@context":{id:"@id",type:"@type","@protected":!0,proof:{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"},Ed25519VerificationKey2020:{"@id":"https://w3id.org/security#Ed25519VerificationKey2020","@context":{"@protected":!0,id:"@id",type:"@type",controller:{"@id":"https://w3id.org/security#controller","@type":"@id"},revoked:{"@id":"https://w3id.org/security#revoked","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},publicKeyMultibase:{"@id":"https://w3id.org/security#publicKeyMultibase","@type":"https://w3id.org/security#multibase"}}},Ed25519Signature2020:{"@id":"https://w3id.org/security#Ed25519Signature2020","@context":{"@protected":!0,id:"@id",type:"@type",challenge:"https://w3id.org/security#challenge",created:{"@id":"http://purl.org/dc/terms/created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},domain:"https://w3id.org/security#domain",expires:{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},nonce:"https://w3id.org/security#nonce",proofPurpose:{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":!0,id:"@id",type:"@type",assertionMethod:{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},capabilityInvocation:{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},capabilityDelegation:{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},keyAgreement:{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},proofValue:{"@id":"https://w3id.org/security#proofValue","@type":"https://w3id.org/security#multibase"},verificationMethod:{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}}}};class iD extends Error{constructor(e,t){super(t),this.stepCode=e}}var oD="en-US",aD={"en-US":{errors:{ensureHashesEqual:"Computed hash does not match remote hash",ensureMerkleRootEqual:"Merkle root does not match remote hash.",ensureValidReceipt:"The receipt is malformed. There was a problem navigating the merkle tree in the receipt.",failedJsonLdNormalization:"Failed JSON-LD normalization",foundUnmappedFields:"Found unmapped fields during JSON-LD normalization",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"Cannot verify this certificate without a transaction ID to compare against.",invalidMerkleReceipt:"Invalid Merkle Receipt. Proof hash did not match Merkle root",isTransactionIdValid:"Cannot verify this certificate without a transaction ID to compare against.",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}},fr:{errors:{ensureHashesEqual:"Calcul du hash local différent du hash distant",ensureMerkleRootEqual:"Le Merkle root ne correspond pas au hash distant",ensureValidReceipt:"Erreur d'écriture du reçu. Un problème est survenu lors de la navigation de l'arbre Merkle du reçu.",failedJsonLdNormalization:"Erreur de normalisation JSON-LD",foundUnmappedFields:"Champs non liés découverts durant la normalisation JSON-LD",identityErrorBaseMessage:"Identité de l'émetteur invalide",deriveIssuingAddressFromPublicKey:"Cette blockchain n'est pas supportée pour la vérification de l'identité décentralisée.",compareIssuingAddress:"La méthode de vérification n'a pas permis d'établir l'identité de l'émetteur.",getTransactionId:"Impossible de vérifier ce certificat sans un identifiant de transaction valide",invalidMerkleReceipt:"Reçu Merkle invalide. Hash de preuve différent du Merkle root",isTransactionIdValid:"Impossible de vérifier ce certificat sans un identifiant de transaction valide",noProofSpecified:"La propriété 'proof' du document est un tableau mais aucune preuve n'a été passée pour savoir ce qu'il faut vérifier"}},es:{errors:{ensureHashesEqual:"La cadena binaria calculada no corresponde con la cadena binaria remota",ensureMerkleRootEqual:"La raíz Merkle no corresponde con la cadena binaria remota",ensureValidReceipt:"El recibo está malformado. Hubo un problema navegando el árbol Merkle en el recibo",failedJsonLdNormalization:"La normalización del JSON-LD ha fallado",foundUnmappedFields:"Se han encontrado campos no mapeados durante la normalización de JSON-LD",identityErrorBaseMessage:"Identitad del emisor inválida",deriveIssuingAddressFromPublicKey:"No se puede validar la identitad decentalisada con esta cadena binaria.",compareIssuingAddress:"El metodo de verificación no corresponde a la identitad del emisor.",getTransactionId:"No se puede verificar este certificado sin una identificación de transacción que sirva como comparación",invalidMerkleReceipt:"Recibo Merkle inválido. La cadena binaria de prueba no corresponde con la raíz Merkle",isTransactionIdValid:"No se puede verificar este certificado sin una identificación de transacción que sirva como comparación",noProofSpecified:"La propiedad 'proof' del documento es una lista, pero no prueba especifica ha sido declarada para conocer el punto de verificación"}},mt:{errors:{ensureHashesEqual:"Il-hash ikkalkulat ma jikkorrispondix mar-remote hash",ensureMerkleRootEqual:"Merkle root ma taqbilx mar-remote hash",ensureValidReceipt:"L-irċevuta hija malformata. Kien hemm problema fin-navigazzjoni tal-merkle tree fl-irċevuta",failedJsonLdNormalization:"In-normalizzazzjoni ta' JSON-LD ma rnexxietx",foundUnmappedFields:"Instabu unmapped fields matul in-normalizzazzjoni JSON-LD",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"Dan iċ-ċertifikat ma jistax jiġi vverifikat mingħajr ID ta' tranżazzjoni mqabbla miegħu",invalidMerkleReceipt:"Irċevuta Merkle invalida. Il-proof hash ma kienx jaqbel mal-Merkle root",isTransactionIdValid:"Dan iċ-ċertifikat ma jistax jiġi vverifikat mingħajr ID ta' tranżazzjoni mqabbla miegħu",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}},"it-IT":{errors:{ensureHashesEqual:"L'hash calcolato non corrisponde all'hash remoto",ensureMerkleRootEqual:"La radice di Merkle non corrisponde all'hash remoto.",ensureValidReceipt:"La ricevuta è malformata. C'è stato un problema nella navigazione dell'albero di Merkle nella ricevuta.",failedJsonLdNormalization:"Normalizzazione JSON-LD fallita",foundUnmappedFields:"Campi non mappati trovati durante la normalizzazione JSON-LD",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"Impossibile verificare questo certificato senza un ID transazione da confrontare.",invalidMerkleReceipt:"Ricevuta Merkle non valida. L'hash di prova non corrisponde alla radice di Merkle",isTransactionIdValid:"Impossibile verificare questo certificato senza un ID transazione da confrontare.",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}},ja:{errors:{ensureHashesEqual:"算出されたハッシュがリモートハッシュと一致しませんでした",ensureMerkleRootEqual:"Merkle rootがリモートハッシュと一致しませんでした",ensureValidReceipt:"レシートが異常です。レシート内のMerkle treeを辿る際に問題が発生しました。",failedJsonLdNormalization:"JSON-LDの正規化に失敗しました",foundUnmappedFields:"JSON-LDの正規化時にマップされていないフィールドを検出しました",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"照合のための取引IDがないため、この証明書を認証できません。",invalidMerkleReceipt:"Merkleレシートが無効です。証明ハッシュがMerkle rootと一致しませんでした。",isTransactionIdValid:"照合するための取引IDがないため、この証明書を認証できません。",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}}};function sD(e,t){return e&&t?aD[oD]?aD[oD][e]?aD[oD][e][t]?aD[oD][e][t]||"":"[missing locale item data]":"[missing locale group data]":"[missing locale data]":""}var lD=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){e.done?i(e.value):function(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(a,s)}l((r=r.apply(e,t||[])).next())}))};class uD extends Error{constructor(e){super(e||"This operation is not supported for this key type")}}var AD=uD;class cD extends Error{constructor(){super("This has not been implemented yet")}}var hD=cD;const fD=hD;var dD,pD=class{constructor(e){this.params=e}fromPrivatePKCS1(e){throw new fD}fromPrivatePKCS8(e){throw new fD}fromPublicPKCS1(e){throw new fD}fromPublicPKCS8(e){throw new fD}fromPrivateBlk(e){throw new fD}fromPublicBlk(e){throw new fD}fromJwk(e){throw new fD}toPrivatePKCS1(e){throw new fD}toPrivatePKCS8(e){throw new fD}toPublicPKCS1(e){throw new fD}toPublicPKCS8(e){throw new fD}toPrivateBlk(e){throw new fD}toPublicBlk(e){throw new fD}toPrivateJwk(e){throw new fD}toPublicJwk(e){throw new fD}static formatPem(e,t){return`-----BEGIN ${t} KEY-----\n`+e.match(/.{1,64}/g).join("\n")+`\n-----END ${t} KEY-----`}},gD={},yD={},mD={},vD=qo,ID=vD.Buffer,wD={};for(dD in vD)vD.hasOwnProperty(dD)&&"SlowBuffer"!==dD&&"Buffer"!==dD&&(wD[dD]=vD[dD]);var bD=wD.Buffer={};for(dD in ID)ID.hasOwnProperty(dD)&&"allocUnsafe"!==dD&&"allocUnsafeSlow"!==dD&&(bD[dD]=ID[dD]);if(wD.Buffer.prototype=ID.prototype,bD.from&&bD.from!==Uint8Array.from||(bD.from=function(e,t,n){if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type '+typeof e);if(e&&void 0===e.length)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);return ID(e,t,n)}),bD.alloc||(bD.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError('The "size" argument must be of type number. Received type '+typeof e);if(e<0||e>=2*(1<<30))throw new RangeError('The value "'+e+'" is invalid for option "size"');var r=ID(e);return t&&0!==t.length?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r}),!wD.kStringMaxLength)try{wD.kStringMaxLength=gu.binding("buffer").kStringMaxLength}catch(e){}wD.constants||(wD.constants={MAX_LENGTH:wD.kMaxLength},wD.kStringMaxLength&&(wD.constants.MAX_STRING_LENGTH=wD.kStringMaxLength));var BD=wD,ED={};const CD=Ow.exports;function SD(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function xD(e,t){this.path=e,this.rethrow(t)}ED.Reporter=SD,SD.prototype.isError=function(e){return e instanceof xD},SD.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},SD.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},SD.prototype.enterKey=function(e){return this._reporterState.path.push(e)},SD.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},SD.prototype.leaveKey=function(e,t,n){const r=this._reporterState;this.exitKey(e),null!==r.obj&&(r.obj[t]=n)},SD.prototype.path=function(){return this._reporterState.path.join("/")},SD.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},SD.prototype.leaveObject=function(e){const t=this._reporterState,n=t.obj;return t.obj=e,n},SD.prototype.error=function(e){let t;const n=this._reporterState,r=e instanceof xD;if(t=r?e:new xD(n.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!n.options.partial)throw t;return r||n.errors.push(t),t},SD.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},CD(xD,Error),xD.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,xD),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this};var QD={};const kD=Ow.exports,_D=ED.Reporter,ND=BD.Buffer;function DD(e,t){_D.call(this,t),ND.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function FD(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return FD.isEncoderBuffer(e)||(e=new FD(e,t)),this.length+=e.length,e}),this);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");this.value=e,this.length=1}else if("string"==typeof e)this.value=e,this.length=ND.byteLength(e);else{if(!ND.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}kD(DD,_D),QD.DecoderBuffer=DD,DD.isDecoderBuffer=function(e){return e instanceof DD||"object"==typeof e&&ND.isBuffer(e.base)&&"DecoderBuffer"===e.constructor.name&&"number"==typeof e.offset&&"number"==typeof e.length&&"function"==typeof e.save&&"function"==typeof e.restore&&"function"==typeof e.isEmpty&&"function"==typeof e.readUInt8&&"function"==typeof e.skip&&"function"==typeof e.raw},DD.prototype.save=function(){return{offset:this.offset,reporter:_D.prototype.save.call(this)}},DD.prototype.restore=function(e){const t=new DD(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,_D.prototype.restore.call(this,e.reporter),t},DD.prototype.isEmpty=function(){return this.offset===this.length},DD.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},DD.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const n=new DD(this.base);return n._reporterState=this._reporterState,n.offset=this.offset,n.length=this.offset+e,this.offset+=e,n},DD.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},QD.EncoderBuffer=FD,FD.isEncoderBuffer=function(e){return e instanceof FD||"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},FD.prototype.join=function(e,t){return e||(e=ND.alloc(this.length)),t||(t=0),0===this.length||(Array.isArray(this.value)?this.value.forEach((function(n){n.join(e,t),t+=n.length})):("number"==typeof this.value?e[t]=this.value:"string"==typeof this.value?e.write(this.value,t):ND.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e};const PD=ED.Reporter,UD=QD.EncoderBuffer,MD=QD.DecoderBuffer,LD=Ew,TD=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],RD=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(TD);function OD(e,t,n){const r={};this._baseState=r,r.name=n,r.enc=e,r.parent=t||null,r.children=null,r.tag=null,r.args=null,r.reverseArgs=null,r.choice=null,r.optional=!1,r.any=!1,r.obj=!1,r.use=null,r.useDecoder=null,r.key=null,r.default=null,r.explicit=null,r.implicit=null,r.contains=null,r.parent||(r.children=[],this._wrap())}var HD=OD;const KD=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];OD.prototype.clone=function(){const e=this._baseState,t={};KD.forEach((function(n){t[n]=e[n]}));const n=new this.constructor(t.parent);return n._baseState=t,n},OD.prototype._wrap=function(){const e=this._baseState;RD.forEach((function(t){this[t]=function(){const n=new this.constructor(this);return e.children.push(n),n[t].apply(n,arguments)}}),this)},OD.prototype._init=function(e){const t=this._baseState;LD(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),LD.equal(t.children.length,1,"Root node can have only one child")},OD.prototype._useArgs=function(e){const t=this._baseState,n=e.filter((function(e){return e instanceof this.constructor}),this);e=e.filter((function(e){return!(e instanceof this.constructor)}),this),0!==n.length&&(LD(null===t.children),t.children=n,n.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(LD(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;const t={};return Object.keys(e).forEach((function(n){n==(0|n)&&(n|=0);const r=e[n];t[r]=n})),t})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){OD.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),TD.forEach((function(e){OD.prototype[e]=function(){const t=this._baseState,n=Array.prototype.slice.call(arguments);return LD(null===t.tag),t.tag=e,this._useArgs(n),this}})),OD.prototype.use=function(e){LD(e);const t=this._baseState;return LD(null===t.use),t.use=e,this},OD.prototype.optional=function(){return this._baseState.optional=!0,this},OD.prototype.def=function(e){const t=this._baseState;return LD(null===t.default),t.default=e,t.optional=!0,this},OD.prototype.explicit=function(e){const t=this._baseState;return LD(null===t.explicit&&null===t.implicit),t.explicit=e,this},OD.prototype.implicit=function(e){const t=this._baseState;return LD(null===t.explicit&&null===t.implicit),t.implicit=e,this},OD.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},OD.prototype.key=function(e){const t=this._baseState;return LD(null===t.key),t.key=e,this},OD.prototype.any=function(){return this._baseState.any=!0,this},OD.prototype.choice=function(e){const t=this._baseState;return LD(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},OD.prototype.contains=function(e){const t=this._baseState;return LD(null===t.use),t.contains=e,this},OD.prototype._decode=function(e,t){const n=this._baseState;if(null===n.parent)return e.wrapResult(n.children[0]._decode(e,t));let r,i=n.default,o=!0,a=null;if(null!==n.key&&(a=e.enterKey(n.key)),n.optional){let r=null;if(null!==n.explicit?r=n.explicit:null!==n.implicit?r=n.implicit:null!==n.tag&&(r=n.tag),null!==r||n.any){if(o=this._peekTag(e,r,n.any),e.isError(o))return o}else{const r=e.save();try{null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),o=!0}catch(e){o=!1}e.restore(r)}}if(n.obj&&o&&(r=e.enterObject()),o){if(null!==n.explicit){const t=this._decodeTag(e,n.explicit);if(e.isError(t))return t;e=t}const r=e.offset;if(null===n.use&&null===n.choice){let t;n.any&&(t=e.save());const r=this._decodeTag(e,null!==n.implicit?n.implicit:n.tag,n.any);if(e.isError(r))return r;n.any?i=e.raw(t):e=r}if(t&&t.track&&null!==n.tag&&t.track(e.path(),r,e.length,"tagged"),t&&t.track&&null!==n.tag&&t.track(e.path(),e.offset,e.length,"content"),n.any||(i=null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t)),e.isError(i))return i;if(n.any||null!==n.choice||null===n.children||n.children.forEach((function(n){n._decode(e,t)})),n.contains&&("octstr"===n.tag||"bitstr"===n.tag)){const r=new MD(i);i=this._getUse(n.contains,e._reporterState.obj)._decode(r,t)}}return n.obj&&o&&(i=e.leaveObject(r)),null===n.key||null===i&&!0!==o?null!==a&&e.exitKey(a):e.leaveKey(a,n.key,i),i},OD.prototype._decodeGeneric=function(e,t,n){const r=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,r.args[0],n):/str$/.test(e)?this._decodeStr(t,e,n):"objid"===e&&r.args?this._decodeObjid(t,r.args[0],r.args[1],n):"objid"===e?this._decodeObjid(t,null,null,n):"gentime"===e||"utctime"===e?this._decodeTime(t,e,n):"null_"===e?this._decodeNull(t,n):"bool"===e?this._decodeBool(t,n):"objDesc"===e?this._decodeStr(t,e,n):"int"===e||"enum"===e?this._decodeInt(t,r.args&&r.args[0],n):null!==r.use?this._getUse(r.use,t._reporterState.obj)._decode(t,n):t.error("unknown tag: "+e)},OD.prototype._getUse=function(e,t){const n=this._baseState;return n.useDecoder=this._use(e,t),LD(null===n.useDecoder._baseState.parent),n.useDecoder=n.useDecoder._baseState.children[0],n.implicit!==n.useDecoder._baseState.implicit&&(n.useDecoder=n.useDecoder.clone(),n.useDecoder._baseState.implicit=n.implicit),n.useDecoder},OD.prototype._decodeChoice=function(e,t){const n=this._baseState;let r=null,i=!1;return Object.keys(n.choice).some((function(o){const a=e.save(),s=n.choice[o];try{const n=s._decode(e,t);if(e.isError(n))return!1;r={type:o,value:n},i=!0}catch(t){return e.restore(a),!1}return!0}),this),i?r:e.error("Choice not matched")},OD.prototype._createEncoderBuffer=function(e){return new UD(e,this.reporter)},OD.prototype._encode=function(e,t,n){const r=this._baseState;if(null!==r.default&&r.default===e)return;const i=this._encodeValue(e,t,n);return void 0===i||this._skipDefault(i,t,n)?void 0:i},OD.prototype._encodeValue=function(e,t,n){const r=this._baseState;if(null===r.parent)return r.children[0]._encode(e,t||new PD);let i=null;if(this.reporter=t,r.optional&&void 0===e){if(null===r.default)return;e=r.default}let o=null,a=!1;if(r.any)i=this._createEncoderBuffer(e);else if(r.choice)i=this._encodeChoice(e,t);else if(r.contains)o=this._getUse(r.contains,n)._encode(e,t),a=!0;else if(r.children)o=r.children.map((function(n){if("null_"===n._baseState.tag)return n._encode(null,t,e);if(null===n._baseState.key)return t.error("Child should have a key");const r=t.enterKey(n._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");const i=n._encode(e[n._baseState.key],t,e);return t.leaveKey(r),i}),this).filter((function(e){return e})),o=this._createEncoderBuffer(o);else if("seqof"===r.tag||"setof"===r.tag){if(!r.args||1!==r.args.length)return t.error("Too many args for : "+r.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");const n=this.clone();n._baseState.implicit=null,o=this._createEncoderBuffer(e.map((function(n){const r=this._baseState;return this._getUse(r.args[0],e)._encode(n,t)}),n))}else null!==r.use?i=this._getUse(r.use,n)._encode(e,t):(o=this._encodePrimitive(r.tag,e),a=!0);if(!r.any&&null===r.choice){const e=null!==r.implicit?r.implicit:r.tag,n=null===r.implicit?"universal":"context";null===e?null===r.use&&t.error("Tag could be omitted only for .use()"):null===r.use&&(i=this._encodeComposite(e,a,n,o))}return null!==r.explicit&&(i=this._encodeComposite(r.explicit,!1,"context",i)),i},OD.prototype._encodeChoice=function(e,t){const n=this._baseState,r=n.choice[e.type];return r||LD(!1,e.type+" not found in "+JSON.stringify(Object.keys(n.choice))),r._encode(e.value,t)},OD.prototype._encodePrimitive=function(e,t){const n=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&n.args)return this._encodeObjid(t,n.reverseArgs[0],n.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,n.args&&n.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},OD.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},OD.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)};var jD={};!function(e){function t(e){const t={};return Object.keys(e).forEach((function(n){(0|n)==n&&(n|=0);const r=e[n];t[r]=n})),t}e.tagClass={0:"universal",1:"application",2:"context",3:"private"},e.tagClassByName=t(e.tagClass),e.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},e.tagByName=t(e.tag)}(jD);const GD=Ow.exports,qD=BD.Buffer,VD=HD,zD=jD;function JD(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new XD,this.tree._init(e.body)}var YD=JD;function XD(e){VD.call(this,"der",e)}function WD(e){return e<10?"0"+e:e}JD.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},GD(XD,VD),XD.prototype._encodeComposite=function(e,t,n,r){const i=function(e,t,n,r){let i;if("seqof"===e?e="seq":"setof"===e&&(e="set"),zD.tagByName.hasOwnProperty(e))i=zD.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return r.error("Unknown tag: "+e);i=e}return i>=31?r.error("Multi-octet tag encoding unsupported"):(t||(i|=32),i|=zD.tagClassByName[n||"universal"]<<6,i)}(e,t,n,this.reporter);if(r.length<128){const e=qD.alloc(2);return e[0]=i,e[1]=r.length,this._createEncoderBuffer([e,r])}let o=1;for(let e=r.length;e>=256;e>>=8)o++;const a=qD.alloc(2+o);a[0]=i,a[1]=128|o;for(let e=1+o,t=r.length;t>0;e--,t>>=8)a[e]=255&t;return this._createEncoderBuffer([a,r])},XD.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){const t=qD.alloc(2*e.length);for(let n=0;n<e.length;n++)t.writeUInt16BE(e.charCodeAt(n),2*n);return this._createEncoderBuffer(t)}return"numstr"===t?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===t?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(t)||"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},XD.prototype._encodeObjid=function(e,t,n){if("string"==typeof e){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[e].split(/[\s.]+/g);for(let t=0;t<e.length;t++)e[t]|=0}else if(Array.isArray(e)){e=e.slice();for(let t=0;t<e.length;t++)e[t]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let r=0;for(let t=0;t<e.length;t++){let n=e[t];for(r++;n>=128;n>>=7)r++}const i=qD.alloc(r);let o=i.length-1;for(let t=e.length-1;t>=0;t--){let n=e[t];for(i[o--]=127&n;(n>>=7)>0;)i[o--]=128|127&n}return this._createEncoderBuffer(i)},XD.prototype._encodeTime=function(e,t){let n;const r=new Date(e);return"gentime"===t?n=[WD(r.getUTCFullYear()),WD(r.getUTCMonth()+1),WD(r.getUTCDate()),WD(r.getUTCHours()),WD(r.getUTCMinutes()),WD(r.getUTCSeconds()),"Z"].join(""):"utctime"===t?n=[WD(r.getUTCFullYear()%100),WD(r.getUTCMonth()+1),WD(r.getUTCDate()),WD(r.getUTCHours()),WD(r.getUTCMinutes()),WD(r.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(n,"octstr")},XD.prototype._encodeNull=function(){return this._createEncoderBuffer("")},XD.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!qD.isBuffer(e)){const t=e.toArray();!e.sign&&128&t[0]&&t.unshift(0),e=qD.from(t)}if(qD.isBuffer(e)){let t=e.length;0===e.length&&t++;const n=qD.alloc(t);return e.copy(n),0===e.length&&(n[0]=0),this._createEncoderBuffer(n)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let t=e;t>=256;t>>=8)n++;const r=new Array(n);for(let t=r.length-1;t>=0;t--)r[t]=255&e,e>>=8;return 128&r[0]&&r.unshift(0),this._createEncoderBuffer(qD.from(r))},XD.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},XD.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},XD.prototype._skipDefault=function(e,t,n){const r=this._baseState;let i;if(null===r.default)return!1;const o=e.join();if(void 0===r.defaultBuffer&&(r.defaultBuffer=this._encodeValue(r.default,t,n).join()),o.length!==r.defaultBuffer.length)return!1;for(i=0;i<o.length;i++)if(o[i]!==r.defaultBuffer[i])return!1;return!0};const ZD=Ow.exports,$D=YD;function eF(e){$D.call(this,e),this.enc="pem"}ZD(eF,$D);var tF=eF;eF.prototype.encode=function(e,t){const n=$D.prototype.encode.call(this,e).toString("base64"),r=["-----BEGIN "+t.label+"-----"];for(let e=0;e<n.length;e+=64)r.push(n.slice(e,e+64));return r.push("-----END "+t.label+"-----"),r.join("\n")},function(e){const t=e;t.der=YD,t.pem=tF}(mD);var nF={};const rF=Ow.exports,iF=Bw.exports,oF=QD.DecoderBuffer,aF=HD,sF=jD;function lF(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new AF,this.tree._init(e.body)}var uF=lF;function AF(e){aF.call(this,"der",e)}function cF(e,t){let n=e.readUInt8(t);if(e.isError(n))return n;const r=sF.tagClass[n>>6],i=0==(32&n);if(31==(31&n)){let r=n;for(n=0;128==(128&r);){if(r=e.readUInt8(t),e.isError(r))return r;n<<=7,n|=127&r}}else n&=31;return{cls:r,primitive:i,tag:n,tagStr:sF.tag[n]}}function hF(e,t,n){let r=e.readUInt8(n);if(e.isError(r))return r;if(!t&&128===r)return null;if(0==(128&r))return r;const i=127&r;if(i>4)return e.error("length octect is too long");r=0;for(let t=0;t<i;t++){r<<=8;const t=e.readUInt8(n);if(e.isError(t))return t;r|=t}return r}lF.prototype.decode=function(e,t){return oF.isDecoderBuffer(e)||(e=new oF(e,t)),this.tree._decode(e,t)},rF(AF,aF),AF.prototype._peekTag=function(e,t,n){if(e.isEmpty())return!1;const r=e.save(),i=cF(e,'Failed to peek tag: "'+t+'"');return e.isError(i)?i:(e.restore(r),i.tag===t||i.tagStr===t||i.tagStr+"of"===t||n)},AF.prototype._decodeTag=function(e,t,n){const r=cF(e,'Failed to decode tag of "'+t+'"');if(e.isError(r))return r;let i=hF(e,r.primitive,'Failed to get length of "'+t+'"');if(e.isError(i))return i;if(!n&&r.tag!==t&&r.tagStr!==t&&r.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(r.primitive||null!==i)return e.skip(i,'Failed to match body of: "'+t+'"');const o=e.save(),a=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(a)?a:(i=e.offset-o.offset,e.restore(o),e.skip(i,'Failed to match body of: "'+t+'"'))},AF.prototype._skipUntilEnd=function(e,t){for(;;){const n=cF(e,t);if(e.isError(n))return n;const r=hF(e,n.primitive,t);if(e.isError(r))return r;let i;if(i=n.primitive||null!==r?e.skip(r):this._skipUntilEnd(e,t),e.isError(i))return i;if("end"===n.tagStr)break}},AF.prototype._decodeList=function(e,t,n,r){const i=[];for(;!e.isEmpty();){const t=this._peekTag(e,"end");if(e.isError(t))return t;const o=n.decode(e,"der",r);if(e.isError(o)&&t)break;i.push(o)}return i},AF.prototype._decodeStr=function(e,t){if("bitstr"===t){const t=e.readUInt8();return e.isError(t)?t:{unused:t,data:e.raw()}}if("bmpstr"===t){const t=e.raw();if(t.length%2==1)return e.error("Decoding of string type: bmpstr length mismatch");let n="";for(let e=0;e<t.length/2;e++)n+=String.fromCharCode(t.readUInt16BE(2*e));return n}if("numstr"===t){const t=e.raw().toString("ascii");return this._isNumstr(t)?t:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){const t=e.raw().toString("ascii");return this._isPrintstr(t)?t:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},AF.prototype._decodeObjid=function(e,t,n){let r;const i=[];let o=0,a=0;for(;!e.isEmpty();)a=e.readUInt8(),o<<=7,o|=127&a,0==(128&a)&&(i.push(o),o=0);128&a&&i.push(o);const s=i[0]/40|0,l=i[0]%40;if(r=n?i:[s,l].concat(i.slice(1)),t){let e=t[r.join(" ")];void 0===e&&(e=t[r.join(".")]),void 0!==e&&(r=e)}return r},AF.prototype._decodeTime=function(e,t){const n=e.raw().toString();let r,i,o,a,s,l;if("gentime"===t)r=0|n.slice(0,4),i=0|n.slice(4,6),o=0|n.slice(6,8),a=0|n.slice(8,10),s=0|n.slice(10,12),l=0|n.slice(12,14);else{if("utctime"!==t)return e.error("Decoding "+t+" time is not supported yet");r=0|n.slice(0,2),i=0|n.slice(2,4),o=0|n.slice(4,6),a=0|n.slice(6,8),s=0|n.slice(8,10),l=0|n.slice(10,12),r=r<70?2e3+r:1900+r}return Date.UTC(r,i-1,o,a,s,l,0)},AF.prototype._decodeNull=function(){return null},AF.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},AF.prototype._decodeInt=function(e,t){const n=e.raw();let r=new iF(n);return t&&(r=t[r.toString(10)]||r),r},AF.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree};const fF=Ow.exports,dF=BD.Buffer,pF=uF;function gF(e){pF.call(this,e),this.enc="pem"}fF(gF,pF);var yF=gF;gF.prototype.decode=function(e,t){const n=e.toString().split(/[\r\n]+/g),r=t.label.toUpperCase(),i=/^-----(BEGIN|END) ([^-]+)-----$/;let o=-1,a=-1;for(let e=0;e<n.length;e++){const t=n[e].match(i);if(null!==t&&t[2]===r){if(-1!==o){if("END"!==t[1])break;a=e;break}if("BEGIN"!==t[1])break;o=e}}if(-1===o||-1===a)throw new Error("PEM section not found for: "+r);const s=n.slice(o+1,a).join("");s.replace(/[^a-z0-9+/=]+/gi,"");const l=dF.from(s,"base64");return pF.prototype.decode.call(this,l,t)},function(e){const t=e;t.der=uF,t.pem=yF}(nF),function(e){const t=mD,n=nF,r=Ow.exports;function i(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}e.define=function(e,t){return new i(e,t)},i.prototype._createNamed=function(e){const t=this.name;function n(e){this._initNamed(e,t)}return r(n,e),n.prototype._initNamed=function(t,n){e.call(this,t,n)},new n(this)},i.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(n[e])),this.decoders[e]},i.prototype.decode=function(e,t,n){return this._getDecoder(t).decode(e,n)},i.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(t[e])),this.encoders[e]},i.prototype.encode=function(e,t,n){return this._getEncoder(t).encode(e,n)}}(yD);var mF={};!function(e){const t=mF;t.Reporter=ED.Reporter,t.DecoderBuffer=QD.DecoderBuffer,t.EncoderBuffer=QD.EncoderBuffer,t.Node=HD}();var vF={};!function(e){const t=e;t._reverse=function(e){const t={};return Object.keys(e).forEach((function(n){(0|n)==n&&(n|=0);const r=e[n];t[r]=n})),t},t.der=jD}(vF),function(e){const t=gD;t.bignum=Bw.exports,t.define=yD.define,t.base=mF,t.constants=vF,t.decoders=nF,t.encoders=mD}();var IF={exports:{}},wF={},bF={};Object.defineProperty(bF,"__esModule",{value:!0}),bF.default=function(e){var t=e.length,n=t%4;if(!n)return e;var r=t,i=4-n,o=t+i,a=ao.alloc(o);for(a.write(e);i--;)a.write("=",r++);return a.toString()},Object.defineProperty(wF,"__esModule",{value:!0});var BF=bF;function EF(e,t){return void 0===t&&(t="utf8"),jo(e)?SF(e.toString("base64")):SF(ao.from(e,t).toString("base64"))}function CF(e){return e=e.toString(),BF.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function SF(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var xF=EF;xF.encode=EF,xF.decode=function(e,t){return void 0===t&&(t="utf8"),ao.from(CF(e),"base64").toString(t)},xF.toBase64=CF,xF.fromBase64=SF,xF.toBuffer=function(e){return ao.from(CF(e),"base64")},wF.default=xF,function(e){e.exports=wF.default,e.exports.default=e.exports}(IF);var QF=IF.exports;const kF=gD,_F=IF.exports;var NF=class{static convert(e,t,n){if(!e)return;if(t===n)return e;let r;if("raw"===t||e instanceof ao)r=e;else if("uint8_array"===t||Array.isArray(e))r=ao.from(e);else if("hex"===t)r=ao.from(e,"hex");else if("base64"===t)r=ao.from(e,"base64");else if("base64url"===t)r=_F.toBuffer(e);else{if("bn"!==t&&"bignum"!==t)throw new Error("Invalid fromType");r=ao.from(this.pad(e.toString(16)),"hex")}if("raw"===n)return r;if("uint8_array"===n)return Array.from(r);if("hex"===n)return r.toString("hex");if("base64"===n)return r.toString("base64");if("base64url"===n)return _F.fromBase64(r.toString("base64"));if("bn"===n||"bignum"===n)return new kF.bignum(r);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}};const DF=gD;const FF=new class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(e,t){this._registry[e]=DF.define(e,t(this))}normalize(e){return this.registry[e]}};FF.define("Version",(e=>function(){this.int({0:"two-prime",1:"multi"})})),FF.define("OtherPrimeInfos",(e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),FF.define("AlgorithmIdentifier",(e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),FF.define("PrivateKeyInfo",(e=>{let t=e.normalize("Version"),n=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("version").use(t),this.key("algorithm").use(n),this.key("privateKey").octstr())}})),FF.define("PublicKeyInfo",(e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}})),FF.define("RSAPrivateKey",(e=>{let t=e.normalize("Version"),n=e.normalize("OtherPrimeInfos");return function(){this.seq().obj(this.key("version").use(t),this.key("n").int(),this.key("e").int(),this.key("d").int(),this.key("p").int(),this.key("q").int(),this.key("dp").int(),this.key("dq").int(),this.key("qi").int(),this.key("other").optional().use(n))}})),FF.define("RSAPublicKey",(e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),FF.define("ECPrivateKey",(e=>function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).optional().choice({namedCurve:this.objid()}),this.key("publicKey").explicit(1).optional().bitstr())}));var PF=FF;const UF=pD,MF=NF,LF=PF;class TF extends UF{fromPrivatePKCS1(e){let t=LF.normalize("RSAPrivateKey"),{n:n,e:r,d:i,p:o,q:a,dp:s,dq:l,qi:u}=t.decode(e,"der");return{n:MF.convert(n,"bn","raw"),e:MF.convert(r,"bn","raw"),d:MF.convert(i,"bn","raw"),p:MF.convert(o,"bn","raw"),q:MF.convert(a,"bn","raw"),dp:MF.convert(s,"bn","raw"),dq:MF.convert(l,"bn","raw"),qi:MF.convert(u,"bn","raw")}}fromPrivatePKCS8(e){let t=LF.normalize("PrivateKeyInfo"),n=LF.normalize("RSAPrivateKey"),r=t.decode(e,"der"),{n:i,e:o,d:a,p:s,q:l,dp:u,dq:A,qi:c}=n.decode(r.privateKey,"der");return{n:MF.convert(i,"bn","raw"),e:MF.convert(o,"bn","raw"),d:MF.convert(a,"bn","raw"),p:MF.convert(s,"bn","raw"),q:MF.convert(l,"bn","raw"),dp:MF.convert(u,"bn","raw"),dq:MF.convert(A,"bn","raw"),qi:MF.convert(c,"bn","raw")}}fromPublicPKCS1(e){let t=LF.normalize("RSAPublicKey"),{n:n,e:r}=t.decode(e,"der");return{n:MF.convert(n,"bn","raw"),e:MF.convert(r,"bn","raw")}}fromPublicPKCS8(e){let t=LF.normalize("PublicKeyInfo"),n=LF.normalize("RSAPublicKey"),r=t.decode(e,"der"),{n:i,e:o}=n.decode(r.publicKey.data,"der");return{n:MF.convert(i,"bn","raw"),e:MF.convert(o,"bn","raw")}}fromJwk(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l,alg:u}=e;return{n:MF.convert(t,"base64url","raw"),e:MF.convert(n,"base64url","raw"),d:MF.convert(r,"base64url","raw"),p:MF.convert(i,"base64url","raw"),q:MF.convert(o,"base64url","raw"),dp:MF.convert(a,"base64url","raw"),dq:MF.convert(s,"base64url","raw"),qi:MF.convert(l,"base64url","raw")}}toPrivatePKCS1(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l}=e,{version:u}=this.params,A=LF.normalize("RSAPrivateKey").encode({version:u,n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn"),d:MF.convert(r,"raw","bn"),p:MF.convert(i,"raw","bn"),q:MF.convert(o,"raw","bn"),dp:MF.convert(a,"raw","bn"),dq:MF.convert(s,"raw","bn"),qi:MF.convert(l,"raw","bn")},"der").toString("base64");return TF.formatPem(A,"RSA PRIVATE")}toPrivatePKCS8(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l}=e,{oid:u,algParameters:A,version:c}=this.params,h=LF.normalize("PrivateKeyInfo"),f=LF.normalize("RSAPrivateKey").encode({version:c,n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn"),d:MF.convert(r,"raw","bn"),p:MF.convert(i,"raw","bn"),q:MF.convert(o,"raw","bn"),dp:MF.convert(a,"raw","bn"),dq:MF.convert(s,"raw","bn"),qi:MF.convert(l,"raw","bn")},"der"),d=h.encode({version:c,algorithm:{algorithm:u.split("."),parameters:ao.from(A,"hex")},privateKey:f},"der").toString("base64");return TF.formatPem(d,"PRIVATE")}toPublicPKCS1(e){let{n:t,e:n}=e,{version:r}=this.params,i=LF.normalize("RSAPublicKey").encode({version:r,n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn")},"der").toString("base64");return TF.formatPem(i,"RSA PUBLIC")}toPublicPKCS8(e){let{n:t,e:n}=e,{oid:r,algParameters:i}=this.params,o=LF.normalize("PublicKeyInfo"),a=LF.normalize("RSAPublicKey").encode({n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn")},"der"),s=o.encode({algorithm:{algorithm:r.split("."),parameters:ao.from(i,"hex")},publicKey:{unused:0,data:a}},"der").toString("base64");return TF.formatPem(s,"PUBLIC")}toPrivateJwk(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l}=e,{kty:u}=this.params;return{kty:u,n:MF.convert(t,"raw","base64url"),e:MF.convert(n,"raw","base64url"),d:MF.convert(r,"raw","base64url"),p:MF.convert(i,"raw","base64url"),q:MF.convert(o,"raw","base64url"),dp:MF.convert(a,"raw","base64url"),dq:MF.convert(s,"raw","base64url"),qi:MF.convert(l,"raw","base64url")}}toPublicJwk(e){let{n:t,e:n}=e,{kty:r}=this.params;return{kty:r,n:MF.convert(t,"raw","base64url"),e:MF.convert(n,"raw","base64url")}}}var RF=TF;const OF=new ww.ec("secp256k1"),HF=pD,KF=NF,jF=PF;class GF extends HF{fromPrivatePKCS1(e){let t=jF.normalize("ECPrivateKey").decode(e,"der"),{privateKey:n,publicKey:{data:r}}=t,i=KF.convert(r,"raw","hex"),{x:o,y:a}=GF.getPoint(i);return{d:n,x:o,y:a}}fromPrivatePKCS8(e){let t=jF.normalize("PrivateKeyInfo"),n=jF.normalize("ECPrivateKey"),r=t.decode(e,"der"),i=n.decode(r.privateKey,"der"),{privateKey:o,publicKey:{data:a}}=i,s=KF.convert(a,"raw","hex"),{x:l,y:u}=GF.getPoint(s);return{d:o,x:l,y:u}}fromPublicPKCS8(e){let t=jF.normalize("PublicKeyInfo").decode(e,"der"),n=KF.convert(t.publicKey.data,"raw","hex");return GF.getPoint(n)}fromPrivateBlk(e){let t=OF.keyFromPrivate(e,"hex"),n=t.getPublic();return{d:KF.convert(t.priv,"bn","raw"),x:KF.convert(n.getX(),"bn","raw"),y:KF.convert(n.getY(),"bn","raw")}}fromPublicBlk(e){return GF.getPoint(e)}fromJwk(e){let{d:t,x:n,y:r}=e;return{d:KF.convert(t,"base64url","raw"),x:KF.convert(n,"base64url","raw"),y:KF.convert(r,"base64url","raw")}}toPrivatePKCS1(e){let{namedCurve:t,keyVersion:n}=this.params,{d:r,x:i,y:o}=e,a=jF.normalize("ECPrivateKey"),s=GF.makePoint(i,o),l=a.encode({version:n,privateKey:r,parameters:{type:"namedCurve",value:t.split(".")},publicKey:{unused:0,data:s}},"der").toString("base64");return GF.formatPem(l,"EC PRIVATE")}toPrivatePKCS8(e){let{oid:t,algParameters:n,keyVersion:r,infoVersion:i}=this.params,{d:o,x:a,y:s}=e,l=jF.normalize("PrivateKeyInfo"),u=jF.normalize("ECPrivateKey"),A=GF.makePoint(a,s),c=u.encode({version:r,privateKey:o,publicKey:{unused:0,data:A}},"der"),h=l.encode({version:i,algorithm:{algorithm:t.split("."),parameters:ao.from(n,"hex")},privateKey:c},"der").toString("base64");return GF.formatPem(h,"PRIVATE")}toPublicPKCS8(e){let{oid:t,algParameters:n}=this.params,{x:r,y:i}=e,o=jF.normalize("PublicKeyInfo"),a=GF.makePoint(r,i),s=o.encode({algorithm:{algorithm:t.split("."),parameters:ao.from(n,"hex")},publicKey:{unused:0,data:a}},"der").toString("base64");return GF.formatPem(s,"PUBLIC")}toPrivateBlk(e){return e.d.toString("hex")}toPublicBlk(e){return KF.convert(GF.makePoint(e.x,e.y),"raw","hex")}toPrivateJwk(e){let{crv:t,kty:n}=this.params,{d:r,x:i,y:o}=e;return{kty:n,crv:t,d:KF.convert(r,"raw","base64url"),x:KF.convert(i,"raw","base64url"),y:KF.convert(o,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:n}=this.params,{x:r,y:i}=e;return{kty:n,crv:t,x:KF.convert(r,"raw","base64url"),y:KF.convert(i,"raw","base64url")}}static getPoint(e){let t=e.slice(2,(e.length-2)/2+2),n=e.slice((e.length-2)/2+2);return{x:KF.convert(t,"hex","raw"),y:KF.convert(n,"hex","raw")}}static makePoint(e,t){let n=ao.from("04","hex");return ao.concat([n,e,t],n.length+e.length+t.length)}}var qF=GF;const VF=pD,zF=NF,JF=PF;class YF extends VF{fromPrivatePKCS8(e){const t=JF.normalize("PrivateKeyInfo").decode(e,"der").privateKey.slice(2);return{d:t,x:this.publicKeyFromPrivate(t)}}fromPublicPKCS8(e){const t=JF.normalize("PublicKeyInfo").decode(e,"der");return{x:zF.convert(t.publicKey.data,"hex","raw")}}fromJwk(e){let{d:t,x:n}=e;return{d:zF.convert(t,"base64url","raw"),x:zF.convert(n,"base64url","raw")}}toPrivatePKCS8(e){let{oid:t,infoVersion:n}=this.params,{d:r}=e;const i=JF.normalize("PrivateKeyInfo"),o=this.privateKeyPadding(r);let a=i.encode({version:n,algorithm:{algorithm:t.split(".")},privateKey:o},"der").toString("base64");return YF.formatPem(a,"PRIVATE")}toPublicPKCS8(e){let{oid:t}=this.params,{x:n}=e,r=JF.normalize("PublicKeyInfo").encode({algorithm:{algorithm:t.split(".")},publicKey:{unused:0,data:zF.convert(n,"hex","raw")}},"der").toString("base64");return YF.formatPem(r,"PUBLIC")}toPrivateJwk(e){let{crv:t,kty:n}=this.params,{d:r,x:i}=e;return{kty:n,crv:t,d:zF.convert(r,"raw","base64url"),x:zF.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:n}=this.params,{x:r}=e;return{kty:n,crv:t,x:zF.convert(r,"raw","base64url")}}privateKeyPadding(e){let t;if("Ed25519"!==this.params.crv)throw new Error(`${this.params.crv} is an invalid curve for EdDSA`);return t=ao.from("0420","hex"),ao.concat([t,e],t.length+e.length)}publicKeyFromPrivate(e){if("Ed25519"===this.params.crv){const t=new ww.eddsa("ed25519");return ao.from(t.keyFromSecret(e).getPublic())}throw new Error(`${this.params.crv} is an invalid curve for EdDSA`)}}const XF=RF,WF=qF,ZF=YF,$F=new class{constructor(){this.registry=[],this.classes={}}find(e){return this.registry.find(e)}define(e,t){e.forEach((e=>{let{kty:n}=e;if(!n)throw new Error("Invalid type definition");this.classes[n]||(this.classes[n]=t),this.registry.push(e)}))}normalize(e,t,n){let r=this.classes[e],i=this.find((e=>e[t]===n));if(!r||!i)throw new Error("Invalid type");return new r(i)}};$F.define([{kty:"RSA",oid:"1.2.840.113549.1.1.1",algParameters:"0500",version:"two-prime"}],XF),$F.define([{kty:"EC",crv:"K-256",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.10",algParameters:"06052b8104000a",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-256",oid:"1.2.840.10045.2.1",namedCurve:"1.2.840.10045.3.1.7",algParameters:"06082a8648ce3d030107",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-384",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.34",algParameters:"06052b81040022",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-521",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.35",algParameters:"06052b81040023",keyVersion:1,infoVersion:"two-prime"}],WF),$F.define([{kty:"OKP",crv:"Ed25519",oid:"1.3.101.112",infoVersion:"two-prime"}],ZF);const eP=AD,tP=hD,nP=$F,rP=PF,iP=RegExp("\r?\n","g");class oP{constructor(e,t){if(!e)throw new eP("key is required");if(!t)throw new eP("options are required");let{kty:n,format:r,selector:i,crv:o,oid:a}=t;if(!t.kty)throw new eP("options.kty is required");if(!t.format)throw new eP("options.format is required");if(!t.selector)throw new eP("options.selector is required");if(!t.crv&&!t.oid)throw new eP("options.crv or options.oid is required");this.kty=n,this.format=r,this.selector=i,this.crv=o,this.oid=a,this.key=this.parseKey(e)}static from(e,t){if(!e)throw new eP("key is required");if(!t)throw new eP("format is required");if("jwk"===t){let n;if("string"==typeof e)try{n=JSON.parse(e)}catch(e){throw new eP("key is not a valid JWK")}else"object"==typeof e&&(n=e);let r,{kty:i,crv:o}=n;if(!i)throw new eP("kty is required for JWK");if("EC"===i&&!o)throw new eP("crv is required for EC JWK");"RSA"===i&&(r=nP.find((e=>e.kty===i)).oid);let a=n.d?"private":"public";return new oP(n,{kty:i,crv:o,oid:r,format:t,selector:a})}if("pem"===t){if("string"!=typeof e)throw new eP("key is not a valid PEM string");let n=e.split(iP),r=n.splice(0,1);n.splice(n.length-1,1);let i,o,a=n.join(""),s=/^-----BEGIN ((RSA|EC) )?(PUBLIC|PRIVATE) KEY-----$/.exec(r),l=s?s[2]:void 0,u=s?s[3]:void 0,A=ao.from(a,"base64");if(!u)throw new eP("key is not a valid PEM string");if(l){if("RSA"===l)u="PRIVATE"===u?"private_pkcs1":"public_pkcs1",i=nP.find((e=>e.kty===l)).oid;else if("EC"===l){let e;if("PRIVATE"===u){let t=rP.normalize(`${l}PrivateKey`);u="private_pkcs1",e=t.decode(A,"der")}else if("PUBLIC"===u){let t=rP.normalize(`${l}PrivateKey`);u="public_pkcs1",e=t.decode(A,"der")}let{parameters:{value:t}}=e;o=nP.find((e=>e.namedCurve===t.join("."))).crv}}else{let e,t=rP.normalize("PrivateKeyInfo"),n=rP.normalize("PublicKeyInfo");"PRIVATE"===u?(u="private_pkcs8",e=t.decode(A,"der")):"PUBLIC"===u&&(u="public_pkcs8",e=n.decode(A,"der"));let{algorithm:{algorithm:r,parameters:a}}=e;r=r.join("."),a=a?a.toString("hex"):void 0;const s=nP.find((e=>e.oid===r));if(l=s?s.kty:void 0,!l)throw new eP(`${r} is not supported`);"RSA"===l||"OKP"===l?i=r:"EC"===l&&(o=nP.find((e=>e.algParameters===a)).crv)}return new oP(A,{kty:l,oid:i,crv:o,format:t,selector:u})}if("blk"===t)return new oP(e,{kty:"EC",crv:"K-256",format:t,selector:e.length>64?"public":"private"});throw new eP(`Invalid format ${t}`)}get alg(){let{kty:e,crv:t,oid:n}=this;if(!this.algorithm){if(t)Object.defineProperty(this,"algorithm",{value:nP.normalize(e,"crv",t)});else{if(!n)throw new Error("Both crv and oid are undefined");Object.defineProperty(this,"algorithm",{value:nP.normalize(e,"oid",n)})}if(!this.algorithm)throw new Error(`${this.crv||this.oid} is not implemented yet`)}return this.algorithm}parseKey(e){let{alg:t,format:n,selector:r}=this;if("pem"===n)switch(r){case"public_pkcs1":return t.fromPublicPKCS1(e);case"public_pkcs8":return t.fromPublicPKCS8(e);case"private_pkcs1":return t.fromPrivatePKCS1(e);case"private_pkcs8":return t.fromPrivatePKCS8(e);default:throw new Error("Invalid selector value")}if("jwk"===n)return t.fromJwk(e,r);if("blk"===n)switch(r){case"public":return t.fromPublicBlk(e);case"private":return t.fromPrivateBlk(e)}}toJwk(e){let{key:t,alg:n,selector:r}=this;switch(e){case"public":return n.toPublicJwk(t);case"private":if(r.includes("public"))throw new eP("Cannot export a private key from a public key");return n.toPrivateJwk(t);default:throw new Error("Invalid key selector")}}toString(e="pem",t="public_pkcs8"){let{key:n,alg:r,selector:i}=this;if("pem"===e)switch(t){case"public_pkcs1":return r.toPublicPKCS1(n);case"public_pkcs8":return r.toPublicPKCS8(n);case"private_pkcs1":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return r.toPrivatePKCS1(n);case"private_pkcs8":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return r.toPrivatePKCS8(n);default:throw new Error("Invalid key selector")}else if("jwk"===e)switch(t){case"public":return JSON.stringify(r.toPublicJwk(n));case"private":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return JSON.stringify(r.toPrivateJwk(n));default:throw new Error("Invalid key selector")}else if("blk"===e)switch(t){case"private":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return r.toPrivateBlk(n);case"public":return r.toPublicBlk(n);default:throw new Error("Invalid key selector")}throw new tP}}var aP=oP,sP=U_("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const lP=ao;var uP={},AP={},cP={};Object.defineProperty(cP,"__esModule",{value:!0}),cP.testnet=cP.regtest=cP.bitcoin=void 0,cP.bitcoin={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},cP.regtest={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},cP.testnet={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var hP={},fP={},dP={},pP={};Object.defineProperty(pP,"__esModule",{value:!0}),pP.encode=pP.decode=pP.check=void 0,pP.check=function(e){if(e.length<8)return!1;if(e.length>72)return!1;if(48!==e[0])return!1;if(e[1]!==e.length-2)return!1;if(2!==e[2])return!1;const t=e[3];if(0===t)return!1;if(5+t>=e.length)return!1;if(2!==e[4+t])return!1;const n=e[5+t];return!(0===n||6+t+n!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||n>1&&0===e[t+6]&&!(128&e[t+7]))},pP.decode=function(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");const t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");const n=e[5+t];if(0===n)throw new Error("S length is zero");if(6+t+n!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(n>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}},pP.encode=function(e,t){const n=e.length,r=t.length;if(0===n)throw new Error("R length is zero");if(0===r)throw new Error("S length is zero");if(n>33)throw new Error("R length is too long");if(r>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(n>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(r>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");const i=ao.allocUnsafe(6+n+r);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+n]=2,i[5+n]=t.length,t.copy(i,6+n),i};var gP={};Object.defineProperty(gP,"__esModule",{value:!0}),gP.REVERSE_OPS=gP.OPS=void 0;const yP={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};gP.OPS=yP;const mP={};gP.REVERSE_OPS=mP;for(const e of Object.keys(yP))mP[yP[e]]=e;var vP={};Object.defineProperty(vP,"__esModule",{value:!0}),vP.decode=vP.encode=vP.encodingLength=void 0;const IP=gP;function wP(e){return e<IP.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}vP.encodingLength=wP,vP.encode=function(e,t,n){const r=wP(t);return 1===r?e.writeUInt8(t,n):2===r?(e.writeUInt8(IP.OPS.OP_PUSHDATA1,n),e.writeUInt8(t,n+1)):3===r?(e.writeUInt8(IP.OPS.OP_PUSHDATA2,n),e.writeUInt16LE(t,n+1)):(e.writeUInt8(IP.OPS.OP_PUSHDATA4,n),e.writeUInt32LE(t,n+1)),r},vP.decode=function(e,t){const n=e.readUInt8(t);let r,i;if(n<IP.OPS.OP_PUSHDATA1)r=n,i=1;else if(n===IP.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;r=e.readUInt8(t+1),i=2}else if(n===IP.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;r=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(n!==IP.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=e.readUInt32LE(t+1),i=5}return{opcode:n,number:r,size:i}};var bP={};Object.defineProperty(bP,"__esModule",{value:!0}),bP.encode=bP.decode=void 0,bP.decode=function(e,t,n){t=t||4,n=void 0===n||n;const r=e.length;if(0===r)return 0;if(r>t)throw new TypeError("Script number overflow");if(n&&0==(127&e[r-1])&&(r<=1||0==(128&e[r-2])))throw new Error("Non-minimally encoded script number");if(5===r){const t=e.readUInt32LE(0),n=e.readUInt8(4);return 128&n?-(4294967296*(-129&n)+t):4294967296*n+t}let i=0;for(let t=0;t<r;++t)i|=e[t]<<8*t;return 128&e[r-1]?-(i&~(128<<8*(r-1))):i},bP.encode=function(e){let t=Math.abs(e);const n=(r=t)>2147483647?5:r>8388607?4:r>32767?3:r>127?2:r>0?1:0;var r;const i=ao.allocUnsafe(n),o=e<0;for(let e=0;e<n;++e)i.writeUInt8(255&t,e),t>>=8;return 128&i[n-1]?i.writeUInt8(o?128:0,n-1):o&&(i[n-1]|=128),i};var BP={},EP={},CP={Array:function(e){return null!=e&&e.constructor===Array},Boolean:function(e){return"boolean"==typeof e},Function:function(e){return"function"==typeof e},Nil:function(e){return null==e},Number:function(e){return"number"==typeof e},Object:function(e){return"object"==typeof e},String:function(e){return"string"==typeof e},"":function(){return!0}};for(var SP in CP.Null=CP.Nil,CP)CP[SP].toJSON=function(e){return e}.bind(null,SP);var xP=CP,QP=xP;function kP(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function _P(e){return QP.Nil(e)?"":kP(e.constructor)}function NP(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function DP(e){return QP.Function(e)?e.toJSON?e.toJSON():kP(e):QP.Array(e)?"Array":e&&QP.Object(e)?"Object":void 0!==e?e:""}function FP(e,t,n){var r=function(e){return QP.Function(e)?"":QP.String(e)?JSON.stringify(e):e&&QP.Object(e)?"":e}(t);return"Expected "+DP(e)+", got"+(""!==n?" "+n:"")+(""!==r?" "+r:"")}function PP(e,t,n){n=n||_P(t),this.message=FP(e,t,n),NP(this,PP),this.__type=e,this.__value=t,this.__valueTypeName=n}function UP(e,t,n,r,i){e?(i=i||_P(r),this.message=function(e,t,n,r,i){var o='" of type ';return"key"===t&&(o='" with key type '),FP('property "'+DP(n)+o+DP(e),r,i)}(e,n,t,r,i)):this.message='Unexpected property "'+t+'"',NP(this,PP),this.__label=n,this.__property=t,this.__type=e,this.__value=r,this.__valueTypeName=i}PP.prototype=Object.create(Error.prototype),PP.prototype.constructor=PP,UP.prototype=Object.create(Error.prototype),UP.prototype.constructor=PP;var MP={TfTypeError:PP,TfPropertyTypeError:UP,tfCustomError:function(e,t){return new PP(e,{},t)},tfSubError:function(e,t,n){return e instanceof UP?(t=t+"."+e.__property,e=new UP(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof PP&&(e=new UP(e.__type,t,n,e.__value,e.__valueTypeName)),NP(e),e},tfJSON:DP,getValueTypeName:_P},LP=xP,TP=MP;function RP(e){return jo(e)}function OP(e){return"string"==typeof e&&/^([0-9a-f]{2})+$/i.test(e)}function HP(e,t){var n=e.toJSON();function r(r){if(!e(r))return!1;if(r.length===t)return!0;throw TP.tfCustomError(n+"(Length: "+t+")",n+"(Length: "+r.length+")")}return r.toJSON=function(){return n},r}var KP=HP.bind(null,LP.Array),jP=HP.bind(null,RP),GP=HP.bind(null,OP),qP=HP.bind(null,LP.String),VP=Math.pow(2,53)-1,zP={ArrayN:KP,Buffer:RP,BufferN:jP,Finite:function(e){return"number"==typeof e&&isFinite(e)},Hex:OP,HexN:GP,Int8:function(e){return e<<24>>24===e},Int16:function(e){return e<<16>>16===e},Int32:function(e){return(0|e)===e},Int53:function(e){return"number"==typeof e&&e>=-VP&&e<=VP&&Math.floor(e)===e},Range:function(e,t,n){function r(r,i){return n(r,i)&&r>e&&r<t}return n=n||LP.Number,r.toJSON=function(){return`${n.toJSON()} between [${e}, ${t}]`},r},StringN:qP,UInt8:function(e){return(255&e)===e},UInt16:function(e){return(65535&e)===e},UInt32:function(e){return e>>>0===e},UInt53:function(e){return"number"==typeof e&&e>=0&&e<=VP&&Math.floor(e)===e}};for(var JP in zP)zP[JP].toJSON=function(e){return e}.bind(null,JP);var YP=zP,XP=xP,WP=MP.tfJSON,ZP=MP.TfTypeError,$P=MP.TfPropertyTypeError,eU=MP.tfSubError,tU=MP.getValueTypeName,nU={arrayOf:function(e,t){function n(n,r){return!!XP.Array(n)&&!XP.Nil(n)&&!(void 0!==t.minLength&&n.length<t.minLength)&&!(void 0!==t.maxLength&&n.length>t.maxLength)&&(void 0===t.length||n.length===t.length)&&n.every((function(t,n){try{return iU(e,t,r)}catch(e){throw eU(e,n)}}))}return e=rU(e),t=t||{},n.toJSON=function(){var n="["+WP(e)+"]";return void 0!==t.length?n+="{"+t.length+"}":void 0===t.minLength&&void 0===t.maxLength||(n+="{"+(void 0===t.minLength?0:t.minLength)+","+(void 0===t.maxLength?1/0:t.maxLength)+"}"),n},n},maybe:function e(t){function n(n,r){return XP.Nil(n)||t(n,r,e)}return t=rU(t),n.toJSON=function(){return"?"+WP(t)},n},map:function(e,t){function n(n,r){if(!XP.Object(n))return!1;if(XP.Nil(n))return!1;for(var i in n){try{t&&iU(t,i,r)}catch(e){throw eU(e,i,"key")}try{var o=n[i];iU(e,o,r)}catch(e){throw eU(e,i)}}return!0}return e=rU(e),t&&(t=rU(t)),n.toJSON=t?function(){return"{"+WP(t)+": "+WP(e)+"}"}:function(){return"{"+WP(e)+"}"},n},object:function(e){var t={};for(var n in e)t[n]=rU(e[n]);function r(e,n){if(!XP.Object(e))return!1;if(XP.Nil(e))return!1;var r;try{for(r in t)iU(t[r],e[r],n)}catch(e){throw eU(e,r)}if(n)for(r in e)if(!t[r])throw new $P(void 0,r);return!0}return r.toJSON=function(){return WP(t)},r},anyOf:function(){var e=[].slice.call(arguments).map(rU);function t(t,n){return e.some((function(e){try{return iU(e,t,n)}catch(e){return!1}}))}return t.toJSON=function(){return e.map(WP).join("|")},t},allOf:function(){var e=[].slice.call(arguments).map(rU);function t(t,n){return e.every((function(e){try{return iU(e,t,n)}catch(e){return!1}}))}return t.toJSON=function(){return e.map(WP).join(" & ")},t},quacksLike:function(e){function t(t){return e===tU(t)}return t.toJSON=function(){return e},t},tuple:function(){var e=[].slice.call(arguments).map(rU);function t(t,n){return!XP.Nil(t)&&!XP.Nil(t.length)&&(!n||t.length===e.length)&&e.every((function(e,r){try{return iU(e,t[r],n)}catch(e){throw eU(e,r)}}))}return t.toJSON=function(){return"("+e.map(WP).join(", ")+")"},t},value:function(e){function t(t){return t===e}return t.toJSON=function(){return e},t}};function rU(e){if(XP.String(e))return"?"===e[0]?nU.maybe(e.slice(1)):XP[e]||nU.quacksLike(e);if(e&&XP.Object(e)){if(XP.Array(e)){if(1!==e.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return nU.arrayOf(e[0])}return nU.object(e)}return XP.Function(e)?e:nU.value(e)}function iU(e,t,n,r){if(XP.Function(e)){if(e(t,n))return!0;throw new ZP(r||e,t)}return iU(rU(e),t,n)}for(var oU in nU.oneOf=nU.anyOf,XP)iU[oU]=XP[oU];for(oU in nU)iU[oU]=nU[oU];var aU=YP;for(oU in aU)iU[oU]=aU[oU];iU.compile=rU,iU.TfTypeError=ZP,iU.TfPropertyTypeError=$P;var sU=iU;!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.Network=e.ECPoint=e.Satoshi=e.Signer=e.BIP32Path=e.UInt31=e.isPoint=e.typeforce=void 0;const t=qo;e.typeforce=sU;const n=t.Buffer.alloc(32,0),r=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");e.isPoint=function(e){if(!t.Buffer.isBuffer(e))return!1;if(e.length<33)return!1;const i=e[0],o=e.slice(1,33);if(0===o.compare(n))return!1;if(o.compare(r)>=0)return!1;if((2===i||3===i)&&33===e.length)return!0;const a=e.slice(33);return 0!==a.compare(n)&&!(a.compare(r)>=0)&&4===i&&65===e.length};const i=Math.pow(2,31)-1;function o(t){return e.typeforce.String(t)&&!!t.match(/^(m\/)?(\d+'?\/)*\d+'?$/)}e.UInt31=function(t){return e.typeforce.UInt32(t)&&t<=i},e.BIP32Path=o,o.toJSON=()=>"BIP32 derivation path",e.Signer=function(t){return(e.typeforce.Buffer(t.publicKey)||"function"==typeof t.getPublicKey)&&"function"==typeof t.sign},e.Satoshi=function(t){return e.typeforce.UInt53(t)&&t<=21e14},e.ECPoint=e.typeforce.quacksLike("Point"),e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf}(EP),Object.defineProperty(BP,"__esModule",{value:!0}),BP.encode=BP.decode=void 0;const lU=pP,uU=EP,{typeforce:AU}=uU,cU=ao.alloc(1,0);function hU(e){let t=0;for(;0===e[t];)++t;return t===e.length?cU:128&(e=e.slice(t))[0]?ao.concat([cU,e],1+e.length):e}function fU(e){0===e[0]&&(e=e.slice(1));const t=ao.alloc(32,0),n=Math.max(0,32-e.length);return e.copy(t,n),t}BP.decode=function(e){const t=e.readUInt8(e.length-1),n=-129&t;if(n<=0||n>=4)throw new Error("Invalid hashType "+t);const r=lU.decode(e.slice(0,-1)),i=fU(r.r),o=fU(r.s);return{signature:ao.concat([i,o],64),hashType:t}},BP.encode=function(e,t){AU({signature:uU.BufferN(64),hashType:uU.UInt8},{signature:e,hashType:t});const n=-129&t;if(n<=0||n>=4)throw new Error("Invalid hashType "+t);const r=ao.allocUnsafe(1);r.writeUInt8(t,0);const i=hU(e.slice(0,32)),o=hU(e.slice(32,64));return ao.concat([lU.encode(i,o),r])},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.isPushOnly=e.OPS=void 0;const t=pP,n=gP;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return n.OPS}});const r=vP,i=bP,o=BP,a=EP,{typeforce:s}=a,l=n.OPS.OP_RESERVED;function u(e){return a.Buffer(e)||function(e){return a.Number(e)&&(e===n.OPS.OP_0||e>=n.OPS.OP_1&&e<=n.OPS.OP_16||e===n.OPS.OP_1NEGATE)}(e)}function A(e){return a.Array(e)&&e.every(u)}function c(e){return 0===e.length?n.OPS.OP_0:1===e.length?e[0]>=1&&e[0]<=16?l+e[0]:129===e[0]?n.OPS.OP_1NEGATE:void 0:void 0}function h(e){return jo(e)}function f(e){return jo(e)}function d(e){if(h(e))return e;s(a.Array,e);const t=e.reduce(((e,t)=>f(t)?1===t.length&&void 0!==c(t)?e+1:e+r.encodingLength(t.length)+t.length:e+1),0),n=ao.allocUnsafe(t);let i=0;if(e.forEach((e=>{if(f(e)){const t=c(e);if(void 0!==t)return n.writeUInt8(t,i),void(i+=1);i+=r.encode(n,e.length,i),e.copy(n,i),i+=e.length}else n.writeUInt8(e,i),i+=1})),i!==n.length)throw new Error("Could not decode chunks");return n}function p(e){if(t=e,a.Array(t))return e;var t;s(a.Buffer,e);const i=[];let o=0;for(;o<e.length;){const t=e[o];if(t>n.OPS.OP_0&&t<=n.OPS.OP_PUSHDATA4){const t=r.decode(e,o);if(null===t)return null;if(o+=t.size,o+t.number>e.length)return null;const n=e.slice(o,o+t.number);o+=t.number;const a=c(n);void 0!==a?i.push(a):i.push(n)}else i.push(t),o+=1}return i}function g(e){const t=-129&e;return t>0&&t<4}e.isPushOnly=A,e.compile=d,e.decompile=p,e.toASM=function(e){return h(e)&&(e=p(e)),e.map((e=>{if(f(e)){const t=c(e);if(void 0===t)return e.toString("hex");e=t}return n.REVERSE_OPS[e]})).join(" ")},e.fromASM=function(e){return s(a.String,e),d(e.split(" ").map((e=>void 0!==n.OPS[e]?n.OPS[e]:(s(a.Hex,e),ao.from(e,"hex")))))},e.toStack=function(e){return e=p(e),s(A,e),e.map((e=>f(e)?e:e===n.OPS.OP_0?ao.allocUnsafe(0):i.encode(e-l)))},e.isCanonicalPubKey=function(e){return a.isPoint(e)},e.isDefinedHashType=g,e.isCanonicalScriptSignature=function(e){return!!jo(e)&&!!g(e[e.length-1])&&t.check(e.slice(0,-1))},e.number=i,e.signature=o}(dP);var dU={};Object.defineProperty(dU,"__esModule",{value:!0}),dU.value=dU.prop=void 0,dU.prop=function(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const e=n.call(this);return this[t]=e,e},set(e){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:e,writable:!0})}})},dU.value=function(e){let t;return()=>(void 0!==t||(t=e()),t)},Object.defineProperty(fP,"__esModule",{value:!0}),fP.p2data=void 0;const pU=cP,gU=dP,yU=EP,mU=dU,vU=gU.OPS;fP.p2data=function(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,yU.typeforce)({network:yU.typeforce.maybe(yU.typeforce.Object),output:yU.typeforce.maybe(yU.typeforce.Buffer),data:yU.typeforce.maybe(yU.typeforce.arrayOf(yU.typeforce.Buffer))},e);const n={name:"embed",network:e.network||pU.bitcoin};if(mU.prop(n,"output",(()=>{if(e.data)return gU.compile([vU.OP_RETURN].concat(e.data))})),mU.prop(n,"data",(()=>{if(e.output)return gU.decompile(e.output).slice(1)})),t.validate&&e.output){const t=gU.decompile(e.output);if(t[0]!==vU.OP_RETURN)throw new TypeError("Output is invalid");if(!t.slice(1).every(yU.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!function(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)};var IU={};Object.defineProperty(IU,"__esModule",{value:!0}),IU.p2ms=void 0;const wU=cP,bU=dP,BU=EP,EU=dU,CU=bU.OPS,SU=CU.OP_RESERVED;function xU(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}IU.p2ms=function(e,t){if(!(e.input||e.output||e.pubkeys&&void 0!==e.m||e.signatures))throw new TypeError("Not enough data");function n(e){return bU.isCanonicalScriptSignature(e)||void 0!==(t.allowIncomplete&&e===CU.OP_0)}t=Object.assign({validate:!0},t||{}),(0,BU.typeforce)({network:BU.typeforce.maybe(BU.typeforce.Object),m:BU.typeforce.maybe(BU.typeforce.Number),n:BU.typeforce.maybe(BU.typeforce.Number),output:BU.typeforce.maybe(BU.typeforce.Buffer),pubkeys:BU.typeforce.maybe(BU.typeforce.arrayOf(BU.isPoint)),signatures:BU.typeforce.maybe(BU.typeforce.arrayOf(n)),input:BU.typeforce.maybe(BU.typeforce.Buffer)},e);const r={network:e.network||wU.bitcoin};let i=[],o=!1;function a(e){o||(o=!0,i=bU.decompile(e),r.m=i[0]-SU,r.n=i[i.length-2]-SU,r.pubkeys=i.slice(1,-2))}if(EU.prop(r,"output",(()=>{if(e.m&&r.n&&e.pubkeys)return bU.compile([].concat(SU+e.m,e.pubkeys,SU+r.n,CU.OP_CHECKMULTISIG))})),EU.prop(r,"m",(()=>{if(r.output)return a(r.output),r.m})),EU.prop(r,"n",(()=>{if(r.pubkeys)return r.pubkeys.length})),EU.prop(r,"pubkeys",(()=>{if(e.output)return a(e.output),r.pubkeys})),EU.prop(r,"signatures",(()=>{if(e.input)return bU.decompile(e.input).slice(1)})),EU.prop(r,"input",(()=>{if(e.signatures)return bU.compile([CU.OP_0].concat(e.signatures))})),EU.prop(r,"witness",(()=>{if(r.input)return[]})),EU.prop(r,"name",(()=>{if(r.m&&r.n)return`p2ms(${r.m} of ${r.n})`})),t.validate){if(e.output){if(a(e.output),!BU.typeforce.Number(i[0]))throw new TypeError("Output is invalid");if(!BU.typeforce.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==CU.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(r.m<=0||r.n>16||r.m>r.n||r.n!==i.length-3)throw new TypeError("Output is invalid");if(!r.pubkeys.every((e=>(0,BU.isPoint)(e))))throw new TypeError("Output is invalid");if(void 0!==e.m&&e.m!==r.m)throw new TypeError("m mismatch");if(void 0!==e.n&&e.n!==r.n)throw new TypeError("n mismatch");if(e.pubkeys&&!xU(e.pubkeys,r.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(void 0!==e.n&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(r.n=e.pubkeys.length,r.n<r.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<r.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>r.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==CU.OP_0)throw new TypeError("Input is invalid");if(0===r.signatures.length||!r.signatures.every(n))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!xU(e.signatures,r.signatures))throw new TypeError("Signature mismatch");if(void 0!==e.m&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(r,e)};var QU={};Object.defineProperty(QU,"__esModule",{value:!0}),QU.p2pk=void 0;const kU=cP,_U=dP,NU=EP,DU=dU,FU=_U.OPS;QU.p2pk=function(e,t){if(!(e.input||e.output||e.pubkey||e.input||e.signature))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,NU.typeforce)({network:NU.typeforce.maybe(NU.typeforce.Object),output:NU.typeforce.maybe(NU.typeforce.Buffer),pubkey:NU.typeforce.maybe(NU.isPoint),signature:NU.typeforce.maybe(_U.isCanonicalScriptSignature),input:NU.typeforce.maybe(NU.typeforce.Buffer)},e);const n=DU.value((()=>_U.decompile(e.input))),r={name:"p2pk",network:e.network||kU.bitcoin};if(DU.prop(r,"output",(()=>{if(e.pubkey)return _U.compile([e.pubkey,FU.OP_CHECKSIG])})),DU.prop(r,"pubkey",(()=>{if(e.output)return e.output.slice(1,-1)})),DU.prop(r,"signature",(()=>{if(e.input)return n()[0]})),DU.prop(r,"input",(()=>{if(e.signature)return _U.compile([e.signature])})),DU.prop(r,"witness",(()=>{if(r.input)return[]})),t.validate){if(e.output){if(e.output[e.output.length-1]!==FU.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,NU.isPoint)(r.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(r.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(r.input))throw new TypeError("Signature mismatch");if(e.input){if(1!==n().length)throw new TypeError("Input is invalid");if(!_U.isCanonicalScriptSignature(r.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(r,e)};var PU={},UU={},MU={exports:{}},LU={},TU=ji(sc),RU=TU.EventEmitter;function OU(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function HU(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var KU=qo.Buffer,jU=AI.inspect,GU=jU&&jU.custom||"inspect";function qU(e,t,n){KU.prototype.copy.call(e,t,n)}var VU=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}var t;return t=[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return KU.alloc(0);for(var t=KU.allocUnsafe(e>>>0),n=this.head,r=0;n;)qU(n.data,t,r),r+=n.data.length,n=n.next;return t}},{key:"consume",value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,o=e>i.length?i.length:e;if(o===i.length?r+=i:r+=i.slice(0,e),0==(e-=o)){o===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++n}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=KU.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,o=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,o),0==(e-=o)){o===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(o));break}++r}return this.length-=r,t}},{key:GU,value:function(e,t){return jU(this,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?OU(Object(n),!0).forEach((function(t){HU(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):OU(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},t,{depth:0,customInspect:!1}))}}],t&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}();function zU(e,t){YU(e,t),JU(e)}function JU(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function YU(e,t){e.emit("error",t)}var XU={destroy:function(e,t){var n=this,r=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return r||i?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,ru(YU,this,e)):ru(YU,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!t&&e?n._writableState?n._writableState.errorEmitted?ru(JU,n):(n._writableState.errorEmitted=!0,ru(zU,n,e)):ru(zU,n,e):t?(ru(JU,n),t(e)):ru(JU,n)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit("error",t)}},WU={},ZU={};function $U(e,t,n){n||(n=Error);var r=function(e){var n,r;function i(n,r,i){return e.call(this,function(e,n,r){return"string"==typeof t?t:t(e,n,r)}(n,r,i))||this}return r=e,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,n.__proto__=r,i}(n);r.prototype.name=n.name,r.prototype.code=e,ZU[e]=r}function eM(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map((function(e){return String(e)})),n>2?"one of ".concat(t," ").concat(e.slice(0,n-1).join(", "),", or ")+e[n-1]:2===n?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}$U("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),$U("ERR_INVALID_ARG_TYPE",(function(e,t,n){var r,i,o;if("string"==typeof t&&(i="not ",t.substr(0,i.length)===i)?(r="must not be",t=t.replace(/^not /,"")):r="must be",function(e,t,n){return(void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}(e," argument"))o="The ".concat(e," ").concat(r," ").concat(eM(t,"type"));else{var a=function(e,t,n){return"number"!=typeof n&&(n=0),!(n+".".length>e.length)&&-1!==e.indexOf(".",n)}(e)?"property":"argument";o='The "'.concat(e,'" ').concat(a," ").concat(r," ").concat(eM(t,"type"))}return o+". Received type ".concat(typeof n)}),TypeError),$U("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),$U("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),$U("ERR_STREAM_PREMATURE_CLOSE","Premature close"),$U("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),$U("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),$U("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),$U("ERR_STREAM_WRITE_AFTER_END","write after end"),$U("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),$U("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),$U("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),WU.codes=ZU;var tM=WU.codes.ERR_INVALID_OPT_VALUE,nM=function(e,t,n,r){var i=function(e,t,n){return null!=e.highWaterMark?e.highWaterMark:t?e[n]:null}(t,r,n);if(null!=i){if(!isFinite(i)||Math.floor(i)!==i||i<0)throw new tM(r?n:"highWaterMark",i);return Math.floor(i)}return e.objectMode?16:16384},rM={},iM=F_.exports.Buffer,oM=iM.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function aM(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(iM.isEncoding===oM||!oM(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=uM,this.end=AM,t=4;break;case"utf8":this.fillLast=lM,t=4;break;case"base64":this.text=cM,this.end=hM,t=3;break;default:return this.write=fM,void(this.end=dM)}this.lastNeed=0,this.lastTotal=0,this.lastChar=iM.allocUnsafe(t)}function sM(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function lM(e){var t=this.lastTotal-this.lastNeed,n=function(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function uM(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function AM(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function cM(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function hM(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function fM(e){return e.toString(this.encoding)}function dM(e){return e&&e.length?this.write(e):""}rM.StringDecoder=aM,aM.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},aM.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},aM.prototype.text=function(e,t){var n=function(e,t,n){var r=t.length-1;if(r<n)return 0;var i=sM(t[r]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--r<n||-2===i?0:(i=sM(t[r]))>=0?(i>0&&(e.lastNeed=i-2),i):--r<n||-2===i?0:(i=sM(t[r]))>=0?(i>0&&(2===i?i=0:e.lastNeed=i-3),i):0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)},aM.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};var pM=WU.codes.ERR_STREAM_PREMATURE_CLOSE;function gM(){}var yM,mM=function e(t,n,r){if("function"==typeof n)return e(t,null,n);n||(n={}),r=function(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.apply(this,r)}}}(r||gM);var i=n.readable||!1!==n.readable&&t.readable,o=n.writable||!1!==n.writable&&t.writable,a=function(){t.writable||l()},s=t._writableState&&t._writableState.finished,l=function(){o=!1,s=!0,i||r.call(t)},u=t._readableState&&t._readableState.endEmitted,A=function(){i=!1,u=!0,o||r.call(t)},c=function(e){r.call(t,e)},h=function(){var e;return i&&!u?(t._readableState&&t._readableState.ended||(e=new pM),r.call(t,e)):o&&!s?(t._writableState&&t._writableState.ended||(e=new pM),r.call(t,e)):void 0},f=function(){t.req.on("finish",l)};return function(e){return e.setHeader&&"function"==typeof e.abort}(t)?(t.on("complete",l),t.on("abort",h),t.req?f():t.on("request",f)):o&&!t._writableState&&(t.on("end",a),t.on("close",a)),t.on("end",A),t.on("finish",l),!1!==n.error&&t.on("error",c),t.on("close",h),function(){t.removeListener("complete",l),t.removeListener("abort",h),t.removeListener("request",f),t.req&&t.req.removeListener("finish",l),t.removeListener("end",a),t.removeListener("close",a),t.removeListener("finish",l),t.removeListener("end",A),t.removeListener("error",c),t.removeListener("close",h)}};function vM(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var IM=mM,wM=Symbol("lastResolve"),bM=Symbol("lastReject"),BM=Symbol("error"),EM=Symbol("ended"),CM=Symbol("lastPromise"),SM=Symbol("handlePromise"),xM=Symbol("stream");function QM(e,t){return{value:e,done:t}}function kM(e){var t=e[wM];if(null!==t){var n=e[xM].read();null!==n&&(e[CM]=null,e[wM]=null,e[bM]=null,t(QM(n,!1)))}}function _M(e){ru(kM,e)}var NM=Object.getPrototypeOf((function(){})),DM=Object.setPrototypeOf((yM={get stream(){return this[xM]},next:function(){var e=this,t=this[BM];if(null!==t)return Promise.reject(t);if(this[EM])return Promise.resolve(QM(void 0,!0));if(this[xM].destroyed)return new Promise((function(t,n){ru((function(){e[BM]?n(e[BM]):t(QM(void 0,!0))}))}));var n,r=this[CM];if(r)n=new Promise(function(e,t){return function(n,r){e.then((function(){t[EM]?n(QM(void 0,!0)):t[SM](n,r)}),r)}}(r,this));else{var i=this[xM].read();if(null!==i)return Promise.resolve(QM(i,!1));n=new Promise(this[SM])}return this[CM]=n,n}},vM(yM,Symbol.asyncIterator,(function(){return this})),vM(yM,"return",(function(){var e=this;return new Promise((function(t,n){e[xM].destroy(null,(function(e){e?n(e):t(QM(void 0,!0))}))}))})),yM),NM),FM=function(e){var t,n=Object.create(DM,(vM(t={},xM,{value:e,writable:!0}),vM(t,wM,{value:null,writable:!0}),vM(t,bM,{value:null,writable:!0}),vM(t,BM,{value:null,writable:!0}),vM(t,EM,{value:e._readableState.endEmitted,writable:!0}),vM(t,SM,{value:function(e,t){var r=n[xM].read();r?(n[CM]=null,n[wM]=null,n[bM]=null,e(QM(r,!1))):(n[wM]=e,n[bM]=t)},writable:!0}),t));return n[CM]=null,IM(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[bM];return null!==t&&(n[CM]=null,n[wM]=null,n[bM]=null,t(e)),void(n[BM]=e)}var r=n[wM];null!==r&&(n[CM]=null,n[wM]=null,n[bM]=null,r(QM(void 0,!0))),n[EM]=!0})),e.on("readable",_M.bind(null,n)),n},PM=function(){throw new Error("Readable.from is not available in the browser")};const UM=LU;UM.Readable=nL,nL.ReadableState=tL,TU.EventEmitter;var MM,LM=function(e,t){return e.listeners(t).length},TM=RU,RM=qo.Buffer,OM=Ki.Uint8Array||function(){},HM=AI;MM=HM&&HM.debuglog?HM.debuglog("stream"):function(){};var KM,jM,GM,qM=VU,VM=XU,zM=nM,JM=WU.codes,YM=JM.ERR_INVALID_ARG_TYPE,XM=JM.ERR_STREAM_PUSH_AFTER_EOF,WM=JM.ERR_METHOD_NOT_IMPLEMENTED,ZM=JM.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;Ow.exports(nL,TM);var $M=VM.errorOrDestroy,eL=["error","close","destroy","pause","resume"];function tL(e,t,n){e=e||{},"boolean"!=typeof n&&(n=t instanceof UM.Duplex),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=zM(this,e,"readableHighWaterMark",n),this.buffer=new qM,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(KM||(KM=rM.StringDecoder),this.decoder=new KM(e.encoding),this.encoding=e.encoding)}function nL(e){if(!(this instanceof nL))return new nL(e);var t=this instanceof UM.Duplex;this._readableState=new tL(e,this,t),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),TM.call(this)}function rL(e,t,n,r,i){MM("readableAddChunk",t);var o,a=e._readableState;if(null===t)a.reading=!1,function(e,t){if(MM("onEofChunk"),!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?aL(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,sL(e)))}}(e,a);else if(i||(o=function(e,t){var n,r;return r=t,RM.isBuffer(r)||r instanceof OM||"string"==typeof t||void 0===t||e.objectMode||(n=new YM("chunk",["string","Buffer","Uint8Array"],t)),n}(a,t)),o)$M(e,o);else if(a.objectMode||t&&t.length>0)if("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===RM.prototype||(t=function(e){return RM.from(e)}(t)),r)a.endEmitted?$M(e,new ZM):iL(e,a,t,!0);else if(a.ended)$M(e,new XM);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!n?(t=a.decoder.write(t),a.objectMode||0!==t.length?iL(e,a,t,!1):lL(e,a)):iL(e,a,t,!1)}else r||(a.reading=!1,lL(e,a));return!a.ended&&(a.length<a.highWaterMark||0===a.length)}function iL(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&aL(e)),lL(e,t)}function oL(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function aL(e){var t=e._readableState;MM("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(MM("emitReadable",t.flowing),t.emittedReadable=!0,ru(sL,e))}function sL(e){var t=e._readableState;MM("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,fL(e)}function lL(e,t){t.readingMore||(t.readingMore=!0,ru(uL,e,t))}function uL(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var n=t.length;if(MM("maybeReadMore read 0"),e.read(0),n===t.length)break}t.readingMore=!1}function AL(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function cL(e){MM("readable nexttick read 0"),e.read(0)}function hL(e,t){MM("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),fL(e),t.flowing&&!t.reading&&e.read(0)}function fL(e){var t=e._readableState;for(MM("flow",t.flowing);t.flowing&&null!==e.read(););}function dL(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n}function pL(e){var t=e._readableState;MM("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,ru(gL,t,e))}function gL(e,t){if(MM("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}function yL(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}Object.defineProperty(nL.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),nL.prototype.destroy=VM.destroy,nL.prototype._undestroy=VM.undestroy,nL.prototype._destroy=function(e,t){t(e)},nL.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=RM.from(e,t),t=""),n=!0),rL(this,e,t,!1,n)},nL.prototype.unshift=function(e){return rL(this,e,null,!0,!1)},nL.prototype.isPaused=function(){return!1===this._readableState.flowing},nL.prototype.setEncoding=function(e){KM||(KM=rM.StringDecoder);var t=new KM(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,r="";null!==n;)r+=t.write(n.data),n=n.next;return this._readableState.buffer.clear(),""!==r&&this._readableState.buffer.push(r),this._readableState.length=r.length,this},nL.prototype.read=function(e){MM("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return MM("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?pL(this):aL(this),null;if(0===(e=oL(e,t))&&t.ended)return 0===t.length&&pL(this),null;var r,i=t.needReadable;return MM("need readable",i),(0===t.length||t.length-e<t.highWaterMark)&&MM("length less than watermark",i=!0),t.ended||t.reading?MM("reading or ended",i=!1):i&&(MM("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=oL(n,t))),null===(r=e>0?dL(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&pL(this)),null!==r&&this.emit("data",r),r},nL.prototype._read=function(e){$M(this,new WM("_read()"))},nL.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e)}r.pipesCount+=1,MM("pipe count=%d opts=%j",r.pipesCount,t);var i=t&&!1===t.end||e===gu.stdout||e===gu.stderr?h:o;function o(){MM("onend"),e.end()}r.endEmitted?ru(i):n.once("end",i),e.on("unpipe",(function t(i,f){MM("onunpipe"),i===n&&f&&!1===f.hasUnpiped&&(f.hasUnpiped=!0,MM("cleanup"),e.removeListener("close",A),e.removeListener("finish",c),e.removeListener("drain",a),e.removeListener("error",u),e.removeListener("unpipe",t),n.removeListener("end",o),n.removeListener("end",h),n.removeListener("data",l),s=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||a())}));var a=function(e){return function(){var t=e._readableState;MM("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&LM(e,"data")&&(t.flowing=!0,fL(e))}}(n);e.on("drain",a);var s=!1;function l(t){MM("ondata");var i=e.write(t);MM("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==yL(r.pipes,e))&&!s&&(MM("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause())}function u(t){MM("onerror",t),h(),e.removeListener("error",u),0===LM(e,"error")&&$M(e,t)}function A(){e.removeListener("finish",c),h()}function c(){MM("onfinish"),e.removeListener("close",A),h()}function h(){MM("unpipe"),n.unpipe(e)}return n.on("data",l),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}(e,"error",u),e.once("close",A),e.once("finish",c),e.emit("pipe",n),r.flowing||(MM("pipe resume"),n.resume()),e},nL.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)r[o].emit("unpipe",this,{hasUnpiped:!1});return this}var a=yL(t.pipes,e);return-1===a||(t.pipes.splice(a,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n)),this},nL.prototype.on=function(e,t){var n=TM.prototype.on.call(this,e,t),r=this._readableState;return"data"===e?(r.readableListening=this.listenerCount("readable")>0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,MM("on readable",r.length,r.reading),r.length?aL(this):r.reading||ru(cL,this))),n},nL.prototype.addListener=nL.prototype.on,nL.prototype.removeListener=function(e,t){var n=TM.prototype.removeListener.call(this,e,t);return"readable"===e&&ru(AL,this),n},nL.prototype.removeAllListeners=function(e){var t=TM.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||ru(AL,this),t},nL.prototype.resume=function(){var e=this._readableState;return e.flowing||(MM("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,ru(hL,e,t))}(this,e)),e.paused=!1,this},nL.prototype.pause=function(){return MM("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(MM("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},nL.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(MM("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){MM("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<eL.length;o++)e.on(eL[o],this.emit.bind(this,eL[o]));return this._read=function(t){MM("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(nL.prototype[Symbol.asyncIterator]=function(){return void 0===jM&&(jM=FM),jM(this)}),Object.defineProperty(nL.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(nL.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(nL.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),nL._fromList=dL,Object.defineProperty(nL.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(nL.from=function(e,t){return void 0===GM&&(GM=PM),GM(nL,e,t)});function mL(e){try{if(!Ki.localStorage)return!1}catch(e){return!1}var t=Ki.localStorage[e];return null!=t&&"true"===String(t).toLowerCase()}const vL=LU;function IL(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,n){var r=e.entry;for(e.entry=null;r;){var i=r.callback;t.pendingcb--,i(undefined),r=r.next}t.corkedRequestsFree.next=e}(t,e)}}vL.Writable=OL,OL.WritableState=RL;var wL,bL=function(e,t){if(mL("noDeprecation"))return e;var n=!1;return function(){if(!n){if(mL("throwDeprecation"))throw new Error(t);mL("traceDeprecation")?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}},BL=RU,EL=qo.Buffer,CL=Ki.Uint8Array||function(){},SL=XU,xL=nM,QL=WU.codes,kL=QL.ERR_INVALID_ARG_TYPE,_L=QL.ERR_METHOD_NOT_IMPLEMENTED,NL=QL.ERR_MULTIPLE_CALLBACK,DL=QL.ERR_STREAM_CANNOT_PIPE,FL=QL.ERR_STREAM_DESTROYED,PL=QL.ERR_STREAM_NULL_VALUES,UL=QL.ERR_STREAM_WRITE_AFTER_END,ML=QL.ERR_UNKNOWN_ENCODING,LL=SL.errorOrDestroy;function TL(){}function RL(e,t,n){e=e||{},"boolean"!=typeof n&&(n=t instanceof vL.Duplex),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=xL(this,e,"writableHighWaterMark",n),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var r=!1===e.decodeStrings;this.decodeStrings=!r,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if("function"!=typeof i)throw new NL;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),t)!function(e,t,n,r,i){--t.pendingcb,n?(ru(i,r),ru(VL,e,t),e._writableState.errorEmitted=!0,LL(e,r)):(i(r),e._writableState.errorEmitted=!0,LL(e,r),VL(e,t))}(e,n,r,t,i);else{var o=GL(n)||e.destroyed;o||n.corked||n.bufferProcessing||!n.bufferedRequest||jL(e,n),r?ru(KL,e,n,o,i):KL(e,n,o,i)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new IL(this)}function OL(e){var t=this instanceof vL.Duplex;if(!t&&!wL.call(OL,this))return new OL(e);this._writableState=new RL(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),BL.call(this)}function HL(e,t,n,r,i,o,a){t.writelen=r,t.writecb=a,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new FL("write")):n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function KL(e,t,n,r){n||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,r(),VL(e,t)}function jL(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,i=new Array(r),o=t.corkedRequestsFree;o.entry=n;for(var a=0,s=!0;n;)i[a]=n,n.isBuf||(s=!1),n=n.next,a+=1;i.allBuffers=s,HL(e,t,!0,t.length,i,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new IL(t),t.bufferedRequestCount=0}else{for(;n;){var l=n.chunk,u=n.encoding,A=n.callback;if(HL(e,t,!1,t.objectMode?1:l.length,l,u,A),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function GL(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function qL(e,t){e._final((function(n){t.pendingcb--,n&&LL(e,n),t.prefinished=!0,e.emit("prefinish"),VL(e,t)}))}function VL(e,t){var n=GL(t);if(n&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,ru(qL,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}Ow.exports(OL,BL),RL.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(RL.prototype,"buffer",{get:bL((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(wL=Function.prototype[Symbol.hasInstance],Object.defineProperty(OL,Symbol.hasInstance,{value:function(e){return!!wL.call(this,e)||this===OL&&e&&e._writableState instanceof RL}})):wL=function(e){return e instanceof this},OL.prototype.pipe=function(){LL(this,new DL)},OL.prototype.write=function(e,t,n){var r,i=this._writableState,o=!1,a=!i.objectMode&&(r=e,EL.isBuffer(r)||r instanceof CL);return a&&!EL.isBuffer(e)&&(e=function(e){return EL.from(e)}(e)),"function"==typeof t&&(n=t,t=null),a?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=TL),i.ending?function(e,t){var n=new UL;LL(e,n),ru(t,n)}(this,n):(a||function(e,t,n,r){var i;return null===n?i=new PL:"string"==typeof n||t.objectMode||(i=new kL("chunk",["string","Buffer"],n)),!i||(LL(e,i),ru(r,i),!1)}(this,i,e,n))&&(i.pendingcb++,o=function(e,t,n,r,i,o){if(!n){var a=function(e,t,n){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=EL.from(t,n)),t}(t,r,i);r!==a&&(n=!0,i="buffer",r=a)}var s=t.objectMode?1:r.length;t.length+=s;var l=t.length<t.highWaterMark;if(l||(t.needDrain=!0),t.writing||t.corked){var u=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:o,next:null},u?u.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else HL(e,t,!1,s,r,i,o);return l}(this,i,a,e,t,n)),o},OL.prototype.cork=function(){this._writableState.corked++},OL.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||jL(this,e))},OL.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new ML(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(OL.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(OL.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),OL.prototype._write=function(e,t,n){n(new _L("_write()"))},OL.prototype._writev=null,OL.prototype.end=function(e,t,n){var r=this._writableState;return"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||function(e,t,n){t.ending=!0,VL(e,t),n&&(t.finished?ru(n):e.once("finish",n)),t.ended=!0,e.writable=!1}(this,r,n),this},Object.defineProperty(OL.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(OL.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),OL.prototype.destroy=SL.destroy,OL.prototype._undestroy=SL.undestroy,OL.prototype._destroy=function(e,t){t(e)};var zL=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};const JL=LU;JL.Duplex=ZL,Ow.exports(ZL,JL.Readable);for(var YL=zL(JL.Writable.prototype),XL=0;XL<YL.length;XL++){var WL=YL[XL];ZL.prototype[WL]||(ZL.prototype[WL]=JL.Writable.prototype[WL])}function ZL(e){if(!(this instanceof ZL))return new ZL(e);JL.Readable.call(this,e),JL.Writable.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",$L)))}function $L(){this._writableState.ended||ru(eT,this)}function eT(e){e.end()}Object.defineProperty(ZL.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(ZL.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(ZL.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(ZL.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&this._readableState.destroyed&&this._writableState.destroyed},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}});const tT=LU;tT.Transform=lT;var nT=WU.codes,rT=nT.ERR_METHOD_NOT_IMPLEMENTED,iT=nT.ERR_MULTIPLE_CALLBACK,oT=nT.ERR_TRANSFORM_ALREADY_TRANSFORMING,aT=nT.ERR_TRANSFORM_WITH_LENGTH_0;function sT(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(null===r)return this.emit("error",new iT);n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function lT(e){if(!(this instanceof lT))return new lT(e);tT.Duplex.call(this,e),this._transformState={afterTransform:sT.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",uT)}function uT(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?AT(this,null,null):this._flush((function(t,n){AT(e,t,n)}))}function AT(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new aT;if(e._transformState.transforming)throw new oT;return e.push(null)}Ow.exports(lT,tT.Duplex),lT.prototype.push=function(e,t){return this._transformState.needTransform=!1,tT.Duplex.prototype.push.call(this,e,t)},lT.prototype._transform=function(e,t,n){n(new rT("_transform()"))},lT.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},lT.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},lT.prototype._destroy=function(e,t){tT.Duplex.prototype._destroy.call(this,e,(function(e){t(e)}))};const cT=LU;function hT(e){if(!(this instanceof hT))return new hT(e);Transform.call(this,e)}var fT;cT.PassThrough=hT,Ow.exports(hT,cT.Transform),hT.prototype._transform=function(e,t,n){n(null,e)};var dT=WU.codes,pT=dT.ERR_MISSING_ARGS,gT=dT.ERR_STREAM_DESTROYED;function yT(e){if(e)throw e}function mT(e,t,n,r){r=function(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}(r);var i=!1;e.on("close",(function(){i=!0})),void 0===fT&&(fT=mM),fT(e,{readable:t,writable:n},(function(e){if(e)return r(e);i=!0,r()}));var o=!1;return function(t){if(!i&&!o)return o=!0,function(e){return e.setHeader&&"function"==typeof e.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void r(t||new gT("pipe"))}}function vT(e){e()}function IT(e,t){return e.pipe(t)}function wT(e){return e.length?"function"!=typeof e[e.length-1]?yT:e.pop():yT}var bT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r,i=wT(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new pT("streams");var o=t.map((function(e,n){var a=n<t.length-1;return mT(e,a,n>0,(function(e){r||(r=e),e&&o.forEach(vT),a||(o.forEach(vT),i(r))}))}));return t.reduce(IT)};!function(e,t){const n=LU;(t=MU.exports=n.Readable).Stream=n.Readable,t.Readable=n.Readable,t.Writable=n.Writable,t.Duplex=n.Duplex,t.Transform=n.Transform,t.PassThrough=n.PassThrough,t.finished=mM,t.pipeline=bT}(0,MU.exports);var BT=F_.exports.Buffer,ET=MU.exports;function CT(e){ET.Stream.Transform.call(this),this._block=BT.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}(0,Ow.exports)(CT,ET.Stream.Transform),CT.prototype._transform=function(e,t,n){var r=null;try{this.update(e,t)}catch(e){r=e}n(r)},CT.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(e){t=e}e(t)},CT.prototype.update=function(e,t){if(function(e,t){if(!BT.isBuffer(e)&&"string"!=typeof e)throw new TypeError("Data must be a string or a buffer")}(e),this._finalized)throw new Error("Digest already called");BT.isBuffer(e)||(e=BT.from(e,t));for(var n=this._block,r=0;this._blockOffset+e.length-r>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)n[i++]=e[r++];this._update(),this._blockOffset=0}for(;r<e.length;)n[this._blockOffset++]=e[r++];for(var o=0,a=8*e.length;a>0;++o)this._length[o]+=a,(a=this._length[o]/4294967296|0)>0&&(this._length[o]-=4294967296*a);return this},CT.prototype._update=function(){throw new Error("_update is not implemented")},CT.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();void 0!==e&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var n=0;n<4;++n)this._length[n]=0;return t},CT.prototype._digest=function(){throw new Error("_digest is not implemented")};var ST=CT,xT=Ow.exports,QT=ST,kT=F_.exports.Buffer,_T=new Array(16);function NT(){QT.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}function DT(e,t){return e<<t|e>>>32-t}function FT(e,t,n,r,i,o,a){return DT(e+(t&n|~t&r)+i+o|0,a)+t|0}function PT(e,t,n,r,i,o,a){return DT(e+(t&r|n&~r)+i+o|0,a)+t|0}function UT(e,t,n,r,i,o,a){return DT(e+(t^n^r)+i+o|0,a)+t|0}function MT(e,t,n,r,i,o,a){return DT(e+(n^(t|~r))+i+o|0,a)+t|0}xT(NT,QT),NT.prototype._update=function(){for(var e=_T,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var n=this._a,r=this._b,i=this._c,o=this._d;n=FT(n,r,i,o,e[0],3614090360,7),o=FT(o,n,r,i,e[1],3905402710,12),i=FT(i,o,n,r,e[2],606105819,17),r=FT(r,i,o,n,e[3],3250441966,22),n=FT(n,r,i,o,e[4],4118548399,7),o=FT(o,n,r,i,e[5],1200080426,12),i=FT(i,o,n,r,e[6],2821735955,17),r=FT(r,i,o,n,e[7],4249261313,22),n=FT(n,r,i,o,e[8],1770035416,7),o=FT(o,n,r,i,e[9],2336552879,12),i=FT(i,o,n,r,e[10],4294925233,17),r=FT(r,i,o,n,e[11],2304563134,22),n=FT(n,r,i,o,e[12],1804603682,7),o=FT(o,n,r,i,e[13],4254626195,12),i=FT(i,o,n,r,e[14],2792965006,17),n=PT(n,r=FT(r,i,o,n,e[15],1236535329,22),i,o,e[1],4129170786,5),o=PT(o,n,r,i,e[6],3225465664,9),i=PT(i,o,n,r,e[11],643717713,14),r=PT(r,i,o,n,e[0],3921069994,20),n=PT(n,r,i,o,e[5],3593408605,5),o=PT(o,n,r,i,e[10],38016083,9),i=PT(i,o,n,r,e[15],3634488961,14),r=PT(r,i,o,n,e[4],3889429448,20),n=PT(n,r,i,o,e[9],568446438,5),o=PT(o,n,r,i,e[14],3275163606,9),i=PT(i,o,n,r,e[3],4107603335,14),r=PT(r,i,o,n,e[8],1163531501,20),n=PT(n,r,i,o,e[13],2850285829,5),o=PT(o,n,r,i,e[2],4243563512,9),i=PT(i,o,n,r,e[7],1735328473,14),n=UT(n,r=PT(r,i,o,n,e[12],2368359562,20),i,o,e[5],4294588738,4),o=UT(o,n,r,i,e[8],2272392833,11),i=UT(i,o,n,r,e[11],1839030562,16),r=UT(r,i,o,n,e[14],4259657740,23),n=UT(n,r,i,o,e[1],2763975236,4),o=UT(o,n,r,i,e[4],1272893353,11),i=UT(i,o,n,r,e[7],4139469664,16),r=UT(r,i,o,n,e[10],3200236656,23),n=UT(n,r,i,o,e[13],681279174,4),o=UT(o,n,r,i,e[0],3936430074,11),i=UT(i,o,n,r,e[3],3572445317,16),r=UT(r,i,o,n,e[6],76029189,23),n=UT(n,r,i,o,e[9],3654602809,4),o=UT(o,n,r,i,e[12],3873151461,11),i=UT(i,o,n,r,e[15],530742520,16),n=MT(n,r=UT(r,i,o,n,e[2],3299628645,23),i,o,e[0],4096336452,6),o=MT(o,n,r,i,e[7],1126891415,10),i=MT(i,o,n,r,e[14],2878612391,15),r=MT(r,i,o,n,e[5],4237533241,21),n=MT(n,r,i,o,e[12],1700485571,6),o=MT(o,n,r,i,e[3],2399980690,10),i=MT(i,o,n,r,e[10],4293915773,15),r=MT(r,i,o,n,e[1],2240044497,21),n=MT(n,r,i,o,e[8],1873313359,6),o=MT(o,n,r,i,e[15],4264355552,10),i=MT(i,o,n,r,e[6],2734768916,15),r=MT(r,i,o,n,e[13],1309151649,21),n=MT(n,r,i,o,e[4],4149444226,6),o=MT(o,n,r,i,e[11],3174756917,10),i=MT(i,o,n,r,e[2],718787259,15),r=MT(r,i,o,n,e[9],3951481745,21),this._a=this._a+n|0,this._b=this._b+r|0,this._c=this._c+i|0,this._d=this._d+o|0},NT.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=kT.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};var LT=NT,TT=qo.Buffer,RT=Ow.exports,OT=ST,HT=new Array(16),KT=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],jT=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],GT=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],qT=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],VT=[0,1518500249,1859775393,2400959708,2840853838],zT=[1352829926,1548603684,1836072691,2053994217,0];function JT(){OT.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}function YT(e,t){return e<<t|e>>>32-t}function XT(e,t,n,r,i,o,a,s){return YT(e+(t^n^r)+o+a|0,s)+i|0}function WT(e,t,n,r,i,o,a,s){return YT(e+(t&n|~t&r)+o+a|0,s)+i|0}function ZT(e,t,n,r,i,o,a,s){return YT(e+((t|~n)^r)+o+a|0,s)+i|0}function $T(e,t,n,r,i,o,a,s){return YT(e+(t&r|n&~r)+o+a|0,s)+i|0}function eR(e,t,n,r,i,o,a,s){return YT(e+(t^(n|~r))+o+a|0,s)+i|0}RT(JT,OT),JT.prototype._update=function(){for(var e=HT,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);for(var n=0|this._a,r=0|this._b,i=0|this._c,o=0|this._d,a=0|this._e,s=0|this._a,l=0|this._b,u=0|this._c,A=0|this._d,c=0|this._e,h=0;h<80;h+=1){var f,d;h<16?(f=XT(n,r,i,o,a,e[KT[h]],VT[0],GT[h]),d=eR(s,l,u,A,c,e[jT[h]],zT[0],qT[h])):h<32?(f=WT(n,r,i,o,a,e[KT[h]],VT[1],GT[h]),d=$T(s,l,u,A,c,e[jT[h]],zT[1],qT[h])):h<48?(f=ZT(n,r,i,o,a,e[KT[h]],VT[2],GT[h]),d=ZT(s,l,u,A,c,e[jT[h]],zT[2],qT[h])):h<64?(f=$T(n,r,i,o,a,e[KT[h]],VT[3],GT[h]),d=WT(s,l,u,A,c,e[jT[h]],zT[3],qT[h])):(f=eR(n,r,i,o,a,e[KT[h]],VT[4],GT[h]),d=XT(s,l,u,A,c,e[jT[h]],zT[4],qT[h])),n=a,a=o,o=YT(i,10),i=r,r=f,s=c,c=A,A=YT(u,10),u=l,l=d}var p=this._b+i+A|0;this._b=this._c+o+c|0,this._c=this._d+a+s|0,this._d=this._e+n+l|0,this._e=this._a+r+u|0,this._a=p},JT.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=TT.alloc?TT.alloc(20):new TT(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};var tR=JT,nR={exports:{}},rR=F_.exports.Buffer;function iR(e,t){this._block=rR.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}iR.prototype.update=function(e,t){"string"==typeof e&&(t=t||"utf8",e=rR.from(e,t));for(var n=this._block,r=this._blockSize,i=e.length,o=this._len,a=0;a<i;){for(var s=o%r,l=Math.min(i-a,r-s),u=0;u<l;u++)n[s+u]=e[a+u];a+=l,(o+=l)%r==0&&this._update(n)}return this._len+=i,this},iR.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var n=8*this._len;if(n<=4294967295)this._block.writeUInt32BE(n,this._blockSize-4);else{var r=(4294967295&n)>>>0,i=(n-r)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(r,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},iR.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var oR=iR,aR=Ow.exports,sR=oR,lR=F_.exports.Buffer,uR=[1518500249,1859775393,-1894007588,-899497514],AR=new Array(80);function cR(){this.init(),this._w=AR,sR.call(this,64,56)}function hR(e){return e<<30|e>>>2}function fR(e,t,n,r){return 0===e?t&n|~t&r:2===e?t&n|t&r|n&r:t^n^r}aR(cR,sR),cR.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},cR.prototype._update=function(e){for(var t,n=this._w,r=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,l=0;l<16;++l)n[l]=e.readInt32BE(4*l);for(;l<80;++l)n[l]=n[l-3]^n[l-8]^n[l-14]^n[l-16];for(var u=0;u<80;++u){var A=~~(u/20),c=0|((t=r)<<5|t>>>27)+fR(A,i,o,a)+s+n[u]+uR[A];s=a,a=o,o=hR(i),i=r,r=c}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},cR.prototype._hash=function(){var e=lR.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var dR=cR,pR=Ow.exports,gR=oR,yR=F_.exports.Buffer,mR=[1518500249,1859775393,-1894007588,-899497514],vR=new Array(80);function IR(){this.init(),this._w=vR,gR.call(this,64,56)}function wR(e){return e<<5|e>>>27}function bR(e){return e<<30|e>>>2}function BR(e,t,n,r){return 0===e?t&n|~t&r:2===e?t&n|t&r|n&r:t^n^r}pR(IR,gR),IR.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},IR.prototype._update=function(e){for(var t,n=this._w,r=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,l=0;l<16;++l)n[l]=e.readInt32BE(4*l);for(;l<80;++l)n[l]=(t=n[l-3]^n[l-8]^n[l-14]^n[l-16])<<1|t>>>31;for(var u=0;u<80;++u){var A=~~(u/20),c=wR(r)+BR(A,i,o,a)+s+n[u]+mR[A]|0;s=a,a=o,o=bR(i),i=r,r=c}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},IR.prototype._hash=function(){var e=yR.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var ER=IR,CR=Ow.exports,SR=oR,xR=F_.exports.Buffer,QR=[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],kR=new Array(64);function _R(){this.init(),this._w=kR,SR.call(this,64,56)}function NR(e,t,n){return n^e&(t^n)}function DR(e,t,n){return e&t|n&(e|t)}function FR(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function PR(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function UR(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function MR(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}CR(_R,SR),_R.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},_R.prototype._update=function(e){for(var t=this._w,n=0|this._a,r=0|this._b,i=0|this._c,o=0|this._d,a=0|this._e,s=0|this._f,l=0|this._g,u=0|this._h,A=0;A<16;++A)t[A]=e.readInt32BE(4*A);for(;A<64;++A)t[A]=MR(t[A-2])+t[A-7]+UR(t[A-15])+t[A-16]|0;for(var c=0;c<64;++c){var h=u+PR(a)+NR(a,s,l)+QR[c]+t[c]|0,f=FR(n)+DR(n,r,i)|0;u=l,l=s,s=a,a=o+h|0,o=i,i=r,r=n,n=h+f|0}this._a=n+this._a|0,this._b=r+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=a+this._e|0,this._f=s+this._f|0,this._g=l+this._g|0,this._h=u+this._h|0},_R.prototype._hash=function(){var e=xR.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var LR=_R,TR=Ow.exports,RR=LR,OR=oR,HR=F_.exports.Buffer,KR=new Array(64);function jR(){this.init(),this._w=KR,OR.call(this,64,56)}TR(jR,RR),jR.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},jR.prototype._hash=function(){var e=HR.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var GR=jR,qR=Ow.exports,VR=oR,zR=F_.exports.Buffer,JR=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],YR=new Array(160);function XR(){this.init(),this._w=YR,VR.call(this,128,112)}function WR(e,t,n){return n^e&(t^n)}function ZR(e,t,n){return e&t|n&(e|t)}function $R(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function eO(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function tO(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function nO(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function rO(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function iO(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function oO(e,t){return e>>>0<t>>>0?1:0}qR(XR,VR),XR.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},XR.prototype._update=function(e){for(var t=this._w,n=0|this._ah,r=0|this._bh,i=0|this._ch,o=0|this._dh,a=0|this._eh,s=0|this._fh,l=0|this._gh,u=0|this._hh,A=0|this._al,c=0|this._bl,h=0|this._cl,f=0|this._dl,d=0|this._el,p=0|this._fl,g=0|this._gl,y=0|this._hl,m=0;m<32;m+=2)t[m]=e.readInt32BE(4*m),t[m+1]=e.readInt32BE(4*m+4);for(;m<160;m+=2){var v=t[m-30],I=t[m-30+1],w=tO(v,I),b=nO(I,v),B=rO(v=t[m-4],I=t[m-4+1]),E=iO(I,v),C=t[m-14],S=t[m-14+1],x=t[m-32],Q=t[m-32+1],k=b+S|0,_=w+C+oO(k,b)|0;_=(_=_+B+oO(k=k+E|0,E)|0)+x+oO(k=k+Q|0,Q)|0,t[m]=_,t[m+1]=k}for(var N=0;N<160;N+=2){_=t[N],k=t[N+1];var D=ZR(n,r,i),F=ZR(A,c,h),P=$R(n,A),U=$R(A,n),M=eO(a,d),L=eO(d,a),T=JR[N],R=JR[N+1],O=WR(a,s,l),H=WR(d,p,g),K=y+L|0,j=u+M+oO(K,y)|0;j=(j=(j=j+O+oO(K=K+H|0,H)|0)+T+oO(K=K+R|0,R)|0)+_+oO(K=K+k|0,k)|0;var G=U+F|0,q=P+D+oO(G,U)|0;u=l,y=g,l=s,g=p,s=a,p=d,a=o+j+oO(d=f+K|0,f)|0,o=i,f=h,i=r,h=c,r=n,c=A,n=j+q+oO(A=K+G|0,K)|0}this._al=this._al+A|0,this._bl=this._bl+c|0,this._cl=this._cl+h|0,this._dl=this._dl+f|0,this._el=this._el+d|0,this._fl=this._fl+p|0,this._gl=this._gl+g|0,this._hl=this._hl+y|0,this._ah=this._ah+n+oO(this._al,A)|0,this._bh=this._bh+r+oO(this._bl,c)|0,this._ch=this._ch+i+oO(this._cl,h)|0,this._dh=this._dh+o+oO(this._dl,f)|0,this._eh=this._eh+a+oO(this._el,d)|0,this._fh=this._fh+s+oO(this._fl,p)|0,this._gh=this._gh+l+oO(this._gl,g)|0,this._hh=this._hh+u+oO(this._hl,y)|0},XR.prototype._hash=function(){var e=zR.allocUnsafe(64);function t(t,n,r){e.writeInt32BE(t,r),e.writeInt32BE(n,r+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var aO=XR,sO=Ow.exports,lO=aO,uO=oR,AO=F_.exports.Buffer,cO=new Array(160);function hO(){this.init(),this._w=cO,uO.call(this,128,112)}sO(hO,lO),hO.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},hO.prototype._hash=function(){var e=AO.allocUnsafe(48);function t(t,n,r){e.writeInt32BE(t,r),e.writeInt32BE(n,r+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var fO=hO,dO=nR.exports=function(e){e=e.toLowerCase();var t=dO[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t};dO.sha=dR,dO.sha1=ER,dO.sha224=GR,dO.sha256=LR,dO.sha384=fO,dO.sha512=aO;var pO=ji(dc),gO=F_.exports.Buffer,yO=LQ.Transform,mO=pO.StringDecoder;function vO(e){yO.call(this),this.hashMode="string"==typeof e,this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}(0,Ow.exports)(vO,yO),vO.prototype.update=function(e,t,n){"string"==typeof e&&(e=gO.from(e,t));var r=this._update(e);return this.hashMode?this:(n&&(r=this._toString(r,n)),r)},vO.prototype.setAutoPadding=function(){},vO.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")},vO.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")},vO.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")},vO.prototype._transform=function(e,t,n){var r;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(e){r=e}finally{n(r)}},vO.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(e){t=e}e(t)},vO.prototype._finalOrDigest=function(e){var t=this.__final()||gO.alloc(0);return e&&(t=this._toString(t,e,!0)),t},vO.prototype._toString=function(e,t,n){if(this._decoder||(this._decoder=new mO(t),this._encoding=t),this._encoding!==t)throw new Error("can't switch encodings");var r=this._decoder.write(e);return n&&(r+=this._decoder.end()),r};var IO=vO,wO=Ow.exports,bO=LT,BO=tR,EO=nR.exports,CO=IO;function SO(e){CO.call(this,"digest"),this._hash=e}wO(SO,CO),SO.prototype._update=function(e){this._hash.update(e)},SO.prototype._final=function(){return this._hash.digest()};var xO=function(e){return"md5"===(e=e.toLowerCase())?new bO:"rmd160"===e||"ripemd160"===e?new BO:new SO(EO(e))};Object.defineProperty(UU,"__esModule",{value:!0}),UU.taggedHash=UU.hash256=UU.hash160=UU.sha256=UU.sha1=UU.ripemd160=void 0;const QO=xO,kO=tR;function _O(e){try{return QO("rmd160").update(e).digest()}catch(t){try{return QO("ripemd160").update(e).digest()}catch(t){return(new kO).update(e).digest()}}}function NO(e){return QO("sha256").update(e).digest()}UU.ripemd160=_O,UU.sha1=function(e){return QO("sha1").update(e).digest()},UU.sha256=NO,UU.hash160=function(e){return _O(NO(e))},UU.hash256=function(e){return NO(NO(e))};const DO=Object.fromEntries(["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"].map((e=>{const t=NO(ao.from(e));return[e,ao.concat([t,t])]})));UU.taggedHash=function(e,t){return NO(ao.concat([DO[e],t]))};var FO=sP,PO=F_.exports.Buffer,UO=xO,MO=function(e){function t(t){var n=t.slice(0,-4),r=t.slice(-4),i=e(n);if(!(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3]))return n}return{encode:function(t){var n=e(t);return FO.encode(PO.concat([t,n],t.length+4))},decode:function(e){var n=t(FO.decode(e));if(!n)throw new Error("Invalid checksum");return n},decodeUnsafe:function(e){var n=FO.decodeUnsafe(e);if(n)return t(n)}}}((function(e){var t=UO("sha256").update(e).digest();return UO("sha256").update(t).digest()}));Object.defineProperty(PU,"__esModule",{value:!0}),PU.p2pkh=void 0;const LO=UU,TO=cP,RO=dP,OO=EP,HO=dU,KO=MO,jO=RO.OPS;PU.p2pkh=function(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,OO.typeforce)({network:OO.typeforce.maybe(OO.typeforce.Object),address:OO.typeforce.maybe(OO.typeforce.String),hash:OO.typeforce.maybe(OO.typeforce.BufferN(20)),output:OO.typeforce.maybe(OO.typeforce.BufferN(25)),pubkey:OO.typeforce.maybe(OO.isPoint),signature:OO.typeforce.maybe(RO.isCanonicalScriptSignature),input:OO.typeforce.maybe(OO.typeforce.Buffer)},e);const n=HO.value((()=>{const t=KO.decode(e.address);return{version:t.readUInt8(0),hash:t.slice(1)}})),r=HO.value((()=>RO.decompile(e.input))),i=e.network||TO.bitcoin,o={name:"p2pkh",network:i};if(HO.prop(o,"address",(()=>{if(!o.hash)return;const e=ao.allocUnsafe(21);return e.writeUInt8(i.pubKeyHash,0),o.hash.copy(e,1),KO.encode(e)})),HO.prop(o,"hash",(()=>e.output?e.output.slice(3,23):e.address?n().hash:e.pubkey||o.pubkey?LO.hash160(e.pubkey||o.pubkey):void 0)),HO.prop(o,"output",(()=>{if(o.hash)return RO.compile([jO.OP_DUP,jO.OP_HASH160,o.hash,jO.OP_EQUALVERIFY,jO.OP_CHECKSIG])})),HO.prop(o,"pubkey",(()=>{if(e.input)return r()[1]})),HO.prop(o,"signature",(()=>{if(e.input)return r()[0]})),HO.prop(o,"input",(()=>{if(e.pubkey&&e.signature)return RO.compile([e.signature,e.pubkey])})),HO.prop(o,"witness",(()=>{if(o.input)return[]})),t.validate){let t=ao.from([]);if(e.address){if(n().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==n().hash.length)throw new TypeError("Invalid address");t=n().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(25!==e.output.length||e.output[0]!==jO.OP_DUP||e.output[1]!==jO.OP_HASH160||20!==e.output[2]||e.output[23]!==jO.OP_EQUALVERIFY||e.output[24]!==jO.OP_CHECKSIG)throw new TypeError("Output is invalid");const n=e.output.slice(3,23);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.pubkey){const n=LO.hash160(e.pubkey);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.input){const n=r();if(2!==n.length)throw new TypeError("Input is invalid");if(!RO.isCanonicalScriptSignature(n[0]))throw new TypeError("Input has invalid signature");if(!(0,OO.isPoint)(n[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(n[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(n[1]))throw new TypeError("Pubkey mismatch");const i=LO.hash160(n[1]);if(t.length>0&&!t.equals(i))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)};var GO={};Object.defineProperty(GO,"__esModule",{value:!0}),GO.p2sh=void 0;const qO=UU,VO=cP,zO=dP,JO=EP,YO=dU,XO=MO,WO=zO.OPS;GO.p2sh=function(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,JO.typeforce)({network:JO.typeforce.maybe(JO.typeforce.Object),address:JO.typeforce.maybe(JO.typeforce.String),hash:JO.typeforce.maybe(JO.typeforce.BufferN(20)),output:JO.typeforce.maybe(JO.typeforce.BufferN(23)),redeem:JO.typeforce.maybe({network:JO.typeforce.maybe(JO.typeforce.Object),output:JO.typeforce.maybe(JO.typeforce.Buffer),input:JO.typeforce.maybe(JO.typeforce.Buffer),witness:JO.typeforce.maybe(JO.typeforce.arrayOf(JO.typeforce.Buffer))}),input:JO.typeforce.maybe(JO.typeforce.Buffer),witness:JO.typeforce.maybe(JO.typeforce.arrayOf(JO.typeforce.Buffer))},e);let n=e.network;n||(n=e.redeem&&e.redeem.network||VO.bitcoin);const r={network:n},i=YO.value((()=>{const t=XO.decode(e.address);return{version:t.readUInt8(0),hash:t.slice(1)}})),o=YO.value((()=>zO.decompile(e.input))),a=YO.value((()=>{const t=o(),r=t[t.length-1];return{network:n,output:r===WO.OP_FALSE?ao.from([]):r,input:zO.compile(t.slice(0,-1)),witness:e.witness||[]}}));if(YO.prop(r,"address",(()=>{if(!r.hash)return;const e=ao.allocUnsafe(21);return e.writeUInt8(r.network.scriptHash,0),r.hash.copy(e,1),XO.encode(e)})),YO.prop(r,"hash",(()=>e.output?e.output.slice(2,22):e.address?i().hash:r.redeem&&r.redeem.output?qO.hash160(r.redeem.output):void 0)),YO.prop(r,"output",(()=>{if(r.hash)return zO.compile([WO.OP_HASH160,r.hash,WO.OP_EQUAL])})),YO.prop(r,"redeem",(()=>{if(e.input)return a()})),YO.prop(r,"input",(()=>{if(e.redeem&&e.redeem.input&&e.redeem.output)return zO.compile([].concat(zO.decompile(e.redeem.input),e.redeem.output))})),YO.prop(r,"witness",(()=>r.redeem&&r.redeem.witness?r.redeem.witness:r.input?[]:void 0)),YO.prop(r,"name",(()=>{const e=["p2sh"];return void 0!==r.redeem&&void 0!==r.redeem.name&&e.push(r.redeem.name),e.join("-")})),t.validate){let t=ao.from([]);if(e.address){if(i().version!==n.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");t=i().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(23!==e.output.length||e.output[0]!==WO.OP_HASH160||20!==e.output[1]||e.output[22]!==WO.OP_EQUAL)throw new TypeError("Output is invalid");const n=e.output.slice(2,22);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}const r=e=>{if(e.output){const n=zO.decompile(e.output);if(!n||n.length<1)throw new TypeError("Redeem.output too short");const r=qO.hash160(e.output);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.input){const t=e.input.length>0,n=e.witness&&e.witness.length>0;if(!t&&!n)throw new TypeError("Empty input");if(t&&n)throw new TypeError("Input and witness provided");if(t){const t=zO.decompile(e.input);if(!zO.isPushOnly(t))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const e=o();if(!e||e.length<1)throw new TypeError("Input too short");if(!jo(a().output))throw new TypeError("Input is invalid");r(a())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==n)throw new TypeError("Network mismatch");if(e.input){const t=a();if(e.redeem.output&&!e.redeem.output.equals(t.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(t.input))throw new TypeError("Redeem.input mismatch")}r(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!function(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(r,e)};var ZO={},$O={};Object.defineProperty($O,"__esModule",{value:!0}),$O.bech32m=$O.bech32=void 0;const eH="qpzry9x8gf2tvdw0s3jn54khce6mua7l",tH={};for(let e=0;e<eH.length;e++){const t=eH.charAt(e);tH[t]=e}function nH(e){const t=e>>25;return(33554431&e)<<5^996825010&-(t>>0&1)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function rH(e){let t=1;for(let n=0;n<e.length;++n){const r=e.charCodeAt(n);if(r<33||r>126)return"Invalid prefix ("+e+")";t=nH(t)^r>>5}t=nH(t);for(let n=0;n<e.length;++n){const r=e.charCodeAt(n);t=nH(t)^31&r}return t}function iH(e,t,n,r){let i=0,o=0;const a=(1<<n)-1,s=[];for(let r=0;r<e.length;++r)for(i=i<<t|e[r],o+=t;o>=n;)o-=n,s.push(i>>o&a);if(r)o>0&&s.push(i<<n-o&a);else{if(o>=t)return"Excess padding";if(i<<n-o&a)return"Non-zero padding"}return s}function oH(e){return iH(e,8,5,!0)}function aH(e){const t=iH(e,5,8,!1);if(Array.isArray(t))return t}function sH(e){const t=iH(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function lH(e){let t;function n(e,n){if(n=n||90,e.length<8)return e+" too short";if(e.length>n)return"Exceeds length limit";const r=e.toLowerCase(),i=e.toUpperCase();if(e!==r&&e!==i)return"Mixed-case string "+e;const o=(e=r).lastIndexOf("1");if(-1===o)return"No separator character for "+e;if(0===o)return"Missing prefix for "+e;const a=e.slice(0,o),s=e.slice(o+1);if(s.length<6)return"Data too short";let l=rH(a);if("string"==typeof l)return l;const u=[];for(let e=0;e<s.length;++e){const t=s.charAt(e),n=tH[t];if(void 0===n)return"Unknown character "+t;l=nH(l)^n,e+6>=s.length||u.push(n)}return l!==t?"Invalid checksum for "+e:{prefix:a,words:u}}return t="bech32"===e?1:734539939,{decodeUnsafe:function(e,t){const r=n(e,t);if("object"==typeof r)return r},decode:function(e,t){const r=n(e,t);if("object"==typeof r)return r;throw new Error(r)},encode:function(e,n,r){if(r=r||90,e.length+7+n.length>r)throw new TypeError("Exceeds length limit");let i=rH(e=e.toLowerCase());if("string"==typeof i)throw new Error(i);let o=e+"1";for(let e=0;e<n.length;++e){const t=n[e];if(t>>5!=0)throw new Error("Non 5-bit word");i=nH(i)^t,o+=eH.charAt(t)}for(let e=0;e<6;++e)i=nH(i);i^=t;for(let e=0;e<6;++e)o+=eH.charAt(i>>5*(5-e)&31);return o},toWords:oH,fromWordsUnsafe:aH,fromWords:sH}}$O.bech32=lH("bech32"),$O.bech32m=lH("bech32m"),Object.defineProperty(ZO,"__esModule",{value:!0}),ZO.p2wpkh=void 0;const uH=UU,AH=cP,cH=dP,hH=EP,fH=dU,dH=$O,pH=cH.OPS,gH=ao.alloc(0);ZO.p2wpkh=function(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,hH.typeforce)({address:hH.typeforce.maybe(hH.typeforce.String),hash:hH.typeforce.maybe(hH.typeforce.BufferN(20)),input:hH.typeforce.maybe(hH.typeforce.BufferN(0)),network:hH.typeforce.maybe(hH.typeforce.Object),output:hH.typeforce.maybe(hH.typeforce.BufferN(22)),pubkey:hH.typeforce.maybe(hH.isPoint),signature:hH.typeforce.maybe(cH.isCanonicalScriptSignature),witness:hH.typeforce.maybe(hH.typeforce.arrayOf(hH.typeforce.Buffer))},e);const n=fH.value((()=>{const t=dH.bech32.decode(e.address),n=t.words.shift(),r=dH.bech32.fromWords(t.words);return{version:n,prefix:t.prefix,data:ao.from(r)}})),r=e.network||AH.bitcoin,i={name:"p2wpkh",network:r};if(fH.prop(i,"address",(()=>{if(!i.hash)return;const e=dH.bech32.toWords(i.hash);return e.unshift(0),dH.bech32.encode(r.bech32,e)})),fH.prop(i,"hash",(()=>e.output?e.output.slice(2,22):e.address?n().data:e.pubkey||i.pubkey?uH.hash160(e.pubkey||i.pubkey):void 0)),fH.prop(i,"output",(()=>{if(i.hash)return cH.compile([pH.OP_0,i.hash])})),fH.prop(i,"pubkey",(()=>e.pubkey?e.pubkey:e.witness?e.witness[1]:void 0)),fH.prop(i,"signature",(()=>{if(e.witness)return e.witness[0]})),fH.prop(i,"input",(()=>{if(i.witness)return gH})),fH.prop(i,"witness",(()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]})),t.validate){let t=ao.from([]);if(e.address){if(r&&r.bech32!==n().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==n().version)throw new TypeError("Invalid address version");if(20!==n().data.length)throw new TypeError("Invalid address data");t=n().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(22!==e.output.length||e.output[0]!==pH.OP_0||20!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");t=e.output.slice(2)}if(e.pubkey){const n=uH.hash160(e.pubkey);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");if(t=n,!(0,hH.isPoint)(e.pubkey)||33!==e.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(2!==e.witness.length)throw new TypeError("Witness is invalid");if(!cH.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,hH.isPoint)(e.witness[1])||33!==e.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const n=uH.hash160(e.witness[1]);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)};var yH={};Object.defineProperty(yH,"__esModule",{value:!0}),yH.p2wsh=void 0;const mH=UU,vH=cP,IH=dP,wH=EP,bH=dU,BH=$O,EH=IH.OPS,CH=ao.alloc(0);function SH(e){return!(!jo(e)||65!==e.length||4!==e[0]||!(0,wH.isPoint)(e))}yH.p2wsh=function(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,wH.typeforce)({network:wH.typeforce.maybe(wH.typeforce.Object),address:wH.typeforce.maybe(wH.typeforce.String),hash:wH.typeforce.maybe(wH.typeforce.BufferN(32)),output:wH.typeforce.maybe(wH.typeforce.BufferN(34)),redeem:wH.typeforce.maybe({input:wH.typeforce.maybe(wH.typeforce.Buffer),network:wH.typeforce.maybe(wH.typeforce.Object),output:wH.typeforce.maybe(wH.typeforce.Buffer),witness:wH.typeforce.maybe(wH.typeforce.arrayOf(wH.typeforce.Buffer))}),input:wH.typeforce.maybe(wH.typeforce.BufferN(0)),witness:wH.typeforce.maybe(wH.typeforce.arrayOf(wH.typeforce.Buffer))},e);const n=bH.value((()=>{const t=BH.bech32.decode(e.address),n=t.words.shift(),r=BH.bech32.fromWords(t.words);return{version:n,prefix:t.prefix,data:ao.from(r)}})),r=bH.value((()=>IH.decompile(e.redeem.input)));let i=e.network;i||(i=e.redeem&&e.redeem.network||vH.bitcoin);const o={network:i};if(bH.prop(o,"address",(()=>{if(!o.hash)return;const e=BH.bech32.toWords(o.hash);return e.unshift(0),BH.bech32.encode(i.bech32,e)})),bH.prop(o,"hash",(()=>e.output?e.output.slice(2):e.address?n().data:o.redeem&&o.redeem.output?mH.sha256(o.redeem.output):void 0)),bH.prop(o,"output",(()=>{if(o.hash)return IH.compile([EH.OP_0,o.hash])})),bH.prop(o,"redeem",(()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:CH,witness:e.witness.slice(0,-1)}})),bH.prop(o,"input",(()=>{if(o.witness)return CH})),bH.prop(o,"witness",(()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const t=IH.toStack(r());return o.redeem=Object.assign({witness:t},e.redeem),o.redeem.input=CH,[].concat(t,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)})),bH.prop(o,"name",(()=>{const e=["p2wsh"];return void 0!==o.redeem&&void 0!==o.redeem.name&&e.push(o.redeem.name),e.join("-")})),t.validate){let t=ao.from([]);if(e.address){if(n().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==n().version)throw new TypeError("Invalid address version");if(32!==n().data.length)throw new TypeError("Invalid address data");t=n().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(34!==e.output.length||e.output[0]!==EH.OP_0||32!==e.output[1])throw new TypeError("Output is invalid");const n=e.output.slice(2);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){if(0===IH.decompile(e.redeem.output).length)throw new TypeError("Redeem.output is invalid");const n=mH.sha256(e.redeem.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem.input&&!IH.isPushOnly(r()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!function(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&r().some(SH)||e.redeem.output&&(IH.decompile(e.redeem.output)||[]).some(SH))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const t=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(t))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(SH)||(IH.decompile(t)||[]).some(SH))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=fP;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const n=IU;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return n.p2ms}});const r=QU;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return r.p2pk}});const i=PU;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const o=GO;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return o.p2sh}});const a=ZO;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return a.p2wpkh}});const s=yH;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return s.p2wsh}})}(hP),Object.defineProperty(AP,"__esModule",{value:!0}),AP.toOutputScript=AP.fromOutputScript=AP.toBech32=AP.toBase58Check=AP.fromBech32=AP.fromBase58Check=void 0;const xH=cP,QH=hP,kH=dP,_H=EP,NH=$O,DH=MO,{typeforce:FH}=_H,PH="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function UH(e){const t=DH.decode(e);if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");return{version:t.readUInt8(0),hash:t.slice(1)}}function MH(e){let t,n;try{t=NH.bech32.decode(e)}catch(e){}if(t){if(n=t.words[0],0!==n)throw new TypeError(e+" uses wrong encoding")}else if(t=NH.bech32m.decode(e),n=t.words[0],0===n)throw new TypeError(e+" uses wrong encoding");const r=NH.bech32.fromWords(t.words.slice(1));return{version:n,prefix:t.prefix,data:ao.from(r)}}function LH(e,t,n){const r=NH.bech32.toWords(e);return r.unshift(t),0===t?NH.bech32.encode(n,r):NH.bech32m.encode(n,r)}AP.fromBase58Check=UH,AP.fromBech32=MH,AP.toBase58Check=function(e,t){FH(_H.tuple(_H.Hash160bit,_H.UInt8),arguments);const n=ao.allocUnsafe(21);return n.writeUInt8(t,0),e.copy(n,1),DH.encode(n)},AP.toBech32=LH,AP.fromOutputScript=function(e,t){t=t||xH.bitcoin;try{return QH.p2pkh({output:e,network:t}).address}catch(e){}try{return QH.p2sh({output:e,network:t}).address}catch(e){}try{return QH.p2wpkh({output:e,network:t}).address}catch(e){}try{return QH.p2wsh({output:e,network:t}).address}catch(e){}try{return function(e,t){const n=e.slice(2);if(n.length<2||n.length>40)throw new TypeError("Invalid program length for segwit address");const r=e[0]-80;if(r<1||r>16)throw new TypeError("Invalid version for segwit address");if(e[1]!==n.length)throw new TypeError("Invalid script for segwit address");return console.warn(PH),LH(n,r,t.bech32)}(e,t)}catch(e){}throw new Error(kH.toASM(e)+" has no matching Address")},AP.toOutputScript=function(e,t){let n,r;t=t||xH.bitcoin;try{n=UH(e)}catch(e){}if(n){if(n.version===t.pubKeyHash)return QH.p2pkh({hash:n.hash}).output;if(n.version===t.scriptHash)return QH.p2sh({hash:n.hash}).output}else{try{r=MH(e)}catch(e){}if(r){if(r.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(0===r.version){if(20===r.data.length)return QH.p2wpkh({hash:r.data}).output;if(32===r.data.length)return QH.p2wsh({hash:r.data}).output}else if(r.version>=1&&r.version<=16&&r.data.length>=2&&r.data.length<=40)return console.warn(PH),kH.compile([r.version+80,r.data])}}throw new Error(e+" has no matching Script")};var TH={},RH={},OH=F_.exports.Buffer;function HH(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function KH(e){return HH(e),e<253?1:e<=65535?3:e<=4294967295?5:9}var jH={encode:function e(t,n,r){if(HH(t),n||(n=OH.allocUnsafe(KH(t))),!OH.isBuffer(n))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),t<253?(n.writeUInt8(t,r),e.bytes=1):t<=65535?(n.writeUInt8(253,r),n.writeUInt16LE(t,r+1),e.bytes=3):t<=4294967295?(n.writeUInt8(254,r),n.writeUInt32LE(t,r+1),e.bytes=5):(n.writeUInt8(255,r),n.writeUInt32LE(t>>>0,r+1),n.writeUInt32LE(t/4294967296|0,r+5),e.bytes=9),n},decode:function e(t,n){if(!OH.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");n||(n=0);var r=t.readUInt8(n);if(r<253)return e.bytes=1,r;if(253===r)return e.bytes=3,t.readUInt16LE(n+1);if(254===r)return e.bytes=5,t.readUInt32LE(n+1);e.bytes=9;var i=t.readUInt32LE(n+1),o=4294967296*t.readUInt32LE(n+5)+i;return HH(o),o},encodingLength:KH};Object.defineProperty(RH,"__esModule",{value:!0}),RH.BufferReader=RH.BufferWriter=RH.cloneBuffer=RH.reverseBuffer=RH.writeUInt64LE=RH.readUInt64LE=RH.varuint=void 0;const GH=EP,{typeforce:qH}=GH,VH=jH;function zH(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function JH(e,t){const n=e.readUInt32LE(t);let r=e.readUInt32LE(t+4);return r*=4294967296,zH(r+n,9007199254740991),r+n}function YH(e,t,n){return zH(t,9007199254740991),e.writeInt32LE(-1&t,n),e.writeUInt32LE(Math.floor(t/4294967296),n+4),n+8}RH.varuint=VH,RH.readUInt64LE=JH,RH.writeUInt64LE=YH,RH.reverseBuffer=function(e){if(e.length<1)return e;let t=e.length-1,n=0;for(let r=0;r<e.length/2;r++)n=e[r],e[r]=e[t],e[t]=n,t--;return e},RH.cloneBuffer=function(e){const t=ao.allocUnsafe(e.length);return e.copy(t),t};class XH{constructor(e,t=0){this.buffer=e,this.offset=t,qH(GH.tuple(GH.Buffer,GH.UInt32),[e,t])}static withCapacity(e){return new XH(ao.alloc(e))}writeUInt8(e){this.offset=this.buffer.writeUInt8(e,this.offset)}writeInt32(e){this.offset=this.buffer.writeInt32LE(e,this.offset)}writeUInt32(e){this.offset=this.buffer.writeUInt32LE(e,this.offset)}writeUInt64(e){this.offset=YH(this.buffer,e,this.offset)}writeVarInt(e){VH.encode(e,this.buffer,this.offset),this.offset+=VH.encode.bytes}writeSlice(e){if(this.buffer.length<this.offset+e.length)throw new Error("Cannot write slice out of bounds");this.offset+=e.copy(this.buffer,this.offset)}writeVarSlice(e){this.writeVarInt(e.length),this.writeSlice(e)}writeVector(e){this.writeVarInt(e.length),e.forEach((e=>this.writeVarSlice(e)))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}RH.BufferWriter=XH,RH.BufferReader=class{constructor(e,t=0){this.buffer=e,this.offset=t,qH(GH.tuple(GH.Buffer,GH.UInt32),[e,t])}readUInt8(){const e=this.buffer.readUInt8(this.offset);return this.offset++,e}readInt32(){const e=this.buffer.readInt32LE(this.offset);return this.offset+=4,e}readUInt32(){const e=this.buffer.readUInt32LE(this.offset);return this.offset+=4,e}readUInt64(){const e=JH(this.buffer,this.offset);return this.offset+=8,e}readVarInt(){const e=VH.decode(this.buffer,this.offset);return this.offset+=VH.decode.bytes,e}readSlice(e){if(this.buffer.length<this.offset+e)throw new Error("Cannot read slice out of bounds");const t=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const e=this.readVarInt(),t=[];for(let n=0;n<e;n++)t.push(this.readVarSlice());return t}};var WH={};Object.defineProperty(WH,"__esModule",{value:!0}),WH.fastMerkleRoot=void 0,WH.fastMerkleRoot=function(e,t){if(!Array.isArray(e))throw TypeError("Expected values Array");if("function"!=typeof t)throw TypeError("Expected digest Function");let n=e.length;const r=e.concat();for(;n>1;){let e=0;for(let i=0;i<n;i+=2,++e){const o=r[i],a=i+1===n?o:r[i+1],s=ao.concat([o,a]);r[e]=t(s)}n=e}return r[0]};var ZH={};Object.defineProperty(ZH,"__esModule",{value:!0}),ZH.Transaction=void 0;const $H=RH,eK=UU,tK=dP,nK=dP,rK=EP,{typeforce:iK}=rK;function oK(e){const t=e.length;return $H.varuint.encodingLength(t)+t}const aK=ao.allocUnsafe(0),sK=[],lK=ao.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),uK=ao.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),AK=ao.from("ffffffffffffffff","hex"),cK={script:aK,valueBuffer:AK};class hK{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(e,t){const n=new $H.BufferReader(e),r=new hK;r.version=n.readInt32();const i=n.readUInt8(),o=n.readUInt8();let a=!1;i===hK.ADVANCED_TRANSACTION_MARKER&&o===hK.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const s=n.readVarInt();for(let e=0;e<s;++e)r.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:sK});const l=n.readVarInt();for(let e=0;e<l;++e)r.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let e=0;e<s;++e)r.ins[e].witness=n.readVector();if(!r.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(r.locktime=n.readUInt32(),t)return r;if(n.offset!==e.length)throw new Error("Transaction has unexpected data");return r}static fromHex(e){return hK.fromBuffer(ao.from(e,"hex"),!1)}static isCoinbaseHash(e){iK(rK.Hash256bit,e);for(let t=0;t<32;++t)if(0!==e[t])return!1;return!0}isCoinbase(){return 1===this.ins.length&&hK.isCoinbaseHash(this.ins[0].hash)}addInput(e,t,n,r){return iK(rK.tuple(rK.Hash256bit,rK.UInt32,rK.maybe(rK.UInt32),rK.maybe(rK.Buffer)),arguments),rK.Null(n)&&(n=hK.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:t,script:r||aK,sequence:n,witness:sK})-1}addOutput(e,t){return iK(rK.tuple(rK.Buffer,rK.Satoshi),arguments),this.outs.push({script:e,value:t})-1}hasWitnesses(){return this.ins.some((e=>0!==e.witness.length))}weight(){return 3*this.byteLength(!1)+this.byteLength(!0)}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(e=!0){const t=e&&this.hasWitnesses();return(t?10:8)+$H.varuint.encodingLength(this.ins.length)+$H.varuint.encodingLength(this.outs.length)+this.ins.reduce(((e,t)=>e+40+oK(t.script)),0)+this.outs.reduce(((e,t)=>e+8+oK(t.script)),0)+(t?this.ins.reduce(((e,t)=>e+function(e){const t=e.length;return $H.varuint.encodingLength(t)+e.reduce(((e,t)=>e+oK(t)),0)}(t.witness)),0):0)}clone(){const e=new hK;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map((e=>({hash:e.hash,index:e.index,script:e.script,sequence:e.sequence,witness:e.witness}))),e.outs=this.outs.map((e=>({script:e.script,value:e.value}))),e}hashForSignature(e,t,n){if(iK(rK.tuple(rK.UInt32,rK.Buffer,rK.Number),arguments),e>=this.ins.length)return uK;const r=tK.compile(tK.decompile(t).filter((e=>e!==nK.OPS.OP_CODESEPARATOR))),i=this.clone();if((31&n)===hK.SIGHASH_NONE)i.outs=[],i.ins.forEach(((t,n)=>{n!==e&&(t.sequence=0)}));else if((31&n)===hK.SIGHASH_SINGLE){if(e>=this.outs.length)return uK;i.outs.length=e+1;for(let t=0;t<e;t++)i.outs[t]=cK;i.ins.forEach(((t,n)=>{n!==e&&(t.sequence=0)}))}n&hK.SIGHASH_ANYONECANPAY?(i.ins=[i.ins[e]],i.ins[0].script=r):(i.ins.forEach((e=>{e.script=aK})),i.ins[e].script=r);const o=ao.allocUnsafe(i.byteLength(!1)+4);return o.writeInt32LE(n,o.length-4),i.__toBuffer(o,0,!1),eK.hash256(o)}hashForWitnessV1(e,t,n,r,i,o){if(iK(rK.tuple(rK.UInt32,iK.arrayOf(rK.Buffer),iK.arrayOf(rK.Satoshi),rK.UInt32),arguments),n.length!==this.ins.length||t.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const a=r===hK.SIGHASH_DEFAULT?hK.SIGHASH_ALL:r&hK.SIGHASH_OUTPUT_MASK,s=(r&hK.SIGHASH_INPUT_MASK)===hK.SIGHASH_ANYONECANPAY,l=a===hK.SIGHASH_NONE,u=a===hK.SIGHASH_SINGLE;let A=aK,c=aK,h=aK,f=aK,d=aK;if(!s){let e=$H.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach((t=>{e.writeSlice(t.hash),e.writeUInt32(t.index)})),A=eK.sha256(e.end()),e=$H.BufferWriter.withCapacity(8*this.ins.length),n.forEach((t=>e.writeUInt64(t))),c=eK.sha256(e.end()),e=$H.BufferWriter.withCapacity(t.map(oK).reduce(((e,t)=>e+t))),t.forEach((t=>e.writeVarSlice(t))),h=eK.sha256(e.end()),e=$H.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach((t=>e.writeUInt32(t.sequence))),f=eK.sha256(e.end())}if(l||u){if(u&&e<this.outs.length){const t=this.outs[e],n=$H.BufferWriter.withCapacity(8+oK(t.script));n.writeUInt64(t.value),n.writeVarSlice(t.script),d=eK.sha256(n.end())}}else{const e=this.outs.map((e=>8+oK(e.script))).reduce(((e,t)=>e+t)),t=$H.BufferWriter.withCapacity(e);this.outs.forEach((e=>{t.writeUInt64(e.value),t.writeVarSlice(e.script)})),d=eK.sha256(t.end())}const p=(i?2:0)+(o?1:0),g=174-(s?49:0)-(l?32:0)+(o?32:0)+(i?37:0),y=$H.BufferWriter.withCapacity(g);if(y.writeUInt8(r),y.writeInt32(this.version),y.writeUInt32(this.locktime),y.writeSlice(A),y.writeSlice(c),y.writeSlice(h),y.writeSlice(f),l||u||y.writeSlice(d),y.writeUInt8(p),s){const r=this.ins[e];y.writeSlice(r.hash),y.writeUInt32(r.index),y.writeUInt64(n[e]),y.writeVarSlice(t[e]),y.writeUInt32(r.sequence)}else y.writeUInt32(e);if(o){const e=$H.BufferWriter.withCapacity(oK(o));e.writeVarSlice(o),y.writeSlice(eK.sha256(e.end()))}return u&&y.writeSlice(d),i&&(y.writeSlice(i),y.writeUInt8(0),y.writeUInt32(4294967295)),eK.taggedHash("TapSighash",ao.concat([ao.of(0),y.end()]))}hashForWitnessV0(e,t,n,r){iK(rK.tuple(rK.UInt32,rK.Buffer,rK.Satoshi,rK.UInt32),arguments);let i,o=ao.from([]),a=lK,s=lK,l=lK;if(r&hK.SIGHASH_ANYONECANPAY||(o=ao.allocUnsafe(36*this.ins.length),i=new $H.BufferWriter(o,0),this.ins.forEach((e=>{i.writeSlice(e.hash),i.writeUInt32(e.index)})),s=eK.hash256(o)),r&hK.SIGHASH_ANYONECANPAY||(31&r)===hK.SIGHASH_SINGLE||(31&r)===hK.SIGHASH_NONE||(o=ao.allocUnsafe(4*this.ins.length),i=new $H.BufferWriter(o,0),this.ins.forEach((e=>{i.writeUInt32(e.sequence)})),l=eK.hash256(o)),(31&r)!==hK.SIGHASH_SINGLE&&(31&r)!==hK.SIGHASH_NONE){const e=this.outs.reduce(((e,t)=>e+8+oK(t.script)),0);o=ao.allocUnsafe(e),i=new $H.BufferWriter(o,0),this.outs.forEach((e=>{i.writeUInt64(e.value),i.writeVarSlice(e.script)})),a=eK.hash256(o)}else if((31&r)===hK.SIGHASH_SINGLE&&e<this.outs.length){const t=this.outs[e];o=ao.allocUnsafe(8+oK(t.script)),i=new $H.BufferWriter(o,0),i.writeUInt64(t.value),i.writeVarSlice(t.script),a=eK.hash256(o)}o=ao.allocUnsafe(156+oK(t)),i=new $H.BufferWriter(o,0);const u=this.ins[e];return i.writeInt32(this.version),i.writeSlice(s),i.writeSlice(l),i.writeSlice(u.hash),i.writeUInt32(u.index),i.writeVarSlice(t),i.writeUInt64(n),i.writeUInt32(u.sequence),i.writeSlice(a),i.writeUInt32(this.locktime),i.writeUInt32(r),eK.hash256(o)}getHash(e){return e&&this.isCoinbase()?ao.alloc(32,0):eK.hash256(this.__toBuffer(void 0,void 0,e))}getId(){return(0,$H.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(e,t){return this.__toBuffer(e,t,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(e,t){iK(rK.tuple(rK.Number,rK.Buffer),arguments),this.ins[e].script=t}setWitness(e,t){iK(rK.tuple(rK.Number,[rK.Buffer]),arguments),this.ins[e].witness=t}__toBuffer(e,t,n=!1){e||(e=ao.allocUnsafe(this.byteLength(n)));const r=new $H.BufferWriter(e,t||0);r.writeInt32(this.version);const i=n&&this.hasWitnesses();return i&&(r.writeUInt8(hK.ADVANCED_TRANSACTION_MARKER),r.writeUInt8(hK.ADVANCED_TRANSACTION_FLAG)),r.writeVarInt(this.ins.length),this.ins.forEach((e=>{r.writeSlice(e.hash),r.writeUInt32(e.index),r.writeVarSlice(e.script),r.writeUInt32(e.sequence)})),r.writeVarInt(this.outs.length),this.outs.forEach((e=>{void 0!==e.value?r.writeUInt64(e.value):r.writeSlice(e.valueBuffer),r.writeVarSlice(e.script)})),i&&this.ins.forEach((e=>{r.writeVector(e.witness)})),r.writeUInt32(this.locktime),void 0!==t?e.slice(t,r.offset):e}}ZH.Transaction=hK,hK.DEFAULT_SEQUENCE=4294967295,hK.SIGHASH_DEFAULT=0,hK.SIGHASH_ALL=1,hK.SIGHASH_NONE=2,hK.SIGHASH_SINGLE=3,hK.SIGHASH_ANYONECANPAY=128,hK.SIGHASH_OUTPUT_MASK=3,hK.SIGHASH_INPUT_MASK=128,hK.ADVANCED_TRANSACTION_MARKER=0,hK.ADVANCED_TRANSACTION_FLAG=1,Object.defineProperty(TH,"__esModule",{value:!0}),TH.Block=void 0;const fK=RH,dK=UU,pK=WH,gK=ZH,yK=EP,{typeforce:mK}=yK,vK=new TypeError("Cannot compute merkle root for zero transactions"),IK=new TypeError("Cannot compute witness commit for non-segwit block");class wK{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(e){if(e.length<80)throw new Error("Buffer too small (< 80 bytes)");const t=new fK.BufferReader(e),n=new wK;if(n.version=t.readInt32(),n.prevHash=t.readSlice(32),n.merkleRoot=t.readSlice(32),n.timestamp=t.readUInt32(),n.bits=t.readUInt32(),n.nonce=t.readUInt32(),80===e.length)return n;const r=()=>{const e=gK.Transaction.fromBuffer(t.buffer.slice(t.offset),!0);return t.offset+=e.byteLength(),e},i=t.readVarInt();n.transactions=[];for(let e=0;e<i;++e){const e=r();n.transactions.push(e)}const o=n.getWitnessCommit();return o&&(n.witnessCommit=o),n}static fromHex(e){return wK.fromBuffer(ao.from(e,"hex"))}static calculateTarget(e){const t=((4278190080&e)>>24)-3,n=8388607&e,r=ao.alloc(32,0);return r.writeUIntBE(n,29-t,3),r}static calculateMerkleRoot(e,t){if(mK([{getHash:yK.Function}],e),0===e.length)throw vK;if(t&&!bK(e))throw IK;const n=e.map((e=>e.getHash(t))),r=(0,pK.fastMerkleRoot)(n,dK.hash256);return t?dK.hash256(ao.concat([r,e[0].ins[0].witness[0]])):r}getWitnessCommit(){if(!bK(this.transactions))return null;const e=this.transactions[0].outs.filter((e=>e.script.slice(0,6).equals(ao.from("6a24aa21a9ed","hex")))).map((e=>e.script.slice(6,38)));if(0===e.length)return null;const t=e[e.length-1];return t instanceof ao&&32===t.length?t:null}hasWitnessCommit(){return this.witnessCommit instanceof ao&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}hasWitness(){return(e=this.transactions)instanceof Array&&e.some((e=>"object"==typeof e&&e.ins instanceof Array&&e.ins.some((e=>"object"==typeof e&&e.witness instanceof Array&&e.witness.length>0))));var e}weight(){return 3*this.byteLength(!1,!1)+this.byteLength(!1,!0)}byteLength(e,t=!0){return e||!this.transactions?80:80+fK.varuint.encodingLength(this.transactions.length)+this.transactions.reduce(((e,n)=>e+n.byteLength(t)),0)}getHash(){return dK.hash256(this.toBuffer(!0))}getId(){return(0,fK.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const e=new Date(0);return e.setUTCSeconds(this.timestamp),e}toBuffer(e){const t=ao.allocUnsafe(this.byteLength(e)),n=new fK.BufferWriter(t);return n.writeInt32(this.version),n.writeSlice(this.prevHash),n.writeSlice(this.merkleRoot),n.writeUInt32(this.timestamp),n.writeUInt32(this.bits),n.writeUInt32(this.nonce),e||!this.transactions||(fK.varuint.encode(this.transactions.length,t,n.offset),n.offset+=fK.varuint.encode.bytes,this.transactions.forEach((e=>{const r=e.byteLength();e.toBuffer(t,n.offset),n.offset+=r}))),t}toHex(e){return this.toBuffer(e).toString("hex")}checkTxRoots(){const e=this.hasWitnessCommit();return!(!e&&this.hasWitness())&&this.__checkMerkleRoot()&&(!e||this.__checkWitnessCommit())}checkProofOfWork(){const e=(0,fK.reverseBuffer)(this.getHash()),t=wK.calculateTarget(this.bits);return e.compare(t)<=0}__checkMerkleRoot(){if(!this.transactions)throw vK;const e=wK.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}__checkWitnessCommit(){if(!this.transactions)throw vK;if(!this.hasWitnessCommit())throw IK;const e=wK.calculateMerkleRoot(this.transactions,!0);return 0===this.witnessCommit.compare(e)}}function bK(e){return e instanceof Array&&e[0]&&e[0].ins&&e[0].ins instanceof Array&&e[0].ins[0]&&e[0].ins[0].witness&&e[0].ins[0].witness instanceof Array&&e[0].ins[0].witness.length>0}TH.Block=wK;var BK={},EK={},CK={},SK={},xK={},QK={},kK={};!function(e){var t,n,r;Object.defineProperty(e,"__esModule",{value:!0}),(t=e.GlobalTypes||(e.GlobalTypes={}))[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(n=e.InputTypes||(e.InputTypes={}))[n.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",n[n.WITNESS_UTXO=1]="WITNESS_UTXO",n[n.PARTIAL_SIG=2]="PARTIAL_SIG",n[n.SIGHASH_TYPE=3]="SIGHASH_TYPE",n[n.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",n[n.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",n[n.BIP32_DERIVATION=6]="BIP32_DERIVATION",n[n.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",n[n.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",n[n.POR_COMMITMENT=9]="POR_COMMITMENT",n[n.TAP_KEY_SIG=19]="TAP_KEY_SIG",n[n.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",n[n.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",n[n.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",n[n.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",n[n.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT",e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(r=e.OutputTypes||(e.OutputTypes={}))[r.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",r[r.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",r[r.BIP32_DERIVATION=2]="BIP32_DERIVATION",r[r.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",r[r.TAP_TREE=6]="TAP_TREE",r[r.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION",e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]}(kK);var _K={};Object.defineProperty(_K,"__esModule",{value:!0});const NK=kK;_K.decode=function(e){if(e.key[0]!==NK.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+e.key.toString("hex"));if(79!==e.key.length||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+e.key.toString("hex"));if(e.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),n={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const t of(r=e.value.length/4-1,[...Array(r).keys()])){const r=e.value.readUInt32LE(4*t+4),i=!!(2147483648&r),o=2147483647&r;n.path+="/"+o.toString(10)+(i?"'":"")}var r;return n},_K.encode=function(e){const t=ao.from([NK.GlobalTypes.GLOBAL_XPUB]),n=ao.concat([t,e.extendedPubkey]),r=e.path.split("/"),i=ao.allocUnsafe(4*r.length);e.masterFingerprint.copy(i,0);let o=4;return r.slice(1).forEach((e=>{const t="'"===e.slice(-1);let n=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(n+=2147483648),i.writeUInt32LE(n,o),o+=4})),{key:n,value:i}},_K.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",_K.check=function(e){const t=e.extendedPubkey,n=e.masterFingerprint,r=e.path;return jo(t)&&78===t.length&&[2,3].indexOf(t[45])>-1&&jo(n)&&4===n.length&&"string"==typeof r&&!!r.match(/^m(\/\d+'?)*$/)},_K.canAddToArray=function(e,t,n){const r=t.extendedPubkey.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.extendedPubkey.equals(t.extendedPubkey))).length)};var DK={};Object.defineProperty(DK,"__esModule",{value:!0});const FK=kK;DK.encode=function(e){return{key:ao.from([FK.GlobalTypes.UNSIGNED_TX]),value:e.toBuffer()}};var PK={};Object.defineProperty(PK,"__esModule",{value:!0});const UK=kK;PK.decode=function(e){if(e.key[0]!==UK.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+e.key.toString("hex"));return e.value},PK.encode=function(e){return{key:ao.from([UK.InputTypes.FINAL_SCRIPTSIG]),value:e}},PK.expected="Buffer",PK.check=function(e){return jo(e)},PK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptSig};var MK={};Object.defineProperty(MK,"__esModule",{value:!0});const LK=kK;MK.decode=function(e){if(e.key[0]!==LK.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+e.key.toString("hex"));return e.value},MK.encode=function(e){return{key:ao.from([LK.InputTypes.FINAL_SCRIPTWITNESS]),value:e}},MK.expected="Buffer",MK.check=function(e){return jo(e)},MK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptWitness};var TK={};Object.defineProperty(TK,"__esModule",{value:!0});const RK=kK;TK.decode=function(e){if(e.key[0]!==RK.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+e.key.toString("hex"));return e.value},TK.encode=function(e){return{key:ao.from([RK.InputTypes.NON_WITNESS_UTXO]),value:e}},TK.expected="Buffer",TK.check=function(e){return jo(e)},TK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.nonWitnessUtxo};var OK={};Object.defineProperty(OK,"__esModule",{value:!0});const HK=kK;OK.decode=function(e){if(e.key[0]!==HK.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+e.key.toString("hex"));if(34!==e.key.length&&66!==e.key.length||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+e.key.toString("hex"));return{pubkey:e.key.slice(1),signature:e.value}},OK.encode=function(e){const t=ao.from([HK.InputTypes.PARTIAL_SIG]);return{key:ao.concat([t,e.pubkey]),value:e.signature}},OK.expected="{ pubkey: Buffer; signature: Buffer; }",OK.check=function(e){return jo(e.pubkey)&&jo(e.signature)&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&function(e){if(!jo(e)||e.length<9)return!1;if(48!==e[0])return!1;if(e.length!==e[1]+3)return!1;if(2!==e[2])return!1;const t=e[3];if(t>33||t<1)return!1;if(2!==e[3+t+1])return!1;const n=e[3+t+2];return!(n>33||n<1)&&e.length===3+t+2+n+2}(e.signature)},OK.canAddToArray=function(e,t,n){const r=t.pubkey.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.pubkey.equals(t.pubkey))).length)};var KK={};Object.defineProperty(KK,"__esModule",{value:!0});const jK=kK;KK.decode=function(e){if(e.key[0]!==jK.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+e.key.toString("hex"));return e.value.toString("utf8")},KK.encode=function(e){return{key:ao.from([jK.InputTypes.POR_COMMITMENT]),value:ao.from(e,"utf8")}},KK.expected="string",KK.check=function(e){return"string"==typeof e},KK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.porCommitment};var GK={};Object.defineProperty(GK,"__esModule",{value:!0});const qK=kK;GK.decode=function(e){if(e.key[0]!==qK.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+e.key.toString("hex"));return e.value.readUInt32LE(0)},GK.encode=function(e){const t=ao.from([qK.InputTypes.SIGHASH_TYPE]),n=ao.allocUnsafe(4);return n.writeUInt32LE(e,0),{key:t,value:n}},GK.expected="number",GK.check=function(e){return"number"==typeof e},GK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.sighashType};var VK={};Object.defineProperty(VK,"__esModule",{value:!0});const zK=kK;function JK(e){return jo(e)&&(64===e.length||65===e.length)}VK.decode=function(e){if(e.key[0]!==zK.InputTypes.TAP_KEY_SIG||1!==e.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+e.key.toString("hex"));if(!JK(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value},VK.encode=function(e){return{key:ao.from([zK.InputTypes.TAP_KEY_SIG]),value:e}},VK.expected="Buffer",VK.check=JK,VK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapKeySig};var YK={};Object.defineProperty(YK,"__esModule",{value:!0});const XK=kK;YK.decode=function(e){if(e.key[0]!==XK.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+e.key.toString("hex"));if((e.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+e.key.toString("hex"));const t=e.value[e.value.length-1];if((254&e.key[1])!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+e.key.toString("hex"));const n=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:n,leafVersion:t}},YK.encode=function(e){const t=ao.from([XK.InputTypes.TAP_LEAF_SCRIPT]),n=ao.from([e.leafVersion]);return{key:ao.concat([t,e.controlBlock]),value:ao.concat([e.script,n])}},YK.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",YK.check=function(e){return jo(e.controlBlock)&&(e.controlBlock.length-1)%32==0&&(254&e.controlBlock[0])===e.leafVersion&&jo(e.script)},YK.canAddToArray=function(e,t,n){const r=t.controlBlock.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.controlBlock.equals(t.controlBlock))).length)};var WK={};Object.defineProperty(WK,"__esModule",{value:!0});const ZK=kK;function $K(e){return jo(e)&&32===e.length}WK.decode=function(e){if(e.key[0]!==ZK.InputTypes.TAP_MERKLE_ROOT||1!==e.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+e.key.toString("hex"));if(!$K(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value},WK.encode=function(e){return{key:ao.from([ZK.InputTypes.TAP_MERKLE_ROOT]),value:e}},WK.expected="Buffer",WK.check=$K,WK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapMerkleRoot};var ej={};Object.defineProperty(ej,"__esModule",{value:!0});const tj=kK;ej.decode=function(e){if(e.key[0]!==tj.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+e.key.toString("hex"));if(65!==e.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+e.key.toString("hex"));if(64!==e.value.length&&65!==e.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+e.key.toString("hex"));return{pubkey:e.key.slice(1,33),leafHash:e.key.slice(33),signature:e.value}},ej.encode=function(e){const t=ao.from([tj.InputTypes.TAP_SCRIPT_SIG]);return{key:ao.concat([t,e.pubkey,e.leafHash]),value:e.signature}},ej.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",ej.check=function(e){return jo(e.pubkey)&&jo(e.leafHash)&&jo(e.signature)&&32===e.pubkey.length&&32===e.leafHash.length&&(64===e.signature.length||65===e.signature.length)},ej.canAddToArray=function(e,t,n){const r=t.pubkey.toString("hex")+t.leafHash.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.pubkey.equals(t.pubkey)&&e.leafHash.equals(t.leafHash))).length)};var nj={},rj={},ij={};function oj(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function aj(e){return oj(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Object.defineProperty(ij,"__esModule",{value:!0}),ij.encode=function e(t,n,r){if(oj(t),n||(n=ao.allocUnsafe(aj(t))),!jo(n))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),t<253?(n.writeUInt8(t,r),Object.assign(e,{bytes:1})):t<=65535?(n.writeUInt8(253,r),n.writeUInt16LE(t,r+1),Object.assign(e,{bytes:3})):t<=4294967295?(n.writeUInt8(254,r),n.writeUInt32LE(t,r+1),Object.assign(e,{bytes:5})):(n.writeUInt8(255,r),n.writeUInt32LE(t>>>0,r+1),n.writeUInt32LE(t/4294967296|0,r+5),Object.assign(e,{bytes:9})),n},ij.decode=function e(t,n){if(!jo(t))throw new TypeError("buffer must be a Buffer instance");n||(n=0);const r=t.readUInt8(n);if(r<253)return Object.assign(e,{bytes:1}),r;if(253===r)return Object.assign(e,{bytes:3}),t.readUInt16LE(n+1);if(254===r)return Object.assign(e,{bytes:5}),t.readUInt32LE(n+1);{Object.assign(e,{bytes:9});const r=t.readUInt32LE(n+1),i=4294967296*t.readUInt32LE(n+5)+r;return oj(i),i}},ij.encodingLength=aj,Object.defineProperty(rj,"__esModule",{value:!0});const sj=ij;function lj(e){const t=e.key.length,n=e.value.length,r=sj.encodingLength(t),i=sj.encodingLength(n),o=ao.allocUnsafe(r+t+i+n);return sj.encode(t,o,0),e.key.copy(o,r),sj.encode(n,o,r+t),e.value.copy(o,r+t+i),o}function uj(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}rj.range=e=>[...Array(e).keys()],rj.reverseBuffer=function(e){if(e.length<1)return e;let t=e.length-1,n=0;for(let r=0;r<e.length/2;r++)n=e[r],e[r]=e[t],e[t]=n,t--;return e},rj.keyValsToBuffer=function(e){const t=e.map(lj);return t.push(ao.from([0])),ao.concat(t)},rj.keyValToBuffer=lj,rj.readUInt64LE=function(e,t){const n=e.readUInt32LE(t);let r=e.readUInt32LE(t+4);return r*=4294967296,uj(r+n,9007199254740991),r+n},rj.writeUInt64LE=function(e,t,n){return uj(t,9007199254740991),e.writeInt32LE(-1&t,n),e.writeUInt32LE(Math.floor(t/4294967296),n+4),n+8},Object.defineProperty(nj,"__esModule",{value:!0});const Aj=kK,cj=rj,hj=ij;nj.decode=function(e){if(e.key[0]!==Aj.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+e.key.toString("hex"));const t=cj.readUInt64LE(e.value,0);let n=8;const r=hj.decode(e.value,n);n+=hj.encodingLength(r);const i=e.value.slice(n);if(i.length!==r)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:i,value:t}},nj.encode=function(e){const{script:t,value:n}=e,r=hj.encodingLength(t.length),i=ao.allocUnsafe(8+r+t.length);return cj.writeUInt64LE(i,n,0),hj.encode(t.length,i,8),t.copy(i,8+r),{key:ao.from([Aj.InputTypes.WITNESS_UTXO]),value:i}},nj.expected="{ script: Buffer; value: number; }",nj.check=function(e){return jo(e.script)&&"number"==typeof e.value},nj.canAdd=function(e,t){return!!e&&!!t&&void 0===e.witnessUtxo};var fj={};Object.defineProperty(fj,"__esModule",{value:!0});const dj=kK,pj=ij;fj.decode=function(e){if(e.key[0]!==dj.OutputTypes.TAP_TREE||1!==e.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+e.key.toString("hex"));let t=0;const n=[];for(;t<e.value.length;){const r=e.value[t++],i=e.value[t++],o=pj.decode(e.value,t);t+=pj.encodingLength(o),n.push({depth:r,leafVersion:i,script:e.value.slice(t,t+o)}),t+=o}return{leaves:n}},fj.encode=function(e){const t=ao.from([dj.OutputTypes.TAP_TREE]),n=[].concat(...e.leaves.map((e=>[ao.of(e.depth,e.leafVersion),pj.encode(e.script.length),e.script])));return{key:t,value:ao.concat(n)}},fj.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",fj.check=function(e){return Array.isArray(e.leaves)&&e.leaves.every((e=>e.depth>=0&&e.depth<=128&&(254&e.leafVersion)===e.leafVersion&&jo(e.script)))},fj.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapTree};var gj={};Object.defineProperty(gj,"__esModule",{value:!0});const yj=e=>33===e.length&&[2,3].includes(e[0])||65===e.length&&4===e[0];gj.makeConverter=function(e,t=yj){return{decode:function(n){if(n.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+n.key.toString("hex"));const r=n.key.slice(1);if(!t(r))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+n.key.toString("hex"));if(n.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:n.value.slice(0,4),pubkey:r,path:"m"};for(const e of(o=n.value.length/4-1,[...Array(o).keys()])){const t=n.value.readUInt32LE(4*e+4),r=!!(2147483648&t),o=2147483647&t;i.path+="/"+o.toString(10)+(r?"'":"")}var o;return i},encode:function(t){const n=ao.from([e]),r=ao.concat([n,t.pubkey]),i=t.path.split("/"),o=ao.allocUnsafe(4*i.length);t.masterFingerprint.copy(o,0);let a=4;return i.slice(1).forEach((e=>{const t="'"===e.slice(-1);let n=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(n+=2147483648),o.writeUInt32LE(n,a),a+=4})),{key:r,value:o}},check:function(e){return jo(e.pubkey)&&jo(e.masterFingerprint)&&"string"==typeof e.path&&t(e.pubkey)&&4===e.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(e,t,n){const r=t.pubkey.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.pubkey.equals(t.pubkey))).length)}}};var mj={};Object.defineProperty(mj,"__esModule",{value:!0}),mj.makeChecker=function(e){return function(t){let n;if(e.includes(t.key[0])&&(n=t.key.slice(1),33!==n.length&&65!==n.length||![2,3,4].includes(n[0])))throw new Error("Format Error: invalid pubkey in key 0x"+t.key.toString("hex"));return n}};var vj={};Object.defineProperty(vj,"__esModule",{value:!0}),vj.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:ao.from([e]),value:t}},check:function(e){return jo(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.redeemScript}}};var Ij={};Object.defineProperty(Ij,"__esModule",{value:!0});const wj=ij,bj=gj,Bj=e=>32===e.length;Ij.makeConverter=function(e){const t=bj.makeConverter(e,Bj);return{decode:function(e){const n=wj.decode(e.value),r=wj.encodingLength(n),i=t.decode({key:e.key,value:e.value.slice(r+32*n)}),o=new Array(n);for(let t=0,i=r;t<n;t++,i+=32)o[t]=e.value.slice(i,i+32);return Object.assign({},i,{leafHashes:o})},encode:function(e){const n=t.encode(e),r=wj.encodingLength(e.leafHashes.length),i=ao.allocUnsafe(r);wj.encode(e.leafHashes.length,i);const o=ao.concat([i,...e.leafHashes,n.value]);return Object.assign({},n,{value:o})},check:function(e){return Array.isArray(e.leafHashes)&&e.leafHashes.every((e=>jo(e)&&32===e.length))&&t.check(e)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:t.canAddToArray}};var Ej={};Object.defineProperty(Ej,"__esModule",{value:!0}),Ej.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e||1!==t.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+t.key.toString("hex"));if(32!==t.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return t.value},encode:function(t){return{key:ao.from([e]),value:t}},check:function(e){return jo(e)&&32===e.length},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.tapInternalKey}}};var Cj={};Object.defineProperty(Cj,"__esModule",{value:!0}),Cj.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:ao.from([e]),value:t}},check:function(e){return jo(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.witnessScript}}},Object.defineProperty(QK,"__esModule",{value:!0});const Sj=kK,xj=PK,Qj=MK,kj=TK,_j=OK,Nj=KK,Dj=GK,Fj=VK,Pj=YK,Uj=WK,Mj=ej,Lj=nj,Tj=fj,Rj=gj,Oj=mj,Hj=vj,Kj=Ij,jj=Ej,Gj=Cj,qj={unsignedTx:DK,globalXpub:_K,checkPubkey:Oj.makeChecker([])};QK.globals=qj;const Vj={nonWitnessUtxo:kj,partialSig:_j,sighashType:Dj,finalScriptSig:xj,finalScriptWitness:Qj,porCommitment:Nj,witnessUtxo:Lj,bip32Derivation:Rj.makeConverter(Sj.InputTypes.BIP32_DERIVATION),redeemScript:Hj.makeConverter(Sj.InputTypes.REDEEM_SCRIPT),witnessScript:Gj.makeConverter(Sj.InputTypes.WITNESS_SCRIPT),checkPubkey:Oj.makeChecker([Sj.InputTypes.PARTIAL_SIG,Sj.InputTypes.BIP32_DERIVATION]),tapKeySig:Fj,tapScriptSig:Mj,tapLeafScript:Pj,tapBip32Derivation:Kj.makeConverter(Sj.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:jj.makeConverter(Sj.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:Uj};QK.inputs=Vj;const zj={bip32Derivation:Rj.makeConverter(Sj.OutputTypes.BIP32_DERIVATION),redeemScript:Hj.makeConverter(Sj.OutputTypes.REDEEM_SCRIPT),witnessScript:Gj.makeConverter(Sj.OutputTypes.WITNESS_SCRIPT),checkPubkey:Oj.makeChecker([Sj.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:Kj.makeConverter(Sj.OutputTypes.TAP_BIP32_DERIVATION),tapTree:Tj,tapInternalKey:jj.makeConverter(Sj.OutputTypes.TAP_INTERNAL_KEY)};QK.outputs=zj,Object.defineProperty(xK,"__esModule",{value:!0});const Jj=QK,Yj=rj,Xj=ij,Wj=kK;function Zj(e,t,n){if(!t.equals(ao.from([n])))throw new Error(`Format Error: Invalid ${e} key: ${t.toString("hex")}`)}function $j(e,{globalMapKeyVals:t,inputKeyVals:n,outputKeyVals:r}){const i={unsignedTx:e};let o=0;for(const e of t)switch(e.key[0]){case Wj.GlobalTypes.UNSIGNED_TX:if(Zj("global",e.key,Wj.GlobalTypes.UNSIGNED_TX),o>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");o++;break;case Wj.GlobalTypes.GLOBAL_XPUB:void 0===i.globalXpub&&(i.globalXpub=[]),i.globalXpub.push(Jj.globals.globalXpub.decode(e));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(e)}const a=n.length,s=r.length,l=[],u=[];for(const e of Yj.range(a)){const t={};for(const r of n[e])switch(Jj.inputs.checkPubkey(r),r.key[0]){case Wj.InputTypes.NON_WITNESS_UTXO:if(Zj("input",r.key,Wj.InputTypes.NON_WITNESS_UTXO),void 0!==t.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");t.nonWitnessUtxo=Jj.inputs.nonWitnessUtxo.decode(r);break;case Wj.InputTypes.WITNESS_UTXO:if(Zj("input",r.key,Wj.InputTypes.WITNESS_UTXO),void 0!==t.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");t.witnessUtxo=Jj.inputs.witnessUtxo.decode(r);break;case Wj.InputTypes.PARTIAL_SIG:void 0===t.partialSig&&(t.partialSig=[]),t.partialSig.push(Jj.inputs.partialSig.decode(r));break;case Wj.InputTypes.SIGHASH_TYPE:if(Zj("input",r.key,Wj.InputTypes.SIGHASH_TYPE),void 0!==t.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");t.sighashType=Jj.inputs.sighashType.decode(r);break;case Wj.InputTypes.REDEEM_SCRIPT:if(Zj("input",r.key,Wj.InputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");t.redeemScript=Jj.inputs.redeemScript.decode(r);break;case Wj.InputTypes.WITNESS_SCRIPT:if(Zj("input",r.key,Wj.InputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");t.witnessScript=Jj.inputs.witnessScript.decode(r);break;case Wj.InputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(Jj.inputs.bip32Derivation.decode(r));break;case Wj.InputTypes.FINAL_SCRIPTSIG:Zj("input",r.key,Wj.InputTypes.FINAL_SCRIPTSIG),t.finalScriptSig=Jj.inputs.finalScriptSig.decode(r);break;case Wj.InputTypes.FINAL_SCRIPTWITNESS:Zj("input",r.key,Wj.InputTypes.FINAL_SCRIPTWITNESS),t.finalScriptWitness=Jj.inputs.finalScriptWitness.decode(r);break;case Wj.InputTypes.POR_COMMITMENT:Zj("input",r.key,Wj.InputTypes.POR_COMMITMENT),t.porCommitment=Jj.inputs.porCommitment.decode(r);break;case Wj.InputTypes.TAP_KEY_SIG:Zj("input",r.key,Wj.InputTypes.TAP_KEY_SIG),t.tapKeySig=Jj.inputs.tapKeySig.decode(r);break;case Wj.InputTypes.TAP_SCRIPT_SIG:void 0===t.tapScriptSig&&(t.tapScriptSig=[]),t.tapScriptSig.push(Jj.inputs.tapScriptSig.decode(r));break;case Wj.InputTypes.TAP_LEAF_SCRIPT:void 0===t.tapLeafScript&&(t.tapLeafScript=[]),t.tapLeafScript.push(Jj.inputs.tapLeafScript.decode(r));break;case Wj.InputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(Jj.inputs.tapBip32Derivation.decode(r));break;case Wj.InputTypes.TAP_INTERNAL_KEY:Zj("input",r.key,Wj.InputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=Jj.inputs.tapInternalKey.decode(r);break;case Wj.InputTypes.TAP_MERKLE_ROOT:Zj("input",r.key,Wj.InputTypes.TAP_MERKLE_ROOT),t.tapMerkleRoot=Jj.inputs.tapMerkleRoot.decode(r);break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(r)}l.push(t)}for(const e of Yj.range(s)){const t={};for(const n of r[e])switch(Jj.outputs.checkPubkey(n),n.key[0]){case Wj.OutputTypes.REDEEM_SCRIPT:if(Zj("output",n.key,Wj.OutputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");t.redeemScript=Jj.outputs.redeemScript.decode(n);break;case Wj.OutputTypes.WITNESS_SCRIPT:if(Zj("output",n.key,Wj.OutputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");t.witnessScript=Jj.outputs.witnessScript.decode(n);break;case Wj.OutputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(Jj.outputs.bip32Derivation.decode(n));break;case Wj.OutputTypes.TAP_INTERNAL_KEY:Zj("output",n.key,Wj.OutputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=Jj.outputs.tapInternalKey.decode(n);break;case Wj.OutputTypes.TAP_TREE:Zj("output",n.key,Wj.OutputTypes.TAP_TREE),t.tapTree=Jj.outputs.tapTree.decode(n);break;case Wj.OutputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(Jj.outputs.tapBip32Derivation.decode(n));break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(n)}u.push(t)}return{globalMap:i,inputs:l,outputs:u}}xK.psbtFromBuffer=function(e,t){let n=0;function r(){const t=Xj.decode(e,n);n+=Xj.encodingLength(t);const r=e.slice(n,n+t);return n+=t,r}function i(){return{key:r(),value:r()}}function o(){if(n>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const t=0===e.readUInt8(n);return t&&n++,t}if(1886610036!==function(){const t=e.readUInt32BE(n);return n+=4,t}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const t=e.readUInt8(n);return n+=1,t}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const a=[],s={};for(;!o();){const e=i(),t=e.key.toString("hex");if(s[t])throw new Error("Format Error: Keys must be unique for global keymap: key "+t);s[t]=1,a.push(e)}const l=a.filter((e=>e.key[0]===Wj.GlobalTypes.UNSIGNED_TX));if(1!==l.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const u=t(l[0].value),{inputCount:A,outputCount:c}=u.getInputOutputCounts(),h=[],f=[];for(const e of Yj.range(A)){const t={},n=[];for(;!o();){const r=i(),o=r.key.toString("hex");if(t[o])throw new Error("Format Error: Keys must be unique for each input: input index "+e+" key "+o);t[o]=1,n.push(r)}h.push(n)}for(const e of Yj.range(c)){const t={},n=[];for(;!o();){const r=i(),o=r.key.toString("hex");if(t[o])throw new Error("Format Error: Keys must be unique for each output: output index "+e+" key "+o);t[o]=1,n.push(r)}f.push(n)}return $j(u,{globalMapKeyVals:a,inputKeyVals:h,outputKeyVals:f})},xK.checkKeyBuffer=Zj,xK.psbtFromKeyVals=$j;var eG={};Object.defineProperty(eG,"__esModule",{value:!0});const tG=QK,nG=rj;eG.psbtToBuffer=function({globalMap:e,inputs:t,outputs:n}){const{globalKeyVals:r,inputKeyVals:i,outputKeyVals:o}=oG({globalMap:e,inputs:t,outputs:n}),a=nG.keyValsToBuffer(r),s=e=>0===e.length?[ao.from([0])]:e.map(nG.keyValsToBuffer),l=s(i),u=s(o),A=ao.allocUnsafe(5);return A.writeUIntBE(482972169471,0,5),ao.concat([A,a].concat(l,u))};const rG=(e,t)=>e.key.compare(t.key);function iG(e,t){const n=new Set,r=Object.entries(e).reduce(((e,[r,i])=>{if("unknownKeyVals"===r)return e;const o=t[r];if(void 0===o)return e;const a=(Array.isArray(i)?i:[i]).map(o.encode);return a.map((e=>e.key.toString("hex"))).forEach((e=>{if(n.has(e))throw new Error("Serialize Error: Duplicate key: "+e);n.add(e)})),e.concat(a)}),[]),i=e.unknownKeyVals?e.unknownKeyVals.filter((e=>!n.has(e.key.toString("hex")))):[];return r.concat(i).sort(rG)}function oG({globalMap:e,inputs:t,outputs:n}){return{globalKeyVals:iG(e,tG.globals),inputKeyVals:t.map((e=>iG(e,tG.inputs))),outputKeyVals:n.map((e=>iG(e,tG.outputs)))}}eG.psbtToKeyVals=oG,function(e){function t(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),t(xK),t(eG)}(SK),Object.defineProperty(CK,"__esModule",{value:!0});const aG=SK;function sG(e,t,n){return r=>{if(e.has(r))return;const i=n.filter((e=>e.key.toString("hex")===r))[0];t.push(i),e.add(r)}}function lG(e){return e.globalMap.unsignedTx}function uG(e){const t=new Set;return e.forEach((e=>{const n=e.key.toString("hex");if(t.has(n))throw new Error("Combine: KeyValue Map keys should be unique");t.add(n)})),t}CK.combine=function(e){const t=e[0],n=aG.psbtToKeyVals(t),r=e.slice(1);if(0===r.length)throw new Error("Combine: Nothing to combine");const i=lG(t);if(void 0===i)throw new Error("Combine: Self missing transaction");const o=uG(n.globalKeyVals),a=n.inputKeyVals.map(uG),s=n.outputKeyVals.map(uG);for(const e of r){const t=lG(e);if(void 0===t||!t.toBuffer().equals(i.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const r=aG.psbtToKeyVals(e);uG(r.globalKeyVals).forEach(sG(o,n.globalKeyVals,r.globalKeyVals)),r.inputKeyVals.map(uG).forEach(((e,t)=>e.forEach(sG(a[t],n.inputKeyVals[t],r.inputKeyVals[t])))),r.outputKeyVals.map(uG).forEach(((e,t)=>e.forEach(sG(s[t],n.outputKeyVals[t],r.outputKeyVals[t]))))}return aG.psbtFromKeyVals(i,{globalMapKeyVals:n.globalKeyVals,inputKeyVals:n.inputKeyVals,outputKeyVals:n.outputKeyVals})};var AG={};!function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=QK;function n(e,t){const n=e[t];if(void 0===n)throw new Error(`No input #${t}`);return n}function r(e,t){const n=e[t];if(void 0===n)throw new Error(`No output #${t}`);return n}function i(e,t,n,r){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${n} and got ${JSON.stringify(r)}`)}function o(e){return(n,r)=>{for(const o of Object.keys(n)){const a=n[o],{canAdd:s,canAddToArray:l,check:u,expected:A}=t[e+"s"][o]||{},c=!!l;if(u)if(c){if(!Array.isArray(a)||r[o]&&!Array.isArray(r[o]))throw new Error(`Key type ${o} must be an array`);a.every(u)||i(e,o,A,a);const t=r[o]||[],n=new Set;if(!a.every((e=>l(t,e,n))))throw new Error("Can not add duplicate data to array");r[o]=t.concat(a)}else{if(u(a)||i(e,o,A,a),!s(r,a))throw new Error(`Can not add duplicate data to ${e}`);r[o]=a}}}}e.checkForInput=n,e.checkForOutput=r,e.checkHasKey=function(e,t,n){if(e.key[0]<n)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&0!==t.filter((t=>t.key.equals(e.key))).length)throw new Error(`Duplicate Key: ${e.key.toString("hex")}`)},e.getEnumLength=function(e){let t=0;return Object.keys(e).forEach((e=>{Number(isNaN(Number(e)))&&t++})),t},e.inputCheckUncleanFinalized=function(e,t){let n=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const e=!!t.redeemScript,r=!!t.witnessScript,i=!e||!!t.finalScriptSig,o=!r||!!t.finalScriptWitness,a=!!t.finalScriptSig||!!t.finalScriptWitness;n=i&&o&&a}if(!1===n)throw new Error(`Input #${e} has too much or too little data to clean`)},e.updateGlobal=o("global"),e.updateInput=o("input"),e.updateOutput=o("output"),e.addInputAttributes=function(t,r){const i=n(t,t.length-1);e.updateInput(r,i)},e.addOutputAttributes=function(t,n){const i=r(t,t.length-1);e.updateOutput(n,i)},e.defaultVersionSetter=function(e,t){if(!jo(t)||t.length<4)throw new Error("Set Version: Invalid Transaction");return t.writeUInt32LE(e,0),t},e.defaultLocktimeSetter=function(e,t){if(!jo(t)||t.length<4)throw new Error("Set Locktime: Invalid Transaction");return t.writeUInt32LE(e,t.length-4),t}}(AG),Object.defineProperty(EK,"__esModule",{value:!0});const cG=CK,hG=SK,fG=kK,dG=AG;EK.Psbt=class{constructor(e){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:e}}static fromBase64(e,t){const n=ao.from(e,"base64");return this.fromBuffer(n,t)}static fromHex(e,t){const n=ao.from(e,"hex");return this.fromBuffer(n,t)}static fromBuffer(e,t){const n=hG.psbtFromBuffer(e,t),r=new this(n.globalMap.unsignedTx);return Object.assign(r,n),r}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return hG.psbtToBuffer(this)}updateGlobal(e){return dG.updateGlobal(e,this.globalMap),this}updateInput(e,t){const n=dG.checkForInput(this.inputs,e);return dG.updateInput(t,n),this}updateOutput(e,t){const n=dG.checkForOutput(this.outputs,e);return dG.updateOutput(t,n),this}addUnknownKeyValToGlobal(e){return dG.checkHasKey(e,this.globalMap.unknownKeyVals,dG.getEnumLength(fG.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(e),this}addUnknownKeyValToInput(e,t){const n=dG.checkForInput(this.inputs,e);return dG.checkHasKey(t,n.unknownKeyVals,dG.getEnumLength(fG.InputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(t),this}addUnknownKeyValToOutput(e,t){const n=dG.checkForOutput(this.outputs,e);return dG.checkHasKey(t,n.unknownKeyVals,dG.getEnumLength(fG.OutputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(t),this}addInput(e){this.globalMap.unsignedTx.addInput(e),this.inputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],n=this.inputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach((e=>this.addUnknownKeyValToInput(n,e))),dG.addInputAttributes(this.inputs,e),this}addOutput(e){this.globalMap.unsignedTx.addOutput(e),this.outputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],n=this.outputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach((e=>this.addUnknownKeyValToInput(n,e))),dG.addOutputAttributes(this.outputs,e),this}clearFinalizedInput(e){const t=dG.checkForInput(this.inputs,e);dG.inputCheckUncleanFinalized(e,t);for(const e of Object.keys(t))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(e)||delete t[e];return this}combine(...e){const t=cG.combine([this].concat(e));return Object.assign(this,t),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}},Object.defineProperty(BK,"__esModule",{value:!0}),BK.Psbt=void 0;const pG=EK,gG=ij,yG=AG,mG=AP,vG=RH,IG=UU,wG=hP,bG=dP,BG=ZH,EG={network:cP.bitcoin,maximumFeeRate:5e3};class CG{constructor(e={},t=new pG.Psbt(new xG)){this.data=t,this.opts=Object.assign({},EG,e),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},0===this.data.inputs.length&&this.setVersion(2);const n=(e,t,n,r)=>Object.defineProperty(e,t,{enumerable:n,writable:r});n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}static fromBase64(e,t={}){const n=ao.from(e,"base64");return this.fromBuffer(n,t)}static fromHex(e,t={}){const n=ao.from(e,"hex");return this.fromBuffer(n,t)}static fromBuffer(e,t={}){const n=pG.Psbt.fromBuffer(e,SG),r=new CG(t,n);return function(e,t){e.ins.forEach((e=>{HG(t,e)}))}(r.__CACHE.__TX,r.__CACHE),r}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(e){this.setVersion(e)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(e){this.setLocktime(e)}get txInputs(){return this.__CACHE.__TX.ins.map((e=>({hash:(0,vG.cloneBuffer)(e.hash),index:e.index,sequence:e.sequence})))}get txOutputs(){return this.__CACHE.__TX.outs.map((e=>{let t;try{t=(0,mG.fromOutputScript)(e.script,this.opts.network)}catch(e){}return{script:(0,vG.cloneBuffer)(e.script),value:e.value,address:t}}))}combine(...e){return this.data.combine(...e.map((e=>e.data))),this}clone(){const e=CG.fromBuffer(this.data.toBuffer());return e.opts=JSON.parse(JSON.stringify(this.opts)),e}setMaximumFeeRate(e){TG(e),this.opts.maximumFeeRate=e}setVersion(e){TG(e),RG(this.data.inputs,"setVersion");const t=this.__CACHE;return t.__TX.version=e,t.__EXTRACTED_TX=void 0,this}setLocktime(e){TG(e),RG(this.data.inputs,"setLocktime");const t=this.__CACHE;return t.__TX.locktime=e,t.__EXTRACTED_TX=void 0,this}setInputSequence(e,t){TG(t),RG(this.data.inputs,"setInputSequence");const n=this.__CACHE;if(n.__TX.ins.length<=e)throw new Error("Input index too high");return n.__TX.ins[e].sequence=t,n.__EXTRACTED_TX=void 0,this}addInputs(e){return e.forEach((e=>this.addInput(e))),this}addInput(e){if(arguments.length>1||!e||void 0===e.hash||void 0===e.index)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");RG(this.data.inputs,"addInput"),e.witnessScript&&rq(e.witnessScript);const t=this.__CACHE;this.data.addInput(e),HG(t,t.__TX.ins[t.__TX.ins.length-1]);const n=this.data.inputs.length-1,r=this.data.inputs[n];return r.nonWitnessUtxo&&WG(this.__CACHE,r,n),t.__FEE=void 0,t.__FEE_RATE=void 0,t.__EXTRACTED_TX=void 0,this}addOutputs(e){return e.forEach((e=>this.addOutput(e))),this}addOutput(e){if(arguments.length>1||!e||void 0===e.value||void 0===e.address&&void 0===e.script)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");RG(this.data.inputs,"addOutput");const{address:t}=e;if("string"==typeof t){const{network:n}=this.opts,r=(0,mG.toOutputScript)(t,n);e=Object.assign(e,{script:r})}const n=this.__CACHE;return this.data.addOutput(e),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(e){if(!this.data.inputs.every(kG))throw new Error("Not finalized");const t=this.__CACHE;if(e||function(e,t,n){const r=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),o=r*i;if(r>=n.maximumFeeRate)throw new Error(`Warning: You are paying around ${(o/1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}(this,t,this.opts),t.__EXTRACTED_TX)return t.__EXTRACTED_TX;const n=t.__TX.clone();return ZG(this.data.inputs,n,t,!0),n}getFeeRate(){return qG("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return qG("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,yG.checkForInput)(this.data.inputs,0),aq(this.data.inputs.length).forEach((e=>this.finalizeInput(e))),this}finalizeInput(e,t=VG){const n=(0,yG.checkForInput)(this.data.inputs,e),{script:r,isP2SH:i,isP2WSH:o,isSegwit:a}=function(e,t,n){const r=n.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const o=$G(n,t,e),a=r.ins[e].index;i.script=o.outs[a].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);return(t.witnessScript||PG(i.script))&&(i.isSegwit=!0),i}(e,n,this.__CACHE);if(!r)throw new Error(`No script found for input #${e}`);!function(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:n}=e;t.forEach((e=>{const{hashType:t}=bG.signature.decode(e.signature);if(n!==t)throw new Error("Signature sighash does not match input sighash type")}))}(n);const{finalScriptSig:s,finalScriptWitness:l}=t(e,n,r,a,i,o);if(s&&this.data.updateInput(e,{finalScriptSig:s}),l&&this.data.updateInput(e,{finalScriptWitness:l}),!s&&!l)throw new Error(`Unknown error finalizing input #${e}`);return this.data.clearFinalizedInput(e),this}getInputType(e){const t=(0,yG.checkForInput)(this.data.inputs,e),n=nq(eq(e,t,this.__CACHE),e,"input",t.redeemScript||function(e){if(!e)return;const t=bG.decompile(e);if(!t)return;const n=t[t.length-1];var r;if(jo(n)&&!tq(n)&&(r=n,!bG.isCanonicalScriptSignature(r))&&bG.decompile(n))return n}(t.finalScriptSig),t.witnessScript||function(e){if(!e)return;const t=XG(e),n=t[t.length-1];return!tq(n)&&bG.decompile(n)?n:void 0}(t.finalScriptWitness));return("raw"===n.type?"":n.type+"-")+oq(n.meaningfulScript)}inputHasPubkey(e,t){return function(e,t,n,r){const i=eq(n,t,r),{meaningfulScript:o}=nq(i,n,"input",t.redeemScript,t.witnessScript);return iq(e,o)}(t,(0,yG.checkForInput)(this.data.inputs,e),e,this.__CACHE)}inputHasHDKey(e,t){const n=(0,yG.checkForInput)(this.data.inputs,e),r=LG(t);return!!n.bip32Derivation&&n.bip32Derivation.some(r)}outputHasPubkey(e,t){return function(e,t,n,r){const i=r.__TX.outs[n].script,{meaningfulScript:o}=nq(i,n,"output",t.redeemScript,t.witnessScript);return iq(e,o)}(t,(0,yG.checkForOutput)(this.data.outputs,e),e,this.__CACHE)}outputHasHDKey(e,t){const n=(0,yG.checkForOutput)(this.data.outputs,e),r=LG(t);return!!n.bip32Derivation&&n.bip32Derivation.some(r)}validateSignaturesOfAllInputs(e){return(0,yG.checkForInput)(this.data.inputs,0),aq(this.data.inputs.length).map((t=>this.validateSignaturesOfInput(t,e))).reduce(((e,t)=>!0===t&&e),!0)}validateSignaturesOfInput(e,t,n){const r=this.data.inputs[e],i=(r||{}).partialSig;if(!r||!i||i.length<1)throw new Error("No signatures to validate");if("function"!=typeof t)throw new Error("Need validator function to validate signatures");const o=n?i.filter((e=>e.pubkey.equals(n))):i;if(o.length<1)throw new Error("No signatures for this pubkey");const a=[];let s,l,u;for(const n of o){const i=bG.signature.decode(n.signature),{hash:o,script:A}=u!==i.hashType?JG(e,Object.assign({},r,{sighashType:i.hashType}),this.__CACHE,!0):{hash:s,script:l};u=i.hashType,s=o,l=A,OG(n.pubkey,A,"verify"),a.push(t(n.pubkey,o,i.signature))}return a.every((e=>!0===e))}signAllInputsHD(e,t=[BG.Transaction.SIGHASH_ALL]){if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");const n=[];for(const r of aq(this.data.inputs.length))try{this.signInputHD(r,e,t),n.push(!0)}catch(e){n.push(!1)}if(n.every((e=>!1===e)))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(e,t=[BG.Transaction.SIGHASH_ALL]){return new Promise(((n,r)=>{if(!e||!e.publicKey||!e.fingerprint)return r(new Error("Need HDSigner to sign input"));const i=[],o=[];for(const n of aq(this.data.inputs.length))o.push(this.signInputHDAsync(n,e,t).then((()=>{i.push(!0)}),(()=>{i.push(!1)})));return Promise.all(o).then((()=>{if(i.every((e=>!1===e)))return r(new Error("No inputs were signed"));n()}))}))}signInputHD(e,t,n=[BG.Transaction.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");return YG(e,this.data.inputs,t).forEach((t=>this.signInput(e,t,n))),this}signInputHDAsync(e,t,n=[BG.Transaction.SIGHASH_ALL]){return new Promise(((r,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const o=YG(e,this.data.inputs,t).map((t=>this.signInputAsync(e,t,n)));return Promise.all(o).then((()=>{r()})).catch(i)}))}signAllInputs(e,t=[BG.Transaction.SIGHASH_ALL]){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");const n=[];for(const r of aq(this.data.inputs.length))try{this.signInput(r,e,t),n.push(!0)}catch(e){n.push(!1)}if(n.every((e=>!1===e)))throw new Error("No inputs were signed");return this}signAllInputsAsync(e,t=[BG.Transaction.SIGHASH_ALL]){return new Promise(((n,r)=>{if(!e||!e.publicKey)return r(new Error("Need Signer to sign input"));const i=[],o=[];for(const[n]of this.data.inputs.entries())o.push(this.signInputAsync(n,e,t).then((()=>{i.push(!0)}),(()=>{i.push(!1)})));return Promise.all(o).then((()=>{if(i.every((e=>!1===e)))return r(new Error("No inputs were signed"));n()}))}))}signInput(e,t,n=[BG.Transaction.SIGHASH_ALL]){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const{hash:r,sighashType:i}=zG(this.data.inputs,e,t.publicKey,this.__CACHE,n),o=[{pubkey:t.publicKey,signature:bG.signature.encode(t.sign(r),i)}];return this.data.updateInput(e,{partialSig:o}),this}signInputAsync(e,t,n=[BG.Transaction.SIGHASH_ALL]){return Promise.resolve().then((()=>{if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const{hash:r,sighashType:i}=zG(this.data.inputs,e,t.publicKey,this.__CACHE,n);return Promise.resolve(t.sign(r)).then((n=>{const r=[{pubkey:t.publicKey,signature:bG.signature.encode(n,i)}];this.data.updateInput(e,{partialSig:r})}))}))}toBuffer(){return QG(this.__CACHE),this.data.toBuffer()}toHex(){return QG(this.__CACHE),this.data.toHex()}toBase64(){return QG(this.__CACHE),this.data.toBase64()}updateGlobal(e){return this.data.updateGlobal(e),this}updateInput(e,t){return t.witnessScript&&rq(t.witnessScript),this.data.updateInput(e,t),t.nonWitnessUtxo&&WG(this.__CACHE,this.data.inputs[e],e),this}updateOutput(e,t){return this.data.updateOutput(e,t),this}addUnknownKeyValToGlobal(e){return this.data.addUnknownKeyValToGlobal(e),this}addUnknownKeyValToInput(e,t){return this.data.addUnknownKeyValToInput(e,t),this}addUnknownKeyValToOutput(e,t){return this.data.addUnknownKeyValToOutput(e,t),this}clearFinalizedInput(e){return this.data.clearFinalizedInput(e),this}}BK.Psbt=CG;const SG=e=>new xG(e);class xG{constructor(e=ao.from([2,0,0,0,0,0,0,0,0,0])){this.tx=BG.Transaction.fromBuffer(e),function(e){if(!e.ins.every((e=>e.script&&0===e.script.length&&e.witness&&0===e.witness.length)))throw new Error("Format Error: Transaction ScriptSigs are not empty")}(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(e){if(void 0===e.hash||void 0===e.index||!jo(e.hash)&&"string"!=typeof e.hash||"number"!=typeof e.index)throw new Error("Error adding input.");const t="string"==typeof e.hash?(0,vG.reverseBuffer)(ao.from(e.hash,"hex")):e.hash;this.tx.addInput(t,e.index,e.sequence)}addOutput(e){if(void 0===e.script||void 0===e.value||!jo(e.script)||"number"!=typeof e.value)throw new Error("Error adding output.");this.tx.addOutput(e.script,e.value)}toBuffer(){return this.tx.toBuffer()}}function QG(e){if(!1!==e.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function kG(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function _G(e){return t=>{try{return e({output:t}),!0}catch(e){return!1}}}const NG=_G(wG.p2ms),DG=_G(wG.p2pk),FG=_G(wG.p2pkh),PG=_G(wG.p2wpkh),UG=_G(wG.p2wsh),MG=_G(wG.p2sh);function LG(e){return t=>!!t.masterFingerprint.equals(e.fingerprint)&&!!e.derivePath(t.path).publicKey.equals(t.pubkey)}function TG(e){if("number"!=typeof e||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function RG(e,t){e.forEach((e=>{let n=!1,r=[];if(0===(e.partialSig||[]).length){if(!e.finalScriptSig&&!e.finalScriptWitness)return;r=function(e){const t=e.finalScriptSig&&bG.decompile(e.finalScriptSig)||[],n=e.finalScriptWitness&&bG.decompile(e.finalScriptWitness)||[];return t.concat(n).filter((e=>jo(e)&&bG.isCanonicalScriptSignature(e))).map((e=>({signature:e})))}(e)}else r=e.partialSig;if(r.forEach((e=>{const{hashType:r}=bG.signature.decode(e.signature),i=[];switch(r&BG.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&r){case BG.Transaction.SIGHASH_ALL:break;case BG.Transaction.SIGHASH_SINGLE:case BG.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}-1===i.indexOf(t)&&(n=!0)})),n)throw new Error("Can not modify transaction, signatures exist.")}))}function OG(e,t,n){if(!iq(e,t))throw new Error(`Can not ${n} for this input with the key ${e.toString("hex")}`)}function HG(e,t){const n=(0,vG.reverseBuffer)(ao.from(t.hash)).toString("hex")+":"+t.index;if(e.__TX_IN_CACHE[n])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[n]=1}function KG(e,t){return(n,r,i,o)=>{const a=e({redeem:{output:i}}).output;if(!r.equals(a))throw new Error(`${t} for ${o} #${n} doesn't match the scriptPubKey in the prevout`)}}const jG=KG(wG.p2sh,"Redeem script"),GG=KG(wG.p2wsh,"Witness script");function qG(e,t,n,r){if(!n.every(kG))throw new Error(`PSBT must be finalized to calculate ${t}`);if("__FEE_RATE"===e&&r.__FEE_RATE)return r.__FEE_RATE;if("__FEE"===e&&r.__FEE)return r.__FEE;let i,o=!0;return r.__EXTRACTED_TX?(i=r.__EXTRACTED_TX,o=!1):i=r.__TX.clone(),ZG(n,i,r,o),"__FEE_RATE"===e?r.__FEE_RATE:"__FEE"===e?r.__FEE:void 0}function VG(e,t,n,r,i,o){oq(n);throw new Error(`Can not finalize input #${e}`)}function zG(e,t,n,r,i){const o=(0,yG.checkForInput)(e,t),{hash:a,sighashType:s,script:l}=JG(t,o,r,!1,i);return OG(n,l,"sign"),{hash:a,sighashType:s}}function JG(e,t,n,r,i){const o=n.__TX,a=t.sighashType||BG.Transaction.SIGHASH_ALL;if(i&&i.indexOf(a)<0){const e=function(e){let t=e&BG.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&e){case BG.Transaction.SIGHASH_ALL:t+="SIGHASH_ALL";break;case BG.Transaction.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case BG.Transaction.SIGHASH_NONE:t+="SIGHASH_NONE"}return t}(a);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${e}`)}let s,l;if(t.nonWitnessUtxo){const r=$G(n,t,e),i=o.ins[e].hash,a=r.getHash();if(!i.equals(a))throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const s=o.ins[e].index;l=r.outs[s]}else{if(!t.witnessUtxo)throw new Error("Need a Utxo input item for signing");l=t.witnessUtxo}const{meaningfulScript:u,type:A}=nq(l.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(A)>=0)s=o.hashForWitnessV0(e,u,l.value,a);else if(PG(u)){const t=wG.p2pkh({hash:u.slice(2)}).output;s=o.hashForWitnessV0(e,t,l.value,a)}else{if(void 0===t.nonWitnessUtxo&&!1===n.__UNSAFE_SIGN_NONSEGWIT)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${u.toString("hex")}`);r||!1===n.__UNSAFE_SIGN_NONSEGWIT||console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecesor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),s=o.hashForSignature(e,u,a)}return{script:u,sighashType:a,hash:s}}function YG(e,t,n){const r=(0,yG.checkForInput)(t,e);if(!r.bip32Derivation||0===r.bip32Derivation.length)throw new Error("Need bip32Derivation to sign with HD");const i=r.bip32Derivation.map((e=>e.masterFingerprint.equals(n.fingerprint)?e:void 0)).filter((e=>!!e));if(0===i.length)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");const o=i.map((e=>{const t=n.derivePath(e.path);if(!e.pubkey.equals(t.publicKey))throw new Error("pubkey did not match bip32Derivation");return t}));return o}function XG(e){let t=0;function n(){const n=gG.decode(e,t);return t+=gG.decode.bytes,n}function r(){return r=n(),t+=r,e.slice(t-r,t);var r}return function(){const e=n(),t=[];for(let n=0;n<e;n++)t.push(r());return t}()}function WG(e,t,n){e.__NON_WITNESS_UTXO_BUF_CACHE[n]=t.nonWitnessUtxo;const r=BG.Transaction.fromBuffer(t.nonWitnessUtxo);e.__NON_WITNESS_UTXO_TX_CACHE[n]=r;const i=e,o=n;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const e=i.__NON_WITNESS_UTXO_BUF_CACHE[o],t=i.__NON_WITNESS_UTXO_TX_CACHE[o];if(void 0!==e)return e;{const e=t.toBuffer();return i.__NON_WITNESS_UTXO_BUF_CACHE[o]=e,e}},set(e){i.__NON_WITNESS_UTXO_BUF_CACHE[o]=e}})}function ZG(e,t,n,r){let i=0;e.forEach(((e,o)=>{if(r&&e.finalScriptSig&&(t.ins[o].script=e.finalScriptSig),r&&e.finalScriptWitness&&(t.ins[o].witness=XG(e.finalScriptWitness)),e.witnessUtxo)i+=e.witnessUtxo.value;else if(e.nonWitnessUtxo){const r=$G(n,e,o),a=t.ins[o].index,s=r.outs[a];i+=s.value}}));const o=t.outs.reduce(((e,t)=>e+t.value),0),a=i-o;if(a<0)throw new Error("Outputs are spending more than Inputs");const s=t.virtualSize();n.__FEE=a,n.__EXTRACTED_TX=t,n.__FEE_RATE=Math.floor(a/s)}function $G(e,t,n){const r=e.__NON_WITNESS_UTXO_TX_CACHE;return r[n]||WG(e,t,n),r[n]}function eq(e,t,n){if(void 0!==t.witnessUtxo)return t.witnessUtxo.script;if(void 0!==t.nonWitnessUtxo)return $G(n,t,e).outs[n.__TX.ins[e].index].script;throw new Error("Can't find pubkey in input without Utxo data")}function tq(e){return 33===e.length&&bG.isCanonicalPubKey(e)}function nq(e,t,n,r,i){const o=MG(e),a=o&&r&&UG(r),s=UG(e);if(o&&void 0===r)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((s||a)&&void 0===i)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let l;return a?(l=i,jG(t,e,r,n),GG(t,r,i,n),rq(l)):s?(l=i,GG(t,e,i,n),rq(l)):o?(l=r,jG(t,e,r,n)):l=e,{meaningfulScript:l,type:a?"p2sh-p2wsh":o?"p2sh":s?"p2wsh":"raw"}}function rq(e){if(PG(e)||MG(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function iq(e,t){const n=(0,IG.hash160)(e),r=bG.decompile(t);if(null===r)throw new Error("Unknown script error");return r.some((t=>"number"!=typeof t&&(t.equals(e)||t.equals(n))))}function oq(e){return PG(e)?"witnesspubkeyhash":FG(e)?"pubkeyhash":NG(e)?"multisig":DG(e)?"pubkey":"nonstandard"}function aq(e){return[...Array(e).keys()]}!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=AP;e.address=t;const n=UU;e.crypto=n;const r=cP;e.networks=r;const i=hP;e.payments=i;const o=dP;e.script=o;var a=TH;Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return a.Block}});var s=BK;Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return s.Psbt}});var l=gP;Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return l.OPS}});var u=ZH;Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}})}(uP);var sq={exports:{}};function lq(e,t){const n=(e=>{const t=(e=>{const t=aP.from(Object.assign(Object.assign({},e),{crv:"K-256"}),"jwk").toString("blk","public"),n=AC.publicKeyConvert(lP.from(t,"hex"),!0);return lP.from(n).toString("hex")})(e);let n=lP.from(t,"hex"),r=32-n.length;for(;r>0;)n=lP.concat([lP.from("00","hex"),n]),r--;return n})(e.publicKeyJwk),r=sD("errors","identityErrorBaseMessage");let i="";switch(t.code){case Ol.Bitcoin:case Ol.Mocknet:case Ol.Testnet:i=function(e,t){return uP.payments.p2pkh({pubkey:e,network:uP.networks[t.code]}).address}(n,t);break;case Ol.Ethmain:case Ol.Ethropst:case Ol.Ethrinkeby:case Ol.Ethgoerli:case Ol.Ethsepolia:i=function(e,t){const n=e.toString("hex"),r=new ww.ec("secp256k1").keyFromPublic(n,"hex").getPublic().encode("hex").slice(2),i=ao;return`0x${sq.exports.keccak256(i.from(r,"hex")).slice(24).toString()}`}(n);break;default:throw new iD("deriveIssuingAddressFromPublicKey",`${r} - ${sD("errors","deriveIssuingAddressFromPublicKey")}`)}return i}function uq(e){if(e){const t="string"==typeof e?e:e.code;return!!Object.keys(jl).some((e=>e===t))&&!!jl[t].test}return!1}!function(e){!function(){var t="input is invalid type",n="object"==typeof window,r=n?window:{};r.JS_SHA3_NO_WINDOW&&(n=!1);var i=!n&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof gu&&gu.versions&&gu.versions.node?r=Ki:i&&(r=self);var o=!r.JS_SHA3_NO_COMMON_JS&&e.exports,a=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,s="0123456789abcdef".split(""),l=[4,1024,262144,67108864],u=[0,8,16,24],A=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],c=[224,256,384,512],h=[128,256],f=["hex","buffer","arrayBuffer","array","digest"],d={128:168,256:136};!r.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!a||!r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer});for(var p=function(e,t,n){return function(r){return new _(e,t,e).update(r)[n]()}},g=function(e,t,n){return function(r,i){return new _(e,t,i).update(r)[n]()}},y=function(e,t,n){return function(t,r,i,o){return b["cshake"+e].update(t,r,i,o)[n]()}},m=function(e,t,n){return function(t,r,i,o){return b["kmac"+e].update(t,r,i,o)[n]()}},v=function(e,t,n,r){for(var i=0;i<f.length;++i){var o=f[i];e[o]=t(n,r,o)}return e},I=function(e,t){var n=p(e,t,"hex");return n.create=function(){return new _(e,t,e)},n.update=function(e){return n.create().update(e)},v(n,p,e,t)},w=[{name:"keccak",padding:[1,256,65536,16777216],bits:c,createMethod:I},{name:"sha3",padding:[6,1536,393216,100663296],bits:c,createMethod:I},{name:"shake",padding:[31,7936,2031616,520093696],bits:h,createMethod:function(e,t){var n=g(e,t,"hex");return n.create=function(n){return new _(e,t,n)},n.update=function(e,t){return n.create(t).update(e)},v(n,g,e,t)}},{name:"cshake",padding:l,bits:h,createMethod:function(e,t){var n=d[e],r=y(e,0,"hex");return r.create=function(r,i,o){return i||o?new _(e,t,r).bytepad([i,o],n):b["shake"+e].create(r)},r.update=function(e,t,n,i){return r.create(t,n,i).update(e)},v(r,y,e,t)}},{name:"kmac",padding:l,bits:h,createMethod:function(e,t){var n=d[e],r=m(e,0,"hex");return r.create=function(r,i,o){return new N(e,t,i).bytepad(["KMAC",o],n).bytepad([r],n)},r.update=function(e,t,n,i){return r.create(e,n,i).update(t)},v(r,m,e,t)}}],b={},B=[],E=0;E<w.length;++E)for(var C=w[E],S=C.bits,x=0;x<S.length;++x){var Q=C.name+"_"+S[x];if(B.push(Q),b[Q]=C.createMethod(S[x],C.padding),"sha3"!==C.name){var k=C.name+S[x];B.push(k),b[k]=b[Q]}}function _(e,t,n){this.blocks=[],this.s=[],this.padding=t,this.outputBits=n,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0}function N(e,t,n){_.call(this,e,t,n)}_.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var n,r=typeof e;if("string"!==r){if("object"!==r)throw new Error(t);if(null===e)throw new Error(t);if(a&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||a&&ArrayBuffer.isView(e)))throw new Error(t);n=!0}for(var i,o,s=this.blocks,l=this.byteCount,A=e.length,c=this.blockCount,h=0,f=this.s;h<A;){if(this.reset)for(this.reset=!1,s[0]=this.block,i=1;i<c+1;++i)s[i]=0;if(n)for(i=this.start;h<A&&i<l;++h)s[i>>2]|=e[h]<<u[3&i++];else for(i=this.start;h<A&&i<l;++h)(o=e.charCodeAt(h))<128?s[i>>2]|=o<<u[3&i++]:o<2048?(s[i>>2]|=(192|o>>6)<<u[3&i++],s[i>>2]|=(128|63&o)<<u[3&i++]):o<55296||o>=57344?(s[i>>2]|=(224|o>>12)<<u[3&i++],s[i>>2]|=(128|o>>6&63)<<u[3&i++],s[i>>2]|=(128|63&o)<<u[3&i++]):(o=65536+((1023&o)<<10|1023&e.charCodeAt(++h)),s[i>>2]|=(240|o>>18)<<u[3&i++],s[i>>2]|=(128|o>>12&63)<<u[3&i++],s[i>>2]|=(128|o>>6&63)<<u[3&i++],s[i>>2]|=(128|63&o)<<u[3&i++]);if(this.lastByteIndex=i,i>=l){for(this.start=i-l,this.block=s[c],i=0;i<c;++i)f[i]^=s[i];D(f),this.reset=!0}else this.start=i}return this},_.prototype.encode=function(e,t){var n=255&e,r=1,i=[n];for(n=255&(e>>=8);n>0;)i.unshift(n),n=255&(e>>=8),++r;return t?i.push(r):i.unshift(r),this.update(i),i.length},_.prototype.encodeString=function(e){var n,r=typeof e;if("string"!==r){if("object"!==r)throw new Error(t);if(null===e)throw new Error(t);if(a&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||a&&ArrayBuffer.isView(e)))throw new Error(t);n=!0}var i=0,o=e.length;if(n)i=o;else for(var s=0;s<e.length;++s){var l=e.charCodeAt(s);l<128?i+=1:l<2048?i+=2:l<55296||l>=57344?i+=3:(l=65536+((1023&l)<<10|1023&e.charCodeAt(++s)),i+=4)}return i+=this.encode(8*i),this.update(e),i},_.prototype.bytepad=function(e,t){for(var n=this.encode(t),r=0;r<e.length;++r)n+=this.encodeString(e[r]);var i=t-n%t,o=[];return o.length=i,this.update(o),this},_.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex,n=this.blockCount,r=this.s;if(e[t>>2]|=this.padding[3&t],this.lastByteIndex===this.byteCount)for(e[0]=e[n],t=1;t<n+1;++t)e[t]=0;for(e[n-1]|=2147483648,t=0;t<n;++t)r[t]^=e[t];D(r)}},_.prototype.toString=_.prototype.hex=function(){this.finalize();for(var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,o=0,a=0,l="";a<r;){for(o=0;o<t&&a<r;++o,++a)e=n[o],l+=s[e>>4&15]+s[15&e]+s[e>>12&15]+s[e>>8&15]+s[e>>20&15]+s[e>>16&15]+s[e>>28&15]+s[e>>24&15];a%t==0&&(D(n),o=0)}return i&&(e=n[o],l+=s[e>>4&15]+s[15&e],i>1&&(l+=s[e>>12&15]+s[e>>8&15]),i>2&&(l+=s[e>>20&15]+s[e>>16&15])),l},_.prototype.arrayBuffer=function(){this.finalize();var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,o=0,a=0,s=this.outputBits>>3;e=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(s);for(var l=new Uint32Array(e);a<r;){for(o=0;o<t&&a<r;++o,++a)l[a]=n[o];a%t==0&&D(n)}return i&&(l[o]=n[o],e=e.slice(0,s)),e},_.prototype.buffer=_.prototype.arrayBuffer,_.prototype.digest=_.prototype.array=function(){this.finalize();for(var e,t,n=this.blockCount,r=this.s,i=this.outputBlocks,o=this.extraBytes,a=0,s=0,l=[];s<i;){for(a=0;a<n&&s<i;++a,++s)e=s<<2,t=r[a],l[e]=255&t,l[e+1]=t>>8&255,l[e+2]=t>>16&255,l[e+3]=t>>24&255;s%n==0&&D(r)}return o&&(e=s<<2,t=r[a],l[e]=255&t,o>1&&(l[e+1]=t>>8&255),o>2&&(l[e+2]=t>>16&255)),l},N.prototype=new _,N.prototype.finalize=function(){return this.encode(this.outputBits,!0),_.prototype.finalize.call(this)};var D=function(e){var t,n,r,i,o,a,s,l,u,c,h,f,d,p,g,y,m,v,I,w,b,B,E,C,S,x,Q,k,_,N,D,F,P,U,M,L,T,R,O,H,K,j,G,q,V,z,J,Y,X,W,Z,$,ee,te,ne,re,ie,oe,ae,se,le,ue,Ae;for(r=0;r<48;r+=2)i=e[0]^e[10]^e[20]^e[30]^e[40],o=e[1]^e[11]^e[21]^e[31]^e[41],a=e[2]^e[12]^e[22]^e[32]^e[42],s=e[3]^e[13]^e[23]^e[33]^e[43],l=e[4]^e[14]^e[24]^e[34]^e[44],u=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],h=e[7]^e[17]^e[27]^e[37]^e[47],t=(f=e[8]^e[18]^e[28]^e[38]^e[48])^(a<<1|s>>>31),n=(d=e[9]^e[19]^e[29]^e[39]^e[49])^(s<<1|a>>>31),e[0]^=t,e[1]^=n,e[10]^=t,e[11]^=n,e[20]^=t,e[21]^=n,e[30]^=t,e[31]^=n,e[40]^=t,e[41]^=n,t=i^(l<<1|u>>>31),n=o^(u<<1|l>>>31),e[2]^=t,e[3]^=n,e[12]^=t,e[13]^=n,e[22]^=t,e[23]^=n,e[32]^=t,e[33]^=n,e[42]^=t,e[43]^=n,t=a^(c<<1|h>>>31),n=s^(h<<1|c>>>31),e[4]^=t,e[5]^=n,e[14]^=t,e[15]^=n,e[24]^=t,e[25]^=n,e[34]^=t,e[35]^=n,e[44]^=t,e[45]^=n,t=l^(f<<1|d>>>31),n=u^(d<<1|f>>>31),e[6]^=t,e[7]^=n,e[16]^=t,e[17]^=n,e[26]^=t,e[27]^=n,e[36]^=t,e[37]^=n,e[46]^=t,e[47]^=n,t=c^(i<<1|o>>>31),n=h^(o<<1|i>>>31),e[8]^=t,e[9]^=n,e[18]^=t,e[19]^=n,e[28]^=t,e[29]^=n,e[38]^=t,e[39]^=n,e[48]^=t,e[49]^=n,p=e[0],g=e[1],z=e[11]<<4|e[10]>>>28,J=e[10]<<4|e[11]>>>28,k=e[20]<<3|e[21]>>>29,_=e[21]<<3|e[20]>>>29,se=e[31]<<9|e[30]>>>23,le=e[30]<<9|e[31]>>>23,j=e[40]<<18|e[41]>>>14,G=e[41]<<18|e[40]>>>14,U=e[2]<<1|e[3]>>>31,M=e[3]<<1|e[2]>>>31,y=e[13]<<12|e[12]>>>20,m=e[12]<<12|e[13]>>>20,Y=e[22]<<10|e[23]>>>22,X=e[23]<<10|e[22]>>>22,N=e[33]<<13|e[32]>>>19,D=e[32]<<13|e[33]>>>19,ue=e[42]<<2|e[43]>>>30,Ae=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,L=e[14]<<6|e[15]>>>26,T=e[15]<<6|e[14]>>>26,v=e[25]<<11|e[24]>>>21,I=e[24]<<11|e[25]>>>21,W=e[34]<<15|e[35]>>>17,Z=e[35]<<15|e[34]>>>17,F=e[45]<<29|e[44]>>>3,P=e[44]<<29|e[45]>>>3,C=e[6]<<28|e[7]>>>4,S=e[7]<<28|e[6]>>>4,re=e[17]<<23|e[16]>>>9,ie=e[16]<<23|e[17]>>>9,R=e[26]<<25|e[27]>>>7,O=e[27]<<25|e[26]>>>7,w=e[36]<<21|e[37]>>>11,b=e[37]<<21|e[36]>>>11,$=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,q=e[8]<<27|e[9]>>>5,V=e[9]<<27|e[8]>>>5,x=e[18]<<20|e[19]>>>12,Q=e[19]<<20|e[18]>>>12,oe=e[29]<<7|e[28]>>>25,ae=e[28]<<7|e[29]>>>25,H=e[38]<<8|e[39]>>>24,K=e[39]<<8|e[38]>>>24,B=e[48]<<14|e[49]>>>18,E=e[49]<<14|e[48]>>>18,e[0]=p^~y&v,e[1]=g^~m&I,e[10]=C^~x&k,e[11]=S^~Q&_,e[20]=U^~L&R,e[21]=M^~T&O,e[30]=q^~z&Y,e[31]=V^~J&X,e[40]=te^~re&oe,e[41]=ne^~ie&ae,e[2]=y^~v&w,e[3]=m^~I&b,e[12]=x^~k&N,e[13]=Q^~_&D,e[22]=L^~R&H,e[23]=T^~O&K,e[32]=z^~Y&W,e[33]=J^~X&Z,e[42]=re^~oe&se,e[43]=ie^~ae&le,e[4]=v^~w&B,e[5]=I^~b&E,e[14]=k^~N&F,e[15]=_^~D&P,e[24]=R^~H&j,e[25]=O^~K&G,e[34]=Y^~W&$,e[35]=X^~Z&ee,e[44]=oe^~se&ue,e[45]=ae^~le&Ae,e[6]=w^~B&p,e[7]=b^~E&g,e[16]=N^~F&C,e[17]=D^~P&S,e[26]=H^~j&U,e[27]=K^~G&M,e[36]=W^~$&q,e[37]=Z^~ee&V,e[46]=se^~ue&te,e[47]=le^~Ae&ne,e[8]=B^~p&y,e[9]=E^~g&m,e[18]=F^~C&x,e[19]=P^~S&Q,e[28]=j^~U&L,e[29]=G^~M&T,e[38]=$^~q&z,e[39]=ee^~V&J,e[48]=ue^~te&re,e[49]=Ae^~ne&ie,e[0]^=A[r],e[1]^=A[r+1]};if(o)e.exports=b;else for(E=0;E<B.length;++E)r[B[E]]=b[B[E]]}()}(sq);var Aq=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){e.done?i(e.value):function(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(a,s)}l((r=r.apply(e,t||[])).next())}))};const{LinkedDataProof:cq}=JN.suites;class hq extends cq{constructor({issuer:e=null,verificationMethod:t=null,document:n=null,proof:r=null,options:i={}}){if(super({type:"MerkleProof2019"}),this.type="MerkleProof2019",this.issuer=null,this.verificationMethod=null,this.proof=null,this.proofValue=null,this.document=null,this.explorerAPIs=[],this.documentLoader=null,this.proofVerificationProcess=["getTransactionId","computeLocalHash","fetchRemoteHash","compareHashes","checkMerkleRoot","checkReceipt"],this.identityVerificationProcess=["deriveIssuingAddressFromPublicKey","compareIssuingAddress"],this.transactionId="",!n)throw new Error("A document signed by MerkleProof2019 is required for the verification process.");this.issuer=e,this.verificationMethod=t,this.document=n,this.setProof(r),this.setOptions(i),this.getChain()}static decodeMerkleProof2019(e){return new Z_(e.proofValue).decode()}setProof(e=null){const t=null!=e?e:this.document.proof;if(!t)throw new Error("The passed document is not signed.");this.proof=t,this.proofValue=hq.decodeMerkleProof2019(this.proof)}verifyProof({documentLoader:e,verifyIdentity:t}={documentLoader:e=>{},verifyIdentity:!0}){return Aq(this,void 0,void 0,(function*(){let n;this.documentLoader=e;let r="";uq(this.chain)&&(this.adaptProofVerificationProcessToMocknet(),this.adaptIdentityVerificationProcessToMocknet());try{yield this.verifyProcess(this.proofVerificationProcess),t&&(yield this.verifyIdentity()),n=!0}catch(e){console.error(e),n=!1,r=e.message}return{verificationMethod:this.verificationMethod,verified:n,error:r}}))}verifyIdentity(){return Aq(this,void 0,void 0,(function*(){if(null!=this.verificationMethod)try{yield this.verifyProcess(this.identityVerificationProcess)}catch(e){throw new Error(e)}}))}getProofVerificationProcess(){return this.proofVerificationProcess}getIdentityVerificationProcess(){return this.identityVerificationProcess}getIssuerPublicKey(){var e,t;return uq(this.chain)?"This mock chain does not support issuing addresses":null!==(t=null===(e=this.getTxData())||void 0===e?void 0:e.issuingAddress)&&void 0!==t?t:""}getIssuanceTime(){var e,t;return null!==(t=null===(e=this.getTxData())||void 0===e?void 0:e.time)&&void 0!==t?t:""}getChain(){return this.chain||(this.chain=function(e=null){if(null==e?void 0:e.anchors){const{anchors:t}=e,n=t[0];if("string"==typeof n)return function(e){const t=e.split(":");let n;switch(t[1]){case jl.mocknet.blinkCode:return ZN(jl.mocknet.signatureValue);case jl.bitcoin.blinkCode:n=jl.bitcoin.name;break;case jl.ethmain.blinkCode:n=jl.ethmain.name;break;default:throw new Error("Could not retrieve chain.")}const r=t[2],i=n.toLowerCase()+function(e){const t=e.substr(0,1),n=e.substr(1,e.length-1);return t.toUpperCase()+n.toLowerCase()}(r);return ZN(i)}(n)}return null}(this.proofValue)),this.chain}getTxData(){return this.txData?this.txData:(console.error("Trying to access issuing address when txData not available yet. Did you run the `verify` method yet?"),null)}adaptProofVerificationProcessToMocknet(){$N(this.proofVerificationProcess,"getTransactionId"),$N(this.proofVerificationProcess,"fetchRemoteHash"),$N(this.proofVerificationProcess,"checkMerkleRoot")}adaptIdentityVerificationProcessToMocknet(){this.identityVerificationProcess=[]}setOptions(e){var t;this.explorerAPIs=null!==(t=e.explorerAPIs)&&void 0!==t?t:[],e.executeStepMethod&&"function"==typeof e.executeStepMethod&&(this.executeStep=e.executeStepMethod)}executeStep(e,t,n=""){return Aq(this,void 0,void 0,(function*(){return yield t()}))}verifyProcess(e){return Aq(this,void 0,void 0,(function*(){for(const t of e){if(!this[t])return void console.error("verification logic for",t,"not implemented");yield this[t]()}}))}checkMerkleRoot(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("checkMerkleRoot",(()=>function(e,t){if(e!==t)throw new iD("checkMerkleRoot",sD("errors","ensureMerkleRootEqual"));return!0}(this.proofValue.merkleRoot,this.txData.remoteHash)),this.type)}))}compareHashes(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("compareHashes",(()=>function(e,t){if(e!==t)throw new iD("compareHashes",sD("errors","ensureHashesEqual"));return!0}(this.localDocumentHash,this.proofValue.targetHash)),this.type)}))}computeLocalHash(){return Aq(this,void 0,void 0,(function*(){this.localDocumentHash=yield this.executeStep("computeLocalHash",(()=>Aq(this,void 0,void 0,(function*(){return yield function(e,t=null,n=(e=>{})){return lD(this,void 0,void 0,(function*(){e["@context"].find((e=>{return(t=e)===Object(t)&&"@vocab"in e;var t}))||e["@context"].push({"@vocab":"http://fallback.org/"});const r=JSON.parse(JSON.stringify(e));if(Array.isArray(r.proof)){if(!t)throw new iD("computeLocalHash",sD("errors","noProofSpecified"));const e=r.proof.findIndex((e=>e.proofValue===t.proofValue));r.proof=r.proof.slice(0,e)}else delete r.proof;const i={algorithm:"URDNA2015",format:"application/nquads",documentLoader:function(e){return lD(this,void 0,void 0,(function*(){return null!=n&&(yield n(e)),e in jh?{contextUrl:null,document:jh[e],documentUrl:e}:ov.documentLoader(e)}))}};let o;try{o=yield ov.normalize(r,i)}catch(e){throw console.error(e),new iD("computeLocalHash",sD("errors","failedJsonLdNormalization"))}const a=function(e){const t=e.split("\n"),n=/<http:\/\/fallback\.org\/(.*)>/,r=t.map((e=>n.exec(e))).filter((e=>null!=e));if(r.length>0){const e=r.map((e=>e[1])).sort();return Array.from(new Set(e))}return null}(o);if(a)throw new iD("computeLocalHash",`${sD("errors","foundUnmappedFields")}: ${a.join(", ")}`);return lS(function(e){const t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r<128?t.push(r):r<2048?t.push(192|r>>6,128|63&r):r<55296||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}(o))}))}(this.document,this.proof,this.documentLoader)}))),this.type)}))}checkReceipt(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("checkReceipt",(()=>function(e){let t=e.targetHash;const n=e.merkleRoot;try{const n=e.path;if(n&&t)for(const e in n){const r=n[e];let i;if(void 0!==r.left)i=rD(`${r.left}${t}`),t=lS(i);else{if(void 0===r.right)throw new iD("checkReceipt","Trigger catch error.");i=rD(`${t}${r.right}`),t=lS(i)}}}catch(e){throw new iD("checkReceipt",sD("errors","ensureValidReceipt"))}if(t!==n)throw new iD("checkReceipt",sD("errors","invalidMerkleReceipt"))}(this.proofValue)),this.type)}))}getTransactionId(){return Aq(this,void 0,void 0,(function*(){return this.transactionId=function(e=null){if(!e)throw new Error("DecodedProof is not set");const{anchors:t}=e,n=t[0];if("string"==typeof n)return n.split(":").pop();throw new Error("Could not retrieve transaction id as was provided an unexpected format")}(this.proofValue),yield this.executeStep("getTransactionId",(()=>function(e){if("string"==typeof e&&e.length>0)return e;throw new iD("getTransactionId",sD("errors","isTransactionIdValid"))}(this.transactionId)),this.type)}))}fetchRemoteHash(){return Aq(this,void 0,void 0,(function*(){this.txData=yield this.executeStep("fetchRemoteHash",(()=>Aq(this,void 0,void 0,(function*(){var e;return yield Lh({transactionId:this.transactionId,chain:null===(e=this.chain)||void 0===e?void 0:e.code,explorerAPIs:this.explorerAPIs})}))),this.type)}))}deriveIssuingAddressFromPublicKey(){return Aq(this,void 0,void 0,(function*(){this.derivedIssuingAddress=yield this.executeStep("deriveIssuingAddressFromPublicKey",(()=>lq(this.verificationMethod,this.chain)),this.type)}))}compareIssuingAddress(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("compareIssuingAddress",(()=>function(e,t){const n=sD("errors","identityErrorBaseMessage");if(e!==t)throw new iD("compareIssuingAddress",`${n} - ${sD("errors","compareIssuingAddress")}`)}(this.getIssuerPublicKey(),this.derivedIssuingAddress)),this.type)}))}}class fq{constructor(e){}}function dq(e){return Array.isArray(e)?e.find((e=>"ChainedProof2021"!==e.type)).verificationMethod:e.verificationMethod}var pq,gq;!function(e){e.getTransactionId="getTransactionId",e.computeLocalHash="computeLocalHash",e.fetchRemoteHash="fetchRemoteHash",e.parseIssuerKeys="parseIssuerKeys",e.compareHashes="compareHashes",e.checkImagesIntegrity="checkImagesIntegrity",e.checkMerkleRoot="checkMerkleRoot",e.checkReceipt="checkReceipt",e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.deriveIssuingAddressFromPublicKey="deriveIssuingAddressFromPublicKey",e.compareIssuingAddress="compareIssuingAddress",e.checkAuthenticity="checkAuthenticity"}(pq||(pq={}));class yq extends fq{proofVerificationProcess=[pq.parseIssuerKeys,pq.checkAuthenticity];transactionId;localHash;documentToVerify;txData;chain;explorerAPIs;receipt;issuerPublicKeyList;issuer;verificationMethodPublicKey;derivedIssuingAddress;hasDid;proof;type="MerkleProof2019";suite;constructor(e){var t;super(e),this.executeStep=e.executeStep,this.documentToVerify=e.document,this.explorerAPIs=e.explorerAPIs,this.proof=e.proof,this.issuer=e.issuer,this.validateProofType(),this.receipt=(t=this.proof,hq.decodeMerkleProof2019(t)),this.transactionId=zC.certificates.getTransactionId(this.receipt),this.setHasDid()}async init(){await this.setVerificationSuite(),this.chain=this.suite.getChain(),this.adaptVerificationProcessToChain()}async verifyProof(){await this.suite.verifyProof({verifyIdentity:!1}),await this.verifyProcess(this.proofVerificationProcess)}async verifyIdentity(){await this.suite.verifyIdentity()}getProofVerificationSteps(e){return[...this.suite.getProofVerificationProcess(),...this.proofVerificationProcess].map((t=>zC.verifier.convertToVerificationSubsteps(e,t)))}getIdentityVerificationSteps(e){return this.hasDid?this.suite.getIdentityVerificationProcess().map((t=>zC.verifier.convertToVerificationSubsteps(e,t))):[]}getIssuerPublicKey(){return this.suite.getIssuerPublicKey()}getIssuanceTime(){return this.suite.getIssuanceTime()}getIssuerName(){return this.issuer.name}getIssuerProfileDomain(){return new URL(this.getIssuerProfileUrl())?.hostname}getIssuerProfileUrl(){return this.issuer.id}getSigningDate(){return this.proof.created}getChain(){return this.suite.getChain()}getReceipt(){return this.receipt}getTransactionIdString(){return zC.certificates.getTransactionId(this.getReceipt())}getTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).transactionLink}getRawTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).rawTransactionLink}async executeStep(e,t,n){throw new Error("executeStep method needs to be overwritten by injecting from Verifier")}async setVerificationSuite(){await this.setIssuerFromProofVerificationMethod(),this.verificationMethodPublicKey=gS(this.getTargetVerificationMethodContainer(),dq(this.proof)),this.suite=new hq({document:this.documentToVerify,proof:this.proof,verificationMethod:this.verificationMethodPublicKey,options:{explorerAPIs:this.explorerAPIs,executeStepMethod:this.executeStep}})}adaptVerificationProcessToChain(){zC.chains.isMockChain(this.chain)&&(sf(this.proofVerificationProcess,pq.parseIssuerKeys),sf(this.proofVerificationProcess,pq.checkAuthenticity))}getTargetVerificationMethodContainer(){return this.issuer.didDocument??this.issuer}isProofChain(){return"ChainedProof2021"===this.proof.type}async setIssuerFromProofVerificationMethod(){if(this.isProofChain()){const e=this.proof.verificationMethod.split("#")[0];this.issuer=await zC.verifier.getIssuerProfile(e)}}setHasDid(){if(this.isProofChain()){const e=this.proof.verificationMethod.split("#")[0];this.hasDid=df(e)}else this.hasDid=!!this.issuer.didDocument}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}async verifyProcess(e){for(const t of e){if(!this[t])return void console.error("verification logic for",t,"not implemented");await this[t]()}}async parseIssuerKeys(){this.issuerPublicKeyList=await this.executeStep(pq.parseIssuerKeys,(()=>zC.verifier.parseIssuerKeys(this.issuer)),this.type)}async checkAuthenticity(){await this.executeStep(pq.checkAuthenticity,(()=>dS(this.issuerPublicKeyList,this.getIssuerPublicKey(),this.getIssuanceTime())),this.type)}}!function(e){e.getTransactionId="getTransactionId",e.computeLocalHash="computeLocalHash",e.fetchRemoteHash="fetchRemoteHash",e.parseIssuerKeys="parseIssuerKeys",e.compareHashes="compareHashes",e.checkMerkleRoot="checkMerkleRoot",e.checkReceipt="checkReceipt",e.checkAuthenticity="checkAuthenticity"}(gq||(gq={}));class mq extends fq{verificationProcess=[gq.getTransactionId,gq.computeLocalHash,gq.fetchRemoteHash,gq.compareHashes,gq.checkMerkleRoot,gq.checkReceipt,gq.parseIssuerKeys,gq.checkAuthenticity];transactionId;localHash;documentToVerify;txData;chain;explorerAPIs;receipt;issuerPublicKeyList;issuer;proof;type="MerkleProof2017";constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.explorerAPIs=e.explorerAPIs,this.issuer=e.issuer,this.proof=e.proof,this.validateProofType(),this.receipt=this.documentToVerify.signature,this.chain=zC.certificates.getChain("",this.receipt),this.transactionId=zC.certificates.getTransactionId(this.receipt),this.adaptVerificationProcessToChain()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(e){return this.verificationProcess.map((t=>zC.verifier.convertToVerificationSubsteps(e,t)))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return zC.chains.isMockChain(this.chain)?"This mock chain does not support issuing addresses":this.txData?this.txData.issuingAddress:void console.error("Trying to access issuing address when txData not available yet. Did you run the `verify` method yet?")}getIssuerName(){return this.issuer.name}getIssuerProfileDomain(){return new URL(this.getIssuerProfileUrl())?.hostname}getIssuerProfileUrl(){return this.issuer.id}getSigningDate(){return this.documentToVerify.issuedOn}getChain(){return this.chain}getReceipt(){return this.receipt}getTransactionIdString(){return zC.certificates.getTransactionId(this.getReceipt())}getTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).transactionLink}getRawTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).rawTransactionLink}validateProofType(){if(this.proof.type[0]!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${this.proof.type[0]}`)}adaptVerificationProcessToChain(){zC.chains.isMockChain(this.chain)&&(sf(this.verificationProcess,gq.getTransactionId),sf(this.verificationProcess,gq.fetchRemoteHash),sf(this.verificationProcess,gq.parseIssuerKeys),sf(this.verificationProcess,gq.checkMerkleRoot),sf(this.verificationProcess,gq.checkAuthenticity))}async executeStep(e,t,n){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async getTransactionId(){await this.executeStep(gq.getTransactionId,(()=>function(e){if("string"==typeof e&&e.length>0)return e;throw new tf("getTransactionId",Wh("errors","isTransactionIdValid"))}(this.transactionId)),this.type)}async computeLocalHash(){this.localHash=await this.executeStep(gq.computeLocalHash,(async()=>await fS(this.documentToVerify)),this.type)}async fetchRemoteHash(){this.txData=await this.executeStep(gq.fetchRemoteHash,(async()=>await zC.verifier.lookForTx({transactionId:this.transactionId,chain:this.chain.code,explorerAPIs:this.explorerAPIs})),this.type)}async compareHashes(){await this.executeStep(gq.compareHashes,(()=>function(e,t){if(e!==t)throw new tf("compareHashes",Wh("errors","ensureHashesEqual"));return!0}(this.localHash,this.receipt.targetHash)),this.type)}async checkMerkleRoot(){await this.executeStep(gq.checkMerkleRoot,(()=>function(e,t){if(e!==t)throw new tf("checkMerkleRoot",Wh("errors","ensureMerkleRootEqual"));return!0}(this.receipt.merkleRoot,this.txData.remoteHash)),this.type)}async checkReceipt(){await this.executeStep(gq.checkReceipt,(()=>function(e){let t=e.targetHash;const n=e.merkleRoot;try{const n=e.proof||e.path;if(n)for(const e in n){const r=n[e];let i;if(void 0!==r.left)i=uS(`${r.left}${t}`),t=lS(i);else{if(void 0===r.right)throw new tf("checkReceipt","Trigger catch error.");i=uS(`${t}${r.right}`),t=lS(i)}}}catch(e){throw new tf("checkReceipt",Wh("errors","ensureValidReceipt"))}if(t!==n)throw new tf("checkReceipt",Wh("errors","invalidMerkleReceipt"))}(this.receipt)),this.type)}async parseIssuerKeys(){this.issuerPublicKeyList=await this.executeStep(gq.parseIssuerKeys,(()=>zC.verifier.parseIssuerKeys(this.issuer)),this.type)}async checkAuthenticity(){await this.executeStep(gq.checkAuthenticity,(()=>dS(this.issuerPublicKeyList,this.txData.issuingAddress,this.txData.time)),this.type)}}const vq={};function Iq(e,t){return function(e,t,n){if(!(e instanceof Uint8Array))throw new TypeError('"input" must be a Uint8Array.');if(void 0!==n&&"number"!=typeof n)throw new TypeError('"maxline" must be a number.');if(0===e.length)return"";let r="",i=0;const o=t.length,a=t.charAt(0),s=[0];for(i=0;i<e.length;++i){let t=e[i];for(let e=0;e<s.length;++e)t+=s[e]<<8,s[e]=t%o,t=t/o|0;for(;t>0;)s.push(t%o),t=t/o|0}for(i=0;0===e[i]&&i<e.length-1;++i)r+=a;for(i=s.length-1;i>=0;--i)r+=t[s[i]];if(n){const e=new RegExp(".{1,"+n+"}","g");r=r.match(e).join("\r\n")}return r}(e,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",t)}function wq(e){return function(e,t){if("string"!=typeof e)throw new TypeError('"input" must be a string.');if(0===e.length)return new Uint8Array;let n=vq[t];if(!n){n=vq[t]=[];for(let e=0;e<t.length;++e)n[t.charCodeAt(e)]=e}e=e.replace(/\s/g,"");const r=t.length,i=t.charAt(0),o=[0];for(let t=0;t<e.length;t++){const i=n[e.charCodeAt(t)];if(void 0===i)return;let a=i;for(let e=0;e<o.length;++e)a+=o[e]*r,o[e]=255&a,a>>=8;for(;a>0;)o.push(255&a),a>>=8}for(let t=0;e[t]===i&&t<e.length-1;++t)o.push(0);return new Uint8Array(o.reverse())}
|
|
637
|
+
const zN={};var JN=zN;const YN=oN;Object.assign(zN,YN);const XN=class{async add(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}={}){if(!t)throw new TypeError('"options.suite" is required.');if(!n)throw new TypeError('"options.purpose" is required.');r=r?mN(r):vN,void 0===i?i=wN:!1===i&&(i=void 0);const o={...e};delete o.proof;const a=await t.createProof({document:o,purpose:n,documentLoader:r,expansionMap:i});return yN.addValue(e,"proof",a),e}async verify(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}={}){if(!t)throw new TypeError('"options.suite" is required.');if(!n)throw new TypeError('"options.purpose" is required.');const o=Array.isArray(t)?t:[t];if(0===o.length)throw new TypeError("At least one suite is required.");r=r?mN(r):vN,void 0===i?i=wN:!1===i&&(i=void 0);try{e={...e};const{proofSet:t,document:a}=await async function({document:e}){let t;if(t=yN.getValues(e,"proof"),delete e.proof,0===t.length)throw new Error("No matching proofs found in the given document.");const n=e["@context"]||gN.SECURITY_CONTEXT_URL;return t=t.map((e=>({"@context":n,...e}))),{proofSet:t,document:e}}({document:e,documentLoader:r,expansionMap:i});e=a;const s=await async function({document:e,suites:t,proofSet:n,purpose:r,documentLoader:i,expansionMap:o}){const a=Array.isArray(r)?r:[r],s=new Map,l=new Map,u=new Map;if(await Promise.all(a.map((r=>async function({purposeToProofs:e,proofToSuite:t,purpose:n,proofSet:r,suites:i,suiteMatchQueue:o,document:a,documentLoader:s,expansionMap:l}){for(const u of r){if(!await n.match(u,{document:a,documentLoader:s,expansionMap:l}))continue;let r=!1;for(const e of i){let n=o.get(e);n||o.set(e,n=new Map);let i=n.get(u);if(i||(i=e.matchProof({proof:u,document:a,documentLoader:s,expansionMap:l}),n.set(u,i)),await i){r=!0,t.set(u,e);break}}if(r){const t=e.get(n);t?t.push(u):e.set(n,[u])}}}({purposeToProofs:s,proofToSuite:l,purpose:r,proofSet:n,suites:t,suiteMatchQueue:u,document:e,documentLoader:i,expansionMap:o})))),s.size<a.length)return[];const A=new Map;return await Promise.all([...l.entries()].map((async([t,n])=>{let r;try{let a;const s={validate:async(e,{verificationMethod:t})=>(a=t,{valid:!0})},{verified:l,verificationMethod:u,error:A}=await n.verifyProof({proof:t,document:e,purpose:s,documentLoader:i,expansionMap:o});a||(a=u),r={proof:t,verified:l,verificationMethod:a,error:A}}catch(e){r={proof:t,verified:!1,error:e}}r.error&&bN(r.error),A.set(t,r)}))),await Promise.all([...s.entries()].map((async([t,n])=>{for(const r of n){const n=A.get(r);if(!n.verified)continue;const{verificationMethod:a}=n,s=l.get(r);let u;try{u=await t.validate(r,{document:e,suite:s,verificationMethod:a,documentLoader:i,expansionMap:o})}catch(e){u={valid:!1,error:e}}n.purposeResult?Array.isArray(n.purposeResult)?n.purposeResult.push(u):n.purposeResult=[n.purposeResult,u]:n.purposeResult=u,u.valid||(bN(u.error),n.error||(n.verified=!1,n.error=u.error))}}))),[...A.values()]}({document:e,suites:o,proofSet:t,purpose:n,documentLoader:r,expansionMap:i});if(0===s.length){const e=new Error("Did not verify any proofs; insufficient proofs matched the acceptable suite(s) and required purpose(s).");throw e.name="NotFoundError",e}const l=s.some((e=>e.verified));if(!l){const e=[].concat(...s.filter((e=>e.error)).map((e=>e.error))),t={verified:l,results:s};return e.length>0&&(t.error=e),t}return{verified:l,results:s}}catch(e){return bN(e),{verified:!1,error:e}}}},WN=EN;function ZN(e){const t=Object.keys(jl).map((e=>jl[e])).find((t=>t.signatureValue===e));return t}function $N(e,t){const n=e.findIndex((e=>e===t));n>-1&&e.splice(n,1)}zN.sign=async function(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i,addSuiteContext:o=!0}={}){if("object"!=typeof e)throw new TypeError('The "document" parameter must be an object.');t.ensureSuiteContext({document:e,addSuiteContext:o});try{return await(new XN).add(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i})}catch(e){if(!r&&"jsonld.InvalidUrl"===e.name){const{details:{url:t}}=e,n=new Error(`A URL "${t}" could not be fetched; you need to pass "documentLoader" or resolve the URL before calling "sign".`);throw n.cause=e,n}throw e}},zN.verify=async function(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}={}){if("object"!=typeof e)throw new TypeError('The "document" parameter must be an object.');const o=await(new XN).verify(e,{suite:t,purpose:n,documentLoader:r,expansionMap:i}),{error:a}=o;if(a)if(r||"jsonld.InvalidUrl"!==a.name)o.error=new WN(a);else{const{details:{url:e}}=a,t=new Error(`A URL "${e}" could not be fetched; you need to pass "documentLoader" or resolve the URL before calling "verify".`);o.error=new WN(t)}return o},zN.suites=MN.suites,zN.purposes=VN.purposes,Object.assign(zN,AN);var eD={"@context":{id:"@id",type:"@type",bc:"https://w3id.org/blockcerts#",obi:"https://w3id.org/openbadges#",cp:"https://w3id.org/chainpoint#",schema:"http://schema.org/",sec:"https://w3id.org/security#",xsd:"http://www.w3.org/2001/XMLSchema#",MerkleProof2017:"sec:MerkleProof2017",RecipientProfile:"bc:RecipientProfile",SignatureLine:"bc:SignatureLine",MerkleProofVerification2017:"bc:MerkleProofVerification2017",recipientProfile:"bc:recipientProfile",signatureLines:"bc:signatureLines",introductionUrl:{"@id":"bc:introductionUrl","@type":"@id"},subtitle:"bc:subtitle",jobTitle:"schema:jobTitle",creator:{"@id":"dc:creator","@type":"@id"},expires:{"@id":"sec:expiration","@type":"xsd:dateTime"},revoked:{"@id":"sec:expiration","@type":"xsd:dateTime"},CryptographicKey:"sec:Key",signature:"sec:signature",verification:"bc:verification",publicKeys:"bc:publicKeys",ChainpointSHA256v2:"cp:ChainpointSHA256v2",BTCOpReturn:"cp:BTCOpReturn",targetHash:"cp:targetHash",merkleRoot:"cp:merkleRoot",proof:"cp:proof",anchors:"cp:anchors",sourceId:"cp:sourceId",right:"cp:right",left:"cp:left"},"obi:validation":[{"obi:validatesType":"RecipientProfile","obi:validationSchema":"https://w3id.org/blockcerts/schema/2.0-alpha/recipientSchema.json"},{"obi:validatesType":"SignatureLine","obi:validationSchema":"https://w3id.org/blockcerts/schema/2.0-alpha/signatureLineSchema.json"},{"obi:validatesType":"MerkleProof2017","obi:validationSchema":"https://w3id.org/blockcerts/schema/2.0-alpha/merkleProof2017Schema.json"}]},tD={"@context":{id:"@id",type:"@type",bc:"https://w3id.org/blockcerts#",cp:"https://w3id.org/chainpoint#",schema:"http://schema.org/",sec:"https://w3id.org/security#",xsd:"http://www.w3.org/2001/XMLSchema#",MerkleProof2019:"sec:MerkleProof2019",BlockcertsCredential:"bc:BlockcertsCredential",introductionUrl:{"@id":"bc:introductionUrl","@type":"@id"},CryptographicKey:"sec:Key",domain:"sec:domain",nonce:"sec:nonce",proofValue:"sec:proofValue",assertionMethod:{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},proofPurpose:{"@id":"sec:proofPurpose","@type":"@vocab"},verificationMethod:{"@id":"sec:verificationMethod","@type":"@id"},created:{"@id":"bc:created","@type":"xsd:dateTime"},name:{"@id":"schema:name"}}},nD={"@context":{id:"@id",type:"@type",bc:"https://w3id.org/blockcerts#",cp:"https://w3id.org/chainpoint#",vc:"https://www.w3.org/2018/credentials/v1",schema:"https://schema.org/",sec:"https://w3id.org/security#",xsd:"http://www.w3.org/2001/XMLSchema#",MerkleProof2019:"sec:MerkleProof2019",BlockcertsCredential:"bc:BlockcertsCredential",introductionUrl:{"@id":"bc:introductionUrl","@type":"@id"},metadata:"bc:metadata",display:{"@id":"bc:display","@context":{id:"@id",type:"@type",contentMediaType:{"@id":"bc:contentMediaType","@type":"@id"},contentEncoding:{"@id":"bc:contentEncoding","@type":"@id"},content:{"@id":"bc:content","@type":"@id"}}},CryptographicKey:"sec:Key",domain:"sec:domain",nonce:"sec:nonce",proofValue:"sec:proofValue",assertionMethod:{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"},proofPurpose:{"@id":"sec:proofPurpose","@type":"@vocab"},verificationMethod:{"@id":"sec:verificationMethod","@type":"@id"},created:{"@id":"https://purl.org/dc/terms/created","@type":"xsd:dateTime"},challenge:"sec:challenge",expires:{"@id":"sec:expiration","@type":"xsd:dateTime"},name:{"@id":"schema:name"},description:{"@id":"schema:description"},email:{"@id":"schema:email"},publicKey:{"@id":"sec:publicKey","@type":"@id"},url:{"@id":"schema:url","@type":"@id"},image:{"@id":"schema:image","@type":"@id"}}};function rD(e){e=e.trim();const t=[];for(let n=0;n<e.length;n+=2)t.push(parseInt(e.substring(n,n+2),16));return t}jh["https://w3id.org/blockcerts/schema/2.0-alpha/context.json"]=eD,jh["https://www.blockcerts.org/schema/2.0-alpha/context.json"]=eD,jh["https://www.blockcerts.org/schema/3.0-alpha/context.json"]=tD,jh["https://w3id.org/blockcerts/schema/3.0-alpha/context.json"]=tD,jh["https://w3id.org/blockcerts/v3.0-alpha"]=tD,jh["https://www.blockcerts.org/schema/3.0-beta/context.json"]=nD,jh["https://w3id.org/blockcerts/schema/3.0-beta/context.json"]=nD,jh["https://w3id.org/blockcerts/v3.0-beta"]=nD,jh["https://w3id.org/security/suites/ed25519-2020/v1"]={"@context":{id:"@id",type:"@type","@protected":!0,proof:{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"},Ed25519VerificationKey2020:{"@id":"https://w3id.org/security#Ed25519VerificationKey2020","@context":{"@protected":!0,id:"@id",type:"@type",controller:{"@id":"https://w3id.org/security#controller","@type":"@id"},revoked:{"@id":"https://w3id.org/security#revoked","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},publicKeyMultibase:{"@id":"https://w3id.org/security#publicKeyMultibase","@type":"https://w3id.org/security#multibase"}}},Ed25519Signature2020:{"@id":"https://w3id.org/security#Ed25519Signature2020","@context":{"@protected":!0,id:"@id",type:"@type",challenge:"https://w3id.org/security#challenge",created:{"@id":"http://purl.org/dc/terms/created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},domain:"https://w3id.org/security#domain",expires:{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},nonce:"https://w3id.org/security#nonce",proofPurpose:{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":!0,id:"@id",type:"@type",assertionMethod:{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},capabilityInvocation:{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},capabilityDelegation:{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},keyAgreement:{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},proofValue:{"@id":"https://w3id.org/security#proofValue","@type":"https://w3id.org/security#multibase"},verificationMethod:{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}}}};class iD extends Error{constructor(e,t){super(t),this.stepCode=e}}var oD="en-US",aD={"en-US":{errors:{ensureHashesEqual:"Computed hash does not match remote hash",ensureMerkleRootEqual:"Merkle root does not match remote hash.",ensureValidReceipt:"The receipt is malformed. There was a problem navigating the merkle tree in the receipt.",failedJsonLdNormalization:"Failed JSON-LD normalization",foundUnmappedFields:"Found unmapped fields during JSON-LD normalization",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"Cannot verify this certificate without a transaction ID to compare against.",invalidMerkleReceipt:"Invalid Merkle Receipt. Proof hash did not match Merkle root",isTransactionIdValid:"Cannot verify this certificate without a transaction ID to compare against.",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}},fr:{errors:{ensureHashesEqual:"Calcul du hash local différent du hash distant",ensureMerkleRootEqual:"Le Merkle root ne correspond pas au hash distant",ensureValidReceipt:"Erreur d'écriture du reçu. Un problème est survenu lors de la navigation de l'arbre Merkle du reçu.",failedJsonLdNormalization:"Erreur de normalisation JSON-LD",foundUnmappedFields:"Champs non liés découverts durant la normalisation JSON-LD",identityErrorBaseMessage:"Identité de l'émetteur invalide",deriveIssuingAddressFromPublicKey:"Cette blockchain n'est pas supportée pour la vérification de l'identité décentralisée.",compareIssuingAddress:"La méthode de vérification n'a pas permis d'établir l'identité de l'émetteur.",getTransactionId:"Impossible de vérifier ce certificat sans un identifiant de transaction valide",invalidMerkleReceipt:"Reçu Merkle invalide. Hash de preuve différent du Merkle root",isTransactionIdValid:"Impossible de vérifier ce certificat sans un identifiant de transaction valide",noProofSpecified:"La propriété 'proof' du document est un tableau mais aucune preuve n'a été passée pour savoir ce qu'il faut vérifier"}},es:{errors:{ensureHashesEqual:"La cadena binaria calculada no corresponde con la cadena binaria remota",ensureMerkleRootEqual:"La raíz Merkle no corresponde con la cadena binaria remota",ensureValidReceipt:"El recibo está malformado. Hubo un problema navegando el árbol Merkle en el recibo",failedJsonLdNormalization:"La normalización del JSON-LD ha fallado",foundUnmappedFields:"Se han encontrado campos no mapeados durante la normalización de JSON-LD",identityErrorBaseMessage:"Identitad del emisor inválida",deriveIssuingAddressFromPublicKey:"No se puede validar la identitad decentalisada con esta cadena binaria.",compareIssuingAddress:"El metodo de verificación no corresponde a la identitad del emisor.",getTransactionId:"No se puede verificar este certificado sin una identificación de transacción que sirva como comparación",invalidMerkleReceipt:"Recibo Merkle inválido. La cadena binaria de prueba no corresponde con la raíz Merkle",isTransactionIdValid:"No se puede verificar este certificado sin una identificación de transacción que sirva como comparación",noProofSpecified:"La propiedad 'proof' del documento es una lista, pero no prueba especifica ha sido declarada para conocer el punto de verificación"}},mt:{errors:{ensureHashesEqual:"Il-hash ikkalkulat ma jikkorrispondix mar-remote hash",ensureMerkleRootEqual:"Merkle root ma taqbilx mar-remote hash",ensureValidReceipt:"L-irċevuta hija malformata. Kien hemm problema fin-navigazzjoni tal-merkle tree fl-irċevuta",failedJsonLdNormalization:"In-normalizzazzjoni ta' JSON-LD ma rnexxietx",foundUnmappedFields:"Instabu unmapped fields matul in-normalizzazzjoni JSON-LD",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"Dan iċ-ċertifikat ma jistax jiġi vverifikat mingħajr ID ta' tranżazzjoni mqabbla miegħu",invalidMerkleReceipt:"Irċevuta Merkle invalida. Il-proof hash ma kienx jaqbel mal-Merkle root",isTransactionIdValid:"Dan iċ-ċertifikat ma jistax jiġi vverifikat mingħajr ID ta' tranżazzjoni mqabbla miegħu",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}},"it-IT":{errors:{ensureHashesEqual:"L'hash calcolato non corrisponde all'hash remoto",ensureMerkleRootEqual:"La radice di Merkle non corrisponde all'hash remoto.",ensureValidReceipt:"La ricevuta è malformata. C'è stato un problema nella navigazione dell'albero di Merkle nella ricevuta.",failedJsonLdNormalization:"Normalizzazione JSON-LD fallita",foundUnmappedFields:"Campi non mappati trovati durante la normalizzazione JSON-LD",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"Impossibile verificare questo certificato senza un ID transazione da confrontare.",invalidMerkleReceipt:"Ricevuta Merkle non valida. L'hash di prova non corrisponde alla radice di Merkle",isTransactionIdValid:"Impossibile verificare questo certificato senza un ID transazione da confrontare.",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}},ja:{errors:{ensureHashesEqual:"算出されたハッシュがリモートハッシュと一致しませんでした",ensureMerkleRootEqual:"Merkle rootがリモートハッシュと一致しませんでした",ensureValidReceipt:"レシートが異常です。レシート内のMerkle treeを辿る際に問題が発生しました。",failedJsonLdNormalization:"JSON-LDの正規化に失敗しました",foundUnmappedFields:"JSON-LDの正規化時にマップされていないフィールドを検出しました",identityErrorBaseMessage:"Issuer identity mismatch",deriveIssuingAddressFromPublicKey:"Unsupported blockchain for DID verification",compareIssuingAddress:"The provided verification method does not match the issuer identity",getTransactionId:"照合のための取引IDがないため、この証明書を認証できません。",invalidMerkleReceipt:"Merkleレシートが無効です。証明ハッシュがMerkle rootと一致しませんでした。",isTransactionIdValid:"照合するための取引IDがないため、この証明書を認証できません。",noProofSpecified:"Document proof is an array but no target proof was specified to know what to verify."}}};function sD(e,t){return e&&t?aD[oD]?aD[oD][e]?aD[oD][e][t]?aD[oD][e][t]||"":"[missing locale item data]":"[missing locale group data]":"[missing locale data]":""}var lD=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){e.done?i(e.value):function(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(a,s)}l((r=r.apply(e,t||[])).next())}))};class uD extends Error{constructor(e){super(e||"This operation is not supported for this key type")}}var AD=uD;class cD extends Error{constructor(){super("This has not been implemented yet")}}var hD=cD;const fD=hD;var dD,pD=class{constructor(e){this.params=e}fromPrivatePKCS1(e){throw new fD}fromPrivatePKCS8(e){throw new fD}fromPublicPKCS1(e){throw new fD}fromPublicPKCS8(e){throw new fD}fromPrivateBlk(e){throw new fD}fromPublicBlk(e){throw new fD}fromJwk(e){throw new fD}toPrivatePKCS1(e){throw new fD}toPrivatePKCS8(e){throw new fD}toPublicPKCS1(e){throw new fD}toPublicPKCS8(e){throw new fD}toPrivateBlk(e){throw new fD}toPublicBlk(e){throw new fD}toPrivateJwk(e){throw new fD}toPublicJwk(e){throw new fD}static formatPem(e,t){return`-----BEGIN ${t} KEY-----\n`+e.match(/.{1,64}/g).join("\n")+`\n-----END ${t} KEY-----`}},gD={},yD={},mD={},vD=qo,ID=vD.Buffer,wD={};for(dD in vD)vD.hasOwnProperty(dD)&&"SlowBuffer"!==dD&&"Buffer"!==dD&&(wD[dD]=vD[dD]);var bD=wD.Buffer={};for(dD in ID)ID.hasOwnProperty(dD)&&"allocUnsafe"!==dD&&"allocUnsafeSlow"!==dD&&(bD[dD]=ID[dD]);if(wD.Buffer.prototype=ID.prototype,bD.from&&bD.from!==Uint8Array.from||(bD.from=function(e,t,n){if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type '+typeof e);if(e&&void 0===e.length)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);return ID(e,t,n)}),bD.alloc||(bD.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError('The "size" argument must be of type number. Received type '+typeof e);if(e<0||e>=2*(1<<30))throw new RangeError('The value "'+e+'" is invalid for option "size"');var r=ID(e);return t&&0!==t.length?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r}),!wD.kStringMaxLength)try{wD.kStringMaxLength=gu.binding("buffer").kStringMaxLength}catch(e){}wD.constants||(wD.constants={MAX_LENGTH:wD.kMaxLength},wD.kStringMaxLength&&(wD.constants.MAX_STRING_LENGTH=wD.kStringMaxLength));var BD=wD,ED={};const CD=Ow.exports;function SD(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function xD(e,t){this.path=e,this.rethrow(t)}ED.Reporter=SD,SD.prototype.isError=function(e){return e instanceof xD},SD.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},SD.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},SD.prototype.enterKey=function(e){return this._reporterState.path.push(e)},SD.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},SD.prototype.leaveKey=function(e,t,n){const r=this._reporterState;this.exitKey(e),null!==r.obj&&(r.obj[t]=n)},SD.prototype.path=function(){return this._reporterState.path.join("/")},SD.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},SD.prototype.leaveObject=function(e){const t=this._reporterState,n=t.obj;return t.obj=e,n},SD.prototype.error=function(e){let t;const n=this._reporterState,r=e instanceof xD;if(t=r?e:new xD(n.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!n.options.partial)throw t;return r||n.errors.push(t),t},SD.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},CD(xD,Error),xD.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,xD),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this};var QD={};const kD=Ow.exports,_D=ED.Reporter,ND=BD.Buffer;function DD(e,t){_D.call(this,t),ND.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function FD(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return FD.isEncoderBuffer(e)||(e=new FD(e,t)),this.length+=e.length,e}),this);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");this.value=e,this.length=1}else if("string"==typeof e)this.value=e,this.length=ND.byteLength(e);else{if(!ND.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}kD(DD,_D),QD.DecoderBuffer=DD,DD.isDecoderBuffer=function(e){return e instanceof DD||"object"==typeof e&&ND.isBuffer(e.base)&&"DecoderBuffer"===e.constructor.name&&"number"==typeof e.offset&&"number"==typeof e.length&&"function"==typeof e.save&&"function"==typeof e.restore&&"function"==typeof e.isEmpty&&"function"==typeof e.readUInt8&&"function"==typeof e.skip&&"function"==typeof e.raw},DD.prototype.save=function(){return{offset:this.offset,reporter:_D.prototype.save.call(this)}},DD.prototype.restore=function(e){const t=new DD(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,_D.prototype.restore.call(this,e.reporter),t},DD.prototype.isEmpty=function(){return this.offset===this.length},DD.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},DD.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const n=new DD(this.base);return n._reporterState=this._reporterState,n.offset=this.offset,n.length=this.offset+e,this.offset+=e,n},DD.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},QD.EncoderBuffer=FD,FD.isEncoderBuffer=function(e){return e instanceof FD||"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},FD.prototype.join=function(e,t){return e||(e=ND.alloc(this.length)),t||(t=0),0===this.length||(Array.isArray(this.value)?this.value.forEach((function(n){n.join(e,t),t+=n.length})):("number"==typeof this.value?e[t]=this.value:"string"==typeof this.value?e.write(this.value,t):ND.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e};const PD=ED.Reporter,UD=QD.EncoderBuffer,MD=QD.DecoderBuffer,LD=Ew,TD=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],RD=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(TD);function OD(e,t,n){const r={};this._baseState=r,r.name=n,r.enc=e,r.parent=t||null,r.children=null,r.tag=null,r.args=null,r.reverseArgs=null,r.choice=null,r.optional=!1,r.any=!1,r.obj=!1,r.use=null,r.useDecoder=null,r.key=null,r.default=null,r.explicit=null,r.implicit=null,r.contains=null,r.parent||(r.children=[],this._wrap())}var HD=OD;const KD=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];OD.prototype.clone=function(){const e=this._baseState,t={};KD.forEach((function(n){t[n]=e[n]}));const n=new this.constructor(t.parent);return n._baseState=t,n},OD.prototype._wrap=function(){const e=this._baseState;RD.forEach((function(t){this[t]=function(){const n=new this.constructor(this);return e.children.push(n),n[t].apply(n,arguments)}}),this)},OD.prototype._init=function(e){const t=this._baseState;LD(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),LD.equal(t.children.length,1,"Root node can have only one child")},OD.prototype._useArgs=function(e){const t=this._baseState,n=e.filter((function(e){return e instanceof this.constructor}),this);e=e.filter((function(e){return!(e instanceof this.constructor)}),this),0!==n.length&&(LD(null===t.children),t.children=n,n.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(LD(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;const t={};return Object.keys(e).forEach((function(n){n==(0|n)&&(n|=0);const r=e[n];t[r]=n})),t})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){OD.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),TD.forEach((function(e){OD.prototype[e]=function(){const t=this._baseState,n=Array.prototype.slice.call(arguments);return LD(null===t.tag),t.tag=e,this._useArgs(n),this}})),OD.prototype.use=function(e){LD(e);const t=this._baseState;return LD(null===t.use),t.use=e,this},OD.prototype.optional=function(){return this._baseState.optional=!0,this},OD.prototype.def=function(e){const t=this._baseState;return LD(null===t.default),t.default=e,t.optional=!0,this},OD.prototype.explicit=function(e){const t=this._baseState;return LD(null===t.explicit&&null===t.implicit),t.explicit=e,this},OD.prototype.implicit=function(e){const t=this._baseState;return LD(null===t.explicit&&null===t.implicit),t.implicit=e,this},OD.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},OD.prototype.key=function(e){const t=this._baseState;return LD(null===t.key),t.key=e,this},OD.prototype.any=function(){return this._baseState.any=!0,this},OD.prototype.choice=function(e){const t=this._baseState;return LD(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},OD.prototype.contains=function(e){const t=this._baseState;return LD(null===t.use),t.contains=e,this},OD.prototype._decode=function(e,t){const n=this._baseState;if(null===n.parent)return e.wrapResult(n.children[0]._decode(e,t));let r,i=n.default,o=!0,a=null;if(null!==n.key&&(a=e.enterKey(n.key)),n.optional){let r=null;if(null!==n.explicit?r=n.explicit:null!==n.implicit?r=n.implicit:null!==n.tag&&(r=n.tag),null!==r||n.any){if(o=this._peekTag(e,r,n.any),e.isError(o))return o}else{const r=e.save();try{null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),o=!0}catch(e){o=!1}e.restore(r)}}if(n.obj&&o&&(r=e.enterObject()),o){if(null!==n.explicit){const t=this._decodeTag(e,n.explicit);if(e.isError(t))return t;e=t}const r=e.offset;if(null===n.use&&null===n.choice){let t;n.any&&(t=e.save());const r=this._decodeTag(e,null!==n.implicit?n.implicit:n.tag,n.any);if(e.isError(r))return r;n.any?i=e.raw(t):e=r}if(t&&t.track&&null!==n.tag&&t.track(e.path(),r,e.length,"tagged"),t&&t.track&&null!==n.tag&&t.track(e.path(),e.offset,e.length,"content"),n.any||(i=null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t)),e.isError(i))return i;if(n.any||null!==n.choice||null===n.children||n.children.forEach((function(n){n._decode(e,t)})),n.contains&&("octstr"===n.tag||"bitstr"===n.tag)){const r=new MD(i);i=this._getUse(n.contains,e._reporterState.obj)._decode(r,t)}}return n.obj&&o&&(i=e.leaveObject(r)),null===n.key||null===i&&!0!==o?null!==a&&e.exitKey(a):e.leaveKey(a,n.key,i),i},OD.prototype._decodeGeneric=function(e,t,n){const r=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,r.args[0],n):/str$/.test(e)?this._decodeStr(t,e,n):"objid"===e&&r.args?this._decodeObjid(t,r.args[0],r.args[1],n):"objid"===e?this._decodeObjid(t,null,null,n):"gentime"===e||"utctime"===e?this._decodeTime(t,e,n):"null_"===e?this._decodeNull(t,n):"bool"===e?this._decodeBool(t,n):"objDesc"===e?this._decodeStr(t,e,n):"int"===e||"enum"===e?this._decodeInt(t,r.args&&r.args[0],n):null!==r.use?this._getUse(r.use,t._reporterState.obj)._decode(t,n):t.error("unknown tag: "+e)},OD.prototype._getUse=function(e,t){const n=this._baseState;return n.useDecoder=this._use(e,t),LD(null===n.useDecoder._baseState.parent),n.useDecoder=n.useDecoder._baseState.children[0],n.implicit!==n.useDecoder._baseState.implicit&&(n.useDecoder=n.useDecoder.clone(),n.useDecoder._baseState.implicit=n.implicit),n.useDecoder},OD.prototype._decodeChoice=function(e,t){const n=this._baseState;let r=null,i=!1;return Object.keys(n.choice).some((function(o){const a=e.save(),s=n.choice[o];try{const n=s._decode(e,t);if(e.isError(n))return!1;r={type:o,value:n},i=!0}catch(t){return e.restore(a),!1}return!0}),this),i?r:e.error("Choice not matched")},OD.prototype._createEncoderBuffer=function(e){return new UD(e,this.reporter)},OD.prototype._encode=function(e,t,n){const r=this._baseState;if(null!==r.default&&r.default===e)return;const i=this._encodeValue(e,t,n);return void 0===i||this._skipDefault(i,t,n)?void 0:i},OD.prototype._encodeValue=function(e,t,n){const r=this._baseState;if(null===r.parent)return r.children[0]._encode(e,t||new PD);let i=null;if(this.reporter=t,r.optional&&void 0===e){if(null===r.default)return;e=r.default}let o=null,a=!1;if(r.any)i=this._createEncoderBuffer(e);else if(r.choice)i=this._encodeChoice(e,t);else if(r.contains)o=this._getUse(r.contains,n)._encode(e,t),a=!0;else if(r.children)o=r.children.map((function(n){if("null_"===n._baseState.tag)return n._encode(null,t,e);if(null===n._baseState.key)return t.error("Child should have a key");const r=t.enterKey(n._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");const i=n._encode(e[n._baseState.key],t,e);return t.leaveKey(r),i}),this).filter((function(e){return e})),o=this._createEncoderBuffer(o);else if("seqof"===r.tag||"setof"===r.tag){if(!r.args||1!==r.args.length)return t.error("Too many args for : "+r.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");const n=this.clone();n._baseState.implicit=null,o=this._createEncoderBuffer(e.map((function(n){const r=this._baseState;return this._getUse(r.args[0],e)._encode(n,t)}),n))}else null!==r.use?i=this._getUse(r.use,n)._encode(e,t):(o=this._encodePrimitive(r.tag,e),a=!0);if(!r.any&&null===r.choice){const e=null!==r.implicit?r.implicit:r.tag,n=null===r.implicit?"universal":"context";null===e?null===r.use&&t.error("Tag could be omitted only for .use()"):null===r.use&&(i=this._encodeComposite(e,a,n,o))}return null!==r.explicit&&(i=this._encodeComposite(r.explicit,!1,"context",i)),i},OD.prototype._encodeChoice=function(e,t){const n=this._baseState,r=n.choice[e.type];return r||LD(!1,e.type+" not found in "+JSON.stringify(Object.keys(n.choice))),r._encode(e.value,t)},OD.prototype._encodePrimitive=function(e,t){const n=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&n.args)return this._encodeObjid(t,n.reverseArgs[0],n.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,n.args&&n.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},OD.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},OD.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)};var jD={};!function(e){function t(e){const t={};return Object.keys(e).forEach((function(n){(0|n)==n&&(n|=0);const r=e[n];t[r]=n})),t}e.tagClass={0:"universal",1:"application",2:"context",3:"private"},e.tagClassByName=t(e.tagClass),e.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},e.tagByName=t(e.tag)}(jD);const GD=Ow.exports,qD=BD.Buffer,VD=HD,zD=jD;function JD(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new XD,this.tree._init(e.body)}var YD=JD;function XD(e){VD.call(this,"der",e)}function WD(e){return e<10?"0"+e:e}JD.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},GD(XD,VD),XD.prototype._encodeComposite=function(e,t,n,r){const i=function(e,t,n,r){let i;if("seqof"===e?e="seq":"setof"===e&&(e="set"),zD.tagByName.hasOwnProperty(e))i=zD.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return r.error("Unknown tag: "+e);i=e}return i>=31?r.error("Multi-octet tag encoding unsupported"):(t||(i|=32),i|=zD.tagClassByName[n||"universal"]<<6,i)}(e,t,n,this.reporter);if(r.length<128){const e=qD.alloc(2);return e[0]=i,e[1]=r.length,this._createEncoderBuffer([e,r])}let o=1;for(let e=r.length;e>=256;e>>=8)o++;const a=qD.alloc(2+o);a[0]=i,a[1]=128|o;for(let e=1+o,t=r.length;t>0;e--,t>>=8)a[e]=255&t;return this._createEncoderBuffer([a,r])},XD.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){const t=qD.alloc(2*e.length);for(let n=0;n<e.length;n++)t.writeUInt16BE(e.charCodeAt(n),2*n);return this._createEncoderBuffer(t)}return"numstr"===t?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===t?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(t)||"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},XD.prototype._encodeObjid=function(e,t,n){if("string"==typeof e){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[e].split(/[\s.]+/g);for(let t=0;t<e.length;t++)e[t]|=0}else if(Array.isArray(e)){e=e.slice();for(let t=0;t<e.length;t++)e[t]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let r=0;for(let t=0;t<e.length;t++){let n=e[t];for(r++;n>=128;n>>=7)r++}const i=qD.alloc(r);let o=i.length-1;for(let t=e.length-1;t>=0;t--){let n=e[t];for(i[o--]=127&n;(n>>=7)>0;)i[o--]=128|127&n}return this._createEncoderBuffer(i)},XD.prototype._encodeTime=function(e,t){let n;const r=new Date(e);return"gentime"===t?n=[WD(r.getUTCFullYear()),WD(r.getUTCMonth()+1),WD(r.getUTCDate()),WD(r.getUTCHours()),WD(r.getUTCMinutes()),WD(r.getUTCSeconds()),"Z"].join(""):"utctime"===t?n=[WD(r.getUTCFullYear()%100),WD(r.getUTCMonth()+1),WD(r.getUTCDate()),WD(r.getUTCHours()),WD(r.getUTCMinutes()),WD(r.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(n,"octstr")},XD.prototype._encodeNull=function(){return this._createEncoderBuffer("")},XD.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!qD.isBuffer(e)){const t=e.toArray();!e.sign&&128&t[0]&&t.unshift(0),e=qD.from(t)}if(qD.isBuffer(e)){let t=e.length;0===e.length&&t++;const n=qD.alloc(t);return e.copy(n),0===e.length&&(n[0]=0),this._createEncoderBuffer(n)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let t=e;t>=256;t>>=8)n++;const r=new Array(n);for(let t=r.length-1;t>=0;t--)r[t]=255&e,e>>=8;return 128&r[0]&&r.unshift(0),this._createEncoderBuffer(qD.from(r))},XD.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},XD.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},XD.prototype._skipDefault=function(e,t,n){const r=this._baseState;let i;if(null===r.default)return!1;const o=e.join();if(void 0===r.defaultBuffer&&(r.defaultBuffer=this._encodeValue(r.default,t,n).join()),o.length!==r.defaultBuffer.length)return!1;for(i=0;i<o.length;i++)if(o[i]!==r.defaultBuffer[i])return!1;return!0};const ZD=Ow.exports,$D=YD;function eF(e){$D.call(this,e),this.enc="pem"}ZD(eF,$D);var tF=eF;eF.prototype.encode=function(e,t){const n=$D.prototype.encode.call(this,e).toString("base64"),r=["-----BEGIN "+t.label+"-----"];for(let e=0;e<n.length;e+=64)r.push(n.slice(e,e+64));return r.push("-----END "+t.label+"-----"),r.join("\n")},function(e){const t=e;t.der=YD,t.pem=tF}(mD);var nF={};const rF=Ow.exports,iF=Bw.exports,oF=QD.DecoderBuffer,aF=HD,sF=jD;function lF(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new AF,this.tree._init(e.body)}var uF=lF;function AF(e){aF.call(this,"der",e)}function cF(e,t){let n=e.readUInt8(t);if(e.isError(n))return n;const r=sF.tagClass[n>>6],i=0==(32&n);if(31==(31&n)){let r=n;for(n=0;128==(128&r);){if(r=e.readUInt8(t),e.isError(r))return r;n<<=7,n|=127&r}}else n&=31;return{cls:r,primitive:i,tag:n,tagStr:sF.tag[n]}}function hF(e,t,n){let r=e.readUInt8(n);if(e.isError(r))return r;if(!t&&128===r)return null;if(0==(128&r))return r;const i=127&r;if(i>4)return e.error("length octect is too long");r=0;for(let t=0;t<i;t++){r<<=8;const t=e.readUInt8(n);if(e.isError(t))return t;r|=t}return r}lF.prototype.decode=function(e,t){return oF.isDecoderBuffer(e)||(e=new oF(e,t)),this.tree._decode(e,t)},rF(AF,aF),AF.prototype._peekTag=function(e,t,n){if(e.isEmpty())return!1;const r=e.save(),i=cF(e,'Failed to peek tag: "'+t+'"');return e.isError(i)?i:(e.restore(r),i.tag===t||i.tagStr===t||i.tagStr+"of"===t||n)},AF.prototype._decodeTag=function(e,t,n){const r=cF(e,'Failed to decode tag of "'+t+'"');if(e.isError(r))return r;let i=hF(e,r.primitive,'Failed to get length of "'+t+'"');if(e.isError(i))return i;if(!n&&r.tag!==t&&r.tagStr!==t&&r.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(r.primitive||null!==i)return e.skip(i,'Failed to match body of: "'+t+'"');const o=e.save(),a=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(a)?a:(i=e.offset-o.offset,e.restore(o),e.skip(i,'Failed to match body of: "'+t+'"'))},AF.prototype._skipUntilEnd=function(e,t){for(;;){const n=cF(e,t);if(e.isError(n))return n;const r=hF(e,n.primitive,t);if(e.isError(r))return r;let i;if(i=n.primitive||null!==r?e.skip(r):this._skipUntilEnd(e,t),e.isError(i))return i;if("end"===n.tagStr)break}},AF.prototype._decodeList=function(e,t,n,r){const i=[];for(;!e.isEmpty();){const t=this._peekTag(e,"end");if(e.isError(t))return t;const o=n.decode(e,"der",r);if(e.isError(o)&&t)break;i.push(o)}return i},AF.prototype._decodeStr=function(e,t){if("bitstr"===t){const t=e.readUInt8();return e.isError(t)?t:{unused:t,data:e.raw()}}if("bmpstr"===t){const t=e.raw();if(t.length%2==1)return e.error("Decoding of string type: bmpstr length mismatch");let n="";for(let e=0;e<t.length/2;e++)n+=String.fromCharCode(t.readUInt16BE(2*e));return n}if("numstr"===t){const t=e.raw().toString("ascii");return this._isNumstr(t)?t:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){const t=e.raw().toString("ascii");return this._isPrintstr(t)?t:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},AF.prototype._decodeObjid=function(e,t,n){let r;const i=[];let o=0,a=0;for(;!e.isEmpty();)a=e.readUInt8(),o<<=7,o|=127&a,0==(128&a)&&(i.push(o),o=0);128&a&&i.push(o);const s=i[0]/40|0,l=i[0]%40;if(r=n?i:[s,l].concat(i.slice(1)),t){let e=t[r.join(" ")];void 0===e&&(e=t[r.join(".")]),void 0!==e&&(r=e)}return r},AF.prototype._decodeTime=function(e,t){const n=e.raw().toString();let r,i,o,a,s,l;if("gentime"===t)r=0|n.slice(0,4),i=0|n.slice(4,6),o=0|n.slice(6,8),a=0|n.slice(8,10),s=0|n.slice(10,12),l=0|n.slice(12,14);else{if("utctime"!==t)return e.error("Decoding "+t+" time is not supported yet");r=0|n.slice(0,2),i=0|n.slice(2,4),o=0|n.slice(4,6),a=0|n.slice(6,8),s=0|n.slice(8,10),l=0|n.slice(10,12),r=r<70?2e3+r:1900+r}return Date.UTC(r,i-1,o,a,s,l,0)},AF.prototype._decodeNull=function(){return null},AF.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},AF.prototype._decodeInt=function(e,t){const n=e.raw();let r=new iF(n);return t&&(r=t[r.toString(10)]||r),r},AF.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree};const fF=Ow.exports,dF=BD.Buffer,pF=uF;function gF(e){pF.call(this,e),this.enc="pem"}fF(gF,pF);var yF=gF;gF.prototype.decode=function(e,t){const n=e.toString().split(/[\r\n]+/g),r=t.label.toUpperCase(),i=/^-----(BEGIN|END) ([^-]+)-----$/;let o=-1,a=-1;for(let e=0;e<n.length;e++){const t=n[e].match(i);if(null!==t&&t[2]===r){if(-1!==o){if("END"!==t[1])break;a=e;break}if("BEGIN"!==t[1])break;o=e}}if(-1===o||-1===a)throw new Error("PEM section not found for: "+r);const s=n.slice(o+1,a).join("");s.replace(/[^a-z0-9+/=]+/gi,"");const l=dF.from(s,"base64");return pF.prototype.decode.call(this,l,t)},function(e){const t=e;t.der=uF,t.pem=yF}(nF),function(e){const t=mD,n=nF,r=Ow.exports;function i(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}e.define=function(e,t){return new i(e,t)},i.prototype._createNamed=function(e){const t=this.name;function n(e){this._initNamed(e,t)}return r(n,e),n.prototype._initNamed=function(t,n){e.call(this,t,n)},new n(this)},i.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(n[e])),this.decoders[e]},i.prototype.decode=function(e,t,n){return this._getDecoder(t).decode(e,n)},i.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(t[e])),this.encoders[e]},i.prototype.encode=function(e,t,n){return this._getEncoder(t).encode(e,n)}}(yD);var mF={};!function(e){const t=mF;t.Reporter=ED.Reporter,t.DecoderBuffer=QD.DecoderBuffer,t.EncoderBuffer=QD.EncoderBuffer,t.Node=HD}();var vF={};!function(e){const t=e;t._reverse=function(e){const t={};return Object.keys(e).forEach((function(n){(0|n)==n&&(n|=0);const r=e[n];t[r]=n})),t},t.der=jD}(vF),function(e){const t=gD;t.bignum=Bw.exports,t.define=yD.define,t.base=mF,t.constants=vF,t.decoders=nF,t.encoders=mD}();var IF={exports:{}},wF={},bF={};Object.defineProperty(bF,"__esModule",{value:!0}),bF.default=function(e){var t=e.length,n=t%4;if(!n)return e;var r=t,i=4-n,o=t+i,a=ao.alloc(o);for(a.write(e);i--;)a.write("=",r++);return a.toString()},Object.defineProperty(wF,"__esModule",{value:!0});var BF=bF;function EF(e,t){return void 0===t&&(t="utf8"),jo(e)?SF(e.toString("base64")):SF(ao.from(e,t).toString("base64"))}function CF(e){return e=e.toString(),BF.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function SF(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var xF=EF;xF.encode=EF,xF.decode=function(e,t){return void 0===t&&(t="utf8"),ao.from(CF(e),"base64").toString(t)},xF.toBase64=CF,xF.fromBase64=SF,xF.toBuffer=function(e){return ao.from(CF(e),"base64")},wF.default=xF,function(e){e.exports=wF.default,e.exports.default=e.exports}(IF);var QF=IF.exports;const kF=gD,_F=IF.exports;var NF=class{static convert(e,t,n){if(!e)return;if(t===n)return e;let r;if("raw"===t||e instanceof ao)r=e;else if("uint8_array"===t||Array.isArray(e))r=ao.from(e);else if("hex"===t)r=ao.from(e,"hex");else if("base64"===t)r=ao.from(e,"base64");else if("base64url"===t)r=_F.toBuffer(e);else{if("bn"!==t&&"bignum"!==t)throw new Error("Invalid fromType");r=ao.from(this.pad(e.toString(16)),"hex")}if("raw"===n)return r;if("uint8_array"===n)return Array.from(r);if("hex"===n)return r.toString("hex");if("base64"===n)return r.toString("base64");if("base64url"===n)return _F.fromBase64(r.toString("base64"));if("bn"===n||"bignum"===n)return new kF.bignum(r);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}};const DF=gD;const FF=new class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(e,t){this._registry[e]=DF.define(e,t(this))}normalize(e){return this.registry[e]}};FF.define("Version",(e=>function(){this.int({0:"two-prime",1:"multi"})})),FF.define("OtherPrimeInfos",(e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),FF.define("AlgorithmIdentifier",(e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),FF.define("PrivateKeyInfo",(e=>{let t=e.normalize("Version"),n=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("version").use(t),this.key("algorithm").use(n),this.key("privateKey").octstr())}})),FF.define("PublicKeyInfo",(e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}})),FF.define("RSAPrivateKey",(e=>{let t=e.normalize("Version"),n=e.normalize("OtherPrimeInfos");return function(){this.seq().obj(this.key("version").use(t),this.key("n").int(),this.key("e").int(),this.key("d").int(),this.key("p").int(),this.key("q").int(),this.key("dp").int(),this.key("dq").int(),this.key("qi").int(),this.key("other").optional().use(n))}})),FF.define("RSAPublicKey",(e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),FF.define("ECPrivateKey",(e=>function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).optional().choice({namedCurve:this.objid()}),this.key("publicKey").explicit(1).optional().bitstr())}));var PF=FF;const UF=pD,MF=NF,LF=PF;class TF extends UF{fromPrivatePKCS1(e){let t=LF.normalize("RSAPrivateKey"),{n:n,e:r,d:i,p:o,q:a,dp:s,dq:l,qi:u}=t.decode(e,"der");return{n:MF.convert(n,"bn","raw"),e:MF.convert(r,"bn","raw"),d:MF.convert(i,"bn","raw"),p:MF.convert(o,"bn","raw"),q:MF.convert(a,"bn","raw"),dp:MF.convert(s,"bn","raw"),dq:MF.convert(l,"bn","raw"),qi:MF.convert(u,"bn","raw")}}fromPrivatePKCS8(e){let t=LF.normalize("PrivateKeyInfo"),n=LF.normalize("RSAPrivateKey"),r=t.decode(e,"der"),{n:i,e:o,d:a,p:s,q:l,dp:u,dq:A,qi:c}=n.decode(r.privateKey,"der");return{n:MF.convert(i,"bn","raw"),e:MF.convert(o,"bn","raw"),d:MF.convert(a,"bn","raw"),p:MF.convert(s,"bn","raw"),q:MF.convert(l,"bn","raw"),dp:MF.convert(u,"bn","raw"),dq:MF.convert(A,"bn","raw"),qi:MF.convert(c,"bn","raw")}}fromPublicPKCS1(e){let t=LF.normalize("RSAPublicKey"),{n:n,e:r}=t.decode(e,"der");return{n:MF.convert(n,"bn","raw"),e:MF.convert(r,"bn","raw")}}fromPublicPKCS8(e){let t=LF.normalize("PublicKeyInfo"),n=LF.normalize("RSAPublicKey"),r=t.decode(e,"der"),{n:i,e:o}=n.decode(r.publicKey.data,"der");return{n:MF.convert(i,"bn","raw"),e:MF.convert(o,"bn","raw")}}fromJwk(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l,alg:u}=e;return{n:MF.convert(t,"base64url","raw"),e:MF.convert(n,"base64url","raw"),d:MF.convert(r,"base64url","raw"),p:MF.convert(i,"base64url","raw"),q:MF.convert(o,"base64url","raw"),dp:MF.convert(a,"base64url","raw"),dq:MF.convert(s,"base64url","raw"),qi:MF.convert(l,"base64url","raw")}}toPrivatePKCS1(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l}=e,{version:u}=this.params,A=LF.normalize("RSAPrivateKey").encode({version:u,n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn"),d:MF.convert(r,"raw","bn"),p:MF.convert(i,"raw","bn"),q:MF.convert(o,"raw","bn"),dp:MF.convert(a,"raw","bn"),dq:MF.convert(s,"raw","bn"),qi:MF.convert(l,"raw","bn")},"der").toString("base64");return TF.formatPem(A,"RSA PRIVATE")}toPrivatePKCS8(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l}=e,{oid:u,algParameters:A,version:c}=this.params,h=LF.normalize("PrivateKeyInfo"),f=LF.normalize("RSAPrivateKey").encode({version:c,n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn"),d:MF.convert(r,"raw","bn"),p:MF.convert(i,"raw","bn"),q:MF.convert(o,"raw","bn"),dp:MF.convert(a,"raw","bn"),dq:MF.convert(s,"raw","bn"),qi:MF.convert(l,"raw","bn")},"der"),d=h.encode({version:c,algorithm:{algorithm:u.split("."),parameters:ao.from(A,"hex")},privateKey:f},"der").toString("base64");return TF.formatPem(d,"PRIVATE")}toPublicPKCS1(e){let{n:t,e:n}=e,{version:r}=this.params,i=LF.normalize("RSAPublicKey").encode({version:r,n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn")},"der").toString("base64");return TF.formatPem(i,"RSA PUBLIC")}toPublicPKCS8(e){let{n:t,e:n}=e,{oid:r,algParameters:i}=this.params,o=LF.normalize("PublicKeyInfo"),a=LF.normalize("RSAPublicKey").encode({n:MF.convert(t,"raw","bn"),e:MF.convert(n,"raw","bn")},"der"),s=o.encode({algorithm:{algorithm:r.split("."),parameters:ao.from(i,"hex")},publicKey:{unused:0,data:a}},"der").toString("base64");return TF.formatPem(s,"PUBLIC")}toPrivateJwk(e){let{n:t,e:n,d:r,p:i,q:o,dp:a,dq:s,qi:l}=e,{kty:u}=this.params;return{kty:u,n:MF.convert(t,"raw","base64url"),e:MF.convert(n,"raw","base64url"),d:MF.convert(r,"raw","base64url"),p:MF.convert(i,"raw","base64url"),q:MF.convert(o,"raw","base64url"),dp:MF.convert(a,"raw","base64url"),dq:MF.convert(s,"raw","base64url"),qi:MF.convert(l,"raw","base64url")}}toPublicJwk(e){let{n:t,e:n}=e,{kty:r}=this.params;return{kty:r,n:MF.convert(t,"raw","base64url"),e:MF.convert(n,"raw","base64url")}}}var RF=TF;const OF=new ww.ec("secp256k1"),HF=pD,KF=NF,jF=PF;class GF extends HF{fromPrivatePKCS1(e){let t=jF.normalize("ECPrivateKey").decode(e,"der"),{privateKey:n,publicKey:{data:r}}=t,i=KF.convert(r,"raw","hex"),{x:o,y:a}=GF.getPoint(i);return{d:n,x:o,y:a}}fromPrivatePKCS8(e){let t=jF.normalize("PrivateKeyInfo"),n=jF.normalize("ECPrivateKey"),r=t.decode(e,"der"),i=n.decode(r.privateKey,"der"),{privateKey:o,publicKey:{data:a}}=i,s=KF.convert(a,"raw","hex"),{x:l,y:u}=GF.getPoint(s);return{d:o,x:l,y:u}}fromPublicPKCS8(e){let t=jF.normalize("PublicKeyInfo").decode(e,"der"),n=KF.convert(t.publicKey.data,"raw","hex");return GF.getPoint(n)}fromPrivateBlk(e){let t=OF.keyFromPrivate(e,"hex"),n=t.getPublic();return{d:KF.convert(t.priv,"bn","raw"),x:KF.convert(n.getX(),"bn","raw"),y:KF.convert(n.getY(),"bn","raw")}}fromPublicBlk(e){return GF.getPoint(e)}fromJwk(e){let{d:t,x:n,y:r}=e;return{d:KF.convert(t,"base64url","raw"),x:KF.convert(n,"base64url","raw"),y:KF.convert(r,"base64url","raw")}}toPrivatePKCS1(e){let{namedCurve:t,keyVersion:n}=this.params,{d:r,x:i,y:o}=e,a=jF.normalize("ECPrivateKey"),s=GF.makePoint(i,o),l=a.encode({version:n,privateKey:r,parameters:{type:"namedCurve",value:t.split(".")},publicKey:{unused:0,data:s}},"der").toString("base64");return GF.formatPem(l,"EC PRIVATE")}toPrivatePKCS8(e){let{oid:t,algParameters:n,keyVersion:r,infoVersion:i}=this.params,{d:o,x:a,y:s}=e,l=jF.normalize("PrivateKeyInfo"),u=jF.normalize("ECPrivateKey"),A=GF.makePoint(a,s),c=u.encode({version:r,privateKey:o,publicKey:{unused:0,data:A}},"der"),h=l.encode({version:i,algorithm:{algorithm:t.split("."),parameters:ao.from(n,"hex")},privateKey:c},"der").toString("base64");return GF.formatPem(h,"PRIVATE")}toPublicPKCS8(e){let{oid:t,algParameters:n}=this.params,{x:r,y:i}=e,o=jF.normalize("PublicKeyInfo"),a=GF.makePoint(r,i),s=o.encode({algorithm:{algorithm:t.split("."),parameters:ao.from(n,"hex")},publicKey:{unused:0,data:a}},"der").toString("base64");return GF.formatPem(s,"PUBLIC")}toPrivateBlk(e){return e.d.toString("hex")}toPublicBlk(e){return KF.convert(GF.makePoint(e.x,e.y),"raw","hex")}toPrivateJwk(e){let{crv:t,kty:n}=this.params,{d:r,x:i,y:o}=e;return{kty:n,crv:t,d:KF.convert(r,"raw","base64url"),x:KF.convert(i,"raw","base64url"),y:KF.convert(o,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:n}=this.params,{x:r,y:i}=e;return{kty:n,crv:t,x:KF.convert(r,"raw","base64url"),y:KF.convert(i,"raw","base64url")}}static getPoint(e){let t=e.slice(2,(e.length-2)/2+2),n=e.slice((e.length-2)/2+2);return{x:KF.convert(t,"hex","raw"),y:KF.convert(n,"hex","raw")}}static makePoint(e,t){let n=ao.from("04","hex");return ao.concat([n,e,t],n.length+e.length+t.length)}}var qF=GF;const VF=pD,zF=NF,JF=PF;class YF extends VF{fromPrivatePKCS8(e){const t=JF.normalize("PrivateKeyInfo").decode(e,"der").privateKey.slice(2);return{d:t,x:this.publicKeyFromPrivate(t)}}fromPublicPKCS8(e){const t=JF.normalize("PublicKeyInfo").decode(e,"der");return{x:zF.convert(t.publicKey.data,"hex","raw")}}fromJwk(e){let{d:t,x:n}=e;return{d:zF.convert(t,"base64url","raw"),x:zF.convert(n,"base64url","raw")}}toPrivatePKCS8(e){let{oid:t,infoVersion:n}=this.params,{d:r}=e;const i=JF.normalize("PrivateKeyInfo"),o=this.privateKeyPadding(r);let a=i.encode({version:n,algorithm:{algorithm:t.split(".")},privateKey:o},"der").toString("base64");return YF.formatPem(a,"PRIVATE")}toPublicPKCS8(e){let{oid:t}=this.params,{x:n}=e,r=JF.normalize("PublicKeyInfo").encode({algorithm:{algorithm:t.split(".")},publicKey:{unused:0,data:zF.convert(n,"hex","raw")}},"der").toString("base64");return YF.formatPem(r,"PUBLIC")}toPrivateJwk(e){let{crv:t,kty:n}=this.params,{d:r,x:i}=e;return{kty:n,crv:t,d:zF.convert(r,"raw","base64url"),x:zF.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:n}=this.params,{x:r}=e;return{kty:n,crv:t,x:zF.convert(r,"raw","base64url")}}privateKeyPadding(e){let t;if("Ed25519"!==this.params.crv)throw new Error(`${this.params.crv} is an invalid curve for EdDSA`);return t=ao.from("0420","hex"),ao.concat([t,e],t.length+e.length)}publicKeyFromPrivate(e){if("Ed25519"===this.params.crv){const t=new ww.eddsa("ed25519");return ao.from(t.keyFromSecret(e).getPublic())}throw new Error(`${this.params.crv} is an invalid curve for EdDSA`)}}const XF=RF,WF=qF,ZF=YF,$F=new class{constructor(){this.registry=[],this.classes={}}find(e){return this.registry.find(e)}define(e,t){e.forEach((e=>{let{kty:n}=e;if(!n)throw new Error("Invalid type definition");this.classes[n]||(this.classes[n]=t),this.registry.push(e)}))}normalize(e,t,n){let r=this.classes[e],i=this.find((e=>e[t]===n));if(!r||!i)throw new Error("Invalid type");return new r(i)}};$F.define([{kty:"RSA",oid:"1.2.840.113549.1.1.1",algParameters:"0500",version:"two-prime"}],XF),$F.define([{kty:"EC",crv:"K-256",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.10",algParameters:"06052b8104000a",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-256",oid:"1.2.840.10045.2.1",namedCurve:"1.2.840.10045.3.1.7",algParameters:"06082a8648ce3d030107",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-384",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.34",algParameters:"06052b81040022",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-521",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.35",algParameters:"06052b81040023",keyVersion:1,infoVersion:"two-prime"}],WF),$F.define([{kty:"OKP",crv:"Ed25519",oid:"1.3.101.112",infoVersion:"two-prime"}],ZF);const eP=AD,tP=hD,nP=$F,rP=PF,iP=RegExp("\r?\n","g");class oP{constructor(e,t){if(!e)throw new eP("key is required");if(!t)throw new eP("options are required");let{kty:n,format:r,selector:i,crv:o,oid:a}=t;if(!t.kty)throw new eP("options.kty is required");if(!t.format)throw new eP("options.format is required");if(!t.selector)throw new eP("options.selector is required");if(!t.crv&&!t.oid)throw new eP("options.crv or options.oid is required");this.kty=n,this.format=r,this.selector=i,this.crv=o,this.oid=a,this.key=this.parseKey(e)}static from(e,t){if(!e)throw new eP("key is required");if(!t)throw new eP("format is required");if("jwk"===t){let n;if("string"==typeof e)try{n=JSON.parse(e)}catch(e){throw new eP("key is not a valid JWK")}else"object"==typeof e&&(n=e);let r,{kty:i,crv:o}=n;if(!i)throw new eP("kty is required for JWK");if("EC"===i&&!o)throw new eP("crv is required for EC JWK");"RSA"===i&&(r=nP.find((e=>e.kty===i)).oid);let a=n.d?"private":"public";return new oP(n,{kty:i,crv:o,oid:r,format:t,selector:a})}if("pem"===t){if("string"!=typeof e)throw new eP("key is not a valid PEM string");let n=e.split(iP),r=n.splice(0,1);n.splice(n.length-1,1);let i,o,a=n.join(""),s=/^-----BEGIN ((RSA|EC) )?(PUBLIC|PRIVATE) KEY-----$/.exec(r),l=s?s[2]:void 0,u=s?s[3]:void 0,A=ao.from(a,"base64");if(!u)throw new eP("key is not a valid PEM string");if(l){if("RSA"===l)u="PRIVATE"===u?"private_pkcs1":"public_pkcs1",i=nP.find((e=>e.kty===l)).oid;else if("EC"===l){let e;if("PRIVATE"===u){let t=rP.normalize(`${l}PrivateKey`);u="private_pkcs1",e=t.decode(A,"der")}else if("PUBLIC"===u){let t=rP.normalize(`${l}PrivateKey`);u="public_pkcs1",e=t.decode(A,"der")}let{parameters:{value:t}}=e;o=nP.find((e=>e.namedCurve===t.join("."))).crv}}else{let e,t=rP.normalize("PrivateKeyInfo"),n=rP.normalize("PublicKeyInfo");"PRIVATE"===u?(u="private_pkcs8",e=t.decode(A,"der")):"PUBLIC"===u&&(u="public_pkcs8",e=n.decode(A,"der"));let{algorithm:{algorithm:r,parameters:a}}=e;r=r.join("."),a=a?a.toString("hex"):void 0;const s=nP.find((e=>e.oid===r));if(l=s?s.kty:void 0,!l)throw new eP(`${r} is not supported`);"RSA"===l||"OKP"===l?i=r:"EC"===l&&(o=nP.find((e=>e.algParameters===a)).crv)}return new oP(A,{kty:l,oid:i,crv:o,format:t,selector:u})}if("blk"===t)return new oP(e,{kty:"EC",crv:"K-256",format:t,selector:e.length>64?"public":"private"});throw new eP(`Invalid format ${t}`)}get alg(){let{kty:e,crv:t,oid:n}=this;if(!this.algorithm){if(t)Object.defineProperty(this,"algorithm",{value:nP.normalize(e,"crv",t)});else{if(!n)throw new Error("Both crv and oid are undefined");Object.defineProperty(this,"algorithm",{value:nP.normalize(e,"oid",n)})}if(!this.algorithm)throw new Error(`${this.crv||this.oid} is not implemented yet`)}return this.algorithm}parseKey(e){let{alg:t,format:n,selector:r}=this;if("pem"===n)switch(r){case"public_pkcs1":return t.fromPublicPKCS1(e);case"public_pkcs8":return t.fromPublicPKCS8(e);case"private_pkcs1":return t.fromPrivatePKCS1(e);case"private_pkcs8":return t.fromPrivatePKCS8(e);default:throw new Error("Invalid selector value")}if("jwk"===n)return t.fromJwk(e,r);if("blk"===n)switch(r){case"public":return t.fromPublicBlk(e);case"private":return t.fromPrivateBlk(e)}}toJwk(e){let{key:t,alg:n,selector:r}=this;switch(e){case"public":return n.toPublicJwk(t);case"private":if(r.includes("public"))throw new eP("Cannot export a private key from a public key");return n.toPrivateJwk(t);default:throw new Error("Invalid key selector")}}toString(e="pem",t="public_pkcs8"){let{key:n,alg:r,selector:i}=this;if("pem"===e)switch(t){case"public_pkcs1":return r.toPublicPKCS1(n);case"public_pkcs8":return r.toPublicPKCS8(n);case"private_pkcs1":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return r.toPrivatePKCS1(n);case"private_pkcs8":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return r.toPrivatePKCS8(n);default:throw new Error("Invalid key selector")}else if("jwk"===e)switch(t){case"public":return JSON.stringify(r.toPublicJwk(n));case"private":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return JSON.stringify(r.toPrivateJwk(n));default:throw new Error("Invalid key selector")}else if("blk"===e)switch(t){case"private":if(i.includes("public"))throw new eP("Cannot export a private key from a public key");return r.toPrivateBlk(n);case"public":return r.toPublicBlk(n);default:throw new Error("Invalid key selector")}throw new tP}}var aP=oP,sP=U_("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const lP=ao;var uP={},AP={},cP={};Object.defineProperty(cP,"__esModule",{value:!0}),cP.testnet=cP.regtest=cP.bitcoin=void 0,cP.bitcoin={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},cP.regtest={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},cP.testnet={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var hP={},fP={},dP={},pP={};Object.defineProperty(pP,"__esModule",{value:!0}),pP.encode=pP.decode=pP.check=void 0,pP.check=function(e){if(e.length<8)return!1;if(e.length>72)return!1;if(48!==e[0])return!1;if(e[1]!==e.length-2)return!1;if(2!==e[2])return!1;const t=e[3];if(0===t)return!1;if(5+t>=e.length)return!1;if(2!==e[4+t])return!1;const n=e[5+t];return!(0===n||6+t+n!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||n>1&&0===e[t+6]&&!(128&e[t+7]))},pP.decode=function(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");const t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");const n=e[5+t];if(0===n)throw new Error("S length is zero");if(6+t+n!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(n>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}},pP.encode=function(e,t){const n=e.length,r=t.length;if(0===n)throw new Error("R length is zero");if(0===r)throw new Error("S length is zero");if(n>33)throw new Error("R length is too long");if(r>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(n>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(r>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");const i=ao.allocUnsafe(6+n+r);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+n]=2,i[5+n]=t.length,t.copy(i,6+n),i};var gP={};Object.defineProperty(gP,"__esModule",{value:!0}),gP.REVERSE_OPS=gP.OPS=void 0;const yP={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};gP.OPS=yP;const mP={};gP.REVERSE_OPS=mP;for(const e of Object.keys(yP))mP[yP[e]]=e;var vP={};Object.defineProperty(vP,"__esModule",{value:!0}),vP.decode=vP.encode=vP.encodingLength=void 0;const IP=gP;function wP(e){return e<IP.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}vP.encodingLength=wP,vP.encode=function(e,t,n){const r=wP(t);return 1===r?e.writeUInt8(t,n):2===r?(e.writeUInt8(IP.OPS.OP_PUSHDATA1,n),e.writeUInt8(t,n+1)):3===r?(e.writeUInt8(IP.OPS.OP_PUSHDATA2,n),e.writeUInt16LE(t,n+1)):(e.writeUInt8(IP.OPS.OP_PUSHDATA4,n),e.writeUInt32LE(t,n+1)),r},vP.decode=function(e,t){const n=e.readUInt8(t);let r,i;if(n<IP.OPS.OP_PUSHDATA1)r=n,i=1;else if(n===IP.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;r=e.readUInt8(t+1),i=2}else if(n===IP.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;r=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(n!==IP.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=e.readUInt32LE(t+1),i=5}return{opcode:n,number:r,size:i}};var bP={};Object.defineProperty(bP,"__esModule",{value:!0}),bP.encode=bP.decode=void 0,bP.decode=function(e,t,n){t=t||4,n=void 0===n||n;const r=e.length;if(0===r)return 0;if(r>t)throw new TypeError("Script number overflow");if(n&&0==(127&e[r-1])&&(r<=1||0==(128&e[r-2])))throw new Error("Non-minimally encoded script number");if(5===r){const t=e.readUInt32LE(0),n=e.readUInt8(4);return 128&n?-(4294967296*(-129&n)+t):4294967296*n+t}let i=0;for(let t=0;t<r;++t)i|=e[t]<<8*t;return 128&e[r-1]?-(i&~(128<<8*(r-1))):i},bP.encode=function(e){let t=Math.abs(e);const n=(r=t)>2147483647?5:r>8388607?4:r>32767?3:r>127?2:r>0?1:0;var r;const i=ao.allocUnsafe(n),o=e<0;for(let e=0;e<n;++e)i.writeUInt8(255&t,e),t>>=8;return 128&i[n-1]?i.writeUInt8(o?128:0,n-1):o&&(i[n-1]|=128),i};var BP={},EP={},CP={Array:function(e){return null!=e&&e.constructor===Array},Boolean:function(e){return"boolean"==typeof e},Function:function(e){return"function"==typeof e},Nil:function(e){return null==e},Number:function(e){return"number"==typeof e},Object:function(e){return"object"==typeof e},String:function(e){return"string"==typeof e},"":function(){return!0}};for(var SP in CP.Null=CP.Nil,CP)CP[SP].toJSON=function(e){return e}.bind(null,SP);var xP=CP,QP=xP;function kP(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function _P(e){return QP.Nil(e)?"":kP(e.constructor)}function NP(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function DP(e){return QP.Function(e)?e.toJSON?e.toJSON():kP(e):QP.Array(e)?"Array":e&&QP.Object(e)?"Object":void 0!==e?e:""}function FP(e,t,n){var r=function(e){return QP.Function(e)?"":QP.String(e)?JSON.stringify(e):e&&QP.Object(e)?"":e}(t);return"Expected "+DP(e)+", got"+(""!==n?" "+n:"")+(""!==r?" "+r:"")}function PP(e,t,n){n=n||_P(t),this.message=FP(e,t,n),NP(this,PP),this.__type=e,this.__value=t,this.__valueTypeName=n}function UP(e,t,n,r,i){e?(i=i||_P(r),this.message=function(e,t,n,r,i){var o='" of type ';return"key"===t&&(o='" with key type '),FP('property "'+DP(n)+o+DP(e),r,i)}(e,n,t,r,i)):this.message='Unexpected property "'+t+'"',NP(this,PP),this.__label=n,this.__property=t,this.__type=e,this.__value=r,this.__valueTypeName=i}PP.prototype=Object.create(Error.prototype),PP.prototype.constructor=PP,UP.prototype=Object.create(Error.prototype),UP.prototype.constructor=PP;var MP={TfTypeError:PP,TfPropertyTypeError:UP,tfCustomError:function(e,t){return new PP(e,{},t)},tfSubError:function(e,t,n){return e instanceof UP?(t=t+"."+e.__property,e=new UP(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof PP&&(e=new UP(e.__type,t,n,e.__value,e.__valueTypeName)),NP(e),e},tfJSON:DP,getValueTypeName:_P},LP=xP,TP=MP;function RP(e){return jo(e)}function OP(e){return"string"==typeof e&&/^([0-9a-f]{2})+$/i.test(e)}function HP(e,t){var n=e.toJSON();function r(r){if(!e(r))return!1;if(r.length===t)return!0;throw TP.tfCustomError(n+"(Length: "+t+")",n+"(Length: "+r.length+")")}return r.toJSON=function(){return n},r}var KP=HP.bind(null,LP.Array),jP=HP.bind(null,RP),GP=HP.bind(null,OP),qP=HP.bind(null,LP.String),VP=Math.pow(2,53)-1,zP={ArrayN:KP,Buffer:RP,BufferN:jP,Finite:function(e){return"number"==typeof e&&isFinite(e)},Hex:OP,HexN:GP,Int8:function(e){return e<<24>>24===e},Int16:function(e){return e<<16>>16===e},Int32:function(e){return(0|e)===e},Int53:function(e){return"number"==typeof e&&e>=-VP&&e<=VP&&Math.floor(e)===e},Range:function(e,t,n){function r(r,i){return n(r,i)&&r>e&&r<t}return n=n||LP.Number,r.toJSON=function(){return`${n.toJSON()} between [${e}, ${t}]`},r},StringN:qP,UInt8:function(e){return(255&e)===e},UInt16:function(e){return(65535&e)===e},UInt32:function(e){return e>>>0===e},UInt53:function(e){return"number"==typeof e&&e>=0&&e<=VP&&Math.floor(e)===e}};for(var JP in zP)zP[JP].toJSON=function(e){return e}.bind(null,JP);var YP=zP,XP=xP,WP=MP.tfJSON,ZP=MP.TfTypeError,$P=MP.TfPropertyTypeError,eU=MP.tfSubError,tU=MP.getValueTypeName,nU={arrayOf:function(e,t){function n(n,r){return!!XP.Array(n)&&!XP.Nil(n)&&!(void 0!==t.minLength&&n.length<t.minLength)&&!(void 0!==t.maxLength&&n.length>t.maxLength)&&(void 0===t.length||n.length===t.length)&&n.every((function(t,n){try{return iU(e,t,r)}catch(e){throw eU(e,n)}}))}return e=rU(e),t=t||{},n.toJSON=function(){var n="["+WP(e)+"]";return void 0!==t.length?n+="{"+t.length+"}":void 0===t.minLength&&void 0===t.maxLength||(n+="{"+(void 0===t.minLength?0:t.minLength)+","+(void 0===t.maxLength?1/0:t.maxLength)+"}"),n},n},maybe:function e(t){function n(n,r){return XP.Nil(n)||t(n,r,e)}return t=rU(t),n.toJSON=function(){return"?"+WP(t)},n},map:function(e,t){function n(n,r){if(!XP.Object(n))return!1;if(XP.Nil(n))return!1;for(var i in n){try{t&&iU(t,i,r)}catch(e){throw eU(e,i,"key")}try{var o=n[i];iU(e,o,r)}catch(e){throw eU(e,i)}}return!0}return e=rU(e),t&&(t=rU(t)),n.toJSON=t?function(){return"{"+WP(t)+": "+WP(e)+"}"}:function(){return"{"+WP(e)+"}"},n},object:function(e){var t={};for(var n in e)t[n]=rU(e[n]);function r(e,n){if(!XP.Object(e))return!1;if(XP.Nil(e))return!1;var r;try{for(r in t)iU(t[r],e[r],n)}catch(e){throw eU(e,r)}if(n)for(r in e)if(!t[r])throw new $P(void 0,r);return!0}return r.toJSON=function(){return WP(t)},r},anyOf:function(){var e=[].slice.call(arguments).map(rU);function t(t,n){return e.some((function(e){try{return iU(e,t,n)}catch(e){return!1}}))}return t.toJSON=function(){return e.map(WP).join("|")},t},allOf:function(){var e=[].slice.call(arguments).map(rU);function t(t,n){return e.every((function(e){try{return iU(e,t,n)}catch(e){return!1}}))}return t.toJSON=function(){return e.map(WP).join(" & ")},t},quacksLike:function(e){function t(t){return e===tU(t)}return t.toJSON=function(){return e},t},tuple:function(){var e=[].slice.call(arguments).map(rU);function t(t,n){return!XP.Nil(t)&&!XP.Nil(t.length)&&(!n||t.length===e.length)&&e.every((function(e,r){try{return iU(e,t[r],n)}catch(e){throw eU(e,r)}}))}return t.toJSON=function(){return"("+e.map(WP).join(", ")+")"},t},value:function(e){function t(t){return t===e}return t.toJSON=function(){return e},t}};function rU(e){if(XP.String(e))return"?"===e[0]?nU.maybe(e.slice(1)):XP[e]||nU.quacksLike(e);if(e&&XP.Object(e)){if(XP.Array(e)){if(1!==e.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return nU.arrayOf(e[0])}return nU.object(e)}return XP.Function(e)?e:nU.value(e)}function iU(e,t,n,r){if(XP.Function(e)){if(e(t,n))return!0;throw new ZP(r||e,t)}return iU(rU(e),t,n)}for(var oU in nU.oneOf=nU.anyOf,XP)iU[oU]=XP[oU];for(oU in nU)iU[oU]=nU[oU];var aU=YP;for(oU in aU)iU[oU]=aU[oU];iU.compile=rU,iU.TfTypeError=ZP,iU.TfPropertyTypeError=$P;var sU=iU;!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.Network=e.ECPoint=e.Satoshi=e.Signer=e.BIP32Path=e.UInt31=e.isPoint=e.typeforce=void 0;const t=qo;e.typeforce=sU;const n=t.Buffer.alloc(32,0),r=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");e.isPoint=function(e){if(!t.Buffer.isBuffer(e))return!1;if(e.length<33)return!1;const i=e[0],o=e.slice(1,33);if(0===o.compare(n))return!1;if(o.compare(r)>=0)return!1;if((2===i||3===i)&&33===e.length)return!0;const a=e.slice(33);return 0!==a.compare(n)&&!(a.compare(r)>=0)&&4===i&&65===e.length};const i=Math.pow(2,31)-1;function o(t){return e.typeforce.String(t)&&!!t.match(/^(m\/)?(\d+'?\/)*\d+'?$/)}e.UInt31=function(t){return e.typeforce.UInt32(t)&&t<=i},e.BIP32Path=o,o.toJSON=()=>"BIP32 derivation path",e.Signer=function(t){return(e.typeforce.Buffer(t.publicKey)||"function"==typeof t.getPublicKey)&&"function"==typeof t.sign},e.Satoshi=function(t){return e.typeforce.UInt53(t)&&t<=21e14},e.ECPoint=e.typeforce.quacksLike("Point"),e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf}(EP),Object.defineProperty(BP,"__esModule",{value:!0}),BP.encode=BP.decode=void 0;const lU=pP,uU=EP,{typeforce:AU}=uU,cU=ao.alloc(1,0);function hU(e){let t=0;for(;0===e[t];)++t;return t===e.length?cU:128&(e=e.slice(t))[0]?ao.concat([cU,e],1+e.length):e}function fU(e){0===e[0]&&(e=e.slice(1));const t=ao.alloc(32,0),n=Math.max(0,32-e.length);return e.copy(t,n),t}BP.decode=function(e){const t=e.readUInt8(e.length-1),n=-129&t;if(n<=0||n>=4)throw new Error("Invalid hashType "+t);const r=lU.decode(e.slice(0,-1)),i=fU(r.r),o=fU(r.s);return{signature:ao.concat([i,o],64),hashType:t}},BP.encode=function(e,t){AU({signature:uU.BufferN(64),hashType:uU.UInt8},{signature:e,hashType:t});const n=-129&t;if(n<=0||n>=4)throw new Error("Invalid hashType "+t);const r=ao.allocUnsafe(1);r.writeUInt8(t,0);const i=hU(e.slice(0,32)),o=hU(e.slice(32,64));return ao.concat([lU.encode(i,o),r])},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.isPushOnly=e.OPS=void 0;const t=pP,n=gP;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return n.OPS}});const r=vP,i=bP,o=BP,a=EP,{typeforce:s}=a,l=n.OPS.OP_RESERVED;function u(e){return a.Buffer(e)||function(e){return a.Number(e)&&(e===n.OPS.OP_0||e>=n.OPS.OP_1&&e<=n.OPS.OP_16||e===n.OPS.OP_1NEGATE)}(e)}function A(e){return a.Array(e)&&e.every(u)}function c(e){return 0===e.length?n.OPS.OP_0:1===e.length?e[0]>=1&&e[0]<=16?l+e[0]:129===e[0]?n.OPS.OP_1NEGATE:void 0:void 0}function h(e){return jo(e)}function f(e){return jo(e)}function d(e){if(h(e))return e;s(a.Array,e);const t=e.reduce(((e,t)=>f(t)?1===t.length&&void 0!==c(t)?e+1:e+r.encodingLength(t.length)+t.length:e+1),0),n=ao.allocUnsafe(t);let i=0;if(e.forEach((e=>{if(f(e)){const t=c(e);if(void 0!==t)return n.writeUInt8(t,i),void(i+=1);i+=r.encode(n,e.length,i),e.copy(n,i),i+=e.length}else n.writeUInt8(e,i),i+=1})),i!==n.length)throw new Error("Could not decode chunks");return n}function p(e){if(t=e,a.Array(t))return e;var t;s(a.Buffer,e);const i=[];let o=0;for(;o<e.length;){const t=e[o];if(t>n.OPS.OP_0&&t<=n.OPS.OP_PUSHDATA4){const t=r.decode(e,o);if(null===t)return null;if(o+=t.size,o+t.number>e.length)return null;const n=e.slice(o,o+t.number);o+=t.number;const a=c(n);void 0!==a?i.push(a):i.push(n)}else i.push(t),o+=1}return i}function g(e){const t=-129&e;return t>0&&t<4}e.isPushOnly=A,e.compile=d,e.decompile=p,e.toASM=function(e){return h(e)&&(e=p(e)),e.map((e=>{if(f(e)){const t=c(e);if(void 0===t)return e.toString("hex");e=t}return n.REVERSE_OPS[e]})).join(" ")},e.fromASM=function(e){return s(a.String,e),d(e.split(" ").map((e=>void 0!==n.OPS[e]?n.OPS[e]:(s(a.Hex,e),ao.from(e,"hex")))))},e.toStack=function(e){return e=p(e),s(A,e),e.map((e=>f(e)?e:e===n.OPS.OP_0?ao.allocUnsafe(0):i.encode(e-l)))},e.isCanonicalPubKey=function(e){return a.isPoint(e)},e.isDefinedHashType=g,e.isCanonicalScriptSignature=function(e){return!!jo(e)&&!!g(e[e.length-1])&&t.check(e.slice(0,-1))},e.number=i,e.signature=o}(dP);var dU={};Object.defineProperty(dU,"__esModule",{value:!0}),dU.value=dU.prop=void 0,dU.prop=function(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const e=n.call(this);return this[t]=e,e},set(e){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:e,writable:!0})}})},dU.value=function(e){let t;return()=>(void 0!==t||(t=e()),t)},Object.defineProperty(fP,"__esModule",{value:!0}),fP.p2data=void 0;const pU=cP,gU=dP,yU=EP,mU=dU,vU=gU.OPS;fP.p2data=function(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,yU.typeforce)({network:yU.typeforce.maybe(yU.typeforce.Object),output:yU.typeforce.maybe(yU.typeforce.Buffer),data:yU.typeforce.maybe(yU.typeforce.arrayOf(yU.typeforce.Buffer))},e);const n={name:"embed",network:e.network||pU.bitcoin};if(mU.prop(n,"output",(()=>{if(e.data)return gU.compile([vU.OP_RETURN].concat(e.data))})),mU.prop(n,"data",(()=>{if(e.output)return gU.decompile(e.output).slice(1)})),t.validate&&e.output){const t=gU.decompile(e.output);if(t[0]!==vU.OP_RETURN)throw new TypeError("Output is invalid");if(!t.slice(1).every(yU.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!function(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)};var IU={};Object.defineProperty(IU,"__esModule",{value:!0}),IU.p2ms=void 0;const wU=cP,bU=dP,BU=EP,EU=dU,CU=bU.OPS,SU=CU.OP_RESERVED;function xU(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}IU.p2ms=function(e,t){if(!(e.input||e.output||e.pubkeys&&void 0!==e.m||e.signatures))throw new TypeError("Not enough data");function n(e){return bU.isCanonicalScriptSignature(e)||void 0!==(t.allowIncomplete&&e===CU.OP_0)}t=Object.assign({validate:!0},t||{}),(0,BU.typeforce)({network:BU.typeforce.maybe(BU.typeforce.Object),m:BU.typeforce.maybe(BU.typeforce.Number),n:BU.typeforce.maybe(BU.typeforce.Number),output:BU.typeforce.maybe(BU.typeforce.Buffer),pubkeys:BU.typeforce.maybe(BU.typeforce.arrayOf(BU.isPoint)),signatures:BU.typeforce.maybe(BU.typeforce.arrayOf(n)),input:BU.typeforce.maybe(BU.typeforce.Buffer)},e);const r={network:e.network||wU.bitcoin};let i=[],o=!1;function a(e){o||(o=!0,i=bU.decompile(e),r.m=i[0]-SU,r.n=i[i.length-2]-SU,r.pubkeys=i.slice(1,-2))}if(EU.prop(r,"output",(()=>{if(e.m&&r.n&&e.pubkeys)return bU.compile([].concat(SU+e.m,e.pubkeys,SU+r.n,CU.OP_CHECKMULTISIG))})),EU.prop(r,"m",(()=>{if(r.output)return a(r.output),r.m})),EU.prop(r,"n",(()=>{if(r.pubkeys)return r.pubkeys.length})),EU.prop(r,"pubkeys",(()=>{if(e.output)return a(e.output),r.pubkeys})),EU.prop(r,"signatures",(()=>{if(e.input)return bU.decompile(e.input).slice(1)})),EU.prop(r,"input",(()=>{if(e.signatures)return bU.compile([CU.OP_0].concat(e.signatures))})),EU.prop(r,"witness",(()=>{if(r.input)return[]})),EU.prop(r,"name",(()=>{if(r.m&&r.n)return`p2ms(${r.m} of ${r.n})`})),t.validate){if(e.output){if(a(e.output),!BU.typeforce.Number(i[0]))throw new TypeError("Output is invalid");if(!BU.typeforce.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==CU.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(r.m<=0||r.n>16||r.m>r.n||r.n!==i.length-3)throw new TypeError("Output is invalid");if(!r.pubkeys.every((e=>(0,BU.isPoint)(e))))throw new TypeError("Output is invalid");if(void 0!==e.m&&e.m!==r.m)throw new TypeError("m mismatch");if(void 0!==e.n&&e.n!==r.n)throw new TypeError("n mismatch");if(e.pubkeys&&!xU(e.pubkeys,r.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(void 0!==e.n&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(r.n=e.pubkeys.length,r.n<r.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<r.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>r.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==CU.OP_0)throw new TypeError("Input is invalid");if(0===r.signatures.length||!r.signatures.every(n))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!xU(e.signatures,r.signatures))throw new TypeError("Signature mismatch");if(void 0!==e.m&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(r,e)};var QU={};Object.defineProperty(QU,"__esModule",{value:!0}),QU.p2pk=void 0;const kU=cP,_U=dP,NU=EP,DU=dU,FU=_U.OPS;QU.p2pk=function(e,t){if(!(e.input||e.output||e.pubkey||e.input||e.signature))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,NU.typeforce)({network:NU.typeforce.maybe(NU.typeforce.Object),output:NU.typeforce.maybe(NU.typeforce.Buffer),pubkey:NU.typeforce.maybe(NU.isPoint),signature:NU.typeforce.maybe(_U.isCanonicalScriptSignature),input:NU.typeforce.maybe(NU.typeforce.Buffer)},e);const n=DU.value((()=>_U.decompile(e.input))),r={name:"p2pk",network:e.network||kU.bitcoin};if(DU.prop(r,"output",(()=>{if(e.pubkey)return _U.compile([e.pubkey,FU.OP_CHECKSIG])})),DU.prop(r,"pubkey",(()=>{if(e.output)return e.output.slice(1,-1)})),DU.prop(r,"signature",(()=>{if(e.input)return n()[0]})),DU.prop(r,"input",(()=>{if(e.signature)return _U.compile([e.signature])})),DU.prop(r,"witness",(()=>{if(r.input)return[]})),t.validate){if(e.output){if(e.output[e.output.length-1]!==FU.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,NU.isPoint)(r.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(r.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(r.input))throw new TypeError("Signature mismatch");if(e.input){if(1!==n().length)throw new TypeError("Input is invalid");if(!_U.isCanonicalScriptSignature(r.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(r,e)};var PU={},UU={},MU={exports:{}},LU={},TU=ji(sc),RU=TU.EventEmitter;function OU(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function HU(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var KU=qo.Buffer,jU=AI.inspect,GU=jU&&jU.custom||"inspect";function qU(e,t,n){KU.prototype.copy.call(e,t,n)}var VU=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}var t;return t=[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return KU.alloc(0);for(var t=KU.allocUnsafe(e>>>0),n=this.head,r=0;n;)qU(n.data,t,r),r+=n.data.length,n=n.next;return t}},{key:"consume",value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,o=e>i.length?i.length:e;if(o===i.length?r+=i:r+=i.slice(0,e),0==(e-=o)){o===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++n}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=KU.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,o=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,o),0==(e-=o)){o===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(o));break}++r}return this.length-=r,t}},{key:GU,value:function(e,t){return jU(this,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?OU(Object(n),!0).forEach((function(t){HU(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):OU(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},t,{depth:0,customInspect:!1}))}}],t&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}();function zU(e,t){YU(e,t),JU(e)}function JU(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function YU(e,t){e.emit("error",t)}var XU={destroy:function(e,t){var n=this,r=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return r||i?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,ru(YU,this,e)):ru(YU,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!t&&e?n._writableState?n._writableState.errorEmitted?ru(JU,n):(n._writableState.errorEmitted=!0,ru(zU,n,e)):ru(zU,n,e):t?(ru(JU,n),t(e)):ru(JU,n)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit("error",t)}},WU={},ZU={};function $U(e,t,n){n||(n=Error);var r=function(e){var n,r;function i(n,r,i){return e.call(this,function(e,n,r){return"string"==typeof t?t:t(e,n,r)}(n,r,i))||this}return r=e,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,n.__proto__=r,i}(n);r.prototype.name=n.name,r.prototype.code=e,ZU[e]=r}function eM(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map((function(e){return String(e)})),n>2?"one of ".concat(t," ").concat(e.slice(0,n-1).join(", "),", or ")+e[n-1]:2===n?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}$U("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),$U("ERR_INVALID_ARG_TYPE",(function(e,t,n){var r,i,o;if("string"==typeof t&&(i="not ",t.substr(0,i.length)===i)?(r="must not be",t=t.replace(/^not /,"")):r="must be",function(e,t,n){return(void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}(e," argument"))o="The ".concat(e," ").concat(r," ").concat(eM(t,"type"));else{var a=function(e,t,n){return"number"!=typeof n&&(n=0),!(n+".".length>e.length)&&-1!==e.indexOf(".",n)}(e)?"property":"argument";o='The "'.concat(e,'" ').concat(a," ").concat(r," ").concat(eM(t,"type"))}return o+". Received type ".concat(typeof n)}),TypeError),$U("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),$U("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),$U("ERR_STREAM_PREMATURE_CLOSE","Premature close"),$U("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),$U("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),$U("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),$U("ERR_STREAM_WRITE_AFTER_END","write after end"),$U("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),$U("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),$U("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),WU.codes=ZU;var tM=WU.codes.ERR_INVALID_OPT_VALUE,nM=function(e,t,n,r){var i=function(e,t,n){return null!=e.highWaterMark?e.highWaterMark:t?e[n]:null}(t,r,n);if(null!=i){if(!isFinite(i)||Math.floor(i)!==i||i<0)throw new tM(r?n:"highWaterMark",i);return Math.floor(i)}return e.objectMode?16:16384},rM={},iM=F_.exports.Buffer,oM=iM.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function aM(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(iM.isEncoding===oM||!oM(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=uM,this.end=AM,t=4;break;case"utf8":this.fillLast=lM,t=4;break;case"base64":this.text=cM,this.end=hM,t=3;break;default:return this.write=fM,void(this.end=dM)}this.lastNeed=0,this.lastTotal=0,this.lastChar=iM.allocUnsafe(t)}function sM(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function lM(e){var t=this.lastTotal-this.lastNeed,n=function(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function uM(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function AM(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function cM(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function hM(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function fM(e){return e.toString(this.encoding)}function dM(e){return e&&e.length?this.write(e):""}rM.StringDecoder=aM,aM.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},aM.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},aM.prototype.text=function(e,t){var n=function(e,t,n){var r=t.length-1;if(r<n)return 0;var i=sM(t[r]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--r<n||-2===i?0:(i=sM(t[r]))>=0?(i>0&&(e.lastNeed=i-2),i):--r<n||-2===i?0:(i=sM(t[r]))>=0?(i>0&&(2===i?i=0:e.lastNeed=i-3),i):0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)},aM.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};var pM=WU.codes.ERR_STREAM_PREMATURE_CLOSE;function gM(){}var yM,mM=function e(t,n,r){if("function"==typeof n)return e(t,null,n);n||(n={}),r=function(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.apply(this,r)}}}(r||gM);var i=n.readable||!1!==n.readable&&t.readable,o=n.writable||!1!==n.writable&&t.writable,a=function(){t.writable||l()},s=t._writableState&&t._writableState.finished,l=function(){o=!1,s=!0,i||r.call(t)},u=t._readableState&&t._readableState.endEmitted,A=function(){i=!1,u=!0,o||r.call(t)},c=function(e){r.call(t,e)},h=function(){var e;return i&&!u?(t._readableState&&t._readableState.ended||(e=new pM),r.call(t,e)):o&&!s?(t._writableState&&t._writableState.ended||(e=new pM),r.call(t,e)):void 0},f=function(){t.req.on("finish",l)};return function(e){return e.setHeader&&"function"==typeof e.abort}(t)?(t.on("complete",l),t.on("abort",h),t.req?f():t.on("request",f)):o&&!t._writableState&&(t.on("end",a),t.on("close",a)),t.on("end",A),t.on("finish",l),!1!==n.error&&t.on("error",c),t.on("close",h),function(){t.removeListener("complete",l),t.removeListener("abort",h),t.removeListener("request",f),t.req&&t.req.removeListener("finish",l),t.removeListener("end",a),t.removeListener("close",a),t.removeListener("finish",l),t.removeListener("end",A),t.removeListener("error",c),t.removeListener("close",h)}};function vM(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var IM=mM,wM=Symbol("lastResolve"),bM=Symbol("lastReject"),BM=Symbol("error"),EM=Symbol("ended"),CM=Symbol("lastPromise"),SM=Symbol("handlePromise"),xM=Symbol("stream");function QM(e,t){return{value:e,done:t}}function kM(e){var t=e[wM];if(null!==t){var n=e[xM].read();null!==n&&(e[CM]=null,e[wM]=null,e[bM]=null,t(QM(n,!1)))}}function _M(e){ru(kM,e)}var NM=Object.getPrototypeOf((function(){})),DM=Object.setPrototypeOf((yM={get stream(){return this[xM]},next:function(){var e=this,t=this[BM];if(null!==t)return Promise.reject(t);if(this[EM])return Promise.resolve(QM(void 0,!0));if(this[xM].destroyed)return new Promise((function(t,n){ru((function(){e[BM]?n(e[BM]):t(QM(void 0,!0))}))}));var n,r=this[CM];if(r)n=new Promise(function(e,t){return function(n,r){e.then((function(){t[EM]?n(QM(void 0,!0)):t[SM](n,r)}),r)}}(r,this));else{var i=this[xM].read();if(null!==i)return Promise.resolve(QM(i,!1));n=new Promise(this[SM])}return this[CM]=n,n}},vM(yM,Symbol.asyncIterator,(function(){return this})),vM(yM,"return",(function(){var e=this;return new Promise((function(t,n){e[xM].destroy(null,(function(e){e?n(e):t(QM(void 0,!0))}))}))})),yM),NM),FM=function(e){var t,n=Object.create(DM,(vM(t={},xM,{value:e,writable:!0}),vM(t,wM,{value:null,writable:!0}),vM(t,bM,{value:null,writable:!0}),vM(t,BM,{value:null,writable:!0}),vM(t,EM,{value:e._readableState.endEmitted,writable:!0}),vM(t,SM,{value:function(e,t){var r=n[xM].read();r?(n[CM]=null,n[wM]=null,n[bM]=null,e(QM(r,!1))):(n[wM]=e,n[bM]=t)},writable:!0}),t));return n[CM]=null,IM(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[bM];return null!==t&&(n[CM]=null,n[wM]=null,n[bM]=null,t(e)),void(n[BM]=e)}var r=n[wM];null!==r&&(n[CM]=null,n[wM]=null,n[bM]=null,r(QM(void 0,!0))),n[EM]=!0})),e.on("readable",_M.bind(null,n)),n},PM=function(){throw new Error("Readable.from is not available in the browser")};const UM=LU;UM.Readable=nL,nL.ReadableState=tL,TU.EventEmitter;var MM,LM=function(e,t){return e.listeners(t).length},TM=RU,RM=qo.Buffer,OM=Ki.Uint8Array||function(){},HM=AI;MM=HM&&HM.debuglog?HM.debuglog("stream"):function(){};var KM,jM,GM,qM=VU,VM=XU,zM=nM,JM=WU.codes,YM=JM.ERR_INVALID_ARG_TYPE,XM=JM.ERR_STREAM_PUSH_AFTER_EOF,WM=JM.ERR_METHOD_NOT_IMPLEMENTED,ZM=JM.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;Ow.exports(nL,TM);var $M=VM.errorOrDestroy,eL=["error","close","destroy","pause","resume"];function tL(e,t,n){e=e||{},"boolean"!=typeof n&&(n=t instanceof UM.Duplex),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=zM(this,e,"readableHighWaterMark",n),this.buffer=new qM,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(KM||(KM=rM.StringDecoder),this.decoder=new KM(e.encoding),this.encoding=e.encoding)}function nL(e){if(!(this instanceof nL))return new nL(e);var t=this instanceof UM.Duplex;this._readableState=new tL(e,this,t),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),TM.call(this)}function rL(e,t,n,r,i){MM("readableAddChunk",t);var o,a=e._readableState;if(null===t)a.reading=!1,function(e,t){if(MM("onEofChunk"),!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?aL(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,sL(e)))}}(e,a);else if(i||(o=function(e,t){var n,r;return r=t,RM.isBuffer(r)||r instanceof OM||"string"==typeof t||void 0===t||e.objectMode||(n=new YM("chunk",["string","Buffer","Uint8Array"],t)),n}(a,t)),o)$M(e,o);else if(a.objectMode||t&&t.length>0)if("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===RM.prototype||(t=function(e){return RM.from(e)}(t)),r)a.endEmitted?$M(e,new ZM):iL(e,a,t,!0);else if(a.ended)$M(e,new XM);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!n?(t=a.decoder.write(t),a.objectMode||0!==t.length?iL(e,a,t,!1):lL(e,a)):iL(e,a,t,!1)}else r||(a.reading=!1,lL(e,a));return!a.ended&&(a.length<a.highWaterMark||0===a.length)}function iL(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&aL(e)),lL(e,t)}function oL(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function aL(e){var t=e._readableState;MM("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(MM("emitReadable",t.flowing),t.emittedReadable=!0,ru(sL,e))}function sL(e){var t=e._readableState;MM("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,fL(e)}function lL(e,t){t.readingMore||(t.readingMore=!0,ru(uL,e,t))}function uL(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var n=t.length;if(MM("maybeReadMore read 0"),e.read(0),n===t.length)break}t.readingMore=!1}function AL(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function cL(e){MM("readable nexttick read 0"),e.read(0)}function hL(e,t){MM("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),fL(e),t.flowing&&!t.reading&&e.read(0)}function fL(e){var t=e._readableState;for(MM("flow",t.flowing);t.flowing&&null!==e.read(););}function dL(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n}function pL(e){var t=e._readableState;MM("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,ru(gL,t,e))}function gL(e,t){if(MM("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}function yL(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}Object.defineProperty(nL.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),nL.prototype.destroy=VM.destroy,nL.prototype._undestroy=VM.undestroy,nL.prototype._destroy=function(e,t){t(e)},nL.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=RM.from(e,t),t=""),n=!0),rL(this,e,t,!1,n)},nL.prototype.unshift=function(e){return rL(this,e,null,!0,!1)},nL.prototype.isPaused=function(){return!1===this._readableState.flowing},nL.prototype.setEncoding=function(e){KM||(KM=rM.StringDecoder);var t=new KM(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,r="";null!==n;)r+=t.write(n.data),n=n.next;return this._readableState.buffer.clear(),""!==r&&this._readableState.buffer.push(r),this._readableState.length=r.length,this},nL.prototype.read=function(e){MM("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return MM("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?pL(this):aL(this),null;if(0===(e=oL(e,t))&&t.ended)return 0===t.length&&pL(this),null;var r,i=t.needReadable;return MM("need readable",i),(0===t.length||t.length-e<t.highWaterMark)&&MM("length less than watermark",i=!0),t.ended||t.reading?MM("reading or ended",i=!1):i&&(MM("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=oL(n,t))),null===(r=e>0?dL(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&pL(this)),null!==r&&this.emit("data",r),r},nL.prototype._read=function(e){$M(this,new WM("_read()"))},nL.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e)}r.pipesCount+=1,MM("pipe count=%d opts=%j",r.pipesCount,t);var i=t&&!1===t.end||e===gu.stdout||e===gu.stderr?h:o;function o(){MM("onend"),e.end()}r.endEmitted?ru(i):n.once("end",i),e.on("unpipe",(function t(i,f){MM("onunpipe"),i===n&&f&&!1===f.hasUnpiped&&(f.hasUnpiped=!0,MM("cleanup"),e.removeListener("close",A),e.removeListener("finish",c),e.removeListener("drain",a),e.removeListener("error",u),e.removeListener("unpipe",t),n.removeListener("end",o),n.removeListener("end",h),n.removeListener("data",l),s=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||a())}));var a=function(e){return function(){var t=e._readableState;MM("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&LM(e,"data")&&(t.flowing=!0,fL(e))}}(n);e.on("drain",a);var s=!1;function l(t){MM("ondata");var i=e.write(t);MM("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==yL(r.pipes,e))&&!s&&(MM("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause())}function u(t){MM("onerror",t),h(),e.removeListener("error",u),0===LM(e,"error")&&$M(e,t)}function A(){e.removeListener("finish",c),h()}function c(){MM("onfinish"),e.removeListener("close",A),h()}function h(){MM("unpipe"),n.unpipe(e)}return n.on("data",l),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}(e,"error",u),e.once("close",A),e.once("finish",c),e.emit("pipe",n),r.flowing||(MM("pipe resume"),n.resume()),e},nL.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)r[o].emit("unpipe",this,{hasUnpiped:!1});return this}var a=yL(t.pipes,e);return-1===a||(t.pipes.splice(a,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n)),this},nL.prototype.on=function(e,t){var n=TM.prototype.on.call(this,e,t),r=this._readableState;return"data"===e?(r.readableListening=this.listenerCount("readable")>0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,MM("on readable",r.length,r.reading),r.length?aL(this):r.reading||ru(cL,this))),n},nL.prototype.addListener=nL.prototype.on,nL.prototype.removeListener=function(e,t){var n=TM.prototype.removeListener.call(this,e,t);return"readable"===e&&ru(AL,this),n},nL.prototype.removeAllListeners=function(e){var t=TM.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||ru(AL,this),t},nL.prototype.resume=function(){var e=this._readableState;return e.flowing||(MM("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,ru(hL,e,t))}(this,e)),e.paused=!1,this},nL.prototype.pause=function(){return MM("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(MM("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},nL.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(MM("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){MM("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<eL.length;o++)e.on(eL[o],this.emit.bind(this,eL[o]));return this._read=function(t){MM("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(nL.prototype[Symbol.asyncIterator]=function(){return void 0===jM&&(jM=FM),jM(this)}),Object.defineProperty(nL.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(nL.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(nL.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),nL._fromList=dL,Object.defineProperty(nL.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(nL.from=function(e,t){return void 0===GM&&(GM=PM),GM(nL,e,t)});function mL(e){try{if(!Ki.localStorage)return!1}catch(e){return!1}var t=Ki.localStorage[e];return null!=t&&"true"===String(t).toLowerCase()}const vL=LU;function IL(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,n){var r=e.entry;for(e.entry=null;r;){var i=r.callback;t.pendingcb--,i(undefined),r=r.next}t.corkedRequestsFree.next=e}(t,e)}}vL.Writable=OL,OL.WritableState=RL;var wL,bL=function(e,t){if(mL("noDeprecation"))return e;var n=!1;return function(){if(!n){if(mL("throwDeprecation"))throw new Error(t);mL("traceDeprecation")?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}},BL=RU,EL=qo.Buffer,CL=Ki.Uint8Array||function(){},SL=XU,xL=nM,QL=WU.codes,kL=QL.ERR_INVALID_ARG_TYPE,_L=QL.ERR_METHOD_NOT_IMPLEMENTED,NL=QL.ERR_MULTIPLE_CALLBACK,DL=QL.ERR_STREAM_CANNOT_PIPE,FL=QL.ERR_STREAM_DESTROYED,PL=QL.ERR_STREAM_NULL_VALUES,UL=QL.ERR_STREAM_WRITE_AFTER_END,ML=QL.ERR_UNKNOWN_ENCODING,LL=SL.errorOrDestroy;function TL(){}function RL(e,t,n){e=e||{},"boolean"!=typeof n&&(n=t instanceof vL.Duplex),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=xL(this,e,"writableHighWaterMark",n),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var r=!1===e.decodeStrings;this.decodeStrings=!r,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if("function"!=typeof i)throw new NL;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),t)!function(e,t,n,r,i){--t.pendingcb,n?(ru(i,r),ru(VL,e,t),e._writableState.errorEmitted=!0,LL(e,r)):(i(r),e._writableState.errorEmitted=!0,LL(e,r),VL(e,t))}(e,n,r,t,i);else{var o=GL(n)||e.destroyed;o||n.corked||n.bufferProcessing||!n.bufferedRequest||jL(e,n),r?ru(KL,e,n,o,i):KL(e,n,o,i)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new IL(this)}function OL(e){var t=this instanceof vL.Duplex;if(!t&&!wL.call(OL,this))return new OL(e);this._writableState=new RL(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),BL.call(this)}function HL(e,t,n,r,i,o,a){t.writelen=r,t.writecb=a,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new FL("write")):n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function KL(e,t,n,r){n||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,r(),VL(e,t)}function jL(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,i=new Array(r),o=t.corkedRequestsFree;o.entry=n;for(var a=0,s=!0;n;)i[a]=n,n.isBuf||(s=!1),n=n.next,a+=1;i.allBuffers=s,HL(e,t,!0,t.length,i,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new IL(t),t.bufferedRequestCount=0}else{for(;n;){var l=n.chunk,u=n.encoding,A=n.callback;if(HL(e,t,!1,t.objectMode?1:l.length,l,u,A),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function GL(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function qL(e,t){e._final((function(n){t.pendingcb--,n&&LL(e,n),t.prefinished=!0,e.emit("prefinish"),VL(e,t)}))}function VL(e,t){var n=GL(t);if(n&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,ru(qL,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}Ow.exports(OL,BL),RL.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(RL.prototype,"buffer",{get:bL((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(wL=Function.prototype[Symbol.hasInstance],Object.defineProperty(OL,Symbol.hasInstance,{value:function(e){return!!wL.call(this,e)||this===OL&&e&&e._writableState instanceof RL}})):wL=function(e){return e instanceof this},OL.prototype.pipe=function(){LL(this,new DL)},OL.prototype.write=function(e,t,n){var r,i=this._writableState,o=!1,a=!i.objectMode&&(r=e,EL.isBuffer(r)||r instanceof CL);return a&&!EL.isBuffer(e)&&(e=function(e){return EL.from(e)}(e)),"function"==typeof t&&(n=t,t=null),a?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=TL),i.ending?function(e,t){var n=new UL;LL(e,n),ru(t,n)}(this,n):(a||function(e,t,n,r){var i;return null===n?i=new PL:"string"==typeof n||t.objectMode||(i=new kL("chunk",["string","Buffer"],n)),!i||(LL(e,i),ru(r,i),!1)}(this,i,e,n))&&(i.pendingcb++,o=function(e,t,n,r,i,o){if(!n){var a=function(e,t,n){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=EL.from(t,n)),t}(t,r,i);r!==a&&(n=!0,i="buffer",r=a)}var s=t.objectMode?1:r.length;t.length+=s;var l=t.length<t.highWaterMark;if(l||(t.needDrain=!0),t.writing||t.corked){var u=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:o,next:null},u?u.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else HL(e,t,!1,s,r,i,o);return l}(this,i,a,e,t,n)),o},OL.prototype.cork=function(){this._writableState.corked++},OL.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||jL(this,e))},OL.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new ML(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(OL.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(OL.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),OL.prototype._write=function(e,t,n){n(new _L("_write()"))},OL.prototype._writev=null,OL.prototype.end=function(e,t,n){var r=this._writableState;return"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||function(e,t,n){t.ending=!0,VL(e,t),n&&(t.finished?ru(n):e.once("finish",n)),t.ended=!0,e.writable=!1}(this,r,n),this},Object.defineProperty(OL.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(OL.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),OL.prototype.destroy=SL.destroy,OL.prototype._undestroy=SL.undestroy,OL.prototype._destroy=function(e,t){t(e)};var zL=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};const JL=LU;JL.Duplex=ZL,Ow.exports(ZL,JL.Readable);for(var YL=zL(JL.Writable.prototype),XL=0;XL<YL.length;XL++){var WL=YL[XL];ZL.prototype[WL]||(ZL.prototype[WL]=JL.Writable.prototype[WL])}function ZL(e){if(!(this instanceof ZL))return new ZL(e);JL.Readable.call(this,e),JL.Writable.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",$L)))}function $L(){this._writableState.ended||ru(eT,this)}function eT(e){e.end()}Object.defineProperty(ZL.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(ZL.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(ZL.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(ZL.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&this._readableState.destroyed&&this._writableState.destroyed},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}});const tT=LU;tT.Transform=lT;var nT=WU.codes,rT=nT.ERR_METHOD_NOT_IMPLEMENTED,iT=nT.ERR_MULTIPLE_CALLBACK,oT=nT.ERR_TRANSFORM_ALREADY_TRANSFORMING,aT=nT.ERR_TRANSFORM_WITH_LENGTH_0;function sT(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(null===r)return this.emit("error",new iT);n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function lT(e){if(!(this instanceof lT))return new lT(e);tT.Duplex.call(this,e),this._transformState={afterTransform:sT.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",uT)}function uT(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?AT(this,null,null):this._flush((function(t,n){AT(e,t,n)}))}function AT(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new aT;if(e._transformState.transforming)throw new oT;return e.push(null)}Ow.exports(lT,tT.Duplex),lT.prototype.push=function(e,t){return this._transformState.needTransform=!1,tT.Duplex.prototype.push.call(this,e,t)},lT.prototype._transform=function(e,t,n){n(new rT("_transform()"))},lT.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},lT.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},lT.prototype._destroy=function(e,t){tT.Duplex.prototype._destroy.call(this,e,(function(e){t(e)}))};const cT=LU;function hT(e){if(!(this instanceof hT))return new hT(e);Transform.call(this,e)}var fT;cT.PassThrough=hT,Ow.exports(hT,cT.Transform),hT.prototype._transform=function(e,t,n){n(null,e)};var dT=WU.codes,pT=dT.ERR_MISSING_ARGS,gT=dT.ERR_STREAM_DESTROYED;function yT(e){if(e)throw e}function mT(e,t,n,r){r=function(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}(r);var i=!1;e.on("close",(function(){i=!0})),void 0===fT&&(fT=mM),fT(e,{readable:t,writable:n},(function(e){if(e)return r(e);i=!0,r()}));var o=!1;return function(t){if(!i&&!o)return o=!0,function(e){return e.setHeader&&"function"==typeof e.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void r(t||new gT("pipe"))}}function vT(e){e()}function IT(e,t){return e.pipe(t)}function wT(e){return e.length?"function"!=typeof e[e.length-1]?yT:e.pop():yT}var bT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r,i=wT(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new pT("streams");var o=t.map((function(e,n){var a=n<t.length-1;return mT(e,a,n>0,(function(e){r||(r=e),e&&o.forEach(vT),a||(o.forEach(vT),i(r))}))}));return t.reduce(IT)};!function(e,t){const n=LU;(t=MU.exports=n.Readable).Stream=n.Readable,t.Readable=n.Readable,t.Writable=n.Writable,t.Duplex=n.Duplex,t.Transform=n.Transform,t.PassThrough=n.PassThrough,t.finished=mM,t.pipeline=bT}(0,MU.exports);var BT=F_.exports.Buffer,ET=MU.exports;function CT(e){ET.Stream.Transform.call(this),this._block=BT.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}(0,Ow.exports)(CT,ET.Stream.Transform),CT.prototype._transform=function(e,t,n){var r=null;try{this.update(e,t)}catch(e){r=e}n(r)},CT.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(e){t=e}e(t)},CT.prototype.update=function(e,t){if(function(e,t){if(!BT.isBuffer(e)&&"string"!=typeof e)throw new TypeError("Data must be a string or a buffer")}(e),this._finalized)throw new Error("Digest already called");BT.isBuffer(e)||(e=BT.from(e,t));for(var n=this._block,r=0;this._blockOffset+e.length-r>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)n[i++]=e[r++];this._update(),this._blockOffset=0}for(;r<e.length;)n[this._blockOffset++]=e[r++];for(var o=0,a=8*e.length;a>0;++o)this._length[o]+=a,(a=this._length[o]/4294967296|0)>0&&(this._length[o]-=4294967296*a);return this},CT.prototype._update=function(){throw new Error("_update is not implemented")},CT.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();void 0!==e&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var n=0;n<4;++n)this._length[n]=0;return t},CT.prototype._digest=function(){throw new Error("_digest is not implemented")};var ST=CT,xT=Ow.exports,QT=ST,kT=F_.exports.Buffer,_T=new Array(16);function NT(){QT.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}function DT(e,t){return e<<t|e>>>32-t}function FT(e,t,n,r,i,o,a){return DT(e+(t&n|~t&r)+i+o|0,a)+t|0}function PT(e,t,n,r,i,o,a){return DT(e+(t&r|n&~r)+i+o|0,a)+t|0}function UT(e,t,n,r,i,o,a){return DT(e+(t^n^r)+i+o|0,a)+t|0}function MT(e,t,n,r,i,o,a){return DT(e+(n^(t|~r))+i+o|0,a)+t|0}xT(NT,QT),NT.prototype._update=function(){for(var e=_T,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var n=this._a,r=this._b,i=this._c,o=this._d;n=FT(n,r,i,o,e[0],3614090360,7),o=FT(o,n,r,i,e[1],3905402710,12),i=FT(i,o,n,r,e[2],606105819,17),r=FT(r,i,o,n,e[3],3250441966,22),n=FT(n,r,i,o,e[4],4118548399,7),o=FT(o,n,r,i,e[5],1200080426,12),i=FT(i,o,n,r,e[6],2821735955,17),r=FT(r,i,o,n,e[7],4249261313,22),n=FT(n,r,i,o,e[8],1770035416,7),o=FT(o,n,r,i,e[9],2336552879,12),i=FT(i,o,n,r,e[10],4294925233,17),r=FT(r,i,o,n,e[11],2304563134,22),n=FT(n,r,i,o,e[12],1804603682,7),o=FT(o,n,r,i,e[13],4254626195,12),i=FT(i,o,n,r,e[14],2792965006,17),n=PT(n,r=FT(r,i,o,n,e[15],1236535329,22),i,o,e[1],4129170786,5),o=PT(o,n,r,i,e[6],3225465664,9),i=PT(i,o,n,r,e[11],643717713,14),r=PT(r,i,o,n,e[0],3921069994,20),n=PT(n,r,i,o,e[5],3593408605,5),o=PT(o,n,r,i,e[10],38016083,9),i=PT(i,o,n,r,e[15],3634488961,14),r=PT(r,i,o,n,e[4],3889429448,20),n=PT(n,r,i,o,e[9],568446438,5),o=PT(o,n,r,i,e[14],3275163606,9),i=PT(i,o,n,r,e[3],4107603335,14),r=PT(r,i,o,n,e[8],1163531501,20),n=PT(n,r,i,o,e[13],2850285829,5),o=PT(o,n,r,i,e[2],4243563512,9),i=PT(i,o,n,r,e[7],1735328473,14),n=UT(n,r=PT(r,i,o,n,e[12],2368359562,20),i,o,e[5],4294588738,4),o=UT(o,n,r,i,e[8],2272392833,11),i=UT(i,o,n,r,e[11],1839030562,16),r=UT(r,i,o,n,e[14],4259657740,23),n=UT(n,r,i,o,e[1],2763975236,4),o=UT(o,n,r,i,e[4],1272893353,11),i=UT(i,o,n,r,e[7],4139469664,16),r=UT(r,i,o,n,e[10],3200236656,23),n=UT(n,r,i,o,e[13],681279174,4),o=UT(o,n,r,i,e[0],3936430074,11),i=UT(i,o,n,r,e[3],3572445317,16),r=UT(r,i,o,n,e[6],76029189,23),n=UT(n,r,i,o,e[9],3654602809,4),o=UT(o,n,r,i,e[12],3873151461,11),i=UT(i,o,n,r,e[15],530742520,16),n=MT(n,r=UT(r,i,o,n,e[2],3299628645,23),i,o,e[0],4096336452,6),o=MT(o,n,r,i,e[7],1126891415,10),i=MT(i,o,n,r,e[14],2878612391,15),r=MT(r,i,o,n,e[5],4237533241,21),n=MT(n,r,i,o,e[12],1700485571,6),o=MT(o,n,r,i,e[3],2399980690,10),i=MT(i,o,n,r,e[10],4293915773,15),r=MT(r,i,o,n,e[1],2240044497,21),n=MT(n,r,i,o,e[8],1873313359,6),o=MT(o,n,r,i,e[15],4264355552,10),i=MT(i,o,n,r,e[6],2734768916,15),r=MT(r,i,o,n,e[13],1309151649,21),n=MT(n,r,i,o,e[4],4149444226,6),o=MT(o,n,r,i,e[11],3174756917,10),i=MT(i,o,n,r,e[2],718787259,15),r=MT(r,i,o,n,e[9],3951481745,21),this._a=this._a+n|0,this._b=this._b+r|0,this._c=this._c+i|0,this._d=this._d+o|0},NT.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=kT.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};var LT=NT,TT=qo.Buffer,RT=Ow.exports,OT=ST,HT=new Array(16),KT=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],jT=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],GT=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],qT=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],VT=[0,1518500249,1859775393,2400959708,2840853838],zT=[1352829926,1548603684,1836072691,2053994217,0];function JT(){OT.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}function YT(e,t){return e<<t|e>>>32-t}function XT(e,t,n,r,i,o,a,s){return YT(e+(t^n^r)+o+a|0,s)+i|0}function WT(e,t,n,r,i,o,a,s){return YT(e+(t&n|~t&r)+o+a|0,s)+i|0}function ZT(e,t,n,r,i,o,a,s){return YT(e+((t|~n)^r)+o+a|0,s)+i|0}function $T(e,t,n,r,i,o,a,s){return YT(e+(t&r|n&~r)+o+a|0,s)+i|0}function eR(e,t,n,r,i,o,a,s){return YT(e+(t^(n|~r))+o+a|0,s)+i|0}RT(JT,OT),JT.prototype._update=function(){for(var e=HT,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);for(var n=0|this._a,r=0|this._b,i=0|this._c,o=0|this._d,a=0|this._e,s=0|this._a,l=0|this._b,u=0|this._c,A=0|this._d,c=0|this._e,h=0;h<80;h+=1){var f,d;h<16?(f=XT(n,r,i,o,a,e[KT[h]],VT[0],GT[h]),d=eR(s,l,u,A,c,e[jT[h]],zT[0],qT[h])):h<32?(f=WT(n,r,i,o,a,e[KT[h]],VT[1],GT[h]),d=$T(s,l,u,A,c,e[jT[h]],zT[1],qT[h])):h<48?(f=ZT(n,r,i,o,a,e[KT[h]],VT[2],GT[h]),d=ZT(s,l,u,A,c,e[jT[h]],zT[2],qT[h])):h<64?(f=$T(n,r,i,o,a,e[KT[h]],VT[3],GT[h]),d=WT(s,l,u,A,c,e[jT[h]],zT[3],qT[h])):(f=eR(n,r,i,o,a,e[KT[h]],VT[4],GT[h]),d=XT(s,l,u,A,c,e[jT[h]],zT[4],qT[h])),n=a,a=o,o=YT(i,10),i=r,r=f,s=c,c=A,A=YT(u,10),u=l,l=d}var p=this._b+i+A|0;this._b=this._c+o+c|0,this._c=this._d+a+s|0,this._d=this._e+n+l|0,this._e=this._a+r+u|0,this._a=p},JT.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=TT.alloc?TT.alloc(20):new TT(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};var tR=JT,nR={exports:{}},rR=F_.exports.Buffer;function iR(e,t){this._block=rR.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}iR.prototype.update=function(e,t){"string"==typeof e&&(t=t||"utf8",e=rR.from(e,t));for(var n=this._block,r=this._blockSize,i=e.length,o=this._len,a=0;a<i;){for(var s=o%r,l=Math.min(i-a,r-s),u=0;u<l;u++)n[s+u]=e[a+u];a+=l,(o+=l)%r==0&&this._update(n)}return this._len+=i,this},iR.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var n=8*this._len;if(n<=4294967295)this._block.writeUInt32BE(n,this._blockSize-4);else{var r=(4294967295&n)>>>0,i=(n-r)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(r,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},iR.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var oR=iR,aR=Ow.exports,sR=oR,lR=F_.exports.Buffer,uR=[1518500249,1859775393,-1894007588,-899497514],AR=new Array(80);function cR(){this.init(),this._w=AR,sR.call(this,64,56)}function hR(e){return e<<30|e>>>2}function fR(e,t,n,r){return 0===e?t&n|~t&r:2===e?t&n|t&r|n&r:t^n^r}aR(cR,sR),cR.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},cR.prototype._update=function(e){for(var t,n=this._w,r=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,l=0;l<16;++l)n[l]=e.readInt32BE(4*l);for(;l<80;++l)n[l]=n[l-3]^n[l-8]^n[l-14]^n[l-16];for(var u=0;u<80;++u){var A=~~(u/20),c=0|((t=r)<<5|t>>>27)+fR(A,i,o,a)+s+n[u]+uR[A];s=a,a=o,o=hR(i),i=r,r=c}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},cR.prototype._hash=function(){var e=lR.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var dR=cR,pR=Ow.exports,gR=oR,yR=F_.exports.Buffer,mR=[1518500249,1859775393,-1894007588,-899497514],vR=new Array(80);function IR(){this.init(),this._w=vR,gR.call(this,64,56)}function wR(e){return e<<5|e>>>27}function bR(e){return e<<30|e>>>2}function BR(e,t,n,r){return 0===e?t&n|~t&r:2===e?t&n|t&r|n&r:t^n^r}pR(IR,gR),IR.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},IR.prototype._update=function(e){for(var t,n=this._w,r=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,l=0;l<16;++l)n[l]=e.readInt32BE(4*l);for(;l<80;++l)n[l]=(t=n[l-3]^n[l-8]^n[l-14]^n[l-16])<<1|t>>>31;for(var u=0;u<80;++u){var A=~~(u/20),c=wR(r)+BR(A,i,o,a)+s+n[u]+mR[A]|0;s=a,a=o,o=bR(i),i=r,r=c}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},IR.prototype._hash=function(){var e=yR.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var ER=IR,CR=Ow.exports,SR=oR,xR=F_.exports.Buffer,QR=[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],kR=new Array(64);function _R(){this.init(),this._w=kR,SR.call(this,64,56)}function NR(e,t,n){return n^e&(t^n)}function DR(e,t,n){return e&t|n&(e|t)}function FR(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function PR(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function UR(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function MR(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}CR(_R,SR),_R.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},_R.prototype._update=function(e){for(var t=this._w,n=0|this._a,r=0|this._b,i=0|this._c,o=0|this._d,a=0|this._e,s=0|this._f,l=0|this._g,u=0|this._h,A=0;A<16;++A)t[A]=e.readInt32BE(4*A);for(;A<64;++A)t[A]=MR(t[A-2])+t[A-7]+UR(t[A-15])+t[A-16]|0;for(var c=0;c<64;++c){var h=u+PR(a)+NR(a,s,l)+QR[c]+t[c]|0,f=FR(n)+DR(n,r,i)|0;u=l,l=s,s=a,a=o+h|0,o=i,i=r,r=n,n=h+f|0}this._a=n+this._a|0,this._b=r+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=a+this._e|0,this._f=s+this._f|0,this._g=l+this._g|0,this._h=u+this._h|0},_R.prototype._hash=function(){var e=xR.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var LR=_R,TR=Ow.exports,RR=LR,OR=oR,HR=F_.exports.Buffer,KR=new Array(64);function jR(){this.init(),this._w=KR,OR.call(this,64,56)}TR(jR,RR),jR.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},jR.prototype._hash=function(){var e=HR.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var GR=jR,qR=Ow.exports,VR=oR,zR=F_.exports.Buffer,JR=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],YR=new Array(160);function XR(){this.init(),this._w=YR,VR.call(this,128,112)}function WR(e,t,n){return n^e&(t^n)}function ZR(e,t,n){return e&t|n&(e|t)}function $R(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function eO(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function tO(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function nO(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function rO(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function iO(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function oO(e,t){return e>>>0<t>>>0?1:0}qR(XR,VR),XR.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},XR.prototype._update=function(e){for(var t=this._w,n=0|this._ah,r=0|this._bh,i=0|this._ch,o=0|this._dh,a=0|this._eh,s=0|this._fh,l=0|this._gh,u=0|this._hh,A=0|this._al,c=0|this._bl,h=0|this._cl,f=0|this._dl,d=0|this._el,p=0|this._fl,g=0|this._gl,y=0|this._hl,m=0;m<32;m+=2)t[m]=e.readInt32BE(4*m),t[m+1]=e.readInt32BE(4*m+4);for(;m<160;m+=2){var v=t[m-30],I=t[m-30+1],w=tO(v,I),b=nO(I,v),B=rO(v=t[m-4],I=t[m-4+1]),E=iO(I,v),C=t[m-14],S=t[m-14+1],x=t[m-32],Q=t[m-32+1],k=b+S|0,_=w+C+oO(k,b)|0;_=(_=_+B+oO(k=k+E|0,E)|0)+x+oO(k=k+Q|0,Q)|0,t[m]=_,t[m+1]=k}for(var N=0;N<160;N+=2){_=t[N],k=t[N+1];var D=ZR(n,r,i),F=ZR(A,c,h),P=$R(n,A),U=$R(A,n),M=eO(a,d),L=eO(d,a),T=JR[N],R=JR[N+1],O=WR(a,s,l),H=WR(d,p,g),K=y+L|0,j=u+M+oO(K,y)|0;j=(j=(j=j+O+oO(K=K+H|0,H)|0)+T+oO(K=K+R|0,R)|0)+_+oO(K=K+k|0,k)|0;var G=U+F|0,q=P+D+oO(G,U)|0;u=l,y=g,l=s,g=p,s=a,p=d,a=o+j+oO(d=f+K|0,f)|0,o=i,f=h,i=r,h=c,r=n,c=A,n=j+q+oO(A=K+G|0,K)|0}this._al=this._al+A|0,this._bl=this._bl+c|0,this._cl=this._cl+h|0,this._dl=this._dl+f|0,this._el=this._el+d|0,this._fl=this._fl+p|0,this._gl=this._gl+g|0,this._hl=this._hl+y|0,this._ah=this._ah+n+oO(this._al,A)|0,this._bh=this._bh+r+oO(this._bl,c)|0,this._ch=this._ch+i+oO(this._cl,h)|0,this._dh=this._dh+o+oO(this._dl,f)|0,this._eh=this._eh+a+oO(this._el,d)|0,this._fh=this._fh+s+oO(this._fl,p)|0,this._gh=this._gh+l+oO(this._gl,g)|0,this._hh=this._hh+u+oO(this._hl,y)|0},XR.prototype._hash=function(){var e=zR.allocUnsafe(64);function t(t,n,r){e.writeInt32BE(t,r),e.writeInt32BE(n,r+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var aO=XR,sO=Ow.exports,lO=aO,uO=oR,AO=F_.exports.Buffer,cO=new Array(160);function hO(){this.init(),this._w=cO,uO.call(this,128,112)}sO(hO,lO),hO.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},hO.prototype._hash=function(){var e=AO.allocUnsafe(48);function t(t,n,r){e.writeInt32BE(t,r),e.writeInt32BE(n,r+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var fO=hO,dO=nR.exports=function(e){e=e.toLowerCase();var t=dO[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t};dO.sha=dR,dO.sha1=ER,dO.sha224=GR,dO.sha256=LR,dO.sha384=fO,dO.sha512=aO;var pO=ji(dc),gO=F_.exports.Buffer,yO=LQ.Transform,mO=pO.StringDecoder;function vO(e){yO.call(this),this.hashMode="string"==typeof e,this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}(0,Ow.exports)(vO,yO),vO.prototype.update=function(e,t,n){"string"==typeof e&&(e=gO.from(e,t));var r=this._update(e);return this.hashMode?this:(n&&(r=this._toString(r,n)),r)},vO.prototype.setAutoPadding=function(){},vO.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")},vO.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")},vO.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")},vO.prototype._transform=function(e,t,n){var r;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(e){r=e}finally{n(r)}},vO.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(e){t=e}e(t)},vO.prototype._finalOrDigest=function(e){var t=this.__final()||gO.alloc(0);return e&&(t=this._toString(t,e,!0)),t},vO.prototype._toString=function(e,t,n){if(this._decoder||(this._decoder=new mO(t),this._encoding=t),this._encoding!==t)throw new Error("can't switch encodings");var r=this._decoder.write(e);return n&&(r+=this._decoder.end()),r};var IO=vO,wO=Ow.exports,bO=LT,BO=tR,EO=nR.exports,CO=IO;function SO(e){CO.call(this,"digest"),this._hash=e}wO(SO,CO),SO.prototype._update=function(e){this._hash.update(e)},SO.prototype._final=function(){return this._hash.digest()};var xO=function(e){return"md5"===(e=e.toLowerCase())?new bO:"rmd160"===e||"ripemd160"===e?new BO:new SO(EO(e))};Object.defineProperty(UU,"__esModule",{value:!0}),UU.taggedHash=UU.hash256=UU.hash160=UU.sha256=UU.sha1=UU.ripemd160=void 0;const QO=xO,kO=tR;function _O(e){try{return QO("rmd160").update(e).digest()}catch(t){try{return QO("ripemd160").update(e).digest()}catch(t){return(new kO).update(e).digest()}}}function NO(e){return QO("sha256").update(e).digest()}UU.ripemd160=_O,UU.sha1=function(e){return QO("sha1").update(e).digest()},UU.sha256=NO,UU.hash160=function(e){return _O(NO(e))},UU.hash256=function(e){return NO(NO(e))};const DO=Object.fromEntries(["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"].map((e=>{const t=NO(ao.from(e));return[e,ao.concat([t,t])]})));UU.taggedHash=function(e,t){return NO(ao.concat([DO[e],t]))};var FO=sP,PO=F_.exports.Buffer,UO=xO,MO=function(e){function t(t){var n=t.slice(0,-4),r=t.slice(-4),i=e(n);if(!(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3]))return n}return{encode:function(t){var n=e(t);return FO.encode(PO.concat([t,n],t.length+4))},decode:function(e){var n=t(FO.decode(e));if(!n)throw new Error("Invalid checksum");return n},decodeUnsafe:function(e){var n=FO.decodeUnsafe(e);if(n)return t(n)}}}((function(e){var t=UO("sha256").update(e).digest();return UO("sha256").update(t).digest()}));Object.defineProperty(PU,"__esModule",{value:!0}),PU.p2pkh=void 0;const LO=UU,TO=cP,RO=dP,OO=EP,HO=dU,KO=MO,jO=RO.OPS;PU.p2pkh=function(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,OO.typeforce)({network:OO.typeforce.maybe(OO.typeforce.Object),address:OO.typeforce.maybe(OO.typeforce.String),hash:OO.typeforce.maybe(OO.typeforce.BufferN(20)),output:OO.typeforce.maybe(OO.typeforce.BufferN(25)),pubkey:OO.typeforce.maybe(OO.isPoint),signature:OO.typeforce.maybe(RO.isCanonicalScriptSignature),input:OO.typeforce.maybe(OO.typeforce.Buffer)},e);const n=HO.value((()=>{const t=KO.decode(e.address);return{version:t.readUInt8(0),hash:t.slice(1)}})),r=HO.value((()=>RO.decompile(e.input))),i=e.network||TO.bitcoin,o={name:"p2pkh",network:i};if(HO.prop(o,"address",(()=>{if(!o.hash)return;const e=ao.allocUnsafe(21);return e.writeUInt8(i.pubKeyHash,0),o.hash.copy(e,1),KO.encode(e)})),HO.prop(o,"hash",(()=>e.output?e.output.slice(3,23):e.address?n().hash:e.pubkey||o.pubkey?LO.hash160(e.pubkey||o.pubkey):void 0)),HO.prop(o,"output",(()=>{if(o.hash)return RO.compile([jO.OP_DUP,jO.OP_HASH160,o.hash,jO.OP_EQUALVERIFY,jO.OP_CHECKSIG])})),HO.prop(o,"pubkey",(()=>{if(e.input)return r()[1]})),HO.prop(o,"signature",(()=>{if(e.input)return r()[0]})),HO.prop(o,"input",(()=>{if(e.pubkey&&e.signature)return RO.compile([e.signature,e.pubkey])})),HO.prop(o,"witness",(()=>{if(o.input)return[]})),t.validate){let t=ao.from([]);if(e.address){if(n().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==n().hash.length)throw new TypeError("Invalid address");t=n().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(25!==e.output.length||e.output[0]!==jO.OP_DUP||e.output[1]!==jO.OP_HASH160||20!==e.output[2]||e.output[23]!==jO.OP_EQUALVERIFY||e.output[24]!==jO.OP_CHECKSIG)throw new TypeError("Output is invalid");const n=e.output.slice(3,23);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.pubkey){const n=LO.hash160(e.pubkey);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.input){const n=r();if(2!==n.length)throw new TypeError("Input is invalid");if(!RO.isCanonicalScriptSignature(n[0]))throw new TypeError("Input has invalid signature");if(!(0,OO.isPoint)(n[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(n[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(n[1]))throw new TypeError("Pubkey mismatch");const i=LO.hash160(n[1]);if(t.length>0&&!t.equals(i))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)};var GO={};Object.defineProperty(GO,"__esModule",{value:!0}),GO.p2sh=void 0;const qO=UU,VO=cP,zO=dP,JO=EP,YO=dU,XO=MO,WO=zO.OPS;GO.p2sh=function(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,JO.typeforce)({network:JO.typeforce.maybe(JO.typeforce.Object),address:JO.typeforce.maybe(JO.typeforce.String),hash:JO.typeforce.maybe(JO.typeforce.BufferN(20)),output:JO.typeforce.maybe(JO.typeforce.BufferN(23)),redeem:JO.typeforce.maybe({network:JO.typeforce.maybe(JO.typeforce.Object),output:JO.typeforce.maybe(JO.typeforce.Buffer),input:JO.typeforce.maybe(JO.typeforce.Buffer),witness:JO.typeforce.maybe(JO.typeforce.arrayOf(JO.typeforce.Buffer))}),input:JO.typeforce.maybe(JO.typeforce.Buffer),witness:JO.typeforce.maybe(JO.typeforce.arrayOf(JO.typeforce.Buffer))},e);let n=e.network;n||(n=e.redeem&&e.redeem.network||VO.bitcoin);const r={network:n},i=YO.value((()=>{const t=XO.decode(e.address);return{version:t.readUInt8(0),hash:t.slice(1)}})),o=YO.value((()=>zO.decompile(e.input))),a=YO.value((()=>{const t=o(),r=t[t.length-1];return{network:n,output:r===WO.OP_FALSE?ao.from([]):r,input:zO.compile(t.slice(0,-1)),witness:e.witness||[]}}));if(YO.prop(r,"address",(()=>{if(!r.hash)return;const e=ao.allocUnsafe(21);return e.writeUInt8(r.network.scriptHash,0),r.hash.copy(e,1),XO.encode(e)})),YO.prop(r,"hash",(()=>e.output?e.output.slice(2,22):e.address?i().hash:r.redeem&&r.redeem.output?qO.hash160(r.redeem.output):void 0)),YO.prop(r,"output",(()=>{if(r.hash)return zO.compile([WO.OP_HASH160,r.hash,WO.OP_EQUAL])})),YO.prop(r,"redeem",(()=>{if(e.input)return a()})),YO.prop(r,"input",(()=>{if(e.redeem&&e.redeem.input&&e.redeem.output)return zO.compile([].concat(zO.decompile(e.redeem.input),e.redeem.output))})),YO.prop(r,"witness",(()=>r.redeem&&r.redeem.witness?r.redeem.witness:r.input?[]:void 0)),YO.prop(r,"name",(()=>{const e=["p2sh"];return void 0!==r.redeem&&void 0!==r.redeem.name&&e.push(r.redeem.name),e.join("-")})),t.validate){let t=ao.from([]);if(e.address){if(i().version!==n.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");t=i().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(23!==e.output.length||e.output[0]!==WO.OP_HASH160||20!==e.output[1]||e.output[22]!==WO.OP_EQUAL)throw new TypeError("Output is invalid");const n=e.output.slice(2,22);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}const r=e=>{if(e.output){const n=zO.decompile(e.output);if(!n||n.length<1)throw new TypeError("Redeem.output too short");const r=qO.hash160(e.output);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.input){const t=e.input.length>0,n=e.witness&&e.witness.length>0;if(!t&&!n)throw new TypeError("Empty input");if(t&&n)throw new TypeError("Input and witness provided");if(t){const t=zO.decompile(e.input);if(!zO.isPushOnly(t))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const e=o();if(!e||e.length<1)throw new TypeError("Input too short");if(!jo(a().output))throw new TypeError("Input is invalid");r(a())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==n)throw new TypeError("Network mismatch");if(e.input){const t=a();if(e.redeem.output&&!e.redeem.output.equals(t.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(t.input))throw new TypeError("Redeem.input mismatch")}r(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!function(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(r,e)};var ZO={},$O={};Object.defineProperty($O,"__esModule",{value:!0}),$O.bech32m=$O.bech32=void 0;const eH="qpzry9x8gf2tvdw0s3jn54khce6mua7l",tH={};for(let e=0;e<eH.length;e++){const t=eH.charAt(e);tH[t]=e}function nH(e){const t=e>>25;return(33554431&e)<<5^996825010&-(t>>0&1)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function rH(e){let t=1;for(let n=0;n<e.length;++n){const r=e.charCodeAt(n);if(r<33||r>126)return"Invalid prefix ("+e+")";t=nH(t)^r>>5}t=nH(t);for(let n=0;n<e.length;++n){const r=e.charCodeAt(n);t=nH(t)^31&r}return t}function iH(e,t,n,r){let i=0,o=0;const a=(1<<n)-1,s=[];for(let r=0;r<e.length;++r)for(i=i<<t|e[r],o+=t;o>=n;)o-=n,s.push(i>>o&a);if(r)o>0&&s.push(i<<n-o&a);else{if(o>=t)return"Excess padding";if(i<<n-o&a)return"Non-zero padding"}return s}function oH(e){return iH(e,8,5,!0)}function aH(e){const t=iH(e,5,8,!1);if(Array.isArray(t))return t}function sH(e){const t=iH(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function lH(e){let t;function n(e,n){if(n=n||90,e.length<8)return e+" too short";if(e.length>n)return"Exceeds length limit";const r=e.toLowerCase(),i=e.toUpperCase();if(e!==r&&e!==i)return"Mixed-case string "+e;const o=(e=r).lastIndexOf("1");if(-1===o)return"No separator character for "+e;if(0===o)return"Missing prefix for "+e;const a=e.slice(0,o),s=e.slice(o+1);if(s.length<6)return"Data too short";let l=rH(a);if("string"==typeof l)return l;const u=[];for(let e=0;e<s.length;++e){const t=s.charAt(e),n=tH[t];if(void 0===n)return"Unknown character "+t;l=nH(l)^n,e+6>=s.length||u.push(n)}return l!==t?"Invalid checksum for "+e:{prefix:a,words:u}}return t="bech32"===e?1:734539939,{decodeUnsafe:function(e,t){const r=n(e,t);if("object"==typeof r)return r},decode:function(e,t){const r=n(e,t);if("object"==typeof r)return r;throw new Error(r)},encode:function(e,n,r){if(r=r||90,e.length+7+n.length>r)throw new TypeError("Exceeds length limit");let i=rH(e=e.toLowerCase());if("string"==typeof i)throw new Error(i);let o=e+"1";for(let e=0;e<n.length;++e){const t=n[e];if(t>>5!=0)throw new Error("Non 5-bit word");i=nH(i)^t,o+=eH.charAt(t)}for(let e=0;e<6;++e)i=nH(i);i^=t;for(let e=0;e<6;++e)o+=eH.charAt(i>>5*(5-e)&31);return o},toWords:oH,fromWordsUnsafe:aH,fromWords:sH}}$O.bech32=lH("bech32"),$O.bech32m=lH("bech32m"),Object.defineProperty(ZO,"__esModule",{value:!0}),ZO.p2wpkh=void 0;const uH=UU,AH=cP,cH=dP,hH=EP,fH=dU,dH=$O,pH=cH.OPS,gH=ao.alloc(0);ZO.p2wpkh=function(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,hH.typeforce)({address:hH.typeforce.maybe(hH.typeforce.String),hash:hH.typeforce.maybe(hH.typeforce.BufferN(20)),input:hH.typeforce.maybe(hH.typeforce.BufferN(0)),network:hH.typeforce.maybe(hH.typeforce.Object),output:hH.typeforce.maybe(hH.typeforce.BufferN(22)),pubkey:hH.typeforce.maybe(hH.isPoint),signature:hH.typeforce.maybe(cH.isCanonicalScriptSignature),witness:hH.typeforce.maybe(hH.typeforce.arrayOf(hH.typeforce.Buffer))},e);const n=fH.value((()=>{const t=dH.bech32.decode(e.address),n=t.words.shift(),r=dH.bech32.fromWords(t.words);return{version:n,prefix:t.prefix,data:ao.from(r)}})),r=e.network||AH.bitcoin,i={name:"p2wpkh",network:r};if(fH.prop(i,"address",(()=>{if(!i.hash)return;const e=dH.bech32.toWords(i.hash);return e.unshift(0),dH.bech32.encode(r.bech32,e)})),fH.prop(i,"hash",(()=>e.output?e.output.slice(2,22):e.address?n().data:e.pubkey||i.pubkey?uH.hash160(e.pubkey||i.pubkey):void 0)),fH.prop(i,"output",(()=>{if(i.hash)return cH.compile([pH.OP_0,i.hash])})),fH.prop(i,"pubkey",(()=>e.pubkey?e.pubkey:e.witness?e.witness[1]:void 0)),fH.prop(i,"signature",(()=>{if(e.witness)return e.witness[0]})),fH.prop(i,"input",(()=>{if(i.witness)return gH})),fH.prop(i,"witness",(()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]})),t.validate){let t=ao.from([]);if(e.address){if(r&&r.bech32!==n().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==n().version)throw new TypeError("Invalid address version");if(20!==n().data.length)throw new TypeError("Invalid address data");t=n().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(22!==e.output.length||e.output[0]!==pH.OP_0||20!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");t=e.output.slice(2)}if(e.pubkey){const n=uH.hash160(e.pubkey);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");if(t=n,!(0,hH.isPoint)(e.pubkey)||33!==e.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(2!==e.witness.length)throw new TypeError("Witness is invalid");if(!cH.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,hH.isPoint)(e.witness[1])||33!==e.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const n=uH.hash160(e.witness[1]);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)};var yH={};Object.defineProperty(yH,"__esModule",{value:!0}),yH.p2wsh=void 0;const mH=UU,vH=cP,IH=dP,wH=EP,bH=dU,BH=$O,EH=IH.OPS,CH=ao.alloc(0);function SH(e){return!(!jo(e)||65!==e.length||4!==e[0]||!(0,wH.isPoint)(e))}yH.p2wsh=function(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,wH.typeforce)({network:wH.typeforce.maybe(wH.typeforce.Object),address:wH.typeforce.maybe(wH.typeforce.String),hash:wH.typeforce.maybe(wH.typeforce.BufferN(32)),output:wH.typeforce.maybe(wH.typeforce.BufferN(34)),redeem:wH.typeforce.maybe({input:wH.typeforce.maybe(wH.typeforce.Buffer),network:wH.typeforce.maybe(wH.typeforce.Object),output:wH.typeforce.maybe(wH.typeforce.Buffer),witness:wH.typeforce.maybe(wH.typeforce.arrayOf(wH.typeforce.Buffer))}),input:wH.typeforce.maybe(wH.typeforce.BufferN(0)),witness:wH.typeforce.maybe(wH.typeforce.arrayOf(wH.typeforce.Buffer))},e);const n=bH.value((()=>{const t=BH.bech32.decode(e.address),n=t.words.shift(),r=BH.bech32.fromWords(t.words);return{version:n,prefix:t.prefix,data:ao.from(r)}})),r=bH.value((()=>IH.decompile(e.redeem.input)));let i=e.network;i||(i=e.redeem&&e.redeem.network||vH.bitcoin);const o={network:i};if(bH.prop(o,"address",(()=>{if(!o.hash)return;const e=BH.bech32.toWords(o.hash);return e.unshift(0),BH.bech32.encode(i.bech32,e)})),bH.prop(o,"hash",(()=>e.output?e.output.slice(2):e.address?n().data:o.redeem&&o.redeem.output?mH.sha256(o.redeem.output):void 0)),bH.prop(o,"output",(()=>{if(o.hash)return IH.compile([EH.OP_0,o.hash])})),bH.prop(o,"redeem",(()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:CH,witness:e.witness.slice(0,-1)}})),bH.prop(o,"input",(()=>{if(o.witness)return CH})),bH.prop(o,"witness",(()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const t=IH.toStack(r());return o.redeem=Object.assign({witness:t},e.redeem),o.redeem.input=CH,[].concat(t,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)})),bH.prop(o,"name",(()=>{const e=["p2wsh"];return void 0!==o.redeem&&void 0!==o.redeem.name&&e.push(o.redeem.name),e.join("-")})),t.validate){let t=ao.from([]);if(e.address){if(n().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==n().version)throw new TypeError("Invalid address version");if(32!==n().data.length)throw new TypeError("Invalid address data");t=n().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(34!==e.output.length||e.output[0]!==EH.OP_0||32!==e.output[1])throw new TypeError("Output is invalid");const n=e.output.slice(2);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){if(0===IH.decompile(e.redeem.output).length)throw new TypeError("Redeem.output is invalid");const n=mH.sha256(e.redeem.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem.input&&!IH.isPushOnly(r()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!function(e,t){return e.length===t.length&&e.every(((e,n)=>e.equals(t[n])))}(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&r().some(SH)||e.redeem.output&&(IH.decompile(e.redeem.output)||[]).some(SH))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const t=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(t))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(SH)||(IH.decompile(t)||[]).some(SH))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=fP;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const n=IU;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return n.p2ms}});const r=QU;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return r.p2pk}});const i=PU;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const o=GO;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return o.p2sh}});const a=ZO;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return a.p2wpkh}});const s=yH;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return s.p2wsh}})}(hP),Object.defineProperty(AP,"__esModule",{value:!0}),AP.toOutputScript=AP.fromOutputScript=AP.toBech32=AP.toBase58Check=AP.fromBech32=AP.fromBase58Check=void 0;const xH=cP,QH=hP,kH=dP,_H=EP,NH=$O,DH=MO,{typeforce:FH}=_H,PH="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function UH(e){const t=DH.decode(e);if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");return{version:t.readUInt8(0),hash:t.slice(1)}}function MH(e){let t,n;try{t=NH.bech32.decode(e)}catch(e){}if(t){if(n=t.words[0],0!==n)throw new TypeError(e+" uses wrong encoding")}else if(t=NH.bech32m.decode(e),n=t.words[0],0===n)throw new TypeError(e+" uses wrong encoding");const r=NH.bech32.fromWords(t.words.slice(1));return{version:n,prefix:t.prefix,data:ao.from(r)}}function LH(e,t,n){const r=NH.bech32.toWords(e);return r.unshift(t),0===t?NH.bech32.encode(n,r):NH.bech32m.encode(n,r)}AP.fromBase58Check=UH,AP.fromBech32=MH,AP.toBase58Check=function(e,t){FH(_H.tuple(_H.Hash160bit,_H.UInt8),arguments);const n=ao.allocUnsafe(21);return n.writeUInt8(t,0),e.copy(n,1),DH.encode(n)},AP.toBech32=LH,AP.fromOutputScript=function(e,t){t=t||xH.bitcoin;try{return QH.p2pkh({output:e,network:t}).address}catch(e){}try{return QH.p2sh({output:e,network:t}).address}catch(e){}try{return QH.p2wpkh({output:e,network:t}).address}catch(e){}try{return QH.p2wsh({output:e,network:t}).address}catch(e){}try{return function(e,t){const n=e.slice(2);if(n.length<2||n.length>40)throw new TypeError("Invalid program length for segwit address");const r=e[0]-80;if(r<1||r>16)throw new TypeError("Invalid version for segwit address");if(e[1]!==n.length)throw new TypeError("Invalid script for segwit address");return console.warn(PH),LH(n,r,t.bech32)}(e,t)}catch(e){}throw new Error(kH.toASM(e)+" has no matching Address")},AP.toOutputScript=function(e,t){let n,r;t=t||xH.bitcoin;try{n=UH(e)}catch(e){}if(n){if(n.version===t.pubKeyHash)return QH.p2pkh({hash:n.hash}).output;if(n.version===t.scriptHash)return QH.p2sh({hash:n.hash}).output}else{try{r=MH(e)}catch(e){}if(r){if(r.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(0===r.version){if(20===r.data.length)return QH.p2wpkh({hash:r.data}).output;if(32===r.data.length)return QH.p2wsh({hash:r.data}).output}else if(r.version>=1&&r.version<=16&&r.data.length>=2&&r.data.length<=40)return console.warn(PH),kH.compile([r.version+80,r.data])}}throw new Error(e+" has no matching Script")};var TH={},RH={},OH=F_.exports.Buffer;function HH(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function KH(e){return HH(e),e<253?1:e<=65535?3:e<=4294967295?5:9}var jH={encode:function e(t,n,r){if(HH(t),n||(n=OH.allocUnsafe(KH(t))),!OH.isBuffer(n))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),t<253?(n.writeUInt8(t,r),e.bytes=1):t<=65535?(n.writeUInt8(253,r),n.writeUInt16LE(t,r+1),e.bytes=3):t<=4294967295?(n.writeUInt8(254,r),n.writeUInt32LE(t,r+1),e.bytes=5):(n.writeUInt8(255,r),n.writeUInt32LE(t>>>0,r+1),n.writeUInt32LE(t/4294967296|0,r+5),e.bytes=9),n},decode:function e(t,n){if(!OH.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");n||(n=0);var r=t.readUInt8(n);if(r<253)return e.bytes=1,r;if(253===r)return e.bytes=3,t.readUInt16LE(n+1);if(254===r)return e.bytes=5,t.readUInt32LE(n+1);e.bytes=9;var i=t.readUInt32LE(n+1),o=4294967296*t.readUInt32LE(n+5)+i;return HH(o),o},encodingLength:KH};Object.defineProperty(RH,"__esModule",{value:!0}),RH.BufferReader=RH.BufferWriter=RH.cloneBuffer=RH.reverseBuffer=RH.writeUInt64LE=RH.readUInt64LE=RH.varuint=void 0;const GH=EP,{typeforce:qH}=GH,VH=jH;function zH(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function JH(e,t){const n=e.readUInt32LE(t);let r=e.readUInt32LE(t+4);return r*=4294967296,zH(r+n,9007199254740991),r+n}function YH(e,t,n){return zH(t,9007199254740991),e.writeInt32LE(-1&t,n),e.writeUInt32LE(Math.floor(t/4294967296),n+4),n+8}RH.varuint=VH,RH.readUInt64LE=JH,RH.writeUInt64LE=YH,RH.reverseBuffer=function(e){if(e.length<1)return e;let t=e.length-1,n=0;for(let r=0;r<e.length/2;r++)n=e[r],e[r]=e[t],e[t]=n,t--;return e},RH.cloneBuffer=function(e){const t=ao.allocUnsafe(e.length);return e.copy(t),t};class XH{constructor(e,t=0){this.buffer=e,this.offset=t,qH(GH.tuple(GH.Buffer,GH.UInt32),[e,t])}static withCapacity(e){return new XH(ao.alloc(e))}writeUInt8(e){this.offset=this.buffer.writeUInt8(e,this.offset)}writeInt32(e){this.offset=this.buffer.writeInt32LE(e,this.offset)}writeUInt32(e){this.offset=this.buffer.writeUInt32LE(e,this.offset)}writeUInt64(e){this.offset=YH(this.buffer,e,this.offset)}writeVarInt(e){VH.encode(e,this.buffer,this.offset),this.offset+=VH.encode.bytes}writeSlice(e){if(this.buffer.length<this.offset+e.length)throw new Error("Cannot write slice out of bounds");this.offset+=e.copy(this.buffer,this.offset)}writeVarSlice(e){this.writeVarInt(e.length),this.writeSlice(e)}writeVector(e){this.writeVarInt(e.length),e.forEach((e=>this.writeVarSlice(e)))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}RH.BufferWriter=XH,RH.BufferReader=class{constructor(e,t=0){this.buffer=e,this.offset=t,qH(GH.tuple(GH.Buffer,GH.UInt32),[e,t])}readUInt8(){const e=this.buffer.readUInt8(this.offset);return this.offset++,e}readInt32(){const e=this.buffer.readInt32LE(this.offset);return this.offset+=4,e}readUInt32(){const e=this.buffer.readUInt32LE(this.offset);return this.offset+=4,e}readUInt64(){const e=JH(this.buffer,this.offset);return this.offset+=8,e}readVarInt(){const e=VH.decode(this.buffer,this.offset);return this.offset+=VH.decode.bytes,e}readSlice(e){if(this.buffer.length<this.offset+e)throw new Error("Cannot read slice out of bounds");const t=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const e=this.readVarInt(),t=[];for(let n=0;n<e;n++)t.push(this.readVarSlice());return t}};var WH={};Object.defineProperty(WH,"__esModule",{value:!0}),WH.fastMerkleRoot=void 0,WH.fastMerkleRoot=function(e,t){if(!Array.isArray(e))throw TypeError("Expected values Array");if("function"!=typeof t)throw TypeError("Expected digest Function");let n=e.length;const r=e.concat();for(;n>1;){let e=0;for(let i=0;i<n;i+=2,++e){const o=r[i],a=i+1===n?o:r[i+1],s=ao.concat([o,a]);r[e]=t(s)}n=e}return r[0]};var ZH={};Object.defineProperty(ZH,"__esModule",{value:!0}),ZH.Transaction=void 0;const $H=RH,eK=UU,tK=dP,nK=dP,rK=EP,{typeforce:iK}=rK;function oK(e){const t=e.length;return $H.varuint.encodingLength(t)+t}const aK=ao.allocUnsafe(0),sK=[],lK=ao.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),uK=ao.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),AK=ao.from("ffffffffffffffff","hex"),cK={script:aK,valueBuffer:AK};class hK{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(e,t){const n=new $H.BufferReader(e),r=new hK;r.version=n.readInt32();const i=n.readUInt8(),o=n.readUInt8();let a=!1;i===hK.ADVANCED_TRANSACTION_MARKER&&o===hK.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const s=n.readVarInt();for(let e=0;e<s;++e)r.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:sK});const l=n.readVarInt();for(let e=0;e<l;++e)r.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let e=0;e<s;++e)r.ins[e].witness=n.readVector();if(!r.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(r.locktime=n.readUInt32(),t)return r;if(n.offset!==e.length)throw new Error("Transaction has unexpected data");return r}static fromHex(e){return hK.fromBuffer(ao.from(e,"hex"),!1)}static isCoinbaseHash(e){iK(rK.Hash256bit,e);for(let t=0;t<32;++t)if(0!==e[t])return!1;return!0}isCoinbase(){return 1===this.ins.length&&hK.isCoinbaseHash(this.ins[0].hash)}addInput(e,t,n,r){return iK(rK.tuple(rK.Hash256bit,rK.UInt32,rK.maybe(rK.UInt32),rK.maybe(rK.Buffer)),arguments),rK.Null(n)&&(n=hK.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:t,script:r||aK,sequence:n,witness:sK})-1}addOutput(e,t){return iK(rK.tuple(rK.Buffer,rK.Satoshi),arguments),this.outs.push({script:e,value:t})-1}hasWitnesses(){return this.ins.some((e=>0!==e.witness.length))}weight(){return 3*this.byteLength(!1)+this.byteLength(!0)}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(e=!0){const t=e&&this.hasWitnesses();return(t?10:8)+$H.varuint.encodingLength(this.ins.length)+$H.varuint.encodingLength(this.outs.length)+this.ins.reduce(((e,t)=>e+40+oK(t.script)),0)+this.outs.reduce(((e,t)=>e+8+oK(t.script)),0)+(t?this.ins.reduce(((e,t)=>e+function(e){const t=e.length;return $H.varuint.encodingLength(t)+e.reduce(((e,t)=>e+oK(t)),0)}(t.witness)),0):0)}clone(){const e=new hK;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map((e=>({hash:e.hash,index:e.index,script:e.script,sequence:e.sequence,witness:e.witness}))),e.outs=this.outs.map((e=>({script:e.script,value:e.value}))),e}hashForSignature(e,t,n){if(iK(rK.tuple(rK.UInt32,rK.Buffer,rK.Number),arguments),e>=this.ins.length)return uK;const r=tK.compile(tK.decompile(t).filter((e=>e!==nK.OPS.OP_CODESEPARATOR))),i=this.clone();if((31&n)===hK.SIGHASH_NONE)i.outs=[],i.ins.forEach(((t,n)=>{n!==e&&(t.sequence=0)}));else if((31&n)===hK.SIGHASH_SINGLE){if(e>=this.outs.length)return uK;i.outs.length=e+1;for(let t=0;t<e;t++)i.outs[t]=cK;i.ins.forEach(((t,n)=>{n!==e&&(t.sequence=0)}))}n&hK.SIGHASH_ANYONECANPAY?(i.ins=[i.ins[e]],i.ins[0].script=r):(i.ins.forEach((e=>{e.script=aK})),i.ins[e].script=r);const o=ao.allocUnsafe(i.byteLength(!1)+4);return o.writeInt32LE(n,o.length-4),i.__toBuffer(o,0,!1),eK.hash256(o)}hashForWitnessV1(e,t,n,r,i,o){if(iK(rK.tuple(rK.UInt32,iK.arrayOf(rK.Buffer),iK.arrayOf(rK.Satoshi),rK.UInt32),arguments),n.length!==this.ins.length||t.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const a=r===hK.SIGHASH_DEFAULT?hK.SIGHASH_ALL:r&hK.SIGHASH_OUTPUT_MASK,s=(r&hK.SIGHASH_INPUT_MASK)===hK.SIGHASH_ANYONECANPAY,l=a===hK.SIGHASH_NONE,u=a===hK.SIGHASH_SINGLE;let A=aK,c=aK,h=aK,f=aK,d=aK;if(!s){let e=$H.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach((t=>{e.writeSlice(t.hash),e.writeUInt32(t.index)})),A=eK.sha256(e.end()),e=$H.BufferWriter.withCapacity(8*this.ins.length),n.forEach((t=>e.writeUInt64(t))),c=eK.sha256(e.end()),e=$H.BufferWriter.withCapacity(t.map(oK).reduce(((e,t)=>e+t))),t.forEach((t=>e.writeVarSlice(t))),h=eK.sha256(e.end()),e=$H.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach((t=>e.writeUInt32(t.sequence))),f=eK.sha256(e.end())}if(l||u){if(u&&e<this.outs.length){const t=this.outs[e],n=$H.BufferWriter.withCapacity(8+oK(t.script));n.writeUInt64(t.value),n.writeVarSlice(t.script),d=eK.sha256(n.end())}}else{const e=this.outs.map((e=>8+oK(e.script))).reduce(((e,t)=>e+t)),t=$H.BufferWriter.withCapacity(e);this.outs.forEach((e=>{t.writeUInt64(e.value),t.writeVarSlice(e.script)})),d=eK.sha256(t.end())}const p=(i?2:0)+(o?1:0),g=174-(s?49:0)-(l?32:0)+(o?32:0)+(i?37:0),y=$H.BufferWriter.withCapacity(g);if(y.writeUInt8(r),y.writeInt32(this.version),y.writeUInt32(this.locktime),y.writeSlice(A),y.writeSlice(c),y.writeSlice(h),y.writeSlice(f),l||u||y.writeSlice(d),y.writeUInt8(p),s){const r=this.ins[e];y.writeSlice(r.hash),y.writeUInt32(r.index),y.writeUInt64(n[e]),y.writeVarSlice(t[e]),y.writeUInt32(r.sequence)}else y.writeUInt32(e);if(o){const e=$H.BufferWriter.withCapacity(oK(o));e.writeVarSlice(o),y.writeSlice(eK.sha256(e.end()))}return u&&y.writeSlice(d),i&&(y.writeSlice(i),y.writeUInt8(0),y.writeUInt32(4294967295)),eK.taggedHash("TapSighash",ao.concat([ao.of(0),y.end()]))}hashForWitnessV0(e,t,n,r){iK(rK.tuple(rK.UInt32,rK.Buffer,rK.Satoshi,rK.UInt32),arguments);let i,o=ao.from([]),a=lK,s=lK,l=lK;if(r&hK.SIGHASH_ANYONECANPAY||(o=ao.allocUnsafe(36*this.ins.length),i=new $H.BufferWriter(o,0),this.ins.forEach((e=>{i.writeSlice(e.hash),i.writeUInt32(e.index)})),s=eK.hash256(o)),r&hK.SIGHASH_ANYONECANPAY||(31&r)===hK.SIGHASH_SINGLE||(31&r)===hK.SIGHASH_NONE||(o=ao.allocUnsafe(4*this.ins.length),i=new $H.BufferWriter(o,0),this.ins.forEach((e=>{i.writeUInt32(e.sequence)})),l=eK.hash256(o)),(31&r)!==hK.SIGHASH_SINGLE&&(31&r)!==hK.SIGHASH_NONE){const e=this.outs.reduce(((e,t)=>e+8+oK(t.script)),0);o=ao.allocUnsafe(e),i=new $H.BufferWriter(o,0),this.outs.forEach((e=>{i.writeUInt64(e.value),i.writeVarSlice(e.script)})),a=eK.hash256(o)}else if((31&r)===hK.SIGHASH_SINGLE&&e<this.outs.length){const t=this.outs[e];o=ao.allocUnsafe(8+oK(t.script)),i=new $H.BufferWriter(o,0),i.writeUInt64(t.value),i.writeVarSlice(t.script),a=eK.hash256(o)}o=ao.allocUnsafe(156+oK(t)),i=new $H.BufferWriter(o,0);const u=this.ins[e];return i.writeInt32(this.version),i.writeSlice(s),i.writeSlice(l),i.writeSlice(u.hash),i.writeUInt32(u.index),i.writeVarSlice(t),i.writeUInt64(n),i.writeUInt32(u.sequence),i.writeSlice(a),i.writeUInt32(this.locktime),i.writeUInt32(r),eK.hash256(o)}getHash(e){return e&&this.isCoinbase()?ao.alloc(32,0):eK.hash256(this.__toBuffer(void 0,void 0,e))}getId(){return(0,$H.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(e,t){return this.__toBuffer(e,t,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(e,t){iK(rK.tuple(rK.Number,rK.Buffer),arguments),this.ins[e].script=t}setWitness(e,t){iK(rK.tuple(rK.Number,[rK.Buffer]),arguments),this.ins[e].witness=t}__toBuffer(e,t,n=!1){e||(e=ao.allocUnsafe(this.byteLength(n)));const r=new $H.BufferWriter(e,t||0);r.writeInt32(this.version);const i=n&&this.hasWitnesses();return i&&(r.writeUInt8(hK.ADVANCED_TRANSACTION_MARKER),r.writeUInt8(hK.ADVANCED_TRANSACTION_FLAG)),r.writeVarInt(this.ins.length),this.ins.forEach((e=>{r.writeSlice(e.hash),r.writeUInt32(e.index),r.writeVarSlice(e.script),r.writeUInt32(e.sequence)})),r.writeVarInt(this.outs.length),this.outs.forEach((e=>{void 0!==e.value?r.writeUInt64(e.value):r.writeSlice(e.valueBuffer),r.writeVarSlice(e.script)})),i&&this.ins.forEach((e=>{r.writeVector(e.witness)})),r.writeUInt32(this.locktime),void 0!==t?e.slice(t,r.offset):e}}ZH.Transaction=hK,hK.DEFAULT_SEQUENCE=4294967295,hK.SIGHASH_DEFAULT=0,hK.SIGHASH_ALL=1,hK.SIGHASH_NONE=2,hK.SIGHASH_SINGLE=3,hK.SIGHASH_ANYONECANPAY=128,hK.SIGHASH_OUTPUT_MASK=3,hK.SIGHASH_INPUT_MASK=128,hK.ADVANCED_TRANSACTION_MARKER=0,hK.ADVANCED_TRANSACTION_FLAG=1,Object.defineProperty(TH,"__esModule",{value:!0}),TH.Block=void 0;const fK=RH,dK=UU,pK=WH,gK=ZH,yK=EP,{typeforce:mK}=yK,vK=new TypeError("Cannot compute merkle root for zero transactions"),IK=new TypeError("Cannot compute witness commit for non-segwit block");class wK{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(e){if(e.length<80)throw new Error("Buffer too small (< 80 bytes)");const t=new fK.BufferReader(e),n=new wK;if(n.version=t.readInt32(),n.prevHash=t.readSlice(32),n.merkleRoot=t.readSlice(32),n.timestamp=t.readUInt32(),n.bits=t.readUInt32(),n.nonce=t.readUInt32(),80===e.length)return n;const r=()=>{const e=gK.Transaction.fromBuffer(t.buffer.slice(t.offset),!0);return t.offset+=e.byteLength(),e},i=t.readVarInt();n.transactions=[];for(let e=0;e<i;++e){const e=r();n.transactions.push(e)}const o=n.getWitnessCommit();return o&&(n.witnessCommit=o),n}static fromHex(e){return wK.fromBuffer(ao.from(e,"hex"))}static calculateTarget(e){const t=((4278190080&e)>>24)-3,n=8388607&e,r=ao.alloc(32,0);return r.writeUIntBE(n,29-t,3),r}static calculateMerkleRoot(e,t){if(mK([{getHash:yK.Function}],e),0===e.length)throw vK;if(t&&!bK(e))throw IK;const n=e.map((e=>e.getHash(t))),r=(0,pK.fastMerkleRoot)(n,dK.hash256);return t?dK.hash256(ao.concat([r,e[0].ins[0].witness[0]])):r}getWitnessCommit(){if(!bK(this.transactions))return null;const e=this.transactions[0].outs.filter((e=>e.script.slice(0,6).equals(ao.from("6a24aa21a9ed","hex")))).map((e=>e.script.slice(6,38)));if(0===e.length)return null;const t=e[e.length-1];return t instanceof ao&&32===t.length?t:null}hasWitnessCommit(){return this.witnessCommit instanceof ao&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}hasWitness(){return(e=this.transactions)instanceof Array&&e.some((e=>"object"==typeof e&&e.ins instanceof Array&&e.ins.some((e=>"object"==typeof e&&e.witness instanceof Array&&e.witness.length>0))));var e}weight(){return 3*this.byteLength(!1,!1)+this.byteLength(!1,!0)}byteLength(e,t=!0){return e||!this.transactions?80:80+fK.varuint.encodingLength(this.transactions.length)+this.transactions.reduce(((e,n)=>e+n.byteLength(t)),0)}getHash(){return dK.hash256(this.toBuffer(!0))}getId(){return(0,fK.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const e=new Date(0);return e.setUTCSeconds(this.timestamp),e}toBuffer(e){const t=ao.allocUnsafe(this.byteLength(e)),n=new fK.BufferWriter(t);return n.writeInt32(this.version),n.writeSlice(this.prevHash),n.writeSlice(this.merkleRoot),n.writeUInt32(this.timestamp),n.writeUInt32(this.bits),n.writeUInt32(this.nonce),e||!this.transactions||(fK.varuint.encode(this.transactions.length,t,n.offset),n.offset+=fK.varuint.encode.bytes,this.transactions.forEach((e=>{const r=e.byteLength();e.toBuffer(t,n.offset),n.offset+=r}))),t}toHex(e){return this.toBuffer(e).toString("hex")}checkTxRoots(){const e=this.hasWitnessCommit();return!(!e&&this.hasWitness())&&this.__checkMerkleRoot()&&(!e||this.__checkWitnessCommit())}checkProofOfWork(){const e=(0,fK.reverseBuffer)(this.getHash()),t=wK.calculateTarget(this.bits);return e.compare(t)<=0}__checkMerkleRoot(){if(!this.transactions)throw vK;const e=wK.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}__checkWitnessCommit(){if(!this.transactions)throw vK;if(!this.hasWitnessCommit())throw IK;const e=wK.calculateMerkleRoot(this.transactions,!0);return 0===this.witnessCommit.compare(e)}}function bK(e){return e instanceof Array&&e[0]&&e[0].ins&&e[0].ins instanceof Array&&e[0].ins[0]&&e[0].ins[0].witness&&e[0].ins[0].witness instanceof Array&&e[0].ins[0].witness.length>0}TH.Block=wK;var BK={},EK={},CK={},SK={},xK={},QK={},kK={};!function(e){var t,n,r;Object.defineProperty(e,"__esModule",{value:!0}),(t=e.GlobalTypes||(e.GlobalTypes={}))[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(n=e.InputTypes||(e.InputTypes={}))[n.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",n[n.WITNESS_UTXO=1]="WITNESS_UTXO",n[n.PARTIAL_SIG=2]="PARTIAL_SIG",n[n.SIGHASH_TYPE=3]="SIGHASH_TYPE",n[n.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",n[n.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",n[n.BIP32_DERIVATION=6]="BIP32_DERIVATION",n[n.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",n[n.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",n[n.POR_COMMITMENT=9]="POR_COMMITMENT",n[n.TAP_KEY_SIG=19]="TAP_KEY_SIG",n[n.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",n[n.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",n[n.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",n[n.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",n[n.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT",e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(r=e.OutputTypes||(e.OutputTypes={}))[r.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",r[r.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",r[r.BIP32_DERIVATION=2]="BIP32_DERIVATION",r[r.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",r[r.TAP_TREE=6]="TAP_TREE",r[r.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION",e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]}(kK);var _K={};Object.defineProperty(_K,"__esModule",{value:!0});const NK=kK;_K.decode=function(e){if(e.key[0]!==NK.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+e.key.toString("hex"));if(79!==e.key.length||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+e.key.toString("hex"));if(e.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),n={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const t of(r=e.value.length/4-1,[...Array(r).keys()])){const r=e.value.readUInt32LE(4*t+4),i=!!(2147483648&r),o=2147483647&r;n.path+="/"+o.toString(10)+(i?"'":"")}var r;return n},_K.encode=function(e){const t=ao.from([NK.GlobalTypes.GLOBAL_XPUB]),n=ao.concat([t,e.extendedPubkey]),r=e.path.split("/"),i=ao.allocUnsafe(4*r.length);e.masterFingerprint.copy(i,0);let o=4;return r.slice(1).forEach((e=>{const t="'"===e.slice(-1);let n=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(n+=2147483648),i.writeUInt32LE(n,o),o+=4})),{key:n,value:i}},_K.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",_K.check=function(e){const t=e.extendedPubkey,n=e.masterFingerprint,r=e.path;return jo(t)&&78===t.length&&[2,3].indexOf(t[45])>-1&&jo(n)&&4===n.length&&"string"==typeof r&&!!r.match(/^m(\/\d+'?)*$/)},_K.canAddToArray=function(e,t,n){const r=t.extendedPubkey.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.extendedPubkey.equals(t.extendedPubkey))).length)};var DK={};Object.defineProperty(DK,"__esModule",{value:!0});const FK=kK;DK.encode=function(e){return{key:ao.from([FK.GlobalTypes.UNSIGNED_TX]),value:e.toBuffer()}};var PK={};Object.defineProperty(PK,"__esModule",{value:!0});const UK=kK;PK.decode=function(e){if(e.key[0]!==UK.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+e.key.toString("hex"));return e.value},PK.encode=function(e){return{key:ao.from([UK.InputTypes.FINAL_SCRIPTSIG]),value:e}},PK.expected="Buffer",PK.check=function(e){return jo(e)},PK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptSig};var MK={};Object.defineProperty(MK,"__esModule",{value:!0});const LK=kK;MK.decode=function(e){if(e.key[0]!==LK.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+e.key.toString("hex"));return e.value},MK.encode=function(e){return{key:ao.from([LK.InputTypes.FINAL_SCRIPTWITNESS]),value:e}},MK.expected="Buffer",MK.check=function(e){return jo(e)},MK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptWitness};var TK={};Object.defineProperty(TK,"__esModule",{value:!0});const RK=kK;TK.decode=function(e){if(e.key[0]!==RK.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+e.key.toString("hex"));return e.value},TK.encode=function(e){return{key:ao.from([RK.InputTypes.NON_WITNESS_UTXO]),value:e}},TK.expected="Buffer",TK.check=function(e){return jo(e)},TK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.nonWitnessUtxo};var OK={};Object.defineProperty(OK,"__esModule",{value:!0});const HK=kK;OK.decode=function(e){if(e.key[0]!==HK.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+e.key.toString("hex"));if(34!==e.key.length&&66!==e.key.length||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+e.key.toString("hex"));return{pubkey:e.key.slice(1),signature:e.value}},OK.encode=function(e){const t=ao.from([HK.InputTypes.PARTIAL_SIG]);return{key:ao.concat([t,e.pubkey]),value:e.signature}},OK.expected="{ pubkey: Buffer; signature: Buffer; }",OK.check=function(e){return jo(e.pubkey)&&jo(e.signature)&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&function(e){if(!jo(e)||e.length<9)return!1;if(48!==e[0])return!1;if(e.length!==e[1]+3)return!1;if(2!==e[2])return!1;const t=e[3];if(t>33||t<1)return!1;if(2!==e[3+t+1])return!1;const n=e[3+t+2];return!(n>33||n<1)&&e.length===3+t+2+n+2}(e.signature)},OK.canAddToArray=function(e,t,n){const r=t.pubkey.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.pubkey.equals(t.pubkey))).length)};var KK={};Object.defineProperty(KK,"__esModule",{value:!0});const jK=kK;KK.decode=function(e){if(e.key[0]!==jK.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+e.key.toString("hex"));return e.value.toString("utf8")},KK.encode=function(e){return{key:ao.from([jK.InputTypes.POR_COMMITMENT]),value:ao.from(e,"utf8")}},KK.expected="string",KK.check=function(e){return"string"==typeof e},KK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.porCommitment};var GK={};Object.defineProperty(GK,"__esModule",{value:!0});const qK=kK;GK.decode=function(e){if(e.key[0]!==qK.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+e.key.toString("hex"));return e.value.readUInt32LE(0)},GK.encode=function(e){const t=ao.from([qK.InputTypes.SIGHASH_TYPE]),n=ao.allocUnsafe(4);return n.writeUInt32LE(e,0),{key:t,value:n}},GK.expected="number",GK.check=function(e){return"number"==typeof e},GK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.sighashType};var VK={};Object.defineProperty(VK,"__esModule",{value:!0});const zK=kK;function JK(e){return jo(e)&&(64===e.length||65===e.length)}VK.decode=function(e){if(e.key[0]!==zK.InputTypes.TAP_KEY_SIG||1!==e.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+e.key.toString("hex"));if(!JK(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value},VK.encode=function(e){return{key:ao.from([zK.InputTypes.TAP_KEY_SIG]),value:e}},VK.expected="Buffer",VK.check=JK,VK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapKeySig};var YK={};Object.defineProperty(YK,"__esModule",{value:!0});const XK=kK;YK.decode=function(e){if(e.key[0]!==XK.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+e.key.toString("hex"));if((e.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+e.key.toString("hex"));const t=e.value[e.value.length-1];if((254&e.key[1])!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+e.key.toString("hex"));const n=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:n,leafVersion:t}},YK.encode=function(e){const t=ao.from([XK.InputTypes.TAP_LEAF_SCRIPT]),n=ao.from([e.leafVersion]);return{key:ao.concat([t,e.controlBlock]),value:ao.concat([e.script,n])}},YK.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",YK.check=function(e){return jo(e.controlBlock)&&(e.controlBlock.length-1)%32==0&&(254&e.controlBlock[0])===e.leafVersion&&jo(e.script)},YK.canAddToArray=function(e,t,n){const r=t.controlBlock.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.controlBlock.equals(t.controlBlock))).length)};var WK={};Object.defineProperty(WK,"__esModule",{value:!0});const ZK=kK;function $K(e){return jo(e)&&32===e.length}WK.decode=function(e){if(e.key[0]!==ZK.InputTypes.TAP_MERKLE_ROOT||1!==e.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+e.key.toString("hex"));if(!$K(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value},WK.encode=function(e){return{key:ao.from([ZK.InputTypes.TAP_MERKLE_ROOT]),value:e}},WK.expected="Buffer",WK.check=$K,WK.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapMerkleRoot};var ej={};Object.defineProperty(ej,"__esModule",{value:!0});const tj=kK;ej.decode=function(e){if(e.key[0]!==tj.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+e.key.toString("hex"));if(65!==e.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+e.key.toString("hex"));if(64!==e.value.length&&65!==e.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+e.key.toString("hex"));return{pubkey:e.key.slice(1,33),leafHash:e.key.slice(33),signature:e.value}},ej.encode=function(e){const t=ao.from([tj.InputTypes.TAP_SCRIPT_SIG]);return{key:ao.concat([t,e.pubkey,e.leafHash]),value:e.signature}},ej.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",ej.check=function(e){return jo(e.pubkey)&&jo(e.leafHash)&&jo(e.signature)&&32===e.pubkey.length&&32===e.leafHash.length&&(64===e.signature.length||65===e.signature.length)},ej.canAddToArray=function(e,t,n){const r=t.pubkey.toString("hex")+t.leafHash.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.pubkey.equals(t.pubkey)&&e.leafHash.equals(t.leafHash))).length)};var nj={},rj={},ij={};function oj(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function aj(e){return oj(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Object.defineProperty(ij,"__esModule",{value:!0}),ij.encode=function e(t,n,r){if(oj(t),n||(n=ao.allocUnsafe(aj(t))),!jo(n))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),t<253?(n.writeUInt8(t,r),Object.assign(e,{bytes:1})):t<=65535?(n.writeUInt8(253,r),n.writeUInt16LE(t,r+1),Object.assign(e,{bytes:3})):t<=4294967295?(n.writeUInt8(254,r),n.writeUInt32LE(t,r+1),Object.assign(e,{bytes:5})):(n.writeUInt8(255,r),n.writeUInt32LE(t>>>0,r+1),n.writeUInt32LE(t/4294967296|0,r+5),Object.assign(e,{bytes:9})),n},ij.decode=function e(t,n){if(!jo(t))throw new TypeError("buffer must be a Buffer instance");n||(n=0);const r=t.readUInt8(n);if(r<253)return Object.assign(e,{bytes:1}),r;if(253===r)return Object.assign(e,{bytes:3}),t.readUInt16LE(n+1);if(254===r)return Object.assign(e,{bytes:5}),t.readUInt32LE(n+1);{Object.assign(e,{bytes:9});const r=t.readUInt32LE(n+1),i=4294967296*t.readUInt32LE(n+5)+r;return oj(i),i}},ij.encodingLength=aj,Object.defineProperty(rj,"__esModule",{value:!0});const sj=ij;function lj(e){const t=e.key.length,n=e.value.length,r=sj.encodingLength(t),i=sj.encodingLength(n),o=ao.allocUnsafe(r+t+i+n);return sj.encode(t,o,0),e.key.copy(o,r),sj.encode(n,o,r+t),e.value.copy(o,r+t+i),o}function uj(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}rj.range=e=>[...Array(e).keys()],rj.reverseBuffer=function(e){if(e.length<1)return e;let t=e.length-1,n=0;for(let r=0;r<e.length/2;r++)n=e[r],e[r]=e[t],e[t]=n,t--;return e},rj.keyValsToBuffer=function(e){const t=e.map(lj);return t.push(ao.from([0])),ao.concat(t)},rj.keyValToBuffer=lj,rj.readUInt64LE=function(e,t){const n=e.readUInt32LE(t);let r=e.readUInt32LE(t+4);return r*=4294967296,uj(r+n,9007199254740991),r+n},rj.writeUInt64LE=function(e,t,n){return uj(t,9007199254740991),e.writeInt32LE(-1&t,n),e.writeUInt32LE(Math.floor(t/4294967296),n+4),n+8},Object.defineProperty(nj,"__esModule",{value:!0});const Aj=kK,cj=rj,hj=ij;nj.decode=function(e){if(e.key[0]!==Aj.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+e.key.toString("hex"));const t=cj.readUInt64LE(e.value,0);let n=8;const r=hj.decode(e.value,n);n+=hj.encodingLength(r);const i=e.value.slice(n);if(i.length!==r)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:i,value:t}},nj.encode=function(e){const{script:t,value:n}=e,r=hj.encodingLength(t.length),i=ao.allocUnsafe(8+r+t.length);return cj.writeUInt64LE(i,n,0),hj.encode(t.length,i,8),t.copy(i,8+r),{key:ao.from([Aj.InputTypes.WITNESS_UTXO]),value:i}},nj.expected="{ script: Buffer; value: number; }",nj.check=function(e){return jo(e.script)&&"number"==typeof e.value},nj.canAdd=function(e,t){return!!e&&!!t&&void 0===e.witnessUtxo};var fj={};Object.defineProperty(fj,"__esModule",{value:!0});const dj=kK,pj=ij;fj.decode=function(e){if(e.key[0]!==dj.OutputTypes.TAP_TREE||1!==e.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+e.key.toString("hex"));let t=0;const n=[];for(;t<e.value.length;){const r=e.value[t++],i=e.value[t++],o=pj.decode(e.value,t);t+=pj.encodingLength(o),n.push({depth:r,leafVersion:i,script:e.value.slice(t,t+o)}),t+=o}return{leaves:n}},fj.encode=function(e){const t=ao.from([dj.OutputTypes.TAP_TREE]),n=[].concat(...e.leaves.map((e=>[ao.of(e.depth,e.leafVersion),pj.encode(e.script.length),e.script])));return{key:t,value:ao.concat(n)}},fj.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",fj.check=function(e){return Array.isArray(e.leaves)&&e.leaves.every((e=>e.depth>=0&&e.depth<=128&&(254&e.leafVersion)===e.leafVersion&&jo(e.script)))},fj.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapTree};var gj={};Object.defineProperty(gj,"__esModule",{value:!0});const yj=e=>33===e.length&&[2,3].includes(e[0])||65===e.length&&4===e[0];gj.makeConverter=function(e,t=yj){return{decode:function(n){if(n.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+n.key.toString("hex"));const r=n.key.slice(1);if(!t(r))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+n.key.toString("hex"));if(n.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:n.value.slice(0,4),pubkey:r,path:"m"};for(const e of(o=n.value.length/4-1,[...Array(o).keys()])){const t=n.value.readUInt32LE(4*e+4),r=!!(2147483648&t),o=2147483647&t;i.path+="/"+o.toString(10)+(r?"'":"")}var o;return i},encode:function(t){const n=ao.from([e]),r=ao.concat([n,t.pubkey]),i=t.path.split("/"),o=ao.allocUnsafe(4*i.length);t.masterFingerprint.copy(o,0);let a=4;return i.slice(1).forEach((e=>{const t="'"===e.slice(-1);let n=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(n+=2147483648),o.writeUInt32LE(n,a),a+=4})),{key:r,value:o}},check:function(e){return jo(e.pubkey)&&jo(e.masterFingerprint)&&"string"==typeof e.path&&t(e.pubkey)&&4===e.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(e,t,n){const r=t.pubkey.toString("hex");return!n.has(r)&&(n.add(r),0===e.filter((e=>e.pubkey.equals(t.pubkey))).length)}}};var mj={};Object.defineProperty(mj,"__esModule",{value:!0}),mj.makeChecker=function(e){return function(t){let n;if(e.includes(t.key[0])&&(n=t.key.slice(1),33!==n.length&&65!==n.length||![2,3,4].includes(n[0])))throw new Error("Format Error: invalid pubkey in key 0x"+t.key.toString("hex"));return n}};var vj={};Object.defineProperty(vj,"__esModule",{value:!0}),vj.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:ao.from([e]),value:t}},check:function(e){return jo(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.redeemScript}}};var Ij={};Object.defineProperty(Ij,"__esModule",{value:!0});const wj=ij,bj=gj,Bj=e=>32===e.length;Ij.makeConverter=function(e){const t=bj.makeConverter(e,Bj);return{decode:function(e){const n=wj.decode(e.value),r=wj.encodingLength(n),i=t.decode({key:e.key,value:e.value.slice(r+32*n)}),o=new Array(n);for(let t=0,i=r;t<n;t++,i+=32)o[t]=e.value.slice(i,i+32);return Object.assign({},i,{leafHashes:o})},encode:function(e){const n=t.encode(e),r=wj.encodingLength(e.leafHashes.length),i=ao.allocUnsafe(r);wj.encode(e.leafHashes.length,i);const o=ao.concat([i,...e.leafHashes,n.value]);return Object.assign({},n,{value:o})},check:function(e){return Array.isArray(e.leafHashes)&&e.leafHashes.every((e=>jo(e)&&32===e.length))&&t.check(e)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:t.canAddToArray}};var Ej={};Object.defineProperty(Ej,"__esModule",{value:!0}),Ej.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e||1!==t.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+t.key.toString("hex"));if(32!==t.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return t.value},encode:function(t){return{key:ao.from([e]),value:t}},check:function(e){return jo(e)&&32===e.length},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.tapInternalKey}}};var Cj={};Object.defineProperty(Cj,"__esModule",{value:!0}),Cj.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:ao.from([e]),value:t}},check:function(e){return jo(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.witnessScript}}},Object.defineProperty(QK,"__esModule",{value:!0});const Sj=kK,xj=PK,Qj=MK,kj=TK,_j=OK,Nj=KK,Dj=GK,Fj=VK,Pj=YK,Uj=WK,Mj=ej,Lj=nj,Tj=fj,Rj=gj,Oj=mj,Hj=vj,Kj=Ij,jj=Ej,Gj=Cj,qj={unsignedTx:DK,globalXpub:_K,checkPubkey:Oj.makeChecker([])};QK.globals=qj;const Vj={nonWitnessUtxo:kj,partialSig:_j,sighashType:Dj,finalScriptSig:xj,finalScriptWitness:Qj,porCommitment:Nj,witnessUtxo:Lj,bip32Derivation:Rj.makeConverter(Sj.InputTypes.BIP32_DERIVATION),redeemScript:Hj.makeConverter(Sj.InputTypes.REDEEM_SCRIPT),witnessScript:Gj.makeConverter(Sj.InputTypes.WITNESS_SCRIPT),checkPubkey:Oj.makeChecker([Sj.InputTypes.PARTIAL_SIG,Sj.InputTypes.BIP32_DERIVATION]),tapKeySig:Fj,tapScriptSig:Mj,tapLeafScript:Pj,tapBip32Derivation:Kj.makeConverter(Sj.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:jj.makeConverter(Sj.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:Uj};QK.inputs=Vj;const zj={bip32Derivation:Rj.makeConverter(Sj.OutputTypes.BIP32_DERIVATION),redeemScript:Hj.makeConverter(Sj.OutputTypes.REDEEM_SCRIPT),witnessScript:Gj.makeConverter(Sj.OutputTypes.WITNESS_SCRIPT),checkPubkey:Oj.makeChecker([Sj.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:Kj.makeConverter(Sj.OutputTypes.TAP_BIP32_DERIVATION),tapTree:Tj,tapInternalKey:jj.makeConverter(Sj.OutputTypes.TAP_INTERNAL_KEY)};QK.outputs=zj,Object.defineProperty(xK,"__esModule",{value:!0});const Jj=QK,Yj=rj,Xj=ij,Wj=kK;function Zj(e,t,n){if(!t.equals(ao.from([n])))throw new Error(`Format Error: Invalid ${e} key: ${t.toString("hex")}`)}function $j(e,{globalMapKeyVals:t,inputKeyVals:n,outputKeyVals:r}){const i={unsignedTx:e};let o=0;for(const e of t)switch(e.key[0]){case Wj.GlobalTypes.UNSIGNED_TX:if(Zj("global",e.key,Wj.GlobalTypes.UNSIGNED_TX),o>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");o++;break;case Wj.GlobalTypes.GLOBAL_XPUB:void 0===i.globalXpub&&(i.globalXpub=[]),i.globalXpub.push(Jj.globals.globalXpub.decode(e));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(e)}const a=n.length,s=r.length,l=[],u=[];for(const e of Yj.range(a)){const t={};for(const r of n[e])switch(Jj.inputs.checkPubkey(r),r.key[0]){case Wj.InputTypes.NON_WITNESS_UTXO:if(Zj("input",r.key,Wj.InputTypes.NON_WITNESS_UTXO),void 0!==t.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");t.nonWitnessUtxo=Jj.inputs.nonWitnessUtxo.decode(r);break;case Wj.InputTypes.WITNESS_UTXO:if(Zj("input",r.key,Wj.InputTypes.WITNESS_UTXO),void 0!==t.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");t.witnessUtxo=Jj.inputs.witnessUtxo.decode(r);break;case Wj.InputTypes.PARTIAL_SIG:void 0===t.partialSig&&(t.partialSig=[]),t.partialSig.push(Jj.inputs.partialSig.decode(r));break;case Wj.InputTypes.SIGHASH_TYPE:if(Zj("input",r.key,Wj.InputTypes.SIGHASH_TYPE),void 0!==t.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");t.sighashType=Jj.inputs.sighashType.decode(r);break;case Wj.InputTypes.REDEEM_SCRIPT:if(Zj("input",r.key,Wj.InputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");t.redeemScript=Jj.inputs.redeemScript.decode(r);break;case Wj.InputTypes.WITNESS_SCRIPT:if(Zj("input",r.key,Wj.InputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");t.witnessScript=Jj.inputs.witnessScript.decode(r);break;case Wj.InputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(Jj.inputs.bip32Derivation.decode(r));break;case Wj.InputTypes.FINAL_SCRIPTSIG:Zj("input",r.key,Wj.InputTypes.FINAL_SCRIPTSIG),t.finalScriptSig=Jj.inputs.finalScriptSig.decode(r);break;case Wj.InputTypes.FINAL_SCRIPTWITNESS:Zj("input",r.key,Wj.InputTypes.FINAL_SCRIPTWITNESS),t.finalScriptWitness=Jj.inputs.finalScriptWitness.decode(r);break;case Wj.InputTypes.POR_COMMITMENT:Zj("input",r.key,Wj.InputTypes.POR_COMMITMENT),t.porCommitment=Jj.inputs.porCommitment.decode(r);break;case Wj.InputTypes.TAP_KEY_SIG:Zj("input",r.key,Wj.InputTypes.TAP_KEY_SIG),t.tapKeySig=Jj.inputs.tapKeySig.decode(r);break;case Wj.InputTypes.TAP_SCRIPT_SIG:void 0===t.tapScriptSig&&(t.tapScriptSig=[]),t.tapScriptSig.push(Jj.inputs.tapScriptSig.decode(r));break;case Wj.InputTypes.TAP_LEAF_SCRIPT:void 0===t.tapLeafScript&&(t.tapLeafScript=[]),t.tapLeafScript.push(Jj.inputs.tapLeafScript.decode(r));break;case Wj.InputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(Jj.inputs.tapBip32Derivation.decode(r));break;case Wj.InputTypes.TAP_INTERNAL_KEY:Zj("input",r.key,Wj.InputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=Jj.inputs.tapInternalKey.decode(r);break;case Wj.InputTypes.TAP_MERKLE_ROOT:Zj("input",r.key,Wj.InputTypes.TAP_MERKLE_ROOT),t.tapMerkleRoot=Jj.inputs.tapMerkleRoot.decode(r);break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(r)}l.push(t)}for(const e of Yj.range(s)){const t={};for(const n of r[e])switch(Jj.outputs.checkPubkey(n),n.key[0]){case Wj.OutputTypes.REDEEM_SCRIPT:if(Zj("output",n.key,Wj.OutputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");t.redeemScript=Jj.outputs.redeemScript.decode(n);break;case Wj.OutputTypes.WITNESS_SCRIPT:if(Zj("output",n.key,Wj.OutputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");t.witnessScript=Jj.outputs.witnessScript.decode(n);break;case Wj.OutputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(Jj.outputs.bip32Derivation.decode(n));break;case Wj.OutputTypes.TAP_INTERNAL_KEY:Zj("output",n.key,Wj.OutputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=Jj.outputs.tapInternalKey.decode(n);break;case Wj.OutputTypes.TAP_TREE:Zj("output",n.key,Wj.OutputTypes.TAP_TREE),t.tapTree=Jj.outputs.tapTree.decode(n);break;case Wj.OutputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(Jj.outputs.tapBip32Derivation.decode(n));break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(n)}u.push(t)}return{globalMap:i,inputs:l,outputs:u}}xK.psbtFromBuffer=function(e,t){let n=0;function r(){const t=Xj.decode(e,n);n+=Xj.encodingLength(t);const r=e.slice(n,n+t);return n+=t,r}function i(){return{key:r(),value:r()}}function o(){if(n>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const t=0===e.readUInt8(n);return t&&n++,t}if(1886610036!==function(){const t=e.readUInt32BE(n);return n+=4,t}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const t=e.readUInt8(n);return n+=1,t}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const a=[],s={};for(;!o();){const e=i(),t=e.key.toString("hex");if(s[t])throw new Error("Format Error: Keys must be unique for global keymap: key "+t);s[t]=1,a.push(e)}const l=a.filter((e=>e.key[0]===Wj.GlobalTypes.UNSIGNED_TX));if(1!==l.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const u=t(l[0].value),{inputCount:A,outputCount:c}=u.getInputOutputCounts(),h=[],f=[];for(const e of Yj.range(A)){const t={},n=[];for(;!o();){const r=i(),o=r.key.toString("hex");if(t[o])throw new Error("Format Error: Keys must be unique for each input: input index "+e+" key "+o);t[o]=1,n.push(r)}h.push(n)}for(const e of Yj.range(c)){const t={},n=[];for(;!o();){const r=i(),o=r.key.toString("hex");if(t[o])throw new Error("Format Error: Keys must be unique for each output: output index "+e+" key "+o);t[o]=1,n.push(r)}f.push(n)}return $j(u,{globalMapKeyVals:a,inputKeyVals:h,outputKeyVals:f})},xK.checkKeyBuffer=Zj,xK.psbtFromKeyVals=$j;var eG={};Object.defineProperty(eG,"__esModule",{value:!0});const tG=QK,nG=rj;eG.psbtToBuffer=function({globalMap:e,inputs:t,outputs:n}){const{globalKeyVals:r,inputKeyVals:i,outputKeyVals:o}=oG({globalMap:e,inputs:t,outputs:n}),a=nG.keyValsToBuffer(r),s=e=>0===e.length?[ao.from([0])]:e.map(nG.keyValsToBuffer),l=s(i),u=s(o),A=ao.allocUnsafe(5);return A.writeUIntBE(482972169471,0,5),ao.concat([A,a].concat(l,u))};const rG=(e,t)=>e.key.compare(t.key);function iG(e,t){const n=new Set,r=Object.entries(e).reduce(((e,[r,i])=>{if("unknownKeyVals"===r)return e;const o=t[r];if(void 0===o)return e;const a=(Array.isArray(i)?i:[i]).map(o.encode);return a.map((e=>e.key.toString("hex"))).forEach((e=>{if(n.has(e))throw new Error("Serialize Error: Duplicate key: "+e);n.add(e)})),e.concat(a)}),[]),i=e.unknownKeyVals?e.unknownKeyVals.filter((e=>!n.has(e.key.toString("hex")))):[];return r.concat(i).sort(rG)}function oG({globalMap:e,inputs:t,outputs:n}){return{globalKeyVals:iG(e,tG.globals),inputKeyVals:t.map((e=>iG(e,tG.inputs))),outputKeyVals:n.map((e=>iG(e,tG.outputs)))}}eG.psbtToKeyVals=oG,function(e){function t(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),t(xK),t(eG)}(SK),Object.defineProperty(CK,"__esModule",{value:!0});const aG=SK;function sG(e,t,n){return r=>{if(e.has(r))return;const i=n.filter((e=>e.key.toString("hex")===r))[0];t.push(i),e.add(r)}}function lG(e){return e.globalMap.unsignedTx}function uG(e){const t=new Set;return e.forEach((e=>{const n=e.key.toString("hex");if(t.has(n))throw new Error("Combine: KeyValue Map keys should be unique");t.add(n)})),t}CK.combine=function(e){const t=e[0],n=aG.psbtToKeyVals(t),r=e.slice(1);if(0===r.length)throw new Error("Combine: Nothing to combine");const i=lG(t);if(void 0===i)throw new Error("Combine: Self missing transaction");const o=uG(n.globalKeyVals),a=n.inputKeyVals.map(uG),s=n.outputKeyVals.map(uG);for(const e of r){const t=lG(e);if(void 0===t||!t.toBuffer().equals(i.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const r=aG.psbtToKeyVals(e);uG(r.globalKeyVals).forEach(sG(o,n.globalKeyVals,r.globalKeyVals)),r.inputKeyVals.map(uG).forEach(((e,t)=>e.forEach(sG(a[t],n.inputKeyVals[t],r.inputKeyVals[t])))),r.outputKeyVals.map(uG).forEach(((e,t)=>e.forEach(sG(s[t],n.outputKeyVals[t],r.outputKeyVals[t]))))}return aG.psbtFromKeyVals(i,{globalMapKeyVals:n.globalKeyVals,inputKeyVals:n.inputKeyVals,outputKeyVals:n.outputKeyVals})};var AG={};!function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=QK;function n(e,t){const n=e[t];if(void 0===n)throw new Error(`No input #${t}`);return n}function r(e,t){const n=e[t];if(void 0===n)throw new Error(`No output #${t}`);return n}function i(e,t,n,r){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${n} and got ${JSON.stringify(r)}`)}function o(e){return(n,r)=>{for(const o of Object.keys(n)){const a=n[o],{canAdd:s,canAddToArray:l,check:u,expected:A}=t[e+"s"][o]||{},c=!!l;if(u)if(c){if(!Array.isArray(a)||r[o]&&!Array.isArray(r[o]))throw new Error(`Key type ${o} must be an array`);a.every(u)||i(e,o,A,a);const t=r[o]||[],n=new Set;if(!a.every((e=>l(t,e,n))))throw new Error("Can not add duplicate data to array");r[o]=t.concat(a)}else{if(u(a)||i(e,o,A,a),!s(r,a))throw new Error(`Can not add duplicate data to ${e}`);r[o]=a}}}}e.checkForInput=n,e.checkForOutput=r,e.checkHasKey=function(e,t,n){if(e.key[0]<n)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&0!==t.filter((t=>t.key.equals(e.key))).length)throw new Error(`Duplicate Key: ${e.key.toString("hex")}`)},e.getEnumLength=function(e){let t=0;return Object.keys(e).forEach((e=>{Number(isNaN(Number(e)))&&t++})),t},e.inputCheckUncleanFinalized=function(e,t){let n=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const e=!!t.redeemScript,r=!!t.witnessScript,i=!e||!!t.finalScriptSig,o=!r||!!t.finalScriptWitness,a=!!t.finalScriptSig||!!t.finalScriptWitness;n=i&&o&&a}if(!1===n)throw new Error(`Input #${e} has too much or too little data to clean`)},e.updateGlobal=o("global"),e.updateInput=o("input"),e.updateOutput=o("output"),e.addInputAttributes=function(t,r){const i=n(t,t.length-1);e.updateInput(r,i)},e.addOutputAttributes=function(t,n){const i=r(t,t.length-1);e.updateOutput(n,i)},e.defaultVersionSetter=function(e,t){if(!jo(t)||t.length<4)throw new Error("Set Version: Invalid Transaction");return t.writeUInt32LE(e,0),t},e.defaultLocktimeSetter=function(e,t){if(!jo(t)||t.length<4)throw new Error("Set Locktime: Invalid Transaction");return t.writeUInt32LE(e,t.length-4),t}}(AG),Object.defineProperty(EK,"__esModule",{value:!0});const cG=CK,hG=SK,fG=kK,dG=AG;EK.Psbt=class{constructor(e){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:e}}static fromBase64(e,t){const n=ao.from(e,"base64");return this.fromBuffer(n,t)}static fromHex(e,t){const n=ao.from(e,"hex");return this.fromBuffer(n,t)}static fromBuffer(e,t){const n=hG.psbtFromBuffer(e,t),r=new this(n.globalMap.unsignedTx);return Object.assign(r,n),r}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return hG.psbtToBuffer(this)}updateGlobal(e){return dG.updateGlobal(e,this.globalMap),this}updateInput(e,t){const n=dG.checkForInput(this.inputs,e);return dG.updateInput(t,n),this}updateOutput(e,t){const n=dG.checkForOutput(this.outputs,e);return dG.updateOutput(t,n),this}addUnknownKeyValToGlobal(e){return dG.checkHasKey(e,this.globalMap.unknownKeyVals,dG.getEnumLength(fG.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(e),this}addUnknownKeyValToInput(e,t){const n=dG.checkForInput(this.inputs,e);return dG.checkHasKey(t,n.unknownKeyVals,dG.getEnumLength(fG.InputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(t),this}addUnknownKeyValToOutput(e,t){const n=dG.checkForOutput(this.outputs,e);return dG.checkHasKey(t,n.unknownKeyVals,dG.getEnumLength(fG.OutputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(t),this}addInput(e){this.globalMap.unsignedTx.addInput(e),this.inputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],n=this.inputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach((e=>this.addUnknownKeyValToInput(n,e))),dG.addInputAttributes(this.inputs,e),this}addOutput(e){this.globalMap.unsignedTx.addOutput(e),this.outputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],n=this.outputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach((e=>this.addUnknownKeyValToInput(n,e))),dG.addOutputAttributes(this.outputs,e),this}clearFinalizedInput(e){const t=dG.checkForInput(this.inputs,e);dG.inputCheckUncleanFinalized(e,t);for(const e of Object.keys(t))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(e)||delete t[e];return this}combine(...e){const t=cG.combine([this].concat(e));return Object.assign(this,t),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}},Object.defineProperty(BK,"__esModule",{value:!0}),BK.Psbt=void 0;const pG=EK,gG=ij,yG=AG,mG=AP,vG=RH,IG=UU,wG=hP,bG=dP,BG=ZH,EG={network:cP.bitcoin,maximumFeeRate:5e3};class CG{constructor(e={},t=new pG.Psbt(new xG)){this.data=t,this.opts=Object.assign({},EG,e),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},0===this.data.inputs.length&&this.setVersion(2);const n=(e,t,n,r)=>Object.defineProperty(e,t,{enumerable:n,writable:r});n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}static fromBase64(e,t={}){const n=ao.from(e,"base64");return this.fromBuffer(n,t)}static fromHex(e,t={}){const n=ao.from(e,"hex");return this.fromBuffer(n,t)}static fromBuffer(e,t={}){const n=pG.Psbt.fromBuffer(e,SG),r=new CG(t,n);return function(e,t){e.ins.forEach((e=>{HG(t,e)}))}(r.__CACHE.__TX,r.__CACHE),r}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(e){this.setVersion(e)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(e){this.setLocktime(e)}get txInputs(){return this.__CACHE.__TX.ins.map((e=>({hash:(0,vG.cloneBuffer)(e.hash),index:e.index,sequence:e.sequence})))}get txOutputs(){return this.__CACHE.__TX.outs.map((e=>{let t;try{t=(0,mG.fromOutputScript)(e.script,this.opts.network)}catch(e){}return{script:(0,vG.cloneBuffer)(e.script),value:e.value,address:t}}))}combine(...e){return this.data.combine(...e.map((e=>e.data))),this}clone(){const e=CG.fromBuffer(this.data.toBuffer());return e.opts=JSON.parse(JSON.stringify(this.opts)),e}setMaximumFeeRate(e){TG(e),this.opts.maximumFeeRate=e}setVersion(e){TG(e),RG(this.data.inputs,"setVersion");const t=this.__CACHE;return t.__TX.version=e,t.__EXTRACTED_TX=void 0,this}setLocktime(e){TG(e),RG(this.data.inputs,"setLocktime");const t=this.__CACHE;return t.__TX.locktime=e,t.__EXTRACTED_TX=void 0,this}setInputSequence(e,t){TG(t),RG(this.data.inputs,"setInputSequence");const n=this.__CACHE;if(n.__TX.ins.length<=e)throw new Error("Input index too high");return n.__TX.ins[e].sequence=t,n.__EXTRACTED_TX=void 0,this}addInputs(e){return e.forEach((e=>this.addInput(e))),this}addInput(e){if(arguments.length>1||!e||void 0===e.hash||void 0===e.index)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");RG(this.data.inputs,"addInput"),e.witnessScript&&rq(e.witnessScript);const t=this.__CACHE;this.data.addInput(e),HG(t,t.__TX.ins[t.__TX.ins.length-1]);const n=this.data.inputs.length-1,r=this.data.inputs[n];return r.nonWitnessUtxo&&WG(this.__CACHE,r,n),t.__FEE=void 0,t.__FEE_RATE=void 0,t.__EXTRACTED_TX=void 0,this}addOutputs(e){return e.forEach((e=>this.addOutput(e))),this}addOutput(e){if(arguments.length>1||!e||void 0===e.value||void 0===e.address&&void 0===e.script)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");RG(this.data.inputs,"addOutput");const{address:t}=e;if("string"==typeof t){const{network:n}=this.opts,r=(0,mG.toOutputScript)(t,n);e=Object.assign(e,{script:r})}const n=this.__CACHE;return this.data.addOutput(e),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(e){if(!this.data.inputs.every(kG))throw new Error("Not finalized");const t=this.__CACHE;if(e||function(e,t,n){const r=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),o=r*i;if(r>=n.maximumFeeRate)throw new Error(`Warning: You are paying around ${(o/1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}(this,t,this.opts),t.__EXTRACTED_TX)return t.__EXTRACTED_TX;const n=t.__TX.clone();return ZG(this.data.inputs,n,t,!0),n}getFeeRate(){return qG("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return qG("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,yG.checkForInput)(this.data.inputs,0),aq(this.data.inputs.length).forEach((e=>this.finalizeInput(e))),this}finalizeInput(e,t=VG){const n=(0,yG.checkForInput)(this.data.inputs,e),{script:r,isP2SH:i,isP2WSH:o,isSegwit:a}=function(e,t,n){const r=n.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const o=$G(n,t,e),a=r.ins[e].index;i.script=o.outs[a].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);return(t.witnessScript||PG(i.script))&&(i.isSegwit=!0),i}(e,n,this.__CACHE);if(!r)throw new Error(`No script found for input #${e}`);!function(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:n}=e;t.forEach((e=>{const{hashType:t}=bG.signature.decode(e.signature);if(n!==t)throw new Error("Signature sighash does not match input sighash type")}))}(n);const{finalScriptSig:s,finalScriptWitness:l}=t(e,n,r,a,i,o);if(s&&this.data.updateInput(e,{finalScriptSig:s}),l&&this.data.updateInput(e,{finalScriptWitness:l}),!s&&!l)throw new Error(`Unknown error finalizing input #${e}`);return this.data.clearFinalizedInput(e),this}getInputType(e){const t=(0,yG.checkForInput)(this.data.inputs,e),n=nq(eq(e,t,this.__CACHE),e,"input",t.redeemScript||function(e){if(!e)return;const t=bG.decompile(e);if(!t)return;const n=t[t.length-1];var r;if(jo(n)&&!tq(n)&&(r=n,!bG.isCanonicalScriptSignature(r))&&bG.decompile(n))return n}(t.finalScriptSig),t.witnessScript||function(e){if(!e)return;const t=XG(e),n=t[t.length-1];return!tq(n)&&bG.decompile(n)?n:void 0}(t.finalScriptWitness));return("raw"===n.type?"":n.type+"-")+oq(n.meaningfulScript)}inputHasPubkey(e,t){return function(e,t,n,r){const i=eq(n,t,r),{meaningfulScript:o}=nq(i,n,"input",t.redeemScript,t.witnessScript);return iq(e,o)}(t,(0,yG.checkForInput)(this.data.inputs,e),e,this.__CACHE)}inputHasHDKey(e,t){const n=(0,yG.checkForInput)(this.data.inputs,e),r=LG(t);return!!n.bip32Derivation&&n.bip32Derivation.some(r)}outputHasPubkey(e,t){return function(e,t,n,r){const i=r.__TX.outs[n].script,{meaningfulScript:o}=nq(i,n,"output",t.redeemScript,t.witnessScript);return iq(e,o)}(t,(0,yG.checkForOutput)(this.data.outputs,e),e,this.__CACHE)}outputHasHDKey(e,t){const n=(0,yG.checkForOutput)(this.data.outputs,e),r=LG(t);return!!n.bip32Derivation&&n.bip32Derivation.some(r)}validateSignaturesOfAllInputs(e){return(0,yG.checkForInput)(this.data.inputs,0),aq(this.data.inputs.length).map((t=>this.validateSignaturesOfInput(t,e))).reduce(((e,t)=>!0===t&&e),!0)}validateSignaturesOfInput(e,t,n){const r=this.data.inputs[e],i=(r||{}).partialSig;if(!r||!i||i.length<1)throw new Error("No signatures to validate");if("function"!=typeof t)throw new Error("Need validator function to validate signatures");const o=n?i.filter((e=>e.pubkey.equals(n))):i;if(o.length<1)throw new Error("No signatures for this pubkey");const a=[];let s,l,u;for(const n of o){const i=bG.signature.decode(n.signature),{hash:o,script:A}=u!==i.hashType?JG(e,Object.assign({},r,{sighashType:i.hashType}),this.__CACHE,!0):{hash:s,script:l};u=i.hashType,s=o,l=A,OG(n.pubkey,A,"verify"),a.push(t(n.pubkey,o,i.signature))}return a.every((e=>!0===e))}signAllInputsHD(e,t=[BG.Transaction.SIGHASH_ALL]){if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");const n=[];for(const r of aq(this.data.inputs.length))try{this.signInputHD(r,e,t),n.push(!0)}catch(e){n.push(!1)}if(n.every((e=>!1===e)))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(e,t=[BG.Transaction.SIGHASH_ALL]){return new Promise(((n,r)=>{if(!e||!e.publicKey||!e.fingerprint)return r(new Error("Need HDSigner to sign input"));const i=[],o=[];for(const n of aq(this.data.inputs.length))o.push(this.signInputHDAsync(n,e,t).then((()=>{i.push(!0)}),(()=>{i.push(!1)})));return Promise.all(o).then((()=>{if(i.every((e=>!1===e)))return r(new Error("No inputs were signed"));n()}))}))}signInputHD(e,t,n=[BG.Transaction.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");return YG(e,this.data.inputs,t).forEach((t=>this.signInput(e,t,n))),this}signInputHDAsync(e,t,n=[BG.Transaction.SIGHASH_ALL]){return new Promise(((r,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const o=YG(e,this.data.inputs,t).map((t=>this.signInputAsync(e,t,n)));return Promise.all(o).then((()=>{r()})).catch(i)}))}signAllInputs(e,t=[BG.Transaction.SIGHASH_ALL]){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");const n=[];for(const r of aq(this.data.inputs.length))try{this.signInput(r,e,t),n.push(!0)}catch(e){n.push(!1)}if(n.every((e=>!1===e)))throw new Error("No inputs were signed");return this}signAllInputsAsync(e,t=[BG.Transaction.SIGHASH_ALL]){return new Promise(((n,r)=>{if(!e||!e.publicKey)return r(new Error("Need Signer to sign input"));const i=[],o=[];for(const[n]of this.data.inputs.entries())o.push(this.signInputAsync(n,e,t).then((()=>{i.push(!0)}),(()=>{i.push(!1)})));return Promise.all(o).then((()=>{if(i.every((e=>!1===e)))return r(new Error("No inputs were signed"));n()}))}))}signInput(e,t,n=[BG.Transaction.SIGHASH_ALL]){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const{hash:r,sighashType:i}=zG(this.data.inputs,e,t.publicKey,this.__CACHE,n),o=[{pubkey:t.publicKey,signature:bG.signature.encode(t.sign(r),i)}];return this.data.updateInput(e,{partialSig:o}),this}signInputAsync(e,t,n=[BG.Transaction.SIGHASH_ALL]){return Promise.resolve().then((()=>{if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const{hash:r,sighashType:i}=zG(this.data.inputs,e,t.publicKey,this.__CACHE,n);return Promise.resolve(t.sign(r)).then((n=>{const r=[{pubkey:t.publicKey,signature:bG.signature.encode(n,i)}];this.data.updateInput(e,{partialSig:r})}))}))}toBuffer(){return QG(this.__CACHE),this.data.toBuffer()}toHex(){return QG(this.__CACHE),this.data.toHex()}toBase64(){return QG(this.__CACHE),this.data.toBase64()}updateGlobal(e){return this.data.updateGlobal(e),this}updateInput(e,t){return t.witnessScript&&rq(t.witnessScript),this.data.updateInput(e,t),t.nonWitnessUtxo&&WG(this.__CACHE,this.data.inputs[e],e),this}updateOutput(e,t){return this.data.updateOutput(e,t),this}addUnknownKeyValToGlobal(e){return this.data.addUnknownKeyValToGlobal(e),this}addUnknownKeyValToInput(e,t){return this.data.addUnknownKeyValToInput(e,t),this}addUnknownKeyValToOutput(e,t){return this.data.addUnknownKeyValToOutput(e,t),this}clearFinalizedInput(e){return this.data.clearFinalizedInput(e),this}}BK.Psbt=CG;const SG=e=>new xG(e);class xG{constructor(e=ao.from([2,0,0,0,0,0,0,0,0,0])){this.tx=BG.Transaction.fromBuffer(e),function(e){if(!e.ins.every((e=>e.script&&0===e.script.length&&e.witness&&0===e.witness.length)))throw new Error("Format Error: Transaction ScriptSigs are not empty")}(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(e){if(void 0===e.hash||void 0===e.index||!jo(e.hash)&&"string"!=typeof e.hash||"number"!=typeof e.index)throw new Error("Error adding input.");const t="string"==typeof e.hash?(0,vG.reverseBuffer)(ao.from(e.hash,"hex")):e.hash;this.tx.addInput(t,e.index,e.sequence)}addOutput(e){if(void 0===e.script||void 0===e.value||!jo(e.script)||"number"!=typeof e.value)throw new Error("Error adding output.");this.tx.addOutput(e.script,e.value)}toBuffer(){return this.tx.toBuffer()}}function QG(e){if(!1!==e.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function kG(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function _G(e){return t=>{try{return e({output:t}),!0}catch(e){return!1}}}const NG=_G(wG.p2ms),DG=_G(wG.p2pk),FG=_G(wG.p2pkh),PG=_G(wG.p2wpkh),UG=_G(wG.p2wsh),MG=_G(wG.p2sh);function LG(e){return t=>!!t.masterFingerprint.equals(e.fingerprint)&&!!e.derivePath(t.path).publicKey.equals(t.pubkey)}function TG(e){if("number"!=typeof e||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function RG(e,t){e.forEach((e=>{let n=!1,r=[];if(0===(e.partialSig||[]).length){if(!e.finalScriptSig&&!e.finalScriptWitness)return;r=function(e){const t=e.finalScriptSig&&bG.decompile(e.finalScriptSig)||[],n=e.finalScriptWitness&&bG.decompile(e.finalScriptWitness)||[];return t.concat(n).filter((e=>jo(e)&&bG.isCanonicalScriptSignature(e))).map((e=>({signature:e})))}(e)}else r=e.partialSig;if(r.forEach((e=>{const{hashType:r}=bG.signature.decode(e.signature),i=[];switch(r&BG.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&r){case BG.Transaction.SIGHASH_ALL:break;case BG.Transaction.SIGHASH_SINGLE:case BG.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}-1===i.indexOf(t)&&(n=!0)})),n)throw new Error("Can not modify transaction, signatures exist.")}))}function OG(e,t,n){if(!iq(e,t))throw new Error(`Can not ${n} for this input with the key ${e.toString("hex")}`)}function HG(e,t){const n=(0,vG.reverseBuffer)(ao.from(t.hash)).toString("hex")+":"+t.index;if(e.__TX_IN_CACHE[n])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[n]=1}function KG(e,t){return(n,r,i,o)=>{const a=e({redeem:{output:i}}).output;if(!r.equals(a))throw new Error(`${t} for ${o} #${n} doesn't match the scriptPubKey in the prevout`)}}const jG=KG(wG.p2sh,"Redeem script"),GG=KG(wG.p2wsh,"Witness script");function qG(e,t,n,r){if(!n.every(kG))throw new Error(`PSBT must be finalized to calculate ${t}`);if("__FEE_RATE"===e&&r.__FEE_RATE)return r.__FEE_RATE;if("__FEE"===e&&r.__FEE)return r.__FEE;let i,o=!0;return r.__EXTRACTED_TX?(i=r.__EXTRACTED_TX,o=!1):i=r.__TX.clone(),ZG(n,i,r,o),"__FEE_RATE"===e?r.__FEE_RATE:"__FEE"===e?r.__FEE:void 0}function VG(e,t,n,r,i,o){oq(n);throw new Error(`Can not finalize input #${e}`)}function zG(e,t,n,r,i){const o=(0,yG.checkForInput)(e,t),{hash:a,sighashType:s,script:l}=JG(t,o,r,!1,i);return OG(n,l,"sign"),{hash:a,sighashType:s}}function JG(e,t,n,r,i){const o=n.__TX,a=t.sighashType||BG.Transaction.SIGHASH_ALL;if(i&&i.indexOf(a)<0){const e=function(e){let t=e&BG.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&e){case BG.Transaction.SIGHASH_ALL:t+="SIGHASH_ALL";break;case BG.Transaction.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case BG.Transaction.SIGHASH_NONE:t+="SIGHASH_NONE"}return t}(a);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${e}`)}let s,l;if(t.nonWitnessUtxo){const r=$G(n,t,e),i=o.ins[e].hash,a=r.getHash();if(!i.equals(a))throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const s=o.ins[e].index;l=r.outs[s]}else{if(!t.witnessUtxo)throw new Error("Need a Utxo input item for signing");l=t.witnessUtxo}const{meaningfulScript:u,type:A}=nq(l.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(A)>=0)s=o.hashForWitnessV0(e,u,l.value,a);else if(PG(u)){const t=wG.p2pkh({hash:u.slice(2)}).output;s=o.hashForWitnessV0(e,t,l.value,a)}else{if(void 0===t.nonWitnessUtxo&&!1===n.__UNSAFE_SIGN_NONSEGWIT)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${u.toString("hex")}`);r||!1===n.__UNSAFE_SIGN_NONSEGWIT||console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecesor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),s=o.hashForSignature(e,u,a)}return{script:u,sighashType:a,hash:s}}function YG(e,t,n){const r=(0,yG.checkForInput)(t,e);if(!r.bip32Derivation||0===r.bip32Derivation.length)throw new Error("Need bip32Derivation to sign with HD");const i=r.bip32Derivation.map((e=>e.masterFingerprint.equals(n.fingerprint)?e:void 0)).filter((e=>!!e));if(0===i.length)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");const o=i.map((e=>{const t=n.derivePath(e.path);if(!e.pubkey.equals(t.publicKey))throw new Error("pubkey did not match bip32Derivation");return t}));return o}function XG(e){let t=0;function n(){const n=gG.decode(e,t);return t+=gG.decode.bytes,n}function r(){return r=n(),t+=r,e.slice(t-r,t);var r}return function(){const e=n(),t=[];for(let n=0;n<e;n++)t.push(r());return t}()}function WG(e,t,n){e.__NON_WITNESS_UTXO_BUF_CACHE[n]=t.nonWitnessUtxo;const r=BG.Transaction.fromBuffer(t.nonWitnessUtxo);e.__NON_WITNESS_UTXO_TX_CACHE[n]=r;const i=e,o=n;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const e=i.__NON_WITNESS_UTXO_BUF_CACHE[o],t=i.__NON_WITNESS_UTXO_TX_CACHE[o];if(void 0!==e)return e;{const e=t.toBuffer();return i.__NON_WITNESS_UTXO_BUF_CACHE[o]=e,e}},set(e){i.__NON_WITNESS_UTXO_BUF_CACHE[o]=e}})}function ZG(e,t,n,r){let i=0;e.forEach(((e,o)=>{if(r&&e.finalScriptSig&&(t.ins[o].script=e.finalScriptSig),r&&e.finalScriptWitness&&(t.ins[o].witness=XG(e.finalScriptWitness)),e.witnessUtxo)i+=e.witnessUtxo.value;else if(e.nonWitnessUtxo){const r=$G(n,e,o),a=t.ins[o].index,s=r.outs[a];i+=s.value}}));const o=t.outs.reduce(((e,t)=>e+t.value),0),a=i-o;if(a<0)throw new Error("Outputs are spending more than Inputs");const s=t.virtualSize();n.__FEE=a,n.__EXTRACTED_TX=t,n.__FEE_RATE=Math.floor(a/s)}function $G(e,t,n){const r=e.__NON_WITNESS_UTXO_TX_CACHE;return r[n]||WG(e,t,n),r[n]}function eq(e,t,n){if(void 0!==t.witnessUtxo)return t.witnessUtxo.script;if(void 0!==t.nonWitnessUtxo)return $G(n,t,e).outs[n.__TX.ins[e].index].script;throw new Error("Can't find pubkey in input without Utxo data")}function tq(e){return 33===e.length&&bG.isCanonicalPubKey(e)}function nq(e,t,n,r,i){const o=MG(e),a=o&&r&&UG(r),s=UG(e);if(o&&void 0===r)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((s||a)&&void 0===i)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let l;return a?(l=i,jG(t,e,r,n),GG(t,r,i,n),rq(l)):s?(l=i,GG(t,e,i,n),rq(l)):o?(l=r,jG(t,e,r,n)):l=e,{meaningfulScript:l,type:a?"p2sh-p2wsh":o?"p2sh":s?"p2wsh":"raw"}}function rq(e){if(PG(e)||MG(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function iq(e,t){const n=(0,IG.hash160)(e),r=bG.decompile(t);if(null===r)throw new Error("Unknown script error");return r.some((t=>"number"!=typeof t&&(t.equals(e)||t.equals(n))))}function oq(e){return PG(e)?"witnesspubkeyhash":FG(e)?"pubkeyhash":NG(e)?"multisig":DG(e)?"pubkey":"nonstandard"}function aq(e){return[...Array(e).keys()]}!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=AP;e.address=t;const n=UU;e.crypto=n;const r=cP;e.networks=r;const i=hP;e.payments=i;const o=dP;e.script=o;var a=TH;Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return a.Block}});var s=BK;Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return s.Psbt}});var l=gP;Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return l.OPS}});var u=ZH;Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}})}(uP);var sq={exports:{}};function lq(e,t){const n=(e=>{const t=(e=>{const t=aP.from(Object.assign(Object.assign({},e),{crv:"K-256"}),"jwk").toString("blk","public"),n=AC.publicKeyConvert(lP.from(t,"hex"),!0);return lP.from(n).toString("hex")})(e);let n=lP.from(t,"hex"),r=32-n.length;for(;r>0;)n=lP.concat([lP.from("00","hex"),n]),r--;return n})(e.publicKeyJwk),r=sD("errors","identityErrorBaseMessage");let i="";switch(t.code){case Ol.Bitcoin:case Ol.Mocknet:case Ol.Testnet:i=function(e,t){return uP.payments.p2pkh({pubkey:e,network:uP.networks[t.code]}).address}(n,t);break;case Ol.Ethmain:case Ol.Ethropst:case Ol.Ethrinkeby:case Ol.Ethgoerli:case Ol.Ethsepolia:i=function(e,t){const n=e.toString("hex"),r=new ww.ec("secp256k1").keyFromPublic(n,"hex").getPublic().encode("hex").slice(2),i=ao;return`0x${sq.exports.keccak256(i.from(r,"hex")).slice(24).toString()}`}(n);break;default:throw new iD("deriveIssuingAddressFromPublicKey",`${r} - ${sD("errors","deriveIssuingAddressFromPublicKey")}`)}return i}function uq(e){if(e){const t="string"==typeof e?e:e.code;return!!Object.keys(jl).some((e=>e===t))&&!!jl[t].test}return!1}!function(e){!function(){var t="input is invalid type",n="object"==typeof window,r=n?window:{};r.JS_SHA3_NO_WINDOW&&(n=!1);var i=!n&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof gu&&gu.versions&&gu.versions.node?r=Ki:i&&(r=self);var o=!r.JS_SHA3_NO_COMMON_JS&&e.exports,a=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,s="0123456789abcdef".split(""),l=[4,1024,262144,67108864],u=[0,8,16,24],A=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],c=[224,256,384,512],h=[128,256],f=["hex","buffer","arrayBuffer","array","digest"],d={128:168,256:136};!r.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!a||!r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer});for(var p=function(e,t,n){return function(r){return new _(e,t,e).update(r)[n]()}},g=function(e,t,n){return function(r,i){return new _(e,t,i).update(r)[n]()}},y=function(e,t,n){return function(t,r,i,o){return b["cshake"+e].update(t,r,i,o)[n]()}},m=function(e,t,n){return function(t,r,i,o){return b["kmac"+e].update(t,r,i,o)[n]()}},v=function(e,t,n,r){for(var i=0;i<f.length;++i){var o=f[i];e[o]=t(n,r,o)}return e},I=function(e,t){var n=p(e,t,"hex");return n.create=function(){return new _(e,t,e)},n.update=function(e){return n.create().update(e)},v(n,p,e,t)},w=[{name:"keccak",padding:[1,256,65536,16777216],bits:c,createMethod:I},{name:"sha3",padding:[6,1536,393216,100663296],bits:c,createMethod:I},{name:"shake",padding:[31,7936,2031616,520093696],bits:h,createMethod:function(e,t){var n=g(e,t,"hex");return n.create=function(n){return new _(e,t,n)},n.update=function(e,t){return n.create(t).update(e)},v(n,g,e,t)}},{name:"cshake",padding:l,bits:h,createMethod:function(e,t){var n=d[e],r=y(e,0,"hex");return r.create=function(r,i,o){return i||o?new _(e,t,r).bytepad([i,o],n):b["shake"+e].create(r)},r.update=function(e,t,n,i){return r.create(t,n,i).update(e)},v(r,y,e,t)}},{name:"kmac",padding:l,bits:h,createMethod:function(e,t){var n=d[e],r=m(e,0,"hex");return r.create=function(r,i,o){return new N(e,t,i).bytepad(["KMAC",o],n).bytepad([r],n)},r.update=function(e,t,n,i){return r.create(e,n,i).update(t)},v(r,m,e,t)}}],b={},B=[],E=0;E<w.length;++E)for(var C=w[E],S=C.bits,x=0;x<S.length;++x){var Q=C.name+"_"+S[x];if(B.push(Q),b[Q]=C.createMethod(S[x],C.padding),"sha3"!==C.name){var k=C.name+S[x];B.push(k),b[k]=b[Q]}}function _(e,t,n){this.blocks=[],this.s=[],this.padding=t,this.outputBits=n,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0}function N(e,t,n){_.call(this,e,t,n)}_.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var n,r=typeof e;if("string"!==r){if("object"!==r)throw new Error(t);if(null===e)throw new Error(t);if(a&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||a&&ArrayBuffer.isView(e)))throw new Error(t);n=!0}for(var i,o,s=this.blocks,l=this.byteCount,A=e.length,c=this.blockCount,h=0,f=this.s;h<A;){if(this.reset)for(this.reset=!1,s[0]=this.block,i=1;i<c+1;++i)s[i]=0;if(n)for(i=this.start;h<A&&i<l;++h)s[i>>2]|=e[h]<<u[3&i++];else for(i=this.start;h<A&&i<l;++h)(o=e.charCodeAt(h))<128?s[i>>2]|=o<<u[3&i++]:o<2048?(s[i>>2]|=(192|o>>6)<<u[3&i++],s[i>>2]|=(128|63&o)<<u[3&i++]):o<55296||o>=57344?(s[i>>2]|=(224|o>>12)<<u[3&i++],s[i>>2]|=(128|o>>6&63)<<u[3&i++],s[i>>2]|=(128|63&o)<<u[3&i++]):(o=65536+((1023&o)<<10|1023&e.charCodeAt(++h)),s[i>>2]|=(240|o>>18)<<u[3&i++],s[i>>2]|=(128|o>>12&63)<<u[3&i++],s[i>>2]|=(128|o>>6&63)<<u[3&i++],s[i>>2]|=(128|63&o)<<u[3&i++]);if(this.lastByteIndex=i,i>=l){for(this.start=i-l,this.block=s[c],i=0;i<c;++i)f[i]^=s[i];D(f),this.reset=!0}else this.start=i}return this},_.prototype.encode=function(e,t){var n=255&e,r=1,i=[n];for(n=255&(e>>=8);n>0;)i.unshift(n),n=255&(e>>=8),++r;return t?i.push(r):i.unshift(r),this.update(i),i.length},_.prototype.encodeString=function(e){var n,r=typeof e;if("string"!==r){if("object"!==r)throw new Error(t);if(null===e)throw new Error(t);if(a&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||a&&ArrayBuffer.isView(e)))throw new Error(t);n=!0}var i=0,o=e.length;if(n)i=o;else for(var s=0;s<e.length;++s){var l=e.charCodeAt(s);l<128?i+=1:l<2048?i+=2:l<55296||l>=57344?i+=3:(l=65536+((1023&l)<<10|1023&e.charCodeAt(++s)),i+=4)}return i+=this.encode(8*i),this.update(e),i},_.prototype.bytepad=function(e,t){for(var n=this.encode(t),r=0;r<e.length;++r)n+=this.encodeString(e[r]);var i=t-n%t,o=[];return o.length=i,this.update(o),this},_.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex,n=this.blockCount,r=this.s;if(e[t>>2]|=this.padding[3&t],this.lastByteIndex===this.byteCount)for(e[0]=e[n],t=1;t<n+1;++t)e[t]=0;for(e[n-1]|=2147483648,t=0;t<n;++t)r[t]^=e[t];D(r)}},_.prototype.toString=_.prototype.hex=function(){this.finalize();for(var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,o=0,a=0,l="";a<r;){for(o=0;o<t&&a<r;++o,++a)e=n[o],l+=s[e>>4&15]+s[15&e]+s[e>>12&15]+s[e>>8&15]+s[e>>20&15]+s[e>>16&15]+s[e>>28&15]+s[e>>24&15];a%t==0&&(D(n),o=0)}return i&&(e=n[o],l+=s[e>>4&15]+s[15&e],i>1&&(l+=s[e>>12&15]+s[e>>8&15]),i>2&&(l+=s[e>>20&15]+s[e>>16&15])),l},_.prototype.arrayBuffer=function(){this.finalize();var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,o=0,a=0,s=this.outputBits>>3;e=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(s);for(var l=new Uint32Array(e);a<r;){for(o=0;o<t&&a<r;++o,++a)l[a]=n[o];a%t==0&&D(n)}return i&&(l[o]=n[o],e=e.slice(0,s)),e},_.prototype.buffer=_.prototype.arrayBuffer,_.prototype.digest=_.prototype.array=function(){this.finalize();for(var e,t,n=this.blockCount,r=this.s,i=this.outputBlocks,o=this.extraBytes,a=0,s=0,l=[];s<i;){for(a=0;a<n&&s<i;++a,++s)e=s<<2,t=r[a],l[e]=255&t,l[e+1]=t>>8&255,l[e+2]=t>>16&255,l[e+3]=t>>24&255;s%n==0&&D(r)}return o&&(e=s<<2,t=r[a],l[e]=255&t,o>1&&(l[e+1]=t>>8&255),o>2&&(l[e+2]=t>>16&255)),l},N.prototype=new _,N.prototype.finalize=function(){return this.encode(this.outputBits,!0),_.prototype.finalize.call(this)};var D=function(e){var t,n,r,i,o,a,s,l,u,c,h,f,d,p,g,y,m,v,I,w,b,B,E,C,S,x,Q,k,_,N,D,F,P,U,M,L,T,R,O,H,K,j,G,q,V,z,J,Y,X,W,Z,$,ee,te,ne,re,ie,oe,ae,se,le,ue,Ae;for(r=0;r<48;r+=2)i=e[0]^e[10]^e[20]^e[30]^e[40],o=e[1]^e[11]^e[21]^e[31]^e[41],a=e[2]^e[12]^e[22]^e[32]^e[42],s=e[3]^e[13]^e[23]^e[33]^e[43],l=e[4]^e[14]^e[24]^e[34]^e[44],u=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],h=e[7]^e[17]^e[27]^e[37]^e[47],t=(f=e[8]^e[18]^e[28]^e[38]^e[48])^(a<<1|s>>>31),n=(d=e[9]^e[19]^e[29]^e[39]^e[49])^(s<<1|a>>>31),e[0]^=t,e[1]^=n,e[10]^=t,e[11]^=n,e[20]^=t,e[21]^=n,e[30]^=t,e[31]^=n,e[40]^=t,e[41]^=n,t=i^(l<<1|u>>>31),n=o^(u<<1|l>>>31),e[2]^=t,e[3]^=n,e[12]^=t,e[13]^=n,e[22]^=t,e[23]^=n,e[32]^=t,e[33]^=n,e[42]^=t,e[43]^=n,t=a^(c<<1|h>>>31),n=s^(h<<1|c>>>31),e[4]^=t,e[5]^=n,e[14]^=t,e[15]^=n,e[24]^=t,e[25]^=n,e[34]^=t,e[35]^=n,e[44]^=t,e[45]^=n,t=l^(f<<1|d>>>31),n=u^(d<<1|f>>>31),e[6]^=t,e[7]^=n,e[16]^=t,e[17]^=n,e[26]^=t,e[27]^=n,e[36]^=t,e[37]^=n,e[46]^=t,e[47]^=n,t=c^(i<<1|o>>>31),n=h^(o<<1|i>>>31),e[8]^=t,e[9]^=n,e[18]^=t,e[19]^=n,e[28]^=t,e[29]^=n,e[38]^=t,e[39]^=n,e[48]^=t,e[49]^=n,p=e[0],g=e[1],z=e[11]<<4|e[10]>>>28,J=e[10]<<4|e[11]>>>28,k=e[20]<<3|e[21]>>>29,_=e[21]<<3|e[20]>>>29,se=e[31]<<9|e[30]>>>23,le=e[30]<<9|e[31]>>>23,j=e[40]<<18|e[41]>>>14,G=e[41]<<18|e[40]>>>14,U=e[2]<<1|e[3]>>>31,M=e[3]<<1|e[2]>>>31,y=e[13]<<12|e[12]>>>20,m=e[12]<<12|e[13]>>>20,Y=e[22]<<10|e[23]>>>22,X=e[23]<<10|e[22]>>>22,N=e[33]<<13|e[32]>>>19,D=e[32]<<13|e[33]>>>19,ue=e[42]<<2|e[43]>>>30,Ae=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,L=e[14]<<6|e[15]>>>26,T=e[15]<<6|e[14]>>>26,v=e[25]<<11|e[24]>>>21,I=e[24]<<11|e[25]>>>21,W=e[34]<<15|e[35]>>>17,Z=e[35]<<15|e[34]>>>17,F=e[45]<<29|e[44]>>>3,P=e[44]<<29|e[45]>>>3,C=e[6]<<28|e[7]>>>4,S=e[7]<<28|e[6]>>>4,re=e[17]<<23|e[16]>>>9,ie=e[16]<<23|e[17]>>>9,R=e[26]<<25|e[27]>>>7,O=e[27]<<25|e[26]>>>7,w=e[36]<<21|e[37]>>>11,b=e[37]<<21|e[36]>>>11,$=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,q=e[8]<<27|e[9]>>>5,V=e[9]<<27|e[8]>>>5,x=e[18]<<20|e[19]>>>12,Q=e[19]<<20|e[18]>>>12,oe=e[29]<<7|e[28]>>>25,ae=e[28]<<7|e[29]>>>25,H=e[38]<<8|e[39]>>>24,K=e[39]<<8|e[38]>>>24,B=e[48]<<14|e[49]>>>18,E=e[49]<<14|e[48]>>>18,e[0]=p^~y&v,e[1]=g^~m&I,e[10]=C^~x&k,e[11]=S^~Q&_,e[20]=U^~L&R,e[21]=M^~T&O,e[30]=q^~z&Y,e[31]=V^~J&X,e[40]=te^~re&oe,e[41]=ne^~ie&ae,e[2]=y^~v&w,e[3]=m^~I&b,e[12]=x^~k&N,e[13]=Q^~_&D,e[22]=L^~R&H,e[23]=T^~O&K,e[32]=z^~Y&W,e[33]=J^~X&Z,e[42]=re^~oe&se,e[43]=ie^~ae&le,e[4]=v^~w&B,e[5]=I^~b&E,e[14]=k^~N&F,e[15]=_^~D&P,e[24]=R^~H&j,e[25]=O^~K&G,e[34]=Y^~W&$,e[35]=X^~Z&ee,e[44]=oe^~se&ue,e[45]=ae^~le&Ae,e[6]=w^~B&p,e[7]=b^~E&g,e[16]=N^~F&C,e[17]=D^~P&S,e[26]=H^~j&U,e[27]=K^~G&M,e[36]=W^~$&q,e[37]=Z^~ee&V,e[46]=se^~ue&te,e[47]=le^~Ae&ne,e[8]=B^~p&y,e[9]=E^~g&m,e[18]=F^~C&x,e[19]=P^~S&Q,e[28]=j^~U&L,e[29]=G^~M&T,e[38]=$^~q&z,e[39]=ee^~V&J,e[48]=ue^~te&re,e[49]=Ae^~ne&ie,e[0]^=A[r],e[1]^=A[r+1]};if(o)e.exports=b;else for(E=0;E<B.length;++E)r[B[E]]=b[B[E]]}()}(sq);var Aq=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){e.done?i(e.value):function(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(a,s)}l((r=r.apply(e,t||[])).next())}))};const{LinkedDataProof:cq}=JN.suites;class hq extends cq{constructor({issuer:e=null,verificationMethod:t=null,document:n=null,proof:r=null,options:i={}}){if(super({type:"MerkleProof2019"}),this.type="MerkleProof2019",this.issuer=null,this.verificationMethod=null,this.proof=null,this.proofValue=null,this.document=null,this.explorerAPIs=[],this.documentLoader=null,this.proofVerificationProcess=["getTransactionId","computeLocalHash","fetchRemoteHash","compareHashes","checkMerkleRoot","checkReceipt"],this.identityVerificationProcess=["deriveIssuingAddressFromPublicKey","compareIssuingAddress"],this.transactionId="",!n)throw new Error("A document signed by MerkleProof2019 is required for the verification process.");this.issuer=e,this.verificationMethod=t,this.document=n,this.setProof(r),this.setOptions(i),this.getChain(),uq(this.chain)&&(this.adaptProofVerificationProcessToMocknet(),this.adaptIdentityVerificationProcessToMocknet())}static decodeMerkleProof2019(e){return new Z_(e.proofValue).decode()}setProof(e=null){const t=null!=e?e:this.document.proof;if(!t)throw new Error("The passed document is not signed.");this.proof=t,this.proofValue=hq.decodeMerkleProof2019(this.proof)}verifyProof({documentLoader:e,verifyIdentity:t}={documentLoader:e=>{},verifyIdentity:!0}){return Aq(this,void 0,void 0,(function*(){let n;this.documentLoader=e;let r="";try{yield this.verifyProcess(this.proofVerificationProcess),t&&(yield this.verifyIdentity()),n=!0}catch(e){console.error(e),n=!1,r=e.message}return{verificationMethod:this.verificationMethod,verified:n,error:r}}))}verifyIdentity(){return Aq(this,void 0,void 0,(function*(){if(null!=this.verificationMethod)try{yield this.verifyProcess(this.identityVerificationProcess)}catch(e){throw new Error(e)}}))}getProofVerificationProcess(){return this.proofVerificationProcess}getIdentityVerificationProcess(){return this.identityVerificationProcess}getIssuerPublicKey(){var e,t;return uq(this.chain)?"This mock chain does not support issuing addresses":null!==(t=null===(e=this.getTxData())||void 0===e?void 0:e.issuingAddress)&&void 0!==t?t:""}getIssuanceTime(){var e,t;return null!==(t=null===(e=this.getTxData())||void 0===e?void 0:e.time)&&void 0!==t?t:""}getChain(){return this.chain||(this.chain=function(e=null){if(null==e?void 0:e.anchors){const{anchors:t}=e,n=t[0];if("string"==typeof n)return function(e){const t=e.split(":");let n;switch(t[1]){case jl.mocknet.blinkCode:return ZN(jl.mocknet.signatureValue);case jl.bitcoin.blinkCode:n=jl.bitcoin.name;break;case jl.ethmain.blinkCode:n=jl.ethmain.name;break;default:throw new Error("Could not retrieve chain.")}const r=t[2],i=n.toLowerCase()+function(e){const t=e.substr(0,1),n=e.substr(1,e.length-1);return t.toUpperCase()+n.toLowerCase()}(r);return ZN(i)}(n)}return null}(this.proofValue)),this.chain}getTxData(){return this.txData?this.txData:(console.error("Trying to access issuing address when txData not available yet. Did you run the `verify` method yet?"),null)}adaptProofVerificationProcessToMocknet(){$N(this.proofVerificationProcess,"getTransactionId"),$N(this.proofVerificationProcess,"fetchRemoteHash"),$N(this.proofVerificationProcess,"checkMerkleRoot")}adaptIdentityVerificationProcessToMocknet(){this.identityVerificationProcess=[]}setOptions(e){var t;this.explorerAPIs=null!==(t=e.explorerAPIs)&&void 0!==t?t:[],e.executeStepMethod&&"function"==typeof e.executeStepMethod&&(this.executeStep=e.executeStepMethod)}executeStep(e,t,n=""){return Aq(this,void 0,void 0,(function*(){return yield t()}))}verifyProcess(e){return Aq(this,void 0,void 0,(function*(){for(const t of e){if(!this[t])return void console.error("verification logic for",t,"not implemented");yield this[t]()}}))}checkMerkleRoot(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("checkMerkleRoot",(()=>function(e,t){if(e!==t)throw new iD("checkMerkleRoot",sD("errors","ensureMerkleRootEqual"));return!0}(this.proofValue.merkleRoot,this.txData.remoteHash)),this.type)}))}compareHashes(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("compareHashes",(()=>function(e,t){if(e!==t)throw new iD("compareHashes",sD("errors","ensureHashesEqual"));return!0}(this.localDocumentHash,this.proofValue.targetHash)),this.type)}))}computeLocalHash(){return Aq(this,void 0,void 0,(function*(){this.localDocumentHash=yield this.executeStep("computeLocalHash",(()=>Aq(this,void 0,void 0,(function*(){return yield function(e,t=null,n=(e=>{})){return lD(this,void 0,void 0,(function*(){e["@context"].find((e=>{return(t=e)===Object(t)&&"@vocab"in e;var t}))||e["@context"].push({"@vocab":"http://fallback.org/"});const r=JSON.parse(JSON.stringify(e));if(Array.isArray(r.proof)){if(!t)throw new iD("computeLocalHash",sD("errors","noProofSpecified"));const e=r.proof.findIndex((e=>e.proofValue===t.proofValue));r.proof=r.proof.slice(0,e)}else delete r.proof;const i={algorithm:"URDNA2015",format:"application/nquads",documentLoader:function(e){return lD(this,void 0,void 0,(function*(){return null!=n&&(yield n(e)),e in jh?{contextUrl:null,document:jh[e],documentUrl:e}:ov.documentLoader(e)}))}};let o;try{o=yield ov.normalize(r,i)}catch(e){throw console.error(e),new iD("computeLocalHash",sD("errors","failedJsonLdNormalization"))}const a=function(e){const t=e.split("\n"),n=/<http:\/\/fallback\.org\/(.*)>/,r=t.map((e=>n.exec(e))).filter((e=>null!=e));if(r.length>0){const e=r.map((e=>e[1])).sort();return Array.from(new Set(e))}return null}(o);if(a)throw new iD("computeLocalHash",`${sD("errors","foundUnmappedFields")}: ${a.join(", ")}`);return lS(function(e){const t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r<128?t.push(r):r<2048?t.push(192|r>>6,128|63&r):r<55296||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}(o))}))}(this.document,this.proof,this.documentLoader)}))),this.type)}))}checkReceipt(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("checkReceipt",(()=>function(e){let t=e.targetHash;const n=e.merkleRoot;try{const n=e.path;if(n&&t)for(const e in n){const r=n[e];let i;if(void 0!==r.left)i=rD(`${r.left}${t}`),t=lS(i);else{if(void 0===r.right)throw new iD("checkReceipt","Trigger catch error.");i=rD(`${t}${r.right}`),t=lS(i)}}}catch(e){throw new iD("checkReceipt",sD("errors","ensureValidReceipt"))}if(t!==n)throw new iD("checkReceipt",sD("errors","invalidMerkleReceipt"))}(this.proofValue)),this.type)}))}getTransactionId(){return Aq(this,void 0,void 0,(function*(){return this.transactionId=function(e=null){if(!e)throw new Error("DecodedProof is not set");const{anchors:t}=e,n=t[0];if("string"==typeof n)return n.split(":").pop();throw new Error("Could not retrieve transaction id as was provided an unexpected format")}(this.proofValue),yield this.executeStep("getTransactionId",(()=>function(e){if("string"==typeof e&&e.length>0)return e;throw new iD("getTransactionId",sD("errors","isTransactionIdValid"))}(this.transactionId)),this.type)}))}fetchRemoteHash(){return Aq(this,void 0,void 0,(function*(){this.txData=yield this.executeStep("fetchRemoteHash",(()=>Aq(this,void 0,void 0,(function*(){var e;return yield Lh({transactionId:this.transactionId,chain:null===(e=this.chain)||void 0===e?void 0:e.code,explorerAPIs:this.explorerAPIs})}))),this.type)}))}deriveIssuingAddressFromPublicKey(){return Aq(this,void 0,void 0,(function*(){this.derivedIssuingAddress=yield this.executeStep("deriveIssuingAddressFromPublicKey",(()=>lq(this.verificationMethod,this.chain)),this.type)}))}compareIssuingAddress(){return Aq(this,void 0,void 0,(function*(){yield this.executeStep("compareIssuingAddress",(()=>function(e,t){const n=sD("errors","identityErrorBaseMessage");if(e!==t)throw new iD("compareIssuingAddress",`${n} - ${sD("errors","compareIssuingAddress")}`)}(this.getIssuerPublicKey(),this.derivedIssuingAddress)),this.type)}))}}class fq{constructor(e){}}function dq(e){return Array.isArray(e)?e.find((e=>"ChainedProof2021"!==e.type)).verificationMethod:e.verificationMethod}var pq,gq;!function(e){e.getTransactionId="getTransactionId",e.computeLocalHash="computeLocalHash",e.fetchRemoteHash="fetchRemoteHash",e.parseIssuerKeys="parseIssuerKeys",e.compareHashes="compareHashes",e.checkImagesIntegrity="checkImagesIntegrity",e.checkMerkleRoot="checkMerkleRoot",e.checkReceipt="checkReceipt",e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.deriveIssuingAddressFromPublicKey="deriveIssuingAddressFromPublicKey",e.compareIssuingAddress="compareIssuingAddress",e.checkAuthenticity="checkAuthenticity"}(pq||(pq={}));class yq extends fq{proofVerificationProcess=[pq.parseIssuerKeys,pq.checkAuthenticity];transactionId;localHash;documentToVerify;txData;chain;explorerAPIs;receipt;issuerPublicKeyList;issuer;verificationMethodPublicKey;derivedIssuingAddress;hasDid;proof;type="MerkleProof2019";suite;constructor(e){var t;super(e),this.executeStep=e.executeStep,this.documentToVerify=e.document,this.explorerAPIs=e.explorerAPIs,this.proof=e.proof,this.issuer=e.issuer,this.validateProofType(),this.receipt=(t=this.proof,hq.decodeMerkleProof2019(t)),this.transactionId=zC.certificates.getTransactionId(this.receipt),this.setHasDid()}async init(){await this.setVerificationSuite(),this.chain=this.suite.getChain(),this.adaptVerificationProcessToChain()}async verifyProof(){await this.suite.verifyProof({verifyIdentity:!1}),await this.verifyProcess(this.proofVerificationProcess)}async verifyIdentity(){await this.suite.verifyIdentity()}getProofVerificationSteps(e){return[...this.suite.getProofVerificationProcess(),...this.proofVerificationProcess].map((t=>zC.verifier.convertToVerificationSubsteps(e,t)))}getIdentityVerificationSteps(e){return this.hasDid?this.suite.getIdentityVerificationProcess().map((t=>zC.verifier.convertToVerificationSubsteps(e,t))):[]}getIssuerPublicKey(){return this.suite.getIssuerPublicKey()}getIssuanceTime(){return this.suite.getIssuanceTime()}getIssuerName(){return this.issuer.name}getIssuerProfileDomain(){return new URL(this.getIssuerProfileUrl())?.hostname}getIssuerProfileUrl(){return this.issuer.id}getSigningDate(){return this.proof.created}getChain(){return this.suite.getChain()}getReceipt(){return this.receipt}getTransactionIdString(){return zC.certificates.getTransactionId(this.getReceipt())}getTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).transactionLink}getRawTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).rawTransactionLink}async executeStep(e,t,n){throw new Error("executeStep method needs to be overwritten by injecting from Verifier")}async setVerificationSuite(){await this.setIssuerFromProofVerificationMethod(),this.verificationMethodPublicKey=gS(this.getTargetVerificationMethodContainer(),dq(this.proof)),this.suite=new hq({document:this.documentToVerify,proof:this.proof,verificationMethod:this.verificationMethodPublicKey,options:{explorerAPIs:this.explorerAPIs,executeStepMethod:this.executeStep}})}adaptVerificationProcessToChain(){zC.chains.isMockChain(this.chain)&&(sf(this.proofVerificationProcess,pq.parseIssuerKeys),sf(this.proofVerificationProcess,pq.checkAuthenticity))}getTargetVerificationMethodContainer(){return this.issuer.didDocument??this.issuer}isProofChain(){return"ChainedProof2021"===this.proof.type}async setIssuerFromProofVerificationMethod(){if(this.isProofChain()){const e=this.proof.verificationMethod.split("#")[0];this.issuer=await zC.verifier.getIssuerProfile(e)}}setHasDid(){if(this.isProofChain()){const e=this.proof.verificationMethod.split("#")[0];this.hasDid=df(e)}else this.hasDid=!!this.issuer.didDocument}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}async verifyProcess(e){for(const t of e){if(!this[t])return void console.error("verification logic for",t,"not implemented");await this[t]()}}async parseIssuerKeys(){this.issuerPublicKeyList=await this.executeStep(pq.parseIssuerKeys,(()=>zC.verifier.parseIssuerKeys(this.issuer)),this.type)}async checkAuthenticity(){await this.executeStep(pq.checkAuthenticity,(()=>dS(this.issuerPublicKeyList,this.getIssuerPublicKey(),this.getIssuanceTime())),this.type)}}!function(e){e.getTransactionId="getTransactionId",e.computeLocalHash="computeLocalHash",e.fetchRemoteHash="fetchRemoteHash",e.parseIssuerKeys="parseIssuerKeys",e.compareHashes="compareHashes",e.checkMerkleRoot="checkMerkleRoot",e.checkReceipt="checkReceipt",e.checkAuthenticity="checkAuthenticity"}(gq||(gq={}));class mq extends fq{verificationProcess=[gq.getTransactionId,gq.computeLocalHash,gq.fetchRemoteHash,gq.compareHashes,gq.checkMerkleRoot,gq.checkReceipt,gq.parseIssuerKeys,gq.checkAuthenticity];transactionId;localHash;documentToVerify;txData;chain;explorerAPIs;receipt;issuerPublicKeyList;issuer;proof;type="MerkleProof2017";constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.explorerAPIs=e.explorerAPIs,this.issuer=e.issuer,this.proof=e.proof,this.validateProofType(),this.receipt=this.documentToVerify.signature,this.chain=zC.certificates.getChain("",this.receipt),this.transactionId=zC.certificates.getTransactionId(this.receipt),this.adaptVerificationProcessToChain()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(e){return this.verificationProcess.map((t=>zC.verifier.convertToVerificationSubsteps(e,t)))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return zC.chains.isMockChain(this.chain)?"This mock chain does not support issuing addresses":this.txData?this.txData.issuingAddress:void console.error("Trying to access issuing address when txData not available yet. Did you run the `verify` method yet?")}getIssuerName(){return this.issuer.name}getIssuerProfileDomain(){return new URL(this.getIssuerProfileUrl())?.hostname}getIssuerProfileUrl(){return this.issuer.id}getSigningDate(){return this.documentToVerify.issuedOn}getChain(){return this.chain}getReceipt(){return this.receipt}getTransactionIdString(){return zC.certificates.getTransactionId(this.getReceipt())}getTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).transactionLink}getRawTransactionLink(){return zC.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).rawTransactionLink}validateProofType(){if(this.proof.type[0]!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${this.proof.type[0]}`)}adaptVerificationProcessToChain(){zC.chains.isMockChain(this.chain)&&(sf(this.verificationProcess,gq.getTransactionId),sf(this.verificationProcess,gq.fetchRemoteHash),sf(this.verificationProcess,gq.parseIssuerKeys),sf(this.verificationProcess,gq.checkMerkleRoot),sf(this.verificationProcess,gq.checkAuthenticity))}async executeStep(e,t,n){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async getTransactionId(){await this.executeStep(gq.getTransactionId,(()=>function(e){if("string"==typeof e&&e.length>0)return e;throw new tf("getTransactionId",Wh("errors","isTransactionIdValid"))}(this.transactionId)),this.type)}async computeLocalHash(){this.localHash=await this.executeStep(gq.computeLocalHash,(async()=>await fS(this.documentToVerify)),this.type)}async fetchRemoteHash(){this.txData=await this.executeStep(gq.fetchRemoteHash,(async()=>await zC.verifier.lookForTx({transactionId:this.transactionId,chain:this.chain.code,explorerAPIs:this.explorerAPIs})),this.type)}async compareHashes(){await this.executeStep(gq.compareHashes,(()=>function(e,t){if(e!==t)throw new tf("compareHashes",Wh("errors","ensureHashesEqual"));return!0}(this.localHash,this.receipt.targetHash)),this.type)}async checkMerkleRoot(){await this.executeStep(gq.checkMerkleRoot,(()=>function(e,t){if(e!==t)throw new tf("checkMerkleRoot",Wh("errors","ensureMerkleRootEqual"));return!0}(this.receipt.merkleRoot,this.txData.remoteHash)),this.type)}async checkReceipt(){await this.executeStep(gq.checkReceipt,(()=>function(e){let t=e.targetHash;const n=e.merkleRoot;try{const n=e.proof||e.path;if(n)for(const e in n){const r=n[e];let i;if(void 0!==r.left)i=uS(`${r.left}${t}`),t=lS(i);else{if(void 0===r.right)throw new tf("checkReceipt","Trigger catch error.");i=uS(`${t}${r.right}`),t=lS(i)}}}catch(e){throw new tf("checkReceipt",Wh("errors","ensureValidReceipt"))}if(t!==n)throw new tf("checkReceipt",Wh("errors","invalidMerkleReceipt"))}(this.receipt)),this.type)}async parseIssuerKeys(){this.issuerPublicKeyList=await this.executeStep(gq.parseIssuerKeys,(()=>zC.verifier.parseIssuerKeys(this.issuer)),this.type)}async checkAuthenticity(){await this.executeStep(gq.checkAuthenticity,(()=>dS(this.issuerPublicKeyList,this.txData.issuingAddress,this.txData.time)),this.type)}}const vq={};function Iq(e,t){return function(e,t,n){if(!(e instanceof Uint8Array))throw new TypeError('"input" must be a Uint8Array.');if(void 0!==n&&"number"!=typeof n)throw new TypeError('"maxline" must be a number.');if(0===e.length)return"";let r="",i=0;const o=t.length,a=t.charAt(0),s=[0];for(i=0;i<e.length;++i){let t=e[i];for(let e=0;e<s.length;++e)t+=s[e]<<8,s[e]=t%o,t=t/o|0;for(;t>0;)s.push(t%o),t=t/o|0}for(i=0;0===e[i]&&i<e.length-1;++i)r+=a;for(i=s.length-1;i>=0;--i)r+=t[s[i]];if(n){const e=new RegExp(".{1,"+n+"}","g");r=r.match(e).join("\r\n")}return r}(e,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",t)}function wq(e){return function(e,t){if("string"!=typeof e)throw new TypeError('"input" must be a string.');if(0===e.length)return new Uint8Array;let n=vq[t];if(!n){n=vq[t]=[];for(let e=0;e<t.length;++e)n[t.charCodeAt(e)]=e}e=e.replace(/\s/g,"");const r=t.length,i=t.charAt(0),o=[0];for(let t=0;t<e.length;t++){const i=n[e.charCodeAt(t)];if(void 0===i)return;let a=i;for(let e=0;e<o.length;++e)a+=o[e]*r,o[e]=255&a,a>>=8;for(;a>0;)o.push(255&a),a>>=8}for(let t=0;e[t]===i&&t<e.length-1;++t)o.push(0);return new Uint8Array(o.reverse())}
|
|
638
638
|
/*!
|
|
639
639
|
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
640
640
|
*/(e,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")}
|