var PWW=(()=>{var kc=Object.create;var qr=Object.defineProperty;var Tc=Object.getOwnPropertyDescriptor;var Ic=Object.getOwnPropertyNames;var Uc=Object.getPrototypeOf,Lc=Object.prototype.hasOwnProperty;var Nc=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Vi=(t,e)=>{for(var r in e)qr(t,r,{get:e[r],enumerable:!0})},zi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ic(e))!Lc.call(t,o)&&o!==r&&qr(t,o,{get:()=>e[o],enumerable:!(n=Tc(e,o))||n.enumerable});return t};var Cc=(t,e,r)=>(r=t!=null?kc(Uc(t)):{},zi(e||!t||!t.__esModule?qr(r,"default",{value:t,enumerable:!0}):r,t)),_c=t=>zi(qr({},"__esModule",{value:!0}),t);var vc=Nc((xc,Ec)=>{var mc=function(){var t=function(m,b){var v=236,x=17,w=m,B=r[b],g=null,d=0,C=null,k=[],T={},D=function(P,_){d=w*4+17,g=function(U){for(var R=new Array(U),H=0;H=7&&M(P),C==null&&(C=it(w,B,k)),j(C,_)},S=function(P,_){for(var U=-1;U<=7;U+=1)if(!(P+U<=-1||d<=P+U))for(var R=-1;R<=7;R+=1)_+R<=-1||d<=_+R||(0<=U&&U<=6&&(R==0||R==6)||0<=R&&R<=6&&(U==0||U==6)||2<=U&&U<=4&&2<=R&&R<=4?g[P+U][_+R]=!0:g[P+U][_+R]=!1)},I=function(){for(var P=0,_=0,U=0;U<8;U+=1){D(!0,U);var R=o.getLostPoint(T);(U==0||P>R)&&(P=R,_=U)}return _},L=function(){for(var P=8;P>U&1)==1;g[Math.floor(U/3)][U%3+d-8-3]=R}for(var U=0;U<18;U+=1){var R=!P&&(_>>U&1)==1;g[U%3+d-8-3][Math.floor(U/3)]=R}},W=function(P,_){for(var U=B<<3|_,R=o.getBCHTypeInfo(U),H=0;H<15;H+=1){var O=!P&&(R>>H&1)==1;H<6?g[H][8]=O:H<8?g[H+1][8]=O:g[d-15+H][8]=O}for(var H=0;H<15;H+=1){var O=!P&&(R>>H&1)==1;H<8?g[8][d-H-1]=O:H<9?g[8][15-H-1+1]=O:g[8][15-H-1]=O}g[d-8][8]=!P},j=function(P,_){for(var U=-1,R=d-1,H=7,O=0,q=o.getMaskFunction(_),K=d-1;K>0;K-=2)for(K==6&&(K-=1);;){for(var G=0;G<2;G+=1)if(g[R][K-G]==null){var Z=!1;O>>H&1)==1);var V=q(R,K-G);V&&(Z=!Z),g[R][K-G]=Z,H-=1,H==-1&&(O+=1,H=7)}if(R+=U,R<0||d<=R){R-=U,U=-U;break}}},Y=function(P,_){for(var U=0,R=0,H=0,O=new Array(_.length),q=new Array(_.length),K=0;K<_.length;K+=1){var G=_[K].dataCount,Z=_[K].totalCount-G;R=Math.max(R,G),H=Math.max(H,Z),O[K]=new Array(G);for(var V=0;V=0?Ki.getAt(qi):0}}for(var Wi=0,V=0;V<_.length;V+=1)Wi+=_[V].totalCount;for(var Fn=new Array(Wi),Kr=0,V=0;VK*8)throw"code length overflow. ("+H.getLengthInBits()+">"+K*8+")";for(H.getLengthInBits()+4<=K*8&&H.put(0,4);H.getLengthInBits()%8!=0;)H.putBit(!1);for(;!(H.getLengthInBits()>=K*8||(H.put(v,8),H.getLengthInBits()>=K*8));)H.put(x,8);return Y(H,R)};T.addData=function(P,_){_=_||"Byte";var U=null;switch(_){case"Numeric":U=f(P);break;case"Alphanumeric":U=h(P);break;case"Byte":U=u(P);break;case"Kanji":U=l(P);break;default:throw"mode:"+_}k.push(U),C=null},T.isDark=function(P,_){if(P<0||d<=P||_<0||d<=_)throw P+","+_;return g[P][_]},T.getModuleCount=function(){return d},T.make=function(){if(w<1){for(var P=1;P<40;P++){for(var _=a.getRSBlocks(P,B),U=c(),R=0;R"u"?P*4:_;var U="";U+='";for(var H=0;H';U+=""}return U+="",U+="
",U},T.createSvgTag=function(P,_,U,R){var H={};typeof arguments[0]=="object"&&(H=arguments[0],P=H.cellSize,_=H.margin,U=H.alt,R=H.title),P=P||2,_=typeof _>"u"?P*4:_,U=typeof U=="string"?{text:U}:U||{},U.text=U.text||null,U.id=U.text?U.id||"qrcode-description":null,R=typeof R=="string"?{text:R}:R||{},R.text=R.text||null,R.id=R.text?R.id||"qrcode-title":null;var O=T.getModuleCount()*P+_*2,q,K,G,Z,V="",_t;for(_t="l"+P+",0 0,"+P+" -"+P+",0 0,-"+P+"z ",V+=''+X(R.text)+"":"",V+=U.text?''+X(U.text)+"":"",V+='',V+='"u"?P*4:_;var U=T.getModuleCount()*P+_*2,R=_,H=U-_;return A(U,U,function(O,q){if(R<=O&&O"u"?P*4:_;var R=T.getModuleCount()*P+_*2,H="";return H+="",H};var X=function(P){for(var _="",U=0;U":_+=">";break;case"&":_+="&";break;case'"':_+=""";break;default:_+=R;break}}return _},F=function(P){var _=1;P=typeof P>"u"?_*2:P;var U=T.getModuleCount()*_+P*2,R=P,H=U-P,O,q,K,G,Z,V={"\u2588\u2588":"\u2588","\u2588 ":"\u2580"," \u2588":"\u2584"," ":" "},_t={"\u2588\u2588":"\u2580","\u2588 ":"\u2580"," \u2588":" "," ":" "},Pt="";for(O=0;O=H?_t[Z]:V[Z];Pt+=` `}return U%2&&P>0?Pt.substring(0,Pt.length-U-1)+Array(U+1).join("\u2580"):Pt.substring(0,Pt.length-1)};return T.createASCII=function(P,_){if(P=P||1,P<2)return F(_);P-=1,_=typeof _>"u"?P*2:_;var U=T.getModuleCount()*P+_*2,R=_,H=U-_,O,q,K,G,Z=Array(P+1).join("\u2588\u2588"),V=Array(P+1).join(" "),_t="",Pt="";for(O=0;O>>8),B.push(C&255)):B.push(x)}}return B}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},r={L:1,M:0,Q:3,H:2},n={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},o=function(){var m=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],b=1335,v=7973,x=21522,w={},B=function(g){for(var d=0;g!=0;)d+=1,g>>>=1;return d};return w.getBCHTypeInfo=function(g){for(var d=g<<10;B(d)-B(b)>=0;)d^=b<=0;)d^=v<5&&(C+=3+D-5)}for(var k=0;k=256;)w-=255;return m[w]},x}();function s(m,b){if(typeof m.length>"u")throw m.length+"/"+b;var v=function(){for(var w=0;w"u")throw"bad rs block @ typeNumber:"+w+"/errorCorrectionLevel:"+B;for(var d=g.length/3,C=[],k=0;k>>7-x%8&1)==1},v.put=function(x,w){for(var B=0;B>>w-B-1&1)==1)},v.getLengthInBits=function(){return b},v.putBit=function(x){var w=Math.floor(b/8);m.length<=w&&m.push(0),x&&(m[w]|=128>>>b%8),b+=1},v},f=function(m){var b=e.MODE_NUMBER,v=m,x={};x.getMode=function(){return b},x.getLength=function(g){return v.length},x.write=function(g){for(var d=v,C=0;C+2>>8&255)*192+(k&255),g.put(k,13),C+=2}if(C>>8)},b.writeBytes=function(v,x,w){x=x||0,w=w||v.length;for(var B=0;B0&&(v+=","),v+=m[x];return v+="]",v},b},N=function(){var m=0,b=0,v=0,x="",w={},B=function(d){x+=String.fromCharCode(g(d&63))},g=function(d){if(!(d<0)){if(d<26)return 65+d;if(d<52)return 97+(d-26);if(d<62)return 48+(d-52);if(d==62)return 43;if(d==63)return 47}throw"n:"+d};return w.writeByte=function(d){for(m=m<<8|d&255,b+=8,v+=1;b>=6;)B(m>>>b-6),b-=6},w.flush=function(){if(b>0&&(B(m<<6-b),m=0,b=0),v%3!=0)for(var d=3-v%3,C=0;C=b.length){if(w==0)return-1;throw"unexpected end of file./"+w}var d=b.charAt(v);if(v+=1,d=="=")return w=0,-1;if(d.match(/^\s$/))continue;x=x<<6|g(d.charCodeAt(0)),w+=6}var C=x>>>w-8&255;return w-=8,C};var g=function(d){if(65<=d&&d<=90)return d-65;if(97<=d&&d<=122)return d-97+26;if(48<=d&&d<=57)return d-48+52;if(d==43)return 62;if(d==47)return 63;throw"c:"+d};return B},p=function(m,b){var v=m,x=b,w=new Array(m*b),B={};B.setPixel=function(k,T,D){w[T*v+k]=D},B.write=function(k){k.writeString("GIF87a"),k.writeShort(v),k.writeShort(x),k.writeByte(128),k.writeByte(0),k.writeByte(0),k.writeByte(0),k.writeByte(0),k.writeByte(0),k.writeByte(255),k.writeByte(255),k.writeByte(255),k.writeString(","),k.writeShort(0),k.writeShort(0),k.writeShort(v),k.writeShort(x),k.writeByte(0);var T=2,D=d(T);k.writeByte(T);for(var S=0;D.length-S>255;)k.writeByte(255),k.writeBytes(D,S,255),S+=255;k.writeByte(D.length-S),k.writeBytes(D,S,D.length-S),k.writeByte(0),k.writeString(";")};var g=function(k){var T=k,D=0,S=0,I={};return I.write=function(L,$){if(L>>>$)throw"length over";for(;D+$>=8;)T.writeByte(255&(L<>>=8-D,S=0,D=0;S=L<0&&T.writeByte(S)},I},d=function(k){for(var T=1<>6,128|i&63):i<55296||i>=57344?n.push(224|i>>12,128|i>>6&63,128|i&63):(o++,i=65536+((i&1023)<<10|r.charCodeAt(o)&1023),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}return n}return e(t)}})();(function(t){typeof define=="function"&&define.amd?define([],t):typeof xc=="object"&&(Ec.exports=t())})(function(){return mc})});var Ol={};Vi(Ol,{buildPayment:()=>Hl,newWords:()=>Cl,open:()=>Pl,qrSvg:()=>$l,sync:()=>Rl,validAddress:()=>Ac,validWords:()=>_l});function Yi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Pc(t,...e){if(!Yi(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Gi(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Rc(t){if(typeof t!="function")throw new Error("function expected");return!0}function Wr(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Zi(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Xn(t){if(!Array.isArray(t))throw new Error("array expected")}function Fi(t,e){if(!Gi(!0,e))throw new Error(`${t}: array of strings expected`)}function Hc(t,e){if(!Gi(!1,e))throw new Error(`${t}: array of numbers expected`)}function $c(...t){let e=i=>i,r=(i,s)=>a=>i(s(a)),n=t.map(i=>i.encode).reduceRight(r,e),o=t.map(i=>i.decode).reduce(r,e);return{encode:n,decode:o}}function Oc(t){let e=typeof t=="string"?t.split(""):t,r=e.length;Fi("alphabet",e);let n=new Map(e.map((o,i)=>[o,i]));return{encode:o=>(Xn(o),o.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${t}`);return e[i]})),decode:o=>(Xn(o),o.map(i=>{Wr("alphabet.decode",i);let s=n.get(i);if(s===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);return s}))}}function Mc(t=""){return Wr("join",t),{encode:e=>(Fi("join.decode",e),e.join(t)),decode:e=>(Wr("join.decode",e),e.split(t))}}function Dc(t){return Rc(t),{encode:e=>e,decode:e=>t(e)}}var Qi=(t,e)=>e===0?t:Qi(e,t%e),Vr=(t,e)=>t+(e-Qi(t,e)),Qn=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function ji(t,e,r,n){if(Xn(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Vr(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Vr(e,r)}`);let o=0,i=0,s=Qn[e],a=Qn[r]-1,c=[];for(let f of t){if(Zi(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(o=o<32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=r;i-=r)c.push((o>>i-r&a)>>>0);let h=Qn[i];if(h===void 0)throw new Error("invalid carry");o&=h-1}if(o=o<=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&c.push(o>>>0),c}function Kc(t,e=!1){if(Zi(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Vr(8,t)>32||Vr(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Yi(r))throw new Error("radix2.encode input should be Uint8Array");return ji(Array.from(r),8,t,!e)},decode:r=>(Hc("radix2.decode",r),Uint8Array.from(ji(r,t,8,e)))}}var Xi={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},qc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wc={encode(t){return Pc(t),t.toHex()},decode(t){return Wr("hex",t),Uint8Array.fromHex(t)}},gr=qc?Wc:$c(Kc(4),Oc("0123456789abcdef"),Mc(""),Dc(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var rt=new Uint8Array,ro=new Uint8Array([0]);function Ze(t,e){if(t.length!==e.length)return!1;for(let r=0;rnew DataView(t.buffer,t.byteOffset,t.byteLength);function Fe(t){return Object.prototype.toString.call(t)==="[object Object]"}function Wt(t){return Number.isSafeInteger(t)}var Ji={equalBytes:Ze,isBytes:Rt,isCoder:Ut,checkBounds:es,concatBytes:Vc,createView:no,isPlainObject:Fe},ts=t=>{if(t!==null&&typeof t!="string"&&!Ut(t)&&!Rt(t)&&!Wt(t))throw new Error(`lengthCoder: expected null | number | Uint8Array | CoderType, got ${t} (${typeof t})`);return{encodeStream(e,r){if(t===null)return;if(Ut(t))return t.encodeStream(e,r);let n;if(typeof t=="number"?n=t:typeof t=="string"&&(n=Gt.resolve(e.stack,t)),typeof n=="bigint"&&(n=Number(n)),n===void 0||n!==r)throw e.err(`Wrong length: ${n} len=${t} exp=${r} (${typeof r})`)},decodeStream(e){let r;if(Ut(t)?r=Number(t.decodeStream(e)):typeof t=="number"?r=t:typeof t=="string"&&(r=Gt.resolve(e.stack,t)),typeof r=="bigint"&&(r=Number(r)),typeof r!="number")throw e.err(`Wrong length: ${r}`);return r}}},wt={BITS:32,FULL_MASK:-1>>>0,len:t=>Math.ceil(t/32),create:t=>new Uint32Array(wt.len(t)),clean:t=>t.fill(0),debug:t=>Array.from(t).map(e=>(e>>>0).toString(2).padStart(32,"0")),checkLen:(t,e)=>{if(wt.len(e)!==t.length)throw new Error(`wrong length=${t.length}. Expected: ${wt.len(e)}`)},chunkLen:(t,e,r)=>{if(e<0)throw new Error(`wrong pos=${e}`);if(e+r>t)throw new Error(`wrong range=${e}/${r} of ${t}`)},set:(t,e,r,n=!0)=>!n&&t[e]&r?!1:(t[e]|=r,!0),pos:(t,e)=>({chunk:Math.floor((t+e)/32),mask:1<<32-(t+e)%32-1}),indices:(t,e,r=!1)=>{wt.checkLen(t,e);let{FULL_MASK:n,BITS:o}=wt,i=o-e%o,s=i?n>>>i<{let e=[],r;for(let n of t)r===void 0||n!==r.pos+r.length?e.push(r={pos:n,length:1}):r.length+=1;return e},rangeDebug:(t,e,r=!1)=>`[${wt.range(wt.indices(t,e,r)).map(n=>`(${n.pos}/${n.length})`).join(", ")}]`,setRange:(t,e,r,n,o=!0)=>{wt.chunkLen(e,r,n);let{FULL_MASK:i,BITS:s}=wt,a=r%s?Math.floor(r/s):void 0,c=r+n,f=c%s?Math.floor(c/s):void 0;if(a!==void 0&&a===f)return wt.set(t,a,i>>>s-n<>>r%s,o))return!1;let h=a!==void 0?a+1:r/s,u=f!==void 0?f:c/s;for(let l=h;l{let n={obj:e};t.push(n),r((o,i)=>{n.field=o,i(),n.field=void 0}),t.pop()},path:t=>{let e=[];for(let r of t)r.field!==void 0&&e.push(r.field);return e.join("/")},err:(t,e,r)=>{let n=new Error(`${t}(${Gt.path(e)}): ${typeof r=="string"?r:r.message}`);return r instanceof Error&&r.stack&&(n.stack=r.stack),n},resolve:(t,e)=>{let r=e.split("/"),n=t.map(s=>s.obj),o=0;for(;othis.data.length)throw this.err("readView: Unexpected end of buffer");let n=r(this.view,this.pos);return this.markBytes(e),n}absBytes(e){if(e>this.data.length)throw new Error("Unexpected end of buffer");return this.data.subarray(e)}finish(){if(!this.opts.allowUnreadBytes){if(this.bitPos)throw this.err(`${this.bitPos} bits left after unpack: ${gr.encode(this.data.slice(this.pos))}`);if(this.bs&&!this.parent){let e=wt.indices(this.bs,this.data.length,!0);if(e.length){let r=wt.range(e).map(({pos:n,length:o})=>`(${n}/${o})[${gr.encode(this.data.subarray(n,n+o))}]`).join(", ");throw this.err(`unread byte ranges: ${r} (total=${this.data.length})`)}else return}if(!this.isEnd())throw this.err(`${this.leftBytes} bytes ${this.bitPos} bits left after unpack: ${gr.encode(this.data.slice(this.pos))}`)}}err(e){return Gt.err("Reader",this.stack,e)}offsetReader(e){if(e>this.data.length)throw this.err("offsetReader: Unexpected end of buffer");return new t(this.absBytes(e),this.opts,this.stack,this,e)}bytes(e,r=!1){if(this.bitPos)throw this.err("readBytes: bitPos not empty");if(!Number.isFinite(e))throw this.err(`readBytes: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let n=this.data.subarray(this.pos,this.pos+e);return r||this.markBytes(e),n}byte(e=!1){if(this.bitPos)throw this.err("readByte: bitPos not empty");if(this.pos+1>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let r=this.data[this.pos];return e||this.markBytes(1),r}get leftBytes(){return this.data.length-this.pos}get totalBytes(){return this.data.length}isEnd(){return this.pos>=this.data.length&&!this.bitPos}bits(e){if(e>32)throw this.err("BitReader: cannot read more than 32 bits in single call");let r=0;for(;e;){this.bitPos||(this.bitBuf=this.byte(),this.bitPos=8);let n=Math.min(e,this.bitPos);this.bitPos-=n,r=r<>this.bitPos&2**n-1,this.bitBuf&=2**this.bitPos-1,e-=n}return r>>>0}find(e,r=this.pos){if(!Rt(e))throw this.err(`find: needle is not bytes! ${e}`);if(this.bitPos)throw this.err("findByte: bitPos not empty");if(!e.length)throw this.err("find: needle is empty");for(let n=r;(n=this.data.indexOf(e[0],n))!==-1;n++){if(n===-1||this.data.length-n8)throw new Error(`wrong writeView length=${e}`);r(this.view),this.bytes(this.viewBuf.slice(0,e)),this.viewBuf.fill(0)}err(e){if(this.finished)throw this.err("buffer: finished");return Gt.err("Reader",this.stack,e)}bytes(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeBytes: ends with non-empty bit buffer");this.buffers.push(e),this.pos+=e.length}byte(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeByte: ends with non-empty bit buffer");this.buffers.push(new Uint8Array([e])),this.pos++}finish(e=!0){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("buffer: ends with non-empty bit buffer");let r=this.buffers.concat(this.ptrs.map(i=>i.buffer)),n=r.map(i=>i.length).reduce((i,s)=>i+s,0),o=new Uint8Array(n);for(let i=0,s=0;i32)throw this.err("writeBits: cannot write more than 32 bits in single call");if(e>=2**r)throw this.err(`writeBits: value (${e}) >= 2**bits (${r})`);for(;r;){let n=Math.min(r,8-this.bitPos);this.bitBuf=this.bitBuf<>r-n,this.bitPos+=n,r-=n,e&=2**r-1,this.bitPos===8&&(this.bitPos=0,this.buffers.push(new Uint8Array([this.bitBuf])),this.pos++)}}},eo=t=>Uint8Array.from(t).reverse();function es(t,e,r){if(r){let n=2n**(e-1n);if(t<-n||t>=n)throw new Error(`value out of signed bounds. Expected ${-n} <= ${t} < ${n}`)}else if(0n>t||t>=2n**e)throw new Error(`value out of unsigned bounds. Expected 0 <= ${t} < ${2n**e}`)}function rs(t){return{encodeStream:t.encodeStream,decodeStream:t.decodeStream,size:t.size,encode:e=>{let r=new to;return t.encodeStream(r,e),r.finish()},decode:(e,r={})=>{let n=new Jn(e,r),o=t.decodeStream(n);return n.finish(),o}}}function vt(t,e){if(!Ut(t))throw new Error(`validate: invalid inner value ${t}`);if(typeof e!="function")throw new Error("validate: fn should be function");return rs({size:t.size,encodeStream:(r,n)=>{let o;try{o=e(n)}catch(i){throw r.err(i)}t.encodeStream(r,o)},decodeStream:r=>{let n=t.decodeStream(r);try{return e(n)}catch(o){throw r.err(o)}}})}var Bt=t=>{let e=rs(t);return t.validate?vt(e,t.validate):e},zr=t=>Fe(t)&&typeof t.decode=="function"&&typeof t.encode=="function";function Ut(t){return Fe(t)&&zr(t)&&typeof t.encodeStream=="function"&&typeof t.decodeStream=="function"&&(t.size===void 0||Wt(t.size))}function zc(){return{encode:t=>{if(!Array.isArray(t))throw new Error("array expected");let e={};for(let r of t){if(!Array.isArray(r)||r.length!==2)throw new Error("array of two elements expected");let n=r[0],o=r[1];if(e[n]!==void 0)throw new Error(`key(${n}) appears twice in struct`);e[n]=o}return e},decode:t=>{if(!Fe(t))throw new Error(`expected plain object, got ${t}`);return Object.entries(t)}}}var jc={encode:t=>{if(typeof t!="bigint")throw new Error(`expected bigint, got ${typeof t}`);if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error(`element bigger than MAX_SAFE_INTEGER=${t}`);return Number(t)},decode:t=>{if(!Wt(t))throw new Error("element is not a safe integer");return BigInt(t)}};function Yc(t){if(!Fe(t))throw new Error("plain object expected");return{encode:e=>{if(!Wt(e)||!(e in t))throw new Error(`wrong value ${e}`);return t[e]},decode:e=>{if(typeof e!="string")throw new Error(`wrong value ${typeof e}`);return t[e]}}}function Gc(t,e=!1){if(!Wt(t))throw new Error(`decimal/precision: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`decimal/round: expected boolean, got ${typeof e}`);let r=10n**BigInt(t);return{encode:n=>{if(typeof n!="bigint")throw new Error(`expected bigint, got ${typeof n}`);let o=(n<0n?-n:n).toString(10),i=o.length-t;i<0&&(o=o.padStart(o.length-i,"0"),i=0);let s=o.length-1;for(;s>=i&&o[s]==="0";s--);let a=o.slice(0,i),c=o.slice(i,s+1);return a||(a="0"),n<0n&&(a="-"+a),c?`${a}.${c}`:a},decode:n=>{if(typeof n!="string")throw new Error(`expected string, got ${typeof n}`);if(n==="-0")throw new Error("negative zero is not allowed");let o=!1;if(n.startsWith("-")&&(o=!0,n=n.slice(1)),!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))throw new Error(`wrong string value=${n}`);let i=n.indexOf(".");i=i===-1?n.length:i;let s=n.slice(0,i),a=n.slice(i+1).replace(/0+$/,""),c=BigInt(s)*r;if(!e&&a.length>t)throw new Error(`fractional part cannot be represented with this precision (num=${n}, prec=${t})`);let f=Math.min(a.length,t),h=BigInt(a.slice(0,f))*10n**BigInt(t-f),u=c+h;return o?-u:u}}}function Zc(t){if(!Array.isArray(t))throw new Error(`expected array, got ${typeof t}`);for(let e of t)if(!zr(e))throw new Error(`wrong base coder ${e}`);return{encode:e=>{for(let r of t){let n=r.encode(e);if(n!==void 0)return n}throw new Error(`match/encode: cannot find match in ${e}`)},decode:e=>{for(let r of t){let n=r.decode(e);if(n!==void 0)return n}throw new Error(`match/decode: cannot find match in ${e}`)}}}var ns=t=>{if(!zr(t))throw new Error("BaseCoder expected");return{encode:t.decode,decode:t.encode}},ue={dict:zc,numberBigint:jc,tsEnum:Yc,decimal:Gc,match:Zc,reverse:ns};var oo=(t,e=!1,r=!1,n=!0)=>{if(!Wt(t))throw new Error(`bigint/size: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`bigint/le: expected boolean, got ${typeof e}`);if(typeof r!="boolean")throw new Error(`bigint/signed: expected boolean, got ${typeof r}`);if(typeof n!="boolean")throw new Error(`bigint/sized: expected boolean, got ${typeof n}`);let o=BigInt(t),i=2n**(8n*o-1n);return Bt({size:n?t:void 0,encodeStream:(s,a)=>{r&&a<0&&(a=a|i);let c=[];for(let h=0;h>=8n;let f=new Uint8Array(c).reverse();if(!n){let h=0;for(h=0;h{let a=s.bytes(n?t:Math.min(t,s.leftBytes)),c=e?a:eo(a),f=0n;for(let h=0;h{if(typeof s!="bigint")throw new Error(`bigint: invalid value: ${s}`);return es(s,8n*o,!!r),s}})};var os=oo(32,!1);var Qe=oo(8,!0);var is=oo(8,!0,!0);var Fc=(t,e)=>Bt({size:t,encodeStream:(r,n)=>r.writeView(t,o=>e.write(o,n)),decodeStream:r=>r.readView(t,e.read),validate:r=>{if(typeof r!="number")throw new Error(`viewCoder: expected number, got ${typeof r}`);return e.validate&&e.validate(r),r}}),wr=(t,e,r)=>{let n=t*8,o=2**(n-1),i=c=>{if(!Wt(c))throw new Error(`sintView: value is not safe integer: ${c}`);if(c<-o||c>=o)throw new Error(`sintView: value out of bounds. Expected ${-o} <= ${c} < ${o}`)},s=2**n,a=c=>{if(!Wt(c))throw new Error(`uintView: value is not safe integer: ${c}`);if(0>c||c>=s)throw new Error(`uintView: value out of bounds. Expected 0 <= ${c} < ${s}`)};return Fc(t,{write:r.write,read:r.read,validate:e?i:a})},Q=wr(4,!1,{read:(t,e)=>t.getUint32(e,!0),write:(t,e)=>t.setUint32(0,e,!0)}),ss=wr(4,!1,{read:(t,e)=>t.getUint32(e,!1),write:(t,e)=>t.setUint32(0,e,!1)}),le=wr(4,!0,{read:(t,e)=>t.getInt32(e,!0),write:(t,e)=>t.setInt32(0,e,!0)});var io=wr(2,!1,{read:(t,e)=>t.getUint16(e,!0),write:(t,e)=>t.setUint16(0,e,!0)});var $t=wr(1,!1,{read:(t,e)=>t.getUint8(e),write:(t,e)=>t.setUint8(0,e)});var et=(t,e=!1)=>{if(typeof e!="boolean")throw new Error(`bytes/le: expected boolean, got ${typeof e}`);let r=ts(t),n=Rt(t);return Bt({size:typeof t=="number"?t:void 0,encodeStream:(o,i)=>{n||r.encodeStream(o,i.length),o.bytes(e?eo(i):i),n&&o.bytes(t)},decodeStream:o=>{let i;if(n){let s=o.find(t);if(!s)throw o.err("bytes: cannot find terminator");i=o.bytes(s-o.pos),o.bytes(t.length)}else i=o.bytes(t===null?o.leftBytes:r.decodeStream(o));return e?eo(i):i},validate:o=>{if(!Rt(o))throw new Error(`bytes: invalid value ${o}`);return o}})};function as(t,e){if(!Ut(e))throw new Error(`prefix: invalid inner value ${e}`);return Vt(et(t),ns(e))}var jr=(t,e=!1)=>vt(Vt(et(t,e),Xi),r=>{if(typeof r!="string")throw new Error(`expected string, got ${typeof r}`);return r});var cs=(t,e={isLE:!1,with0x:!1})=>{let r=Vt(et(t,e.isLE),gr),n=e.with0x;if(typeof n!="boolean")throw new Error(`hex/with0x: expected boolean, got ${typeof n}`);return n&&(r=Vt(r,{encode:o=>`0x${o}`,decode:o=>{if(!o.startsWith("0x"))throw new Error("hex(with0x=true).encode input should start with 0x");return o.slice(2)}})),r};function Vt(t,e){if(!Ut(t))throw new Error(`apply: invalid inner value ${t}`);if(!zr(e))throw new Error(`apply: invalid base value ${t}`);return Bt({size:t.size,encodeStream:(r,n)=>{let o;try{o=e.decode(n)}catch(i){throw r.err(""+i)}return t.encodeStream(r,o)},decodeStream:r=>{let n=t.decodeStream(r);try{return e.encode(n)}catch(o){throw r.err(""+o)}}})}var fs=(t,e=!1)=>{if(!Rt(t))throw new Error(`flag/flagValue: expected Uint8Array, got ${typeof t}`);if(typeof e!="boolean")throw new Error(`flag/xor: expected boolean, got ${typeof e}`);return Bt({size:t.length,encodeStream:(r,n)=>{!!n!==e&&r.bytes(t)},decodeStream:r=>{let n=r.leftBytes>=t.length;return n&&(n=Ze(r.bytes(t.length,!0),t),n&&r.bytes(t.length)),n!==e},validate:r=>{if(r!==void 0&&typeof r!="boolean")throw new Error(`flag: expected boolean value or undefined, got ${typeof r}`);return r}})};function us(t,e,r){if(!Ut(e))throw new Error(`flagged: invalid inner value ${e}`);if(typeof t!="string"&&!Ut(e))throw new Error(`flagged: wrong path=${t}`);return Bt({encodeStream:(n,o)=>{typeof t=="string"?Gt.resolve(n.stack,t)?e.encodeStream(n,o):r&&e.encodeStream(n,r):(t.encodeStream(n,!!o),o?e.encodeStream(n,o):r&&e.encodeStream(n,r))},decodeStream:n=>{let o=!1;if(typeof t=="string"?o=!!Gt.resolve(n.stack,t):o=t.decodeStream(n),o)return e.decodeStream(n);r&&e.decodeStream(n)}})}function Yr(t,e,r=!0){if(!Ut(t))throw new Error(`magic: invalid inner value ${t}`);if(typeof r!="boolean")throw new Error(`magic: expected boolean, got ${typeof r}`);return Bt({size:t.size,encodeStream:(n,o)=>t.encodeStream(n,e),decodeStream:n=>{let o=t.decodeStream(n);if(r&&typeof o!="object"&&o!==e||Rt(e)&&!Ze(e,o))throw n.err(`magic: invalid value: ${o} !== ${e}`)},validate:n=>{if(n!==void 0)throw new Error(`magic: wrong value=${typeof n}`);return n}})}function ls(t){let e=0;for(let r of t){if(r.size===void 0)return;if(!Wt(r.size))throw new Error(`sizeof: wrong element size=${e}`);e+=r.size}return e}function ft(t){if(!Fe(t))throw new Error(`struct: expected plain object, got ${t}`);for(let e in t)if(!Ut(t[e]))throw new Error(`struct: field ${e} is not CoderType`);return Bt({size:ls(Object.values(t)),encodeStream:(e,r)=>{e.pushObj(r,n=>{for(let o in t)n(o,()=>t[o].encodeStream(e,r[o]))})},decodeStream:e=>{let r={};return e.pushObj(r,n=>{for(let o in t)n(o,()=>r[o]=t[o].decodeStream(e))}),r},validate:e=>{if(typeof e!="object"||e===null)throw new Error(`struct: invalid value ${e}`);return e}})}function ds(t){if(!Array.isArray(t))throw new Error(`Packed.Tuple: got ${typeof t} instead of array`);for(let e=0;e{if(!Array.isArray(r))throw e.err(`tuple: invalid value ${r}`);e.pushObj(r,n=>{for(let o=0;ot[o].encodeStream(e,r[o]))})},decodeStream:e=>{let r=[];return e.pushObj(r,n=>{for(let o=0;or.push(t[o].decodeStream(e)))}),r},validate:e=>{if(!Array.isArray(e))throw new Error(`tuple: invalid value ${e}`);if(e.length!==t.length)throw new Error(`tuple: wrong length=${e.length}, expected ${t.length}`);return e}})}function St(t,e){if(!Ut(e))throw new Error(`array: invalid inner value ${e}`);let r=ts(typeof t=="string"?`../${t}`:t);return Bt({size:typeof t=="number"&&e.size?t*e.size:void 0,encodeStream:(n,o)=>{let i=n;i.pushObj(o,s=>{Rt(t)||r.encodeStream(n,o.length);for(let a=0;a{let c=o[a],f=n.pos;if(e.encodeStream(n,c),Rt(t)){if(t.length>i.pos-f)return;let h=i.finish(!1).subarray(f,i.pos);if(Ze(h.subarray(0,t.length),t))throw i.err(`array: inner element encoding same as separator. elm=${c} data=${h}`)}})}),Rt(t)&&n.bytes(t)},decodeStream:n=>{let o=[];return n.pushObj(o,i=>{if(t===null)for(let s=0;!n.isEnd()&&(i(`${s}`,()=>o.push(e.decodeStream(n))),!(e.size&&n.leftByteso.push(e.decodeStream(n)))}else{let s;i("arrayLen",()=>s=r.decodeStream(n));for(let a=0;ao.push(e.decodeStream(n)))}}),o},validate:n=>{if(!Array.isArray(n))throw new Error(`array: invalid value ${n}`);return n}})}function Qc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function so(t,...e){if(!Qc(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function ao(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function hs(t,e){so(t);let r=e.outputLen;if(t.lengthnew DataView(t.buffer,t.byteOffset,t.byteLength),Ot=(t,e)=>t<<32-e|t>>>e,yr=(t,e)=>t<>>32-e>>>0;function Xc(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function co(t){return typeof t=="string"&&(t=Xc(t)),so(t),t}var Zr=class{clone(){return this._cloneInto()}};function Qr(t){let e=n=>t().update(co(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Jc(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+f,a,n)}var ps=(t,e,r)=>t&e^~t&r,gs=(t,e,r)=>t&e^t&r^e&r,Xe=class extends Zr{constructor(e,r,n,o){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Fr(this.buffer)}update(e){ao(this);let{view:r,buffer:n,blockLen:o}=this;e=co(e);let i=e.length;for(let s=0;so-s&&(this.process(n,0),s=0);for(let u=s;uh.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;ue)),ef=ys.map(t=>(9*t+5)%16),uo=[ys],lo=[ef];for(let t=0;t<4;t++)for(let e of[uo,lo])e.push(e[t].map(r=>tf[r]));var bs=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>new Uint8Array(t)),rf=uo.map((t,e)=>t.map(r=>bs[e][r])),nf=lo.map((t,e)=>t.map(r=>bs[e][r])),of=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),sf=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function ws(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var Xr=new Uint32Array(16),fo=class extends Xe{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:r,h2:n,h3:o,h4:i}=this;return[e,r,n,o,i]}set(e,r,n,o,i){this.h0=e|0,this.h1=r|0,this.h2=n|0,this.h3=o|0,this.h4=i|0}process(e,r){for(let y=0;y<16;y++,r+=4)Xr[y]=e.getUint32(r,!0);let n=this.h0|0,o=n,i=this.h1|0,s=i,a=this.h2|0,c=a,f=this.h3|0,h=f,u=this.h4|0,l=u;for(let y=0;y<5;y++){let N=4-y,E=of[y],p=sf[y],A=uo[y],m=lo[y],b=rf[y],v=nf[y];for(let x=0;x<16;x++){let w=yr(n+ws(y,i,a,f)+Xr[A[x]]+E,b[x])+u|0;n=u,u=f,f=yr(a,10)|0,a=i,i=w}for(let x=0;x<16;x++){let w=yr(o+ws(N,s,c,h)+Xr[m[x]]+p,v[x])+l|0;o=l,l=h,h=yr(c,10)|0,c=s,s=w}}this.set(this.h1+a+h|0,this.h2+f+l|0,this.h3+u+o|0,this.h4+n+s|0,this.h0+i+c|0)}roundClean(){Xr.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}},ms=Qr(()=>new fo);var af=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),de=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),he=new Uint32Array(64),ho=class extends Xe{constructor(){super(64,32,8,!1),this.A=de[0]|0,this.B=de[1]|0,this.C=de[2]|0,this.D=de[3]|0,this.E=de[4]|0,this.F=de[5]|0,this.G=de[6]|0,this.H=de[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let u=0;u<16;u++,r+=4)he[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let l=he[u-15],y=he[u-2],N=Ot(l,7)^Ot(l,18)^l>>>3,E=Ot(y,17)^Ot(y,19)^y>>>10;he[u]=E+he[u-7]+N+he[u-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let l=Ot(a,6)^Ot(a,11)^Ot(a,25),y=h+l+ps(a,c,f)+af[u]+he[u]|0,E=(Ot(n,2)^Ot(n,13)^Ot(n,22))+gs(n,o,i)|0;h=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+E|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){he.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var kt=Qr(()=>new ho);function xs(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function cf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Je(t,...e){if(!cf(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Es(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");xs(t.outputLen),xs(t.blockLen)}function tr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function vs(t,e){Je(t);let r=e.outputLen;if(t.lengthnew DataView(t.buffer,t.byteOffset,t.byteLength),Mt=(t,e)=>t<<32-e|t>>>e;function ff(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function br(t){return typeof t=="string"&&(t=ff(t)),Je(t),t}function Bs(...t){let e=0;for(let n=0;nt().update(br(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function tn(t=32){if(Ne&&typeof Ne.getRandomValues=="function")return Ne.getRandomValues(new Uint8Array(t));if(Ne&&typeof Ne.randomBytes=="function")return Ne.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function uf(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+f,a,n)}var As=(t,e,r)=>t&e^~t&r,ks=(t,e,r)=>t&e^t&r^e&r,en=class extends er{constructor(e,r,n,o){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Jr(this.buffer)}update(e){tr(this);let{view:r,buffer:n,blockLen:o}=this;e=br(e);let i=e.length;for(let s=0;so-s&&(this.process(n,0),s=0);for(let u=s;uh.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u>>3,E=Mt(y,17)^Mt(y,19)^y>>>10;ge[u]=E+ge[u-7]+N+ge[u-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let l=Mt(a,6)^Mt(a,11)^Mt(a,25),y=h+l+As(a,c,f)+lf[u]+ge[u]|0,E=(Mt(n,2)^Mt(n,13)^Mt(n,22))+ks(n,o,i)|0;h=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+E|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){ge.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var rn=Ss(()=>new po);var nn=class extends er{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Es(e);let n=br(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;snew nn(t,e).update(r).digest();go.create=(t,e)=>new nn(t,e);var Eo={};Vi(Eo,{aInRange:()=>zt,abool:()=>Ce,abytes:()=>rr,bitGet:()=>yf,bitLen:()=>mo,bitMask:()=>mr,bitSet:()=>bf,bytesToHex:()=>_e,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>an,concatBytes:()=>Ft,createHmacDrbg:()=>xo,ensureBytes:()=>ut,equalBytes:()=>gf,hexToBytes:()=>Re,hexToNumber:()=>bo,inRange:()=>ye,isBytes:()=>we,memoized:()=>fn,notImplemented:()=>xf,numberToBytesBE:()=>Dt,numberToBytesLE:()=>cn,numberToHexUnpadded:()=>Pe,numberToVarBytesBE:()=>pf,utf8ToBytes:()=>wf,validateObject:()=>be});var on=BigInt(0),sn=BigInt(1),df=BigInt(2);function we(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function rr(t){if(!we(t))throw new Error("Uint8Array expected")}function Ce(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}var hf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function _e(t){rr(t);let e="";for(let r=0;r=Zt._0&&t<=Zt._9)return t-Zt._0;if(t>=Zt.A&&t<=Zt.F)return t-(Zt.A-10);if(t>=Zt.a&&t<=Zt.f)return t-(Zt.a-10)}function Re(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;otypeof t=="bigint"&&on<=t;function ye(t,e,r){return wo(t)&&wo(e)&&wo(r)&&e<=t&&ton;t>>=sn,e+=1);return e}function yf(t,e){return t>>BigInt(e)&sn}function bf(t,e,r){return t|(r?sn:on)<(df<new Uint8Array(t),Is=t=>Uint8Array.from(t);function xo(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=yo(t),o=yo(t),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...u)=>r(o,n,...u),c=(u=yo())=>{o=a(Is([0]),u),n=a(),u.length!==0&&(o=a(Is([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,l=[];for(;u{s(),c(u);let y;for(;!(y=l(f()));)c();return s(),y}}var mf={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||we(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function be(t,e,r={}){let n=(o,i,s)=>{let a=mf[i];if(typeof a!="function")throw new Error("invalid validator function");let c=t[o];if(!(s&&c===void 0)&&!a(c,t))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return t}var xf=()=>{throw new Error("not implemented")};function fn(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let i=t(r,...n);return e.set(r,i),i}}var dt=BigInt(0),nt=BigInt(1),He=BigInt(2),Ef=BigInt(3),vo=BigInt(4),Us=BigInt(5),Ls=BigInt(8),vf=BigInt(9),Bf=BigInt(16);function lt(t,e){let r=t%e;return r>=dt?r:e+r}function Sf(t,e,r){if(edt;)e&nt&&(n=n*t%r),t=t*t%r,e>>=nt;return n}function Lt(t,e,r){let n=t;for(;e-- >dt;)n*=n,n%=r;return n}function un(t,e){if(t===dt)throw new Error("invert: expected non-zero number");if(e<=dt)throw new Error("invert: expected positive modulus, got "+e);let r=lt(t,e),n=e,o=dt,i=nt,s=nt,a=dt;for(;r!==dt;){let f=n/r,h=n%r,u=o-s*f,l=i-a*f;n=r,r=h,o=s,i=a,s=u,a=l}if(n!==nt)throw new Error("invert: does not exist");return lt(o,e)}function Af(t){let e=(t-nt)/He,r,n,o;for(r=t-nt,n=0;r%He===dt;r/=He,n++);for(o=He;o1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(t+nt)/vo;return function(c,f){let h=c.pow(f,s);if(!c.eql(c.sqr(h),f))throw new Error("Cannot find square root");return h}}let i=(r+nt)/He;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,h=a.pow(a.mul(a.ONE,o),r),u=a.pow(c,i),l=a.pow(c,r);for(;!a.eql(l,a.ONE);){if(a.eql(l,a.ZERO))return a.ZERO;let y=1;for(let E=a.sqr(l);y(n[o]="function",n),e);return be(t,r)}function If(t,e,r){if(rdt;)r&nt&&(n=t.mul(n,o)),o=t.sqr(o),r>>=nt;return n}function Uf(t,e){let r=new Array(e.length),n=e.reduce((i,s,a)=>t.is0(s)?i:(r[a]=i,t.mul(i,s)),t.ONE),o=t.inv(n);return e.reduceRight((i,s,a)=>t.is0(s)?i:(r[a]=t.mul(i,r[a]),t.mul(i,s)),o),r}function So(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ln(t,e,r=!1,n={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:o,nByteLength:i}=So(t,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:t,BITS:o,BYTES:i,MASK:mr(o),ZERO:dt,ONE:nt,create:c=>lt(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return dt<=c&&cc===dt,isOdd:c=>(c&nt)===nt,neg:c=>lt(-c,t),eql:(c,f)=>c===f,sqr:c=>lt(c*c,t),add:(c,f)=>lt(c+f,t),sub:(c,f)=>lt(c-f,t),mul:(c,f)=>lt(c*f,t),pow:(c,f)=>If(a,c,f),div:(c,f)=>lt(c*un(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>un(c,t),sqrt:n.sqrt||(c=>(s||(s=kf(t)),s(a,c))),invertBatch:c=>Uf(a,c),cmov:(c,f,h)=>h?f:c,toBytes:c=>r?cn(c,i):Dt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?an(c):Ht(c)}});return Object.freeze(a)}function Ns(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ao(t){let e=Ns(t);return e+Math.ceil(e/2)}function Cs(t,e,r=!1){let n=t.length,o=Ns(e),i=Ao(e);if(n<16||n1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ht(t):an(t),a=lt(s,e-nt)+nt;return r?cn(a,o):Dt(a,o)}var _s=BigInt(0),dn=BigInt(1);function ko(t,e){let r=e.negate();return t?r:e}function Ps(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function To(t,e){Ps(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1);return{windows:r,windowSize:n}}function Nf(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Cf(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Io=new WeakMap,Rs=new WeakMap;function Uo(t){return Rs.get(t)||1}function Hs(t,e){return{constTimeNegate:ko,hasPrecomputes(r){return Uo(r)!==1},unsafeLadder(r,n,o=t.ZERO){let i=r;for(;n>_s;)n&dn&&(o=o.add(i)),i=i.double(),n>>=dn;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=To(n,e),s=[],a=r,c=a;for(let f=0;f>=u,N>s&&(N-=h,o+=dn);let E=y,p=y+Math.abs(N)-1,A=l%2!==0,m=N<0;N===0?c=c.add(ko(A,n[E])):a=a.add(ko(m,n[p]))}return{p:a,f:c}},wNAFUnsafe(r,n,o,i=t.ZERO){let{windows:s,windowSize:a}=To(r,e),c=BigInt(2**r-1),f=2**r,h=BigInt(r);for(let u=0;u>=h,y>a&&(y-=f,o+=dn),y===0)continue;let N=n[l+Math.abs(y)-1];y<0&&(N=N.negate()),i=i.add(N)}return i},getPrecomputes(r,n,o){let i=Io.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&Io.set(n,o(i))),i},wNAFCached(r,n,o){let i=Uo(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=Uo(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){Ps(n,e),Rs.set(r,n),Io.delete(r)}}}function $s(t,e,r,n){if(Nf(r,t),Cf(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,i=mo(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=(1<=0;u-=s){c.fill(o);for(let y=0;y>BigInt(u)&BigInt(a));c[E]=c[E].add(r[y])}let l=o;for(let y=c.length-1,N=o;y>0;y--)N=N.add(c[y]),l=l.add(N);if(h=h.add(l),u!==0)for(let y=0;y{let{Err:r}=Qt;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Pe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Pe(o.length/2|128):"";return Pe(t)+i+o+e},decode(t,e){let{Err:r}=Qt,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of f)s=s<<8|h;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=Qt;if(t{let m=p.toAffine();return Ft(Uint8Array.from([4]),r.toBytes(m.x),r.toBytes(m.y))}),i=e.fromBytes||(E=>{let p=E.subarray(1),A=r.fromBytes(p.subarray(0,r.BYTES)),m=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:A,y:m}});function s(E){let{a:p,b:A}=e,m=r.sqr(E),b=r.mul(m,E);return r.add(r.add(b,r.mul(E,p)),A)}if(!r.eql(r.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(E){return ye(E,yt,e.n)}function c(E){let{allowedPrivateKeyLengths:p,nByteLength:A,wrapPrivateKey:m,n:b}=e;if(p&&typeof E!="bigint"){if(we(E)&&(E=_e(E)),typeof E!="string"||!p.includes(E.length))throw new Error("invalid private key");E=E.padStart(A*2,"0")}let v;try{v=typeof E=="bigint"?E:Ht(ut("private key",E,A))}catch{throw new Error("invalid private key, expected hex or "+A+" bytes, got "+typeof E)}return m&&(v=lt(v,b)),zt("private key",v,yt,b),v}function f(E){if(!(E instanceof l))throw new Error("ProjectivePoint expected")}let h=fn((E,p)=>{let{px:A,py:m,pz:b}=E;if(r.eql(b,r.ONE))return{x:A,y:m};let v=E.is0();p==null&&(p=v?r.ONE:r.inv(b));let x=r.mul(A,p),w=r.mul(m,p),B=r.mul(b,p);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(B,r.ONE))throw new Error("invZ was invalid");return{x,y:w}}),u=fn(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.py))return;throw new Error("bad point: ZERO")}let{x:p,y:A}=E.toAffine();if(!r.isValid(p)||!r.isValid(A))throw new Error("bad point: x or y not FE");let m=r.sqr(A),b=s(p);if(!r.eql(m,b))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(p,A,m){if(this.px=p,this.py=A,this.pz=m,p==null||!r.isValid(p))throw new Error("x required");if(A==null||!r.isValid(A))throw new Error("y required");if(m==null||!r.isValid(m))throw new Error("z required");Object.freeze(this)}static fromAffine(p){let{x:A,y:m}=p||{};if(!p||!r.isValid(A)||!r.isValid(m))throw new Error("invalid affine point");if(p instanceof l)throw new Error("projective point not allowed");let b=v=>r.eql(v,r.ZERO);return b(A)&&b(m)?l.ZERO:new l(A,m,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){let A=r.invertBatch(p.map(m=>m.pz));return p.map((m,b)=>m.toAffine(A[b])).map(l.fromAffine)}static fromHex(p){let A=l.fromAffine(i(ut("pointHex",p)));return A.assertValidity(),A}static fromPrivateKey(p){return l.BASE.multiply(c(p))}static msm(p,A){return $s(l,n,p,A)}_setWindowSize(p){N.setWindowSize(this,p)}assertValidity(){u(this)}hasEvenY(){let{y:p}=this.toAffine();if(r.isOdd)return!r.isOdd(p);throw new Error("Field doesn't support isOdd")}equals(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.eql(r.mul(A,w),r.mul(v,b)),g=r.eql(r.mul(m,w),r.mul(x,b));return B&&g}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:p,b:A}=e,m=r.mul(A,Ms),{px:b,py:v,pz:x}=this,w=r.ZERO,B=r.ZERO,g=r.ZERO,d=r.mul(b,b),C=r.mul(v,v),k=r.mul(x,x),T=r.mul(b,v);return T=r.add(T,T),g=r.mul(b,x),g=r.add(g,g),w=r.mul(p,g),B=r.mul(m,k),B=r.add(w,B),w=r.sub(C,B),B=r.add(C,B),B=r.mul(w,B),w=r.mul(T,w),g=r.mul(m,g),k=r.mul(p,k),T=r.sub(d,k),T=r.mul(p,T),T=r.add(T,g),g=r.add(d,d),d=r.add(g,d),d=r.add(d,k),d=r.mul(d,T),B=r.add(B,d),k=r.mul(v,x),k=r.add(k,k),d=r.mul(k,T),w=r.sub(w,d),g=r.mul(k,C),g=r.add(g,g),g=r.add(g,g),new l(w,B,g)}add(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.ZERO,g=r.ZERO,d=r.ZERO,C=e.a,k=r.mul(e.b,Ms),T=r.mul(A,v),D=r.mul(m,x),S=r.mul(b,w),I=r.add(A,m),L=r.add(v,x);I=r.mul(I,L),L=r.add(T,D),I=r.sub(I,L),L=r.add(A,b);let $=r.add(v,w);return L=r.mul(L,$),$=r.add(T,S),L=r.sub(L,$),$=r.add(m,b),B=r.add(x,w),$=r.mul($,B),B=r.add(D,S),$=r.sub($,B),d=r.mul(C,L),B=r.mul(k,S),d=r.add(B,d),B=r.sub(D,d),d=r.add(D,d),g=r.mul(B,d),D=r.add(T,T),D=r.add(D,T),S=r.mul(C,S),L=r.mul(k,L),D=r.add(D,S),S=r.sub(T,S),S=r.mul(C,S),L=r.add(L,S),T=r.mul(D,L),g=r.add(g,T),T=r.mul($,L),B=r.mul(I,B),B=r.sub(B,T),T=r.mul(I,D),d=r.mul($,d),d=r.add(d,T),new l(B,g,d)}subtract(p){return this.add(p.negate())}is0(){return this.equals(l.ZERO)}wNAF(p){return N.wNAFCached(this,p,l.normalizeZ)}multiplyUnsafe(p){let{endo:A,n:m}=e;zt("scalar",p,Xt,m);let b=l.ZERO;if(p===Xt)return b;if(this.is0()||p===yt)return this;if(!A||N.hasPrecomputes(this))return N.wNAFCachedUnsafe(this,p,l.normalizeZ);let{k1neg:v,k1:x,k2neg:w,k2:B}=A.splitScalar(p),g=b,d=b,C=this;for(;x>Xt||B>Xt;)x&yt&&(g=g.add(C)),B&yt&&(d=d.add(C)),C=C.double(),x>>=yt,B>>=yt;return v&&(g=g.negate()),w&&(d=d.negate()),d=new l(r.mul(d.px,A.beta),d.py,d.pz),g.add(d)}multiply(p){let{endo:A,n:m}=e;zt("scalar",p,yt,m);let b,v;if(A){let{k1neg:x,k1:w,k2neg:B,k2:g}=A.splitScalar(p),{p:d,f:C}=this.wNAF(w),{p:k,f:T}=this.wNAF(g);d=N.constTimeNegate(x,d),k=N.constTimeNegate(B,k),k=new l(r.mul(k.px,A.beta),k.py,k.pz),b=d.add(k),v=C.add(T)}else{let{p:x,f:w}=this.wNAF(p);b=x,v=w}return l.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(p,A,m){let b=l.BASE,v=(w,B)=>B===Xt||B===yt||!w.equals(b)?w.multiplyUnsafe(B):w.multiply(B),x=v(this,A).add(v(p,m));return x.is0()?void 0:x}toAffine(p){return h(this,p)}isTorsionFree(){let{h:p,isTorsionFree:A}=e;if(p===yt)return!0;if(A)return A(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:p,clearCofactor:A}=e;return p===yt?this:A?A(l,this):this.multiplyUnsafe(e.h)}toRawBytes(p=!0){return Ce("isCompressed",p),this.assertValidity(),o(l,this,p)}toHex(p=!0){return Ce("isCompressed",p),_e(this.toRawBytes(p))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let y=e.nBitLength,N=Hs(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function $f(t){let e=Lo(t);return be(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Ds(t){let e=$f(t),{Fp:r,n}=e,o=r.BYTES+1,i=2*r.BYTES+1;function s(S){return lt(S,n)}function a(S){return un(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:h,isWithinCurveOrder:u}=Hf({...e,toBytes(S,I,L){let $=I.toAffine(),M=r.toBytes($.x),W=Ft;return Ce("isCompressed",L),L?W(Uint8Array.from([I.hasEvenY()?2:3]),M):W(Uint8Array.from([4]),M,r.toBytes($.y))},fromBytes(S){let I=S.length,L=S[0],$=S.subarray(1);if(I===o&&(L===2||L===3)){let M=Ht($);if(!ye(M,yt,r.ORDER))throw new Error("Point is not on curve");let W=h(M),j;try{j=r.sqrt(W)}catch(X){let F=X instanceof Error?": "+X.message:"";throw new Error("Point is not on curve"+F)}let Y=(j&yt)===yt;return(L&1)===1!==Y&&(j=r.neg(j)),{x:M,y:j}}else if(I===i&&L===4){let M=r.fromBytes($.subarray(0,r.BYTES)),W=r.fromBytes($.subarray(r.BYTES,2*r.BYTES));return{x:M,y:W}}else{let M=o,W=i;throw new Error("invalid Point, expected length of "+M+", or uncompressed "+W+", got "+I)}}}),l=S=>_e(Dt(S,e.nByteLength));function y(S){let I=n>>yt;return S>I}function N(S){return y(S)?s(-S):S}let E=(S,I,L)=>Ht(S.slice(I,L));class p{constructor(I,L,$){this.r=I,this.s=L,this.recovery=$,this.assertValidity()}static fromCompact(I){let L=e.nByteLength;return I=ut("compactSignature",I,L*2),new p(E(I,0,L),E(I,L,2*L))}static fromDER(I){let{r:L,s:$}=Qt.toSig(ut("DER",I));return new p(L,$)}assertValidity(){zt("r",this.r,yt,n),zt("s",this.s,yt,n)}addRecoveryBit(I){return new p(this.r,this.s,I)}recoverPublicKey(I){let{r:L,s:$,recovery:M}=this,W=w(ut("msgHash",I));if(M==null||![0,1,2,3].includes(M))throw new Error("recovery id invalid");let j=M===2||M===3?L+e.n:L;if(j>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let Y=M&1?"03":"02",it=c.fromHex(Y+l(j)),X=a(j),F=s(-W*X),P=s($*X),_=c.BASE.multiplyAndAddUnsafe(it,F,P);if(!_)throw new Error("point at infinify");return _.assertValidity(),_}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Re(this.toDERHex())}toDERHex(){return Qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Re(this.toCompactHex())}toCompactHex(){return l(this.r)+l(this.s)}}let A={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=Ao(e.n);return Cs(e.randomBytes(S),e.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function m(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function b(S){let I=we(S),L=typeof S=="string",$=(I||L)&&S.length;return I?$===o||$===i:L?$===2*o||$===2*i:S instanceof c}function v(S,I,L=!0){if(b(S))throw new Error("first arg must be private key");if(!b(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(f(S)).toRawBytes(L)}let x=e.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=Ht(S),L=S.length*8-e.nBitLength;return L>0?I>>BigInt(L):I},w=e.bits2int_modN||function(S){return s(x(S))},B=mr(e.nBitLength);function g(S){return zt("num < 2^"+e.nBitLength,S,Xt,B),Dt(S,e.nByteLength)}function d(S,I,L=C){if(["recovered","canonical"].some(R=>R in L))throw new Error("sign() legacy options not supported");let{hash:$,randomBytes:M}=e,{lowS:W,prehash:j,extraEntropy:Y}=L;W==null&&(W=!0),S=ut("msgHash",S),Os(L),j&&(S=ut("prehashed msgHash",$(S)));let it=w(S),X=f(I),F=[g(X),g(it)];if(Y!=null&&Y!==!1){let R=Y===!0?M(r.BYTES):Y;F.push(ut("extraEntropy",R))}let P=Ft(...F),_=it;function U(R){let H=x(R);if(!u(H))return;let O=a(H),q=c.BASE.multiply(H).toAffine(),K=s(q.x);if(K===Xt)return;let G=s(O*s(_+K*X));if(G===Xt)return;let Z=(q.x===K?0:2)|Number(q.y&yt),V=G;return W&&y(G)&&(V=N(G),Z^=1),new p(K,V,Z)}return{seed:P,k2sig:U}}let C={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(S,I,L=C){let{seed:$,k2sig:M}=d(S,I,L),W=e;return xo(W.hash.outputLen,W.nByteLength,W.hmac)($,M)}c.BASE._setWindowSize(8);function D(S,I,L,$=k){let M=S;I=ut("msgHash",I),L=ut("publicKey",L);let{lowS:W,prehash:j,format:Y}=$;if(Os($),"strict"in $)throw new Error("options.strict was renamed to lowS");if(Y!==void 0&&Y!=="compact"&&Y!=="der")throw new Error("format must be compact or der");let it=typeof M=="string"||we(M),X=!it&&!Y&&typeof M=="object"&&M!==null&&typeof M.r=="bigint"&&typeof M.s=="bigint";if(!it&&!X)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let F,P;try{if(X&&(F=new p(M.r,M.s)),it){try{Y!=="compact"&&(F=p.fromDER(M))}catch(Z){if(!(Z instanceof Qt.Err))throw Z}!F&&Y!=="der"&&(F=p.fromCompact(M))}P=c.fromHex(L)}catch{return!1}if(!F||W&&F.hasHighS())return!1;j&&(I=e.hash(I));let{r:_,s:U}=F,R=w(I),H=a(U),O=s(R*H),q=s(_*H),K=c.BASE.multiplyAndAddUnsafe(P,O,q)?.toAffine();return K?s(K.x)===_:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:v,sign:T,verify:D,ProjectivePoint:c,Signature:p,utils:A}}function Of(t){return{hash:t,hmac:(e,...r)=>go(t,e,Bs(...r)),randomBytes:tn}}function Ks(t,e){let r=n=>Ds({...t,...Of(n)});return Object.freeze({...r(e),create:r})}var vr=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),hn=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),xr=BigInt(1),pn=BigInt(2),qs=(t,e)=>(t+e/pn)/e;function Vs(t){let e=vr,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,h=f*f*t%e,u=Lt(h,r,e)*h%e,l=Lt(u,r,e)*h%e,y=Lt(l,pn,e)*f%e,N=Lt(y,o,e)*y%e,E=Lt(N,i,e)*N%e,p=Lt(E,a,e)*E%e,A=Lt(p,c,e)*p%e,m=Lt(A,a,e)*E%e,b=Lt(m,r,e)*h%e,v=Lt(b,s,e)*N%e,x=Lt(v,n,e)*f%e,w=Lt(x,pn,e);if(!Co.eql(Co.sqr(w),t))throw new Error("Cannot find square root");return w}var Co=ln(vr,void 0,void 0,{sqrt:Vs}),Jt=Ks({a:BigInt(0),b:BigInt(7),Fp:Co,n:hn,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=hn,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-xr*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=qs(i*t,e),c=qs(-n*t,e),f=lt(t-a*r-c*o,e),h=lt(-a*n-c*i,e),u=f>s,l=h>s;if(u&&(f=e-f),l&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:f,k2neg:l,k2:h}}}},rn),zs=BigInt(0),Ws={};function gn(t,...e){let r=Ws[t];if(r===void 0){let n=rn(Uint8Array.from(t,o=>o.charCodeAt(0)));r=Ft(n,n),Ws[t]=r}return rn(Ft(r,...e))}var Ro=t=>t.toRawBytes(!0).slice(1),_o=t=>Dt(t,32),No=t=>lt(t,vr),Er=t=>lt(t,hn),Ho=Jt.ProjectivePoint,Mf=(t,e,r)=>Ho.BASE.multiplyAndAddUnsafe(t,e,r);function Po(t){let e=Jt.utils.normPrivateKeyToScalar(t),r=Ho.fromPrivateKey(e);return{scalar:r.hasEvenY()?e:Er(-e),bytes:Ro(r)}}function js(t){zt("x",t,xr,vr);let e=No(t*t),r=No(e*t+BigInt(7)),n=Vs(r);n%pn!==zs&&(n=No(-n));let o=new Ho(t,n,xr);return o.assertValidity(),o}var nr=Ht;function Ys(...t){return Er(nr(gn("BIP0340/challenge",...t)))}function Df(t){return Po(t).bytes}function Kf(t,e,r=tn(32)){let n=ut("message",t),{bytes:o,scalar:i}=Po(e),s=ut("auxRand",r,32),a=_o(i^nr(gn("BIP0340/aux",s))),c=gn("BIP0340/nonce",a,o,n),f=Er(nr(c));if(f===zs)throw new Error("sign failed: k is zero");let{bytes:h,scalar:u}=Po(f),l=Ys(h,o,n),y=new Uint8Array(64);if(y.set(h,0),y.set(_o(Er(u+l*i)),32),!Gs(y,n,o))throw new Error("sign: Invalid signature produced");return y}function Gs(t,e,r){let n=ut("signature",t,64),o=ut("message",e),i=ut("publicKey",r,32);try{let s=js(nr(i)),a=nr(n.subarray(0,32));if(!ye(a,xr,vr))return!1;let c=nr(n.subarray(32,64));if(!ye(c,xr,hn))return!1;let f=Ys(_o(a),Ro(s),o),h=Mf(s,c,Er(-f));return!(!h||!h.hasEvenY()||h.toAffine().x!==a)}catch{return!1}}var jt={getPublicKey:Df,sign:Kf,verify:Gs,utils:{randomPrivateKey:Jt.utils.randomPrivateKey,lift_x:js,pointToBytes:Ro,numberToBytesBE:Dt,bytesToNumberBE:Ht,taggedHash:gn,mod:lt}};var yn=Jt.ProjectivePoint,wn=Jt.CURVE.n,{isBytes:J,concatBytes:te,equalBytes:st}=Ji;var Br=t=>ms(kt(t)),ee=(...t)=>kt(kt(te(...t))),Od=jt.utils.randomPrivateKey,bn=jt.getPublicKey,$o=Jt.getPublicKey,Zs=t=>t.r4294967295)throw new Error("lowR counter overflow: report the error")}return n.toDERRawBytes()}var Oo=jt.sign,mn=jt.utils.taggedHash,xt;(function(t){t[t.ecdsa=0]="ecdsa",t[t.schnorr=1]="schnorr"})(xt||(xt={}));function me(t,e){let r=t.length;if(e===xt.ecdsa){if(r===32)throw new Error("Expected non-Schnorr key");return yn.fromHex(t),t}else if(e===xt.schnorr){if(r!==32)throw new Error("Expected 32-byte Schnorr key");return jt.utils.lift_x(jt.utils.bytesToNumberBE(t)),t}else throw new Error("Unknown key type")}function Qs(t,e){let r=jt.utils,n=r.taggedHash("TapTweak",t,e),o=r.bytesToNumberBE(n);if(o>=wn)throw new Error("tweak higher than curve order");return o}function Xs(t,e=new Uint8Array){let r=jt.utils,n=r.bytesToNumberBE(t),o=yn.fromPrivateKey(n),i=o.hasEvenY()?n:r.mod(-n,wn),s=r.pointToBytes(o),a=Qs(s,e);return r.numberToBytesBE(r.mod(i+a,wn),32)}function Mo(t,e){let r=jt.utils,n=Qs(t,e),i=r.lift_x(r.bytesToNumberBE(t)).add(yn.fromPrivateKey(n)),s=i.hasEvenY()?0:1;return[r.pointToBytes(i),s]}var Do=kt(yn.BASE.toRawBytes(!1)),re={bech32:"bc",pubKeyHash:0,scriptHash:5,wif:128},Ko={bech32:"tb",pubKeyHash:111,scriptHash:196,wif:239};function Sr(t,e){if(!J(t)||!J(e))throw new Error(`cmp: wrong type a=${typeof t} b=${typeof e}`);let r=Math.min(t.length,e.length);for(let n=0;ntypeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Vo(t){if(typeof t!="function")throw new Error("function expected");return!0}function or(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function ir(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function En(t){if(!Array.isArray(t))throw new Error("array expected")}function vn(t,e){if(!na(!0,e))throw new Error(`${t}: array of strings expected`)}function zo(t,e){if(!na(!1,e))throw new Error(`${t}: array of numbers expected`)}function Tr(...t){let e=i=>i,r=(i,s)=>a=>i(s(a)),n=t.map(i=>i.encode).reduceRight(r,e),o=t.map(i=>i.decode).reduce(r,e);return{encode:n,decode:o}}function An(t){let e=typeof t=="string"?t.split(""):t,r=e.length;vn("alphabet",e);let n=new Map(e.map((o,i)=>[o,i]));return{encode:o=>(En(o),o.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${t}`);return e[i]})),decode:o=>(En(o),o.map(i=>{or("alphabet.decode",i);let s=n.get(i);if(s===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);return s}))}}function kn(t=""){return or("join",t),{encode:e=>(vn("join.decode",e),e.join(t)),decode:e=>(or("join.decode",e),e.split(t))}}function qf(t,e="="){return ir(t),or("padding",e),{encode(r){for(vn("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){vn("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function Wf(t){return Vo(t),{encode:e=>e,decode:e=>t(e)}}function qo(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(En(t),!t.length)return[];let n=0,o=[],i=Array.from(t,a=>{if(ir(a),a<0||a>=e)throw new Error(`invalid integer: ${a}`);return a}),s=i.length;for(;;){let a=0,c=!0;for(let f=n;fe===0?t:oa(e,t%e),Bn=(t,e)=>t+(e-oa(t,e)),xn=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Sn(t,e,r,n){if(En(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Bn(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Bn(e,r)}`);let o=0,i=0,s=xn[e],a=xn[r]-1,c=[];for(let f of t){if(ir(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(o=o<32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=r;i-=r)c.push((o>>i-r&a)>>>0);let h=xn[i];if(h===void 0)throw new Error("invalid carry");o&=h-1}if(o=o<=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&c.push(o>>>0),c}function ia(t){ir(t);let e=2**8;return{encode:r=>{if(!kr(r))throw new Error("radix.encode input should be Uint8Array");return qo(Array.from(r),e,t)},decode:r=>(zo("radix.decode",r),Uint8Array.from(qo(r,t,e)))}}function jo(t,e=!1){if(ir(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Bn(8,t)>32||Bn(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!kr(r))throw new Error("radix2.encode input should be Uint8Array");return Sn(Array.from(r),8,t,!e)},decode:r=>(zo("radix2.decode",r),Uint8Array.from(Sn(r,t,8,e)))}}function ta(t){return Vo(t),function(...e){try{return t.apply(null,e)}catch{}}}function sa(t,e){return ir(t),Vo(e),{encode(r){if(!kr(r))throw new Error("checksum.encode: input should be Uint8Array");let n=e(r).slice(0,t),o=new Uint8Array(r.length+t);return o.set(r),o.set(n,r.length),o},decode(r){if(!kr(r))throw new Error("checksum.decode: input should be Uint8Array");let n=r.slice(0,-t),o=r.slice(-t),i=e(n).slice(0,t);for(let s=0;sTr(ia(58),An(t),kn("")),zf=Vf("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var Tn=t=>Tr(sa(4,e=>t(t(e))),zf);var Wo=Tr(An("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),kn("")),ea=[996825010,642813549,513874426,1027748829,705979059];function Ar(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n>n&1)===1&&(r^=ea[n]);return r}function ra(t,e,r=1){let n=t.length,o=1;for(let i=0;i126)throw new Error(`Invalid prefix (${t})`);o=Ar(o)^s>>5}o=Ar(o);for(let i=0;iy)throw new TypeError(`Length ${E} exceeds limit ${y}`);let p=u.toLowerCase(),A=ra(p,l,e);return`${p}1${Wo.encode(l)}${A}`}function a(u,l=90){or("bech32.decode input",u);let y=u.length;if(y<8||l!==!1&&y>l)throw new TypeError(`invalid string length: ${y} (${u}). Expected (8..${l})`);let N=u.toLowerCase();if(u!==N&&u!==u.toUpperCase())throw new Error("String must be lowercase or uppercase");let E=N.lastIndexOf("1");if(E===0||E===-1)throw new Error('Letter "1" must be present between prefix and data only');let p=N.slice(0,E),A=N.slice(E+1);if(A.length<6)throw new Error("Data must be at least 6 characters long");let m=Wo.decode(A).slice(0,-6),b=ra(p,m,e);if(!A.endsWith(b))throw new Error(`Invalid checksum in ${u}: expected "${b}"`);return{prefix:p,words:m}}let c=ta(a);function f(u){let{prefix:l,words:y}=a(u,!1);return{prefix:l,words:y,bytes:n(y)}}function h(u,l){return s(u,o(l))}return{encode:s,decode:a,encodeFromBytes:h,decodeToBytes:f,decodeUnsafe:c,fromWords:n,fromWordsUnsafe:i,toWords:o}}var In=aa("bech32"),Yo=aa("bech32m");var at=Tr(jo(4),An("0123456789abcdef"),kn(""),Wf(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var ht;(function(t){t[t.OP_0=0]="OP_0",t[t.PUSHDATA1=76]="PUSHDATA1",t[t.PUSHDATA2=77]="PUSHDATA2",t[t.PUSHDATA4=78]="PUSHDATA4",t[t["1NEGATE"]=79]="1NEGATE",t[t.RESERVED=80]="RESERVED",t[t.OP_1=81]="OP_1",t[t.OP_2=82]="OP_2",t[t.OP_3=83]="OP_3",t[t.OP_4=84]="OP_4",t[t.OP_5=85]="OP_5",t[t.OP_6=86]="OP_6",t[t.OP_7=87]="OP_7",t[t.OP_8=88]="OP_8",t[t.OP_9=89]="OP_9",t[t.OP_10=90]="OP_10",t[t.OP_11=91]="OP_11",t[t.OP_12=92]="OP_12",t[t.OP_13=93]="OP_13",t[t.OP_14=94]="OP_14",t[t.OP_15=95]="OP_15",t[t.OP_16=96]="OP_16",t[t.NOP=97]="NOP",t[t.VER=98]="VER",t[t.IF=99]="IF",t[t.NOTIF=100]="NOTIF",t[t.VERIF=101]="VERIF",t[t.VERNOTIF=102]="VERNOTIF",t[t.ELSE=103]="ELSE",t[t.ENDIF=104]="ENDIF",t[t.VERIFY=105]="VERIFY",t[t.RETURN=106]="RETURN",t[t.TOALTSTACK=107]="TOALTSTACK",t[t.FROMALTSTACK=108]="FROMALTSTACK",t[t["2DROP"]=109]="2DROP",t[t["2DUP"]=110]="2DUP",t[t["3DUP"]=111]="3DUP",t[t["2OVER"]=112]="2OVER",t[t["2ROT"]=113]="2ROT",t[t["2SWAP"]=114]="2SWAP",t[t.IFDUP=115]="IFDUP",t[t.DEPTH=116]="DEPTH",t[t.DROP=117]="DROP",t[t.DUP=118]="DUP",t[t.NIP=119]="NIP",t[t.OVER=120]="OVER",t[t.PICK=121]="PICK",t[t.ROLL=122]="ROLL",t[t.ROT=123]="ROT",t[t.SWAP=124]="SWAP",t[t.TUCK=125]="TUCK",t[t.CAT=126]="CAT",t[t.SUBSTR=127]="SUBSTR",t[t.LEFT=128]="LEFT",t[t.RIGHT=129]="RIGHT",t[t.SIZE=130]="SIZE",t[t.INVERT=131]="INVERT",t[t.AND=132]="AND",t[t.OR=133]="OR",t[t.XOR=134]="XOR",t[t.EQUAL=135]="EQUAL",t[t.EQUALVERIFY=136]="EQUALVERIFY",t[t.RESERVED1=137]="RESERVED1",t[t.RESERVED2=138]="RESERVED2",t[t["1ADD"]=139]="1ADD",t[t["1SUB"]=140]="1SUB",t[t["2MUL"]=141]="2MUL",t[t["2DIV"]=142]="2DIV",t[t.NEGATE=143]="NEGATE",t[t.ABS=144]="ABS",t[t.NOT=145]="NOT",t[t["0NOTEQUAL"]=146]="0NOTEQUAL",t[t.ADD=147]="ADD",t[t.SUB=148]="SUB",t[t.MUL=149]="MUL",t[t.DIV=150]="DIV",t[t.MOD=151]="MOD",t[t.LSHIFT=152]="LSHIFT",t[t.RSHIFT=153]="RSHIFT",t[t.BOOLAND=154]="BOOLAND",t[t.BOOLOR=155]="BOOLOR",t[t.NUMEQUAL=156]="NUMEQUAL",t[t.NUMEQUALVERIFY=157]="NUMEQUALVERIFY",t[t.NUMNOTEQUAL=158]="NUMNOTEQUAL",t[t.LESSTHAN=159]="LESSTHAN",t[t.GREATERTHAN=160]="GREATERTHAN",t[t.LESSTHANOREQUAL=161]="LESSTHANOREQUAL",t[t.GREATERTHANOREQUAL=162]="GREATERTHANOREQUAL",t[t.MIN=163]="MIN",t[t.MAX=164]="MAX",t[t.WITHIN=165]="WITHIN",t[t.RIPEMD160=166]="RIPEMD160",t[t.SHA1=167]="SHA1",t[t.SHA256=168]="SHA256",t[t.HASH160=169]="HASH160",t[t.HASH256=170]="HASH256",t[t.CODESEPARATOR=171]="CODESEPARATOR",t[t.CHECKSIG=172]="CHECKSIG",t[t.CHECKSIGVERIFY=173]="CHECKSIGVERIFY",t[t.CHECKMULTISIG=174]="CHECKMULTISIG",t[t.CHECKMULTISIGVERIFY=175]="CHECKMULTISIGVERIFY",t[t.NOP1=176]="NOP1",t[t.CHECKLOCKTIMEVERIFY=177]="CHECKLOCKTIMEVERIFY",t[t.CHECKSEQUENCEVERIFY=178]="CHECKSEQUENCEVERIFY",t[t.NOP4=179]="NOP4",t[t.NOP5=180]="NOP5",t[t.NOP6=181]="NOP6",t[t.NOP7=182]="NOP7",t[t.NOP8=183]="NOP8",t[t.NOP9=184]="NOP9",t[t.NOP10=185]="NOP10",t[t.CHECKSIGADD=186]="CHECKSIGADD",t[t.INVALID=255]="INVALID"})(ht||(ht={}));function fa(t=6,e=!1){return Bt({encodeStream:(r,n)=>{if(n===0n)return;let o=n<0,i=BigInt(n),s=[];for(let a=o?-i:i;a;a>>=8n)s.push(Number(a&0xffn));s[s.length-1]>=128?s.push(o?128:0):o&&(s[s.length-1]|=128),r.bytes(new Uint8Array(s))},decodeStream:r=>{let n=r.leftBytes;if(n>t)throw new Error(`ScriptNum: number (${n}) bigger than limit=${t}`);if(n===0)return 0n;if(e){let s=r.bytes(n,!0);if(!(s[s.length-1]&127)&&(n<=1||!(s[s.length-2]&128)))throw new Error("Non-minimally encoded ScriptNum")}let o=0,i=0n;for(let s=0;s=128&&(i&=2n**BigInt(n*8)-1n>>1n,i=-i),i}})}function ua(t,e=4,r=!0){if(typeof t=="number")return t;if(J(t))try{let n=fa(e,r).decode(t);return n>Number.MAX_SAFE_INTEGER?void 0:Number(n)}catch{return}}var ct=Bt({encodeStream:(t,e)=>{for(let r of e){if(typeof r=="string"){if(ht[r]===void 0)throw new Error(`Unknown opcode=${r}`);t.byte(ht[r]);continue}else if(typeof r=="number"){if(r===0){t.byte(0);continue}else if(1<=r&&r<=16){t.byte(ht.OP_1-1+r);continue}}if(typeof r=="number"&&(r=fa().encode(BigInt(r))),!J(r))throw new Error(`Wrong Script OP=${r} (${typeof r})`);let n=r.length;n{let e=[];for(;!t.isEnd();){let r=t.byte();if(ht.OP_0{if(typeof e=="number"&&(e=BigInt(e)),0n<=e&&e<=252n)return t.byte(Number(e));for(let[r,n,o,i]of Object.values(ca))if(!(o>e||e>i)){t.byte(r);for(let s=0;s>8n*BigInt(s)&0xffn));return}throw t.err(`VarInt too big: ${e}`)},decodeStream:t=>{let e=t.byte();if(e<=252)return BigInt(e);let[r,n,o]=ca[e],i=0n;for(let s=0;sSt(Ur,t),la=ft({txid:et(32,!0),index:Q,finalScriptSig:Tt,sequence:Q}),ne=ft({amount:Qe,script:Tt}),jf=ft({version:le,segwitFlag:fs(new Uint8Array([0,1])),inputs:Un(la),outputs:Un(ne),witnesses:us("segwitFlag",St("inputs/length",sr)),lockTime:Q});function Yf(t){if(t.segwitFlag&&t.witnesses&&!t.witnesses.length)throw new Error("Segwit flag with empty witnesses array");return t}var oe=vt(jf,Yf),$e=ft({version:le,inputs:Un(la),outputs:Un(ne),lockTime:Q});function Lr(t){if(t.nonWitnessUtxo){if(t.index===void 0)throw new Error("Unknown input index");return t.nonWitnessUtxo.outputs[t.index]}else{if(t.witnessUtxo)return t.witnessUtxo;throw new Error("Cannot find previous output info")}}function Go(t,e,r,n=!1){let{nonWitnessUtxo:o,txid:i}=t;typeof o=="string"&&(o=at.decode(o)),J(o)&&(o=oe.decode(o)),!("nonWitnessUtxo"in t)&&o===void 0&&(o=e?.nonWitnessUtxo),typeof i=="string"&&(i=at.decode(i)),i===void 0&&(i=e?.txid);let s={...e,...t,nonWitnessUtxo:o,txid:i};!("nonWitnessUtxo"in t)&&s.nonWitnessUtxo===void 0&&delete s.nonWitnessUtxo,s.sequence===void 0&&(s.sequence=Fo),s.tapMerkleRoot===null&&delete s.tapMerkleRoot,s=Nr(cr,s,e,r),Ln.encode(s);let a;return s.nonWitnessUtxo&&s.index!==void 0?a=s.nonWitnessUtxo.outputs[s.index]:s.witnessUtxo&&(a=s.witnessUtxo),a&&!n&&Nn(a&&a.script,s.redeemScript,s.witnessScript),s}function Zo(t,e=!1){let r="legacy",n=tt.ALL,o=Lr(t),i=Et.decode(o.script),s=i.type,a=i,c=[i];if(i.type==="tr")return n=tt.DEFAULT,{txType:"taproot",type:"tr",last:i,lastScript:o.script,defaultSighash:n,sighash:t.sighashType||n};{if((i.type==="wpkh"||i.type==="wsh")&&(r="segwit"),i.type==="sh"){if(!t.redeemScript)throw new Error("inputType: sh without redeemScript");let l=Et.decode(t.redeemScript);(l.type==="wpkh"||l.type==="wsh")&&(r="segwit"),c.push(l),a=l,s+=`-${l.type}`}if(a.type==="wsh"){if(!t.witnessScript)throw new Error("inputType: wsh without witnessScript");let l=Et.decode(t.witnessScript);l.type==="wsh"&&(r="segwit"),c.push(l),a=l,s+=`-${l.type}`}let f=c[c.length-1];if(f.type==="sh"||f.type==="wsh")throw new Error("inputType: sh/wsh cannot be terminal type");let h=Et.encode(f),u={type:s,txType:r,last:f,lastScript:h,defaultSighash:n,sighash:t.sighashType||n};if(r==="legacy"&&!e&&!t.nonWitnessUtxo)throw new Error("Transaction/sign: legacy input without nonWitnessUtxo, can result in attack that forces paying higher fees. Pass allowLegacyWitnessUtxo=true, if you sure");return u}}var da=t=>Math.ceil(t/4);var Cn=new Uint8Array(32),Gf={amount:0xffffffffffffffffn,script:rt},Zf=8,Ff=2,Me=0,Fo=4294967295,th=ue.decimal(Zf),_r=(t,e)=>t===void 0?e:t;function _n(t){if(Array.isArray(t))return t.map(e=>_n(e));if(J(t))return Uint8Array.from(t);if(["number","bigint","boolean","string","undefined"].includes(typeof t))return t;if(t===null)return t;if(typeof t=="object")return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,_n(r)]));throw new Error(`cloneDeep: unknown type=${t} (${typeof t})`)}var tt;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.ANYONECANPAY=128]="ANYONECANPAY"})(tt||(tt={}));var Jo;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.DEFAULT_ANYONECANPAY=128]="DEFAULT_ANYONECANPAY",t[t.ALL_ANYONECANPAY=129]="ALL_ANYONECANPAY",t[t.NONE_ANYONECANPAY=130]="NONE_ANYONECANPAY",t[t.SINGLE_ANYONECANPAY=131]="SINGLE_ANYONECANPAY"})(Jo||(Jo={}));function Qf(t,e,r,n=rt){return st(r,e)&&(t=Xs(t,n),e=bn(t)),{privKey:t,pubKey:e}}function De(t){if(t.script===void 0||t.amount===void 0)throw new Error("Transaction/output: script and amount required");return{script:t.script,amount:t.amount}}function ar(t){if(t.txid===void 0||t.index===void 0)throw new Error("Transaction/input: txid and index required");return{txid:t.txid,index:t.index,sequence:_r(t.sequence,Fo),finalScriptSig:_r(t.finalScriptSig,rt)}}function Qo(t){for(let e in t){let r=e;ga.includes(r)||delete t[r]}}var Xo=ft({txid:et(32,!0),index:Q});function Xf(t){if(typeof t!="number"||typeof Jo[t]!="string")throw new Error(`Invalid SigHash=${t}`);return t}function pa(t){let e=t&31;return{isAny:!!(t&tt.ANYONECANPAY),isNone:e===tt.NONE,isSingle:e===tt.SINGLE}}function Jf(t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error(`Wrong object type for transaction options: ${t}`);let e={...t,version:_r(t.version,Ff),lockTime:_r(t.lockTime,0),PSBTVersion:_r(t.PSBTVersion,0)};if(typeof e.allowUnknowInput<"u"&&(t.allowUnknownInputs=e.allowUnknowInput),typeof e.allowUnknowOutput<"u"&&(t.allowUnknownOutputs=e.allowUnknowOutput),![-1,0,1,2].includes(e.version))throw new Error(`Unknown version: ${e.version}`);if(typeof e.lockTime!="number")throw new Error("Transaction lock time should be number");if(Q.encode(e.lockTime),e.PSBTVersion!==0&&e.PSBTVersion!==2)throw new Error(`Unknown PSBT version ${e.PSBTVersion}`);for(let r of["allowUnknownOutputs","allowUnknownInputs","disableScriptCheck","bip174jsCompat","allowLegacyWitnessUtxo","lowR"]){let n=e[r];if(n!==void 0&&typeof n!="boolean")throw new Error(`Transation options wrong type: ${r}=${n} (${typeof n})`)}if(e.customScripts!==void 0){let r=e.customScripts;if(!Array.isArray(r))throw new Error(`wrong custom scripts type (expected array): customScripts=${r} (${typeof r})`);for(let n of r){if(typeof n.encode!="function"||typeof n.decode!="function")throw new Error(`wrong script=${n} (${typeof n})`);if(n.finalizeTaproot!==void 0&&typeof n.finalizeTaproot!="function")throw new Error(`wrong script=${n} (${typeof n})`)}}return Object.freeze(e)}var xe=class t{constructor(e={}){this.global={},this.inputs=[],this.outputs=[];let r=this.opts=Jf(e);r.lockTime!==Me&&(this.global.fallbackLocktime=r.lockTime),this.global.txVersion=r.version}static fromRaw(e,r={}){let n=oe.decode(e),o=new t({...r,version:n.version,lockTime:n.lockTime});for(let i of n.outputs)o.addOutput(i);if(o.outputs=n.outputs,o.inputs=n.inputs,n.witnesses)for(let i=0;i({finalScriptSig:rt,...n.global.unsignedTx?.inputs[l],...u}));let h=o===0?i?.outputs.length:n.global.outputCount;return c.outputs=n.outputs.slice(0,h).map((u,l)=>({...u,...n.global.unsignedTx?.outputs[l]})),c.global={...n.global,txVersion:s},a!==Me&&(c.global.fallbackLocktime=a),c}toPSBT(e=this.opts.PSBTVersion){if(e!==0&&e!==2)throw new Error(`Wrong PSBT version=${e}`);let r=this.inputs.map(i=>ti(e,cr,i));for(let i of r)i.partialSig&&!i.partialSig.length&&delete i.partialSig,i.finalScriptSig&&!i.finalScriptSig.length&&delete i.finalScriptSig,i.finalScriptWitness&&!i.finalScriptWitness.length&&delete i.finalScriptWitness;let n=this.outputs.map(i=>ti(e,Pr,i)),o={...this.global};return e===0?(o.unsignedTx=$e.decode($e.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(ar).map(i=>({...i,finalScriptSig:rt})),outputs:this.outputs.map(De)})),delete o.fallbackLocktime,delete o.txVersion):(o.version=e,o.txVersion=this.version,o.inputCount=this.inputs.length,o.outputCount=this.outputs.length,o.fallbackLocktime&&o.fallbackLocktime===Me&&delete o.fallbackLocktime),this.opts.bip174jsCompat&&(r.length||r.push({}),n.length||n.push({})),(e===0?ei:ri).encode({global:o,inputs:r,outputs:n})}get lockTime(){let e=Me,r=0,n=Me,o=0;for(let i of this.inputs)i.requiredHeightLocktime&&(e=Math.max(e,i.requiredHeightLocktime),r++),i.requiredTimeLocktime&&(n=Math.max(n,i.requiredTimeLocktime),o++);return r&&r>=o?e:n!==Me?n:this.global.fallbackLocktime||Me}get version(){if(this.global.txVersion===void 0)throw new Error("No global.txVersion");return this.global.txVersion}inputStatus(e){this.checkInputIdx(e);let r=this.inputs[e];return r.finalScriptSig&&r.finalScriptSig.length||r.finalScriptWitness&&r.finalScriptWitness.length?"finalized":r.tapKeySig||r.tapScriptSig&&r.tapScriptSig.length||r.partialSig&&r.partialSig.length?"signed":"unsigned"}inputSighash(e){this.checkInputIdx(e);let r=this.inputs[e].sighashType,n=r===void 0?tt.DEFAULT:r,o=n===tt.DEFAULT?tt.ALL:n&3;return{sigInputs:n&tt.ANYONECANPAY,sigOutputs:o}}signStatus(){let e=!0,r=!0,n=[],o=[];for(let i=0;i({...n,finalScriptSig:e&&n.finalScriptSig||rt})),outputs:this.outputs.map(De),witnesses:this.inputs.map(n=>n.finalScriptWitness||[]),segwitFlag:r&&this.hasWitnesses})}get unsignedTx(){return this.toBytes(!1,!1)}get hex(){return at.encode(this.toBytes(!0,this.hasWitnesses))}get hash(){if(!this.isFinal)throw new Error("Transaction is not finalized");return at.encode(ee(this.toBytes(!0)))}get id(){if(!this.isFinal)throw new Error("Transaction is not finalized");return at.encode(ee(this.toBytes(!0)).reverse())}checkInputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.inputs.length)throw new Error(`Wrong input index=${e}`)}getInput(e){return this.checkInputIdx(e),_n(this.inputs[e])}get inputsLength(){return this.inputs.length}addInput(e,r=!1){if(!r&&!this.signStatus().addInput)throw new Error("Tx has signed inputs, cannot add new one");return this.inputs.push(Go(e,void 0,void 0,this.opts.disableScriptCheck)),this.inputs.length-1}updateInput(e,r,n=!1){this.checkInputIdx(e);let o;if(!n){let i=this.signStatus();(!i.addInput||i.inputs.includes(e))&&(o=wa)}this.inputs[e]=Go(r,this.inputs[e],o,this.opts.disableScriptCheck)}checkOutputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.outputs.length)throw new Error(`Wrong output index=${e}`)}getOutput(e){return this.checkOutputIdx(e),_n(this.outputs[e])}getOutputAddress(e,r=re){let n=this.getOutput(e);if(n.script)return Ee(r).encode(Et.decode(n.script))}get outputsLength(){return this.outputs.length}normalizeOutput(e,r,n){let{amount:o,script:i}=e;if(o===void 0&&(o=r?.amount),typeof o!="bigint")throw new Error(`Wrong amount type, should be of type bigint in sats, but got ${o} of type ${typeof o}`);typeof i=="string"&&(i=at.decode(i)),i===void 0&&(i=r?.script);let s={...r,...e,amount:o,script:i};if(s.amount===void 0&&delete s.amount,s=Nr(Pr,s,r,n),Rn.encode(s),s.script&&!this.opts.allowUnknownOutputs&&Et.decode(s.script).type==="unknown")throw new Error("Transaction/output: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure");return this.opts.disableScriptCheck||Nn(s.script,s.redeemScript,s.witnessScript),s}addOutput(e,r=!1){if(!r&&!this.signStatus().addOutput)throw new Error("Tx has signed outputs, cannot add new one");return this.outputs.push(this.normalizeOutput(e)),this.outputs.length-1}updateOutput(e,r,n=!1){this.checkOutputIdx(e);let o;if(!n){let i=this.signStatus();(!i.addOutput||i.outputs.includes(e))&&(o=ya)}this.outputs[e]=this.normalizeOutput(r,this.outputs[e],o)}addOutputAddress(e,r,n=re){return this.addOutput({script:Et.encode(Ee(n).decode(e)),amount:r})}get fee(){let e=0n;for(let n of this.inputs){let o=Lr(n);if(!o)throw new Error("Empty input amount");e+=o.amount}let r=this.outputs.map(De);for(let n of r)e-=n.amount;return e}preimageLegacy(e,r,n){let{isAny:o,isNone:i,isSingle:s}=pa(n);if(e<0||!Number.isSafeInteger(e))throw new Error(`Invalid input idx=${e}`);if(s&&e>=this.outputs.length||e>=this.inputs.length)return os.encode(1n);r=ct.encode(ct.decode(r).filter(h=>h!=="CODESEPARATOR"));let a=this.inputs.map(ar).map((h,u)=>({...h,finalScriptSig:u===e?r:rt}));o?a=[a[e]]:(i||s)&&(a=a.map((h,u)=>({...h,sequence:u===e?h.sequence:0})));let c=this.outputs.map(De);i?c=[]:s&&(c=c.slice(0,e).fill(Gf).concat([c[e]]));let f=oe.encode({lockTime:this.lockTime,version:this.version,segwitFlag:!1,inputs:a,outputs:c});return ee(f,le.encode(n))}preimageWitnessV0(e,r,n,o){let{isAny:i,isNone:s,isSingle:a}=pa(n),c=Cn,f=Cn,h=Cn,u=this.inputs.map(ar),l=this.outputs.map(De);i||(c=ee(...u.map(Xo.encode))),!i&&!a&&!s&&(f=ee(...u.map(N=>Q.encode(N.sequence)))),!a&&!s?h=ee(...l.map(ne.encode)):a&&eQ.encode(E.sequence))].map(E=>kt(te(...E)))),h===tt.ALL&&f.push(kt(te(...y.map(ne.encode))));let N=(c?1:0)|(s?2:0);if(f.push(new Uint8Array([N])),u===tt.ANYONECANPAY){let E=l[e];f.push(Xo.encode(E),Qe.encode(o[e]),Tt.encode(r[e]),Q.encode(E.sequence))}else f.push(Q.encode(e));return N&1&&f.push(kt(Tt.encode(c||rt))),h===tt.SINGLE&&f.push(el[1].fingerprint==e.fingerprint).map(([l,{path:y}])=>{let N=e;for(let E of y)N=N.deriveChild(E);if(!st(N.publicKey,l))throw new Error("bip32Derivation: wrong pubKey");if(!N.privateKey)throw new Error("bip32Derivation: no privateKey");return N});if(!h.length)throw new Error(`bip32Derivation: no items with fingerprint=${e.fingerprint}`);let u=!1;for(let l of h)this.signIdx(l.privateKey,r)&&(u=!0);return u}n?n.forEach(Xf):n=[s.defaultSighash];let a=s.sighash;if(!n.includes(a))throw new Error(`Input with not allowed sigHash=${a}. Allowed: ${n.join(", ")}`);let{sigOutputs:c}=this.inputSighash(r);if(c===tt.SINGLE&&r>=this.outputs.length)throw new Error(`Input with sighash SINGLE, but there is no output with corresponding index=${r}`);let f=Lr(i);if(s.txType==="taproot"){let h=this.inputs.map(Lr),u=h.map(p=>p.script),l=h.map(p=>p.amount),y=!1,N=bn(e),E=i.tapMerkleRoot||rt;if(i.tapInternalKey){let{pubKey:p,privKey:A}=Qf(e,N,i.tapInternalKey,E),[m,b]=Mo(i.tapInternalKey,E);if(st(m,p)){let v=this.preimageWitnessV1(r,u,a,l),x=te(Oo(v,A,o),a!==tt.DEFAULT?new Uint8Array([a]):rt);this.updateInput(r,{tapKeySig:x},!0),y=!0}}if(i.tapLeafScript){i.tapScriptSig=i.tapScriptSig||[];for(let[p,A]of i.tapLeafScript){let m=A.subarray(0,-1),b=ct.decode(m),v=A[A.length-1],x=Cr(m,v);if(b.findIndex(d=>J(d)&&st(d,N))===-1)continue;let B=this.preimageWitnessV1(r,u,a,l,void 0,m,v),g=te(Oo(B,e,o),a!==tt.DEFAULT?new Uint8Array([a]):rt);this.updateInput(r,{tapScriptSig:[[{pubKey:N,leafHash:x},g]]},!0),y=!0}}if(!y)throw new Error("No taproot scripts signed");return!0}else{let h=$o(e),u=!1,l=Br(h);for(let E of ct.decode(s.lastScript))J(E)&&(st(E,h)||st(E,l))&&(u=!0);if(!u)throw new Error(`Input script doesn't have pubKey: ${s.lastScript}`);let y;if(s.txType==="legacy")y=this.preimageLegacy(r,s.lastScript,a);else if(s.txType==="segwit"){let E=s.lastScript;s.last.type==="wpkh"&&(E=Et.encode({type:"pkh",hash:s.last.hash})),y=this.preimageWitnessV0(r,E,a,f.amount)}else throw new Error(`Transaction/sign: unknown tx type: ${s.txType}`);let N=Fs(y,e,this.opts.lowR);this.updateInput(r,{partialSig:[[h,te(N,new Uint8Array([a]))]]},!0)}return!0}sign(e,r,n){let o=0;for(let i=0;iOe.encode(f[0]).length-Oe.encode(h[0]).length);for(let[f,h]of c){let u=h.slice(0,-1),l=h[h.length-1],y=Et.decode(u),N=Cr(u,l),E=r.tapScriptSig.filter(A=>st(A[0].leafHash,N)),p=[];if(y.type==="tr_ms"){let A=y.m,m=y.pubkeys,b=0;for(let v of m){let x=E.findIndex(w=>st(w[0].pubKey,v));if(b===A||x===-1){p.push(rt);continue}p.push(E[x][1]),b++}if(b!==A)continue}else if(y.type==="tr_ns"){for(let A of y.pubkeys){let m=E.findIndex(b=>st(b[0].pubKey,A));m!==-1&&p.push(E[m][1])}if(p.length!==y.pubkeys.length)continue}else if(y.type==="unknown"&&this.opts.allowUnknownInputs){let A=ct.decode(u);if(p=E.map(([{pubKey:m},b])=>{let v=A.findIndex(x=>J(x)&&st(x,m));if(v===-1)throw new Error("finalize/taproot: cannot find position of pubkey in script");return{signature:b,pos:v}}).sort((m,b)=>m.pos-b.pos).map(m=>m.signature),!p.length)continue}else{let A=this.opts.customScripts;if(A)for(let m of A){if(!m.finalizeTaproot)continue;let b=ct.decode(u),v=m.encode(b);if(v===void 0)continue;let x=m.finalizeTaproot(u,v,E);if(x){r.finalScriptWitness=x.concat(Oe.encode(f)),r.finalScriptSig=rt,Qo(r);return}}throw new Error("Finalize: Unknown tapLeafScript")}r.finalScriptWitness=p.reverse().concat([u,Oe.encode(f)]);break}if(!r.finalScriptWitness)throw new Error("finalize/taproot: empty witness")}else throw new Error("finalize/taproot: unknown input");r.finalScriptSig=rt,Qo(r);return}if(!r.partialSig||!r.partialSig.length)throw new Error("Not enough partial sign");let o=rt,i=[];if(n.last.type==="ms"){let c=n.last.m,f=n.last.pubkeys,h=[];for(let u of f){let l=r.partialSig.find(y=>st(u,y[0]));l&&h.push(l[1])}if(h=h.slice(0,c),h.length!==c)throw new Error(`Multisig: wrong signatures count, m=${c} n=${f.length} signatures=${h.length}`);o=ct.encode([0,...h])}else if(n.last.type==="pk")o=ct.encode([r.partialSig[0][1]]);else if(n.last.type==="pkh")o=ct.encode([r.partialSig[0][1],r.partialSig[0][0]]);else if(n.last.type==="wpkh")o=rt,i=[r.partialSig[0][1],r.partialSig[0][0]];else if(n.last.type==="unknown"&&!this.opts.allowUnknownInputs)throw new Error("Unknown inputs not allowed");let s,a;if(n.type.includes("wsh-")&&(o.length&&n.lastScript.length&&(i=ct.decode(o).map(c=>{if(c===0)return rt;if(J(c))return c;throw new Error(`Wrong witness op=${c}`)})),i=i.concat(n.lastScript)),n.txType==="segwit"&&(a=i),n.type.startsWith("sh-wsh-")?s=ct.encode([ct.encode([0,kt(n.lastScript)])]):n.type.startsWith("sh-")?s=ct.encode([...ct.decode(o),n.lastScript]):n.type.startsWith("wsh-")||n.txType!=="segwit"&&(s=o),!s&&!a)throw new Error("Unknown error finalizing input");s&&(r.finalScriptSig=s),a&&(r.finalScriptWitness=a),Qo(r)}finalize(){for(let e=0;eme(t,xt.ecdsa)),Hn=vt(et(32),t=>me(t,xt.schnorr)),ba=vt(et(null),t=>{if(t.length!==64&&t.length!==65)throw new Error("Schnorr signature should be 64 or 65 bytes long");return t}),$n=ft({fingerprint:ss,path:St(null,Q)}),Ea=ft({hashes:St(It,et(32)),der:$n}),tu=et(78),eu=ft({pubKey:Hn,leafHash:et(32)}),ru=ft({version:$t,internalKey:et(32),merklePath:St(null,et(32))}),Oe=vt(ru,t=>{if(t.merklePath.length>128)throw new Error("TaprootControlBlock: merklePath should be of length 0..128 (inclusive)");return t}),nu=St(null,ft({depth:$t,version:$t,script:Tt})),pt=et(null),ma=et(20),Rr=et(32),Pn={unsignedTx:[0,!1,$e,[0],[0],!1],xpub:[1,tu,$n,[],[0,2],!1],txVersion:[2,!1,Q,[2],[2],!1],fallbackLocktime:[3,!1,Q,[],[2],!1],inputCount:[4,!1,It,[2],[2],!1],outputCount:[5,!1,It,[2],[2],!1],txModifiable:[6,!1,$t,[],[2],!1],version:[251,!1,Q,[],[0,2],!1],proprietary:[252,pt,pt,[],[0,2],!1]},cr={nonWitnessUtxo:[0,!1,oe,[],[0,2],!1],witnessUtxo:[1,!1,ne,[],[0,2],!1],partialSig:[2,oi,pt,[],[0,2],!1],sighashType:[3,!1,Q,[],[0,2],!1],redeemScript:[4,!1,pt,[],[0,2],!1],witnessScript:[5,!1,pt,[],[0,2],!1],bip32Derivation:[6,oi,$n,[],[0,2],!1],finalScriptSig:[7,!1,pt,[],[0,2],!1],finalScriptWitness:[8,!1,sr,[],[0,2],!1],porCommitment:[9,!1,pt,[],[0,2],!1],ripemd160:[10,ma,pt,[],[0,2],!1],sha256:[11,Rr,pt,[],[0,2],!1],hash160:[12,ma,pt,[],[0,2],!1],hash256:[13,Rr,pt,[],[0,2],!1],txid:[14,!1,Rr,[2],[2],!0],index:[15,!1,Q,[2],[2],!0],sequence:[16,!1,Q,[],[2],!0],requiredTimeLocktime:[17,!1,Q,[],[2],!1],requiredHeightLocktime:[18,!1,Q,[],[2],!1],tapKeySig:[19,!1,ba,[],[0,2],!1],tapScriptSig:[20,eu,ba,[],[0,2],!1],tapLeafScript:[21,Oe,pt,[],[0,2],!1],tapBip32Derivation:[22,Rr,Ea,[],[0,2],!1],tapInternalKey:[23,!1,Hn,[],[0,2],!1],tapMerkleRoot:[24,!1,Rr,[],[0,2],!1],proprietary:[252,pt,pt,[],[0,2],!1]},ga=["txid","sequence","index","witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknown"],wa=["partialSig","finalScriptSig","finalScriptWitness","tapKeySig","tapScriptSig"],Pr={redeemScript:[0,!1,pt,[],[0,2],!1],witnessScript:[1,!1,pt,[],[0,2],!1],bip32Derivation:[2,oi,$n,[],[0,2],!1],amount:[3,!1,is,[2],[2],!0],script:[4,!1,pt,[2],[2],!0],tapInternalKey:[5,!1,Hn,[],[0,2],!1],tapTree:[6,!1,nu,[],[0,2],!1],tapBip32Derivation:[7,Hn,Ea,[],[0,2],!1],proprietary:[252,pt,pt,[],[0,2],!1]},ya=[],xa=St(ro,ft({key:as(It,ft({type:It,key:et(null)})),value:et(It)}));function ii(t){let[e,r,n,o,i,s]=t;return{type:e,kc:r,vc:n,reqInc:o,allowInc:i,silentIgnore:s}}var ah=ft({type:It,key:et(null)});function si(t){let e={};for(let r in t){let[n,o,i]=t[r];e[n]=[r,o,i]}return Bt({encodeStream:(r,n)=>{let o=[];for(let i in t){let s=n[i];if(s===void 0)continue;let[a,c,f]=t[i];if(!c)o.push({key:{type:a,key:rt},value:f.encode(s)});else{let h=s.map(([u,l])=>[c.encode(u),f.encode(l)]);h.sort((u,l)=>Sr(u[0],l[0]));for(let[u,l]of h)o.push({key:{key:u,type:a},value:l})}}if(n.unknown){n.unknown.sort((i,s)=>Sr(i[0].key,s[0].key));for(let[i,s]of n.unknown)o.push({key:i,value:s})}xa.encodeStream(r,o)},decodeStream:r=>{let n=xa.decodeStream(r),o={},i={};for(let s of n){let a="unknown",c=s.key.key,f=s.value;if(e[s.key.type]){let[h,u,l]=e[s.key.type];if(a=h,!u&&c.length)throw new Error(`PSBT: Non-empty key for ${a} (key=${at.encode(c)} value=${at.encode(f)}`);if(c=u?u.decode(c):void 0,f=l.decode(f),!u){if(o[a])throw new Error(`PSBT: Same keys: ${a} (key=${c} value=${f})`);o[a]=f,i[a]=!0;continue}}else c={type:s.key.type,key:s.key.key};if(i[a])throw new Error(`PSBT: Key type with empty key and no key=${a} val=${f}`);o[a]||(o[a]=[]),o[a].push([c,f])}return o}})}var Ln=vt(si(cr),t=>{if(t.finalScriptWitness&&!t.finalScriptWitness.length)throw new Error("validateInput: empty finalScriptWitness");if(t.partialSig&&!t.partialSig.length)throw new Error("Empty partialSig");if(t.partialSig)for(let[e]of t.partialSig)me(e,xt.ecdsa);if(t.bip32Derivation)for(let[e]of t.bip32Derivation)me(e,xt.ecdsa);if(t.requiredTimeLocktime!==void 0&&t.requiredTimeLocktime<5e8)throw new Error(`validateInput: wrong timeLocktime=${t.requiredTimeLocktime}`);if(t.requiredHeightLocktime!==void 0&&(t.requiredHeightLocktime<=0||t.requiredHeightLocktime>=5e8))throw new Error(`validateInput: wrong heighLocktime=${t.requiredHeightLocktime}`);if(t.nonWitnessUtxo&&t.index!==void 0){let e=t.nonWitnessUtxo.outputs.length-1;if(t.index>e)throw new Error(`validateInput: index(${t.index}) not in nonWitnessUtxo`);let r=t.nonWitnessUtxo.outputs[t.index];if(t.witnessUtxo&&(!st(t.witnessUtxo.script,r.script)||t.witnessUtxo.amount!==r.amount))throw new Error("validateInput: witnessUtxo different from nonWitnessUtxo")}if(t.tapLeafScript)for(let[e,r]of t.tapLeafScript){if((e.version&254)!==r[r.length-1])throw new Error("validateInput: tapLeafScript version mimatch");if(r[r.length-1]&1)throw new Error("validateInput: tapLeafScript version has parity bit!")}if(t.nonWitnessUtxo&&t.index!==void 0&&t.txid){if(t.nonWitnessUtxo.outputs.length-1{if(t.bip32Derivation)for(let[e]of t.bip32Derivation)me(e,xt.ecdsa);return t}),va=vt(si(Pn),t=>{if((t.version||0)===0){if(!t.unsignedTx)throw new Error("PSBTv0: missing unsignedTx");for(let r of t.unsignedTx.inputs)if(r.finalScriptSig&&r.finalScriptSig.length)throw new Error("PSBTv0: input scriptSig found in unsignedTx")}return t}),ou=ft({magic:Yr(jr(new Uint8Array([255])),"psbt"),global:va,inputs:St("global/unsignedTx/inputs/length",Ln),outputs:St(null,Rn)}),iu=ft({magic:Yr(jr(new Uint8Array([255])),"psbt"),global:va,inputs:St("global/inputCount",Ln),outputs:St("global/outputCount",Rn)}),ch=ft({magic:Yr(jr(new Uint8Array([255])),"psbt"),items:St(null,Vt(St(ro,ds([cs(It),et(Ur)])),ue.dict()))});function ni(t,e,r){for(let n in r){if(n==="unknown"||!e[n])continue;let{allowInc:o}=ii(e[n]);if(!o.includes(t))throw new Error(`PSBTv${t}: field ${n} is not allowed`)}for(let n in e){let{reqInc:o}=ii(e[n]);if(o.includes(t)&&r[n]===void 0)throw new Error(`PSBTv${t}: missing required field ${n}`)}}function ti(t,e,r){let n={};for(let o in r){let i=o;if(i!=="unknown"){if(!e[i])continue;let{allowInc:s,silentIgnore:a}=ii(e[i]);if(!s.includes(t)){if(a)continue;throw new Error(`Failed to serialize in PSBTv${t}: ${i} but versions allows inclusion=${s}`)}}n[i]=r[i]}return n}function Ba(t){let e=t&&t.global&&t.global.version||0;ni(e,Pn,t.global);for(let s of t.inputs)ni(e,cr,s);for(let s of t.outputs)ni(e,Pr,s);let r=e?t.global.inputCount:t.global.unsignedTx.inputs.length;if(t.inputs.length1||n.length&&Object.keys(n[0]).length)throw new Error(`Unexpected inputs left in tx=${n}`);let o=e?t.global.outputCount:t.global.unsignedTx.outputs.length;if(t.outputs.length1||i.length&&Object.keys(i[0]).length)throw new Error(`Unexpected outputs left in tx=${i}`);return t}function Nr(t,e,r,n){let o={...r,...e};for(let i in t){let s=i,[a,c,f]=t[s],h=n&&!n.includes(i);if(e[i]===void 0&&i in e){if(h)throw new Error(`Cannot remove signed field=${i}`);delete o[i]}else if(c){let u=r&&r[i]?r[i]:[],l=e[s];if(l){if(!Array.isArray(l))throw new Error(`keyMap(${i}): KV pairs should be [k, v][]`);l=l.map(E=>{if(E.length!==2)throw new Error(`keyMap(${i}): KV pairs should be [k, v][]`);return[typeof E[0]=="string"?c.decode(at.decode(E[0])):E[0],typeof E[1]=="string"?f.decode(at.decode(E[1])):E[1]]});let y={},N=(E,p,A)=>{if(y[E]===void 0){y[E]=[p,A];return}let m=at.encode(f.encode(y[E][1])),b=at.encode(f.encode(A));if(m!==b)throw new Error(`keyMap(${s}): same key=${E} oldVal=${m} newVal=${b}`)};for(let[E,p]of u){let A=at.encode(c.encode(E));N(A,E,p)}for(let[E,p]of l){let A=at.encode(c.encode(E));if(p===void 0){if(h)throw new Error(`Cannot remove signed field=${s}/${E}`);delete y[A]}else N(A,E,p)}o[s]=Object.values(y)}}else if(typeof o[i]=="string")o[i]=f.decode(at.decode(o[i]));else if(h&&i in e&&r&&r[i]!==void 0&&!st(f.encode(e[i]),f.encode(r[i])))throw new Error(`Cannot change signed field=${i}`)}for(let i in o)t[i]||delete o[i];return o}var ei=vt(ou,Ba),ri=vt(iu,Ba);function fr(t,e){try{return me(t,e),!0}catch{return!1}}var su={encode(t){if(!(t.length!==2||!J(t[0])||!fr(t[0],xt.ecdsa)||t[1]!=="CHECKSIG"))return{type:"pk",pubkey:t[0]}},decode:t=>t.type==="pk"?[t.pubkey,"CHECKSIG"]:void 0},au={encode(t){if(!(t.length!==5||t[0]!=="DUP"||t[1]!=="HASH160"||!J(t[2]))&&!(t[3]!=="EQUALVERIFY"||t[4]!=="CHECKSIG"))return{type:"pkh",hash:t[2]}},decode:t=>t.type==="pkh"?["DUP","HASH160",t.hash,"EQUALVERIFY","CHECKSIG"]:void 0},cu={encode(t){if(!(t.length!==3||t[0]!=="HASH160"||!J(t[1])||t[2]!=="EQUAL"))return{type:"sh",hash:t[1]}},decode:t=>t.type==="sh"?["HASH160",t.hash,"EQUAL"]:void 0},fu={encode(t){if(!(t.length!==2||t[0]!==0||!J(t[1]))&&t[1].length===32)return{type:"wsh",hash:t[1]}},decode:t=>t.type==="wsh"?[0,t.hash]:void 0},uu={encode(t){if(!(t.length!==2||t[0]!==0||!J(t[1]))&&t[1].length===20)return{type:"wpkh",hash:t[1]}},decode:t=>t.type==="wpkh"?[0,t.hash]:void 0},lu={encode(t){let e=t.length-1;if(t[e]!=="CHECKMULTISIG")return;let r=t[0],n=t[e-1];if(typeof r!="number"||typeof n!="number")return;let o=t.slice(1,-2);if(n===o.length){for(let i of o)if(!J(i))return;return{type:"ms",m:r,pubkeys:o}}},decode:t=>t.type==="ms"?[t.m,...t.pubkeys,t.pubkeys.length,"CHECKMULTISIG"]:void 0},du={encode(t){if(!(t.length!==2||t[0]!==1||!J(t[1])))return{type:"tr",pubkey:t[1]}},decode:t=>t.type==="tr"?[1,t.pubkey]:void 0},hu={encode(t){let e=t.length-1;if(t[e]!=="CHECKSIG")return;let r=[];for(let n=0;n{if(t.type!=="tr_ns")return;let e=[];for(let r=0;r{if(t.type!=="tr_ms")return;let e=[t.pubkeys[0],"CHECKSIG"];for(let r=1;rt.type==="unknown"?ct.decode(t.script):void 0},wu=[su,au,cu,fu,uu,lu,du,hu,pu,gu],yu=Vt(ct,ue.match(wu)),Et=vt(yu,t=>{if(t.type==="pk"&&!fr(t.pubkey,xt.ecdsa))throw new Error("OutScript/pk: wrong key");if((t.type==="pkh"||t.type==="sh"||t.type==="wpkh")&&(!J(t.hash)||t.hash.length!==20))throw new Error(`OutScript/${t.type}: wrong hash`);if(t.type==="wsh"&&(!J(t.hash)||t.hash.length!==32))throw new Error("OutScript/wsh: wrong hash");if(t.type==="tr"&&(!J(t.pubkey)||!fr(t.pubkey,xt.schnorr)))throw new Error("OutScript/tr: wrong taproot public key");if((t.type==="ms"||t.type==="tr_ns"||t.type==="tr_ms")&&!Array.isArray(t.pubkeys))throw new Error("OutScript/multisig: wrong pubkeys array");if(t.type==="ms"){let e=t.pubkeys.length;for(let r of t.pubkeys)if(!fr(r,xt.ecdsa))throw new Error("OutScript/multisig: wrong pubkey");if(t.m<=0||e>16||t.m>e)throw new Error("OutScript/multisig: invalid params")}if(t.type==="tr_ns"||t.type==="tr_ms"){for(let e of t.pubkeys)if(!fr(e,xt.schnorr))throw new Error(`OutScript/${t.type}: wrong pubkey`)}if(t.type==="tr_ms"){let e=t.pubkeys.length;if(t.m<=0||e>999||t.m>e)throw new Error("OutScript/tr_ms: invalid params")}return t});function Sa(t,e){if(!st(t.hash,kt(e)))throw new Error("checkScript: wsh wrong witnessScript hash");let r=Et.decode(e);if(r.type==="tr"||r.type==="tr_ns"||r.type==="tr_ms")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2SH`);if(r.type==="wpkh"||r.type==="sh")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2WSH`)}function Nn(t,e,r){if(t){let n=Et.decode(t);if(n.type==="tr_ns"||n.type==="tr_ms"||n.type==="ms"||n.type=="pk")throw new Error(`checkScript: non-wrapped ${n.type}`);if(n.type==="sh"&&e){if(!st(n.hash,Br(e)))throw new Error("checkScript: sh wrong redeemScript hash");let o=Et.decode(e);if(o.type==="tr"||o.type==="tr_ns"||o.type==="tr_ms")throw new Error(`checkScript: P2${o.type} cannot be wrapped in P2SH`);if(o.type==="sh")throw new Error("checkScript: P2SH cannot be wrapped in P2SH")}n.type==="wsh"&&r&&Sa(n,r)}if(e){let n=Et.decode(e);n.type==="wsh"&&r&&Sa(n,r)}}var ci=(t,e=re)=>{if(!fr(t,xt.ecdsa))throw new Error("P2WPKH: invalid publicKey");if(t.length===65)throw new Error("P2WPKH: uncompressed public key");let r=Br(t);return{type:"wpkh",script:Et.encode({type:"wpkh",hash:r}),address:Ee(e).encode({type:"wpkh",hash:r})}};var bu=192,Cr=(t,e=bu)=>mn("TapLeaf",new Uint8Array([e]),Tt.encode(t));var ka=Tn(kt);function Ta(t,e){if(e.length<2||e.length>40)throw new Error("Witness: invalid length");if(t>16)throw new Error("Witness: invalid version");if(t===0&&!(e.length===20||e.length===32))throw new Error("Witness: invalid length for version")}function ai(t,e,r=re){Ta(t,e);let n=t===0?In:Yo;return n.encode(r.bech32,[t].concat(n.toWords(e)))}function Aa(t,e){return ka.encode(te(Uint8Array.from(e),t))}function Ee(t=re){return{encode(e){let{type:r}=e;if(r==="wpkh")return ai(0,e.hash,t);if(r==="wsh")return ai(0,e.hash,t);if(r==="tr")return ai(1,e.pubkey,t);if(r==="pkh")return Aa(e.hash,[t.pubKeyHash]);if(r==="sh")return Aa(e.hash,[t.scriptHash]);throw new Error(`Unknown address type=${r}`)},decode(e){if(e.length<14||e.length>74)throw new Error("Invalid address length");if(t.bech32&&e.toLowerCase().startsWith(`${t.bech32}1`)){let n;try{if(n=In.decode(e),n.words[0]!==0)throw new Error(`bech32: wrong version=${n.words[0]}`)}catch{if(n=Yo.decode(e),n.words[0]===0)throw new Error(`bech32m: wrong version=${n.words[0]}`)}if(n.prefix!==t.bech32)throw new Error(`wrong bech32 prefix=${n.prefix}`);let[o,...i]=n.words,s=In.fromWords(i);if(Ta(o,s),o===0&&s.length===32)return{type:"wsh",hash:s};if(o===0&&s.length===20)return{type:"wpkh",hash:s};if(o===1&&s.length===32)return{type:"tr",pubkey:s};throw new Error("Unknown witness program")}let r=ka.decode(e);if(r.length!==21)throw new Error("Invalid base58 address");if(r[0]===t.pubKeyHash)return{type:"pkh",hash:r.slice(1)};if(r[0]===t.scriptHash)return{type:"sh",hash:r.slice(1)};throw new Error(`Invalid address prefix=${r[0]}`)}}}function ve(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function xu(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function At(t,...e){if(!xu(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function On(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ve(t.outputLen),ve(t.blockLen)}function ur(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Ia(t,e){At(t);let r=e.outputLen;if(t.length>>e}function Hr(t,e){return t<>>32-e>>>0}var La=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Eu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Na(t){if(At(t),La)return t.toHex();let e="";for(let r=0;r=ie._0&&t<=ie._9)return t-ie._0;if(t>=ie.A&&t<=ie.F)return t-(ie.A-10);if(t>=ie.a&&t<=ie.f)return t-(ie.a-10)}function Ca(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(La)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;ot().update(Be(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Mn(t=32){if(Ke&&typeof Ke.getRandomValues=="function")return Ke.getRandomValues(new Uint8Array(t));if(Ke&&typeof Ke.randomBytes=="function")return Uint8Array.from(Ke.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}var Dn=class extends lr{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,On(e);let n=Be(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;snew Dn(t,e).update(r).digest();Se.create=(t,e)=>new Dn(t,e);function vu(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+f,a,n)}function Pa(t,e,r){return t&e^~t&r}function Ra(t,e,r){return t&e^t&r^e&r}var Ae=class extends lr{constructor(e,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Yt(this.buffer)}update(e){ur(this);let{view:r,buffer:n,blockLen:o}=this;e=Be(e);let i=e.length;for(let s=0;so-s&&(this.process(n,0),s=0);for(let u=s;uh.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;ue)),Su=$a.map(t=>(9*t+5)%16),li=[$a],di=[Su];for(let t=0;t<4;t++)for(let e of[li,di])e.push(e[t].map(r=>Bu[r]));var Oa=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>new Uint8Array(t)),Au=li.map((t,e)=>t.map(r=>Oa[e][r])),ku=di.map((t,e)=>t.map(r=>Oa[e][r])),Tu=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Iu=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function Ha(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var Kn=new Uint32Array(16),ui=class extends Ae{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:r,h2:n,h3:o,h4:i}=this;return[e,r,n,o,i]}set(e,r,n,o,i){this.h0=e|0,this.h1=r|0,this.h2=n|0,this.h3=o|0,this.h4=i|0}process(e,r){for(let y=0;y<16;y++,r+=4)Kn[y]=e.getUint32(r,!0);let n=this.h0|0,o=n,i=this.h1|0,s=i,a=this.h2|0,c=a,f=this.h3|0,h=f,u=this.h4|0,l=u;for(let y=0;y<5;y++){let N=4-y,E=Tu[y],p=Iu[y],A=li[y],m=di[y],b=Au[y],v=ku[y];for(let x=0;x<16;x++){let w=Hr(n+Ha(y,i,a,f)+Kn[A[x]]+E,b[x])+u|0;n=u,u=f,f=Hr(a,10)|0,a=i,i=w}for(let x=0;x<16;x++){let w=Hr(o+Ha(N,s,c,h)+Kn[m[x]]+p,v[x])+l|0;o=l,l=h,h=Hr(c,10)|0,c=s,s=w}}this.set(this.h1+a+h|0,this.h2+f+l|0,this.h3+u+o|0,this.h4+n+s|0,this.h0+i+c|0)}roundClean(){Kn.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}},Ma=dr(()=>new ui);var Uu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ke=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Te=new Uint32Array(64),hi=class extends Ae{constructor(e=32){super(64,e,8,!1),this.A=ke[0]|0,this.B=ke[1]|0,this.C=ke[2]|0,this.D=ke[3]|0,this.E=ke[4]|0,this.F=ke[5]|0,this.G=ke[6]|0,this.H=ke[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let u=0;u<16;u++,r+=4)Te[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let l=Te[u-15],y=Te[u-2],N=Kt(l,7)^Kt(l,18)^l>>>3,E=Kt(y,17)^Kt(y,19)^y>>>10;Te[u]=E+Te[u-7]+N+Te[u-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let l=Kt(a,6)^Kt(a,11)^Kt(a,25),y=h+l+Pa(a,c,f)+Uu[u]+Te[u]|0,E=(Kt(n,2)^Kt(n,13)^Kt(n,22))+Ra(n,o,i)|0;h=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+E|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){Te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ie=dr(()=>new hi);var qn=BigInt(4294967295),pi=BigInt(32);function Da(t,e=!1){return e?{h:Number(t&qn),l:Number(t>>pi&qn)}:{h:Number(t>>pi&qn)|0,l:Number(t&qn)|0}}function Lu(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let o=0;oBigInt(t>>>0)<>>0),Cu=(t,e,r)=>t>>>r,_u=(t,e,r)=>t<<32-r|e>>>r,Pu=(t,e,r)=>t>>>r|e<<32-r,Ru=(t,e,r)=>t<<32-r|e>>>r,Hu=(t,e,r)=>t<<64-r|e>>>r-32,$u=(t,e,r)=>t>>>r-32|e<<64-r,Ou=(t,e)=>e,Mu=(t,e)=>t,Du=(t,e,r)=>t<>>32-r,Ku=(t,e,r)=>e<>>32-r,qu=(t,e,r)=>e<>>64-r,Wu=(t,e,r)=>t<>>64-r;function Vu(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var zu=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ju=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Yu=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Gu=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Zu=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Fu=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var Qu={fromBig:Da,split:Lu,toBig:Nu,shrSH:Cu,shrSL:_u,rotrSH:Pu,rotrSL:Ru,rotrBH:Hu,rotrBL:$u,rotr32H:Ou,rotr32L:Mu,rotlSH:Du,rotlSL:Ku,rotlBH:qu,rotlBL:Wu,add:Vu,add3L:zu,add3H:ju,add4L:Yu,add4H:Gu,add5H:Fu,add5L:Zu},z=Qu;var[Xu,Ju]=z.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Ue=new Uint32Array(80),Le=new Uint32Array(80),gi=class extends Ae{constructor(e=64){super(128,e,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:h,Fh:u,Fl:l,Gh:y,Gl:N,Hh:E,Hl:p}=this;return[e,r,n,o,i,s,a,c,f,h,u,l,y,N,E,p]}set(e,r,n,o,i,s,a,c,f,h,u,l,y,N,E,p){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=h|0,this.Fh=u|0,this.Fl=l|0,this.Gh=y|0,this.Gl=N|0,this.Hh=E|0,this.Hl=p|0}process(e,r){for(let b=0;b<16;b++,r+=4)Ue[b]=e.getUint32(r),Le[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let v=Ue[b-15]|0,x=Le[b-15]|0,w=z.rotrSH(v,x,1)^z.rotrSH(v,x,8)^z.shrSH(v,x,7),B=z.rotrSL(v,x,1)^z.rotrSL(v,x,8)^z.shrSL(v,x,7),g=Ue[b-2]|0,d=Le[b-2]|0,C=z.rotrSH(g,d,19)^z.rotrBH(g,d,61)^z.shrSH(g,d,6),k=z.rotrSL(g,d,19)^z.rotrBL(g,d,61)^z.shrSL(g,d,6),T=z.add4L(B,k,Le[b-7],Le[b-16]),D=z.add4H(T,w,C,Ue[b-7],Ue[b-16]);Ue[b]=D|0,Le[b]=T|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:h,Eh:u,El:l,Fh:y,Fl:N,Gh:E,Gl:p,Hh:A,Hl:m}=this;for(let b=0;b<80;b++){let v=z.rotrSH(u,l,14)^z.rotrSH(u,l,18)^z.rotrBH(u,l,41),x=z.rotrSL(u,l,14)^z.rotrSL(u,l,18)^z.rotrBL(u,l,41),w=u&y^~u&E,B=l&N^~l&p,g=z.add5L(m,x,B,Ju[b],Le[b]),d=z.add5H(g,A,v,w,Xu[b],Ue[b]),C=g|0,k=z.rotrSH(n,o,28)^z.rotrBH(n,o,34)^z.rotrBH(n,o,39),T=z.rotrSL(n,o,28)^z.rotrBL(n,o,34)^z.rotrBL(n,o,39),D=n&i^n&a^i&a,S=o&s^o&c^s&c;A=E|0,m=p|0,E=y|0,p=N|0,y=u|0,N=l|0,{h:u,l}=z.add(f|0,h|0,d|0,C|0),f=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let I=z.add3L(C,T,S);n=z.add3H(I,d,k,D),o=I|0}({h:n,l:o}=z.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=z.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:h}=z.add(this.Dh|0,this.Dl|0,f|0,h|0),{h:u,l}=z.add(this.Eh|0,this.El|0,u|0,l|0),{h:y,l:N}=z.add(this.Fh|0,this.Fl|0,y|0,N|0),{h:E,l:p}=z.add(this.Gh|0,this.Gl|0,E|0,p|0),{h:A,l:m}=z.add(this.Hh|0,this.Hl|0,A|0,m|0),this.set(n,o,i,s,a,c,f,h,u,l,y,N,E,p,A,m)}roundClean(){Ue.fill(0),Le.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var $r=dr(()=>new gi);var mi=BigInt(0),bi=BigInt(1);function We(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function xi(t){if(!We(t))throw new Error("Uint8Array expected")}function hr(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function Or(t){let e=t.toString(16);return e.length&1?"0"+e:e}function Wa(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?mi:BigInt("0x"+t)}var Va=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",tl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function pr(t){if(xi(t),Va)return t.toHex();let e="";for(let r=0;r=se._0&&t<=se._9)return t-se._0;if(t>=se.A&&t<=se.F)return t-(se.A-10);if(t>=se.a&&t<=se.f)return t-(se.a-10)}function Mr(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Va)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;otypeof t=="bigint"&&mi<=t;function Wn(t,e,r){return wi(t)&&wi(e)&&wi(r)&&e<=t&&tmi;t>>=bi,e+=1);return e}var je=t=>(bi<new Uint8Array(t),qa=t=>Uint8Array.from(t);function ja(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=yi(t),o=yi(t),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...u)=>r(o,n,...u),c=(u=yi(0))=>{o=a(qa([0]),u),n=a(),u.length!==0&&(o=a(qa([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,l=[];for(;u{s(),c(u);let y;for(;!(y=l(f()));)c();return s(),y}}var el={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||We(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Ye(t,e,r={}){let n=(o,i,s)=>{let a=el[i];if(typeof a!="function")throw new Error("invalid validator function");let c=t[o];if(!(s&&c===void 0)&&!a(c,t))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return t}function Bi(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let i=t(r,...n);return e.set(r,i),i}}var gt=BigInt(0),ot=BigInt(1),Ge=BigInt(2),rl=BigInt(3),Si=BigInt(4),Ya=BigInt(5),Ga=BigInt(8),nl=BigInt(9),ol=BigInt(16);function bt(t,e){let r=t%e;return r>=gt?r:e+r}function il(t,e,r){if(egt;)e&ot&&(n=n*t%r),t=t*t%r,e>>=ot;return n}function Ct(t,e,r){let n=t;for(;e-- >gt;)n*=n,n%=r;return n}function Vn(t,e){if(t===gt)throw new Error("invert: expected non-zero number");if(e<=gt)throw new Error("invert: expected positive modulus, got "+e);let r=bt(t,e),n=e,o=gt,i=ot,s=ot,a=gt;for(;r!==gt;){let f=n/r,h=n%r,u=o-s*f,l=i-a*f;n=r,r=h,o=s,i=a,s=u,a=l}if(n!==ot)throw new Error("invert: does not exist");return bt(o,e)}function sl(t){let e=(t-ot)/Ge,r,n,o;for(r=t-ot,n=0;r%Ge===gt;r/=Ge,n++);for(o=Ge;o1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(t+ot)/Si;return function(c,f){let h=c.pow(f,s);if(!c.eql(c.sqr(h),f))throw new Error("Cannot find square root");return h}}let i=(r+ot)/Ge;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,h=a.pow(a.mul(a.ONE,o),r),u=a.pow(c,i),l=a.pow(c,r);for(;!a.eql(l,a.ONE);){if(a.eql(l,a.ZERO))return a.ZERO;let y=1;for(let E=a.sqr(l);y(n[o]="function",n),e);return Ye(t,r)}function fl(t,e,r){if(rgt;)r&ot&&(n=t.mul(n,o)),o=t.sqr(o),r>>=ot;return n}function ul(t,e){let r=new Array(e.length),n=e.reduce((i,s,a)=>t.is0(s)?i:(r[a]=i,t.mul(i,s)),t.ONE),o=t.inv(n);return e.reduceRight((i,s,a)=>t.is0(s)?i:(r[a]=t.mul(i,r[a]),t.mul(i,s)),o),r}function ki(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function zn(t,e,r=!1,n={}){if(t<=gt)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:o,nByteLength:i}=ki(t,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:t,isLE:r,BITS:o,BYTES:i,MASK:je(o),ZERO:gt,ONE:ot,create:c=>bt(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return gt<=c&&cc===gt,isOdd:c=>(c&ot)===ot,neg:c=>bt(-c,t),eql:(c,f)=>c===f,sqr:c=>bt(c*c,t),add:(c,f)=>bt(c+f,t),sub:(c,f)=>bt(c-f,t),mul:(c,f)=>bt(c*f,t),pow:(c,f)=>fl(a,c,f),div:(c,f)=>bt(c*Vn(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Vn(c,t),sqrt:n.sqrt||(c=>(s||(s=al(t)),s(a,c))),invertBatch:c=>ul(a,c),cmov:(c,f,h)=>h?f:c,toBytes:c=>r?vi(c,i):Ve(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?Ei(c):ae(c)}});return Object.freeze(a)}function Za(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ti(t){let e=Za(t);return e+Math.ceil(e/2)}function Fa(t,e,r=!1){let n=t.length,o=Za(e),i=Ti(e);if(n<16||n1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ei(t):ae(t),a=bt(s,e-ot)+ot;return r?vi(a,o):Ve(a,o)}var Qa=BigInt(0),Ci=BigInt(1);function Ii(t,e){let r=e.negate();return t?r:e}function Ja(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Ui(t,e){Ja(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=je(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Xa(t,e,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(t&o),c=t>>s;a>n&&(a-=i,c+=Ci);let f=e*n,h=f+Math.abs(a)-1,u=a===0,l=a<0,y=e%2!==0;return{nextN:c,offset:h,isZero:u,isNeg:l,isNegF:y,offsetF:f}}function ll(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function dl(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Li=new WeakMap,tc=new WeakMap;function Ni(t){return tc.get(t)||1}function ec(t,e){return{constTimeNegate:Ii,hasPrecomputes(r){return Ni(r)!==1},unsafeLadder(r,n,o=t.ZERO){let i=r;for(;n>Qa;)n&Ci&&(o=o.add(i)),i=i.double(),n>>=Ci;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=Ui(n,e),s=[],a=r,c=a;for(let f=0;f12?i-3:i>4?i-2:i?2:1,a=je(s),c=new Array(Number(a)+1).fill(o),f=Math.floor((e.BITS-1)/s)*s,h=o;for(let u=f;u>=0;u-=s){c.fill(o);for(let y=0;y>BigInt(u)&a);c[E]=c[E].add(r[y])}let l=o;for(let y=c.length-1,N=o;y>0;y--)N=N.add(c[y]),l=l.add(N);if(h=h.add(l),u!==0)for(let y=0;y{let{Err:r}=ce;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Or(o.length/2|128):"";return Or(t)+i+o+e},decode(t,e){let{Err:r}=ce,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of f)s=s<<8|h;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=ce;if(t{let m=p.toAffine();return Dr(Uint8Array.from([4]),r.toBytes(m.x),r.toBytes(m.y))}),i=e.fromBytes||(E=>{let p=E.subarray(1),A=r.fromBytes(p.subarray(0,r.BYTES)),m=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:A,y:m}});function s(E){let{a:p,b:A}=e,m=r.sqr(E),b=r.mul(m,E);return r.add(r.add(b,r.mul(E,p)),A)}if(!r.eql(r.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(E){return Wn(E,mt,e.n)}function c(E){let{allowedPrivateKeyLengths:p,nByteLength:A,wrapPrivateKey:m,n:b}=e;if(p&&typeof E!="bigint"){if(We(E)&&(E=pr(E)),typeof E!="string"||!p.includes(E.length))throw new Error("invalid private key");E=E.padStart(A*2,"0")}let v;try{v=typeof E=="bigint"?E:ae(Nt("private key",E,A))}catch{throw new Error("invalid private key, expected hex or "+A+" bytes, got "+typeof E)}return m&&(v=bt(v,b)),ze("private key",v,mt,b),v}function f(E){if(!(E instanceof l))throw new Error("ProjectivePoint expected")}let h=Bi((E,p)=>{let{px:A,py:m,pz:b}=E;if(r.eql(b,r.ONE))return{x:A,y:m};let v=E.is0();p==null&&(p=v?r.ONE:r.inv(b));let x=r.mul(A,p),w=r.mul(m,p),B=r.mul(b,p);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(B,r.ONE))throw new Error("invZ was invalid");return{x,y:w}}),u=Bi(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.py))return;throw new Error("bad point: ZERO")}let{x:p,y:A}=E.toAffine();if(!r.isValid(p)||!r.isValid(A))throw new Error("bad point: x or y not FE");let m=r.sqr(A),b=s(p);if(!r.eql(m,b))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(p,A,m){if(p==null||!r.isValid(p))throw new Error("x required");if(A==null||!r.isValid(A))throw new Error("y required");if(m==null||!r.isValid(m))throw new Error("z required");this.px=p,this.py=A,this.pz=m,Object.freeze(this)}static fromAffine(p){let{x:A,y:m}=p||{};if(!p||!r.isValid(A)||!r.isValid(m))throw new Error("invalid affine point");if(p instanceof l)throw new Error("projective point not allowed");let b=v=>r.eql(v,r.ZERO);return b(A)&&b(m)?l.ZERO:new l(A,m,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){let A=r.invertBatch(p.map(m=>m.pz));return p.map((m,b)=>m.toAffine(A[b])).map(l.fromAffine)}static fromHex(p){let A=l.fromAffine(i(Nt("pointHex",p)));return A.assertValidity(),A}static fromPrivateKey(p){return l.BASE.multiply(c(p))}static msm(p,A){return rc(l,n,p,A)}_setWindowSize(p){N.setWindowSize(this,p)}assertValidity(){u(this)}hasEvenY(){let{y:p}=this.toAffine();if(r.isOdd)return!r.isOdd(p);throw new Error("Field doesn't support isOdd")}equals(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.eql(r.mul(A,w),r.mul(v,b)),g=r.eql(r.mul(m,w),r.mul(x,b));return B&&g}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:p,b:A}=e,m=r.mul(A,oc),{px:b,py:v,pz:x}=this,w=r.ZERO,B=r.ZERO,g=r.ZERO,d=r.mul(b,b),C=r.mul(v,v),k=r.mul(x,x),T=r.mul(b,v);return T=r.add(T,T),g=r.mul(b,x),g=r.add(g,g),w=r.mul(p,g),B=r.mul(m,k),B=r.add(w,B),w=r.sub(C,B),B=r.add(C,B),B=r.mul(w,B),w=r.mul(T,w),g=r.mul(m,g),k=r.mul(p,k),T=r.sub(d,k),T=r.mul(p,T),T=r.add(T,g),g=r.add(d,d),d=r.add(g,d),d=r.add(d,k),d=r.mul(d,T),B=r.add(B,d),k=r.mul(v,x),k=r.add(k,k),d=r.mul(k,T),w=r.sub(w,d),g=r.mul(k,C),g=r.add(g,g),g=r.add(g,g),new l(w,B,g)}add(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.ZERO,g=r.ZERO,d=r.ZERO,C=e.a,k=r.mul(e.b,oc),T=r.mul(A,v),D=r.mul(m,x),S=r.mul(b,w),I=r.add(A,m),L=r.add(v,x);I=r.mul(I,L),L=r.add(T,D),I=r.sub(I,L),L=r.add(A,b);let $=r.add(v,w);return L=r.mul(L,$),$=r.add(T,S),L=r.sub(L,$),$=r.add(m,b),B=r.add(x,w),$=r.mul($,B),B=r.add(D,S),$=r.sub($,B),d=r.mul(C,L),B=r.mul(k,S),d=r.add(B,d),B=r.sub(D,d),d=r.add(D,d),g=r.mul(B,d),D=r.add(T,T),D=r.add(D,T),S=r.mul(C,S),L=r.mul(k,L),D=r.add(D,S),S=r.sub(T,S),S=r.mul(C,S),L=r.add(L,S),T=r.mul(D,L),g=r.add(g,T),T=r.mul($,L),B=r.mul(I,B),B=r.sub(B,T),T=r.mul(I,D),d=r.mul($,d),d=r.add(d,T),new l(B,g,d)}subtract(p){return this.add(p.negate())}is0(){return this.equals(l.ZERO)}wNAF(p){return N.wNAFCached(this,p,l.normalizeZ)}multiplyUnsafe(p){let{endo:A,n:m}=e;ze("scalar",p,fe,m);let b=l.ZERO;if(p===fe)return b;if(this.is0()||p===mt)return this;if(!A||N.hasPrecomputes(this))return N.wNAFCachedUnsafe(this,p,l.normalizeZ);let{k1neg:v,k1:x,k2neg:w,k2:B}=A.splitScalar(p),g=b,d=b,C=this;for(;x>fe||B>fe;)x&mt&&(g=g.add(C)),B&mt&&(d=d.add(C)),C=C.double(),x>>=mt,B>>=mt;return v&&(g=g.negate()),w&&(d=d.negate()),d=new l(r.mul(d.px,A.beta),d.py,d.pz),g.add(d)}multiply(p){let{endo:A,n:m}=e;ze("scalar",p,mt,m);let b,v;if(A){let{k1neg:x,k1:w,k2neg:B,k2:g}=A.splitScalar(p),{p:d,f:C}=this.wNAF(w),{p:k,f:T}=this.wNAF(g);d=N.constTimeNegate(x,d),k=N.constTimeNegate(B,k),k=new l(r.mul(k.px,A.beta),k.py,k.pz),b=d.add(k),v=C.add(T)}else{let{p:x,f:w}=this.wNAF(p);b=x,v=w}return l.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(p,A,m){let b=l.BASE,v=(w,B)=>B===fe||B===mt||!w.equals(b)?w.multiplyUnsafe(B):w.multiply(B),x=v(this,A).add(v(p,m));return x.is0()?void 0:x}toAffine(p){return h(this,p)}isTorsionFree(){let{h:p,isTorsionFree:A}=e;if(p===mt)return!0;if(A)return A(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:p,clearCofactor:A}=e;return p===mt?this:A?A(l,this):this.multiplyUnsafe(e.h)}toRawBytes(p=!0){return hr("isCompressed",p),this.assertValidity(),o(l,this,p)}toHex(p=!0){return hr("isCompressed",p),pr(this.toRawBytes(p))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let y=e.nBitLength,N=ec(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function gl(t){let e=_i(t);return Ye(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ic(t){let e=gl(t),{Fp:r,n}=e,o=r.BYTES+1,i=2*r.BYTES+1;function s(S){return bt(S,n)}function a(S){return Vn(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:h,isWithinCurveOrder:u}=pl({...e,toBytes(S,I,L){let $=I.toAffine(),M=r.toBytes($.x),W=Dr;return hr("isCompressed",L),L?W(Uint8Array.from([I.hasEvenY()?2:3]),M):W(Uint8Array.from([4]),M,r.toBytes($.y))},fromBytes(S){let I=S.length,L=S[0],$=S.subarray(1);if(I===o&&(L===2||L===3)){let M=ae($);if(!Wn(M,mt,r.ORDER))throw new Error("Point is not on curve");let W=h(M),j;try{j=r.sqrt(W)}catch(X){let F=X instanceof Error?": "+X.message:"";throw new Error("Point is not on curve"+F)}let Y=(j&mt)===mt;return(L&1)===1!==Y&&(j=r.neg(j)),{x:M,y:j}}else if(I===i&&L===4){let M=r.fromBytes($.subarray(0,r.BYTES)),W=r.fromBytes($.subarray(r.BYTES,2*r.BYTES));return{x:M,y:W}}else{let M=o,W=i;throw new Error("invalid Point, expected length of "+M+", or uncompressed "+W+", got "+I)}}}),l=S=>pr(Ve(S,e.nByteLength));function y(S){let I=n>>mt;return S>I}function N(S){return y(S)?s(-S):S}let E=(S,I,L)=>ae(S.slice(I,L));class p{constructor(I,L,$){ze("r",I,mt,n),ze("s",L,mt,n),this.r=I,this.s=L,$!=null&&(this.recovery=$),Object.freeze(this)}static fromCompact(I){let L=e.nByteLength;return I=Nt("compactSignature",I,L*2),new p(E(I,0,L),E(I,L,2*L))}static fromDER(I){let{r:L,s:$}=ce.toSig(Nt("DER",I));return new p(L,$)}assertValidity(){}addRecoveryBit(I){return new p(this.r,this.s,I)}recoverPublicKey(I){let{r:L,s:$,recovery:M}=this,W=w(Nt("msgHash",I));if(M==null||![0,1,2,3].includes(M))throw new Error("recovery id invalid");let j=M===2||M===3?L+e.n:L;if(j>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let Y=M&1?"03":"02",it=c.fromHex(Y+l(j)),X=a(j),F=s(-W*X),P=s($*X),_=c.BASE.multiplyAndAddUnsafe(it,F,P);if(!_)throw new Error("point at infinify");return _.assertValidity(),_}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Mr(this.toDERHex())}toDERHex(){return ce.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Mr(this.toCompactHex())}toCompactHex(){return l(this.r)+l(this.s)}}let A={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=Ti(e.n);return Fa(e.randomBytes(S),e.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function m(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function b(S){let I=We(S),L=typeof S=="string",$=(I||L)&&S.length;return I?$===o||$===i:L?$===2*o||$===2*i:S instanceof c}function v(S,I,L=!0){if(b(S))throw new Error("first arg must be private key");if(!b(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(f(S)).toRawBytes(L)}let x=e.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=ae(S),L=S.length*8-e.nBitLength;return L>0?I>>BigInt(L):I},w=e.bits2int_modN||function(S){return s(x(S))},B=je(e.nBitLength);function g(S){return ze("num < 2^"+e.nBitLength,S,fe,B),Ve(S,e.nByteLength)}function d(S,I,L=C){if(["recovered","canonical"].some(R=>R in L))throw new Error("sign() legacy options not supported");let{hash:$,randomBytes:M}=e,{lowS:W,prehash:j,extraEntropy:Y}=L;W==null&&(W=!0),S=Nt("msgHash",S),nc(L),j&&(S=Nt("prehashed msgHash",$(S)));let it=w(S),X=f(I),F=[g(X),g(it)];if(Y!=null&&Y!==!1){let R=Y===!0?M(r.BYTES):Y;F.push(Nt("extraEntropy",R))}let P=Dr(...F),_=it;function U(R){let H=x(R);if(!u(H))return;let O=a(H),q=c.BASE.multiply(H).toAffine(),K=s(q.x);if(K===fe)return;let G=s(O*s(_+K*X));if(G===fe)return;let Z=(q.x===K?0:2)|Number(q.y&mt),V=G;return W&&y(G)&&(V=N(G),Z^=1),new p(K,V,Z)}return{seed:P,k2sig:U}}let C={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(S,I,L=C){let{seed:$,k2sig:M}=d(S,I,L),W=e;return ja(W.hash.outputLen,W.nByteLength,W.hmac)($,M)}c.BASE._setWindowSize(8);function D(S,I,L,$=k){let M=S;I=Nt("msgHash",I),L=Nt("publicKey",L);let{lowS:W,prehash:j,format:Y}=$;if(nc($),"strict"in $)throw new Error("options.strict was renamed to lowS");if(Y!==void 0&&Y!=="compact"&&Y!=="der")throw new Error("format must be compact or der");let it=typeof M=="string"||We(M),X=!it&&!Y&&typeof M=="object"&&M!==null&&typeof M.r=="bigint"&&typeof M.s=="bigint";if(!it&&!X)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let F,P;try{if(X&&(F=new p(M.r,M.s)),it){try{Y!=="compact"&&(F=p.fromDER(M))}catch(Z){if(!(Z instanceof ce.Err))throw Z}!F&&Y!=="der"&&(F=p.fromCompact(M))}P=c.fromHex(L)}catch{return!1}if(!F||W&&F.hasHighS())return!1;j&&(I=e.hash(I));let{r:_,s:U}=F,R=w(I),H=a(U),O=s(R*H),q=s(_*H),K=c.BASE.multiplyAndAddUnsafe(P,O,q)?.toAffine();return K?s(K.x)===_:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:v,sign:T,verify:D,ProjectivePoint:c,Signature:p,utils:A}}function wl(t){return{hash:t,hmac:(e,...r)=>Se(t,e,qe(...r)),randomBytes:Mn}}function sc(t,e){let r=n=>ic({...t,...wl(n)});return{...r(e),create:r}}var fc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ac=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yl=BigInt(1),Ri=BigInt(2),cc=(t,e)=>(t+e/Ri)/e;function bl(t){let e=fc,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,h=f*f*t%e,u=Ct(h,r,e)*h%e,l=Ct(u,r,e)*h%e,y=Ct(l,Ri,e)*f%e,N=Ct(y,o,e)*y%e,E=Ct(N,i,e)*N%e,p=Ct(E,a,e)*E%e,A=Ct(p,c,e)*p%e,m=Ct(A,a,e)*E%e,b=Ct(m,r,e)*h%e,v=Ct(b,s,e)*N%e,x=Ct(v,n,e)*f%e,w=Ct(x,Ri,e);if(!Hi.eql(Hi.sqr(w),t))throw new Error("Cannot find square root");return w}var Hi=zn(fc,void 0,void 0,{sqrt:bl}),qt=sc({a:BigInt(0),b:BigInt(7),Fp:Hi,n:ac,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=ac,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-yl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=cc(i*t,e),c=cc(-n*t,e),f=bt(t-a*r-c*o,e),h=bt(-a*n-c*i,e),u=f>s,l=h>s;if(u&&(f=e-f),l&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:f,k2neg:l,k2:h}}}},Ie),Bp=BigInt(0);var Sp=qt.ProjectivePoint;var jn=qt.ProjectivePoint,$i=Tn(Ie);function uc(t){At(t);let e=t.length===0?"0":Na(t);return BigInt("0x"+e)}function ml(t){if(typeof t!="bigint")throw new Error("bigint expected");return Ca(t.toString(16).padStart(64,"0"))}var xl=fi("Bitcoin seed"),Oi={private:76066276,public:76067358},Mi=2147483648,El=t=>Ma(Ie(t)),vl=t=>Yt(t).getUint32(0,!1),Yn=t=>{if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new Error("invalid number, should be from 0 to 2**32-1, got "+t);let e=new Uint8Array(4);return Yt(e).setUint32(0,t,!1),e},Gn=class t{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return vl(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){let e=this.privateKey;if(!e)throw new Error("No private key");return $i.encode(this.serialize(this.versions.private,qe(new Uint8Array([0]),e)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return $i.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(e,r=Oi){if(At(e),8*e.length<128||8*e.length>512)throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+e.length);let n=Se($r,xl,e);return new t({versions:r,chainCode:n.slice(32),privateKey:n.slice(0,32)})}static fromExtendedKey(e,r=Oi){let n=$i.decode(e),o=Yt(n),i=o.getUint32(0,!1),s={versions:r,depth:n[4],parentFingerprint:o.getUint32(5,!1),index:o.getUint32(9,!1),chainCode:n.slice(13,45)},a=n.slice(45),c=a[0]===0;if(i!==r[c?"private":"public"])throw new Error("Version mismatch");return c?new t({...s,privateKey:a.slice(1)}):new t({...s,publicKey:a})}static fromJSON(e){return t.fromExtendedKey(e.xpriv)}constructor(e){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions||Oi,this.depth=e.depth||0,this.chainCode=e.chainCode||null,this.index=e.index||0,this.parentFingerprint=e.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(e.publicKey&&e.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(e.privateKey){if(!qt.utils.isValidPrivateKey(e.privateKey))throw new Error("Invalid private key");this.privKey=typeof e.privateKey=="bigint"?e.privateKey:uc(e.privateKey),this.privKeyBytes=ml(this.privKey),this.pubKey=qt.getPublicKey(e.privateKey,!0)}else if(e.publicKey)this.pubKey=jn.fromHex(e.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=El(this.pubKey)}derive(e){if(!/^[mM]'?/.test(e))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(e))return this;let r=e.replace(/^[mM]'?\//,"").split("/"),n=this;for(let o of r){let i=/^(\d+)('?)$/.exec(o),s=i&&i[1];if(!i||i.length!==3||typeof s!="string")throw new Error("invalid child index: "+o);let a=+s;if(!Number.isSafeInteger(a)||a>=Mi)throw new Error("Invalid index");i[2]==="'"&&(a+=Mi),n=n.deriveChild(a)}return n}deriveChild(e){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let r=Yn(e);if(e>=Mi){let a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");r=qe(new Uint8Array([0]),a,r)}else r=qe(this.pubKey,r);let n=Se($r,this.chainCode,r),o=uc(n.slice(0,32)),i=n.slice(32);if(!qt.utils.isValidPrivateKey(o))throw new Error("Tweak bigger than curve order");let s={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};try{if(this.privateKey){let a=bt(this.privKey+o,qt.CURVE.n);if(!qt.utils.isValidPrivateKey(a))throw new Error("The tweak was out of range or the resulted private key is invalid");s.privateKey=a}else{let a=jn.fromHex(this.pubKey).add(jn.fromPrivateKey(o));if(a.equals(jn.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");s.publicKey=a.toRawBytes(!0)}return new t(s)}catch{return this.deriveChild(e+1)}}sign(e){if(!this.privateKey)throw new Error("No privateKey set!");return At(e,32),qt.sign(e,this.privKey).toCompactRawBytes()}verify(e,r){if(At(e,32),At(r,64),!this.publicKey)throw new Error("No publicKey set!");let n;try{n=qt.Signature.fromCompact(r)}catch{return!1}return qt.verify(n,e,this.publicKey)}wipePrivateData(){return this.privKey=void 0,this.privKeyBytes&&(this.privKeyBytes.fill(0),this.privKeyBytes=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(e,r){if(!this.chainCode)throw new Error("No chainCode set");return At(r,33),qe(Yn(e),new Uint8Array([this.depth]),Yn(this.parentFingerprint),Yn(this.index),this.chainCode,r)}};function Bl(t,e,r,n){On(t);let o=_a({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(ve(i),ve(s),ve(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Be(e),f=Be(r),h=new Uint8Array(s),u=Se.create(t,c),l=u._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:a,DK:h,PRF:u,PRFSalt:l}}function Sl(t,e,r,n,o){return t.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),r}function lc(t,e,r,n){let{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=Bl(t,e,r,n),f,h=new Uint8Array(4),u=Yt(h),l=new Uint8Array(a.outputLen);for(let y=1,N=0;Nt[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function dc(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function hc(t){let e=dc(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function pc(t){At(t,16,20,24,28,32)}function gc(t,e=128){if(ve(e),e%32!==0||e>256)throw new TypeError("Invalid entropy");return Il(Mn(e/8),t)}var kl=t=>{let e=8-t.length/4;return new Uint8Array([Ie(t)[0]>>e<{if(typeof e!="string")throw new Error("wordlist: non-string element: "+e)}),Ir.chain(Ir.checksum(1,kl),Ir.radix2(11,!0),Ir.alphabet(t))}function Tl(t,e){let{words:r}=hc(t),n=wc(e).decode(r);return pc(n),n}function Il(t,e){return pc(t),wc(e).encode(t).join(Al(e)?"\u3000":" ")}function yc(t,e){try{Tl(t,e)}catch{return!1}return!0}var Ul=t=>dc("mnemonic"+t);function bc(t,e=""){return lc($r,hc(t).nfkd,Ul(e),{c:2048,dkLen:64})}var Di=`abandon ability able about above absent absorb abstract absurd abuse access accident account accuse achieve acid acoustic acquire across act action actor actress actual adapt add addict address adjust admit adult advance advice aerobic affair afford afraid again age agent agree ahead aim air airport aisle alarm album alcohol alert alien all alley allow almost alone alpha already also alter always amateur amazing among amount amused analyst anchor ancient anger angle angry animal ankle announce annual another answer antenna antique anxiety any apart apology appear apple approve april arch arctic area arena argue arm armed armor army around arrange arrest arrive arrow art artefact artist artwork ask aspect assault asset assist assume asthma athlete atom attack attend attitude attract auction audit august aunt author auto autumn average avocado avoid awake aware away awesome awful awkward axis baby bachelor bacon badge bag balance balcony ball bamboo banana banner bar barely bargain barrel base basic basket battle beach bean beauty because become beef before begin behave behind believe below belt bench benefit best betray better between beyond bicycle bid bike bind biology bird birth bitter black blade blame blanket blast bleak bless blind blood blossom blouse blue blur blush board boat body boil bomb bone bonus book boost border boring borrow boss bottom bounce box boy bracket brain brand brass brave bread breeze brick bridge brief bright bring brisk broccoli broken bronze broom brother brown brush bubble buddy budget buffalo build bulb bulk bullet bundle bunker burden burger burst bus business busy butter buyer buzz cabbage cabin cable cactus cage cake call calm camera camp can canal cancel candy cannon canoe canvas canyon capable capital captain car carbon card cargo carpet carry cart case cash casino castle casual cat catalog catch category cattle caught cause caution cave ceiling celery cement census century cereal certain chair chalk champion change chaos chapter charge chase chat cheap check cheese chef cherry chest chicken chief child chimney choice choose chronic chuckle chunk churn cigar cinnamon circle citizen city civil claim clap clarify claw clay clean clerk clever click client cliff climb clinic clip clock clog close cloth cloud clown club clump cluster clutch coach coast coconut code coffee coil coin collect color column combine come comfort comic common company concert conduct confirm congress connect consider control convince cook cool copper copy coral core corn correct cost cotton couch country couple course cousin cover coyote crack cradle craft cram crane crash crater crawl crazy cream credit creek crew cricket crime crisp critic crop cross crouch crowd crucial cruel cruise crumble crunch crush cry crystal cube culture cup cupboard curious current curtain curve cushion custom cute cycle dad damage damp dance danger daring dash daughter dawn day deal debate debris decade december decide decline decorate decrease deer defense define defy degree delay deliver demand demise denial dentist deny depart depend deposit depth deputy derive describe desert design desk despair destroy detail detect develop device devote diagram dial diamond diary dice diesel diet differ digital dignity dilemma dinner dinosaur direct dirt disagree discover disease dish dismiss disorder display distance divert divide divorce dizzy doctor document dog doll dolphin domain donate donkey donor door dose double dove draft dragon drama drastic draw dream dress drift drill drink drip drive drop drum dry duck dumb dune during dust dutch duty dwarf dynamic eager eagle early earn earth easily east easy echo ecology economy edge edit educate effort egg eight either elbow elder electric elegant element elephant elevator elite else embark embody embrace emerge emotion employ empower empty enable enact end endless endorse enemy energy enforce engage engine enhance enjoy enlist enough enrich enroll ensure enter entire entry envelope episode equal equip era erase erode erosion error erupt escape essay essence estate eternal ethics evidence evil evoke evolve exact example excess exchange excite exclude excuse execute exercise exhaust exhibit exile exist exit exotic expand expect expire explain expose express extend extra eye eyebrow fabric face faculty fade faint faith fall false fame family famous fan fancy fantasy farm fashion fat fatal father fatigue fault favorite feature february federal fee feed feel female fence festival fetch fever few fiber fiction field figure file film filter final find fine finger finish fire firm first fiscal fish fit fitness fix flag flame flash flat flavor flee flight flip float flock floor flower fluid flush fly foam focus fog foil fold follow food foot force forest forget fork fortune forum forward fossil foster found fox fragile frame frequent fresh friend fringe frog front frost frown frozen fruit fuel fun funny furnace fury future gadget gain galaxy gallery game gap garage garbage garden garlic garment gas gasp gate gather gauge gaze general genius genre gentle genuine gesture ghost giant gift giggle ginger giraffe girl give glad glance glare glass glide glimpse globe gloom glory glove glow glue goat goddess gold good goose gorilla gospel gossip govern gown grab grace grain grant grape grass gravity great green grid grief grit grocery group grow grunt guard guess guide guilt guitar gun gym habit hair half hammer hamster hand happy harbor hard harsh harvest hat have hawk hazard head health heart heavy hedgehog height hello helmet help hen hero hidden high hill hint hip hire history hobby hockey hold hole holiday hollow home honey hood hope horn horror horse hospital host hotel hour hover hub huge human humble humor hundred hungry hunt hurdle hurry hurt husband hybrid ice icon idea identify idle ignore ill illegal illness image imitate immense immune impact impose improve impulse inch include income increase index indicate indoor industry infant inflict inform inhale inherit initial inject injury inmate inner innocent input inquiry insane insect inside inspire install intact interest into invest invite involve iron island isolate issue item ivory jacket jaguar jar jazz jealous jeans jelly jewel job join joke journey joy judge juice jump jungle junior junk just kangaroo keen keep ketchup key kick kid kidney kind kingdom kiss kit kitchen kite kitten kiwi knee knife knock know lab label labor ladder lady lake lamp language laptop large later latin laugh laundry lava law lawn lawsuit layer lazy leader leaf learn leave lecture left leg legal legend leisure lemon lend length lens leopard lesson letter level liar liberty library license life lift light like limb limit link lion liquid list little live lizard load loan lobster local lock logic lonely long loop lottery loud lounge love loyal lucky luggage lumber lunar lunch luxury lyrics machine mad magic magnet maid mail main major make mammal man manage mandate mango mansion manual maple marble march margin marine market marriage mask mass master match material math matrix matter maximum maze meadow mean measure meat mechanic medal media melody melt member memory mention menu mercy merge merit merry mesh message metal method middle midnight milk million mimic mind minimum minor minute miracle mirror misery miss mistake mix mixed mixture mobile model modify mom moment monitor monkey monster month moon moral more morning mosquito mother motion motor mountain mouse move movie much muffin mule multiply muscle museum mushroom music must mutual myself mystery myth naive name napkin narrow nasty nation nature near neck need negative neglect neither nephew nerve nest net network neutral never news next nice night noble noise nominee noodle normal north nose notable note nothing notice novel now nuclear number nurse nut oak obey object oblige obscure observe obtain obvious occur ocean october odor off offer office often oil okay old olive olympic omit once one onion online only open opera opinion oppose option orange orbit orchard order ordinary organ orient original orphan ostrich other outdoor outer output outside oval oven over own owner oxygen oyster ozone pact paddle page pair palace palm panda panel panic panther paper parade parent park parrot party pass patch path patient patrol pattern pause pave payment peace peanut pear peasant pelican pen penalty pencil people pepper perfect permit person pet phone photo phrase physical piano picnic picture piece pig pigeon pill pilot pink pioneer pipe pistol pitch pizza place planet plastic plate play please pledge pluck plug plunge poem poet point polar pole police pond pony pool popular portion position possible post potato pottery poverty powder power practice praise predict prefer prepare present pretty prevent price pride primary print priority prison private prize problem process produce profit program project promote proof property prosper protect proud provide public pudding pull pulp pulse pumpkin punch pupil puppy purchase purity purpose purse push put puzzle pyramid quality quantum quarter question quick quit quiz quote rabbit raccoon race rack radar radio rail rain raise rally ramp ranch random range rapid rare rate rather raven raw razor ready real reason rebel rebuild recall receive recipe record recycle reduce reflect reform refuse region regret regular reject relax release relief rely remain remember remind remove render renew rent reopen repair repeat replace report require rescue resemble resist resource response result retire retreat return reunion reveal review reward rhythm rib ribbon rice rich ride ridge rifle right rigid ring riot ripple risk ritual rival river road roast robot robust rocket romance roof rookie room rose rotate rough round route royal rubber rude rug rule run runway rural sad saddle sadness safe sail salad salmon salon salt salute same sample sand satisfy satoshi sauce sausage save say scale scan scare scatter scene scheme school science scissors scorpion scout scrap screen script scrub sea search season seat second secret section security seed seek segment select sell seminar senior sense sentence series service session settle setup seven shadow shaft shallow share shed shell sheriff shield shift shine ship shiver shock shoe shoot shop short shoulder shove shrimp shrug shuffle shy sibling sick side siege sight sign silent silk silly silver similar simple since sing siren sister situate six size skate sketch ski skill skin skirt skull slab slam sleep slender slice slide slight slim slogan slot slow slush small smart smile smoke smooth snack snake snap sniff snow soap soccer social sock soda soft solar soldier solid solution solve someone song soon sorry sort soul sound soup source south space spare spatial spawn speak special speed spell spend sphere spice spider spike spin spirit split spoil sponsor spoon sport spot spray spread spring spy square squeeze squirrel stable stadium staff stage stairs stamp stand start state stay steak steel stem step stereo stick still sting stock stomach stone stool story stove strategy street strike strong struggle student stuff stumble style subject submit subway success such sudden suffer sugar suggest suit summer sun sunny sunset super supply supreme sure surface surge surprise surround survey suspect sustain swallow swamp swap swarm swear sweet swift swim swing switch sword symbol symptom syrup system table tackle tag tail talent talk tank tape target task taste tattoo taxi teach team tell ten tenant tennis tent term test text thank that theme then theory there they thing this thought three thrive throw thumb thunder ticket tide tiger tilt timber time tiny tip tired tissue title toast tobacco today toddler toe together toilet token tomato tomorrow tone tongue tonight tool tooth top topic topple torch tornado tortoise toss total tourist toward tower town toy track trade traffic tragic train transfer trap trash travel tray treat tree trend trial tribe trick trigger trim trip trophy trouble truck true truly trumpet trust truth try tube tuition tumble tuna tunnel turkey turn turtle twelve twenty twice twin twist two type typical ugly umbrella unable unaware uncle uncover under undo unfair unfold unhappy uniform unique unit universe unknown unlock until unusual unveil update upgrade uphold upon upper upset urban urge usage use used useful useless usual utility vacant vacuum vague valid valley valve van vanish vapor various vast vault vehicle velvet vendor venture venue verb verify version very vessel veteran viable vibrant vicious victory video view village vintage violin virtual virus visa visit visual vital vivid vocal voice void volcano volume vote voyage wage wagon wait walk wall walnut want warfare warm warrior wash wasp waste water wave way wealth weapon wear weasel weather web wedding weekend weird welcome west wet whale what wheat wheel when where whip whisper wide width wife wild will win window wine wing wink winner winter wire wisdom wise wish witness wolf woman wonder wood wool word work world worry worth wrap wreck wrestle wrist write wrong yard year yellow you young youth zebra zero zone zoo`.split(` `);var Sc=Cc(vc()),Zn=Ko,Ll="m/84'/1'/0'",Nl=10;function Cl(){return gc(Di,128)}function _l(t){return yc(String(t||"").trim().toLowerCase().replace(/\s+/g," "),Di)}function Pl(t){let e=bc(String(t).trim().toLowerCase().replace(/\s+/g," ")),r=Gn.fromMasterSeed(e).derive(Ll),n=(i,s)=>r.deriveChild(i).deriveChild(s),o=(i,s)=>ci(n(i,s).publicKey,Zn);return{address:(i=0,s=0)=>o(s,i).address,key:n,addr:o}}async function Bc(t){let e=await fetch(t);if(!e.ok)throw new Error("Network busy, try again.");return e.json()}async function Rl(t){let e=[],r=new Map,n=0,o=0;for(let c of[0,1]){let f=0;for(let h=0;h<40&&f<(c?4:Nl);h++){let u=t.addr(c,h),[l,y]=await Promise.all([Bc(`/api/chain/address/${u.address}/utxo`),Bc(`/api/chain/address/${u.address}/txs`)]);if(!y.length){f++;continue}f=0,c?o=h+1:n=h+1;for(let N of l)e.push({txid:N.txid,vout:N.vout,value:N.value,confirmed:N.status&&N.status.confirmed,change:c,i:h,script:u.script});for(let N of y)r.set(N.txid,N)}}let i=new Set;for(let c of[0,1])for(let f=0;f<(c?o:n)+1;f++)i.add(t.address(f,c));let s=[...r.values()].map(c=>{let f=0;for(let h of c.vout)i.has(h.scriptpubkey_address)&&(f+=h.value);for(let h of c.vin)h.prevout&&i.has(h.prevout.scriptpubkey_address)&&(f-=h.prevout.value);return{txid:c.txid,delta:f,time:c.status&&c.status.block_time?c.status.block_time*1e3:null,confirmed:!!(c.status&&c.status.confirmed)}}).sort((c,f)=>(f.time||9e15)-(c.time||9e15)),a=e.reduce((c,f)=>c+f.value,0);return{utxos:e,balance:a,history:s,nextReceive:n,nextChange:o}}function Ac(t){try{return Ee(Zn).decode(String(t).trim()),!0}catch{return!1}}function Hl(t,e,r,n,o){if(r=String(r).trim(),!Ac(r))throw new Error("That isn\u2019t a test-network Bitcoin address (they start with tb1).");if(n=Math.floor(n),!(n>=330))throw new Error("That amount is too small to send.");let i=[...e.utxos].sort((u,l)=>l.value-u.value),s=[],a=0,c=0;for(let u of i)if(s.push(u),a+=u.value,c=Math.ceil((11+68*s.length+31*2)*o),a>=n+c)break;if(a=546?f.addOutputAddress(t.address(e.nextChange,1),BigInt(h),Zn):c+=h,s.forEach((u,l)=>f.signIdx(t.key(u.change,u.i).privateKey,l)),f.finalize(),{hex:f.hex,fee:c,txid:f.id}}function $l(t){let e=(0,Sc.default)(0,"M");return e.addData(t),e.make(),e.createSvgTag({cellSize:6,margin:2,scalable:!0})}return _c(Ol);})(); /*! Bundled license information: @scure/base/lib/esm/index.js: (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/hashes/esm/utils.js: (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/hashes/esm/utils.js: (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/utils.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/modular.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/curve.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/weierstrass.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/_shortw_utils.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/secp256k1.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @scure/base/lib/esm/index.js: (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @scure/btc-signer/esm/index.js: (*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/hashes/esm/utils.js: (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/utils.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/modular.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/curve.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/abstract/weierstrass.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/_shortw_utils.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/esm/secp256k1.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @scure/bip32/lib/esm/index.js: (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *) @scure/bip39/esm/index.js: (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *) */