@btc-vision/wallet-sdk 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function e(e,t){for(var r=0;r<t.length;r++){const n=t[r];if("string"!=typeof n&&!Array.isArray(n))for(const t in n)if("default"!==t&&!(t in e)){const r=Object.getOwnPropertyDescriptor(n,t);r&&Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var r,n,i,o={},s={},a={},u={},c={},f={};function l(){return r||(r=1,Object.defineProperty(f,"__esModule",{value:!0}),f.crypto=void 0,f.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0),f}function h(){return n||(n=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=r,e.anumber=n,e.abytes=i,e.ahash=function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");n(e.outputLen),n(e.blockLen)},e.aexists=function(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")},e.aoutput=function(e,t){i(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)},e.u8=function(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},e.u32=function(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))},e.clean=function(...e){for(let t=0;t<e.length;t++)e[t].fill(0)},e.createView=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},e.rotr=function(e,t){return e<<32-t|e>>>t},e.rotl=function(e,t){return e<<t|e>>>32-t>>>0},e.byteSwap=o,e.byteSwap32=s,e.bytesToHex=function(e){if(i(e),a)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=u[e[r]];return t},e.hexToBytes=function(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(a)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){const t=f(e.charCodeAt(o)),r=f(e.charCodeAt(o+1));if(void 0===t||void 0===r){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}n[i]=16*t+r}return n},e.asyncLoop=async function(t,r,n){let i=Date.now();for(let o=0;o<t;o++){n(o);const t=Date.now()-i;t>=0&&t<r||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=h,e.bytesToUtf8=function(e){return(new TextDecoder).decode(e)},e.toBytes=p,e.kdfInputToBytes=function(e){"string"==typeof e&&(e=h(e));return i(e),e},e.concatBytes=function(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];i(r),t+=r.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const t=e[n];r.set(t,i),i+=t.length}return r},e.checkOpts=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign(e,t)},e.createHasher=d,e.createOptHasher=y,e.createXOFer=g,e.randomBytes=function(e=32){if(t.crypto&&"function"==typeof t.crypto.getRandomValues)return t.crypto.getRandomValues(new Uint8Array(e));if(t.crypto&&"function"==typeof t.crypto.randomBytes)return Uint8Array.from(t.crypto.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")};const t=l();function r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function n(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function i(e,...t){if(!r(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function o(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function s(e){for(let t=0;t<e.length;t++)e[t]=o(e[t]);return e}e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],e.swap8IfBE=e.isLE?e=>e:e=>o(e),e.byteSwapIfBE=e.swap8IfBE,e.swap32IfBE=e.isLE?e=>e:s;const a=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),u=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));const c={_0:48,_9:57,A:65,F:70,a:97,f:102};function f(e){return e>=c._0&&e<=c._9?e-c._0:e>=c.A&&e<=c.F?e-(c.A-10):e>=c.a&&e<=c.f?e-(c.a-10):void 0}function h(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function p(e){return"string"==typeof e&&(e=h(e)),i(e),e}e.nextTick=async()=>{};function d(e){const t=t=>e().update(p(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function y(e){const t=(t,r)=>e(r).update(p(t)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=t=>e(t),t}function g(e){const t=(t,r)=>e(r).update(p(t)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=t=>e(t),t}e.Hash=class{},e.wrapConstructor=d,e.wrapConstructorWithOpts=y,e.wrapXOFConstructorWithOpts=g}(c)),c}function p(){if(i)return u;i=1,Object.defineProperty(u,"__esModule",{value:!0}),u.SHA512_IV=u.SHA384_IV=u.SHA224_IV=u.SHA256_IV=u.HashMD=void 0,u.setBigUint64=t,u.Chi=function(e,t,r){return e&t^~e&r},u.Maj=function(e,t,r){return e&t^e&r^t&r};const e=h();function t(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,c=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+c,a,n)}class r extends e.Hash{constructor(t,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=(0,e.createView)(this.buffer)}update(t){(0,e.aexists)(this),t=(0,e.toBytes)(t),(0,e.abytes)(t);const{view:r,buffer:n,blockLen:i}=this,o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const r=(0,e.createView)(t);for(;i<=o-s;s+=i)this.process(r,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(r){(0,e.aexists)(this),(0,e.aoutput)(r,this),this.finished=!0;const{buffer:n,view:i,blockLen:o,isLE:s}=this;let{pos:a}=this;n[a++]=128,(0,e.clean)(this.buffer.subarray(a)),this.padOffset>o-a&&(this.process(i,0),a=0);for(let e=a;e<o;e++)n[e]=0;t(i,o-8,BigInt(8*this.length),s),this.process(i,0);const u=(0,e.createView)(r),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<f;e++)u.setUint32(4*e,l[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}return u.HashMD=r,u.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),u.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),u.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),u.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),u}var d,y,g={};function m(){if(d)return g;d=1,Object.defineProperty(g,"__esModule",{value:!0}),g.toBig=g.shrSL=g.shrSH=g.rotrSL=g.rotrSH=g.rotrBL=g.rotrBH=g.rotr32L=g.rotr32H=g.rotlSL=g.rotlSH=g.rotlBL=g.rotlBH=g.add5L=g.add5H=g.add4L=g.add4H=g.add3L=g.add3H=void 0,g.add=w,g.fromBig=r,g.split=n;const e=BigInt(2**32-1),t=BigInt(32);function r(r,n=!1){return n?{h:Number(r&e),l:Number(r>>t&e)}:{h:0|Number(r>>t&e),l:0|Number(r&e)}}function n(e,t=!1){const n=e.length;let i=new Uint32Array(n),o=new Uint32Array(n);for(let s=0;s<n;s++){const{h:n,l:a}=r(e[s],t);[i[s],o[s]]=[n,a]}return[i,o]}const i=(e,r)=>BigInt(e>>>0)<<t|BigInt(r>>>0);g.toBig=i;const o=(e,t,r)=>e>>>r;g.shrSH=o;const s=(e,t,r)=>e<<32-r|t>>>r;g.shrSL=s;const a=(e,t,r)=>e>>>r|t<<32-r;g.rotrSH=a;const u=(e,t,r)=>e<<32-r|t>>>r;g.rotrSL=u;const c=(e,t,r)=>e<<64-r|t>>>r-32;g.rotrBH=c;const f=(e,t,r)=>e>>>r-32|t<<64-r;g.rotrBL=f;const l=(e,t)=>t;g.rotr32H=l;const h=(e,t)=>e;g.rotr32L=h;const p=(e,t,r)=>e<<r|t>>>32-r;g.rotlSH=p;const y=(e,t,r)=>t<<r|e>>>32-r;g.rotlSL=y;const m=(e,t,r)=>t<<r-32|e>>>64-r;g.rotlBH=m;const b=(e,t,r)=>e<<r-32|t>>>64-r;function w(e,t,r,n){const i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:0|i}}g.rotlBL=b;const v=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0);g.add3L=v;const E=(e,t,r,n)=>t+r+n+(e/2**32|0)|0;g.add3H=E;const _=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0);g.add4L=_;const S=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0;g.add4H=S;const k=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0);g.add5L=k;const A=(e,t,r,n,i,o)=>t+r+n+i+o+(e/2**32|0)|0;g.add5H=A;const I={fromBig:r,split:n,toBig:i,shrSH:o,shrSL:s,rotrSH:a,rotrSL:u,rotrBH:c,rotrBL:f,rotr32H:l,rotr32L:h,rotlSH:p,rotlSL:y,rotlBH:m,rotlBL:b,add:w,add3L:v,add3H:E,add4L:_,add4H:S,add5H:A,add5L:k};return g.default=I,g}function b(){if(y)return a;y=1,Object.defineProperty(a,"__esModule",{value:!0}),a.sha512_224=a.sha512_256=a.sha384=a.sha512=a.sha224=a.sha256=a.SHA512_256=a.SHA512_224=a.SHA384=a.SHA512=a.SHA224=a.SHA256=void 0;const e=p(),t=m(),r=h(),n=Uint32Array.from([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]),i=new Uint32Array(64);class o extends e.HashMD{constructor(t=32){super(64,t,8,!1),this.A=0|e.SHA256_IV[0],this.B=0|e.SHA256_IV[1],this.C=0|e.SHA256_IV[2],this.D=0|e.SHA256_IV[3],this.E=0|e.SHA256_IV[4],this.F=0|e.SHA256_IV[5],this.G=0|e.SHA256_IV[6],this.H=0|e.SHA256_IV[7]}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,o){for(let e=0;e<16;e++,o+=4)i[e]=t.getUint32(o,!1);for(let e=16;e<64;e++){const t=i[e-15],n=i[e-2],o=(0,r.rotr)(t,7)^(0,r.rotr)(t,18)^t>>>3,s=(0,r.rotr)(n,17)^(0,r.rotr)(n,19)^n>>>10;i[e]=s+i[e-7]+o+i[e-16]|0}let{A:s,B:a,C:u,D:c,E:f,F:l,G:h,H:p}=this;for(let d=0;d<64;d++){const t=p+((0,r.rotr)(f,6)^(0,r.rotr)(f,11)^(0,r.rotr)(f,25))+(0,e.Chi)(f,l,h)+n[d]+i[d]|0,o=((0,r.rotr)(s,2)^(0,r.rotr)(s,13)^(0,r.rotr)(s,22))+(0,e.Maj)(s,a,u)|0;p=h,h=l,l=f,f=c+t|0,c=u,u=a,a=s,s=t+o|0}s=s+this.A|0,a=a+this.B|0,u=u+this.C|0,c=c+this.D|0,f=f+this.E|0,l=l+this.F|0,h=h+this.G|0,p=p+this.H|0,this.set(s,a,u,c,f,l,h,p)}roundClean(){(0,r.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,r.clean)(this.buffer)}}a.SHA256=o;class s extends o{constructor(){super(28),this.A=0|e.SHA224_IV[0],this.B=0|e.SHA224_IV[1],this.C=0|e.SHA224_IV[2],this.D=0|e.SHA224_IV[3],this.E=0|e.SHA224_IV[4],this.F=0|e.SHA224_IV[5],this.G=0|e.SHA224_IV[6],this.H=0|e.SHA224_IV[7]}}a.SHA224=s;const u=(()=>t.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(e=>BigInt(e))))(),c=(()=>u[0])(),f=(()=>u[1])(),l=new Uint32Array(80),d=new Uint32Array(80);class g extends e.HashMD{constructor(t=64){super(128,t,16,!1),this.Ah=0|e.SHA512_IV[0],this.Al=0|e.SHA512_IV[1],this.Bh=0|e.SHA512_IV[2],this.Bl=0|e.SHA512_IV[3],this.Ch=0|e.SHA512_IV[4],this.Cl=0|e.SHA512_IV[5],this.Dh=0|e.SHA512_IV[6],this.Dl=0|e.SHA512_IV[7],this.Eh=0|e.SHA512_IV[8],this.El=0|e.SHA512_IV[9],this.Fh=0|e.SHA512_IV[10],this.Fl=0|e.SHA512_IV[11],this.Gh=0|e.SHA512_IV[12],this.Gl=0|e.SHA512_IV[13],this.Hh=0|e.SHA512_IV[14],this.Hl=0|e.SHA512_IV[15]}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:i,Cl:o,Dh:s,Dl:a,Eh:u,El:c,Fh:f,Fl:l,Gh:h,Gl:p,Hh:d,Hl:y}=this;return[e,t,r,n,i,o,s,a,u,c,f,l,h,p,d,y]}set(e,t,r,n,i,o,s,a,u,c,f,l,h,p,d,y){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|i,this.Cl=0|o,this.Dh=0|s,this.Dl=0|a,this.Eh=0|u,this.El=0|c,this.Fh=0|f,this.Fl=0|l,this.Gh=0|h,this.Gl=0|p,this.Hh=0|d,this.Hl=0|y}process(e,r){for(let t=0;t<16;t++,r+=4)l[t]=e.getUint32(r),d[t]=e.getUint32(r+=4);for(let c=16;c<80;c++){const e=0|l[c-15],r=0|d[c-15],n=t.rotrSH(e,r,1)^t.rotrSH(e,r,8)^t.shrSH(e,r,7),i=t.rotrSL(e,r,1)^t.rotrSL(e,r,8)^t.shrSL(e,r,7),o=0|l[c-2],s=0|d[c-2],a=t.rotrSH(o,s,19)^t.rotrBH(o,s,61)^t.shrSH(o,s,6),u=t.rotrSL(o,s,19)^t.rotrBL(o,s,61)^t.shrSL(o,s,6),f=t.add4L(i,u,d[c-7],d[c-16]),h=t.add4H(f,n,a,l[c-7],l[c-16]);l[c]=0|h,d[c]=0|f}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:u,Dh:h,Dl:p,Eh:y,El:g,Fh:m,Fl:b,Gh:w,Gl:v,Hh:E,Hl:_}=this;for(let S=0;S<80;S++){const e=t.rotrSH(y,g,14)^t.rotrSH(y,g,18)^t.rotrBH(y,g,41),r=t.rotrSL(y,g,14)^t.rotrSL(y,g,18)^t.rotrBL(y,g,41),k=y&m^~y&w,A=g&b^~g&v,I=t.add5L(_,r,A,f[S],d[S]),T=t.add5H(I,E,e,k,c[S],l[S]),x=0|I,O=t.rotrSH(n,i,28)^t.rotrBH(n,i,34)^t.rotrBH(n,i,39),B=t.rotrSL(n,i,28)^t.rotrBL(n,i,34)^t.rotrBL(n,i,39),P=n&o^n&a^o&a,U=i&s^i&u^s&u;E=0|w,_=0|v,w=0|m,v=0|b,m=0|y,b=0|g,({h:y,l:g}=t.add(0|h,0|p,0|T,0|x)),h=0|a,p=0|u,a=0|o,u=0|s,o=0|n,s=0|i;const L=t.add3L(x,B,U);n=t.add3H(L,T,O,P),i=0|L}({h:n,l:i}=t.add(0|this.Ah,0|this.Al,0|n,0|i)),({h:o,l:s}=t.add(0|this.Bh,0|this.Bl,0|o,0|s)),({h:a,l:u}=t.add(0|this.Ch,0|this.Cl,0|a,0|u)),({h:h,l:p}=t.add(0|this.Dh,0|this.Dl,0|h,0|p)),({h:y,l:g}=t.add(0|this.Eh,0|this.El,0|y,0|g)),({h:m,l:b}=t.add(0|this.Fh,0|this.Fl,0|m,0|b)),({h:w,l:v}=t.add(0|this.Gh,0|this.Gl,0|w,0|v)),({h:E,l:_}=t.add(0|this.Hh,0|this.Hl,0|E,0|_)),this.set(n,i,o,s,a,u,h,p,y,g,m,b,w,v,E,_)}roundClean(){(0,r.clean)(l,d)}destroy(){(0,r.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}a.SHA512=g;class b extends g{constructor(){super(48),this.Ah=0|e.SHA384_IV[0],this.Al=0|e.SHA384_IV[1],this.Bh=0|e.SHA384_IV[2],this.Bl=0|e.SHA384_IV[3],this.Ch=0|e.SHA384_IV[4],this.Cl=0|e.SHA384_IV[5],this.Dh=0|e.SHA384_IV[6],this.Dl=0|e.SHA384_IV[7],this.Eh=0|e.SHA384_IV[8],this.El=0|e.SHA384_IV[9],this.Fh=0|e.SHA384_IV[10],this.Fl=0|e.SHA384_IV[11],this.Gh=0|e.SHA384_IV[12],this.Gl=0|e.SHA384_IV[13],this.Hh=0|e.SHA384_IV[14],this.Hl=0|e.SHA384_IV[15]}}a.SHA384=b;const w=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),v=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class E extends g{constructor(){super(28),this.Ah=0|w[0],this.Al=0|w[1],this.Bh=0|w[2],this.Bl=0|w[3],this.Ch=0|w[4],this.Cl=0|w[5],this.Dh=0|w[6],this.Dl=0|w[7],this.Eh=0|w[8],this.El=0|w[9],this.Fh=0|w[10],this.Fl=0|w[11],this.Gh=0|w[12],this.Gl=0|w[13],this.Hh=0|w[14],this.Hl=0|w[15]}}a.SHA512_224=E;class _ extends g{constructor(){super(32),this.Ah=0|v[0],this.Al=0|v[1],this.Bh=0|v[2],this.Bl=0|v[3],this.Ch=0|v[4],this.Cl=0|v[5],this.Dh=0|v[6],this.Dl=0|v[7],this.Eh=0|v[8],this.El=0|v[9],this.Fh=0|v[10],this.Fl=0|v[11],this.Gh=0|v[12],this.Gl=0|v[13],this.Hh=0|v[14],this.Hl=0|v[15]}}return a.SHA512_256=_,a.sha256=(0,r.createHasher)(()=>new o),a.sha224=(0,r.createHasher)(()=>new s),a.sha512=(0,r.createHasher)(()=>new g),a.sha384=(0,r.createHasher)(()=>new b),a.sha512_256=(0,r.createHasher)(()=>new _),a.sha512_224=(0,r.createHasher)(()=>new E),a}var w,v={},E={},_={};function S(){return w||(w=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=h();class r extends t.Hash{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(e);const n=(0,t.toBytes)(r);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=e.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),(0,t.clean)(o)}update(e){return(0,t.aexists)(this),this.iHash.update(e),this}digestInto(e){(0,t.aexists)(this),(0,t.abytes)(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:n,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=n,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=r;e.hmac=(e,t,n)=>new r(e,t).update(n).digest(),e.hmac.create=(e,t)=>new r(e,t)}(_)),_}var k,A={};function I(){return k||(k=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.notImplemented=e.bitMask=e.utf8ToBytes=e.randomBytes=e.isBytes=e.hexToBytes=e.concatBytes=e.bytesToUtf8=e.bytesToHex=e.anumber=e.abytes=void 0,e.abool=function(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)},e._abool2=function(e,t=""){if("boolean"!=typeof e){throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e)}return e},e._abytes2=function(e,r,n=""){const i=(0,t.isBytes)(e),o=e?.length,s=void 0!==r;if(!i||s&&o!==r){throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(s?` of length ${r}`:"")+", got "+(i?`length=${o}`:"type="+typeof e))}return e},e.numberToHexUnpadded=o,e.hexToNumber=s,e.bytesToNumberBE=function(e){return s((0,t.bytesToHex)(e))},e.bytesToNumberLE=function(e){return(0,t.abytes)(e),s((0,t.bytesToHex)(Uint8Array.from(e).reverse()))},e.numberToBytesBE=a,e.numberToBytesLE=function(e,t){return a(e,t).reverse()},e.numberToVarBytesBE=function(e){return(0,t.hexToBytes)(o(e))},e.ensureBytes=function(e,r,n){let i;if("string"==typeof r)try{i=(0,t.hexToBytes)(r)}catch(e_){throw new Error(e+" must be hex string or Uint8Array, cause: "+e_)}else{if(!(0,t.isBytes)(r))throw new Error(e+" must be hex string or Uint8Array");i=Uint8Array.from(r)}const o=i.length;if("number"==typeof n&&o!==n)throw new Error(e+" of length "+n+" expected, got "+o);return i},e.equalBytes=function(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r},e.copyBytes=function(e){return Uint8Array.from(e)},e.asciiToBytes=function(e){return Uint8Array.from(e,(t,r)=>{const n=t.charCodeAt(0);if(1!==t.length||n>127)throw new Error(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})},e.inRange=c,e.aInRange=function(e,t,r,n){if(!c(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)},e.bitLen=function(e){let t;for(t=0;e>n;e>>=i,t+=1);return t},e.bitGet=function(e,t){return e>>BigInt(t)&i},e.bitSet=function(e,t,r){return e|(r?i:n)<<BigInt(t)},e.createHmacDrbg=function(e,r,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof r||r<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const i=e=>new Uint8Array(e),o=e=>Uint8Array.of(e);let s=i(e),a=i(e),u=0;const c=()=>{s.fill(1),a.fill(0),u=0},f=(...e)=>n(a,s,...e),l=(e=i(0))=>{a=f(o(0),e),s=f(),0!==e.length&&(a=f(o(1),e),s=f())},h=()=>{if(u++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<r;){s=f();const t=s.slice();n.push(t),e+=s.length}return(0,t.concatBytes)(...n)};return(e,t)=>{let r;for(c(),l(e);!(r=t(h()));)l();return c(),r}},e.validateObject=function(e,t,r={}){const n=(t,r,n)=>{const i=f[r];if("function"!=typeof i)throw new Error("invalid validator function");const o=e[t];if(!(n&&void 0===o||i(o,e)))throw new Error("param "+String(t)+" is invalid. Expected "+r+", got "+o)};for(const[i,o]of Object.entries(t))n(i,o,!1);for(const[i,o]of Object.entries(r))n(i,o,!0);return e},e.isHash=function(e){return"function"==typeof e&&Number.isSafeInteger(e.outputLen)},e._validateObject=function(e,t,r={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function n(t,r,n){const i=e[t];if(n&&void 0===i)return;const o=typeof i;if(o!==r||null===i)throw new Error(`param "${t}" is invalid: expected ${r}, got ${o}`)}Object.entries(t).forEach(([e,t])=>n(e,t,!1)),Object.entries(r).forEach(([e,t])=>n(e,t,!0))},e.memoized=function(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(void 0!==i)return i;const o=e(r,...n);return t.set(r,o),o}};const t=h();var r=h();Object.defineProperty(e,"abytes",{enumerable:!0,get:function(){return r.abytes}}),Object.defineProperty(e,"anumber",{enumerable:!0,get:function(){return r.anumber}}),Object.defineProperty(e,"bytesToHex",{enumerable:!0,get:function(){return r.bytesToHex}}),Object.defineProperty(e,"bytesToUtf8",{enumerable:!0,get:function(){return r.bytesToUtf8}}),Object.defineProperty(e,"concatBytes",{enumerable:!0,get:function(){return r.concatBytes}}),Object.defineProperty(e,"hexToBytes",{enumerable:!0,get:function(){return r.hexToBytes}}),Object.defineProperty(e,"isBytes",{enumerable:!0,get:function(){return r.isBytes}}),Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return r.randomBytes}}),Object.defineProperty(e,"utf8ToBytes",{enumerable:!0,get:function(){return r.utf8ToBytes}});const n=BigInt(0),i=BigInt(1);function o(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function s(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?n:BigInt("0x"+e)}function a(e,r){return(0,t.hexToBytes)(e.toString(16).padStart(2*r,"0"))}const u=e=>"bigint"==typeof e&&n<=e;function c(e,t,r){return u(e)&&u(t)&&u(r)&&t<=e&&e<r}e.bitMask=e=>(i<<BigInt(e))-i;const f={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||(0,t.isBytes)(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};e.notImplemented=()=>{throw new Error("not implemented")}}(A)),A}var T,x,O,B,P={},U={};function L(){if(T)return U;T=1,Object.defineProperty(U,"__esModule",{value:!0}),U.isNegativeLE=void 0,U.mod=l,U.pow=function(e,t,r){return w(S(r),e,t)},U.pow2=function(e,r,n){let i=e;for(;r-- >t;)i*=i,i%=n;return i},U.invert=h,U.tonelliShanks=g,U.FpSqrt=m,U.validateField=function(t){const r=b.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"});return(0,e._validateObject)(t,r),t},U.FpPow=w,U.FpInvertBatch=v,U.FpDiv=function(e,t,r){return e.mul(t,"bigint"==typeof r?h(r,e.ORDER):e.inv(r))},U.FpLegendre=E,U.FpIsSquare=function(e,t){return 1===E(e,t)},U.nLength=_,U.Field=S,U.FpSqrtOdd=function(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?r:e.neg(r)},U.FpSqrtEven=function(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?e.neg(r):r},U.hashToPrivateScalar=function(t,n,i=!1){const o=(t=(0,e.ensureBytes)("privateHash",t)).length,s=_(n).nByteLength+8;if(s<24||o<s||o>1024)throw new Error("hashToPrivateScalar: expected "+s+"-1024 bytes of input, got "+o);return l(i?(0,e.bytesToNumberLE)(t):(0,e.bytesToNumberBE)(t),n-r)+r},U.getFieldBytesLength=k,U.getMinHashLength=A,U.mapHashToField=function(t,n,i=!1){const o=t.length,s=k(n),a=A(n);if(o<16||o<a||o>1024)throw new Error("expected "+a+"-1024 bytes of input, got "+o);const u=l(i?(0,e.bytesToNumberLE)(t):(0,e.bytesToNumberBE)(t),n-r)+r;return i?(0,e.numberToBytesLE)(u,s):(0,e.numberToBytesBE)(u,s)};const e=I(),t=BigInt(0),r=BigInt(1),n=BigInt(2),i=BigInt(3),o=BigInt(4),s=BigInt(5),a=BigInt(7),u=BigInt(8),c=BigInt(9),f=BigInt(16);function l(e,r){const n=e%r;return n>=t?n:r+n}function h(e,n){if(e===t)throw new Error("invert: expected non-zero number");if(n<=t)throw new Error("invert: expected positive modulus, got "+n);let i=l(e,n),o=n,s=t,a=r;for(;i!==t;){const e=o%i,t=s-a*(o/i);o=i,i=e,s=a,a=t}if(o!==r)throw new Error("invert: does not exist");return l(s,n)}function p(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function d(e,t){const n=(e.ORDER+r)/o,i=e.pow(t,n);return p(e,i,t),i}function y(e,t){const r=(e.ORDER-s)/u,i=e.mul(t,n),o=e.pow(i,r),a=e.mul(t,o),c=e.mul(e.mul(a,n),o),f=e.mul(a,e.sub(c,e.ONE));return p(e,f,t),f}function g(e){if(e<i)throw new Error("sqrt is not defined for small field");let o=e-r,s=0;for(;o%n===t;)o/=n,s++;let a=n;const u=S(e);for(;1===E(u,a);)if(a++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===s)return d;let c=u.pow(a,o);const f=(o+r)/n;return function(e,t){if(e.is0(t))return t;if(1!==E(e,t))throw new Error("Cannot find square root");let n=s,i=e.mul(e.ONE,c),a=e.pow(t,o),u=e.pow(t,f);for(;!e.eql(a,e.ONE);){if(e.is0(a))return e.ZERO;let t=1,o=e.sqr(a);for(;!e.eql(o,e.ONE);)if(t++,o=e.sqr(o),t===n)throw new Error("Cannot find square root");const s=r<<BigInt(n-t-1),c=e.pow(i,s);n=t,i=e.sqr(c),a=e.mul(a,i),u=e.mul(u,c)}return u}}function m(e){return e%o===i?d:e%u===s?y:e%f===c?function(e){const t=S(e),r=g(e),n=r(t,t.neg(t.ONE)),i=r(t,n),o=r(t,t.neg(n)),s=(e+a)/f;return(e,t)=>{let r=e.pow(t,s),a=e.mul(r,n);const u=e.mul(r,i),c=e.mul(r,o),f=e.eql(e.sqr(a),t),l=e.eql(e.sqr(u),t);r=e.cmov(r,a,f),a=e.cmov(c,u,l);const h=e.eql(e.sqr(a),t),d=e.cmov(r,a,h);return p(e,d,t),d}}(e):g(e)}U.isNegativeLE=(e,t)=>(l(e,t)&r)===r;const b=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function w(e,n,i){if(i<t)throw new Error("invalid exponent, negatives unsupported");if(i===t)return e.ONE;if(i===r)return n;let o=e.ONE,s=n;for(;i>t;)i&r&&(o=e.mul(o,s)),s=e.sqr(s),i>>=r;return o}function v(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),i=t.reduce((t,r,i)=>e.is0(r)?t:(n[i]=t,e.mul(t,r)),e.ONE),o=e.inv(i);return t.reduceRight((t,r,i)=>e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r)),o),n}function E(e,t){const i=(e.ORDER-r)/n,o=e.pow(t,i),s=e.eql(o,e.ONE),a=e.eql(o,e.ZERO),u=e.eql(o,e.neg(e.ONE));if(!s&&!a&&!u)throw new Error("invalid Legendre symbol result");return s?1:a?0:-1}function _(t,r){void 0!==r&&(0,e.anumber)(r);const n=void 0!==r?r:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function S(n,i,o=!1,s={}){if(n<=t)throw new Error("invalid field: expected ORDER > 0, got "+n);let a,u,c,f=!1;if("object"==typeof i&&null!=i){if(s.sqrt||o)throw new Error("cannot specify opts in two arguments");const e=i;e.BITS&&(a=e.BITS),e.sqrt&&(u=e.sqrt),"boolean"==typeof e.isLE&&(o=e.isLE),"boolean"==typeof e.modFromBytes&&(f=e.modFromBytes),c=e.allowedLengths}else"number"==typeof i&&(a=i),s.sqrt&&(u=s.sqrt);const{nBitLength:p,nByteLength:d}=_(n,a);if(d>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y;const g=Object.freeze({ORDER:n,isLE:o,BITS:p,BYTES:d,MASK:(0,e.bitMask)(p),ZERO:t,ONE:r,allowedLengths:c,create:e=>l(e,n),isValid:e=>{if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return t<=e&&e<n},is0:e=>e===t,isValidNot0:e=>!g.is0(e)&&g.isValid(e),isOdd:e=>(e&r)===r,neg:e=>l(-e,n),eql:(e,t)=>e===t,sqr:e=>l(e*e,n),add:(e,t)=>l(e+t,n),sub:(e,t)=>l(e-t,n),mul:(e,t)=>l(e*t,n),pow:(e,t)=>w(g,e,t),div:(e,t)=>l(e*h(t,n),n),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:e=>h(e,n),sqrt:u||(e=>(y||(y=m(n)),y(g,e))),toBytes:t=>o?(0,e.numberToBytesLE)(t,d):(0,e.numberToBytesBE)(t,d),fromBytes:(t,r=!0)=>{if(c){if(!c.includes(t.length)||t.length>d)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+t.length);const e=new Uint8Array(d);e.set(t,o?0:e.length-t.length),t=e}if(t.length!==d)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+t.length);let i=o?(0,e.bytesToNumberLE)(t):(0,e.bytesToNumberBE)(t);if(f&&(i=l(i,n)),!r&&!g.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>v(g,e),cmov:(e,t,r)=>r?t:e});return Object.freeze(g)}function k(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function A(e){const t=k(e);return t+Math.ceil(t/2)}return U}function N(){if(x)return P;x=1,Object.defineProperty(P,"__esModule",{value:!0}),P.wNAF=void 0,P.negateCt=i,P.normalizeZ=function(e,r){const n=(0,t.FpInvertBatch)(e.Fp,r.map(e=>e.Z));return r.map((t,r)=>e.fromAffine(t.toAffine(n[r])))},P.mulEndoUnsafe=function(e,t,i,o){let s=t,a=e.ZERO,u=e.ZERO;for(;i>r||o>r;)i&n&&(a=a.add(s)),o&n&&(u=u.add(s)),s=s.double(),i>>=n,o>>=n;return{p1:a,p2:u}},P.pippenger=function(t,r,n,i){u(n,t),c(i,r);const o=n.length,s=i.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");const a=t.ZERO,f=(0,e.bitLen)(BigInt(o));let l=1;f>12?l=f-3:f>4?l=f-2:f>0&&(l=2);const h=(0,e.bitMask)(l),p=new Array(Number(h)+1).fill(a),d=Math.floor((r.BITS-1)/l)*l;let y=a;for(let e=d;e>=0;e-=l){p.fill(a);for(let r=0;r<s;r++){const t=i[r],o=Number(t>>BigInt(e)&h);p[o]=p[o].add(n[r])}let t=a;for(let e=p.length-1,r=a;e>0;e--)r=r.add(p[e]),t=t.add(r);if(y=y.add(t),0!==e)for(let e=0;e<l;e++)y=y.double()}return y},P.precomputeMSMUnsafe=function(t,r,n,i){o(i,r.BITS),u(n,t);const s=t.ZERO,a=2**i-1,f=Math.ceil(r.BITS/i),l=(0,e.bitMask)(i),h=n.map(e=>{const t=[];for(let r=0,n=e;r<a;r++)t.push(n),n=n.add(e);return t});return e=>{if(c(e,r),e.length>n.length)throw new Error("array of scalars must be smaller than array of points");let t=s;for(let r=0;r<f;r++){if(t!==s)for(let e=0;e<i;e++)t=t.double();const n=BigInt(f*i-(r+1)*i);for(let r=0;r<e.length;r++){const i=e[r],o=Number(i>>n&l);o&&(t=t.add(h[r][o-1]))}}return t}},P.validateBasic=function(r){return(0,t.validateField)(r.Fp),(0,e.validateObject)(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(r.n,r.nBitLength),...r,p:r.Fp.ORDER})},P._createCurveFields=function(e,t,n={},i){void 0===i&&(i="edwards"===e);if(!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const u of["p","n","h"]){const e=t[u];if(!("bigint"==typeof e&&e>r))throw new Error(`CURVE.${u} must be positive bigint`)}const o=d(t.p,n.Fp,i),s=d(t.n,n.Fn,i),a=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const r of a)if(!o.isValid(t[r]))throw new Error(`CURVE.${r} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:s}};const e=I(),t=L(),r=BigInt(0),n=BigInt(1);function i(e,t){const r=t.negate();return e?r:t}function o(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function s(t,r){o(t,r);const n=2**t;return{windows:Math.ceil(r/t)+1,windowSize:2**(t-1),mask:(0,e.bitMask)(t),maxNumber:n,shiftBy:BigInt(t)}}function a(e,t,r){const{windowSize:i,mask:o,maxNumber:s,shiftBy:a}=r;let u=Number(e&o),c=e>>a;u>i&&(u-=s,c+=n);const f=t*i;return{nextN:c,offset:f+Math.abs(u)-1,isZero:0===u,isNeg:u<0,isNegF:t%2!=0,offsetF:f}}function u(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)})}function c(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,r)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+r)})}const f=new WeakMap,l=new WeakMap;function h(e){return l.get(e)||1}function p(e){if(e!==r)throw new Error("invalid wNAF")}function d(e,r,n){if(r){if(r.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(r),r}return(0,t.Field)(e,{isLE:n})}return P.wNAF=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,i=this.ZERO){let o=e;for(;t>r;)t&n&&(i=i.add(o)),o=o.double(),t>>=n;return i}precomputeWindow(e,t){const{windows:r,windowSize:n}=s(t,this.bits),i=[];let o=e,a=o;for(let s=0;s<r;s++){a=o,i.push(a);for(let e=1;e<n;e++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let n=this.ZERO,o=this.BASE;const u=s(e,this.bits);for(let s=0;s<u.windows;s++){const{nextN:e,offset:c,isZero:f,isNeg:l,isNegF:h,offsetF:p}=a(r,s,u);r=e,f?o=o.add(i(h,t[p])):n=n.add(i(l,t[c]))}return p(r),{p:n,f:o}}wNAFUnsafe(e,t,n,i=this.ZERO){const o=s(e,this.bits);for(let s=0;s<o.windows&&n!==r;s++){const{nextN:e,offset:r,isZero:u,isNeg:c}=a(n,s,o);if(n=e,!u){const e=t[r];i=i.add(c?e.negate():e)}}return p(n),i}getPrecomputes(e,t,r){let n=f.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&("function"==typeof r&&(n=r(n)),f.set(t,n))),n}cached(e,t,r){const n=h(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)}unsafe(e,t,r,n){const i=h(e);return 1===i?this._unsafeLadder(e,t,n):this.wNAFUnsafe(i,this.getPrecomputes(i,e,r),t,n)}createCache(e,t){o(t,this.bits),l.set(e,t),f.delete(e)}hasCache(e){return 1!==h(e)}},P}function R(){return O||(O=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=a,e._normFnElement=m,e.weierstrassN=b,e.SWUFpSqrtRatio=v,e.mapToCurveSimpleSWU=function(e,t){(0,o.validateField)(e);const{A:r,B:n,Z:i}=t;if(!e.isValid(r)||!e.isValid(n)||!e.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");const s=v(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return t=>{let a,u,c,f,l,h,p,d;a=e.sqr(t),a=e.mul(a,i),u=e.sqr(a),u=e.add(u,a),c=e.add(u,e.ONE),c=e.mul(c,n),f=e.cmov(i,e.neg(u),!e.eql(u,e.ZERO)),f=e.mul(f,r),u=e.sqr(c),h=e.sqr(f),l=e.mul(h,r),u=e.add(u,l),u=e.mul(u,c),h=e.mul(h,f),l=e.mul(h,n),u=e.add(u,l),p=e.mul(a,c);const{isValid:y,value:g}=s(u,h);d=e.mul(a,t),d=e.mul(d,g),p=e.cmov(p,c,y),d=e.cmov(d,g,y);const m=e.isOdd(t)===e.isOdd(d);d=e.cmov(e.neg(d),d,m);const b=(0,o.FpInvertBatch)(e,[f],!0)[0];return p=e.mul(p,b),{x:p,y:d}}},e.ecdh=_,e.ecdsa=k,e.weierstrassPoints=function(e){const{CURVE:t,curveOpts:r}=A(e),i=b(t,r);return function(e,t){const{Fp:r,Fn:i}=t;function o(e){return(0,n.inRange)(e,p,i.ORDER)}const s=T(r,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:e=>m(i,e),weierstrassEquation:s,isWithinCurveOrder:o})}(e,i)},e._legacyHelperEquat=T,e.weierstrass=function(e){const{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:i}=function(e){const{CURVE:t,curveOpts:r}=A(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}(e),s=k(b(t,r),n,i);return function(e,t){const r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,(0,o.nLength)(r.Fn.ORDER,r.Fn.BITS))})}(e,s)};const t=S(),r=h(),n=I(),i=N(),o=L(),s=(e,t)=>(e+(e>=0?t:-t)/d)/t;function a(e,t,r){const[[i,o],[a,u]]=t,c=s(u*e,r),f=s(-o*e,r);let h=e-c*i-f*a,d=-c*o-f*u;const y=h<l,g=d<l;y&&(h=-h),g&&(d=-d);const m=(0,n.bitMask)(Math.ceil((0,n.bitLen)(r)/2))+p;if(h<l||h>=m||d<l||d>=m)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:y,k1:h,k2neg:g,k2:d}}function u(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function c(e,t){const r={};for(let n of Object.keys(t))r[n]=void 0===e[n]?t[n]:e[n];return(0,n._abool2)(r.lowS,"lowS"),(0,n._abool2)(r.prehash,"prehash"),void 0!==r.format&&u(r.format),r}class f extends Error{constructor(e=""){super(e)}}e.DERErr=f,e.DER={Err:f,_tlv:{encode:(t,r)=>{const{Err:i}=e.DER;if(t<0||t>256)throw new i("tlv.encode: wrong tag");if(1&r.length)throw new i("tlv.encode: unpadded data");const o=r.length/2,s=(0,n.numberToHexUnpadded)(o);if(s.length/2&128)throw new i("tlv.encode: long form length too big");const a=o>127?(0,n.numberToHexUnpadded)(s.length/2|128):"";return(0,n.numberToHexUnpadded)(t)+a+s+r},decode(t,r){const{Err:n}=e.DER;let i=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(r.length<2||r[i++]!==t)throw new n("tlv.decode: wrong tlv");const o=r[i++];let s=0;if(!!(128&o)){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const t=r.subarray(i,i+e);if(t.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===t[0])throw new n("tlv.decode(long): zero leftmost byte");for(const r of t)s=s<<8|r;if(i+=e,s<128)throw new n("tlv.decode(long): not minimal encoding")}else s=o;const a=r.subarray(i,i+s);if(a.length!==s)throw new n("tlv.decode: wrong value length");return{v:a,l:r.subarray(i+s)}}},_int:{encode(t){const{Err:r}=e.DER;if(t<l)throw new r("integer: negative integers are not allowed");let i=(0,n.numberToHexUnpadded)(t);if(8&Number.parseInt(i[0],16)&&(i="00"+i),1&i.length)throw new r("unexpected DER parsing assertion: unpadded hex");return i},decode(t){const{Err:r}=e.DER;if(128&t[0])throw new r("invalid signature integer: negative");if(0===t[0]&&!(128&t[1]))throw new r("invalid signature integer: unnecessary leading zero");return(0,n.bytesToNumberBE)(t)}},toSig(t){const{Err:r,_int:i,_tlv:o}=e.DER,s=(0,n.ensureBytes)("signature",t),{v:a,l:u}=o.decode(48,s);if(u.length)throw new r("invalid signature: left bytes after parsing");const{v:c,l:f}=o.decode(2,a),{v:l,l:h}=o.decode(2,f);if(h.length)throw new r("invalid signature: left bytes after parsing");return{r:i.decode(c),s:i.decode(l)}},hexFromSig(t){const{_tlv:r,_int:n}=e.DER,i=r.encode(2,n.encode(t.r))+r.encode(2,n.encode(t.s));return r.encode(48,i)}};const l=BigInt(0),p=BigInt(1),d=BigInt(2),y=BigInt(3),g=BigInt(4);function m(e,t){const{BYTES:r}=e;let i;if("bigint"==typeof t)i=t;else{let s=(0,n.ensureBytes)("private key",t);try{i=e.fromBytes(s)}catch(o){throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}function b(e,t={}){const r=(0,i._createCurveFields)("weierstrass",e,t),{Fp:o,Fn:s}=r;let u=r.CURVE;const{h:c,n:f}=u;(0,n._validateObject)(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:h}=t;if(h&&(!o.is0(u.a)||"bigint"!=typeof h.beta||!Array.isArray(h.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const d=E(o,s);function b(){if(!o.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const v=t.toBytes||function(e,t,r){const{x:i,y:s}=t.toAffine(),a=o.toBytes(i);if((0,n._abool2)(r,"isCompressed"),r){b();const e=!o.isOdd(s);return(0,n.concatBytes)(w(e),a)}return(0,n.concatBytes)(Uint8Array.of(4),a,o.toBytes(s))},_=t.fromBytes||function(e){(0,n._abytes2)(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:r}=d,i=e.length,s=e[0],a=e.subarray(1);if(i!==t||2!==s&&3!==s){if(i===r&&4===s){const e=o.BYTES,t=o.fromBytes(a.subarray(0,e)),r=o.fromBytes(a.subarray(e,2*e));if(!k(t,r))throw new Error("bad point: is not on curve");return{x:t,y:r}}throw new Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${r}`)}{const e=o.fromBytes(a);if(!o.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=S(e);let r;try{r=o.sqrt(t)}catch(u){const e=u instanceof Error?": "+u.message:"";throw new Error("bad point: is not on curve, sqrt error"+e)}b();return!(1&~s)!==o.isOdd(r)&&(r=o.neg(r)),{x:e,y:r}}};function S(e){const t=o.sqr(e),r=o.mul(t,e);return o.add(o.add(r,o.mul(e,u.a)),u.b)}function k(e,t){const r=o.sqr(t),n=S(e);return o.eql(r,n)}if(!k(u.Gx,u.Gy))throw new Error("bad curve params: generator point");const A=o.mul(o.pow(u.a,y),g),I=o.mul(o.sqr(u.b),BigInt(27));if(o.is0(o.add(A,I)))throw new Error("bad curve params: a or b");function T(e,t,r=!1){if(!o.isValid(t)||r&&o.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function x(e){if(!(e instanceof L))throw new Error("ProjectivePoint expected")}function O(e){if(!h||!h.basises)throw new Error("no endo");return a(e,h.basises,s.ORDER)}const B=(0,n.memoized)((e,t)=>{const{X:r,Y:n,Z:i}=e;if(o.eql(i,o.ONE))return{x:r,y:n};const s=e.is0();null==t&&(t=s?o.ONE:o.inv(i));const a=o.mul(r,t),u=o.mul(n,t),c=o.mul(i,t);if(s)return{x:o.ZERO,y:o.ZERO};if(!o.eql(c,o.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),P=(0,n.memoized)(e=>{if(e.is0()){if(t.allowInfinityPoint&&!o.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:n}=e.toAffine();if(!o.isValid(r)||!o.isValid(n))throw new Error("bad point: x or y not field elements");if(!k(r,n))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function U(e,t,r,n,s){return r=new L(o.mul(r.X,e),r.Y,r.Z),t=(0,i.negateCt)(n,t),r=(0,i.negateCt)(s,r),t.add(r)}class L{constructor(e,t,r){this.X=T("x",e),this.Y=T("y",t,!0),this.Z=T("z",r),Object.freeze(this)}static CURVE(){return u}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!o.isValid(t)||!o.isValid(r))throw new Error("invalid affine point");if(e instanceof L)throw new Error("projective point not allowed");return o.is0(t)&&o.is0(r)?L.ZERO:new L(t,r,o.ONE)}static fromBytes(e){const t=L.fromAffine(_((0,n._abytes2)(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return L.fromBytes((0,n.ensureBytes)("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return R.createCache(this,e),t||this.multiply(y),this}assertValidity(){P(this)}hasEvenY(){const{y:e}=this.toAffine();if(!o.isOdd)throw new Error("Field doesn't support isOdd");return!o.isOdd(e)}equals(e){x(e);const{X:t,Y:r,Z:n}=this,{X:i,Y:s,Z:a}=e,u=o.eql(o.mul(t,a),o.mul(i,n)),c=o.eql(o.mul(r,a),o.mul(s,n));return u&&c}negate(){return new L(this.X,o.neg(this.Y),this.Z)}double(){const{a:e,b:t}=u,r=o.mul(t,y),{X:n,Y:i,Z:s}=this;let a=o.ZERO,c=o.ZERO,f=o.ZERO,l=o.mul(n,n),h=o.mul(i,i),p=o.mul(s,s),d=o.mul(n,i);return d=o.add(d,d),f=o.mul(n,s),f=o.add(f,f),a=o.mul(e,f),c=o.mul(r,p),c=o.add(a,c),a=o.sub(h,c),c=o.add(h,c),c=o.mul(a,c),a=o.mul(d,a),f=o.mul(r,f),p=o.mul(e,p),d=o.sub(l,p),d=o.mul(e,d),d=o.add(d,f),f=o.add(l,l),l=o.add(f,l),l=o.add(l,p),l=o.mul(l,d),c=o.add(c,l),p=o.mul(i,s),p=o.add(p,p),l=o.mul(p,d),a=o.sub(a,l),f=o.mul(p,h),f=o.add(f,f),f=o.add(f,f),new L(a,c,f)}add(e){x(e);const{X:t,Y:r,Z:n}=this,{X:i,Y:s,Z:a}=e;let c=o.ZERO,f=o.ZERO,l=o.ZERO;const h=u.a,p=o.mul(u.b,y);let d=o.mul(t,i),g=o.mul(r,s),m=o.mul(n,a),b=o.add(t,r),w=o.add(i,s);b=o.mul(b,w),w=o.add(d,g),b=o.sub(b,w),w=o.add(t,n);let v=o.add(i,a);return w=o.mul(w,v),v=o.add(d,m),w=o.sub(w,v),v=o.add(r,n),c=o.add(s,a),v=o.mul(v,c),c=o.add(g,m),v=o.sub(v,c),l=o.mul(h,w),c=o.mul(p,m),l=o.add(c,l),c=o.sub(g,l),l=o.add(g,l),f=o.mul(c,l),g=o.add(d,d),g=o.add(g,d),m=o.mul(h,m),w=o.mul(p,w),g=o.add(g,m),m=o.sub(d,m),m=o.mul(h,m),w=o.add(w,m),d=o.mul(g,w),f=o.add(f,d),d=o.mul(v,w),c=o.mul(b,c),c=o.sub(c,d),d=o.mul(b,g),l=o.mul(v,l),l=o.add(l,d),new L(c,f,l)}subtract(e){return this.add(e.negate())}is0(){return this.equals(L.ZERO)}multiply(e){const{endo:r}=t;if(!s.isValidNot0(e))throw new Error("invalid scalar: out of range");let n,o;const a=e=>R.cached(this,e,e=>(0,i.normalizeZ)(L,e));if(r){const{k1neg:t,k1:i,k2neg:s,k2:u}=O(e),{p:c,f:f}=a(i),{p:l,f:h}=a(u);o=f.add(h),n=U(r.beta,c,l,t,s)}else{const{p:t,f:r}=a(e);n=t,o=r}return(0,i.normalizeZ)(L,[n,o])[0]}multiplyUnsafe(e){const{endo:r}=t,n=this;if(!s.isValid(e))throw new Error("invalid scalar: out of range");if(e===l||n.is0())return L.ZERO;if(e===p)return n;if(R.hasCache(this))return this.multiply(e);if(r){const{k1neg:t,k1:o,k2neg:s,k2:a}=O(e),{p1:u,p2:c}=(0,i.mulEndoUnsafe)(L,n,o,a);return U(r.beta,u,c,t,s)}return R.unsafe(n,e)}multiplyAndAddUnsafe(e,t,r){const n=this.multiplyUnsafe(t).add(e.multiplyUnsafe(r));return n.is0()?void 0:n}toAffine(e){return B(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return c===p||(e?e(L,this):R.unsafe(this,f).is0())}clearCofactor(){const{clearCofactor:e}=t;return c===p?this:e?e(L,this):this.multiplyUnsafe(c)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}toBytes(e=!0){return(0,n._abool2)(e,"isCompressed"),this.assertValidity(),v(L,this,e)}toHex(e=!0){return(0,n.bytesToHex)(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return(0,i.normalizeZ)(L,e)}static msm(e,t){return(0,i.pippenger)(L,s,e,t)}static fromPrivateKey(e){return L.BASE.multiply(m(s,e))}}L.BASE=new L(u.Gx,u.Gy,o.ONE),L.ZERO=new L(o.ZERO,o.ONE,o.ZERO),L.Fp=o,L.Fn=s;const N=s.BITS,R=new i.wNAF(L,t.endo?Math.ceil(N/2):N);return L.BASE.precompute(8),L}function w(e){return Uint8Array.of(e?2:3)}function v(e,t){const r=e.ORDER;let n=l;for(let y=r-p;y%d===l;y/=d)n+=p;const i=n,o=d<<i-p-p,s=o*d,a=(r-p)/s,u=(a-p)/d,c=s-p,f=o,h=e.pow(t,a),m=e.pow(t,(a+p)/d);let b=(t,r)=>{let n=h,o=e.pow(r,c),s=e.sqr(o);s=e.mul(s,r);let a=e.mul(t,s);a=e.pow(a,u),a=e.mul(a,o),o=e.mul(a,r),s=e.mul(a,t);let l=e.mul(s,o);a=e.pow(l,f);let y=e.eql(a,e.ONE);o=e.mul(s,m),a=e.mul(l,n),s=e.cmov(o,s,y),l=e.cmov(a,l,y);for(let u=i;u>p;u--){let t=u-d;t=d<<t-p;let r=e.pow(l,t);const i=e.eql(r,e.ONE);o=e.mul(s,n),n=e.mul(n,n),r=e.mul(l,n),s=e.cmov(o,s,i),l=e.cmov(r,l,i)}return{isValid:y,value:s}};if(e.ORDER%g===y){const r=(e.ORDER-y)/g,n=e.sqrt(e.neg(t));b=(t,i)=>{let o=e.sqr(i);const s=e.mul(t,i);o=e.mul(o,s);let a=e.pow(o,r);a=e.mul(a,s);const u=e.mul(a,n),c=e.mul(e.sqr(a),i),f=e.eql(c,t);return{isValid:f,value:e.cmov(u,a,f)}}}return b}function E(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function _(e,t={}){const{Fn:r}=e,i=t.randomBytes||n.randomBytes,s=Object.assign(E(e.Fp,r),{seed:(0,o.getMinHashLength)(r.ORDER)});function a(e){try{return!!m(r,e)}catch(t){return!1}}function u(e=i(s.seed)){return(0,o.mapHashToField)((0,n._abytes2)(e,s.seed,"seed"),r.ORDER)}function c(t,n=!0){return e.BASE.multiply(m(r,t)).toBytes(n)}function f(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:i,publicKey:o,publicKeyUncompressed:a}=s;if(r.allowedLengths||i===o)return;const u=(0,n.ensureBytes)("key",t).length;return u===o||u===a}const l={isValidSecretKey:a,isValidPublicKey:function(t,r){const{publicKey:n,publicKeyUncompressed:i}=s;try{const o=t.length;return(!0!==r||o===n)&&((!1!==r||o===i)&&!!e.fromBytes(t))}catch(o){return!1}},randomSecretKey:u,isValidPrivateKey:a,randomPrivateKey:u,normPrivateKeyToScalar:e=>m(r,e),precompute:(t=8,r=e.BASE)=>r.precompute(t,!1)};return Object.freeze({getPublicKey:c,getSharedSecret:function(t,n,i=!0){if(!0===f(t))throw new Error("first arg must be private key");if(!1===f(n))throw new Error("second arg must be public key");const o=m(r,t);return e.fromHex(n).multiply(o).toBytes(i)},keygen:function(e){const t=u(e);return{secretKey:t,publicKey:c(t)}},Point:e,utils:l,lengths:s})}function k(i,o,s={}){(0,r.ahash)(o),(0,n._validateObject)(s,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const a=s.randomBytes||n.randomBytes,f=s.hmac||((e,...r)=>(0,t.hmac)(o,e,(0,n.concatBytes)(...r))),{Fp:h,Fn:y}=i,{ORDER:g,BITS:b}=y,{keygen:v,getPublicKey:E,getSharedSecret:S,utils:k,lengths:A}=_(i,s),I={prehash:!1,lowS:"boolean"==typeof s.lowS&&s.lowS,format:void 0,extraEntropy:!1},T="compact";function x(e){return e>g>>p}function O(e,t){if(!y.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class B{constructor(e,t,r){this.r=O("r",e),this.s=O("s",t),null!=r&&(this.recovery=r),Object.freeze(this)}static fromBytes(t,r=T){let i;if(function(e,t){u(t);const r=A.signature,i="compact"===t?r:"recovered"===t?r+1:void 0;(0,n._abytes2)(e,i,`${t} signature`)}(t,r),"der"===r){const{r:r,s:i}=e.DER.toSig((0,n._abytes2)(t));return new B(r,i)}"recovered"===r&&(i=t[0],r="compact",t=t.subarray(1));const o=y.BYTES,s=t.subarray(0,o),a=t.subarray(o,2*o);return new B(y.fromBytes(s),y.fromBytes(a),i)}static fromHex(e,t){return this.fromBytes((0,n.hexToBytes)(e),t)}addRecoveryBit(e){return new B(this.r,this.s,e)}recoverPublicKey(e){const t=h.ORDER,{r:r,s:o,recovery:s}=this;if(null==s||![0,1,2,3].includes(s))throw new Error("recovery id invalid");if(g*d<t&&s>1)throw new Error("recovery id is ambiguous for h>1 curve");const a=2===s||3===s?r+g:r;if(!h.isValid(a))throw new Error("recovery id 2 or 3 invalid");const u=h.toBytes(a),c=i.fromBytes((0,n.concatBytes)(w(!(1&s)),u)),f=y.inv(a),l=U((0,n.ensureBytes)("msgHash",e)),p=y.create(-l*f),m=y.create(o*f),b=i.BASE.multiplyUnsafe(p).add(c.multiplyUnsafe(m));if(b.is0())throw new Error("point at infinify");return b.assertValidity(),b}hasHighS(){return x(this.s)}toBytes(t=T){if(u(t),"der"===t)return(0,n.hexToBytes)(e.DER.hexFromSig(this));const r=y.toBytes(this.r),i=y.toBytes(this.s);if("recovered"===t){if(null==this.recovery)throw new Error("recovery bit must be present");return(0,n.concatBytes)(Uint8Array.of(this.recovery),r,i)}return(0,n.concatBytes)(r,i)}toHex(e){return(0,n.bytesToHex)(this.toBytes(e))}assertValidity(){}static fromCompact(e){return B.fromBytes((0,n.ensureBytes)("sig",e),"compact")}static fromDER(e){return B.fromBytes((0,n.ensureBytes)("sig",e),"der")}normalizeS(){return this.hasHighS()?new B(this.r,y.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,n.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,n.bytesToHex)(this.toBytes("compact"))}}const P=s.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=(0,n.bytesToNumberBE)(e),r=8*e.length-b;return r>0?t>>BigInt(r):t},U=s.bits2int_modN||function(e){return y.create(P(e))},L=(0,n.bitMask)(b);function N(e){return(0,n.aInRange)("num < 2^"+b,e,l,L),y.toBytes(e)}function R(e,t){return(0,n._abytes2)(e,void 0,"message"),t?(0,n._abytes2)(o(e),void 0,"prehashed message"):e}return Object.freeze({keygen:v,getPublicKey:E,getSharedSecret:S,utils:k,lengths:A,Point:i,sign:function(e,t,r={}){e=(0,n.ensureBytes)("message",e);const{seed:s,k2sig:u}=function(e,t,r){if(["recovered","canonical"].some(e=>e in r))throw new Error("sign() legacy options not supported");const{lowS:o,prehash:s,extraEntropy:u}=c(r,I);e=R(e,s);const f=U(e),h=m(y,t),d=[N(h),N(f)];if(null!=u&&!1!==u){const e=!0===u?a(A.secretKey):u;d.push((0,n.ensureBytes)("extraEntropy",e))}const g=(0,n.concatBytes)(...d),b=f;return{seed:g,k2sig:function(e){const t=P(e);if(!y.isValidNot0(t))return;const r=y.inv(t),n=i.BASE.multiply(t).toAffine(),s=y.create(n.x);if(s===l)return;const a=y.create(r*y.create(b+s*h));if(a===l)return;let u=(n.x===s?0:2)|Number(n.y&p),c=a;return o&&x(a)&&(c=y.neg(a),u^=1),new B(s,c,u)}}}(e,t,r);return(0,n.createHmacDrbg)(o.outputLen,y.BYTES,f)(s,u)},verify:function(t,r,o,s={}){const{lowS:a,prehash:u,format:f}=c(s,I);if(o=(0,n.ensureBytes)("publicKey",o),r=R((0,n.ensureBytes)("message",r),u),"strict"in s)throw new Error("options.strict was renamed to lowS");const l=void 0===f?function(t){let r;const i="string"==typeof t||(0,n.isBytes)(t),o=!i&&null!==t&&"object"==typeof t&&"bigint"==typeof t.r&&"bigint"==typeof t.s;if(!i&&!o)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(o)r=new B(t.r,t.s);else if(i){try{r=B.fromBytes((0,n.ensureBytes)("sig",t),"der")}catch(s){if(!(s instanceof e.DER.Err))throw s}if(!r)try{r=B.fromBytes((0,n.ensureBytes)("sig",t),"compact")}catch(a){return!1}}return r||!1}(t):B.fromBytes((0,n.ensureBytes)("sig",t),f);if(!1===l)return!1;try{const e=i.fromBytes(o);if(a&&l.hasHighS())return!1;const{r:t,s:n}=l,s=U(r),u=y.inv(n),c=y.create(s*u),f=y.create(t*u),h=i.BASE.multiplyUnsafe(c).add(e.multiplyUnsafe(f));if(h.is0())return!1;return y.create(h.x)===t}catch(e_){return!1}},recoverPublicKey:function(e,t,r={}){const{prehash:n}=c(r,I);return t=R(t,n),B.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:B,hash:o})}function A(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp;let n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:r,Fn:(0,o.Field)(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function T(e,t,r){return function(n){const i=e.sqr(n),o=e.mul(i,n);return e.add(e.add(o,e.mul(n,t)),r)}}}(E)),E}function C(){if(B)return v;B=1,Object.defineProperty(v,"__esModule",{value:!0}),v.getHash=function(e){return{hash:e}},v.createCurve=function(t,r){const n=r=>(0,e.weierstrass)({...t,hash:r});return{...n(r),create:n}};const e=R();return v}var H,K,z={};function M(){return H||(H=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=u,e.expand_message_xof=c,e.hash_to_field=f,e.isogenyMap=function(e,t){const n=t.map(e=>Array.from(e).reverse());return(t,i)=>{const[o,s,a,u]=n.map(r=>r.reduce((r,n)=>e.add(e.mul(r,t),n))),[c,f]=(0,r.FpInvertBatch)(e,[s,u],!0);return t=e.mul(o,c),i=e.mul(i,e.mul(a,f)),{x:t,y:i}}},e.createHasher=function(t,r,n){if("function"!=typeof r)throw new Error("mapToCurve() must be defined");function i(e){return t.fromAffine(r(e))}function o(e){const r=e.clearCofactor();return r.equals(t.ZERO)?t.ZERO:(r.assertValidity(),r)}return{defaults:n,hashToCurve(e,t){const r=f(e,2,Object.assign({},n,t)),s=i(r[0]),a=i(r[1]);return o(s.add(a))},encodeToCurve(e,t){const r=n.encodeDST?{DST:n.encodeDST}:{};return o(i(f(e,1,Object.assign({},n,r,t))[0]))},mapToCurve(e){if(!Array.isArray(e))throw new Error("expected array of bigints");for(const t of e)if("bigint"!=typeof t)throw new Error("expected array of bigints");return o(i(e))},hashToScalar(r,i){const o=t.Fn.ORDER;return f(r,1,Object.assign({},n,{p:o,m:1,DST:e._DST_scalar},i))[0][0]}}};const t=I(),r=L(),n=t.bytesToNumberBE;function i(e,t){if(s(e),s(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=255&e,e>>>=8;return new Uint8Array(r)}function o(e,t){const r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function s(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function a(e){if(!(0,t.isBytes)(e)&&"string"!=typeof e)throw new Error("DST must be Uint8Array or string");return"string"==typeof e?(0,t.utf8ToBytes)(e):e}function u(e,r,n,u){(0,t.abytes)(e),s(n),(r=a(r)).length>255&&(r=u((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),r)));const{outputLen:c,blockLen:f}=u,l=Math.ceil(n/c);if(n>65535||l>255)throw new Error("expand_message_xmd: invalid lenInBytes");const h=(0,t.concatBytes)(r,i(r.length,1)),p=i(0,f),d=i(n,2),y=new Array(l),g=u((0,t.concatBytes)(p,e,d,i(0,1),h));y[0]=u((0,t.concatBytes)(g,i(1,1),h));for(let s=1;s<=l;s++){const e=[o(g,y[s-1]),i(s+1,1),h];y[s]=u((0,t.concatBytes)(...e))}return(0,t.concatBytes)(...y).slice(0,n)}function c(e,r,n,o,u){if((0,t.abytes)(e),s(n),(r=a(r)).length>255){const e=Math.ceil(2*o/8);r=u.create({dkLen:e}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(r).digest()}if(n>65535||r.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return u.create({dkLen:n}).update(e).update(i(n,2)).update(r).update(i(r.length,1)).digest()}function f(e,i,o){(0,t._validateObject)(o,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:a,k:f,m:l,hash:h,expand:p,DST:d}=o;if(!(0,t.isHash)(o.hash))throw new Error("expected valid hash");(0,t.abytes)(e),s(i);const y=a.toString(2).length,g=Math.ceil((y+f)/8),m=i*l*g;let b;if("xmd"===p)b=u(e,d,m,h);else if("xof"===p)b=c(e,d,m,f,h);else{if("_internal_pass"!==p)throw new Error('expand must be "xmd" or "xof"');b=e}const w=new Array(i);for(let t=0;t<i;t++){const e=new Array(l);for(let i=0;i<l;i++){const o=g*(i+t*l),s=b.subarray(o,o+g);e[i]=(0,r.mod)(n(s),a)}w[t]=e}return w}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-")}(z)),z}function D(){return K||(K=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.encodeToCurve=e.hashToCurve=e.secp256k1_hasher=e.schnorr=e.secp256k1=void 0;const t=b(),r=h(),n=C(),i=M(),o=L(),s=R(),a=I(),u={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},c={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},f=BigInt(0),l=BigInt(1),p=BigInt(2);const d=(0,o.Field)(u.p,{sqrt:function(e){const t=u.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),a=BigInt(23),c=BigInt(44),f=BigInt(88),l=e*e*e%t,h=l*l*e%t,y=(0,o.pow2)(h,r,t)*h%t,g=(0,o.pow2)(y,r,t)*h%t,m=(0,o.pow2)(g,p,t)*l%t,b=(0,o.pow2)(m,i,t)*m%t,w=(0,o.pow2)(b,s,t)*b%t,v=(0,o.pow2)(w,c,t)*w%t,E=(0,o.pow2)(v,f,t)*v%t,_=(0,o.pow2)(E,c,t)*w%t,S=(0,o.pow2)(_,r,t)*h%t,k=(0,o.pow2)(S,a,t)*b%t,A=(0,o.pow2)(k,n,t)*l%t,I=(0,o.pow2)(A,p,t);if(!d.eql(d.sqr(I),e))throw new Error("Cannot find square root");return I}});e.secp256k1=(0,n.createCurve)({...u,Fp:d,lowS:!0,endo:c},t.sha256);const y={};function g(e,...r){let n=y[e];if(void 0===n){const r=(0,t.sha256)((0,a.utf8ToBytes)(e));n=(0,a.concatBytes)(r,r),y[e]=n}return(0,t.sha256)((0,a.concatBytes)(n,...r))}const m=e=>e.toBytes(!0).slice(1),w=(()=>e.secp256k1.Point)(),v=e=>e%p===f;function E(e){const{Fn:t,BASE:r}=w,n=(0,s._normFnElement)(t,e),i=r.multiply(n);return{scalar:v(i.y)?n:t.neg(n),bytes:m(i)}}function _(e){const t=d;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const r=t.create(e*e),n=t.create(r*e+BigInt(7));let i=t.sqrt(n);v(i)||(i=t.neg(i));const o=w.fromAffine({x:e,y:i});return o.assertValidity(),o}const S=a.bytesToNumberBE;function k(...e){return w.Fn.create(S(g("BIP0340/challenge",...e)))}function A(e){return E(e).bytes}function T(e,t,n=(0,r.randomBytes)(32)){const{Fn:i}=w,o=(0,a.ensureBytes)("message",e),{bytes:s,scalar:u}=E(t),c=(0,a.ensureBytes)("auxRand",n,32),f=i.toBytes(u^S(g("BIP0340/aux",c))),l=g("BIP0340/nonce",f,s,o),{bytes:h,scalar:p}=E(l),d=k(h,s,o),y=new Uint8Array(64);if(y.set(h,0),y.set(i.toBytes(i.create(p+d*u)),32),!x(y,o,s))throw new Error("sign: Invalid signature produced");return y}function x(e,t,r){const{Fn:n,BASE:i}=w,o=(0,a.ensureBytes)("signature",e,64),s=(0,a.ensureBytes)("message",t),c=(0,a.ensureBytes)("publicKey",r,32);try{const e=_(S(c)),t=S(o.subarray(0,32));if(!(0,a.inRange)(t,l,u.p))return!1;const r=S(o.subarray(32,64));if(!(0,a.inRange)(r,l,u.n))return!1;const f=k(n.toBytes(t),m(e),s),h=i.multiplyUnsafe(r).add(e.multiplyUnsafe(n.neg(f))),{x:p,y:d}=h.toAffine();return!(h.is0()||!v(d)||p!==t)}catch(f){return!1}}e.schnorr=(()=>{const t=(e=(0,r.randomBytes)(48))=>(0,o.mapHashToField)(e,u.n);return e.secp256k1.utils.randomSecretKey,{keygen:function(e){const r=t(e);return{secretKey:r,publicKey:A(r)}},getPublicKey:A,sign:T,verify:x,Point:w,utils:{randomSecretKey:t,randomPrivateKey:t,taggedHash:g,lift_x:_,pointToBytes:m,numberToBytesBE:a.numberToBytesBE,bytesToNumberBE:a.bytesToNumberBE,mod:o.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const O=(()=>(0,i.isogenyMap)(d,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(e=>BigInt(e)))))(),B=(()=>(0,s.mapToCurveSimpleSWU)(d,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:d.create(BigInt("-11"))}))();e.secp256k1_hasher=(0,i.createHasher)(e.secp256k1.Point,e=>{const{x:t,y:r}=B(d.create(e[0]));return O(t,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:d.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve}(s)),s}var j,F,V={};function q(){if(j)return V;j=1,Object.defineProperty(V,"__esModule",{value:!0}),V.isHash=V.validateObject=V.memoized=V.notImplemented=V.createHmacDrbg=V.bitMask=V.bitSet=V.bitGet=V.bitLen=V.aInRange=V.inRange=V.asciiToBytes=V.copyBytes=V.equalBytes=V.ensureBytes=V.numberToVarBytesBE=V.numberToBytesLE=V.numberToBytesBE=V.bytesToNumberLE=V.bytesToNumberBE=V.hexToNumber=V.numberToHexUnpadded=V.abool=V.utf8ToBytes=V.randomBytes=V.isBytes=V.hexToBytes=V.concatBytes=V.bytesToUtf8=V.bytesToHex=V.anumber=V.abytes=void 0;const e=I();return V.abytes=e.abytes,V.anumber=e.anumber,V.bytesToHex=e.bytesToHex,V.bytesToUtf8=e.bytesToUtf8,V.concatBytes=e.concatBytes,V.hexToBytes=e.hexToBytes,V.isBytes=e.isBytes,V.randomBytes=e.randomBytes,V.utf8ToBytes=e.utf8ToBytes,V.abool=e.abool,V.numberToHexUnpadded=e.numberToHexUnpadded,V.hexToNumber=e.hexToNumber,V.bytesToNumberBE=e.bytesToNumberBE,V.bytesToNumberLE=e.bytesToNumberLE,V.numberToBytesBE=e.numberToBytesBE,V.numberToBytesLE=e.numberToBytesLE,V.numberToVarBytesBE=e.numberToVarBytesBE,V.ensureBytes=e.ensureBytes,V.equalBytes=e.equalBytes,V.copyBytes=e.copyBytes,V.asciiToBytes=e.asciiToBytes,V.inRange=e.inRange,V.aInRange=e.aInRange,V.bitLen=e.bitLen,V.bitGet=e.bitGet,V.bitSet=e.bitSet,V.bitMask=e.bitMask,V.createHmacDrbg=e.createHmacDrbg,V.notImplemented=e.notImplemented,V.memoized=e.memoized,V.validateObject=e.validateObject,V.isHash=e.isHash,V}var W=function(){if(F)return o;F=1;var e=D(),t=L(),r=q();function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var i=n(t),s=n(r);const a=e.secp256k1.ProjectivePoint,u="Expected Private",c="Expected Point",f="Expected Tweak",l="Expected Signature",h="Expected Extra Data (32 bytes)",p="Expected Scalar",d=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230,175,72,160,59,191,210,94,140,208,54,65,65]),y=new Uint8Array(32),g=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,69,81,35,25,80,183,95,196,64,45,161,114,47,201,186,238]),m=BigInt(1);function b(e,t){for(let r=0;r<32;++r)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function w(e){return 0===b(e,y)}function v(e){return e instanceof Uint8Array&&32===e.length&&!(b(e,d)>=0)}function E(e){return e instanceof Uint8Array&&64===e.length&&b(e.subarray(0,32),d)<0&&b(e.subarray(32,64),d)<0}function _(e){return e instanceof Uint8Array&&64===e.length&&b(e.subarray(0,32),g)<0}function S(e){return e instanceof Uint8Array&&32===e.length}function k(e){return void 0===e||e instanceof Uint8Array&&32===e.length}function A(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e&&Number.isSafeInteger(e)&&e>=0)t=BigInt(e);else if("string"==typeof e){if(64!==e.length)throw new Error("Expected 32 bytes of private scalar");t=s.hexToNumber(e)}else{if(!(e instanceof Uint8Array))throw new TypeError("Expected valid private scalar");if(32!==e.length)throw new Error("Expected 32 bytes of private scalar");t=s.bytesToNumberBE(e)}if(t<0)throw new Error("Expected private scalar >= 0");return t}function I(t){return e.secp256k1.utils.normPrivateKeyToScalar(t)}function T(e,t,r){const n=P(e),i=A(t),o=a.BASE.multiplyAndAddUnsafe(n,i,m);if(!o)throw new Error("Tweaked point at infinity");return o.toRawBytes(r)}function x(e,t){return void 0===e?void 0===t||R(t):!!e}function O(e){try{return e()}catch(e_){return null}}function B(t){return e.schnorr.utils.lift_x(s.bytesToNumberBE(t))}function P(e){return 32===e.length?B(e):a.fromHex(e)}function U(e,t){if(32===e.length!==t)return!1;try{return t?!!B(e):!!a.fromHex(e)}catch(e_){return!1}}function N(e){return U(e,!1)}function R(e){return U(e,!1)&&33===e.length}function C(t){return e.secp256k1.utils.isValidPrivateKey(t)}function H(e){return U(e,!0)}function K(e){if(!N(e))throw new Error(c);return e.slice(1,33)}function z(t,r){if(!C(t))throw new Error(u);return O(()=>e.secp256k1.getPublicKey(t,x(r)))}return o.isPoint=N,o.isPointCompressed=R,o.isPrivate=C,o.isXOnlyPoint=H,o.pointAdd=function(e,t,r){if(!N(e)||!N(t))throw new Error(c);return O(()=>{const n=P(e),i=P(t);return n.equals(i.negate())?null:n.add(i).toRawBytes(x(r,e))})},o.pointAddScalar=function(e,t,r){if(!N(e))throw new Error(c);if(!v(t))throw new Error(f);return O(()=>T(e,t,x(r,e)))},o.pointCompress=function(e,t){if(!N(e))throw new Error(c);return P(e).toRawBytes(x(t,e))},o.pointFromScalar=z,o.pointMultiply=function(e,t,r){if(!N(e))throw new Error(c);if(!v(t))throw new Error(f);return O(()=>function(e,t,r){const n=P(e),i="string"==typeof t?t:s.bytesToHex(t),o=s.hexToNumber(i);return n.multiply(o).toRawBytes(r)}(e,t,x(r,e)))},o.privateAdd=function(t,r){if(!C(t))throw new Error(u);if(!v(r))throw new Error(f);return O(()=>function(t,r){const n=I(t),o=A(r),a=s.numberToBytesBE(i.mod(n+o,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(a)?a:null}(t,r))},o.privateNegate=function(t){if(!C(t))throw new Error(u);return function(t){const r=I(t),n=s.numberToBytesBE(e.secp256k1.CURVE.n-r,32);return e.secp256k1.utils.isValidPrivateKey(n)?n:null}(t)},o.privateSub=function(t,r){if(!C(t))throw new Error(u);if(!v(r))throw new Error(f);return O(()=>function(t,r){const n=I(t),o=A(r),a=s.numberToBytesBE(i.mod(n-o,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(a)?a:null}(t,r))},o.recover=function(t,r,n,i){if(!S(t))throw new Error("Expected Hash");if(!E(r)||!function(e){return!(w(e.subarray(0,32))||w(e.subarray(32,64)))}(r))throw new Error(l);if(2&n&&!_(r))throw new Error("Bad Recovery Id");if(!H(r.subarray(0,32)))throw new Error(l);const o=e.secp256k1.Signature.fromCompact(r).addRecoveryBit(n).recoverPublicKey(t);if(!o)throw new Error(l);return o.toRawBytes(x(i))},o.sign=function(t,r,n){if(!C(r))throw new Error(u);if(!S(t))throw new Error(p);if(!k(n))throw new Error(h);return e.secp256k1.sign(t,r,{extraEntropy:n}).toCompactRawBytes()},o.signRecoverable=function(t,r,n){if(!C(r))throw new Error(u);if(!S(t))throw new Error(p);if(!k(n))throw new Error(h);const i=e.secp256k1.sign(t,r,{extraEntropy:n});return{signature:i.toCompactRawBytes(),recoveryId:i.recovery}},o.signSchnorr=function(t,r,n){if(!C(r))throw new Error(u);if(!S(t))throw new Error(p);if(!k(n))throw new Error(h);return e.schnorr.sign(t,r,n)},o.verify=function(t,r,n,i){if(!N(r))throw new Error(c);if(!E(n))throw new Error(l);if(!S(t))throw new Error(p);return e.secp256k1.verify(n,t,r,{lowS:i})},o.verifySchnorr=function(t,r,n){if(!H(r))throw new Error(c);if(!E(n))throw new Error(l);if(!S(t))throw new Error(p);return e.schnorr.verify(n,t,r)},o.xOnlyPointAddTweak=function(e,t){if(!H(e))throw new Error(c);if(!v(t))throw new Error(f);return O(()=>{const r=T(e,t,!0);return{parity:r[0]%2==1?1:0,xOnlyPubkey:r.slice(1)}})},o.xOnlyPointFromPoint=K,o.xOnlyPointFromScalar=function(e){if(!C(e))throw new Error(u);return K(z(e))},o}();const $=e({__proto__:null,default:t(W)},[W]);for(var G={},X={byteLength:function(e){var t=te(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=te(e),i=n[0],o=n[1],s=new Q(function(e,t,r){return 3*(t+r)/4-r}(0,i,o)),a=0,u=o>0?i-4:i;for(r=0;r<u;r+=4)t=Z[e.charCodeAt(r)]<<18|Z[e.charCodeAt(r+1)]<<12|Z[e.charCodeAt(r+2)]<<6|Z[e.charCodeAt(r+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=255&t;return 2===o&&(t=Z[e.charCodeAt(r)]<<2|Z[e.charCodeAt(r+1)]>>4,s[a++]=255&t),1===o&&(t=Z[e.charCodeAt(r)]<<10|Z[e.charCodeAt(r+1)]<<4|Z[e.charCodeAt(r+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t),s},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(ne(e,s,s+o>a?a:s+o));return 1===n?(t=e[r-1],i.push(Y[t>>2]+Y[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(Y[t>>10]+Y[t>>4&63]+Y[t<<2&63]+"=")),i.join("")}},Y=[],Z=[],Q=typeof Uint8Array<"u"?Uint8Array:Array,J="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ee=0;ee<64;++ee)Y[ee]=J[ee],Z[J.charCodeAt(ee)]=ee;function te(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function re(e){return Y[e>>18&63]+Y[e>>12&63]+Y[e>>6&63]+Y[63&e]}function ne(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(re(n));return i.join("")}Z[45]=62,Z[95]=63;var ie={read:function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,f=-7,l=r?i-1:0,h=r?-1:1,p=e[t+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},write:function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<<c)-1,l=f>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?h/u:h*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*y}};!function(e){const t=X,r=ie,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=c,e.SlowBuffer=function(e){return+e!=e&&(e=0),c.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i;const{Uint8Array:o,ArrayBuffer:s,SharedArrayBuffer:a}=globalThis;function u(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new o(e);return Object.setPrototypeOf(t,c.prototype),t}function c(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return h(e)}return f(e,t,r)}function f(e,t,r){if("string"==typeof e)return function(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!c.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|g(e,t);let n=u(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(s.isView(e))return function(e){if(Z(e,o)){const t=new o(e);return d(t.buffer,t.byteOffset,t.byteLength)}return p(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(Z(e,s)||e&&Z(e.buffer,s)||typeof a<"u"&&(Z(e,a)||e&&Z(e.buffer,a)))return d(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return c.from(n,t,r);const i=function(e){if(c.isBuffer(e)){const t=0|y(e.length),r=u(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||Q(e.length)?u(0):p(e);if("Buffer"===e.type&&Array.isArray(e.data))return p(e.data)}(e);if(i)return i;if(typeof Symbol<"u"&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return c.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function h(e){return l(e),u(e<0?0:0|y(e))}function p(e){const t=e.length<0?0:0|y(e.length),r=u(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function d(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new o(e):void 0===r?new o(e,t):new o(e,t,r),Object.setPrototypeOf(n,c.prototype),n}function y(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function g(e,t){if(c.isBuffer(e))return e.length;if(s.isView(e)||Z(e,s))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return $(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:$(e).length;t=(""+t).toLowerCase(),i=!0}}function m(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0)||(r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return P(this,t,r);case"utf8":case"utf-8":return T(this,t,r);case"ascii":return O(this,t,r);case"latin1":case"binary":return B(this,t,r);case"base64":return I(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function b(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function w(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Q(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:v(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof o.prototype.indexOf?i?o.prototype.indexOf.call(e,t,r):o.prototype.lastIndexOf.call(e,t,r):v(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function v(e,t,r,n,i){let o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){let n=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(c(e,o+n)!==c(t,n)){r=!1;break}if(r)return o}return-1}function E(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=t.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(Q(n))return s;e[r+s]=n}return s}function _(e,t,r,n){return Y($(t,e.length-r),e,r,n)}function S(e,t,r,n){return Y(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function k(e,t,r,n){return Y(G(t),e,r,n)}function A(e,t,r,n){return Y(function(e,t){let r,n,i;const o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function I(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function T(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let o=null,s=t>239?4:t>223?3:t>191?2:1;if(i+s<=r){let r,n,a,u;switch(s){case 1:t<128&&(o=t);break;case 2:r=e[i+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(o=u));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(e){const t=e.length;if(t<=x)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=x));return r}(n)}c.TYPED_ARRAY_SUPPORT=function(){try{const e=new o(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,o.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch{return!1}}(),!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&"function"==typeof console.error&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),c.poolSize=8192,c.from=function(e,t,r){return f(e,t,r)},Object.setPrototypeOf(c.prototype,o.prototype),Object.setPrototypeOf(c,o),c.alloc=function(e,t,r){return function(e,t,r){return l(e),e<=0?u(e):void 0!==t?"string"==typeof r?u(e).fill(t,r):u(e).fill(t):u(e)}(e,t,r)},c.allocUnsafe=function(e){return h(e)},c.allocUnsafeSlow=function(e){return h(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==c.prototype},c.compare=function(e,t){if(Z(e,o)&&(e=c.from(e,e.offset,e.byteLength)),Z(t,o)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=c.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(Z(t,o))i+t.length>n.length?(c.isBuffer(t)||(t=c.from(t)),t.copy(n,i)):o.prototype.set.call(n,t,i);else{if(!c.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},c.byteLength=g,c.prototype._isBuffer=!0,c.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)b(this,t,t+1);return this},c.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)b(this,t,t+3),b(this,t+1,t+2);return this},c.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)b(this,t,t+7),b(this,t+1,t+6),b(this,t+2,t+5),b(this,t+3,t+4);return this},c.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?T(this,0,e):m.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(c.prototype[n]=c.prototype.inspect),c.prototype.compare=function(e,t,r,n,i){if(Z(e,o)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const u=Math.min(s,a),f=this.slice(n,i),l=e.slice(t,r);for(let o=0;o<u;++o)if(f[o]!==l[o]){s=f[o],a=l[o];break}return s<a?-1:a<s?1:0},c.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},c.prototype.indexOf=function(e,t,r){return w(this,e,t,r,!0)},c.prototype.lastIndexOf=function(e,t,r){return w(this,e,t,r,!1)},c.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return E(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":case"latin1":case"binary":return S(this,e,t,r);case"base64":return k(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const x=4096;function O(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function B(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function P(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=t;o<r;++o)i+=J[e[o]];return i}function U(e,t,r){const n=e.slice(t,r);let i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function L(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,r,n,i,o){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function R(e,t,r,n,i){F(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function H(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function K(e,t,n,i,o){return t=+t,n>>>=0,o||H(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function z(e,t,n,i,o){return t=+t,n>>>=0,o||H(e,0,n,8),r.write(e,t,n,i,52,8),n+8}c.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,c.prototype),n},c.prototype.readUintLE=c.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return n},c.prototype.readUintBE=c.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},c.prototype.readUint8=c.prototype.readUInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),this[e]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readBigUInt64LE=ee(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),c.prototype.readBigUInt64BE=ee(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)}),c.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=t,i=1,o=this[e+--n];for(;n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},c.prototype.readInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||L(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt16BE=function(e,t){e>>>=0,t||L(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readBigInt64LE=ee(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),c.prototype.readBigInt64BE=ee(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)}),c.prototype.readFloatLE=function(e,t){return e>>>=0,t||L(e,4,this.length),r.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||L(e,4,this.length),r.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||L(e,8,this.length),r.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||L(e,8,this.length),r.read(this,e,!1,52,8)},c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){N(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){N(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},c.prototype.writeUint8=c.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigUInt64LE=ee(function(e,t=0){return R(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=ee(function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=0,o=1,s=0;for(this[t]=255&e;++i<r&&(o*=256);)e<0&&0===s&&0!==this[t+i-1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},c.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===s&&0!==this[t+i+1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},c.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigInt64LE=ee(function(e,t=0){return R(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=ee(function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeFloatLE=function(e,t,r){return K(this,e,t,!0,r)},c.prototype.writeFloatBE=function(e,t,r){return K(this,e,t,!1,r)},c.prototype.writeDoubleLE=function(e,t,r){return z(this,e,t,!0,r)},c.prototype.writeDoubleBE=function(e,t,r){return z(this,e,t,!1,r)},c.prototype.copy=function(e,t,r,n){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!n&&0!==n&&(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof o.prototype.copyWithin?this.copyWithin(t,r,n):o.prototype.set.call(e,this.subarray(r,n),t),i},c.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const o=c.isBuffer(e)?e:c.from(e,n),s=o.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=o[i%s]}return this};const M={};function D(e,t,r){M[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function j(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,o){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new M.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,r){V(t,"offset"),(void 0===e[t]||void 0===e[t+r])&&q(t,e.length-(r+1))}(n,i,o)}function V(e,t){if("number"!=typeof e)throw new M.ERR_INVALID_ARG_TYPE(t,"number",e)}function q(e,t,r){throw Math.floor(e)!==e?(V(e,r),new M.ERR_OUT_OF_RANGE("offset","an integer",e)):t<0?new M.ERR_BUFFER_OUT_OF_BOUNDS:new M.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),D("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=j(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=j(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);const W=/[^+/0-9A-Za-z-_]/g;function $(e,t){let r;t=t||1/0;const n=e.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(W,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Y(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Z(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Q(e){return e!=e}const J=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function ee(e){return typeof BigInt>"u"?te:e}function te(){throw new Error("BigInt not supported")}}(G);const oe=G.Buffer,se=G.Buffer;function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ue(e,t,r=""){const n=function(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}(e),i=e?.length;if(!n||void 0!==t){throw new Error((r&&`"${r}" `)+"expected Uint8Array"+""+", got "+(n?`length=${i}`:"type="+typeof e))}return e}function ce(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function fe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function le(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function he(e,t){return e<<32-t|e>>>t}function pe(e,t){return e<<t|e>>>32-t>>>0}function de(e,t={}){const r=(t,r)=>e(r).update(t).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=t=>e(t),Object.assign(r,t),Object.freeze(r)}const ye=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ge(e,t,r){return e&t^~e&r}function me(e,t,r){return e&t^e&r^t&r}let be=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,r,n){this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=le(this.buffer)}update(e){ce(this),ue(e);const{view:t,buffer:r,blockLen:n}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s===n){const t=le(e);for(;n<=i-o;o+=n)this.process(t,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ce(this),function(e,t){ue(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,fe(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let f=o;f<n;f++)t[f]=0;r.setBigUint64(n-8,BigInt(8*this.length),i),this.process(r,0);const s=le(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)s.setUint32(4*f,c[f],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}};const we=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ve=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Ee=new Uint32Array(80);let _e=class extends be{A=0|ve[0];B=0|ve[1];C=0|ve[2];D=0|ve[3];E=0|ve[4];constructor(){super(64,20,8,!1)}get(){const{A:e,B:t,C:r,D:n,E:i}=this;return[e,t,r,n,i]}set(e,t,r,n,i){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i}process(e,t){for(let a=0;a<16;a++,t+=4)Ee[a]=e.getUint32(t,!1);for(let a=16;a<80;a++)Ee[a]=pe(Ee[a-3]^Ee[a-8]^Ee[a-14]^Ee[a-16],1);let{A:r,B:n,C:i,D:o,E:s}=this;for(let a=0;a<80;a++){let e,t;a<20?(e=ge(n,i,o),t=1518500249):a<40?(e=n^i^o,t=1859775393):a<60?(e=me(n,i,o),t=2400959708):(e=n^i^o,t=3395469782);const u=pe(r,5)+e+s+t+Ee[a]|0;s=o,o=i,i=pe(n,30),n=r,r=u}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,this.set(r,n,i,o,s)}roundClean(){fe(Ee)}destroy(){this.set(0,0,0,0,0),fe(this.buffer)}};const Se=de(()=>new _e),ke=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ae=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),Ie=Ae.map(e=>(9*e+5)%16),Te=(()=>{const e=[[Ae],[Ie]];for(let t=0;t<4;t++)for(let r of e)r.push(r[t].map(e=>ke[e]));return e})(),xe=Te[0],Oe=Te[1],Be=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Pe=xe.map((e,t)=>e.map(e=>Be[t][e])),Ue=Oe.map((e,t)=>e.map(e=>Be[t][e])),Le=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ne=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Re(e,t,r,n){return 0===e?t^r^n:1===e?t&r|~t&n:2===e?(t|~r)^n:3===e?t&n|r&~n:t^(r|~n)}const Ce=new Uint32Array(16);let He=class extends be{h0=1732584193;h1=-271733879;h2=-1732584194;h3=271733878;h4=-1009589776;constructor(){super(64,20,8,!0)}get(){const{h0:e,h1:t,h2:r,h3:n,h4:i}=this;return[e,t,r,n,i]}set(e,t,r,n,i){this.h0=0|e,this.h1=0|t,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(e,t){for(let h=0;h<16;h++,t+=4)Ce[h]=e.getUint32(t,!0);let r=0|this.h0,n=r,i=0|this.h1,o=i,s=0|this.h2,a=s,u=0|this.h3,c=u,f=0|this.h4,l=f;for(let h=0;h<5;h++){const e=4-h,t=Le[h],p=Ne[h],d=xe[h],y=Oe[h],g=Pe[h],m=Ue[h];for(let n=0;n<16;n++){const e=pe(r+Re(h,i,s,u)+Ce[d[n]]+t,g[n])+f|0;r=f,f=u,u=0|pe(s,10),s=i,i=e}for(let r=0;r<16;r++){const t=pe(n+Re(e,o,a,c)+Ce[y[r]]+p,m[r])+l|0;n=l,l=c,c=0|pe(a,10),a=o,o=t}}this.set(this.h1+s+c|0,this.h2+u+l|0,this.h3+f+n|0,this.h4+r+o|0,this.h0+i+a|0)}roundClean(){fe(Ce)}destroy(){this.destroyed=!0,fe(this.buffer),this.set(0,0,0,0,0)}};const Ke=de(()=>new He),ze=Uint32Array.from([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]),Me=new Uint32Array(64);let De=class extends be{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let f=0;f<16;f++,t+=4)Me[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){const e=Me[f-15],t=Me[f-2],r=he(e,7)^he(e,18)^e>>>3,n=he(t,17)^he(t,19)^t>>>10;Me[f]=n+Me[f-7]+r+Me[f-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let f=0;f<64;f++){const e=c+(he(s,6)^he(s,11)^he(s,25))+ge(s,a,u)+ze[f]+Me[f]|0,t=(he(r,2)^he(r,13)^he(r,22))+me(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+t|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){fe(Me)}destroy(){this.set(0,0,0,0,0,0,0,0),fe(this.buffer)}},je=class extends De{A=0|we[0];B=0|we[1];C=0|we[2];D=0|we[3];E=0|we[4];F=0|we[5];G=0|we[6];H=0|we[7];constructor(){super(32)}};const Fe=de(()=>new je,ye(1));function Ve(e){return oe.from(Fe(Uint8Array.from(e)))}function qe(e){return oe.from(Ke(Fe(Uint8Array.from(e))))}function We(e){return oe.from(Fe(Fe(Uint8Array.from(e))))}const $e={"BIP0340/challenge":oe.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":oe.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":oe.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:oe.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:oe.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:oe.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:oe.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":oe.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":oe.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function Ge(e,t){return Ve(oe.concat([$e[e],t]))}const Xe=Object.freeze(Object.defineProperty({__proto__:null,TAGGED_HASH_PREFIXES:$e,TAGS:["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],hash160:qe,hash256:We,ripemd160:function(e){return oe.from(Ke(Uint8Array.from(e)))},sha1:function(e){return oe.from(Se(Uint8Array.from(e)))},sha256:Ve,taggedHash:Ge},Symbol.toStringTag,{value:"Module"}));function Ye(e,t){const r=e.length,n=t.length;if(0===r)throw new Error("R length is zero");if(0===n)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(r>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(n>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");const i=oe.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+r]=2,i[5+r]=t.length,t.copy(i,6+r),i}function Ze(e){return e<Gt.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function Qe(e,t){const r=e.readUInt8(t);let n,i;if(r<Gt.OP_PUSHDATA1)n=r,i=1;else if(r===Gt.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===Gt.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==Gt.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}var Je,et,tt,rt,nt,it,ot,st;function at(){if(et)return Je;et=1;var e={Array:function(e){return null!=e&&e.constructor===Array},Boolean:function(e){return"boolean"==typeof e},Function:function(e){return"function"==typeof e},Nil:function(e){return null==e},Number:function(e){return"number"==typeof e},Object:function(e){return"object"==typeof e},String:function(e){return"string"==typeof e},"":function(){return!0}};for(var t in e.Null=e.Nil,e)e[t].toJSON=function(e){return e}.bind(null,t);return Je=e}function ut(){if(rt)return tt;rt=1;var e=at();function t(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function r(r){return e.Nil(r)?"":t(r.constructor)}function n(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function i(r){return e.Function(r)?r.toJSON?r.toJSON():t(r):e.Array(r)?"Array":r&&e.Object(r)?"Object":void 0!==r?r:""}function o(t,r,n){var o=function(t){return e.Function(t)?"":e.String(t)?JSON.stringify(t):t&&e.Object(t)?"":t}(r);return"Expected "+i(t)+", got"+(""!==n?" "+n:"")+(""!==o?" "+o:"")}function s(e,t,i){i=i||r(t),this.message=o(e,t,i),n(this,s),this.__type=e,this.__value=t,this.__valueTypeName=i}function a(e,t,a,u,c){e?(c=c||r(u),this.message=function(e,t,r,n,s){var a='" of type ';return"key"===t&&(a='" with key type '),o('property "'+i(r)+a+i(e),n,s)}(e,a,t,u,c)):this.message='Unexpected property "'+t+'"',n(this,s),this.__label=a,this.__property=t,this.__type=e,this.__value=u,this.__valueTypeName=c}return s.prototype=Object.create(Error.prototype),s.prototype.constructor=s,a.prototype=Object.create(Error.prototype),a.prototype.constructor=s,tt={TfTypeError:s,TfPropertyTypeError:a,tfCustomError:function(e,t){return new s(e,{},t)},tfSubError:function(e,t,r){return e instanceof a?(t=t+"."+e.__property,e=new a(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof s&&(e=new a(e.__type,t,r,e.__value,e.__valueTypeName)),n(e),e},tfJSON:i,getValueTypeName:r},tt}var ct=function(){if(st)return ot;st=1;var e=ut(),t=at(),r=e.tfJSON,n=e.TfTypeError,i=e.TfPropertyTypeError,o=e.tfSubError,s=e.getValueTypeName,a={arrayOf:function(e,n){function i(r,i){return!(!t.Array(r)||t.Nil(r)||void 0!==n.minLength&&r.length<n.minLength||void 0!==n.maxLength&&r.length>n.maxLength||void 0!==n.length&&r.length!==n.length)&&r.every(function(t,r){try{return c(e,t,i)}catch(n){throw o(n,r)}})}return e=u(e),n=n||{},i.toJSON=function(){var t="["+r(e)+"]";return void 0!==n.length?t+="{"+n.length+"}":(void 0!==n.minLength||void 0!==n.maxLength)&&(t+="{"+(void 0===n.minLength?0:n.minLength)+","+(void 0===n.maxLength?1/0:n.maxLength)+"}"),t},i},maybe:function e(n){function i(r,i){return t.Nil(r)||n(r,i,e)}return n=u(n),i.toJSON=function(){return"?"+r(n)},i},map:function(e,n){function i(r,i){if(!t.Object(r)||t.Nil(r))return!1;for(var s in r){try{n&&c(n,s,i)}catch(u){throw o(u,s,"key")}try{var a=r[s];c(e,a,i)}catch(u){throw o(u,s)}}return!0}return e=u(e),n&&(n=u(n)),i.toJSON=n?function(){return"{"+r(n)+": "+r(e)+"}"}:function(){return"{"+r(e)+"}"},i},object:function(e){var n={};for(var s in e)n[s]=u(e[s]);function a(e,r){if(!t.Object(e)||t.Nil(e))return!1;var s;try{for(s in n){c(n[s],e[s],r)}}catch(a){throw o(a,s)}if(r)for(s in e)if(!n[s])throw new i(void 0,s);return!0}return a.toJSON=function(){return r(n)},a},anyOf:function(){var e=[].slice.call(arguments).map(u);function t(t,r){return e.some(function(e){try{return c(e,t,r)}catch{return!1}})}return t.toJSON=function(){return e.map(r).join("|")},t},allOf:function(){var e=[].slice.call(arguments).map(u);function t(t,r){return e.every(function(e){try{return c(e,t,r)}catch{return!1}})}return t.toJSON=function(){return e.map(r).join(" & ")},t},quacksLike:function(e){function t(t){return e===s(t)}return t.toJSON=function(){return e},t},tuple:function(){var e=[].slice.call(arguments).map(u);function n(r,n){return!(t.Nil(r)||t.Nil(r.length)||n&&r.length!==e.length)&&e.every(function(e,t){try{return c(e,r[t],n)}catch(i){throw o(i,t)}})}return n.toJSON=function(){return"("+e.map(r).join(", ")+")"},n},value:function(e){function t(t){return t===e}return t.toJSON=function(){return e},t}};function u(e){if(t.String(e))return"?"===e[0]?a.maybe(e.slice(1)):t[e]||a.quacksLike(e);if(e&&t.Object(e)){if(t.Array(e)){if(1!==e.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return a.arrayOf(e[0])}return a.object(e)}return t.Function(e)?e:a.value(e)}function c(e,r,i,o){if(t.Function(e)){if(e(r,i))return!0;throw new n(o||e,r)}return c(u(e),r,i)}for(var f in a.oneOf=a.anyOf,t)c[f]=t[f];for(f in a)c[f]=a[f];var l=function(){if(it)return nt;it=1;var e=at(),t=ut();function r(e){return oe.isBuffer(e)}function n(e){return"string"==typeof e&&/^([0-9a-f]{2})+$/i.test(e)}function i(e,r){var n=e.toJSON();function i(i){if(!e(i))return!1;if(i.length===r)return!0;throw t.tfCustomError(n+"(Length: "+r+")",n+"(Length: "+i.length+")")}return i.toJSON=function(){return n},i}var o=i.bind(null,e.Array),s=i.bind(null,r),a=i.bind(null,n),u=i.bind(null,e.String),c=Math.pow(2,53)-1,f={ArrayN:o,Buffer:r,BufferN:s,Finite:function(e){return"number"==typeof e&&isFinite(e)},Hex:n,HexN:a,Int8:function(e){return e<<24>>24===e},Int16:function(e){return e<<16>>16===e},Int32:function(e){return(0|e)===e},Int53:function(e){return"number"==typeof e&&e>=-c&&e<=c&&Math.floor(e)===e},Range:function(t,r,n){function i(e,i){return n(e,i)&&e>t&&e<r}return n=n||e.Number,i.toJSON=function(){return`${n.toJSON()} between [${t}, ${r}]`},i},StringN:u,UInt8:function(e){return(255&e)===e},UInt16:function(e){return(65535&e)===e},UInt32:function(e){return e>>>0===e},UInt53:function(e){return"number"==typeof e&&e>=0&&e<=c&&Math.floor(e)===e}};for(var l in f)f[l].toJSON=function(e){return e}.bind(null,l);return nt=f}();for(f in l)c[f]=l[f];return c.compile=u,c.TfTypeError=n,c.TfPropertyTypeError=i,ot=c}();const ft=ae(ct),lt=se.alloc(32,0),ht=se.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function pt(e,t){return e.length===t.length&&e.every((e,r)=>e.equals(t[r]))}function dt(e){if(!se.isBuffer(e)||e.length<33)return!1;const t=e[0],r=e.subarray(1,33);if(0===r.compare(lt)||r.compare(ht)>=0)return!1;if((2===t||3===t)&&33===e.length)return!0;if(65!==e.length)return!1;const n=e.subarray(33);return!(0===n.compare(lt)||n.compare(ht)>=0)&&(4===t||6===t||7===t)}function yt(e){return ft.UInt53(e)&&e<=21e14}const gt=254;function mt(e){if(!e||"object"!=typeof e||!("output"in e))return!1;const t=e;return!!se.isBuffer(t.output)&&(void 0===t.version||(t.version&gt)===t.version)}function bt(e){return globalThis.Array.isArray(e)?2===e.length&&e.every(e=>bt(e)):mt(e)}const wt=ft.BufferN(32),vt=ft.BufferN(20),Et=ft.BufferN(32),_t=ft.Number,St=ft.Array,kt=ft.Boolean,At=ft.String,It=ft.Buffer,Tt=ft.Hex,xt=ft.maybe,Ot=ft.tuple,Bt=ft.UInt8,Pt=ft.UInt32,Ut=ft.Function,Lt=ft.BufferN,Nt=ft.Null,Rt=ft.oneOf,Ct=Object.freeze(Object.defineProperty({__proto__:null,Array:St,Boolean:kt,Buffer:It,Buffer256bit:wt,BufferN:Lt,Function:Ut,Hash160bit:vt,Hash256bit:Et,Hex:Tt,Null:Nt,Number:_t,Satoshi:yt,String:At,TAPLEAF_VERSION_MASK:gt,UInt32:Pt,UInt8:Bt,isPoint:dt,isTapleaf:mt,isTaptree:bt,maybe:xt,oneOf:Rt,stacksEqual:pt,tuple:Ot,typeforce:ft},Symbol.toStringTag,{value:"Module"})),Ht="0123456789abcdefABCDEF";Ht.split("").map(e=>e.codePointAt(0)),Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=Ht.indexOf(r);return n<0?void 0:n<16?n:n-6}),new TextEncoder,new TextDecoder;function Kt(e){"number"==typeof e?function(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!=0)throw new RangeError("value out of range")}(e):(e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")})(e)}function zt(e,t,r){Kt(e),void 0===r&&(r=0),void 0===t&&(t=new Uint8Array(Dt(e)));let n=0;return e<253?(t.set([Number(e)],r),n=1):e<=65535?(t.set([253],r),function(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);"LE"===n?(e[t]=255&r,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=255&r)}(t,r+1,Number(e),"LE"),n=3):e<=4294967295?(t.set([254],r),function(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);"LE"===n?(e[t]=255&r,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r)}(t,r+1,Number(e),"LE"),n=5):(t.set([255],r),function(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 18446744073709551615. Received ${r}`);"LE"===n?(e[t]=Number(0xffn&r),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(0xffn&r))}(t,r+1,BigInt(e),"LE"),n=9),{buffer:t,bytes:n}}function Mt(e,t){void 0===t&&(t=0);const r=e.at(t);if(void 0===r)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(253===r){const r=function(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}}(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}if(254===r){const r=function(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}}(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}{const r=function(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0n;return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),r}{let r=0n;return r=(r<<8n)+BigInt(e[t]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+7]),r}}(e,t+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function Dt(e){return Kt(e),e<253?1:e<=65535?3:e<=4294967295?5:9}const{typeforce:jt}=Ct;function Ft(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function Vt(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}function qt(e){const t=oe.allocUnsafe(e.length);return e.copy(t),t}let Wt=class e{constructor(e,t=0){this.buffer=e,this.offset=t,jt(Ot(It,Pt),[e,t])}static withCapacity(t){return new e(oe.alloc(t))}writeUInt8(e){this.offset=this.buffer.writeUInt8(e,this.offset)}writeInt32(e){this.offset=this.buffer.writeInt32LE(e,this.offset)}writeUInt32(e){this.offset=this.buffer.writeUInt32LE(e,this.offset)}writeUInt64(e){this.offset=function(e,t,r){return Ft(t,9007199254740991),e.writeInt32LE(-1&t,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}(this.buffer,e,this.offset)}writeVarInt(e){const t=zt(e,this.buffer,this.offset);this.offset+=t.bytes}writeSlice(e){if(this.buffer.length<this.offset+e.length)throw new Error("Cannot write slice out of bounds");this.offset+=e.copy(this.buffer,this.offset)}writeVarSlice(e){this.writeVarInt(e.length),this.writeSlice(e)}writeVector(e){this.writeVarInt(e.length),e.forEach(e=>this.writeVarSlice(e))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}},$t=class{constructor(e,t=0){this.buffer=e,this.offset=t,jt(Ot(It,Pt),[e,t])}readUInt8(){const e=this.buffer.readUInt8(this.offset);return this.offset++,e}readInt32(){const e=this.buffer.readInt32LE(this.offset);return this.offset+=4,e}readUInt32(){const e=this.buffer.readUInt32LE(this.offset);return this.offset+=4,e}readUInt64(){const e=function(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Ft(n+r,9007199254740991),n+r}(this.buffer,this.offset);return this.offset+=8,e}readVarInt(){const e=Mt(this.buffer,this.offset);return this.offset+=e.bytes,e.numberValue||0}readSlice(e){if(this.buffer.length<this.offset+e)throw new Error("Cannot read slice out of bounds");const t=oe.from(this.buffer.subarray(this.offset,this.offset+e));return this.offset+=e,t}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const e=this.readVarInt(),t=[];for(let r=0;r<e;r++)t.push(this.readVarSlice());return t}};const Gt={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},Xt={};for(const _R of Object.keys(Gt)){const e=Gt[_R];Xt[e]=_R}function Yt(e){let t=Math.abs(e);const r=function(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}(t),n=oe.allocUnsafe(r),i=e<0;for(let o=0;o<r;++o)n.writeUInt8(255&t,o),t>>=8;return 128&n[r-1]?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}const Zt=Object.freeze(Object.defineProperty({__proto__:null,decode:function(e,t,r){t=t||4,r=void 0===r||r;const n=e.length;if(0===n)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(127&e[n-1])&&(n<=1||!(128&e[n-2])))throw new Error("Non-minimally encoded script number");if(5===n){const t=e.readUInt32LE(0),r=e.readUInt8(4);return 128&r?-(4294967296*(-129&r)+t):4294967296*r+t}let i=0;for(let o=0;o<n;++o)i|=e[o]<<8*o;return 128&e[n-1]?-(i&~(128<<8*(n-1))):i},encode:Yt},Symbol.toStringTag,{value:"Module"})),{typeforce:Qt}=Ct,Jt=oe.alloc(1,0);function er(e){const t=-129&e;return t>0&&t<4}function tr(e){let t=0;for(;0===e[t];)++t;return t===e.length?Jt:128&(e=e.subarray(t))[0]?oe.concat([Jt,e],1+e.length):e}function rr(e){0===e[0]&&(e=e.subarray(1));const t=oe.alloc(32,0),r=Math.max(0,32-e.length);return e.copy(t,r),t}const nr=Object.freeze(Object.defineProperty({__proto__:null,decode:function(e){const t=e.readUInt8(e.length-1);if(!er(t))throw new Error(`Invalid hashType ${t}`);const r=function(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");const t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");const r=e[5+t];if(0===r)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(r>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.subarray(4,4+t),s:e.subarray(6+t)}}(e.subarray(0,-1)),n=rr(r.r),i=rr(r.s);return{signature:oe.concat([n,i],64),hashType:t}},encode:function(e,t){if(Qt({signature:Lt(64),hashType:Bt},{signature:e,hashType:t}),!er(t))throw new Error(`Invalid hashType ${t}`);const r=oe.allocUnsafe(1);r.writeUInt8(t,0);const n=tr(e.subarray(0,32)),i=tr(e.subarray(32,64));return oe.concat([Ye(n,i),r])},isDefinedHashType:er},Symbol.toStringTag,{value:"Module"})),{typeforce:ir}=Ct,or=Gt.OP_RESERVED;function sr(e){return It(e)||function(e){return _t(e)&&(e===Gt.OP_0||e>=Gt.OP_1&&e<=Gt.OP_16||e===Gt.OP_1NEGATE)}(e)}function ar(e){return St(e)&&e.every(sr)}function ur(e){return e.length-e.filter(sr).length}function cr(e){if(0===e.length)return Gt.OP_0;if(1===e.length){if(e[0]>=1&&e[0]<=16)return or+e[0];if(129===e[0])return Gt.OP_1NEGATE}}function fr(e){return oe.isBuffer(e)}function lr(e){return oe.isBuffer(e)}function hr(e){if(fr(e))return e;ir(St,e);const t=e.reduce((e,t)=>lr(t)?1===t.length&&void 0!==cr(t)?e+1:e+Ze(t.length)+t.length:e+1,0),r=oe.allocUnsafe(t);let n=0;if(e.forEach(e=>{if(lr(e)){const t=cr(e);if(void 0!==t)return r.writeUInt8(t,n),void(n+=1);n+=function(e,t,r){const n=Ze(t);return 1===n?e.writeUInt8(t,r):2===n?(e.writeUInt8(Gt.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):3===n?(e.writeUInt8(Gt.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(Gt.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}(r,e.length,n),e.copy(r,n),n+=e.length}else r.writeUInt8(e,n),n+=1}),n!==r.length)throw new Error("Could not decode chunks");return r}function pr(e){if(function(e){return St(e)}(e))return e;ir(It,e);const t=[];let r=0;for(;r<e.length;){const n=e[r];if(n>Gt.OP_0&&n<=Gt.OP_PUSHDATA4){const n=Qe(e,r);if(null===n||(r+=n.size,r+n.number>e.length))return null;const i=e.subarray(r,r+n.number);r+=n.number;const o=cr(i);void 0!==o?t.push(o):t.push(i)}else t.push(n),r+=1}return t}function dr(e){if(fr(e)&&(e=pr(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(e=>{if(lr(e)){const t=cr(e);if(void 0===t)return e.toString("hex");e=t}return Xt[e]}).join(" ")}function yr(e){return e=pr(e),ir(ar,e),e.map(e=>lr(e)?e:e===Gt.OP_0?oe.allocUnsafe(0):Yt(e-or))}function gr(e){return dt(e)}function mr(e){return!(!oe.isBuffer(e)||!er(e[e.length-1]))&&function(e){if(e.length<8||e.length>72||48!==e[0]||e[1]!==e.length-2||2!==e[2])return!1;const t=e[3];if(0===t||5+t>=e.length||2!==e[4+t])return!1;const r=e[5+t];return!(0===r||6+t+r!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||r>1&&0===e[t+6]&&!(128&e[t+7]))}(e.subarray(0,-1))}const br=Zt,wr=nr,vr=Object.freeze(Object.defineProperty({__proto__:null,compile:hr,countNonPushOnlyOPs:ur,decompile:pr,fromASM:function(e){return ir(At,e),hr(e.split(" ").map(e=>void 0!==Gt[e]?Gt[e]:(ir(Tt,e),oe.from(e,"hex"))))},isCanonicalPubKey:gr,isCanonicalScriptSignature:mr,isPushOnly:ar,number:br,opcodes:Gt,signature:wr,toASM:dr,toStack:yr},Symbol.toStringTag,{value:"Module"}));var Er=(e=>(e.P2PK="p2pk",e.P2PKH="p2pkh",e.P2SH="p2sh",e.P2MS="p2ms",e.P2WPKH="p2wpkh",e.P2WSH="p2wsh",e.P2TR="p2tr",e.P2OP="p2op",e.Embed="embed",e.ScriptRedeem="scriptRedeem",e))(Er||{});function _r(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const e=r.call(this);return this[t]=e,e},set(e){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:e,writable:!0})}})}function Sr(e){let t;return()=>(void 0!==t||(t=e()),t)}const kr=Gt;function Ar(e,t){if(!e.address&&!e.output&&!e.program&&(typeof e.deploymentVersion>"u"||!e.hash160))throw new TypeError("At least one of address, output or program must be provided");t=Object.assign({validate:!0},t||{}),ft({address:ft.maybe(ft.String),output:ft.maybe(ft.Buffer),program:ft.maybe(ft.Buffer),network:ft.maybe(ft.Object),deploymentVersion:ft.maybe(ft.Number),hash160:ft.maybe(ft.BufferN(20))},e);const r=()=>{if(typeof e.deploymentVersion<"u"&&typeof e.hash160<"u"){if(20!==e.hash160.length)throw new TypeError("hash160 must be exactly 20 bytes");if(e.deploymentVersion<0||e.deploymentVersion>255)throw new TypeError("deploymentVersion must fit in one byte");return oe.concat([oe.of(e.deploymentVersion),e.hash160])}},n=Sr(()=>Gn(e.address)),i=e.network||yn,o={name:Er.P2OP,network:i,deploymentVersion:0};if(_r(o,"program",()=>{if(e.program)return e.program;const t=r();if(t)return t;if(e.output){if(e.output[0]!==kr.OP_16)throw new TypeError("Invalid P2OP script");let t,r=1;if(e.output[1]<76)t=e.output[1],r=2;else{if(76!==e.output[1])throw new TypeError("Unsupported push opcode in P2OP script");t=e.output[2],r=3}return e.output.subarray(r,r+t)}return e.address?n().data:void 0}),_r(o,"deploymentVersion",()=>{if(o.program)return o.program[0]}),_r(o,"hash160",()=>{if(o.program)return o.program.subarray(1)}),_r(o,"output",()=>{if(o.program)return hr([kr.OP_16,o.program])}),_r(o,"address",()=>{if(!o.program)return;if(!i.bech32Opnet)throw new TypeError("Network does not support opnet");const e=On.bech32m.toWords(o.program);return e.unshift(16),On.bech32m.encode(i.bech32Opnet,e)}),t.validate){let t=se.alloc(0);if(e.address){const e=n();if(i.bech32Opnet!==e.prefix)throw new TypeError("Invalid prefix or network mismatch");if(16!==e.version)throw new TypeError("Invalid witness version for p2op");if(e.data.length<2||e.data.length>40)throw new TypeError("Invalid witness program length");t=e.data}if(e.program){if(t.length&&!t.equals(e.program))throw new TypeError("Program mismatch");t=e.program}if(!t.length&&void 0!==e.deploymentVersion&&e.hash160&&(t=r()),e.output){const e=o.program;if(t.length&&!t.equals(e))throw new TypeError("Program mismatch (output vs other source)");t=e}if(t.length<2||t.length>40)throw new TypeError(`Witness program must be 2–40 bytes. Was ${t.length} bytes`);if(void 0!==e.deploymentVersion&&e.deploymentVersion!==t[0])throw new TypeError("deploymentVersion mismatch");if(e.hash160&&!e.hash160.equals(t.subarray(1)))throw new TypeError("hash160 mismatch")}return Object.assign(o,e)}const Ir=Gt;function Tr(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({network:ft.maybe(ft.Object),address:ft.maybe(ft.String),hash:ft.maybe(ft.BufferN(20)),output:ft.maybe(ft.BufferN(25)),pubkey:ft.maybe(dt),signature:ft.maybe(mr),input:ft.maybe(ft.Buffer)},e);const r=Sr(()=>{const t=oe.from($n.decode(e.address));return{version:t.readUInt8(0),hash:t.subarray(1)}}),n=Sr(()=>pr(e.input)),i=e.network||yn,o={name:Er.P2PKH,network:i,hash:void 0};if(_r(o,"address",()=>{if(!o.hash)return;const e=oe.allocUnsafe(21);return e.writeUInt8(i.pubKeyHash,0),o.hash.copy(e,1),$n.encode(e)}),_r(o,"hash",()=>e.output?e.output.subarray(3,23):e.address?r().hash:e.pubkey||o.pubkey?qe(e.pubkey||o.pubkey):void 0),_r(o,"output",()=>{if(o.hash)return hr([Ir.OP_DUP,Ir.OP_HASH160,o.hash,Ir.OP_EQUALVERIFY,Ir.OP_CHECKSIG])}),_r(o,"pubkey",()=>{if(e.input)return n()[1]}),_r(o,"signature",()=>{if(e.input)return n()[0]}),_r(o,"input",()=>{if(!e.pubkey||!e.signature)return;let t=e.pubkey;if(e.useHybrid||e.useUncompressed){const r=Mi(e.pubkey);r&&(t=e.useUncompressed?r.uncompressed:r.hybrid)}return hr([e.signature,t])}),_r(o,"witness",()=>{if(o.input)return[]}),t.validate){let t=oe.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");t=r().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(25!==e.output.length||e.output[0]!==Ir.OP_DUP||e.output[1]!==Ir.OP_HASH160||20!==e.output[2]||e.output[23]!==Ir.OP_EQUALVERIFY||e.output[24]!==Ir.OP_CHECKSIG)throw new TypeError("Output is invalid");const r=e.output.subarray(3,23);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.pubkey){const r=qe(e.pubkey);let n=t.length>0&&!t.equals(r);if(n&&(33===e.pubkey.length&&(2===e.pubkey[0]||3===e.pubkey[0])||65===e.pubkey.length&&4===e.pubkey[0])){const r=Mi(e.pubkey);if(r){const i=qe(r.uncompressed);if(t.equals(i))n=!1,e.useUncompressed=!0;else{const i=qe(r.hybrid);n=!t.equals(i),n||(e.useHybrid=!0)}}}if(n)throw new TypeError("Hash mismatch");t=r}if(e.input){const r=n();if(2!==r.length)throw new TypeError("Input is invalid");if(!mr(r[0]))throw new TypeError("Input has invalid signature");if(!dt(r[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(r[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(r[1]))throw new TypeError("Pubkey mismatch");const i=qe(r[1]);if(t.length>0&&!t.equals(i))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,e)}const xr=Gt;function Or(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({network:ft.maybe(ft.Object),address:ft.maybe(ft.String),hash:ft.maybe(ft.BufferN(20)),output:ft.maybe(ft.BufferN(23)),redeem:ft.maybe({network:ft.maybe(ft.Object),output:ft.maybe(ft.Buffer),input:ft.maybe(ft.Buffer),witness:ft.maybe(ft.arrayOf(ft.Buffer))}),input:ft.maybe(ft.Buffer),witness:ft.maybe(ft.arrayOf(ft.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||yn);const n={network:r,name:Er.P2SH},i=Sr(()=>{const t=oe.from($n.decode(e.address));return{version:t.readUInt8(0),hash:t.subarray(1)}}),o=Sr(()=>pr(e.input)),s=Sr(()=>{const t=o(),n=t[t.length-1];return{network:r,output:n===xr.OP_FALSE?oe.from([]):n,input:hr(t.slice(0,-1)),witness:e.witness||[]}});if(_r(n,"address",()=>{if(!n.hash)return;const e=oe.allocUnsafe(21);return e.writeUInt8(n.network.scriptHash,0),n.hash.copy(e,1),$n.encode(e)}),_r(n,"hash",()=>e.output?e.output.subarray(2,22):e.address?i().hash:n.redeem&&n.redeem.output?qe(n.redeem.output):void 0),_r(n,"output",()=>{if(n.hash)return hr([xr.OP_HASH160,n.hash,xr.OP_EQUAL])}),_r(n,"redeem",()=>{if(e.input)return s()}),_r(n,"input",()=>{if(e.redeem&&e.redeem.input&&e.redeem.output)return hr([].concat(pr(e.redeem.input),e.redeem.output))}),_r(n,"witness",()=>n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0),_r(n,"name",()=>{const e=["p2sh"];return void 0!==n.redeem&&void 0!==n.redeem.name&&e.push(n.redeem.name),e.join("-")}),t.validate){let t=oe.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");t=i().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(23!==e.output.length||e.output[0]!==xr.OP_HASH160||20!==e.output[1]||e.output[22]!==xr.OP_EQUAL)throw new TypeError("Output is invalid");const r=e.output.subarray(2,22);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}const n=e=>{if(e.output){const r=pr(e.output);if(!r||r.length<1)throw new TypeError("Redeem.output too short");if(e.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(ur(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=qe(e.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.input){const t=e.input.length>0,r=e.witness&&e.witness.length>0;if(!t&&!r)throw new TypeError("Empty input");if(t&&r)throw new TypeError("Input and witness provided");if(t){if(!ar(pr(e.input)))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const e=o();if(!e||e.length<1)throw new TypeError("Input too short");if(!oe.isBuffer(s().output))throw new TypeError("Input is invalid");n(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const t=s();if(e.redeem.output&&!e.redeem.output.equals(t.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(t.input))throw new TypeError("Redeem.input mismatch")}n(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!pt(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}const Br={};function Pr(){if(!Br.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Br.eccLib}const Ur=e=>oe.from(e,"hex");function Lr(e){if(!e)throw new Error("ecc library invalid")}const Nr=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];function Rr(e,t){if(e.length<33)throw new TypeError(`The control-block length is too small. Got ${e.length}, expected min 33.`);const r=(e.length-33)/32;let n=t;for(let i=0;i<r;i++){const t=e.subarray(33+32*i,65+32*i);n=n.compare(t)<0?Mr(n,t):Mr(t,n)}return n}function Cr(e){if(mt(e))return{hash:Kr(e)};const t=[Cr(e[0]),Cr(e[1])];t.sort((e,t)=>e.hash.compare(t.hash));const[r,n]=t;return{hash:Mr(r.hash,n.hash),left:r,right:n}}function Hr(e,t){if((e=>"left"in e&&"right"in e)(e)){const r=Hr(e.left,t);if(void 0!==r)return[...r,e.right.hash];const n=Hr(e.right,t);if(void 0!==n)return[...n,e.left.hash]}else if(e.hash.equals(t))return[]}function Kr(e){const t=e.version||192;return Ge("TapLeaf",se.concat([se.from([t]),Dr(e.output)]))}function zr(e,t){if(!se.isBuffer(e)||32!==e.length||t&&32!==t.length)return null;const r=function(e,t){return Ge("TapTweak",se.concat(t?[e,t]:[e]))}(e,t),n=Pr().xOnlyPointAddTweak(e,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:se.from(n.xOnlyPubkey)}:null}function Mr(e,t){return Ge("TapBranch",se.concat([e,t]))}function Dr(e){const t=Dt(e.length),r=se.allocUnsafe(t);return zt(e.length,r),se.concat([r,e])}const jr=Gt;function Fr(e,t){if(!(e.address||e.output||e.pubkey||e.internalPubkey||e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({address:ft.maybe(ft.String),input:ft.maybe(ft.BufferN(0)),network:ft.maybe(ft.Object),output:ft.maybe(ft.BufferN(34)),internalPubkey:ft.maybe(ft.BufferN(32)),hash:ft.maybe(ft.BufferN(32)),pubkey:ft.maybe(ft.BufferN(32)),signature:ft.maybe(ft.anyOf(ft.BufferN(64),ft.BufferN(65))),witness:ft.maybe(ft.arrayOf(ft.Buffer)),scriptTree:ft.maybe(bt),redeem:ft.maybe({output:ft.maybe(ft.Buffer),redeemVersion:ft.maybe(ft.Number),witness:ft.maybe(ft.arrayOf(ft.Buffer))}),redeemVersion:ft.maybe(ft.Number)},e);const r=Sr(()=>Gn(e.address)),n=Sr(()=>{if(e.witness&&e.witness.length)return e.witness.length>=2&&80===e.witness[e.witness.length-1][0]?e.witness.slice(0,-1):e.witness.slice()}),i=Sr(()=>e.scriptTree?Cr(e.scriptTree):e.hash?{hash:e.hash}:void 0),o=e.network||yn,s={name:Er.P2TR,network:o};if(_r(s,"address",()=>{if(!s.pubkey)return;const e=On.bech32m.toWords(s.pubkey);return e.unshift(1),On.bech32m.encode(o.bech32,e)}),_r(s,"hash",()=>{const e=i();if(e)return e.hash;const t=n();if(t&&t.length>1){const e=t[t.length-1],r=e[0]&gt;return Rr(e,Kr({output:t[t.length-2],version:r}))}}),_r(s,"output",()=>{if(s.pubkey)return hr([jr.OP_1,s.pubkey])}),_r(s,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&void 0!==e.redeem.redeemVersion&&null!==e.redeem.redeemVersion?e.redeem.redeemVersion:192),_r(s,"redeem",()=>{const e=n();if(e&&!(e.length<2))return{output:e[e.length-2],witness:e.slice(0,-2),redeemVersion:e[e.length-1][0]&gt}}),_r(s,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.subarray(2);if(e.address)return r().data;if(s.internalPubkey){const e=zr(s.internalPubkey,s.hash);if(e)return e.x}}),_r(s,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const t=n();return t&&t.length>1?t[t.length-1].subarray(1,33):void 0}),_r(s,"signature",()=>{if(e.signature)return e.signature;const t=n();return t&&1===t.length?t[0]:void 0}),_r(s,"witness",()=>{if(e.witness)return e.witness;const t=i();if(t&&e.redeem&&e.redeem.output&&e.internalPubkey){const r=Hr(t,Kr({output:e.redeem.output,version:s.redeemVersion}));if(!r)return;const n=zr(e.internalPubkey,t.hash);if(!n)return;const i=se.concat([se.from([s.redeemVersion|n.parity]),e.internalPubkey].concat(r));return[e.redeem.output,i]}return e.signature?[e.signature]:void 0}),t.validate){let t=se.from([]);if(e.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(1!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.pubkey){if(t.length>0&&!t.equals(e.pubkey))throw new TypeError("Pubkey mismatch");t=e.pubkey}if(e.output){if(34!==e.output.length||e.output[0]!==jr.OP_1||32!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.subarray(2)))throw new TypeError("Pubkey mismatch");t=e.output.subarray(2)}if(e.internalPubkey){const r=zr(e.internalPubkey,s.hash);if(t.length>0&&!t.equals(r.x))throw new TypeError("Pubkey mismatch");t=r.x}const a=i();if(e.hash&&a&&!e.hash.equals(a.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&a){if(!Hr(a,Kr({output:e.redeem.output,version:s.redeemVersion})))throw new TypeError("Redeem script not in tree")}const u=n();if(e.redeem&&s.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==s.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(0===pr(e.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(s.redeem.output&&!e.redeem.output.equals(s.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&s.redeem.witness&&!pt(e.redeem.witness,s.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(1===u.length){if(e.signature&&!e.signature.equals(u[0]))throw new TypeError("Signature mismatch")}else{const r=u[u.length-1];if(r.length<33)throw new TypeError(`The control-block length is too small. Got ${r.length}, expected min 33.`);if((r.length-33)%32!=0)throw new TypeError(`The control-block length of ${r.length} is incorrect!`);const n=(r.length-33)/32;if(n>128)throw new TypeError(`The script path is too long. Got ${n}, expected max 128.`);const i=r.subarray(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(i))throw new TypeError("Internal pubkey mismatch");if(!Pr().isXOnlyPoint(i))throw new TypeError("Invalid internalPubkey for p2tr witness");const o=r[0]&gt,s=zr(i,Rr(r,Kr({output:u[u.length-2],version:o})));if(!s)throw new TypeError("Invalid outputKey for p2tr witness");if(t.length&&!t.equals(s.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(s.parity!==(1&r[0]))throw new Error("Incorrect parity")}}return Object.assign(s,e)}const Vr=Gt,qr=oe.alloc(0);function Wr(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({address:ft.maybe(ft.String),hash:ft.maybe(ft.BufferN(20)),input:ft.maybe(ft.BufferN(0)),network:ft.maybe(ft.Object),output:ft.maybe(ft.BufferN(22)),pubkey:ft.maybe(dt),signature:ft.maybe(mr),witness:ft.maybe(ft.arrayOf(ft.Buffer))},e);const r=Sr(()=>{const t=On.bech32.decode(e.address),r=t.words.shift(),n=On.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:oe.from(n)}}),n=e.network||yn,i={name:Er.P2WPKH,network:n};if(_r(i,"address",()=>{if(!i.hash)return;const e=On.bech32.toWords(i.hash);return e.unshift(0),On.bech32.encode(n.bech32,e)}),_r(i,"hash",()=>e.output?e.output.subarray(2,22):e.address?r().data:e.pubkey||i.pubkey?qe(e.pubkey||i.pubkey):void 0),_r(i,"output",()=>{if(i.hash)return hr([Vr.OP_0,i.hash])}),_r(i,"pubkey",()=>e.pubkey?e.pubkey:e.witness?e.witness[1]:void 0),_r(i,"signature",()=>{if(e.witness)return e.witness[0]}),_r(i,"input",()=>{if(i.witness)return qr}),_r(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let t=oe.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(20!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(22!==e.output.length||e.output[0]!==Vr.OP_0||20!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.subarray(2)))throw new TypeError("Hash mismatch");t=e.output.subarray(2)}if(e.pubkey){const r=qe(e.pubkey);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");if(t=r,!dt(e.pubkey)||33!==e.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(2!==e.witness.length)throw new TypeError("Witness is invalid");if(!mr(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!dt(e.witness[1])||33!==e.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const r=qe(e.witness[1]);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}const $r=Gt,Gr=oe.alloc(0);function Xr(e){return!(!oe.isBuffer(e)||65!==e.length||4!==e[0]||!dt(e))}function Yr(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({network:ft.maybe(ft.Object),address:ft.maybe(ft.String),hash:ft.maybe(ft.BufferN(32)),output:ft.maybe(ft.BufferN(34)),redeem:ft.maybe({input:ft.maybe(ft.Buffer),network:ft.maybe(ft.Object),output:ft.maybe(ft.Buffer),witness:ft.maybe(ft.arrayOf(ft.Buffer))}),input:ft.maybe(ft.BufferN(0)),witness:ft.maybe(ft.arrayOf(ft.Buffer))},e);const r=Sr(()=>{const t=On.bech32.decode(e.address),r=t.words.shift(),n=On.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:oe.from(n)}}),n=Sr(()=>pr(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||yn);const o={network:i,name:Er.P2WSH};if(_r(o,"address",()=>{if(!o.hash)return;const e=On.bech32.toWords(o.hash);return e.unshift(0),On.bech32.encode(i.bech32,e)}),_r(o,"hash",()=>e.output?e.output.subarray(2):e.address?r().data:o.redeem&&o.redeem.output?Ve(o.redeem.output):void 0),_r(o,"output",()=>{if(o.hash)return hr([$r.OP_0,o.hash])}),_r(o,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Gr,witness:e.witness.slice(0,-1)}}),_r(o,"input",()=>{if(o.witness)return Gr}),_r(o,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const t=yr(n());return o.redeem=Object.assign({witness:t},e.redeem),o.redeem.input=Gr,[].concat(t,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),_r(o,"name",()=>{const e=["p2wsh"];return void 0!==o.redeem&&void 0!==o.redeem.name&&e.push(o.redeem.name),e.join("-")}),t.validate){let t=oe.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(34!==e.output.length||e.output[0]!==$r.OP_0||32!==e.output[1])throw new TypeError("Output is invalid");const r=e.output.subarray(2);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const r=pr(e.redeem.output);if(!r||r.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(ur(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=Ve(e.redeem.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem.input&&!ar(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!pt(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Xr)||e.redeem.output&&(pr(e.redeem.output)||[]).some(Xr))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const t=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(t))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(Xr)||(pr(t)||[]).some(Xr))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)}const Zr=Gt;const Qr=Gt,Jr=Qr.OP_RESERVED;function en(e,t){if(!(e.input||e.output||e.pubkeys&&void 0!==e.m||e.signatures))throw new TypeError("Not enough data");function r(e){return mr(e)||void 0!==(t.allowIncomplete&&e===Qr.OP_0)}t=Object.assign({validate:!0},t||{}),ft({network:ft.maybe(ft.Object),m:ft.maybe(ft.Number),n:ft.maybe(ft.Number),output:ft.maybe(ft.Buffer),pubkeys:ft.maybe(ft.arrayOf(dt)),signatures:ft.maybe(ft.arrayOf(r)),input:ft.maybe(ft.Buffer)},e);const n={network:e.network||yn,name:Er.P2MS};let i=[],o=!1;function s(e){o||(o=!0,i=pr(e),n.m=i[0]-Jr,n.n=i[i.length-2]-Jr,n.pubkeys=i.slice(1,-2))}if(_r(n,"output",()=>{if(e.m&&n.n&&e.pubkeys)return hr([].concat(Jr+e.m,e.pubkeys,Jr+n.n,Qr.OP_CHECKMULTISIG))}),_r(n,"m",()=>{if(n.output)return s(n.output),n.m}),_r(n,"n",()=>{if(n.pubkeys)return n.pubkeys.length}),_r(n,"pubkeys",()=>{if(e.output)return s(e.output),n.pubkeys}),_r(n,"signatures",()=>{if(!e.input)return;const t=pr(e.input);return null!=t?t.slice(1):void 0}),_r(n,"input",()=>{if(e.signatures)return hr([Qr.OP_0].concat(e.signatures))}),_r(n,"witness",()=>{if(n.input)return[]}),_r(n,"name",()=>{if(n.m&&n.n)return`p2ms(${n.m} of ${n.n})`}),t.validate){if(e.output){if(s(e.output),!ft.Number(i[0]))throw new TypeError("Output is invalid");if(!ft.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==Qr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every(e=>dt(e)))throw new TypeError("Output is invalid");if(void 0!==e.m&&e.m!==n.m)throw new TypeError("m mismatch");if(void 0!==e.n&&e.n!==n.n)throw new TypeError("n mismatch");if(e.pubkeys&&!pt(e.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(void 0!==e.n&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=e.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==Qr.OP_0)throw new TypeError("Input is invalid");if(0===n.signatures.length||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!pt(e.signatures,n.signatures))throw new TypeError("Signature mismatch");if(void 0!==e.m&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,e)}const tn=Gt;function rn(e,t){if(!(e.input||e.output||e.pubkey||e.input||e.signature))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({network:ft.maybe(ft.Object),output:ft.maybe(ft.Buffer),pubkey:ft.maybe(dt),signature:ft.maybe(mr),input:ft.maybe(ft.Buffer)},e);const r=Sr(()=>pr(e.input)),n=e.network||yn,i={name:Er.P2PK,network:n,pubkey:void 0};if(_r(i,"output",()=>{if(e.pubkey)return hr([e.pubkey,tn.OP_CHECKSIG])}),_r(i,"pubkey",()=>{if(e.output)return e.output.subarray(1,-1)}),_r(i,"signature",()=>{if(e.input)return r()[0]}),_r(i,"input",()=>{if(e.signature)return hr([e.signature])}),_r(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==tn.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!dt(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(i.input))throw new TypeError("Signature mismatch");if(e.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!mr(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}const nn=Object.freeze(Object.defineProperty({__proto__:null,LEAF_VERSION_TAPSCRIPT:192,MAX_TAPTREE_DEPTH:128,PaymentType:Er,findScriptPath:Hr,p2data:function(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft({network:ft.maybe(ft.Object),output:ft.maybe(ft.Buffer),data:ft.maybe(ft.arrayOf(ft.Buffer))},e);const r=e.network||yn,n={name:Er.Embed,network:r,data:[]};if(_r(n,"output",()=>{if(e.data)return hr([Zr.OP_RETURN].concat(e.data))}),_r(n,"data",()=>{if(!e.output)return;const t=pr(e.output);return null!=t?t.slice(1):void 0}),t.validate&&e.output){const t=pr(e.output);if(t[0]!==Zr.OP_RETURN)throw new TypeError("Output is invalid");if(!t.slice(1).every(ft.Buffer))throw new TypeError("Output is invalid");if(e.data&&!pt(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)},p2ms:en,p2op:Ar,p2pk:rn,p2pkh:Tr,p2sh:Or,p2tr:Fr,p2wpkh:Wr,p2wsh:Yr,prop:_r,rootHashFromPath:Rr,tapleafHash:Kr,toHashTree:Cr,tweakKey:zr,value:Sr},Symbol.toStringTag,{value:"Module"})),{typeforce:on}=Ct;function sn(e){const t=e.length;return Dt(t)+t}const an=oe.allocUnsafe(0),un=[],cn=oe.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),fn=oe.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),ln=oe.from("ffffffffffffffff","hex"),hn={script:an,valueBuffer:ln};class pn{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static{this.DEFAULT_SEQUENCE=4294967295}static{this.SIGHASH_DEFAULT=0}static{this.SIGHASH_ALL=1}static{this.SIGHASH_NONE=2}static{this.SIGHASH_SINGLE=3}static{this.SIGHASH_ANYONECANPAY=128}static{this.SIGHASH_OUTPUT_MASK=3}static{this.SIGHASH_INPUT_MASK=128}static{this.ADVANCED_TRANSACTION_MARKER=0}static{this.ADVANCED_TRANSACTION_FLAG=1}static{this.TRUC_VERSION=3}static{this.TRUC_MAX_VSIZE=1e4}static{this.TRUC_CHILD_MAX_VSIZE=1e3}static fromBuffer(e,t){const r=new $t(e),n=new pn;n.version=r.readInt32();const i=r.readUInt8(),o=r.readUInt8();let s=!1;i===pn.ADVANCED_TRANSACTION_MARKER&&o===pn.ADVANCED_TRANSACTION_FLAG?s=!0:r.offset-=2;const a=r.readVarInt();for(let c=0;c<a;++c){const e=r.readSlice(32),t=r.readUInt32(),i=r.readVarSlice(),o=r.readUInt32();n.ins.push({hash:e,index:t,script:i,sequence:o,witness:un})}const u=r.readVarInt();for(let c=0;c<u;++c)n.outs.push({value:r.readUInt64(),script:r.readVarSlice()});if(s){for(let e=0;e<a;++e)n.ins[e].witness=r.readVector();if(!n.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(n.locktime=r.readUInt32(),t)return n;if(r.offset!==e.length)throw new Error("Transaction has unexpected data");return n}static fromHex(e){return pn.fromBuffer(oe.from(e,"hex"),!1)}static isCoinbaseHash(e){on(Et,e);for(let t=0;t<32;++t)if(0!==e[t])return!1;return!0}isCoinbase(){return 1===this.ins.length&&pn.isCoinbaseHash(this.ins[0].hash)}addInput(e,t,r,n){return on(Ot(Et,Pt,xt(Pt),xt(It)),[e,t,r,n]),Nt(r)&&(r=pn.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:t,script:n||an,sequence:r,witness:un})-1}addOutput(e,t){return on(Ot(It,yt),[e,t]),this.outs.push({script:e,value:t})-1}hasWitnesses(){return this.ins.some(e=>0!==e.witness.length)}weight(){return 3*this.byteLength(!1)+this.byteLength(!0)}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(e=!0){const t=e&&this.hasWitnesses();return(t?10:8)+Dt(this.ins.length)+Dt(this.outs.length)+this.ins.reduce((e,t)=>e+40+sn(t.script),0)+this.outs.reduce((e,t)=>e+8+sn(t.script),0)+(t?this.ins.reduce((e,t)=>{return e+(Dt((r=t.witness).length)+r.reduce((e,t)=>e+sn(t),0));var r},0):0)}clone(){const e=new pn;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map(e=>({hash:e.hash,index:e.index,script:e.script,sequence:e.sequence,witness:e.witness})),e.outs=this.outs.map(e=>({script:e.script,value:e.value})),e}hashForSignature(e,t,r){if(on(Ot(Pt,It,_t),[e,t,r]),e>=this.ins.length)return fn;const n=pr(t);if(!n)throw new Error("Could not decompile prevOutScript");const i=hr(n.filter(e=>e!==Gt.OP_CODESEPARATOR)),o=this.clone();if((31&r)===pn.SIGHASH_NONE)o.outs=[],o.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)});else if((31&r)===pn.SIGHASH_SINGLE){if(e>=this.outs.length)return fn;o.outs.length=e+1;for(let t=0;t<e;t++)o.outs[t]=hn;o.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)})}r&pn.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[e]],o.ins[0].script=i):(o.ins.forEach(e=>{e.script=an}),o.ins[e].script=i);const s=oe.allocUnsafe(o.byteLength(!1)+4);return s.writeInt32LE(r,s.length-4),o.__toBuffer(s,0,!1),We(s)}hashForWitnessV1(e,t,r,n,i,o){if(on(Ot(Pt,on.arrayOf(It),on.arrayOf(yt),Pt),[e,t,r,n]),r.length!==this.ins.length||t.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const s=n===pn.SIGHASH_DEFAULT?pn.SIGHASH_ALL:n&pn.SIGHASH_OUTPUT_MASK,a=(n&pn.SIGHASH_INPUT_MASK)===pn.SIGHASH_ANYONECANPAY,u=s===pn.SIGHASH_NONE,c=s===pn.SIGHASH_SINGLE;let f=an,l=an,h=an,p=an,d=an;if(!a){let e=Wt.withCapacity(36*this.ins.length);this.ins.forEach(t=>{e.writeSlice(t.hash),e.writeUInt32(t.index)}),f=Ve(e.end()),e=Wt.withCapacity(8*this.ins.length),r.forEach(t=>e.writeUInt64(t)),l=Ve(e.end()),e=Wt.withCapacity(t.map(sn).reduce((e,t)=>e+t)),t.forEach(t=>e.writeVarSlice(t)),h=Ve(e.end()),e=Wt.withCapacity(4*this.ins.length),this.ins.forEach(t=>e.writeUInt32(t.sequence)),p=Ve(e.end())}if(u||c){if(c&&e<this.outs.length){const t=this.outs[e],r=Wt.withCapacity(8+sn(t.script));r.writeUInt64(t.value),r.writeVarSlice(t.script),d=Ve(r.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const e=this.outs.map(e=>8+sn(e.script)).reduce((e,t)=>e+t),t=Wt.withCapacity(e);this.outs.forEach(e=>{t.writeUInt64(e.value),t.writeVarSlice(e.script)}),d=Ve(t.end())}const y=(i?2:0)+(o?1:0),g=174-(a?49:0)-(u?32:0)+(o?32:0)+(i?37:0),m=Wt.withCapacity(g);if(m.writeUInt8(n),m.writeInt32(this.version),m.writeUInt32(this.locktime),m.writeSlice(f),m.writeSlice(l),m.writeSlice(h),m.writeSlice(p),u||c||m.writeSlice(d),m.writeUInt8(y),a){const n=this.ins[e];m.writeSlice(n.hash),m.writeUInt32(n.index),m.writeUInt64(r[e]),m.writeVarSlice(t[e]),m.writeUInt32(n.sequence)}else m.writeUInt32(e);if(o){const e=Wt.withCapacity(sn(o));e.writeVarSlice(o),m.writeSlice(Ve(e.end()))}return c&&m.writeSlice(d),i&&(m.writeSlice(i),m.writeUInt8(0),m.writeUInt32(4294967295)),Ge("TapSighash",oe.concat([oe.from([0]),m.end()]))}hashForWitnessV0(e,t,r,n){on(Ot(Pt,It,yt,Pt),[e,t,r,n]);let i,o=oe.from([]),s=cn,a=cn,u=cn;if(n&pn.SIGHASH_ANYONECANPAY||(o=oe.allocUnsafe(36*this.ins.length),i=new Wt(o,0),this.ins.forEach(e=>{i.writeSlice(e.hash),i.writeUInt32(e.index)}),a=We(o)),!(n&pn.SIGHASH_ANYONECANPAY)&&(31&n)!==pn.SIGHASH_SINGLE&&(31&n)!==pn.SIGHASH_NONE&&(o=oe.allocUnsafe(4*this.ins.length),i=new Wt(o,0),this.ins.forEach(e=>{i.writeUInt32(e.sequence)}),u=We(o)),(31&n)!==pn.SIGHASH_SINGLE&&(31&n)!==pn.SIGHASH_NONE){const e=this.outs.reduce((e,t)=>e+8+sn(t.script),0);o=oe.allocUnsafe(e),i=new Wt(o,0),this.outs.forEach(e=>{i.writeUInt64(e.value),i.writeVarSlice(e.script)}),s=We(o)}else if((31&n)===pn.SIGHASH_SINGLE&&e<this.outs.length){const t=this.outs[e];o=oe.allocUnsafe(8+sn(t.script)),i=new Wt(o,0),i.writeUInt64(t.value),i.writeVarSlice(t.script),s=We(o)}o=oe.allocUnsafe(156+sn(t)),i=new Wt(o,0);const c=this.ins[e];return i.writeInt32(this.version),i.writeSlice(a),i.writeSlice(u),i.writeSlice(c.hash),i.writeUInt32(c.index),i.writeVarSlice(t),i.writeUInt64(r),i.writeUInt32(c.sequence),i.writeSlice(s),i.writeUInt32(this.locktime),i.writeUInt32(n),We(o)}getHash(e){return e&&this.isCoinbase()?oe.alloc(32,0):We(this.__toBuffer(void 0,void 0,e))}getId(){return Vt(this.getHash(!1)).toString("hex")}toBuffer(e,t){return this.__toBuffer(e,t,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(e,t){on(Ot(_t,It),[e,t]),this.ins[e].script=t}setWitness(e,t){on(Ot(_t,[It]),[e,t]),this.ins[e].witness=t}__toBuffer(e,t,r=!1){e||(e=oe.allocUnsafe(this.byteLength(r)));const n=new Wt(e,t||0);n.writeInt32(this.version);const i=r&&this.hasWitnesses();return i&&(n.writeUInt8(pn.ADVANCED_TRANSACTION_MARKER),n.writeUInt8(pn.ADVANCED_TRANSACTION_FLAG)),n.writeVarInt(this.ins.length),this.ins.forEach(e=>{n.writeSlice(e.hash),n.writeUInt32(e.index),n.writeVarSlice(e.script),n.writeUInt32(e.sequence)}),n.writeVarInt(this.outs.length),this.outs.forEach(e=>{"value"in e?n.writeUInt64(e.value):n.writeSlice(e.valueBuffer),n.writeVarSlice(e.script)}),i&&this.ins.forEach(e=>{n.writeVector(e.witness)}),n.writeUInt32(this.locktime),void 0!==t?e.subarray(t,n.offset):e}}const{typeforce:dn}=Ct,yn={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bech32Opnet:"op",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},gn={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bech32Opnet:"opr",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},mn={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bech32Opnet:"opt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},bn={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:49990397,private:49988504},pubKeyHash:30,scriptHash:22,wif:158},wn={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:70429096,private:70427203},pubKeyHash:113,scriptHash:196,wif:241},vn={messagePrefix:"Litecoin Signed Message:\n",bech32:"ltc",bech32Opnet:"opl",bip32:{public:27108450,private:27106558},pubKeyHash:48,scriptHash:50,wif:176},En={messagePrefix:"Litecoin Signed Message:\n",bech32:"tltc",bech32Opnet:"oplt",bip32:{public:70709117,private:70711009},pubKeyHash:111,scriptHash:58,wif:239},_n={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bitcoincash",bech32Opnet:"opbch",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},Sn={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bchtest",bech32Opnet:"opbcht",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},kn={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:50221772,private:50221816},pubKeyHash:76,scriptHash:16,wif:204},An={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:981492128,private:981489719},pubKeyHash:140,scriptHash:19,wif:239},In=Object.freeze(Object.defineProperty({__proto__:null,bitcoin:yn,bitcoinCash:_n,bitcoinCashTestnet:Sn,dash:kn,dashTestnet:An,dogecoin:bn,dogecoinTestnet:wn,litecoin:vn,litecoinTestnet:En,regtest:gn,testnet:mn},Symbol.toStringTag,{value:"Module"}));var Tn,xn={};var On=function(){if(Tn)return xn;Tn=1,Object.defineProperty(xn,"__esModule",{value:!0}),xn.bech32m=xn.bech32=void 0;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",t={};for(let c=0;c<32;c++){const r=e.charAt(c);t[r]=c}function r(e){const t=e>>25;return(33554431&e)<<5^996825010&-(1&t)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function n(e){let t=1;for(let n=0;n<e.length;++n){const i=e.charCodeAt(n);if(i<33||i>126)return"Invalid prefix ("+e+")";t=r(t)^i>>5}t=r(t);for(let n=0;n<e.length;++n){const i=e.charCodeAt(n);t=r(t)^31&i}return t}function i(e,t,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let u=0;u<e.length;++u)for(i=i<<t|e[u],o+=t;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=t)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function o(e){return i(e,8,5,!0)}function s(e){const t=i(e,5,8,!1);if(Array.isArray(t))return t}function a(e){const t=i(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function u(i){let u;function c(e,i){if(i=i||90,e.length<8)return e+" too short";if(e.length>i)return"Exceeds length limit";const o=e.toLowerCase(),s=e.toUpperCase();if(e!==o&&e!==s)return"Mixed-case string "+e;const a=(e=o).lastIndexOf("1");if(-1===a)return"No separator character for "+e;if(0===a)return"Missing prefix for "+e;const c=e.slice(0,a),f=e.slice(a+1);if(f.length<6)return"Data too short";let l=n(c);if("string"==typeof l)return l;const h=[];for(let n=0;n<f.length;++n){const e=f.charAt(n),i=t[e];if(void 0===i)return"Unknown character "+e;l=r(l)^i,!(n+6>=f.length)&&h.push(i)}return l!==u?"Invalid checksum for "+e:{prefix:c,words:h}}return u="bech32"===i?1:734539939,{decodeUnsafe:function(e,t){const r=c(e,t);if("object"==typeof r)return r},decode:function(e,t){const r=c(e,t);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,i,o){if(o=o||90,t.length+7+i.length>o)throw new TypeError("Exceeds length limit");let s=n(t=t.toLowerCase());if("string"==typeof s)throw new Error(s);let a=t+"1";for(let n=0;n<i.length;++n){const t=i[n];if(t>>5)throw new Error("Non 5-bit word");s=r(s)^t,a+=e.charAt(t)}for(let e=0;e<6;++e)s=r(s);s^=u;for(let r=0;r<6;++r){a+=e.charAt(s>>5*(5-r)&31)}return a},toWords:o,fromWordsUnsafe:s,fromWords:a}}return xn.bech32=u("bech32"),xn.bech32m=u("bech32m"),xn}();function Bn(e,...t){if(!function(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Pn(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Un(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ln(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Nn(e,t){return e<<32-t|e>>>t}function Rn(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),Bn(e),e}let Cn=class{};function Hn(e){const t=t=>e().update(Rn(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Kn(e,t,r){return e&t^~e&r}function zn(e,t,r){return e&t^e&r^t&r}let Mn=class extends Cn{constructor(e,t,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=Ln(this.buffer)}update(e){Pn(this),Bn(e=Rn(e));const{view:t,buffer:r,blockLen:n}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s===n){const t=Ln(e);for(;n<=i-o;o+=n)this.process(t,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pn(this),function(e,t){Bn(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,Un(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let f=o;f<n;f++)t[f]=0;(function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,c=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+c,a,n)})(r,n-8,BigInt(8*this.length),i),this.process(r,0);const s=Ln(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)s.setUint32(4*f,c[f],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}};const Dn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),jn=Uint32Array.from([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]),Fn=new Uint32Array(64);let Vn=class extends Mn{constructor(e=32){super(64,e,8,!1),this.A=0|Dn[0],this.B=0|Dn[1],this.C=0|Dn[2],this.D=0|Dn[3],this.E=0|Dn[4],this.F=0|Dn[5],this.G=0|Dn[6],this.H=0|Dn[7]}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let f=0;f<16;f++,t+=4)Fn[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){const e=Fn[f-15],t=Fn[f-2],r=Nn(e,7)^Nn(e,18)^e>>>3,n=Nn(t,17)^Nn(t,19)^t>>>10;Fn[f]=n+Fn[f-7]+r+Fn[f-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let f=0;f<64;f++){const e=c+(Nn(s,6)^Nn(s,11)^Nn(s,25))+Kn(s,a,u)+jn[f]+Fn[f]|0,t=(Nn(r,2)^Nn(r,13)^Nn(r,22))+zn(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+t|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){Un(Fn)}destroy(){this.set(0,0,0,0,0,0,0,0),Un(this.buffer)}};const qn=Hn(()=>new Vn);const Wn=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let a=0;a<t.length;a++)t[a]=255;for(let a=0;a<e.length;a++){const r=e.charAt(a),n=r.charCodeAt(0);if(255!==t[n])throw new TypeError(r+" is ambiguous");t[n]=a}const r=e.length,n=e.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let o=0,s=0,a=0;for(;e[o]===n;)s++,o++;const u=(e.length-o)*i+1>>>0,c=new Uint8Array(u);for(;o<e.length;){const n=e.charCodeAt(o);if(n>255)return;let i=t[n];if(255===i)return;let s=0;for(let e=u-1;(0!==i||s<a)&&-1!==e;e--,s++)i+=r*c[e]>>>0,c[e]=i%256>>>0,i=i/256>>>0;if(0!==i)throw new Error("Non-zero carry");a=s,o++}let f=u-a;for(;f!==u&&0===c[f];)f++;const l=new Uint8Array(s+(u-f));let h=s;for(;f!==u;)l[h++]=c[f++];return l}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let i=0,s=0,a=0;const u=t.length;for(;a!==u&&0===t[a];)a++,i++;const c=(u-a)*o+1>>>0,f=new Uint8Array(c);for(;a!==u;){let e=t[a],n=0;for(let t=c-1;(0!==e||n<s)&&-1!==t;t--,n++)e+=256*f[t]>>>0,f[t]=e%r>>>0,e=e/r>>>0;if(0!==e)throw new Error("Non-zero carry");s=n,a++}let l=c-s;for(;l!==c&&0===f[l];)l++;let h=n.repeat(i);for(;l<c;++l)h+=e.charAt(f[l]);return h},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const $n=function(e){function t(t){var r=t.slice(0,-4),n=t.slice(-4),i=e(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(t){var r=Uint8Array.from(t),n=e(r),i=r.length+4,o=new Uint8Array(i);return o.set(r,0),o.set(n.subarray(0,4),r.length),Wn.encode(o)},decode:function(e){var r=t(Wn.decode(e));if(null==r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(e){var r=Wn.decodeUnsafe(e);if(null!=r)return t(r)}}}(function(e){return qn(qn(e))});function Gn(e){let t,r;try{t=On.bech32.decode(e)}catch{}if(t){if(r=t.words[0],0!==r)throw new TypeError(e+" uses wrong encoding")}else if(t=On.bech32m.decode(e),r=t.words[0],0===r)throw new TypeError(e+" uses wrong encoding");const n=On.bech32.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:oe.from(n)}}const{p:Xn,n:Yn,Gx:Zn,Gy:Qn,b:Jn}={p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n},ei=(e="")=>{throw new Error(e)},ti=e=>"bigint"==typeof e,ri=e=>"string"==typeof e,ni=(e,t)=>!(e=>e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name)(e)||"number"==typeof t&&t>0&&e.length!==t?ei("Uint8Array expected"):e,ii=e=>new Uint8Array(e),oi=(e,t)=>e.toString(16).padStart(t,"0"),si=e=>Array.from(ni(e)).map(e=>oi(e,2)).join(""),ai=48,ui=57,ci=65,fi=70,li=97,hi=102,pi=e=>e>=ai&&e<=ui?e-ai:e>=ci&&e<=fi?e-(ci-10):e>=li&&e<=hi?e-(li-10):void 0,di=e=>{const t="hex invalid";if(!ri(e))return ei(t);const r=e.length,n=r/2;if(r%2)return ei(t);const i=ii(n);for(let o=0,s=0;o<n;o++,s+=2){const r=pi(e.charCodeAt(s)),n=pi(e.charCodeAt(s+1));if(void 0===r||void 0===n)return ei(t);i[o]=16*r+n}return i},yi=(e,t)=>ni(ri(e)?di(e):(e=>Uint8Array.from(e))(ni(e)),t),gi=(...e)=>{const t=ii(e.reduce((e,t)=>e+ni(t).length,0));let r=0;return e.forEach(e=>{t.set(e,r),r+=e.length}),t},mi=BigInt,bi=(e,t,r,n="bad number: out of range")=>ti(e)&&t<=e&&e<r?e:ei(n),wi=(e,t=Xn)=>{const r=e%t;return r>=0n?r:t+r},vi=e=>e instanceof Ii?e:ei("Point expected"),Ei=e=>wi(wi(e*e)*e+Jn),_i=e=>bi(e,0n,Xn),Si=e=>bi(e,1n,Xn),ki=e=>0n==(1n&e),Ai=e=>Uint8Array.of(e);let Ii=class e{static BASE;static ZERO;px;py;pz;constructor(e,t,r){this.px=_i(e),this.py=Si(t),this.pz=_i(r),Object.freeze(this)}static fromBytes(t){let r;ni(t);const n=t[0],i=t.subarray(1),o=Bi(i,0,32),s=t.length;if(33===s&&[2,3].includes(n)){let t=(e=>{const t=Ei(Si(e));let r=1n;for(let n=t,i=(Xn+1n)/4n;i>0n;i>>=1n)1n&i&&(r=r*n%Xn),n=n*n%Xn;return wi(r*r)===t?r:ei("sqrt invalid")})(o);const i=ki(t);ki(mi(n))!==i&&(t=wi(-t)),r=new e(o,t,1n)}return 65===s&&4===n&&(r=new e(o,Bi(i,32,64),1n)),r?r.assertValidity():ei("bad point: not on curve")}equals(e){const{px:t,py:r,pz:n}=this,{px:i,py:o,pz:s}=vi(e),a=wi(t*s),u=wi(i*n),c=wi(r*s),f=wi(o*n);return a===u&&c===f}is0(){return this.equals(xi)}negate(){return new e(this.px,wi(-this.py),this.pz)}double(){return this.add(this)}add(t){const{px:r,py:n,pz:i}=this,{px:o,py:s,pz:a}=vi(t);let u=0n,c=0n,f=0n;const l=wi(3n*Jn);let h=wi(r*o),p=wi(n*s),d=wi(i*a),y=wi(r+n),g=wi(o+s);y=wi(y*g),g=wi(h+p),y=wi(y-g),g=wi(r+i);let m=wi(o+a);return g=wi(g*m),m=wi(h+d),g=wi(g-m),m=wi(n+i),u=wi(s+a),m=wi(m*u),u=wi(p+d),m=wi(m-u),f=wi(0n*g),u=wi(l*d),f=wi(u+f),u=wi(p-f),f=wi(p+f),c=wi(u*f),p=wi(h+h),p=wi(p+h),d=wi(0n*d),g=wi(l*g),p=wi(p+d),d=wi(h-d),d=wi(0n*d),g=wi(g+d),h=wi(p*g),c=wi(c+h),h=wi(m*g),u=wi(y*u),u=wi(u-h),h=wi(y*p),f=wi(m*f),f=wi(f+h),new e(u,c,f)}multiply(e,t=!0){if(!t&&0n===e)return xi;if(bi(e,1n,Yn),1n===e)return this;if(this.equals(Ti))return Hi(e).p;let r=xi,n=Ti;for(let i=this;e>0n;i=i.double(),e>>=1n)1n&e?r=r.add(i):t&&(n=n.add(i));return r}toAffine(){const{px:e,py:t,pz:r}=this;if(this.equals(xi))return{x:0n,y:0n};if(1n===r)return{x:e,y:t};const n=((e,t)=>{(0n===e||t<=0n)&&ei("no inverse n="+e+" mod="+t);let r=wi(e,t),n=t,i=0n,o=1n;for(;0n!==r;){const e=n%r,t=i-o*(n/r);n=r,r=e,i=o,o=t}return 1n===n?wi(i,t):ei("no inverse")})(r,Xn);return 1n!==wi(r*n)&&ei("inverse invalid"),{x:wi(e*n),y:wi(t*n)}}assertValidity(){const{x:e,y:t}=this.toAffine();return Si(e),Si(t),wi(t*t)===Ei(e)?this:ei("bad point: not on curve")}toBytes(e=!0){const{x:t,y:r}=this.assertValidity().toAffine(),n=Ui(t);return e?gi(Ai(ki(r)?2:3),n):gi(Ai(4),n,Ui(r))}static fromAffine(t){const{x:r,y:n}=t;return 0n===r&&0n===n?xi:new e(r,n,1n)}toHex(e){return si(this.toBytes(e))}static fromPrivateKey(e){return Ti.multiply(Li(e))}static fromHex(t){return e.fromBytes(yi(t))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(e){return this.toBytes(e)}};const Ti=new Ii(Zn,Qn,1n),xi=new Ii(0n,1n,0n);Ii.BASE=Ti,Ii.ZERO=xi;const Oi=e=>mi("0x"+(si(e)||"0")),Bi=(e,t,r)=>Oi(e.subarray(t,r)),Pi=2n**256n,Ui=e=>di(oi(bi(e,0n,Pi),64)),Li=e=>{const t=ti(e)?e:Oi(yi(e,32));return bi(t,1n,Yn,"private key invalid 3")},Ni=Math.ceil(32)+1;let Ri;const Ci=(e,t)=>{const r=t.negate();return e?r:t},Hi=e=>{const t=Ri||(Ri=(()=>{const e=[];let t=Ti,r=t;for(let n=0;n<Ni;n++){r=t,e.push(r);for(let n=1;n<128;n++)r=r.add(t),e.push(r);t=r.double()}return e})());let r=xi,n=Ti;const i=mi(255),o=mi(8);for(let s=0;s<Ni;s++){let a=Number(e&i);e>>=o,a>128&&(a-=256,e+=1n);const u=128*s,c=u,f=u+Math.abs(a)-1,l=s%2!=0,h=a<0;0===a?n=n.add(Ci(l,t[c])):r=r.add(Ci(h,t[f]))}return{p:r,f:n}},Ki=e=>{const t=32===e.length?e:e.subarray(1,33);return oe.isBuffer(t)?t:oe.from(t)};function zi(e){let t=e.toString(16);return t=t.padStart(64,"0"),t.length>64&&(t=t.slice(-64)),oe.from(t,"hex")}function Mi(e){if(32===e.length)return;if(![33,65].includes(e.length))return void console.warn(`Unsupported key length=${e.length}. Must be 33 (compressed) or 65 (uncompressed).`);let t;try{t=Ii.fromHex(e)}catch{throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}const r=zi(t.x),n=zi(t.y),i=t.y%2n==0n?6:7,o=oe.alloc(65);o[0]=i,r.copy(o,1),n.copy(o,33);return{hybrid:o,uncompressed:oe.concat([oe.from([4]),r,n])}}function Di(e,t){if(e.equals(t))return!0;if(65===e.length&&65===t.length){const r=oe.from(e),n=oe.from(t);return(6===r[0]||7===r[0])&&(r[0]=4),(6===n[0]||7===n[0])&&(n[0]=4),r.equals(n)}return!1}const ji=e=>{try{const t=oe.from(e.subarray(2));if(t.length<2||t.length>40)throw new TypeError("Invalid program length for segwit address");const r=e[0]-80;if(r<2||r>16)throw new TypeError("Invalid version for segwit address");if(1===r)throw new TypeError("taproot");return!0}catch{}return!1};function Fi(e,t){if(!oe.isBuffer(e))throw new TypeError("output must be a Buffer");if(!t.bech32Opnet)throw new Error("Network does not support opnet");const r=e[0];let n,i=1;if(e[1]<76)n=e[1],i=2;else{if(76!==e[1])throw new TypeError("Unsupported push opcode in script");n=e[2],i=3}const o=oe.from(e.subarray(i,i+n));if(o.length<2||o.length>40)throw new TypeError("Invalid program length for segwit address");const s=r===Gt.OP_0?0:r>=Gt.OP_1&&r<=Gt.OP_16?r-(Gt.OP_1-1):-1;if(s<15||s>16)throw new TypeError(`Invalid segwit version ${s}`);const a=[s,...On.bech32m.toWords(o)];return On.bech32m.encode(t.bech32Opnet,a)}function Vi(e,t){const r=oe.from(e.subarray(2));if(r.length<2||r.length>40)throw new TypeError("Invalid program length for segwit address");const n=e[0]-80;if(n<2||n>15)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError(`Invalid script for segwit address ${e[1]} !== ${r.length}`);return Wi(r,n,t.bech32,t.bech32Opnet)}function qi(e){const t=oe.from($n.decode(e));if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");return{version:t.readUInt8(0),hash:oe.from(t.subarray(1))}}function Wi(e,t,r,n){const i=On.bech32.toWords(e);return i.unshift(t),16===t&&n?On.bech32m.encode(n,i):0===t?On.bech32.encode(r,i):On.bech32m.encode(r,i)}function $i(e,t){t=t||yn;try{return Tr({output:e,network:t}).address}catch{}try{return Or({output:e,network:t}).address}catch{}try{return Wr({output:e,network:t}).address}catch{}try{return Yr({output:e,network:t}).address}catch{}try{return Fr({output:e,network:t}).address}catch{}try{return Fi(e,t)}catch{}try{return Vi(e,t)}catch{}throw new Error(dr(e)+" has no matching Address")}function Gi(e,t){let r,n;t=t||yn;try{r=qi(e)}catch{}if(r){if(r.version===t.pubKeyHash)return Tr({hash:r.hash}).output;if(r.version===t.scriptHash)return Or({hash:r.hash}).output}else{try{n=Gn(e)}catch{}if(n){if(n.prefix!==t.bech32&&t.bech32Opnet&&n.prefix!==t.bech32Opnet)throw new Error(e+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return Wr({hash:n.data}).output;if(32===n.data.length)return Yr({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return Fr({pubkey:n.data}).output}else{if(16===n.version){if(!t.bech32Opnet)throw new Error(e+" has an invalid prefix");return Ar({program:n.data,network:t}).output}if(n.version>=2&&n.version<=15&&n.data.length>=2&&n.data.length<=40)return 16!==n.version&&console.warn("WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit."),hr([n.version+80,n.data])}}}throw new TypeError(e+" has no matching Script")}const Xi=Object.freeze(Object.defineProperty({__proto__:null,FUTURE_MAX_VERSION:16,FUTURE_OPNET_VERSION:16,FUTURE_SEGWIT_MAX_SIZE:40,FUTURE_SEGWIT_MAX_VERSION:15,FUTURE_SEGWIT_MIN_SIZE:2,FUTURE_SEGWIT_MIN_VERSION:2,FUTURE_SEGWIT_VERSION_DIFF:80,_toFutureSegwitAddress:Vi,fromBase58Check:qi,fromBech32:Gn,fromOutputScript:$i,isUnknownSegwitVersion:ji,toBase58Check:function(e,t){ft(Ot(vt,Bt),[e,t]);const r=oe.allocUnsafe(21);return r.writeUInt8(t,0),e.copy(r,1),$n.encode(r)},toBech32:Wi,toFutureOPNetAddress:Fi,toOutputScript:Gi},Symbol.toStringTag,{value:"Module"}));var Yi,Zi={},Qi={},Ji={},eo={},to={},ro={};function no(){return Yi||(Yi=1,e=ro,Object.defineProperty(e,"__esModule",{value:!0}),(t=e.GlobalTypes||(e.GlobalTypes={}))[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],function(e){e[e.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",e[e.WITNESS_UTXO=1]="WITNESS_UTXO",e[e.PARTIAL_SIG=2]="PARTIAL_SIG",e[e.SIGHASH_TYPE=3]="SIGHASH_TYPE",e[e.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=6]="BIP32_DERIVATION",e[e.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",e[e.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",e[e.POR_COMMITMENT=9]="POR_COMMITMENT",e[e.TAP_KEY_SIG=19]="TAP_KEY_SIG",e[e.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",e[e.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",e[e.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",e[e.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"}(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],function(e){e[e.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=2]="BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",e[e.TAP_TREE=6]="TAP_TREE",e[e.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"}(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]),ro;var e,t}var io,oo={};function so(){if(io)return oo;io=1,Object.defineProperty(oo,"__esModule",{value:!0});const e=no();return oo.decode=function(t){if(t.key[0]!==e.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+t.key.toString("hex"));if(79!==t.key.length||![2,3].includes(t.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+t.key.toString("hex"));if(t.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const r=t.key.slice(1),n={masterFingerprint:t.value.slice(0,4),extendedPubkey:r,path:"m"};for(const e of(e=>[...Array(e).keys()])(t.value.length/4-1)){const r=t.value.readUInt32LE(4*e+4),i=!!(2147483648&r),o=2147483647&r;n.path+="/"+o.toString(10)+(i?"'":"")}return n},oo.encode=function(t){const r=oe.from([e.GlobalTypes.GLOBAL_XPUB]),n=oe.concat([r,t.extendedPubkey]),i=t.path.split("/"),o=oe.allocUnsafe(4*i.length);t.masterFingerprint.copy(o,0);let s=4;return i.slice(1).forEach(e=>{const t="'"===e.slice(-1);let r=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(r+=2147483648),o.writeUInt32LE(r,s),s+=4}),{key:n,value:o}},oo.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",oo.check=function(e){const t=e.extendedPubkey,r=e.masterFingerprint,n=e.path;return oe.isBuffer(t)&&78===t.length&&[2,3].indexOf(t[45])>-1&&oe.isBuffer(r)&&4===r.length&&"string"==typeof n&&!!n.match(/^m(\/\d+'?)*$/)},oo.canAddToArray=function(e,t,r){const n=t.extendedPubkey.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.extendedPubkey.equals(t.extendedPubkey)).length)},oo}var ao,uo={};var co,fo={};var lo,ho={};var po,yo={};var go,mo={};function bo(){if(go)return mo;go=1,Object.defineProperty(mo,"__esModule",{value:!0});const e=no();return mo.decode=function(t){if(t.key[0]!==e.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+t.key.toString("hex"));if(34!==t.key.length&&66!==t.key.length||![2,3,4].includes(t.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1),signature:t.value}},mo.encode=function(t){const r=oe.from([e.InputTypes.PARTIAL_SIG]);return{key:oe.concat([r,t.pubkey]),value:t.signature}},mo.expected="{ pubkey: Buffer; signature: Buffer; }",mo.check=function(e){return oe.isBuffer(e.pubkey)&&oe.isBuffer(e.signature)&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&function(e){if(!oe.isBuffer(e)||e.length<9||48!==e[0]||e.length!==e[1]+3||2!==e[2])return!1;const t=e[3];if(t>33||t<1||2!==e[3+t+1])return!1;const r=e[3+t+2];return!(r>33||r<1||e.length!==3+t+2+r+2)}(e.signature)},mo.canAddToArray=function(e,t,r){const n=t.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.pubkey.equals(t.pubkey)).length)},mo}var wo,vo={};var Eo,_o={};var So,ko={};var Ao,Io={};var To,xo={};var Oo,Bo={};var Po,Uo,Lo,No={},Ro={},Co={};function Ho(){if(Po)return Co;Po=1,Object.defineProperty(Co,"__esModule",{value:!0});function e(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function t(t){return e(t),t<253?1:t<=65535?3:t<=4294967295?5:9}return Co.encode=function r(n,i,o){if(e(n),i||(i=oe.allocUnsafe(t(n))),!oe.isBuffer(i))throw new TypeError("buffer must be a Buffer instance");return o||(o=0),n<253?(i.writeUInt8(n,o),Object.assign(r,{bytes:1})):n<=65535?(i.writeUInt8(253,o),i.writeUInt16LE(n,o+1),Object.assign(r,{bytes:3})):n<=4294967295?(i.writeUInt8(254,o),i.writeUInt32LE(n,o+1),Object.assign(r,{bytes:5})):(i.writeUInt8(255,o),i.writeUInt32LE(n>>>0,o+1),i.writeUInt32LE(n/4294967296|0,o+5),Object.assign(r,{bytes:9})),i},Co.decode=function t(r,n){if(!oe.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");n||(n=0);const i=r.readUInt8(n);if(i<253)return Object.assign(t,{bytes:1}),i;if(253===i)return Object.assign(t,{bytes:3}),r.readUInt16LE(n+1);if(254===i)return Object.assign(t,{bytes:5}),r.readUInt32LE(n+1);{Object.assign(t,{bytes:9});const i=r.readUInt32LE(n+1),o=4294967296*r.readUInt32LE(n+5)+i;return e(o),o}},Co.encodingLength=t,Co}function Ko(){if(Uo)return Ro;Uo=1,Object.defineProperty(Ro,"__esModule",{value:!0});const e=Ho();function t(t){const r=t.key.length,n=t.value.length,i=e.encodingLength(r),o=e.encodingLength(n),s=oe.allocUnsafe(i+r+o+n);return e.encode(r,s,0),t.key.copy(s,i),e.encode(n,s,i+r),t.value.copy(s,i+r+o),s}function r(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}return Ro.range=e=>[...Array(e).keys()],Ro.reverseBuffer=function(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e},Ro.keyValsToBuffer=function(e){const r=e.map(t);return r.push(oe.from([0])),oe.concat(r)},Ro.keyValToBuffer=t,Ro.readUInt64LE=function(e,t){const n=e.readUInt32LE(t);let i=e.readUInt32LE(t+4);return i*=4294967296,r(i+n,9007199254740991),i+n},Ro.writeUInt64LE=function(e,t,n){return r(t,9007199254740991),e.writeInt32LE(-1&t,n),e.writeUInt32LE(Math.floor(t/4294967296),n+4),n+8},Ro}var zo,Mo={};var Do,jo={};function Fo(){if(Do)return jo;Do=1,Object.defineProperty(jo,"__esModule",{value:!0});const e=e=>33===e.length&&[2,3].includes(e[0])||65===e.length&&4===e[0];return jo.makeConverter=function(t,r=e){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+e.key.toString("hex"));const n=e.key.slice(1);if(!r(n))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+e.key.toString("hex"));if(e.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:e.value.slice(0,4),pubkey:n,path:"m"};for(const t of(e=>[...Array(e).keys()])(e.value.length/4-1)){const r=e.value.readUInt32LE(4*t+4),n=!!(2147483648&r),o=2147483647&r;i.path+="/"+o.toString(10)+(n?"'":"")}return i},encode:function(e){const r=oe.from([t]),n=oe.concat([r,e.pubkey]),i=e.path.split("/"),o=oe.allocUnsafe(4*i.length);e.masterFingerprint.copy(o,0);let s=4;return i.slice(1).forEach(e=>{const t="'"===e.slice(-1);let r=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(r+=2147483648),o.writeUInt32LE(r,s),s+=4}),{key:n,value:o}},check:function(e){return oe.isBuffer(e.pubkey)&&oe.isBuffer(e.masterFingerprint)&&"string"==typeof e.path&&r(e.pubkey)&&4===e.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(e,t,r){const n=t.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.pubkey.equals(t.pubkey)).length)}}},jo}var Vo,qo={};var Wo,$o={};var Go,Xo={};var Yo,Zo={};var Qo,Jo,es,ts={};function rs(){if(Jo)return to;Jo=1,Object.defineProperty(to,"__esModule",{value:!0});const e=no(),t=so(),r=function(){if(ao)return uo;ao=1,Object.defineProperty(uo,"__esModule",{value:!0});const e=no();return uo.encode=function(t){return{key:oe.from([e.GlobalTypes.UNSIGNED_TX]),value:t.toBuffer()}},uo}(),n=function(){if(co)return fo;co=1,Object.defineProperty(fo,"__esModule",{value:!0});const e=no();return fo.decode=function(t){if(t.key[0]!==e.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+t.key.toString("hex"));return t.value},fo.encode=function(t){return{key:oe.from([e.InputTypes.FINAL_SCRIPTSIG]),value:t}},fo.expected="Buffer",fo.check=function(e){return oe.isBuffer(e)},fo.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptSig},fo}(),i=function(){if(lo)return ho;lo=1,Object.defineProperty(ho,"__esModule",{value:!0});const e=no();return ho.decode=function(t){if(t.key[0]!==e.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+t.key.toString("hex"));return t.value},ho.encode=function(t){return{key:oe.from([e.InputTypes.FINAL_SCRIPTWITNESS]),value:t}},ho.expected="Buffer",ho.check=function(e){return oe.isBuffer(e)},ho.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptWitness},ho}(),o=function(){if(po)return yo;po=1,Object.defineProperty(yo,"__esModule",{value:!0});const e=no();return yo.decode=function(t){if(t.key[0]!==e.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+t.key.toString("hex"));return t.value},yo.encode=function(t){return{key:oe.from([e.InputTypes.NON_WITNESS_UTXO]),value:t}},yo.expected="Buffer",yo.check=function(e){return oe.isBuffer(e)},yo.canAdd=function(e,t){return!!e&&!!t&&void 0===e.nonWitnessUtxo},yo}(),s=bo(),a=function(){if(wo)return vo;wo=1,Object.defineProperty(vo,"__esModule",{value:!0});const e=no();return vo.decode=function(t){if(t.key[0]!==e.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+t.key.toString("hex"));return t.value.toString("utf8")},vo.encode=function(t){return{key:oe.from([e.InputTypes.POR_COMMITMENT]),value:oe.from(t,"utf8")}},vo.expected="string",vo.check=function(e){return"string"==typeof e},vo.canAdd=function(e,t){return!!e&&!!t&&void 0===e.porCommitment},vo}(),u=function(){if(Eo)return _o;Eo=1,Object.defineProperty(_o,"__esModule",{value:!0});const e=no();return _o.decode=function(t){if(t.key[0]!==e.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+t.key.toString("hex"));return t.value.readUInt32LE(0)},_o.encode=function(t){const r=oe.from([e.InputTypes.SIGHASH_TYPE]),n=oe.allocUnsafe(4);return n.writeUInt32LE(t,0),{key:r,value:n}},_o.expected="number",_o.check=function(e){return"number"==typeof e},_o.canAdd=function(e,t){return!!e&&!!t&&void 0===e.sighashType},_o}(),c=function(){if(So)return ko;So=1,Object.defineProperty(ko,"__esModule",{value:!0});const e=no();function t(e){return oe.isBuffer(e)&&(64===e.length||65===e.length)}return ko.decode=function(r){if(r.key[0]!==e.InputTypes.TAP_KEY_SIG||1!==r.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+r.key.toString("hex"));if(!t(r.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return r.value},ko.encode=function(t){return{key:oe.from([e.InputTypes.TAP_KEY_SIG]),value:t}},ko.expected="Buffer",ko.check=t,ko.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapKeySig},ko}(),f=function(){if(Ao)return Io;Ao=1,Object.defineProperty(Io,"__esModule",{value:!0});const e=no();return Io.decode=function(t){if(t.key[0]!==e.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+t.key.toString("hex"));if((t.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+t.key.toString("hex"));const r=t.value[t.value.length-1];if((254&t.key[1])!==r)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+t.key.toString("hex"));const n=t.value.slice(0,-1);return{controlBlock:t.key.slice(1),script:n,leafVersion:r}},Io.encode=function(t){const r=oe.from([e.InputTypes.TAP_LEAF_SCRIPT]),n=oe.from([t.leafVersion]);return{key:oe.concat([r,t.controlBlock]),value:oe.concat([t.script,n])}},Io.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",Io.check=function(e){return oe.isBuffer(e.controlBlock)&&(e.controlBlock.length-1)%32==0&&(254&e.controlBlock[0])===e.leafVersion&&oe.isBuffer(e.script)},Io.canAddToArray=function(e,t,r){const n=t.controlBlock.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.controlBlock.equals(t.controlBlock)).length)},Io}(),l=function(){if(To)return xo;To=1,Object.defineProperty(xo,"__esModule",{value:!0});const e=no();function t(e){return oe.isBuffer(e)&&32===e.length}return xo.decode=function(r){if(r.key[0]!==e.InputTypes.TAP_MERKLE_ROOT||1!==r.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+r.key.toString("hex"));if(!t(r.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return r.value},xo.encode=function(t){return{key:oe.from([e.InputTypes.TAP_MERKLE_ROOT]),value:t}},xo.expected="Buffer",xo.check=t,xo.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapMerkleRoot},xo}(),h=function(){if(Oo)return Bo;Oo=1,Object.defineProperty(Bo,"__esModule",{value:!0});const e=no();return Bo.decode=function(t){if(t.key[0]!==e.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+t.key.toString("hex"));if(65!==t.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+t.key.toString("hex"));if(64!==t.value.length&&65!==t.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1,33),leafHash:t.key.slice(33),signature:t.value}},Bo.encode=function(t){const r=oe.from([e.InputTypes.TAP_SCRIPT_SIG]);return{key:oe.concat([r,t.pubkey,t.leafHash]),value:t.signature}},Bo.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",Bo.check=function(e){return oe.isBuffer(e.pubkey)&&oe.isBuffer(e.leafHash)&&oe.isBuffer(e.signature)&&32===e.pubkey.length&&32===e.leafHash.length&&(64===e.signature.length||65===e.signature.length)},Bo.canAddToArray=function(e,t,r){const n=t.pubkey.toString("hex")+t.leafHash.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.pubkey.equals(t.pubkey)&&e.leafHash.equals(t.leafHash)).length)},Bo}(),p=function(){if(Lo)return No;Lo=1,Object.defineProperty(No,"__esModule",{value:!0});const e=no(),t=Ko(),r=Ho();return No.decode=function(n){if(n.key[0]!==e.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+n.key.toString("hex"));const i=t.readUInt64LE(n.value,0);let o=8;const s=r.decode(n.value,o);o+=r.encodingLength(s);const a=n.value.slice(o);if(a.length!==s)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:a,value:i}},No.encode=function(n){const{script:i,value:o}=n,s=r.encodingLength(i.length),a=oe.allocUnsafe(8+s+i.length);return t.writeUInt64LE(a,o,0),r.encode(i.length,a,8),i.copy(a,8+s),{key:oe.from([e.InputTypes.WITNESS_UTXO]),value:a}},No.expected="{ script: Buffer; value: number; }",No.check=function(e){return oe.isBuffer(e.script)&&"number"==typeof e.value},No.canAdd=function(e,t){return!!e&&!!t&&void 0===e.witnessUtxo},No}(),d=function(){if(zo)return Mo;zo=1,Object.defineProperty(Mo,"__esModule",{value:!0});const e=no(),t=Ho();return Mo.decode=function(r){if(r.key[0]!==e.OutputTypes.TAP_TREE||1!==r.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+r.key.toString("hex"));let n=0;const i=[];for(;n<r.value.length;){const e=r.value[n++],o=r.value[n++],s=t.decode(r.value,n);n+=t.encodingLength(s),i.push({depth:e,leafVersion:o,script:r.value.slice(n,n+s)}),n+=s}return{leaves:i}},Mo.encode=function(r){const n=oe.from([e.OutputTypes.TAP_TREE]),i=[].concat(...r.leaves.map(e=>[oe.of(e.depth,e.leafVersion),t.encode(e.script.length),e.script]));return{key:n,value:oe.concat(i)}},Mo.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",Mo.check=function(e){return Array.isArray(e.leaves)&&e.leaves.every(e=>e.depth>=0&&e.depth<=128&&(254&e.leafVersion)===e.leafVersion&&oe.isBuffer(e.script))},Mo.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapTree},Mo}(),y=Fo(),g=(Vo||(Vo=1,Object.defineProperty(qo,"__esModule",{value:!0}),qo.makeChecker=function(e){return function(t){let r;if(e.includes(t.key[0])&&(r=t.key.slice(1),33!==r.length&&65!==r.length||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+t.key.toString("hex"));return r}}),qo),m=(Wo||(Wo=1,Object.defineProperty($o,"__esModule",{value:!0}),$o.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:oe.from([e]),value:t}},check:function(e){return oe.isBuffer(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.redeemScript}}}),$o),b=function(){if(Go)return Xo;Go=1,Object.defineProperty(Xo,"__esModule",{value:!0});const e=Ho(),t=Fo(),r=e=>32===e.length;return Xo.makeConverter=function(n){const i=t.makeConverter(n,r);return{decode:function(t){const r=e.decode(t.value),n=e.encodingLength(r),o=i.decode({key:t.key,value:t.value.slice(n+32*r)}),s=new Array(r);for(let e=0,i=n;e<r;e++,i+=32)s[e]=t.value.slice(i,i+32);return Object.assign({},o,{leafHashes:s})},encode:function(t){const r=i.encode(t),n=e.encodingLength(t.leafHashes.length),o=oe.allocUnsafe(n);e.encode(t.leafHashes.length,o);const s=oe.concat([o,...t.leafHashes,r.value]);return Object.assign({},r,{value:s})},check:function(e){return Array.isArray(e.leafHashes)&&e.leafHashes.every(e=>oe.isBuffer(e)&&32===e.length)&&i.check(e)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:i.canAddToArray}},Xo}(),w=(Yo||(Yo=1,Object.defineProperty(Zo,"__esModule",{value:!0}),Zo.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e||1!==t.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+t.key.toString("hex"));if(32!==t.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return t.value},encode:function(t){return{key:oe.from([e]),value:t}},check:function(e){return oe.isBuffer(e)&&32===e.length},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.tapInternalKey}}}),Zo),v=(Qo||(Qo=1,Object.defineProperty(ts,"__esModule",{value:!0}),ts.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:oe.from([e]),value:t}},check:function(e){return oe.isBuffer(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.witnessScript}}}),ts),E={unsignedTx:r,globalXpub:t,checkPubkey:g.makeChecker([])};to.globals=E;const _={nonWitnessUtxo:o,partialSig:s,sighashType:u,finalScriptSig:n,finalScriptWitness:i,porCommitment:a,witnessUtxo:p,bip32Derivation:y.makeConverter(e.InputTypes.BIP32_DERIVATION),redeemScript:m.makeConverter(e.InputTypes.REDEEM_SCRIPT),witnessScript:v.makeConverter(e.InputTypes.WITNESS_SCRIPT),checkPubkey:g.makeChecker([e.InputTypes.PARTIAL_SIG,e.InputTypes.BIP32_DERIVATION]),tapKeySig:c,tapScriptSig:h,tapLeafScript:f,tapBip32Derivation:b.makeConverter(e.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:w.makeConverter(e.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:l};to.inputs=_;const S={bip32Derivation:y.makeConverter(e.OutputTypes.BIP32_DERIVATION),redeemScript:m.makeConverter(e.OutputTypes.REDEEM_SCRIPT),witnessScript:v.makeConverter(e.OutputTypes.WITNESS_SCRIPT),checkPubkey:g.makeChecker([e.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:b.makeConverter(e.OutputTypes.TAP_BIP32_DERIVATION),tapTree:d,tapInternalKey:w.makeConverter(e.OutputTypes.TAP_INTERNAL_KEY)};return to.outputs=S,to}var ns,is,os,ss={};function as(){return is||(is=1,function(e){function t(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),t(function(){if(es)return eo;es=1,Object.defineProperty(eo,"__esModule",{value:!0});const e=rs(),t=Ko(),r=Ho(),n=no();function i(e,t,r){if(!t.equals(oe.from([r])))throw new Error(`Format Error: Invalid ${e} key: ${t.toString("hex")}`)}function o(r,{globalMapKeyVals:o,inputKeyVals:s,outputKeyVals:a}){const u={unsignedTx:r};let c=0;for(const t of o)switch(t.key[0]){case n.GlobalTypes.UNSIGNED_TX:if(i("global",t.key,n.GlobalTypes.UNSIGNED_TX),c>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");c++;break;case n.GlobalTypes.GLOBAL_XPUB:void 0===u.globalXpub&&(u.globalXpub=[]),u.globalXpub.push(e.globals.globalXpub.decode(t));break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(t)}const f=s.length,l=a.length,h=[],p=[];for(const d of t.range(f)){const t={};for(const r of s[d])switch(e.inputs.checkPubkey(r),r.key[0]){case n.InputTypes.NON_WITNESS_UTXO:if(i("input",r.key,n.InputTypes.NON_WITNESS_UTXO),void 0!==t.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");t.nonWitnessUtxo=e.inputs.nonWitnessUtxo.decode(r);break;case n.InputTypes.WITNESS_UTXO:if(i("input",r.key,n.InputTypes.WITNESS_UTXO),void 0!==t.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");t.witnessUtxo=e.inputs.witnessUtxo.decode(r);break;case n.InputTypes.PARTIAL_SIG:void 0===t.partialSig&&(t.partialSig=[]),t.partialSig.push(e.inputs.partialSig.decode(r));break;case n.InputTypes.SIGHASH_TYPE:if(i("input",r.key,n.InputTypes.SIGHASH_TYPE),void 0!==t.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");t.sighashType=e.inputs.sighashType.decode(r);break;case n.InputTypes.REDEEM_SCRIPT:if(i("input",r.key,n.InputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");t.redeemScript=e.inputs.redeemScript.decode(r);break;case n.InputTypes.WITNESS_SCRIPT:if(i("input",r.key,n.InputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");t.witnessScript=e.inputs.witnessScript.decode(r);break;case n.InputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(e.inputs.bip32Derivation.decode(r));break;case n.InputTypes.FINAL_SCRIPTSIG:i("input",r.key,n.InputTypes.FINAL_SCRIPTSIG),t.finalScriptSig=e.inputs.finalScriptSig.decode(r);break;case n.InputTypes.FINAL_SCRIPTWITNESS:i("input",r.key,n.InputTypes.FINAL_SCRIPTWITNESS),t.finalScriptWitness=e.inputs.finalScriptWitness.decode(r);break;case n.InputTypes.POR_COMMITMENT:i("input",r.key,n.InputTypes.POR_COMMITMENT),t.porCommitment=e.inputs.porCommitment.decode(r);break;case n.InputTypes.TAP_KEY_SIG:i("input",r.key,n.InputTypes.TAP_KEY_SIG),t.tapKeySig=e.inputs.tapKeySig.decode(r);break;case n.InputTypes.TAP_SCRIPT_SIG:void 0===t.tapScriptSig&&(t.tapScriptSig=[]),t.tapScriptSig.push(e.inputs.tapScriptSig.decode(r));break;case n.InputTypes.TAP_LEAF_SCRIPT:void 0===t.tapLeafScript&&(t.tapLeafScript=[]),t.tapLeafScript.push(e.inputs.tapLeafScript.decode(r));break;case n.InputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(e.inputs.tapBip32Derivation.decode(r));break;case n.InputTypes.TAP_INTERNAL_KEY:i("input",r.key,n.InputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=e.inputs.tapInternalKey.decode(r);break;case n.InputTypes.TAP_MERKLE_ROOT:i("input",r.key,n.InputTypes.TAP_MERKLE_ROOT),t.tapMerkleRoot=e.inputs.tapMerkleRoot.decode(r);break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(r)}h.push(t)}for(const d of t.range(l)){const t={};for(const r of a[d])switch(e.outputs.checkPubkey(r),r.key[0]){case n.OutputTypes.REDEEM_SCRIPT:if(i("output",r.key,n.OutputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");t.redeemScript=e.outputs.redeemScript.decode(r);break;case n.OutputTypes.WITNESS_SCRIPT:if(i("output",r.key,n.OutputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");t.witnessScript=e.outputs.witnessScript.decode(r);break;case n.OutputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(e.outputs.bip32Derivation.decode(r));break;case n.OutputTypes.TAP_INTERNAL_KEY:i("output",r.key,n.OutputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=e.outputs.tapInternalKey.decode(r);break;case n.OutputTypes.TAP_TREE:i("output",r.key,n.OutputTypes.TAP_TREE),t.tapTree=e.outputs.tapTree.decode(r);break;case n.OutputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(e.outputs.tapBip32Derivation.decode(r));break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(r)}p.push(t)}return{globalMap:u,inputs:h,outputs:p}}return eo.psbtFromBuffer=function(e,i){let s=0;function a(){const t=r.decode(e,s);s+=r.encodingLength(t);const n=e.slice(s,s+t);return s+=t,n}function u(){return{key:a(),value:a()}}function c(){if(s>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const t=0===e.readUInt8(s);return t&&s++,t}if(1886610036!==function(){const t=e.readUInt32BE(s);return s+=4,t}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const t=e.readUInt8(s);return s+=1,t}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const f=[],l={};for(;!c();){const e=u(),t=e.key.toString("hex");if(l[t])throw new Error("Format Error: Keys must be unique for global keymap: key "+t);l[t]=1,f.push(e)}const h=f.filter(e=>e.key[0]===n.GlobalTypes.UNSIGNED_TX);if(1!==h.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const p=i(h[0].value),{inputCount:d,outputCount:y}=p.getInputOutputCounts(),g=[],m=[];for(const r of t.range(d)){const e={},t=[];for(;!c();){const n=u(),i=n.key.toString("hex");if(e[i])throw new Error("Format Error: Keys must be unique for each input: input index "+r+" key "+i);e[i]=1,t.push(n)}g.push(t)}for(const r of t.range(y)){const e={},t=[];for(;!c();){const n=u(),i=n.key.toString("hex");if(e[i])throw new Error("Format Error: Keys must be unique for each output: output index "+r+" key "+i);e[i]=1,t.push(n)}m.push(t)}return o(p,{globalMapKeyVals:f,inputKeyVals:g,outputKeyVals:m})},eo.checkKeyBuffer=i,eo.psbtFromKeyVals=o,eo}()),t(function(){if(ns)return ss;ns=1,Object.defineProperty(ss,"__esModule",{value:!0});const e=rs(),t=Ko();ss.psbtToBuffer=function({globalMap:e,inputs:r,outputs:n}){const{globalKeyVals:o,inputKeyVals:s,outputKeyVals:a}=i({globalMap:e,inputs:r,outputs:n}),u=t.keyValsToBuffer(o),c=e=>0===e.length?[oe.from([0])]:e.map(t.keyValsToBuffer),f=c(s),l=c(a),h=oe.allocUnsafe(5);return h.writeUIntBE(482972169471,0,5),oe.concat([h,u].concat(f,l))};const r=(e,t)=>e.key.compare(t.key);function n(e,t){const n=new Set,i=Object.entries(e).reduce((e,[r,i])=>{if("unknownKeyVals"===r)return e;const o=t[r];if(void 0===o)return e;const s=(Array.isArray(i)?i:[i]).map(o.encode);return s.map(e=>e.key.toString("hex")).forEach(e=>{if(n.has(e))throw new Error("Serialize Error: Duplicate key: "+e);n.add(e)}),e.concat(s)},[]),o=e.unknownKeyVals?e.unknownKeyVals.filter(e=>!n.has(e.key.toString("hex"))):[];return i.concat(o).sort(r)}function i({globalMap:t,inputs:r,outputs:i}){return{globalKeyVals:n(t,e.globals),inputKeyVals:r.map(t=>n(t,e.inputs)),outputKeyVals:i.map(t=>n(t,e.outputs))}}return ss.psbtToKeyVals=i,ss}())}(Ji)),Ji}var us,cs,fs={};function ls(){return us||(us=1,function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=rs();function r(e,t){const r=e[t];if(void 0===r)throw new Error(`No input #${t}`);return r}function n(e,t){const r=e[t];if(void 0===r)throw new Error(`No output #${t}`);return r}function i(e,t,r,n){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function o(e){return(r,n)=>{for(const o of Object.keys(r)){const s=r[o],{canAdd:a,canAddToArray:u,check:c,expected:f}=t[e+"s"][o]||{};if(c)if(!!u){if(!Array.isArray(s)||n[o]&&!Array.isArray(n[o]))throw new Error(`Key type ${o} must be an array`);s.every(c)||i(e,o,f,s);const t=n[o]||[],r=new Set;if(!s.every(e=>u(t,e,r)))throw new Error("Can not add duplicate data to array");n[o]=t.concat(s)}else{if(c(s)||i(e,o,f,s),!a(n,s))throw new Error(`Can not add duplicate data to ${e}`);n[o]=s}}}}e.checkForInput=r,e.checkForOutput=n,e.checkHasKey=function(e,t,r){if(e.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&0!==t.filter(t=>t.key.equals(e.key)).length)throw new Error(`Duplicate Key: ${e.key.toString("hex")}`)},e.getEnumLength=function(e){let t=0;return Object.keys(e).forEach(e=>{Number(isNaN(Number(e)))&&t++}),t},e.inputCheckUncleanFinalized=function(e,t){let r=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const e=!!t.redeemScript,n=!!t.witnessScript,i=!e||!!t.finalScriptSig,o=!n||!!t.finalScriptWitness,s=!!t.finalScriptSig||!!t.finalScriptWitness;r=i&&o&&s}if(!1===r)throw new Error(`Input #${e} has too much or too little data to clean`)},e.updateGlobal=o("global"),e.updateInput=o("input"),e.updateOutput=o("output"),e.addInputAttributes=function(t,n){const i=r(t,t.length-1);e.updateInput(n,i)},e.addOutputAttributes=function(t,r){const i=n(t,t.length-1);e.updateOutput(r,i)},e.defaultVersionSetter=function(e,t){if(!oe.isBuffer(t)||t.length<4)throw new Error("Set Version: Invalid Transaction");return t.writeUInt32LE(e,0),t},e.defaultLocktimeSetter=function(e,t){if(!oe.isBuffer(t)||t.length<4)throw new Error("Set Locktime: Invalid Transaction");return t.writeUInt32LE(e,t.length-4),t}}(fs)),fs}var hs=function(){if(cs)return Zi;cs=1,Object.defineProperty(Zi,"__esModule",{value:!0});const e=function(){if(os)return Qi;os=1,Object.defineProperty(Qi,"__esModule",{value:!0});const e=as();function t(e,t,r){return n=>{if(e.has(n))return;const i=r.filter(e=>e.key.toString("hex")===n)[0];t.push(i),e.add(n)}}function r(e){return e.globalMap.unsignedTx}function n(e){const t=new Set;return e.forEach(e=>{const r=e.key.toString("hex");if(t.has(r))throw new Error("Combine: KeyValue Map keys should be unique");t.add(r)}),t}return Qi.combine=function(i){const o=i[0],s=e.psbtToKeyVals(o),a=i.slice(1);if(0===a.length)throw new Error("Combine: Nothing to combine");const u=r(o);if(void 0===u)throw new Error("Combine: Self missing transaction");const c=n(s.globalKeyVals),f=s.inputKeyVals.map(n),l=s.outputKeyVals.map(n);for(const h of a){const i=r(h);if(void 0===i||!i.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const o=e.psbtToKeyVals(h);n(o.globalKeyVals).forEach(t(c,s.globalKeyVals,o.globalKeyVals)),o.inputKeyVals.map(n).forEach((e,r)=>e.forEach(t(f[r],s.inputKeyVals[r],o.inputKeyVals[r]))),o.outputKeyVals.map(n).forEach((e,r)=>e.forEach(t(l[r],s.outputKeyVals[r],o.outputKeyVals[r])))}return e.psbtFromKeyVals(u,{globalMapKeyVals:s.globalKeyVals,inputKeyVals:s.inputKeyVals,outputKeyVals:s.outputKeyVals})},Qi}(),t=as(),r=no(),n=ls();return Zi.Psbt=class{constructor(e){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:e}}static fromBase64(e,t){const r=oe.from(e,"base64");return this.fromBuffer(r,t)}static fromHex(e,t){const r=oe.from(e,"hex");return this.fromBuffer(r,t)}static fromBuffer(e,r){const n=t.psbtFromBuffer(e,r),i=new this(n.globalMap.unsignedTx);return Object.assign(i,n),i}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return t.psbtToBuffer(this)}updateGlobal(e){return n.updateGlobal(e,this.globalMap),this}updateInput(e,t){const r=n.checkForInput(this.inputs,e);return n.updateInput(t,r),this}updateOutput(e,t){const r=n.checkForOutput(this.outputs,e);return n.updateOutput(t,r),this}addUnknownKeyValToGlobal(e){return n.checkHasKey(e,this.globalMap.unknownKeyVals,n.getEnumLength(r.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(e),this}addUnknownKeyValToInput(e,t){const i=n.checkForInput(this.inputs,e);return n.checkHasKey(t,i.unknownKeyVals,n.getEnumLength(r.InputTypes)),i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(t),this}addUnknownKeyValToOutput(e,t){const i=n.checkForOutput(this.outputs,e);return n.checkHasKey(t,i.unknownKeyVals,n.getEnumLength(r.OutputTypes)),i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(t),this}addInput(e){this.globalMap.unsignedTx.addInput(e),this.inputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach(e=>this.addUnknownKeyValToInput(r,e)),n.addInputAttributes(this.inputs,e),this}addOutput(e){this.globalMap.unsignedTx.addOutput(e),this.outputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach(e=>this.addUnknownKeyValToOutput(r,e)),n.addOutputAttributes(this.outputs,e),this}clearFinalizedInput(e){const t=n.checkForInput(this.inputs,e);n.inputCheckUncleanFinalized(e,t);for(const r of Object.keys(t))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(r)||delete t[r];return this}combine(...t){const r=e.combine([this].concat(t));return Object.assign(this,r),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}},Zi}(),ps=Ho(),ds=ls();function ys(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}const gs=ys(en),ms=ys(rn),bs=ys(Tr),ws=ys(Wr),vs=ys(Yr),Es=ys(Or),_s=ys(Fr);function Ss(e){let t=oe.allocUnsafe(0);function r(e){const r=t.length,n=ps.encodingLength(e);t=oe.concat([t,oe.allocUnsafe(n)]),ps.encode(e,t,r)}function n(e){r(e.length),function(e){t=oe.concat([t,oe.from(e)])}(e)}return r((i=e).length),i.forEach(n),t;var i}function ks(e,t){const r=pr(t);if(null===r)throw new Error("Unknown script error");const n=qe(e),i=Ki(e),o=Mi(e),s=o?.hybrid?qe(o.hybrid):void 0,a=o?.uncompressed?qe(o.uncompressed):void 0;return r.findIndex(t=>"number"!=typeof t&&(!!(Di(t,e)||Di(t,i)||t.equals(n)||o&&(Di(t,o.uncompressed)||Di(t,o.hybrid)||s&&t.equals(s)||a&&t.equals(a)))||void 0))}function As(e,t){return-1!==ks(e,t)}function Is(e,t){return function(e){const{partialSig:t}=e;let r;if(t&&0!==t.length)r=t;else{if(!e.finalScriptSig&&!e.finalScriptWitness)return[];r=function(e){const t=e.finalScriptSig&&pr(e.finalScriptSig)||[],r=e.finalScriptWitness&&pr(e.finalScriptWitness)||[];return t.concat(r).filter(e=>oe.isBuffer(e)&&mr(e)).map(e=>({signature:e}))}(e)}return r.map(e=>e.signature)}(e).some(e=>Ts(e,wr.decode,t))}function Ts(e,t,r){const{hashType:n}=t(e),i=[];switch(n&pn.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case pn.SIGHASH_ALL:break;case pn.SIGHASH_SINGLE:case pn.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function xs(e,t,r){const n=function(e,t,r){const{tapScriptSig:n}=e;if(!n||!n.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const i=(e.tapLeafScript||[]).sort((e,t)=>e.controlBlock.length-t.controlBlock.length).find(e=>function(e,t,r){const n=Kr({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&void 0!==t.find(e=>e.leafHash.equals(n))}(e,n,r));if(!i)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return i}(t,e,r);try{const e=function(e,t){const r=Kr({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(e=>e.leafHash.equals(r)).map(e=>function(e,t){return Object.assign({positionInScript:ks(t.pubkey,e)},t)}(t.script,e)).sort((e,t)=>t.positionInScript-e.positionInScript).map(e=>e.signature)}(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:Ss(e)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}function Os(e,t){const r=t?oe.from([t]):oe.from([]);return oe.concat([e,r])}function Bs(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&_s(e.witnessUtxo.script))}function Ps(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function Us(e,t,r){(function(e,t,r){const n=Bs(e)&&Ks(t),i=Ks(e)&&Bs(t),o=e===t&&Bs(t)&&Ks(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)})(e,t,r),function(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(e=>Hs(e,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(e=>Hs(e,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(t=>Hs(t,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}(e,t,r)}function Ls(e,t,r){(function(e,t,r){const n=Ps(e)&&Ks(t),i=Ks(e)&&Ps(t),o=e===t&&Ps(t)&&Ks(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)})(e,t,r),function(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const t=e.script,i=function(e,t){const r=t&&function(e=[]){return 1===e.length&&0===e[0].depth?{output:e[0].script,version:e[0].leafVersion}:function(e){let t;for(const r of e)if(t=Cs(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}(e)}(t.leaves),{output:n}=Fr({internalPubkey:e,scriptTree:r});if(!n)throw new Error("Failed to generate taproot script pubkey");return n}(r,n);if(t&&!t.equals(i))throw new Error("Error adding output. Script or address missmatch.")}}(e,t)}function Ns(e,t){return function(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(e=>e.signature)),!t.length){const r=function(e){if(!e)return;const t=e.subarray(2);if(64===t.length||65===t.length)return t}(e.finalScriptWitness);r&&t.push(r)}return t}(e).some(e=>Ts(e,Rs,t))}function Rs(e){return{signature:e.subarray(0,64),hashType:e.subarray(64)[0]||pn.SIGHASH_DEFAULT}}function Cs(e,t,r=0){if(r>128)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if(mt(t))return;const n=Cs(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=Cs(e,t&&t[1],r+1);return i?[t&&t[0],i]:void 0}function Hs(e,t){if(!t)return!0;const r=Kr({output:e.script,version:e.leafVersion});return Rr(e.controlBlock,r).equals(t)}function Ks(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const zs=ps.decode,Ms={network:yn,maximumFeeRate:5e3};let Ds=class e{constructor(e={},t=new hs.Psbt(new Fs)){this.data=t,this.opts=Object.assign({},Ms,e),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},3===e.version?this.setVersionTRUC():0===this.data.inputs.length&&this.setVersion(2);const r=(e,t,r,n)=>{Object.defineProperty(e,t,{enumerable:r,writable:n})};r(this,"__CACHE",!1,!0),r(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(e){this.setVersion(e)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(e){this.setLocktime(e)}get txInputs(){return this.__CACHE.__TX.ins.map(e=>({hash:qt(e.hash),index:e.index,sequence:e.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(e=>{let t;try{t=$i(e.script,this.opts.network)}catch{}return{script:qt(e.script),value:e.value,address:t}})}static fromBase64(e,t={}){const r=oe.from(e,"base64");return this.fromBuffer(r,t)}static fromHex(e,t={}){const r=oe.from(e,"hex");return this.fromBuffer(r,t)}static fromBuffer(t,r={}){const n=hs.Psbt.fromBuffer(t,js),i=new e(r,n);return function(e,t){e.ins.forEach(e=>{Zs(t,e)})}(i.__CACHE.__TX,i.__CACHE),i}combine(...e){return this.data.combine(...e.map(e=>e.data)),this}clone(){const t=JSON.parse(JSON.stringify(this.opts));return e.fromBuffer(this.data.toBuffer(),t)}setMaximumFeeRate(e){Gs(e),this.opts.maximumFeeRate=e}setVersion(e){Gs(e),Xs(this.data.inputs,"setVersion");const t=this.__CACHE;return t.__TX.version=e,t.__EXTRACTED_TX=void 0,this}setVersionTRUC(){return this.setVersion(pn.TRUC_VERSION)}setLocktime(e){Gs(e),Xs(this.data.inputs,"setLocktime");const t=this.__CACHE;return t.__TX.locktime=e,t.__EXTRACTED_TX=void 0,this}setInputSequence(e,t){Gs(t),Xs(this.data.inputs,"setInputSequence");const r=this.__CACHE;if(r.__TX.ins.length<=e)throw new Error("Input index too high");return r.__TX.ins[e].sequence=t,r.__EXTRACTED_TX=void 0,this}addInputs(e,t=!0){return e.forEach(e=>this.addInput(e,t)),this}addInput(e,t=!0){if(!e||void 0===e.hash||void 0===e.index)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");Us(e,e,"addInput"),t&&Xs(this.data.inputs,"addInput"),e.witnessScript&&ba(e.witnessScript);const r=this.__CACHE;this.data.addInput(e);Zs(r,r.__TX.ins[r.__TX.ins.length-1]);const n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&la(this.__CACHE,i,n),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}addOutputs(e){return e.forEach(e=>this.addOutput(e)),this}addOutput(e){const t="address"in e,r="script"in e;if(arguments.length>1||!e||void 0===e.value||!t&&!r)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");if(Xs(this.data.inputs,"addOutput"),t){const{address:t}=e,{network:r}=this.opts,n=Gi(t,r);e=Object.assign({},e,{script:n})}Ls(e,e,"addOutput");const n=this.__CACHE;return this.data.addOutput(e),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(e,t){if(t&&(this.data.inputs=this.data.inputs.filter(e=>!e.partialSig)),!this.data.inputs.every(Ws))throw new Error("Not finalized");const r=this.__CACHE;if(e||function(e,t,r){const n=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),o=n*i;if(n>=r.maximumFeeRate)throw new Error(`Warning: You are paying around ${(o/1e8).toFixed(8)} in fees, which is ${n} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return ha(this.data.inputs,n,r,!0,t),n}getFeeRate(e=!1){return ta("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE,e)}getFee(e=!1){return ta("__FEE","fee",this.data.inputs,this.__CACHE,e)}finalizeAllInputs(){return ds.checkForInput(this.data.inputs,0),va(this.data.inputs.length).forEach(e=>this.finalizeInput(e)),this}finalizeInput(e,t,r){const n=ds.checkForInput(this.data.inputs,e);return Bs(n)?this._finalizeTaprootInput(e,n,void 0,t):this._finalizeInput(e,n,t,r??!0)}finalizeTaprootInput(e,t,r=xs){const n=ds.checkForInput(this.data.inputs,e);if(Bs(n))return this._finalizeTaprootInput(e,n,t,r);throw new Error(`Cannot finalize input #${e}. Not Taproot.`)}getInputType(e){const t=ds.checkForInput(this.data.inputs,e),r=ma(da(e,t,this.__CACHE),e,"input",t.redeemScript||function(e){if(!e)return;const t=pr(e);if(!t)return;const r=t[t.length-1];if(oe.isBuffer(r)&&!ga(r)&&!function(e){return mr(e)}(r)&&pr(r))return r}(t.finalScriptSig),t.witnessScript||function(e){if(!e)return;const t=fa(e),r=t[t.length-1];if(!ga(r)&&pr(r))return r}(t.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+wa(r.meaningfulScript)}inputHasPubkey(e,t){return function(e,t,r,n){const i=da(r,t,n),{meaningfulScript:o}=ma(i,r,"input",t.redeemScript,t.witnessScript);return As(e,o)}(t,ds.checkForInput(this.data.inputs,e),e,this.__CACHE)}inputHasHDKey(e,t){const r=ds.checkForInput(this.data.inputs,e),n=$s(t);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}outputHasPubkey(e,t){return function(e,t,r,n){const i=n.__TX.outs[r].script,{meaningfulScript:o}=ma(i,r,"output",t.redeemScript,t.witnessScript);return As(e,o)}(t,ds.checkForOutput(this.data.outputs,e),e,this.__CACHE)}outputHasHDKey(e,t){const r=ds.checkForOutput(this.data.outputs,e),n=$s(t);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}validateSignaturesOfAllInputs(e){return ds.checkForInput(this.data.inputs,0),va(this.data.inputs.length).map(t=>this.validateSignaturesOfInput(t,e)).reduce((e,t)=>t&&e,!0)}validateSignaturesOfInput(e,t,r){return Bs(this.data.inputs[e])?this.validateSignaturesOfTaprootInput(e,t,r):this._validateSignaturesOfInput(e,t,r)}signAllInputsHD(e,t=[pn.SIGHASH_ALL]){if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");const r=[];for(const n of va(this.data.inputs.length))try{this.signInputHD(n,e,t),r.push(!0)}catch{r.push(!1)}if(r.every(e=>!e))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(e,t=[pn.SIGHASH_ALL]){return new Promise((r,n)=>{if(!e||!e.publicKey||!e.fingerprint)return n(new Error("Need HDSigner to sign input"));const i=[],o=[];for(const s of va(this.data.inputs.length))o.push(this.signInputHDAsync(s,e,t).then(()=>{i.push(!0)},()=>{i.push(!1)}));return Promise.all(o).then(()=>{if(i.every(e=>!e))return n(new Error("No inputs were signed"));r()})})}signInputHD(e,t,r=[pn.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");return ca(e,this.data.inputs,t).forEach(t=>this.signInput(e,t,r)),this}signInputHDAsync(e,t,r=[pn.SIGHASH_ALL]){return new Promise((n,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const o=ca(e,this.data.inputs,t).map(t=>this.signInputAsync(e,t,r));return Promise.all(o).then(()=>{n()}).catch(i)})}signAllInputs(e,t){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");const r=[];for(const n of va(this.data.inputs.length))try{this.signInput(n,e,t),r.push(!0)}catch{r.push(!1)}if(r.every(e=>!e))throw new Error("No inputs were signed");return this}signAllInputsAsync(e,t){return new Promise((r,n)=>{if(!e||!e.publicKey)return n(new Error("Need Signer to sign input"));const i=[],o=[];for(const[s]of this.data.inputs.entries())o.push(this.signInputAsync(s,e,t).then(()=>{i.push(!0)},()=>{i.push(!1)}));return Promise.all(o).then(()=>{if(i.every(e=>!e))return n(new Error("No inputs were signed"));r()})})}signInput(e,t,r){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=ds.checkForInput(this.data.inputs,e);return Bs(n)?this._signTaprootInput(e,n,t,void 0,r):this._signInput(e,t,r)}signTaprootInput(e,t,r,n){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const i=ds.checkForInput(this.data.inputs,e);if(Bs(i))return this._signTaprootInput(e,i,t,r,n);throw new Error(`Input #${e} is not of type Taproot.`)}signInputAsync(e,t,r){return Promise.resolve().then(()=>{if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=ds.checkForInput(this.data.inputs,e);return Bs(n)?this._signTaprootInputAsync(e,n,t,void 0,r):this._signInputAsync(e,t,r)})}signTaprootInputAsync(e,t,r,n){return Promise.resolve().then(()=>{if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const i=ds.checkForInput(this.data.inputs,e);if(Bs(i))return this._signTaprootInputAsync(e,i,t,r,n);throw new Error(`Input #${e} is not of type Taproot.`)})}toBuffer(){return Vs(this.__CACHE),this.data.toBuffer()}toHex(){return Vs(this.__CACHE),this.data.toHex()}toBase64(){return Vs(this.__CACHE),this.data.toBase64()}updateGlobal(e){return this.data.updateGlobal(e),this}updateInput(e,t){return t.witnessScript&&ba(t.witnessScript),Us(this.data.inputs[e],t,"updateInput"),this.data.updateInput(e,t),t.nonWitnessUtxo&&la(this.__CACHE,this.data.inputs[e],e),this}updateOutput(e,t){return Ls(this.data.outputs[e],t,"updateOutput"),this.data.updateOutput(e,t),this}addUnknownKeyValToGlobal(e){return this.data.addUnknownKeyValToGlobal(e),this}addUnknownKeyValToInput(e,t){return this.data.addUnknownKeyValToInput(e,t),this}addUnknownKeyValToOutput(e,t){return this.data.addUnknownKeyValToOutput(e,t),this}clearFinalizedInput(e){return this.data.clearFinalizedInput(e),this}checkTaprootHashesForSig(e,t,r,n,i){if("function"!=typeof r.signSchnorr)throw new Error(`Need Schnorr Signer to sign taproot input #${e}.`);const o=oe.isBuffer(r.publicKey)?r.publicKey:oe.from(r.publicKey),s=aa(e,t,this.data.inputs,o,this.__CACHE,n,i);if(!s||!s.length)throw new Error(`Can not sign for input #${e} with the key ${o.toString("hex")}`);return s}_finalizeInput(e,t,r=ra,n=!0){const{script:i,isP2SH:o,isP2WSH:s,isSegwit:a}=function(e,t,r){const n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const o=pa(r,t,e),s=n.ins[e].index;i.script=o.outs[s].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);if(t.witnessScript||ws(i.script))i.isSegwit=!0;else try{const e=i.script;if(!e)throw new TypeError("Invalid script for segwit address");i.isSegwit=ji(e)}catch{}return i}(e,t,this.__CACHE);if(!i)throw new Error(`No script found for input #${e}`);!function(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(e=>{const{hashType:t}=wr.decode(e.signature);if(r!==t)throw new Error("Signature sighash does not match input sighash type")})}(t);const{finalScriptSig:u,finalScriptWitness:c}=r(e,t,i,a,o,s,n);if(u&&this.data.updateInput(e,{finalScriptSig:u}),c&&this.data.updateInput(e,{finalScriptWitness:c}),!u&&!c)throw new Error(`Unknown error finalizing input #${e}`);return this.data.clearFinalizedInput(e),this}_finalizeTaprootInput(e,t,r,n=xs){if(!t.witnessUtxo)throw new Error(`Cannot finalize input #${e}. Missing witness utxo.`);if(t.tapKeySig){const r=Fr({output:t.witnessUtxo.script,signature:t.tapKeySig});if(!r.witness)throw new Error("Cannot finalize taproot key spend");const n=Ss(r.witness);this.data.updateInput(e,{finalScriptWitness:n})}else{const{finalScriptWitness:i}=n(e,t,r);this.data.updateInput(e,{finalScriptWitness:i})}return this.data.clearFinalizedInput(e),this}_validateSignaturesOfInput(e,t,r){const n=this.data.inputs[e],i=(n||{}).partialSig;if(!n||!i||i.length<1)throw new Error("No signatures to validate");if("function"!=typeof t)throw new Error("Need validator function to validate signatures");const o=r?i.filter(e=>e.pubkey.equals(r)):i;if(o.length<1)throw new Error("No signatures for this pubkey");const s=[];let a,u,c;for(const f of o){const r=wr.decode(f.signature),{hash:i,script:o}=c===r.hashType&&a&&u?{hash:a,script:u}:ia(e,Object.assign({},n,{sighashType:r.hashType}),this.__CACHE,!0);c=r.hashType,a=i,u=o,Ys(f.pubkey,o,"verify"),s.push(t(f.pubkey,i,r.signature))}return s.every(e=>e)}validateSignaturesOfTaprootInput(e,t,r){const n=this.data.inputs[e],i=(n||{}).tapKeySig,o=(n||{}).tapScriptSig;if(!n&&!i&&(!o||o.length))throw new Error("No signatures to validate");if("function"!=typeof t)throw new Error("Need validator function to validate signatures");const s=(r=r&&Ki(r))?aa(e,n,this.data.inputs,r,this.__CACHE):function(e,t,r,n){const i=[];if(t.tapInternalKey){const r=oa(e,t,n);r&&i.push(r)}if(t.tapScriptSig){const e=t.tapScriptSig.map(e=>e.pubkey);i.push(...e)}return i.map(i=>aa(e,t,r,i,n)).flat()}(e,n,this.data.inputs,this.__CACHE);if(!s.length)throw new Error("No signatures for this pubkey");const a=s.find(e=>!e.leafHash);let u=0;if(i&&a){if(!t(a.pubkey,a.hash,sa(i)))return!1;u++}if(o)for(const c of o){const e=s.find(e=>c.pubkey.equals(e.pubkey));if(e){if(!t(c.pubkey,e.hash,sa(c.signature)))return!1;u++}}return u>0}_signInput(e,t,r=[pn.SIGHASH_ALL]){const n=oe.isBuffer(t.publicKey)?t.publicKey:oe.from(t.publicKey),{hash:i,sighashType:o}=na(this.data.inputs,e,n,this.__CACHE,r),s=t.sign(i),a=[{pubkey:n,signature:wr.encode(oe.isBuffer(s)?s:oe.from(s),o)}];return this.data.updateInput(e,{partialSig:a}),this}_signTaprootInput(e,t,r,n,i=[pn.SIGHASH_DEFAULT]){const o=oe.isBuffer(r.publicKey)?r.publicKey:oe.from(r.publicKey),s=this.checkTaprootHashesForSig(e,t,r,n,i),a=r.signSchnorr.bind(r),u=e=>oe.isBuffer(e)?e:oe.from(e),c=s.filter(e=>!e.leafHash).map(e=>Os(u(a(e.hash)),t.sighashType))[0],f=s.filter(e=>!!e.leafHash).map(e=>({pubkey:Ki(o),signature:Os(u(a(e.hash)),t.sighashType),leafHash:e.leafHash}));return c&&this.data.updateInput(e,{tapKeySig:c}),f.length&&this.data.updateInput(e,{tapScriptSig:f}),this}_signInputAsync(e,t,r=[pn.SIGHASH_ALL]){const n=oe.isBuffer(t.publicKey)?t.publicKey:oe.from(t.publicKey),{hash:i,sighashType:o}=na(this.data.inputs,e,n,this.__CACHE,r);return Promise.resolve(t.sign(i)).then(t=>{const r=oe.isBuffer(t)?t:oe.from(t),i=[{pubkey:n,signature:wr.encode(r,o)}];this.data.updateInput(e,{partialSig:i})})}async _signTaprootInputAsync(e,t,r,n,i=[pn.SIGHASH_DEFAULT]){const o=oe.isBuffer(r.publicKey)?r.publicKey:oe.from(r.publicKey),s=this.checkTaprootHashesForSig(e,t,r,n,i),a=r.signSchnorr.bind(r),u=e=>oe.isBuffer(e)?e:oe.from(e),c=[],f=s.filter(e=>!e.leafHash)[0];if(f){const e=Promise.resolve(a(f.hash)).then(e=>({tapKeySig:Os(u(e),t.sighashType)}));c.push(e)}const l=s.filter(e=>!!e.leafHash);if(l.length){const e=l.map(async e=>{const r=await a(e.hash);return{tapScriptSig:[{pubkey:Ki(o),signature:Os(u(r),t.sighashType),leafHash:e.leafHash}]}});c.push(...e)}const h=await Promise.all(c);for(const p of h)this.data.updateInput(e,p)}};const js=e=>new Fs(e);let Fs=class{constructor(e=oe.from([2,0,0,0,0,0,0,0,0,0])){this.tx=pn.fromBuffer(e),function(e){if(!e.ins.every(e=>e.script&&0===e.script.length&&e.witness&&0===e.witness.length))throw new Error("Format Error: Transaction ScriptSigs are not empty")}(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(e){if(void 0===e.hash||void 0===e.index||!oe.isBuffer(e.hash)&&"string"!=typeof e.hash||"number"!=typeof e.index)throw new Error("Error adding input.");const t="string"==typeof e.hash?Vt(oe.from(e.hash,"hex")):e.hash;this.tx.addInput(t,e.index,e.sequence)}addOutput(e){if(void 0===e.script||void 0===e.value||!oe.isBuffer(e.script)||"number"!=typeof e.value)throw new Error("Error adding output.");this.tx.addOutput(e.script,e.value)}toBuffer(){return this.tx.toBuffer()}};function Vs(e){if(e.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function qs(e,t,r){if(!t)return!1;let n;if(n=r?r.map(e=>{const r=function(e){if(65===e.length){const t=1&e[64],r=oe.from(e.subarray(0,33));return r[0]=2|t,r}return oe.from(e)}(e);return t.find(e=>e.pubkey.equals(r))}).filter(e=>!!e):t,n.length>e)throw new Error("Too many signatures");return n.length===e}function Ws(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function $s(e){return t=>{const r=oe.isBuffer(e.fingerprint)?e.fingerprint:oe.from(e.fingerprint);if(!t.masterFingerprint.equals(r))return!1;const n=e.derivePath(t.path).publicKey;return!!(oe.isBuffer(n)?n:oe.from(n)).equals(t.pubkey)}}function Gs(e){if("number"!=typeof e||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function Xs(e,t){e.forEach(e=>{if(Bs(e)?Ns(e,t):Is(e,t))throw new Error("Can not modify transaction, signatures exist.")})}function Ys(e,t,r){if(!As(e,t))throw new Error(`Can not ${r} for this input with the key ${e.toString("hex")}`)}function Zs(e,t){const r=`${Vt(oe.from(t.hash)).toString("hex")}:${t.index}`;if(e.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[r]=1}function Qs(e,t){return(r,n,i,o)=>{const s=e({redeem:{output:i}}).output;if(!n.equals(s))throw new Error(`${t} for ${o} #${r} doesn't match the scriptPubKey in the prevout`)}}const Js=Qs(Or,"Redeem script"),ea=Qs(Yr,"Witness script");function ta(e,t,r,n,i=!1){if(!r.every(Ws))throw new Error(`PSBT must be finalized to calculate ${t}`);if("__FEE_RATE"===e&&n.__FEE_RATE)return n.__FEE_RATE;if("__FEE"===e&&n.__FEE)return n.__FEE;let o,s=!0;n.__EXTRACTED_TX?(o=n.__EXTRACTED_TX,s=!1):o=n.__TX.clone(),ha(r,o,n,s,i);const a="__FEE_RATE"===e?n.__FEE_RATE:n.__FEE;if(void 0===a)throw new Error(`Failed to calculate ${t}`);return a}function ra(e,t,r,n,i,o,s=!0,a){const u=wa(r);if(!function(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return qs(1,e.partialSig);case"multisig":{const r=en({output:t});return qs(r.m,e.partialSig,r.pubkeys)}case"nonstandard":return!0;default:return!1}}(t,r,u)&&s)throw new Error(`Can not finalize input #${e}`);return function(e,t,r,n,i,o,s){let a,u;const c=function(e,t,r){let n;switch(t){case"multisig":{const t=function(e,t){return en({output:e}).pubkeys.map(e=>(t.filter(t=>t.pubkey.equals(e))[0]||{}).signature).filter(e=>!!e)}(e,r);n=en({output:e,signatures:t});break}case"pubkey":n=rn({output:e,signature:r[0].signature});break;case"pubkeyhash":n=Tr({output:e,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=Wr({output:e,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(e,t,r),f=o?Yr({redeem:c}):null,l=i?Or({redeem:f||c}):null;return n?(u=Ss(f?f.witness:c?c.witness:s??[oe.from([0])]),l&&(a=l?.input)):a=l?l?.input:c?c.input:Array.isArray(s)&&s[0]?s[0]:oe.from([1]),{finalScriptSig:a,finalScriptWitness:u}}(r,u,t.partialSig,n,i,o,a)}function na(e,t,r,n,i){const o=ds.checkForInput(e,t),{hash:s,sighashType:a,script:u}=ia(t,o,n,!1,i);return Ys(r,u,"sign"),{hash:s,sighashType:a}}function ia(e,t,r,n,i){const o=r.__TX,s=t.sighashType||pn.SIGHASH_ALL;let a,u;if(ua(s,i),t.nonWitnessUtxo){const n=pa(r,t,e),i=o.ins[e].hash,s=n.getHash();if(!i.equals(s))throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const a=o.ins[e].index;u=n.outs[a]}else{if(!t.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=t.witnessUtxo}const{meaningfulScript:c,type:f}=ma(u.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(f)>=0)a=o.hashForWitnessV0(e,c,u.value,s);else if(ws(c)){const t=Tr({hash:c.subarray(2)}).output;a=o.hashForWitnessV0(e,t,u.value,s)}else{if(void 0===t.nonWitnessUtxo&&!r.__UNSAFE_SIGN_NONSEGWIT)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: `+c.toString("hex"));!n&&r.__UNSAFE_SIGN_NONSEGWIT&&console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),a=o.hashForSignature(e,c,s)}return{script:c,sighashType:s,hash:a}}function oa(e,t,r){const{script:n}=ya(e,t,r);return _s(n)?oe.from(n.subarray(2,34)):null}function sa(e){return 64===e.length?e:oe.from(e.subarray(0,64))}function aa(e,t,r,n,i,o,s){const a=i.__TX,u=t.sighashType||pn.SIGHASH_DEFAULT;ua(u,s);const c=r.map((e,t)=>ya(t,e,i)),f=c.map(e=>e.script),l=c.map(e=>e.value),h=[];if(t.tapInternalKey&&!o){const r=oa(e,t,i)||oe.from([]);if(Ki(n).equals(r)){const t=a.hashForWitnessV1(e,f,l,u);h.push({pubkey:n,hash:t})}}const p=(t.tapLeafScript||[]).filter(e=>As(n,e.script)).map(e=>{const t=Kr({output:e.script,version:e.leafVersion});return Object.assign({hash:t},e)}).filter(e=>!o||o.equals(e.hash)).map(t=>{const r=a.hashForWitnessV1(e,f,l,u,t.hash);return{pubkey:n,hash:r,leafHash:t.hash}});return h.concat(p)}function ua(e,t){if(t&&t.indexOf(e)<0){const t=function(e){let t=e&pn.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&e){case pn.SIGHASH_ALL:t+="SIGHASH_ALL";break;case pn.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case pn.SIGHASH_NONE:t+="SIGHASH_NONE"}return t}(e);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${t}`)}}function ca(e,t,r){const n=ds.checkForInput(t,e);if(!n.bip32Derivation||0===n.bip32Derivation.length)throw new Error("Need bip32Derivation to sign with HD");const i=n.bip32Derivation.map(e=>{if(e.masterFingerprint.equals(r.fingerprint))return e}).filter(e=>!!e);if(0===i.length)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map(e=>{const t=r.derivePath(e.path);if(!e.pubkey.equals(t.publicKey))throw new Error("pubkey did not match bip32Derivation");return t})}function fa(e){let t=0;function r(){const r=zs(e,t);return t+=zs.bytes,r}function n(){return n=r(),t+=n,e.subarray(t-n,t);var n}return function(){const e=r(),t=[];for(let r=0;r<e;r++)t.push(n());return t}()}function la(e,t,r){e.__NON_WITNESS_UTXO_BUF_CACHE[r]=t.nonWitnessUtxo,e.__NON_WITNESS_UTXO_TX_CACHE[r]=pn.fromBuffer(t.nonWitnessUtxo);const n=e,i=r;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const e=n.__NON_WITNESS_UTXO_BUF_CACHE[i],t=n.__NON_WITNESS_UTXO_TX_CACHE[i];if(void 0!==e)return e;{const e=t.toBuffer();return n.__NON_WITNESS_UTXO_BUF_CACHE[i]=e,e}},set(e){n.__NON_WITNESS_UTXO_BUF_CACHE[i]=e}})}function ha(e,t,r,n,i){let o=0;e.forEach((e,i)=>{if(n&&e.finalScriptSig&&(t.ins[i].script=e.finalScriptSig),n&&e.finalScriptWitness&&(t.ins[i].witness=fa(e.finalScriptWitness)),e.witnessUtxo)o+=e.witnessUtxo.value;else if(e.nonWitnessUtxo){const n=pa(r,e,i),s=t.ins[i].index,a=n.outs[s];o+=a.value}});const s=t.outs.reduce((e,t)=>e+t.value,0),a=o-s;if(!i&&a<0)throw new Error(`Outputs are spending more than Inputs ${o} < ${s}`);const u=t.virtualSize();r.__FEE=a,r.__EXTRACTED_TX=t,r.__FEE_RATE=Math.floor(a/u)}function pa(e,t,r){const n=e.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||la(e,t,r),n[r]}function da(e,t,r){const{script:n}=ya(e,t,r);return n}function ya(e,t,r){if(void 0!==t.witnessUtxo)return{script:t.witnessUtxo.script,value:t.witnessUtxo.value};if(void 0!==t.nonWitnessUtxo){const n=pa(r,t,e).outs[r.__TX.ins[e].index];return{script:n.script,value:n.value}}throw new Error("Can't find pubkey in input without Utxo data")}function ga(e){return 33===e.length&&gr(e)}function ma(e,t,r,n,i){const o=Es(e),s=o&&n&&vs(n),a=vs(e);if(o&&void 0===n)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((a||s)&&void 0===i)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let u;return s?(u=i,Js(t,e,n,r),ea(t,n,i,r),ba(u)):a?(u=i,ea(t,e,i,r),ba(u)):o?(u=n,Js(t,e,n,r)):u=e,{meaningfulScript:u,type:s?"p2sh-p2wsh":o?"p2sh":a?"p2wsh":"raw"}}function ba(e){if(ws(e)||Es(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function wa(e){return ws(e)?"witnesspubkeyhash":bs(e)?"pubkeyhash":gs(e)?"multisig":ms(e)?"pubkey":"nonstandard"}function va(e){return[...Array(e).keys()]}const Ea="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function _a(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Sa(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ka(e,...t){if(!_a(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Aa(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");Sa(e.outputLen),Sa(e.blockLen)}function Ia(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ta(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function xa(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Oa(e,t){return e<<32-t|e>>>t}const Ba="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex,Pa=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ua(e){if(ka(e),Ba)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Pa[e[r]];return t}const La=48,Na=57,Ra=65,Ca=70,Ha=97,Ka=102;function za(e){return e>=La&&e<=Na?e-La:e>=Ra&&e<=Ca?e-(Ra-10):e>=Ha&&e<=Ka?e-(Ha-10):void 0}function Ma(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Ba)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){const t=za(e.charCodeAt(o)),r=za(e.charCodeAt(o+1));if(void 0===t||void 0===r){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}n[i]=16*t+r}return n}function Da(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function ja(e){return"string"==typeof e&&(e=Da(e)),ka(e),e}function Fa(e){return"string"==typeof e&&(e=Da(e)),ka(e),e}function Va(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];ka(r),t+=r.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const t=e[n];r.set(t,i),i+=t.length}return r}let qa=class{};function Wa(e){const t=t=>e().update(ja(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function $a(e=32){if(Ea&&"function"==typeof Ea.getRandomValues)return Ea.getRandomValues(new Uint8Array(e));if(Ea&&"function"==typeof Ea.randomBytes)return Uint8Array.from(Ea.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Ga(e,t,r){return e&t^~e&r}function Xa(e,t,r){return e&t^e&r^t&r}let Ya=class extends qa{constructor(e,t,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=xa(this.buffer)}update(e){Ia(this),ka(e=ja(e));const{view:t,buffer:r,blockLen:n}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s===n){const t=xa(e);for(;n<=i-o;o+=n)this.process(t,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ia(this),function(e,t){ka(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,Ta(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let f=o;f<n;f++)t[f]=0;(function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,c=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+c,a,n)})(r,n-8,BigInt(8*this.length),i),this.process(r,0);const s=xa(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)s.setUint32(4*f,c[f],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}};const Za=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qa=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Ja=BigInt(2**32-1),eu=BigInt(32);function tu(e,t=!1){return t?{h:Number(e&Ja),l:Number(e>>eu&Ja)}:{h:0|Number(e>>eu&Ja),l:0|Number(e&Ja)}}const ru=(e,t,r)=>e>>>r,nu=(e,t,r)=>e<<32-r|t>>>r,iu=(e,t,r)=>e>>>r|t<<32-r,ou=(e,t,r)=>e<<32-r|t>>>r,su=(e,t,r)=>e<<64-r|t>>>r-32,au=(e,t,r)=>e>>>r-32|t<<64-r;function uu(e,t,r,n){const i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:0|i}}const cu=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),fu=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,lu=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),hu=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0,pu=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0),du=(e,t,r,n,i,o)=>t+r+n+i+o+(e/2**32|0)|0,yu=Uint32Array.from([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]),gu=new Uint32Array(64);let mu=class extends Ya{constructor(e=32){super(64,e,8,!1),this.A=0|Za[0],this.B=0|Za[1],this.C=0|Za[2],this.D=0|Za[3],this.E=0|Za[4],this.F=0|Za[5],this.G=0|Za[6],this.H=0|Za[7]}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let f=0;f<16;f++,t+=4)gu[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){const e=gu[f-15],t=gu[f-2],r=Oa(e,7)^Oa(e,18)^e>>>3,n=Oa(t,17)^Oa(t,19)^t>>>10;gu[f]=n+gu[f-7]+r+gu[f-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let f=0;f<64;f++){const e=c+(Oa(s,6)^Oa(s,11)^Oa(s,25))+Ga(s,a,u)+yu[f]+gu[f]|0,t=(Oa(r,2)^Oa(r,13)^Oa(r,22))+Xa(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+t|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){Ta(gu)}destroy(){this.set(0,0,0,0,0,0,0,0),Ta(this.buffer)}};const bu=function(e,t=!1){const r=e.length;let n=new Uint32Array(r),i=new Uint32Array(r);for(let o=0;o<r;o++){const{h:r,l:s}=tu(e[o],t);[n[o],i[o]]=[r,s]}return[n,i]}(["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(e=>BigInt(e))),wu=bu[0],vu=bu[1],Eu=new Uint32Array(80),_u=new Uint32Array(80);let Su=class extends Ya{constructor(e=64){super(128,e,16,!1),this.Ah=0|Qa[0],this.Al=0|Qa[1],this.Bh=0|Qa[2],this.Bl=0|Qa[3],this.Ch=0|Qa[4],this.Cl=0|Qa[5],this.Dh=0|Qa[6],this.Dl=0|Qa[7],this.Eh=0|Qa[8],this.El=0|Qa[9],this.Fh=0|Qa[10],this.Fl=0|Qa[11],this.Gh=0|Qa[12],this.Gl=0|Qa[13],this.Hh=0|Qa[14],this.Hl=0|Qa[15]}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:i,Cl:o,Dh:s,Dl:a,Eh:u,El:c,Fh:f,Fl:l,Gh:h,Gl:p,Hh:d,Hl:y}=this;return[e,t,r,n,i,o,s,a,u,c,f,l,h,p,d,y]}set(e,t,r,n,i,o,s,a,u,c,f,l,h,p,d,y){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|i,this.Cl=0|o,this.Dh=0|s,this.Dl=0|a,this.Eh=0|u,this.El=0|c,this.Fh=0|f,this.Fl=0|l,this.Gh=0|h,this.Gl=0|p,this.Hh=0|d,this.Hl=0|y}process(e,t){for(let b=0;b<16;b++,t+=4)Eu[b]=e.getUint32(t),_u[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){const e=0|Eu[b-15],t=0|_u[b-15],r=iu(e,t,1)^iu(e,t,8)^ru(e,0,7),n=ou(e,t,1)^ou(e,t,8)^nu(e,t,7),i=0|Eu[b-2],o=0|_u[b-2],s=iu(i,o,19)^su(i,o,61)^ru(i,0,6),a=ou(i,o,19)^au(i,o,61)^nu(i,o,6),u=lu(n,a,_u[b-7],_u[b-16]),c=hu(u,r,s,Eu[b-7],Eu[b-16]);Eu[b]=0|c,_u[b]=0|u}let{Ah:r,Al:n,Bh:i,Bl:o,Ch:s,Cl:a,Dh:u,Dl:c,Eh:f,El:l,Fh:h,Fl:p,Gh:d,Gl:y,Hh:g,Hl:m}=this;for(let b=0;b<80;b++){const e=iu(f,l,14)^iu(f,l,18)^su(f,l,41),t=ou(f,l,14)^ou(f,l,18)^au(f,l,41),w=f&h^~f&d,v=pu(m,t,l&p^~l&y,vu[b],_u[b]),E=du(v,g,e,w,wu[b],Eu[b]),_=0|v,S=iu(r,n,28)^su(r,n,34)^su(r,n,39),k=ou(r,n,28)^au(r,n,34)^au(r,n,39),A=r&i^r&s^i&s,I=n&o^n&a^o&a;g=0|d,m=0|y,d=0|h,y=0|p,h=0|f,p=0|l,({h:f,l:l}=uu(0|u,0|c,0|E,0|_)),u=0|s,c=0|a,s=0|i,a=0|o,i=0|r,o=0|n;const T=cu(_,k,I);r=fu(T,E,S,A),n=0|T}({h:r,l:n}=uu(0|this.Ah,0|this.Al,0|r,0|n)),({h:i,l:o}=uu(0|this.Bh,0|this.Bl,0|i,0|o)),({h:s,l:a}=uu(0|this.Ch,0|this.Cl,0|s,0|a)),({h:u,l:c}=uu(0|this.Dh,0|this.Dl,0|u,0|c)),({h:f,l:l}=uu(0|this.Eh,0|this.El,0|f,0|l)),({h:h,l:p}=uu(0|this.Fh,0|this.Fl,0|h,0|p)),({h:d,l:y}=uu(0|this.Gh,0|this.Gl,0|d,0|y)),({h:g,l:m}=uu(0|this.Hh,0|this.Hl,0|g,0|m)),this.set(r,n,i,o,s,a,u,c,f,l,h,p,d,y,g,m)}roundClean(){Ta(Eu,_u)}destroy(){Ta(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};const ku=Wa(()=>new mu),Au=Wa(()=>new Su),Iu=ku;var Tu,xu,Ou,Bu={},Pu={},Uu={},Lu={};function Nu(){return Tu||(Tu=1,Object.defineProperty(Lu,"__esModule",{value:!0}),Lu.crypto=void 0,Lu.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0),Lu}function Ru(){return xu||(xu=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=r,e.anumber=n,e.abytes=i,e.ahash=function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");n(e.outputLen),n(e.blockLen)},e.aexists=function(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")},e.aoutput=function(e,t){i(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)},e.u8=function(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},e.u32=function(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))},e.clean=function(...e){for(let t=0;t<e.length;t++)e[t].fill(0)},e.createView=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},e.rotr=function(e,t){return e<<32-t|e>>>t},e.rotl=function(e,t){return e<<t|e>>>32-t>>>0},e.byteSwap=o,e.byteSwap32=s,e.bytesToHex=function(e){if(i(e),a)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=u[e[r]];return t},e.hexToBytes=function(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(a)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){const t=f(e.charCodeAt(o)),r=f(e.charCodeAt(o+1));if(void 0===t||void 0===r){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}n[i]=16*t+r}return n},e.asyncLoop=async function(t,r,n){let i=Date.now();for(let o=0;o<t;o++){n(o);const t=Date.now()-i;t>=0&&t<r||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=l,e.bytesToUtf8=function(e){return(new TextDecoder).decode(e)},e.toBytes=h,e.kdfInputToBytes=function(e){return"string"==typeof e&&(e=l(e)),i(e),e},e.concatBytes=function(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];i(r),t+=r.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const t=e[n];r.set(t,i),i+=t.length}return r},e.checkOpts=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign(e,t)},e.createHasher=p,e.createOptHasher=d,e.createXOFer=y,e.randomBytes=function(e=32){if(t.crypto&&"function"==typeof t.crypto.getRandomValues)return t.crypto.getRandomValues(new Uint8Array(e));if(t.crypto&&"function"==typeof t.crypto.randomBytes)return Uint8Array.from(t.crypto.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")};const t=Nu();function r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function n(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function i(e,...t){if(!r(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function o(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function s(e){for(let t=0;t<e.length;t++)e[t]=o(e[t]);return e}e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],e.swap8IfBE=e.isLE?e=>e:e=>o(e),e.byteSwapIfBE=e.swap8IfBE,e.swap32IfBE=e.isLE?e=>e:s;const a="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex,u=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));const c={_0:48,_9:57,A:65,F:70,a:97,f:102};function f(e){return e>=c._0&&e<=c._9?e-c._0:e>=c.A&&e<=c.F?e-(c.A-10):e>=c.a&&e<=c.f?e-(c.a-10):void 0}function l(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function h(e){return"string"==typeof e&&(e=l(e)),i(e),e}e.nextTick=async()=>{};function p(e){const t=t=>e().update(h(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function d(e){const t=(t,r)=>e(r).update(h(t)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=t=>e(t),t}function y(e){const t=(t,r)=>e(r).update(h(t)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=t=>e(t),t}e.Hash=class{},e.wrapConstructor=p,e.wrapConstructorWithOpts=d,e.wrapXOFConstructorWithOpts=y}(Uu)),Uu}function Cu(){if(Ou)return Pu;Ou=1,Object.defineProperty(Pu,"__esModule",{value:!0}),Pu.SHA512_IV=Pu.SHA384_IV=Pu.SHA224_IV=Pu.SHA256_IV=Pu.HashMD=void 0,Pu.setBigUint64=t,Pu.Chi=function(e,t,r){return e&t^~e&r},Pu.Maj=function(e,t,r){return e&t^e&r^t&r};const e=Ru();function t(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,c=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+c,a,n)}class r extends e.Hash{constructor(t,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=(0,e.createView)(this.buffer)}update(t){(0,e.aexists)(this),t=(0,e.toBytes)(t),(0,e.abytes)(t);const{view:r,buffer:n,blockLen:i}=this,o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const r=(0,e.createView)(t);for(;i<=o-s;s+=i)this.process(r,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(r){(0,e.aexists)(this),(0,e.aoutput)(r,this),this.finished=!0;const{buffer:n,view:i,blockLen:o,isLE:s}=this;let{pos:a}=this;n[a++]=128,(0,e.clean)(this.buffer.subarray(a)),this.padOffset>o-a&&(this.process(i,0),a=0);for(let e=a;e<o;e++)n[e]=0;t(i,o-8,BigInt(8*this.length),s),this.process(i,0);const u=(0,e.createView)(r),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<f;e++)u.setUint32(4*e,l[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}return Pu.HashMD=r,Pu.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pu.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Pu.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Pu.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Pu}var Hu,Ku,zu={};function Mu(){if(Hu)return zu;Hu=1,Object.defineProperty(zu,"__esModule",{value:!0}),zu.toBig=zu.shrSL=zu.shrSH=zu.rotrSL=zu.rotrSH=zu.rotrBL=zu.rotrBH=zu.rotr32L=zu.rotr32H=zu.rotlSL=zu.rotlSH=zu.rotlBL=zu.rotlBH=zu.add5L=zu.add5H=zu.add4L=zu.add4H=zu.add3L=zu.add3H=void 0,zu.add=m,zu.fromBig=r,zu.split=n;const e=BigInt(2**32-1),t=BigInt(32);function r(r,n=!1){return n?{h:Number(r&e),l:Number(r>>t&e)}:{h:0|Number(r>>t&e),l:0|Number(r&e)}}function n(e,t=!1){const n=e.length;let i=new Uint32Array(n),o=new Uint32Array(n);for(let s=0;s<n;s++){const{h:n,l:a}=r(e[s],t);[i[s],o[s]]=[n,a]}return[i,o]}const i=(e,r)=>BigInt(e>>>0)<<t|BigInt(r>>>0);zu.toBig=i;const o=(e,t,r)=>e>>>r;zu.shrSH=o;const s=(e,t,r)=>e<<32-r|t>>>r;zu.shrSL=s;const a=(e,t,r)=>e>>>r|t<<32-r;zu.rotrSH=a;const u=(e,t,r)=>e<<32-r|t>>>r;zu.rotrSL=u;const c=(e,t,r)=>e<<64-r|t>>>r-32;zu.rotrBH=c;const f=(e,t,r)=>e>>>r-32|t<<64-r;zu.rotrBL=f;const l=(e,t)=>t;zu.rotr32H=l;const h=(e,t)=>e;zu.rotr32L=h;const p=(e,t,r)=>e<<r|t>>>32-r;zu.rotlSH=p;const d=(e,t,r)=>t<<r|e>>>32-r;zu.rotlSL=d;const y=(e,t,r)=>t<<r-32|e>>>64-r;zu.rotlBH=y;const g=(e,t,r)=>e<<r-32|t>>>64-r;function m(e,t,r,n){const i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:0|i}}zu.rotlBL=g;const b=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0);zu.add3L=b;const w=(e,t,r,n)=>t+r+n+(e/2**32|0)|0;zu.add3H=w;const v=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0);zu.add4L=v;const E=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0;zu.add4H=E;const _=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0);zu.add5L=_;const S=(e,t,r,n,i,o)=>t+r+n+i+o+(e/2**32|0)|0;zu.add5H=S;const k={fromBig:r,split:n,toBig:i,shrSH:o,shrSL:s,rotrSH:a,rotrSL:u,rotrBH:c,rotrBL:f,rotr32H:l,rotr32L:h,rotlSH:p,rotlSL:d,rotlBH:y,rotlBL:g,add:m,add3L:b,add3H:w,add4L:v,add4H:E,add5H:S,add5L:_};return zu.default=k,zu}function Du(){if(Ku)return Bu;Ku=1,Object.defineProperty(Bu,"__esModule",{value:!0}),Bu.sha512_224=Bu.sha512_256=Bu.sha384=Bu.sha512=Bu.sha224=Bu.sha256=Bu.SHA512_256=Bu.SHA512_224=Bu.SHA384=Bu.SHA512=Bu.SHA224=Bu.SHA256=void 0;const e=Cu(),t=Mu(),r=Ru(),n=Uint32Array.from([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]),i=new Uint32Array(64);class o extends e.HashMD{constructor(t=32){super(64,t,8,!1),this.A=0|e.SHA256_IV[0],this.B=0|e.SHA256_IV[1],this.C=0|e.SHA256_IV[2],this.D=0|e.SHA256_IV[3],this.E=0|e.SHA256_IV[4],this.F=0|e.SHA256_IV[5],this.G=0|e.SHA256_IV[6],this.H=0|e.SHA256_IV[7]}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,o){for(let e=0;e<16;e++,o+=4)i[e]=t.getUint32(o,!1);for(let e=16;e<64;e++){const t=i[e-15],n=i[e-2],o=(0,r.rotr)(t,7)^(0,r.rotr)(t,18)^t>>>3,s=(0,r.rotr)(n,17)^(0,r.rotr)(n,19)^n>>>10;i[e]=s+i[e-7]+o+i[e-16]|0}let{A:s,B:a,C:u,D:c,E:f,F:l,G:h,H:p}=this;for(let d=0;d<64;d++){const t=p+((0,r.rotr)(f,6)^(0,r.rotr)(f,11)^(0,r.rotr)(f,25))+(0,e.Chi)(f,l,h)+n[d]+i[d]|0,o=((0,r.rotr)(s,2)^(0,r.rotr)(s,13)^(0,r.rotr)(s,22))+(0,e.Maj)(s,a,u)|0;p=h,h=l,l=f,f=c+t|0,c=u,u=a,a=s,s=t+o|0}s=s+this.A|0,a=a+this.B|0,u=u+this.C|0,c=c+this.D|0,f=f+this.E|0,l=l+this.F|0,h=h+this.G|0,p=p+this.H|0,this.set(s,a,u,c,f,l,h,p)}roundClean(){(0,r.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,r.clean)(this.buffer)}}Bu.SHA256=o;class s extends o{constructor(){super(28),this.A=0|e.SHA224_IV[0],this.B=0|e.SHA224_IV[1],this.C=0|e.SHA224_IV[2],this.D=0|e.SHA224_IV[3],this.E=0|e.SHA224_IV[4],this.F=0|e.SHA224_IV[5],this.G=0|e.SHA224_IV[6],this.H=0|e.SHA224_IV[7]}}Bu.SHA224=s;const a=t.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(e=>BigInt(e))),u=a[0],c=a[1],f=new Uint32Array(80),l=new Uint32Array(80);class h extends e.HashMD{constructor(t=64){super(128,t,16,!1),this.Ah=0|e.SHA512_IV[0],this.Al=0|e.SHA512_IV[1],this.Bh=0|e.SHA512_IV[2],this.Bl=0|e.SHA512_IV[3],this.Ch=0|e.SHA512_IV[4],this.Cl=0|e.SHA512_IV[5],this.Dh=0|e.SHA512_IV[6],this.Dl=0|e.SHA512_IV[7],this.Eh=0|e.SHA512_IV[8],this.El=0|e.SHA512_IV[9],this.Fh=0|e.SHA512_IV[10],this.Fl=0|e.SHA512_IV[11],this.Gh=0|e.SHA512_IV[12],this.Gl=0|e.SHA512_IV[13],this.Hh=0|e.SHA512_IV[14],this.Hl=0|e.SHA512_IV[15]}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:i,Cl:o,Dh:s,Dl:a,Eh:u,El:c,Fh:f,Fl:l,Gh:h,Gl:p,Hh:d,Hl:y}=this;return[e,t,r,n,i,o,s,a,u,c,f,l,h,p,d,y]}set(e,t,r,n,i,o,s,a,u,c,f,l,h,p,d,y){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|i,this.Cl=0|o,this.Dh=0|s,this.Dl=0|a,this.Eh=0|u,this.El=0|c,this.Fh=0|f,this.Fl=0|l,this.Gh=0|h,this.Gl=0|p,this.Hh=0|d,this.Hl=0|y}process(e,r){for(let t=0;t<16;t++,r+=4)f[t]=e.getUint32(r),l[t]=e.getUint32(r+=4);for(let u=16;u<80;u++){const e=0|f[u-15],r=0|l[u-15],n=t.rotrSH(e,r,1)^t.rotrSH(e,r,8)^t.shrSH(e,r,7),i=t.rotrSL(e,r,1)^t.rotrSL(e,r,8)^t.shrSL(e,r,7),o=0|f[u-2],s=0|l[u-2],a=t.rotrSH(o,s,19)^t.rotrBH(o,s,61)^t.shrSH(o,s,6),c=t.rotrSL(o,s,19)^t.rotrBL(o,s,61)^t.shrSL(o,s,6),h=t.add4L(i,c,l[u-7],l[u-16]),p=t.add4H(h,n,a,f[u-7],f[u-16]);f[u]=0|p,l[u]=0|h}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:h,Dh:p,Dl:d,Eh:y,El:g,Fh:m,Fl:b,Gh:w,Gl:v,Hh:E,Hl:_}=this;for(let S=0;S<80;S++){const e=t.rotrSH(y,g,14)^t.rotrSH(y,g,18)^t.rotrBH(y,g,41),r=t.rotrSL(y,g,14)^t.rotrSL(y,g,18)^t.rotrBL(y,g,41),k=y&m^~y&w,A=g&b^~g&v,I=t.add5L(_,r,A,c[S],l[S]),T=t.add5H(I,E,e,k,u[S],f[S]),x=0|I,O=t.rotrSH(n,i,28)^t.rotrBH(n,i,34)^t.rotrBH(n,i,39),B=t.rotrSL(n,i,28)^t.rotrBL(n,i,34)^t.rotrBL(n,i,39),P=n&o^n&a^o&a,U=i&s^i&h^s&h;E=0|w,_=0|v,w=0|m,v=0|b,m=0|y,b=0|g,({h:y,l:g}=t.add(0|p,0|d,0|T,0|x)),p=0|a,d=0|h,a=0|o,h=0|s,o=0|n,s=0|i;const L=t.add3L(x,B,U);n=t.add3H(L,T,O,P),i=0|L}({h:n,l:i}=t.add(0|this.Ah,0|this.Al,0|n,0|i)),({h:o,l:s}=t.add(0|this.Bh,0|this.Bl,0|o,0|s)),({h:a,l:h}=t.add(0|this.Ch,0|this.Cl,0|a,0|h)),({h:p,l:d}=t.add(0|this.Dh,0|this.Dl,0|p,0|d)),({h:y,l:g}=t.add(0|this.Eh,0|this.El,0|y,0|g)),({h:m,l:b}=t.add(0|this.Fh,0|this.Fl,0|m,0|b)),({h:w,l:v}=t.add(0|this.Gh,0|this.Gl,0|w,0|v)),({h:E,l:_}=t.add(0|this.Hh,0|this.Hl,0|E,0|_)),this.set(n,i,o,s,a,h,p,d,y,g,m,b,w,v,E,_)}roundClean(){(0,r.clean)(f,l)}destroy(){(0,r.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}Bu.SHA512=h;class p extends h{constructor(){super(48),this.Ah=0|e.SHA384_IV[0],this.Al=0|e.SHA384_IV[1],this.Bh=0|e.SHA384_IV[2],this.Bl=0|e.SHA384_IV[3],this.Ch=0|e.SHA384_IV[4],this.Cl=0|e.SHA384_IV[5],this.Dh=0|e.SHA384_IV[6],this.Dl=0|e.SHA384_IV[7],this.Eh=0|e.SHA384_IV[8],this.El=0|e.SHA384_IV[9],this.Fh=0|e.SHA384_IV[10],this.Fl=0|e.SHA384_IV[11],this.Gh=0|e.SHA384_IV[12],this.Gl=0|e.SHA384_IV[13],this.Hh=0|e.SHA384_IV[14],this.Hl=0|e.SHA384_IV[15]}}Bu.SHA384=p;const d=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),y=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class g extends h{constructor(){super(28),this.Ah=0|d[0],this.Al=0|d[1],this.Bh=0|d[2],this.Bl=0|d[3],this.Ch=0|d[4],this.Cl=0|d[5],this.Dh=0|d[6],this.Dl=0|d[7],this.Eh=0|d[8],this.El=0|d[9],this.Fh=0|d[10],this.Fl=0|d[11],this.Gh=0|d[12],this.Gl=0|d[13],this.Hh=0|d[14],this.Hl=0|d[15]}}Bu.SHA512_224=g;class m extends h{constructor(){super(32),this.Ah=0|y[0],this.Al=0|y[1],this.Bh=0|y[2],this.Bl=0|y[3],this.Ch=0|y[4],this.Cl=0|y[5],this.Dh=0|y[6],this.Dl=0|y[7],this.Eh=0|y[8],this.El=0|y[9],this.Fh=0|y[10],this.Fl=0|y[11],this.Gh=0|y[12],this.Gl=0|y[13],this.Hh=0|y[14],this.Hl=0|y[15]}}return Bu.SHA512_256=m,Bu.sha256=(0,r.createHasher)(()=>new o),Bu.sha224=(0,r.createHasher)(()=>new s),Bu.sha512=(0,r.createHasher)(()=>new h),Bu.sha384=(0,r.createHasher)(()=>new p),Bu.sha512_256=(0,r.createHasher)(()=>new m),Bu.sha512_224=(0,r.createHasher)(()=>new g),Bu}var ju,Fu={};function Vu(){return ju||(ju=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=Ru();class r extends t.Hash{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(e);const n=(0,t.toBytes)(r);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=e.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),(0,t.clean)(o)}update(e){return(0,t.aexists)(this),this.iHash.update(e),this}digestInto(e){(0,t.aexists)(this),(0,t.abytes)(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:n,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=n,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=r;e.hmac=(e,t,n)=>new r(e,t).update(n).digest(),e.hmac.create=(e,t)=>new r(e,t)}(Fu)),Fu}var qu,Wu,$u={},Gu={};function Xu(){if(qu)return Gu;qu=1,Object.defineProperty(Gu,"__esModule",{value:!0}),Gu.ripemd160=Gu.RIPEMD160=Gu.md5=Gu.MD5=Gu.sha1=Gu.SHA1=void 0;const e=Cu(),t=Ru(),r=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),n=new Uint32Array(80);class i extends e.HashMD{constructor(){super(64,20,8,!1),this.A=0|r[0],this.B=0|r[1],this.C=0|r[2],this.D=0|r[3],this.E=0|r[4]}get(){const{A:e,B:t,C:r,D:n,E:i}=this;return[e,t,r,n,i]}set(e,t,r,n,i){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i}process(r,i){for(let e=0;e<16;e++,i+=4)n[e]=r.getUint32(i,!1);for(let e=16;e<80;e++)n[e]=(0,t.rotl)(n[e-3]^n[e-8]^n[e-14]^n[e-16],1);let{A:o,B:s,C:a,D:u,E:c}=this;for(let f=0;f<80;f++){let r,i;f<20?(r=(0,e.Chi)(s,a,u),i=1518500249):f<40?(r=s^a^u,i=1859775393):f<60?(r=(0,e.Maj)(s,a,u),i=2400959708):(r=s^a^u,i=3395469782);const l=(0,t.rotl)(o,5)+r+c+i+n[f]|0;c=u,u=a,a=(0,t.rotl)(s,30),s=o,o=l}o=o+this.A|0,s=s+this.B|0,a=a+this.C|0,u=u+this.D|0,c=c+this.E|0,this.set(o,s,a,u,c)}roundClean(){(0,t.clean)(n)}destroy(){this.set(0,0,0,0,0),(0,t.clean)(this.buffer)}}Gu.SHA1=i,Gu.sha1=(0,t.createHasher)(()=>new i);const o=Math.pow(2,32),s=Array.from({length:64},(e,t)=>Math.floor(o*Math.abs(Math.sin(t+1)))),a=r.slice(0,4),u=new Uint32Array(16);class c extends e.HashMD{constructor(){super(64,16,8,!0),this.A=0|a[0],this.B=0|a[1],this.C=0|a[2],this.D=0|a[3]}get(){const{A:e,B:t,C:r,D:n}=this;return[e,t,r,n]}set(e,t,r,n){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n}process(r,n){for(let e=0;e<16;e++,n+=4)u[e]=r.getUint32(n,!0);let{A:i,B:o,C:a,D:c}=this;for(let f=0;f<64;f++){let r,n,l;f<16?(r=(0,e.Chi)(o,a,c),n=f,l=[7,12,17,22]):f<32?(r=(0,e.Chi)(c,o,a),n=(5*f+1)%16,l=[5,9,14,20]):f<48?(r=o^a^c,n=(3*f+5)%16,l=[4,11,16,23]):(r=a^(o|~c),n=7*f%16,l=[6,10,15,21]),r=r+i+s[f]+u[n],i=c,c=a,a=o,o+=(0,t.rotl)(r,l[f%4])}i=i+this.A|0,o=o+this.B|0,a=a+this.C|0,c=c+this.D|0,this.set(i,o,a,c)}roundClean(){(0,t.clean)(u)}destroy(){this.set(0,0,0,0),(0,t.clean)(this.buffer)}}Gu.MD5=c,Gu.md5=(0,t.createHasher)(()=>new c);const f=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),l=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),h=l.map(e=>(9*e+5)%16),p=(()=>{const e=[[l],[h]];for(let t=0;t<4;t++)for(let r of e)r.push(r[t].map(e=>f[e]));return e})(),d=p[0],y=p[1],g=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),m=d.map((e,t)=>e.map(e=>g[t][e])),b=y.map((e,t)=>e.map(e=>g[t][e])),w=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),v=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function E(e,t,r,n){return 0===e?t^r^n:1===e?t&r|~t&n:2===e?(t|~r)^n:3===e?t&n|r&~n:t^(r|~n)}const _=new Uint32Array(16);class S extends e.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:r,h3:n,h4:i}=this;return[e,t,r,n,i]}set(e,t,r,n,i){this.h0=0|e,this.h1=0|t,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(e,r){for(let t=0;t<16;t++,r+=4)_[t]=e.getUint32(r,!0);let n=0|this.h0,i=n,o=0|this.h1,s=o,a=0|this.h2,u=a,c=0|this.h3,f=c,l=0|this.h4,h=l;for(let p=0;p<5;p++){const e=4-p,r=w[p],g=v[p],S=d[p],k=y[p],A=m[p],I=b[p];for(let i=0;i<16;i++){const e=(0,t.rotl)(n+E(p,o,a,c)+_[S[i]]+r,A[i])+l|0;n=l,l=c,c=0|(0,t.rotl)(a,10),a=o,o=e}for(let n=0;n<16;n++){const r=(0,t.rotl)(i+E(e,s,u,f)+_[k[n]]+g,I[n])+h|0;i=h,h=f,f=0|(0,t.rotl)(u,10),u=s,s=r}}this.set(this.h1+a+f|0,this.h2+c+h|0,this.h3+l+i|0,this.h4+n+s|0,this.h0+o+u|0)}roundClean(){(0,t.clean)(_)}destroy(){this.destroyed=!0,(0,t.clean)(this.buffer),this.set(0,0,0,0,0)}}return Gu.RIPEMD160=S,Gu.ripemd160=(0,t.createHasher)(()=>new S),Gu}function Yu(){if(Wu)return $u;Wu=1,Object.defineProperty($u,"__esModule",{value:!0}),$u.ripemd160=$u.RIPEMD160=void 0;const e=Xu();return $u.RIPEMD160=e.RIPEMD160,$u.ripemd160=e.ripemd160,$u}var Zu,Qu={};function Ju(){if(Zu)return Qu;Zu=1,Object.defineProperty(Qu,"__esModule",{value:!0}),Qu.sha224=Qu.SHA224=Qu.sha256=Qu.SHA256=void 0;const e=Du();return Qu.SHA256=e.SHA256,Qu.sha256=e.sha256,Qu.SHA224=e.SHA224,Qu.sha224=e.sha224,Qu}var ec,tc={};function rc(){if(ec)return tc;ec=1,Object.defineProperty(tc,"__esModule",{value:!0}),tc.sha512_256=tc.SHA512_256=tc.sha512_224=tc.SHA512_224=tc.sha384=tc.SHA384=tc.sha512=tc.SHA512=void 0;const e=Du();return tc.SHA512=e.SHA512,tc.sha512=e.sha512,tc.SHA384=e.SHA384,tc.sha384=e.sha384,tc.SHA512_224=e.SHA512_224,tc.sha512_224=e.sha512_224,tc.SHA512_256=e.SHA512_256,tc.sha512_256=e.sha512_256,tc}function nc(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ic(e,t=""){if(!Number.isSafeInteger(e)||e<0){throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}}function oc(e,t,r=""){const n=nc(e),i=e?.length,o=void 0!==t;if(!n||o&&i!==t){throw new Error((r&&`"${r}" `)+"expected Uint8Array"+(o?` of length ${t}`:"")+", got "+(n?`length=${i}`:"type="+typeof e))}return e}function sc(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ac(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function uc(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const cc=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=uc(e[t]);return e};function fc(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];oc(r),t+=r.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const t=e[n];r.set(t,i),i+=t.length}return r}const lc=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])}),hc=BigInt(2**32-1),pc=BigInt(32);function dc(e,t=!1){return t?{h:Number(e&hc),l:Number(e>>pc&hc)}:{h:0|Number(e>>pc&hc),l:0|Number(e&hc)}}const yc=BigInt(0),gc=BigInt(1),mc=BigInt(2),bc=BigInt(7),wc=BigInt(256),vc=BigInt(113),Ec=[],_c=[],Sc=[];for(let _R=0,SR=gc,kR=1,AR=0;_R<24;_R++){[kR,AR]=[AR,(2*kR+3*AR)%5],Ec.push(2*(5*AR+kR)),_c.push((_R+1)*(_R+2)/2%64);let e=yc;for(let t=0;t<7;t++)SR=(SR<<gc^(SR>>bc)*vc)%wc,SR&mc&&(e^=gc<<(gc<<BigInt(t))-gc);Sc.push(e)}const kc=function(e,t=!1){const r=e.length;let n=new Uint32Array(r),i=new Uint32Array(r);for(let o=0;o<r;o++){const{h:r,l:s}=dc(e[o],t);[n[o],i[o]]=[r,s]}return[n,i]}(Sc,!0),Ac=kc[0],Ic=kc[1],Tc=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),xc=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);let Oc=class e{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;enableXOF=!1;rounds;constructor(e,t,r,n=!1,i=24){if(this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=n,this.rounds=i,ic(r,"outputLen"),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}clone(){return this._cloneInto()}keccak(){cc(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let n=0;n<10;n++)r[n]=e[n]^e[n+10]^e[n+20]^e[n+30]^e[n+40];for(let n=0;n<10;n+=2){const t=(n+8)%10,i=(n+2)%10,o=r[i],s=r[i+1],a=Tc(o,s,1)^r[t],u=xc(o,s,1)^r[t+1];for(let r=0;r<50;r+=10)e[n+r]^=a,e[n+r+1]^=u}let t=e[2],i=e[3];for(let r=0;r<24;r++){const n=_c[r],o=Tc(t,i,n),s=xc(t,i,n),a=Ec[r];t=e[a],i=e[a+1],e[a]=o,e[a+1]=s}for(let n=0;n<50;n+=10){for(let t=0;t<10;t++)r[t]=e[n+t];for(let t=0;t<10;t++)e[n+t]^=~r[(t+2)%10]&r[(t+4)%10]}e[0]^=Ac[n],e[1]^=Ic[n]}ac(r)}(this.state32,this.rounds),cc(this.state32),this.posOut=0,this.pos=0}update(e){sc(this),oc(e);const{blockLen:t,state:r}=this,n=e.length;for(let i=0;i<n;){const o=Math.min(t-this.pos,n-i);for(let t=0;t<o;t++)r[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,!!(128&t)&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){sc(this,!1),oc(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,i=e.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);e.set(t.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ic(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){oc(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ac(this.state)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:o,enableXOF:s}=this;return t||=new e(r,n,i,s,o),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=n,t.outputLen=i,t.enableXOF=s,t.destroyed=this.destroyed,t}};const Bc=(e,t,r,n={})=>function(e,t={}){const r=(t,r)=>e(r).update(t).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=t=>e(t),Object.assign(r,t),Object.freeze(r)}((n={})=>new Oc(t,e,void 0===n.dkLen?r:n.dkLen,!0),n),Pc=Bc(31,168,16,lc(11)),Uc=Bc(31,136,32,lc(12));let Lc=class extends qa{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Aa(e);const r=ja(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Ta(i)}update(e){return Ia(this),this.iHash.update(e),this}digestInto(e){Ia(this),ka(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:n,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=n,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const Nc=(e,t,r)=>new Lc(e,t).update(r).digest();function Rc(e,t,r,n){Aa(e);const i=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign(e,t)}({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:a}=i;if(Sa(o),Sa(s),Sa(a),o<1)throw new Error("iterations (c) should be >= 1");const u=Fa(t),c=Fa(r),f=new Uint8Array(s),l=Nc.create(e,u),h=l._cloneInto().update(c);return{c:o,dkLen:s,asyncTick:a,DK:f,PRF:l,PRFSalt:h}}function Cc(e,t,r,n){const{c:i,dkLen:o,DK:s,PRF:a,PRFSalt:u}=Rc(e,t,r,n);let c;const f=new Uint8Array(4),l=xa(f),h=new Uint8Array(a.outputLen);for(let p=1,d=0;d<o;p++,d+=a.outputLen){const e=s.subarray(d,d+a.outputLen);l.setInt32(0,p,!1),(c=u._cloneInto(c)).update(f).digestInto(h),e.set(h.subarray(0,e.length));for(let t=1;t<i;t++){a._cloneInto(c).update(h).digestInto(h);for(let t=0;t<e.length;t++)e[t]^=h[t]}}return function(e,t,r,n,i){return e.destroy(),t.destroy(),n&&n.destroy(),Ta(i),r}(a,u,s,c,h)}Nc.create=(e,t)=>new Lc(e,t);const Hc=Au;var Kc,zc={};function Mc(){if(Kc)return zc;Kc=1,Object.defineProperty(zc,"__esModule",{value:!0}),zc.pbkdf2=function(e,i,o,s){const{c:a,dkLen:u,DK:c,PRF:f,PRFSalt:l}=r(e,i,o,s);let h;const p=new Uint8Array(4),d=(0,t.createView)(p),y=new Uint8Array(f.outputLen);for(let t=1,r=0;r<u;t++,r+=f.outputLen){const e=c.subarray(r,r+f.outputLen);d.setInt32(0,t,!1),(h=l._cloneInto(h)).update(p).digestInto(y),e.set(y.subarray(0,e.length));for(let t=1;t<a;t++){f._cloneInto(h).update(y).digestInto(y);for(let t=0;t<e.length;t++)e[t]^=y[t]}}return n(f,l,c,h,y)},zc.pbkdf2Async=async function(e,i,o,s){const{c:a,dkLen:u,asyncTick:c,DK:f,PRF:l,PRFSalt:h}=r(e,i,o,s);let p;const d=new Uint8Array(4),y=(0,t.createView)(d),g=new Uint8Array(l.outputLen);for(let r=1,n=0;n<u;r++,n+=l.outputLen){const e=f.subarray(n,n+l.outputLen);y.setInt32(0,r,!1),(p=h._cloneInto(p)).update(d).digestInto(g),e.set(g.subarray(0,e.length)),await(0,t.asyncLoop)(a-1,c,()=>{l._cloneInto(p).update(g).digestInto(g);for(let t=0;t<e.length;t++)e[t]^=g[t]})}return n(l,h,f,p,g)};const e=Vu(),t=Ru();function r(r,n,i,o){(0,t.ahash)(r);const s=(0,t.checkOpts)({dkLen:32,asyncTick:10},o),{c:a,dkLen:u,asyncTick:c}=s;if((0,t.anumber)(a),(0,t.anumber)(u),(0,t.anumber)(c),a<1)throw new Error("iterations (c) should be >= 1");const f=(0,t.kdfInputToBytes)(n),l=(0,t.kdfInputToBytes)(i),h=new Uint8Array(u),p=e.hmac.create(r,f),d=p._cloneInto().update(l);return{c:a,dkLen:u,asyncTick:c,DK:h,PRF:p,PRFSalt:d}}function n(e,r,n,i,o){return e.destroy(),r.destroy(),i&&i.destroy(),(0,t.clean)(o),n}return zc}var Dc,jc={},Fc={},Vc={},qc={};function Wc(){return Dc||(Dc=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.notImplemented=e.bitMask=e.utf8ToBytes=e.randomBytes=e.isBytes=e.hexToBytes=e.concatBytes=e.bytesToUtf8=e.bytesToHex=e.anumber=e.abytes=void 0,e.abool=function(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)},e._abool2=function(e,t=""){if("boolean"!=typeof e){throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e)}return e},e._abytes2=function(e,r,n=""){const i=(0,t.isBytes)(e),o=e?.length,s=void 0!==r;if(!i||s&&o!==r){throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(s?` of length ${r}`:"")+", got "+(i?`length=${o}`:"type="+typeof e))}return e},e.numberToHexUnpadded=o,e.hexToNumber=s,e.bytesToNumberBE=function(e){return s((0,t.bytesToHex)(e))},e.bytesToNumberLE=function(e){return(0,t.abytes)(e),s((0,t.bytesToHex)(Uint8Array.from(e).reverse()))},e.numberToBytesBE=a,e.numberToBytesLE=function(e,t){return a(e,t).reverse()},e.numberToVarBytesBE=function(e){return(0,t.hexToBytes)(o(e))},e.ensureBytes=function(e,r,n){let i;if("string"==typeof r)try{i=(0,t.hexToBytes)(r)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else{if(!(0,t.isBytes)(r))throw new Error(e+" must be hex string or Uint8Array");i=Uint8Array.from(r)}const o=i.length;if("number"==typeof n&&o!==n)throw new Error(e+" of length "+n+" expected, got "+o);return i},e.equalBytes=function(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r},e.copyBytes=function(e){return Uint8Array.from(e)},e.asciiToBytes=function(e){return Uint8Array.from(e,(t,r)=>{const n=t.charCodeAt(0);if(1!==t.length||n>127)throw new Error(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})},e.inRange=c,e.aInRange=function(e,t,r,n){if(!c(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)},e.bitLen=function(e){let t;for(t=0;e>n;e>>=i,t+=1);return t},e.bitGet=function(e,t){return e>>BigInt(t)&i},e.bitSet=function(e,t,r){return e|(r?i:n)<<BigInt(t)},e.createHmacDrbg=function(e,r,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof r||r<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const i=e=>new Uint8Array(e),o=e=>Uint8Array.of(e);let s=i(e),a=i(e),u=0;const c=()=>{s.fill(1),a.fill(0),u=0},f=(...e)=>n(a,s,...e),l=(e=i(0))=>{a=f(o(0),e),s=f(),0!==e.length&&(a=f(o(1),e),s=f())},h=()=>{if(u++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<r;){s=f();const t=s.slice();n.push(t),e+=s.length}return(0,t.concatBytes)(...n)};return(e,t)=>{let r;for(c(),l(e);!(r=t(h()));)l();return c(),r}},e.validateObject=function(e,t,r={}){const n=(t,r,n)=>{const i=f[r];if("function"!=typeof i)throw new Error("invalid validator function");const o=e[t];if(!(n&&void 0===o||i(o,e)))throw new Error("param "+String(t)+" is invalid. Expected "+r+", got "+o)};for(const[i,o]of Object.entries(t))n(i,o,!1);for(const[i,o]of Object.entries(r))n(i,o,!0);return e},e.isHash=function(e){return"function"==typeof e&&Number.isSafeInteger(e.outputLen)},e._validateObject=function(e,t,r={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function n(t,r,n){const i=e[t];if(n&&void 0===i)return;const o=typeof i;if(o!==r||null===i)throw new Error(`param "${t}" is invalid: expected ${r}, got ${o}`)}Object.entries(t).forEach(([e,t])=>n(e,t,!1)),Object.entries(r).forEach(([e,t])=>n(e,t,!0))},e.memoized=function(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(void 0!==i)return i;const o=e(r,...n);return t.set(r,o),o}};const t=Ru();var r=Ru();Object.defineProperty(e,"abytes",{enumerable:!0,get:function(){return r.abytes}}),Object.defineProperty(e,"anumber",{enumerable:!0,get:function(){return r.anumber}}),Object.defineProperty(e,"bytesToHex",{enumerable:!0,get:function(){return r.bytesToHex}}),Object.defineProperty(e,"bytesToUtf8",{enumerable:!0,get:function(){return r.bytesToUtf8}}),Object.defineProperty(e,"concatBytes",{enumerable:!0,get:function(){return r.concatBytes}}),Object.defineProperty(e,"hexToBytes",{enumerable:!0,get:function(){return r.hexToBytes}}),Object.defineProperty(e,"isBytes",{enumerable:!0,get:function(){return r.isBytes}}),Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return r.randomBytes}}),Object.defineProperty(e,"utf8ToBytes",{enumerable:!0,get:function(){return r.utf8ToBytes}});const n=BigInt(0),i=BigInt(1);function o(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function s(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?n:BigInt("0x"+e)}function a(e,r){return(0,t.hexToBytes)(e.toString(16).padStart(2*r,"0"))}const u=e=>"bigint"==typeof e&&n<=e;function c(e,t,r){return u(e)&&u(t)&&u(r)&&t<=e&&e<r}e.bitMask=e=>(i<<BigInt(e))-i;const f={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||(0,t.isBytes)(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};e.notImplemented=()=>{throw new Error("not implemented")}}(qc)),qc}var $c,Gc,Xc,Yc,Zc={},Qc={};function Jc(){if($c)return Qc;$c=1,Object.defineProperty(Qc,"__esModule",{value:!0}),Qc.isNegativeLE=void 0,Qc.mod=l,Qc.pow=function(e,t,r){return w(S(r),e,t)},Qc.pow2=function(e,r,n){let i=e;for(;r-- >t;)i*=i,i%=n;return i},Qc.invert=h,Qc.tonelliShanks=g,Qc.FpSqrt=m,Qc.validateField=function(t){const r=b.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"});return(0,e._validateObject)(t,r),t},Qc.FpPow=w,Qc.FpInvertBatch=v,Qc.FpDiv=function(e,t,r){return e.mul(t,"bigint"==typeof r?h(r,e.ORDER):e.inv(r))},Qc.FpLegendre=E,Qc.FpIsSquare=function(e,t){return 1===E(e,t)},Qc.nLength=_,Qc.Field=S,Qc.FpSqrtOdd=function(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?r:e.neg(r)},Qc.FpSqrtEven=function(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?e.neg(r):r},Qc.hashToPrivateScalar=function(t,n,i=!1){const o=(t=(0,e.ensureBytes)("privateHash",t)).length,s=_(n).nByteLength+8;if(s<24||o<s||o>1024)throw new Error("hashToPrivateScalar: expected "+s+"-1024 bytes of input, got "+o);return l(i?(0,e.bytesToNumberLE)(t):(0,e.bytesToNumberBE)(t),n-r)+r},Qc.getFieldBytesLength=k,Qc.getMinHashLength=A,Qc.mapHashToField=function(t,n,i=!1){const o=t.length,s=k(n),a=A(n);if(o<16||o<a||o>1024)throw new Error("expected "+a+"-1024 bytes of input, got "+o);const u=l(i?(0,e.bytesToNumberLE)(t):(0,e.bytesToNumberBE)(t),n-r)+r;return i?(0,e.numberToBytesLE)(u,s):(0,e.numberToBytesBE)(u,s)};const e=Wc(),t=BigInt(0),r=BigInt(1),n=BigInt(2),i=BigInt(3),o=BigInt(4),s=BigInt(5),a=BigInt(7),u=BigInt(8),c=BigInt(9),f=BigInt(16);function l(e,r){const n=e%r;return n>=t?n:r+n}function h(e,n){if(e===t)throw new Error("invert: expected non-zero number");if(n<=t)throw new Error("invert: expected positive modulus, got "+n);let i=l(e,n),o=n,s=t,a=r;for(;i!==t;){const e=o%i,t=s-a*(o/i);o=i,i=e,s=a,a=t}if(o!==r)throw new Error("invert: does not exist");return l(s,n)}function p(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function d(e,t){const n=(e.ORDER+r)/o,i=e.pow(t,n);return p(e,i,t),i}function y(e,t){const r=(e.ORDER-s)/u,i=e.mul(t,n),o=e.pow(i,r),a=e.mul(t,o),c=e.mul(e.mul(a,n),o),f=e.mul(a,e.sub(c,e.ONE));return p(e,f,t),f}function g(e){if(e<i)throw new Error("sqrt is not defined for small field");let o=e-r,s=0;for(;o%n===t;)o/=n,s++;let a=n;const u=S(e);for(;1===E(u,a);)if(a++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===s)return d;let c=u.pow(a,o);const f=(o+r)/n;return function(e,t){if(e.is0(t))return t;if(1!==E(e,t))throw new Error("Cannot find square root");let n=s,i=e.mul(e.ONE,c),a=e.pow(t,o),u=e.pow(t,f);for(;!e.eql(a,e.ONE);){if(e.is0(a))return e.ZERO;let t=1,o=e.sqr(a);for(;!e.eql(o,e.ONE);)if(t++,o=e.sqr(o),t===n)throw new Error("Cannot find square root");const s=r<<BigInt(n-t-1),c=e.pow(i,s);n=t,i=e.sqr(c),a=e.mul(a,i),u=e.mul(u,c)}return u}}function m(e){return e%o===i?d:e%u===s?y:e%f===c?function(e){const t=S(e),r=g(e),n=r(t,t.neg(t.ONE)),i=r(t,n),o=r(t,t.neg(n)),s=(e+a)/f;return(e,t)=>{let r=e.pow(t,s),a=e.mul(r,n);const u=e.mul(r,i),c=e.mul(r,o),f=e.eql(e.sqr(a),t),l=e.eql(e.sqr(u),t);r=e.cmov(r,a,f),a=e.cmov(c,u,l);const h=e.eql(e.sqr(a),t),d=e.cmov(r,a,h);return p(e,d,t),d}}(e):g(e)}Qc.isNegativeLE=(e,t)=>(l(e,t)&r)===r;const b=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function w(e,n,i){if(i<t)throw new Error("invalid exponent, negatives unsupported");if(i===t)return e.ONE;if(i===r)return n;let o=e.ONE,s=n;for(;i>t;)i&r&&(o=e.mul(o,s)),s=e.sqr(s),i>>=r;return o}function v(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),i=t.reduce((t,r,i)=>e.is0(r)?t:(n[i]=t,e.mul(t,r)),e.ONE),o=e.inv(i);return t.reduceRight((t,r,i)=>e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r)),o),n}function E(e,t){const i=(e.ORDER-r)/n,o=e.pow(t,i),s=e.eql(o,e.ONE),a=e.eql(o,e.ZERO),u=e.eql(o,e.neg(e.ONE));if(!s&&!a&&!u)throw new Error("invalid Legendre symbol result");return s?1:a?0:-1}function _(t,r){void 0!==r&&(0,e.anumber)(r);const n=void 0!==r?r:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function S(n,i,o=!1,s={}){if(n<=t)throw new Error("invalid field: expected ORDER > 0, got "+n);let a,u,c,f=!1;if("object"==typeof i&&null!=i){if(s.sqrt||o)throw new Error("cannot specify opts in two arguments");const e=i;e.BITS&&(a=e.BITS),e.sqrt&&(u=e.sqrt),"boolean"==typeof e.isLE&&(o=e.isLE),"boolean"==typeof e.modFromBytes&&(f=e.modFromBytes),c=e.allowedLengths}else"number"==typeof i&&(a=i),s.sqrt&&(u=s.sqrt);const{nBitLength:p,nByteLength:d}=_(n,a);if(d>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y;const g=Object.freeze({ORDER:n,isLE:o,BITS:p,BYTES:d,MASK:(0,e.bitMask)(p),ZERO:t,ONE:r,allowedLengths:c,create:e=>l(e,n),isValid:e=>{if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return t<=e&&e<n},is0:e=>e===t,isValidNot0:e=>!g.is0(e)&&g.isValid(e),isOdd:e=>(e&r)===r,neg:e=>l(-e,n),eql:(e,t)=>e===t,sqr:e=>l(e*e,n),add:(e,t)=>l(e+t,n),sub:(e,t)=>l(e-t,n),mul:(e,t)=>l(e*t,n),pow:(e,t)=>w(g,e,t),div:(e,t)=>l(e*h(t,n),n),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:e=>h(e,n),sqrt:u||(e=>(y||(y=m(n)),y(g,e))),toBytes:t=>o?(0,e.numberToBytesLE)(t,d):(0,e.numberToBytesBE)(t,d),fromBytes:(t,r=!0)=>{if(c){if(!c.includes(t.length)||t.length>d)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+t.length);const e=new Uint8Array(d);e.set(t,o?0:e.length-t.length),t=e}if(t.length!==d)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+t.length);let i=o?(0,e.bytesToNumberLE)(t):(0,e.bytesToNumberBE)(t);if(f&&(i=l(i,n)),!r&&!g.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>v(g,e),cmov:(e,t,r)=>r?t:e});return Object.freeze(g)}function k(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function A(e){const t=k(e);return t+Math.ceil(t/2)}return Qc}function ef(){if(Gc)return Zc;Gc=1,Object.defineProperty(Zc,"__esModule",{value:!0}),Zc.wNAF=void 0,Zc.negateCt=i,Zc.normalizeZ=function(e,r){const n=(0,t.FpInvertBatch)(e.Fp,r.map(e=>e.Z));return r.map((t,r)=>e.fromAffine(t.toAffine(n[r])))},Zc.mulEndoUnsafe=function(e,t,i,o){let s=t,a=e.ZERO,u=e.ZERO;for(;i>r||o>r;)i&n&&(a=a.add(s)),o&n&&(u=u.add(s)),s=s.double(),i>>=n,o>>=n;return{p1:a,p2:u}},Zc.pippenger=function(t,r,n,i){u(n,t),c(i,r);const o=n.length,s=i.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");const a=t.ZERO,f=(0,e.bitLen)(BigInt(o));let l=1;f>12?l=f-3:f>4?l=f-2:f>0&&(l=2);const h=(0,e.bitMask)(l),p=new Array(Number(h)+1).fill(a),d=Math.floor((r.BITS-1)/l)*l;let y=a;for(let e=d;e>=0;e-=l){p.fill(a);for(let r=0;r<s;r++){const t=i[r],o=Number(t>>BigInt(e)&h);p[o]=p[o].add(n[r])}let t=a;for(let e=p.length-1,r=a;e>0;e--)r=r.add(p[e]),t=t.add(r);if(y=y.add(t),0!==e)for(let e=0;e<l;e++)y=y.double()}return y},Zc.precomputeMSMUnsafe=function(t,r,n,i){o(i,r.BITS),u(n,t);const s=t.ZERO,a=2**i-1,f=Math.ceil(r.BITS/i),l=(0,e.bitMask)(i),h=n.map(e=>{const t=[];for(let r=0,n=e;r<a;r++)t.push(n),n=n.add(e);return t});return e=>{if(c(e,r),e.length>n.length)throw new Error("array of scalars must be smaller than array of points");let t=s;for(let r=0;r<f;r++){if(t!==s)for(let e=0;e<i;e++)t=t.double();const n=BigInt(f*i-(r+1)*i);for(let r=0;r<e.length;r++){const i=e[r],o=Number(i>>n&l);o&&(t=t.add(h[r][o-1]))}}return t}},Zc.validateBasic=function(r){return(0,t.validateField)(r.Fp),(0,e.validateObject)(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(r.n,r.nBitLength),...r,p:r.Fp.ORDER})},Zc._createCurveFields=function(e,t,n={},i){if(void 0===i&&(i="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const u of["p","n","h"]){const e=t[u];if(!("bigint"==typeof e&&e>r))throw new Error(`CURVE.${u} must be positive bigint`)}const o=d(t.p,n.Fp,i),s=d(t.n,n.Fn,i),a=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const r of a)if(!o.isValid(t[r]))throw new Error(`CURVE.${r} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:s}};const e=Wc(),t=Jc(),r=BigInt(0),n=BigInt(1);function i(e,t){const r=t.negate();return e?r:t}function o(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function s(t,r){o(t,r);const n=2**t;return{windows:Math.ceil(r/t)+1,windowSize:2**(t-1),mask:(0,e.bitMask)(t),maxNumber:n,shiftBy:BigInt(t)}}function a(e,t,r){const{windowSize:i,mask:o,maxNumber:s,shiftBy:a}=r;let u=Number(e&o),c=e>>a;u>i&&(u-=s,c+=n);const f=t*i;return{nextN:c,offset:f+Math.abs(u)-1,isZero:0===u,isNeg:u<0,isNegF:t%2!=0,offsetF:f}}function u(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)})}function c(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,r)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+r)})}const f=new WeakMap,l=new WeakMap;function h(e){return l.get(e)||1}function p(e){if(e!==r)throw new Error("invalid wNAF")}function d(e,r,n){if(r){if(r.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(r),r}return(0,t.Field)(e,{isLE:n})}return Zc.wNAF=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,i=this.ZERO){let o=e;for(;t>r;)t&n&&(i=i.add(o)),o=o.double(),t>>=n;return i}precomputeWindow(e,t){const{windows:r,windowSize:n}=s(t,this.bits),i=[];let o=e,a=o;for(let s=0;s<r;s++){a=o,i.push(a);for(let e=1;e<n;e++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let n=this.ZERO,o=this.BASE;const u=s(e,this.bits);for(let s=0;s<u.windows;s++){const{nextN:e,offset:c,isZero:f,isNeg:l,isNegF:h,offsetF:p}=a(r,s,u);r=e,f?o=o.add(i(h,t[p])):n=n.add(i(l,t[c]))}return p(r),{p:n,f:o}}wNAFUnsafe(e,t,n,i=this.ZERO){const o=s(e,this.bits);for(let s=0;s<o.windows&&n!==r;s++){const{nextN:e,offset:r,isZero:u,isNeg:c}=a(n,s,o);if(n=e,!u){const e=t[r];i=i.add(c?e.negate():e)}}return p(n),i}getPrecomputes(e,t,r){let n=f.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&("function"==typeof r&&(n=r(n)),f.set(t,n))),n}cached(e,t,r){const n=h(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)}unsafe(e,t,r,n){const i=h(e);return 1===i?this._unsafeLadder(e,t,n):this.wNAFUnsafe(i,this.getPrecomputes(i,e,r),t,n)}createCache(e,t){o(t,this.bits),l.set(e,t),f.delete(e)}hasCache(e){return 1!==h(e)}},Zc}function tf(){return Xc||(Xc=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=a,e._normFnElement=g,e.weierstrassN=m,e.SWUFpSqrtRatio=w,e.mapToCurveSimpleSWU=function(e,t){(0,o.validateField)(e);const{A:r,B:n,Z:i}=t;if(!e.isValid(r)||!e.isValid(n)||!e.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");const s=w(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return t=>{let a,u,c,f,l,h,p,d;a=e.sqr(t),a=e.mul(a,i),u=e.sqr(a),u=e.add(u,a),c=e.add(u,e.ONE),c=e.mul(c,n),f=e.cmov(i,e.neg(u),!e.eql(u,e.ZERO)),f=e.mul(f,r),u=e.sqr(c),h=e.sqr(f),l=e.mul(h,r),u=e.add(u,l),u=e.mul(u,c),h=e.mul(h,f),l=e.mul(h,n),u=e.add(u,l),p=e.mul(a,c);const{isValid:y,value:g}=s(u,h);d=e.mul(a,t),d=e.mul(d,g),p=e.cmov(p,c,y),d=e.cmov(d,g,y);const m=e.isOdd(t)===e.isOdd(d);d=e.cmov(e.neg(d),d,m);const b=(0,o.FpInvertBatch)(e,[f],!0)[0];return p=e.mul(p,b),{x:p,y:d}}},e.ecdh=E,e.ecdsa=_,e.weierstrassPoints=function(e){const{CURVE:t,curveOpts:r}=S(e),i=m(t,r);return function(e,t){const{Fp:r,Fn:i}=t;function o(e){return(0,n.inRange)(e,h,i.ORDER)}const s=k(r,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:e=>g(i,e),weierstrassEquation:s,isWithinCurveOrder:o})}(e,i)},e._legacyHelperEquat=k,e.weierstrass=function(e){const{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:i}=function(e){const{CURVE:t,curveOpts:r}=S(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}(e),s=m(t,r),a=_(s,n,i);return function(e,t){const r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,(0,o.nLength)(r.Fn.ORDER,r.Fn.BITS))})}(e,a)};const t=Vu(),r=Ru(),n=Wc(),i=ef(),o=Jc(),s=(e,t)=>(e+(e>=0?t:-t)/p)/t;function a(e,t,r){const[[i,o],[a,u]]=t,c=s(u*e,r),f=s(-o*e,r);let p=e-c*i-f*a,d=-c*o-f*u;const y=p<l,g=d<l;y&&(p=-p),g&&(d=-d);const m=(0,n.bitMask)(Math.ceil((0,n.bitLen)(r)/2))+h;if(p<l||p>=m||d<l||d>=m)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:y,k1:p,k2neg:g,k2:d}}function u(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function c(e,t){const r={};for(let n of Object.keys(t))r[n]=void 0===e[n]?t[n]:e[n];return(0,n._abool2)(r.lowS,"lowS"),(0,n._abool2)(r.prehash,"prehash"),void 0!==r.format&&u(r.format),r}class f extends Error{constructor(e=""){super(e)}}e.DERErr=f,e.DER={Err:f,_tlv:{encode:(t,r)=>{const{Err:i}=e.DER;if(t<0||t>256)throw new i("tlv.encode: wrong tag");if(1&r.length)throw new i("tlv.encode: unpadded data");const o=r.length/2,s=(0,n.numberToHexUnpadded)(o);if(s.length/2&128)throw new i("tlv.encode: long form length too big");const a=o>127?(0,n.numberToHexUnpadded)(s.length/2|128):"";return(0,n.numberToHexUnpadded)(t)+a+s+r},decode(t,r){const{Err:n}=e.DER;let i=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(r.length<2||r[i++]!==t)throw new n("tlv.decode: wrong tlv");const o=r[i++];let s=0;if(!!(128&o)){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const t=r.subarray(i,i+e);if(t.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===t[0])throw new n("tlv.decode(long): zero leftmost byte");for(const r of t)s=s<<8|r;if(i+=e,s<128)throw new n("tlv.decode(long): not minimal encoding")}else s=o;const a=r.subarray(i,i+s);if(a.length!==s)throw new n("tlv.decode: wrong value length");return{v:a,l:r.subarray(i+s)}}},_int:{encode(t){const{Err:r}=e.DER;if(t<l)throw new r("integer: negative integers are not allowed");let i=(0,n.numberToHexUnpadded)(t);if(8&Number.parseInt(i[0],16)&&(i="00"+i),1&i.length)throw new r("unexpected DER parsing assertion: unpadded hex");return i},decode(t){const{Err:r}=e.DER;if(128&t[0])throw new r("invalid signature integer: negative");if(0===t[0]&&!(128&t[1]))throw new r("invalid signature integer: unnecessary leading zero");return(0,n.bytesToNumberBE)(t)}},toSig(t){const{Err:r,_int:i,_tlv:o}=e.DER,s=(0,n.ensureBytes)("signature",t),{v:a,l:u}=o.decode(48,s);if(u.length)throw new r("invalid signature: left bytes after parsing");const{v:c,l:f}=o.decode(2,a),{v:l,l:h}=o.decode(2,f);if(h.length)throw new r("invalid signature: left bytes after parsing");return{r:i.decode(c),s:i.decode(l)}},hexFromSig(t){const{_tlv:r,_int:n}=e.DER,i=r.encode(2,n.encode(t.r))+r.encode(2,n.encode(t.s));return r.encode(48,i)}};const l=BigInt(0),h=BigInt(1),p=BigInt(2),d=BigInt(3),y=BigInt(4);function g(e,t){const{BYTES:r}=e;let i;if("bigint"==typeof t)i=t;else{let o=(0,n.ensureBytes)("private key",t);try{i=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}function m(e,t={}){const r=(0,i._createCurveFields)("weierstrass",e,t),{Fp:o,Fn:s}=r;let u=r.CURVE;const{h:c,n:f}=u;(0,n._validateObject)(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:p}=t;if(p&&(!o.is0(u.a)||"bigint"!=typeof p.beta||!Array.isArray(p.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const m=v(o,s);function w(){if(!o.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const E=t.toBytes||function(e,t,r){const{x:i,y:s}=t.toAffine(),a=o.toBytes(i);if((0,n._abool2)(r,"isCompressed"),r){w();const e=!o.isOdd(s);return(0,n.concatBytes)(b(e),a)}return(0,n.concatBytes)(Uint8Array.of(4),a,o.toBytes(s))},_=t.fromBytes||function(e){(0,n._abytes2)(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:r}=m,i=e.length,s=e[0],a=e.subarray(1);if(i!==t||2!==s&&3!==s){if(i===r&&4===s){const e=o.BYTES,t=o.fromBytes(a.subarray(0,e)),r=o.fromBytes(a.subarray(e,2*e));if(!k(t,r))throw new Error("bad point: is not on curve");return{x:t,y:r}}throw new Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${r}`)}{const e=o.fromBytes(a);if(!o.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=S(e);let r;try{r=o.sqrt(t)}catch(u){const e=u instanceof Error?": "+u.message:"";throw new Error("bad point: is not on curve, sqrt error"+e)}w();return!(1&~s)!==o.isOdd(r)&&(r=o.neg(r)),{x:e,y:r}}};function S(e){const t=o.sqr(e),r=o.mul(t,e);return o.add(o.add(r,o.mul(e,u.a)),u.b)}function k(e,t){const r=o.sqr(t),n=S(e);return o.eql(r,n)}if(!k(u.Gx,u.Gy))throw new Error("bad curve params: generator point");const A=o.mul(o.pow(u.a,d),y),I=o.mul(o.sqr(u.b),BigInt(27));if(o.is0(o.add(A,I)))throw new Error("bad curve params: a or b");function T(e,t,r=!1){if(!o.isValid(t)||r&&o.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function x(e){if(!(e instanceof L))throw new Error("ProjectivePoint expected")}function O(e){if(!p||!p.basises)throw new Error("no endo");return a(e,p.basises,s.ORDER)}const B=(0,n.memoized)((e,t)=>{const{X:r,Y:n,Z:i}=e;if(o.eql(i,o.ONE))return{x:r,y:n};const s=e.is0();null==t&&(t=s?o.ONE:o.inv(i));const a=o.mul(r,t),u=o.mul(n,t),c=o.mul(i,t);if(s)return{x:o.ZERO,y:o.ZERO};if(!o.eql(c,o.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),P=(0,n.memoized)(e=>{if(e.is0()){if(t.allowInfinityPoint&&!o.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:n}=e.toAffine();if(!o.isValid(r)||!o.isValid(n))throw new Error("bad point: x or y not field elements");if(!k(r,n))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function U(e,t,r,n,s){return r=new L(o.mul(r.X,e),r.Y,r.Z),t=(0,i.negateCt)(n,t),r=(0,i.negateCt)(s,r),t.add(r)}class L{constructor(e,t,r){this.X=T("x",e),this.Y=T("y",t,!0),this.Z=T("z",r),Object.freeze(this)}static CURVE(){return u}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!o.isValid(t)||!o.isValid(r))throw new Error("invalid affine point");if(e instanceof L)throw new Error("projective point not allowed");return o.is0(t)&&o.is0(r)?L.ZERO:new L(t,r,o.ONE)}static fromBytes(e){const t=L.fromAffine(_((0,n._abytes2)(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return L.fromBytes((0,n.ensureBytes)("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return R.createCache(this,e),t||this.multiply(d),this}assertValidity(){P(this)}hasEvenY(){const{y:e}=this.toAffine();if(!o.isOdd)throw new Error("Field doesn't support isOdd");return!o.isOdd(e)}equals(e){x(e);const{X:t,Y:r,Z:n}=this,{X:i,Y:s,Z:a}=e,u=o.eql(o.mul(t,a),o.mul(i,n)),c=o.eql(o.mul(r,a),o.mul(s,n));return u&&c}negate(){return new L(this.X,o.neg(this.Y),this.Z)}double(){const{a:e,b:t}=u,r=o.mul(t,d),{X:n,Y:i,Z:s}=this;let a=o.ZERO,c=o.ZERO,f=o.ZERO,l=o.mul(n,n),h=o.mul(i,i),p=o.mul(s,s),y=o.mul(n,i);return y=o.add(y,y),f=o.mul(n,s),f=o.add(f,f),a=o.mul(e,f),c=o.mul(r,p),c=o.add(a,c),a=o.sub(h,c),c=o.add(h,c),c=o.mul(a,c),a=o.mul(y,a),f=o.mul(r,f),p=o.mul(e,p),y=o.sub(l,p),y=o.mul(e,y),y=o.add(y,f),f=o.add(l,l),l=o.add(f,l),l=o.add(l,p),l=o.mul(l,y),c=o.add(c,l),p=o.mul(i,s),p=o.add(p,p),l=o.mul(p,y),a=o.sub(a,l),f=o.mul(p,h),f=o.add(f,f),f=o.add(f,f),new L(a,c,f)}add(e){x(e);const{X:t,Y:r,Z:n}=this,{X:i,Y:s,Z:a}=e;let c=o.ZERO,f=o.ZERO,l=o.ZERO;const h=u.a,p=o.mul(u.b,d);let y=o.mul(t,i),g=o.mul(r,s),m=o.mul(n,a),b=o.add(t,r),w=o.add(i,s);b=o.mul(b,w),w=o.add(y,g),b=o.sub(b,w),w=o.add(t,n);let v=o.add(i,a);return w=o.mul(w,v),v=o.add(y,m),w=o.sub(w,v),v=o.add(r,n),c=o.add(s,a),v=o.mul(v,c),c=o.add(g,m),v=o.sub(v,c),l=o.mul(h,w),c=o.mul(p,m),l=o.add(c,l),c=o.sub(g,l),l=o.add(g,l),f=o.mul(c,l),g=o.add(y,y),g=o.add(g,y),m=o.mul(h,m),w=o.mul(p,w),g=o.add(g,m),m=o.sub(y,m),m=o.mul(h,m),w=o.add(w,m),y=o.mul(g,w),f=o.add(f,y),y=o.mul(v,w),c=o.mul(b,c),c=o.sub(c,y),y=o.mul(b,g),l=o.mul(v,l),l=o.add(l,y),new L(c,f,l)}subtract(e){return this.add(e.negate())}is0(){return this.equals(L.ZERO)}multiply(e){const{endo:r}=t;if(!s.isValidNot0(e))throw new Error("invalid scalar: out of range");let n,o;const a=e=>R.cached(this,e,e=>(0,i.normalizeZ)(L,e));if(r){const{k1neg:t,k1:i,k2neg:s,k2:u}=O(e),{p:c,f:f}=a(i),{p:l,f:h}=a(u);o=f.add(h),n=U(r.beta,c,l,t,s)}else{const{p:t,f:r}=a(e);n=t,o=r}return(0,i.normalizeZ)(L,[n,o])[0]}multiplyUnsafe(e){const{endo:r}=t,n=this;if(!s.isValid(e))throw new Error("invalid scalar: out of range");if(e===l||n.is0())return L.ZERO;if(e===h)return n;if(R.hasCache(this))return this.multiply(e);if(r){const{k1neg:t,k1:o,k2neg:s,k2:a}=O(e),{p1:u,p2:c}=(0,i.mulEndoUnsafe)(L,n,o,a);return U(r.beta,u,c,t,s)}return R.unsafe(n,e)}multiplyAndAddUnsafe(e,t,r){const n=this.multiplyUnsafe(t).add(e.multiplyUnsafe(r));return n.is0()?void 0:n}toAffine(e){return B(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return c===h||(e?e(L,this):R.unsafe(this,f).is0())}clearCofactor(){const{clearCofactor:e}=t;return c===h?this:e?e(L,this):this.multiplyUnsafe(c)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}toBytes(e=!0){return(0,n._abool2)(e,"isCompressed"),this.assertValidity(),E(L,this,e)}toHex(e=!0){return(0,n.bytesToHex)(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return(0,i.normalizeZ)(L,e)}static msm(e,t){return(0,i.pippenger)(L,s,e,t)}static fromPrivateKey(e){return L.BASE.multiply(g(s,e))}}L.BASE=new L(u.Gx,u.Gy,o.ONE),L.ZERO=new L(o.ZERO,o.ONE,o.ZERO),L.Fp=o,L.Fn=s;const N=s.BITS,R=new i.wNAF(L,t.endo?Math.ceil(N/2):N);return L.BASE.precompute(8),L}function b(e){return Uint8Array.of(e?2:3)}function w(e,t){const r=e.ORDER;let n=l;for(let d=r-h;d%p===l;d/=p)n+=h;const i=n,o=p<<i-h-h,s=o*p,a=(r-h)/s,u=(a-h)/p,c=s-h,f=o,g=e.pow(t,a),m=e.pow(t,(a+h)/p);let b=(t,r)=>{let n=g,o=e.pow(r,c),s=e.sqr(o);s=e.mul(s,r);let a=e.mul(t,s);a=e.pow(a,u),a=e.mul(a,o),o=e.mul(a,r),s=e.mul(a,t);let l=e.mul(s,o);a=e.pow(l,f);let d=e.eql(a,e.ONE);o=e.mul(s,m),a=e.mul(l,n),s=e.cmov(o,s,d),l=e.cmov(a,l,d);for(let u=i;u>h;u--){let t=u-p;t=p<<t-h;let r=e.pow(l,t);const i=e.eql(r,e.ONE);o=e.mul(s,n),n=e.mul(n,n),r=e.mul(l,n),s=e.cmov(o,s,i),l=e.cmov(r,l,i)}return{isValid:d,value:s}};if(e.ORDER%y===d){const r=(e.ORDER-d)/y,n=e.sqrt(e.neg(t));b=(t,i)=>{let o=e.sqr(i);const s=e.mul(t,i);o=e.mul(o,s);let a=e.pow(o,r);a=e.mul(a,s);const u=e.mul(a,n),c=e.mul(e.sqr(a),i),f=e.eql(c,t);return{isValid:f,value:e.cmov(u,a,f)}}}return b}function v(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function E(e,t={}){const{Fn:r}=e,i=t.randomBytes||n.randomBytes,s=Object.assign(v(e.Fp,r),{seed:(0,o.getMinHashLength)(r.ORDER)});function a(e){try{return!!g(r,e)}catch{return!1}}function u(e=i(s.seed)){return(0,o.mapHashToField)((0,n._abytes2)(e,s.seed,"seed"),r.ORDER)}function c(t,n=!0){return e.BASE.multiply(g(r,t)).toBytes(n)}function f(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:i,publicKey:o,publicKeyUncompressed:a}=s;if(r.allowedLengths||i===o)return;const u=(0,n.ensureBytes)("key",t).length;return u===o||u===a}return Object.freeze({getPublicKey:c,getSharedSecret:function(t,n,i=!0){if(!0===f(t))throw new Error("first arg must be private key");if(!1===f(n))throw new Error("second arg must be public key");const o=g(r,t);return e.fromHex(n).multiply(o).toBytes(i)},keygen:function(e){const t=u(e);return{secretKey:t,publicKey:c(t)}},Point:e,utils:{isValidSecretKey:a,isValidPublicKey:function(t,r){const{publicKey:n,publicKeyUncompressed:i}=s;try{const o=t.length;return!(!0===r&&o!==n||!1===r&&o!==i)&&!!e.fromBytes(t)}catch{return!1}},randomSecretKey:u,isValidPrivateKey:a,randomPrivateKey:u,normPrivateKeyToScalar:e=>g(r,e),precompute:(t=8,r=e.BASE)=>r.precompute(t,!1)},lengths:s})}function _(i,o,s={}){(0,r.ahash)(o),(0,n._validateObject)(s,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const a=s.randomBytes||n.randomBytes,f=s.hmac||((e,...r)=>(0,t.hmac)(o,e,(0,n.concatBytes)(...r))),{Fp:d,Fn:y}=i,{ORDER:m,BITS:w}=y,{keygen:v,getPublicKey:_,getSharedSecret:S,utils:k,lengths:A}=E(i,s),I={prehash:!1,lowS:"boolean"==typeof s.lowS&&s.lowS,format:void 0,extraEntropy:!1},T="compact";function x(e){return e>m>>h}function O(e,t){if(!y.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class B{constructor(e,t,r){this.r=O("r",e),this.s=O("s",t),null!=r&&(this.recovery=r),Object.freeze(this)}static fromBytes(t,r=T){let i;if(function(e,t){u(t);const r=A.signature,i="compact"===t?r:"recovered"===t?r+1:void 0;(0,n._abytes2)(e,i,`${t} signature`)}(t,r),"der"===r){const{r:r,s:i}=e.DER.toSig((0,n._abytes2)(t));return new B(r,i)}"recovered"===r&&(i=t[0],r="compact",t=t.subarray(1));const o=y.BYTES,s=t.subarray(0,o),a=t.subarray(o,2*o);return new B(y.fromBytes(s),y.fromBytes(a),i)}static fromHex(e,t){return this.fromBytes((0,n.hexToBytes)(e),t)}addRecoveryBit(e){return new B(this.r,this.s,e)}recoverPublicKey(e){const t=d.ORDER,{r:r,s:o,recovery:s}=this;if(null==s||![0,1,2,3].includes(s))throw new Error("recovery id invalid");if(m*p<t&&s>1)throw new Error("recovery id is ambiguous for h>1 curve");const a=2===s||3===s?r+m:r;if(!d.isValid(a))throw new Error("recovery id 2 or 3 invalid");const u=d.toBytes(a),c=i.fromBytes((0,n.concatBytes)(b(!(1&s)),u)),f=y.inv(a),l=U((0,n.ensureBytes)("msgHash",e)),h=y.create(-l*f),g=y.create(o*f),w=i.BASE.multiplyUnsafe(h).add(c.multiplyUnsafe(g));if(w.is0())throw new Error("point at infinify");return w.assertValidity(),w}hasHighS(){return x(this.s)}toBytes(t=T){if(u(t),"der"===t)return(0,n.hexToBytes)(e.DER.hexFromSig(this));const r=y.toBytes(this.r),i=y.toBytes(this.s);if("recovered"===t){if(null==this.recovery)throw new Error("recovery bit must be present");return(0,n.concatBytes)(Uint8Array.of(this.recovery),r,i)}return(0,n.concatBytes)(r,i)}toHex(e){return(0,n.bytesToHex)(this.toBytes(e))}assertValidity(){}static fromCompact(e){return B.fromBytes((0,n.ensureBytes)("sig",e),"compact")}static fromDER(e){return B.fromBytes((0,n.ensureBytes)("sig",e),"der")}normalizeS(){return this.hasHighS()?new B(this.r,y.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,n.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,n.bytesToHex)(this.toBytes("compact"))}}const P=s.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=(0,n.bytesToNumberBE)(e),r=8*e.length-w;return r>0?t>>BigInt(r):t},U=s.bits2int_modN||function(e){return y.create(P(e))},L=(0,n.bitMask)(w);function N(e){return(0,n.aInRange)("num < 2^"+w,e,l,L),y.toBytes(e)}function R(e,t){return(0,n._abytes2)(e,void 0,"message"),t?(0,n._abytes2)(o(e),void 0,"prehashed message"):e}return Object.freeze({keygen:v,getPublicKey:_,getSharedSecret:S,utils:k,lengths:A,Point:i,sign:function(e,t,r={}){e=(0,n.ensureBytes)("message",e);const{seed:s,k2sig:u}=function(e,t,r){if(["recovered","canonical"].some(e=>e in r))throw new Error("sign() legacy options not supported");const{lowS:o,prehash:s,extraEntropy:u}=c(r,I);e=R(e,s);const f=U(e),p=g(y,t),d=[N(p),N(f)];if(null!=u&&!1!==u){const e=!0===u?a(A.secretKey):u;d.push((0,n.ensureBytes)("extraEntropy",e))}const m=(0,n.concatBytes)(...d),b=f;return{seed:m,k2sig:function(e){const t=P(e);if(!y.isValidNot0(t))return;const r=y.inv(t),n=i.BASE.multiply(t).toAffine(),s=y.create(n.x);if(s===l)return;const a=y.create(r*y.create(b+s*p));if(a===l)return;let u=(n.x===s?0:2)|Number(n.y&h),c=a;return o&&x(a)&&(c=y.neg(a),u^=1),new B(s,c,u)}}}(e,t,r);return(0,n.createHmacDrbg)(o.outputLen,y.BYTES,f)(s,u)},verify:function(t,r,o,s={}){const{lowS:a,prehash:u,format:f}=c(s,I);if(o=(0,n.ensureBytes)("publicKey",o),r=R((0,n.ensureBytes)("message",r),u),"strict"in s)throw new Error("options.strict was renamed to lowS");const l=void 0===f?function(t){let r;const i="string"==typeof t||(0,n.isBytes)(t),o=!i&&null!==t&&"object"==typeof t&&"bigint"==typeof t.r&&"bigint"==typeof t.s;if(!i&&!o)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(o)r=new B(t.r,t.s);else if(i){try{r=B.fromBytes((0,n.ensureBytes)("sig",t),"der")}catch(a){if(!(a instanceof e.DER.Err))throw a}if(!r)try{r=B.fromBytes((0,n.ensureBytes)("sig",t),"compact")}catch{return!1}}return r||!1}(t):B.fromBytes((0,n.ensureBytes)("sig",t),f);if(!1===l)return!1;try{const e=i.fromBytes(o);if(a&&l.hasHighS())return!1;const{r:t,s:n}=l,s=U(r),u=y.inv(n),c=y.create(s*u),f=y.create(t*u),h=i.BASE.multiplyUnsafe(c).add(e.multiplyUnsafe(f));return!h.is0()&&y.create(h.x)===t}catch{return!1}},recoverPublicKey:function(e,t,r={}){const{prehash:n}=c(r,I);return t=R(t,n),B.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:B,hash:o})}function S(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp;let n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:r,Fn:(0,o.Field)(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function k(e,t,r){return function(n){const i=e.sqr(n),o=e.mul(i,n);return e.add(e.add(o,e.mul(n,t)),r)}}}(Vc)),Vc}function rf(){if(Yc)return Fc;Yc=1,Object.defineProperty(Fc,"__esModule",{value:!0}),Fc.getHash=function(e){return{hash:e}},Fc.createCurve=function(t,r){const n=r=>(0,e.weierstrass)({...t,hash:r});return{...n(r),create:n}};const e=tf();return Fc}var nf,of,sf={};function af(){return nf||(nf=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=u,e.expand_message_xof=c,e.hash_to_field=f,e.isogenyMap=function(e,t){const n=t.map(e=>Array.from(e).reverse());return(t,i)=>{const[o,s,a,u]=n.map(r=>r.reduce((r,n)=>e.add(e.mul(r,t),n))),[c,f]=(0,r.FpInvertBatch)(e,[s,u],!0);return t=e.mul(o,c),i=e.mul(i,e.mul(a,f)),{x:t,y:i}}},e.createHasher=function(t,r,n){if("function"!=typeof r)throw new Error("mapToCurve() must be defined");function i(e){return t.fromAffine(r(e))}function o(e){const r=e.clearCofactor();return r.equals(t.ZERO)?t.ZERO:(r.assertValidity(),r)}return{defaults:n,hashToCurve(e,t){const r=f(e,2,Object.assign({},n,t)),s=i(r[0]),a=i(r[1]);return o(s.add(a))},encodeToCurve(e,t){const r=n.encodeDST?{DST:n.encodeDST}:{};return o(i(f(e,1,Object.assign({},n,r,t))[0]))},mapToCurve(e){if(!Array.isArray(e))throw new Error("expected array of bigints");for(const t of e)if("bigint"!=typeof t)throw new Error("expected array of bigints");return o(i(e))},hashToScalar(r,i){const o=t.Fn.ORDER;return f(r,1,Object.assign({},n,{p:o,m:1,DST:e._DST_scalar},i))[0][0]}}};const t=Wc(),r=Jc(),n=t.bytesToNumberBE;function i(e,t){if(s(e),s(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=255&e,e>>>=8;return new Uint8Array(r)}function o(e,t){const r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function s(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function a(e){if(!(0,t.isBytes)(e)&&"string"!=typeof e)throw new Error("DST must be Uint8Array or string");return"string"==typeof e?(0,t.utf8ToBytes)(e):e}function u(e,r,n,u){(0,t.abytes)(e),s(n),(r=a(r)).length>255&&(r=u((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),r)));const{outputLen:c,blockLen:f}=u,l=Math.ceil(n/c);if(n>65535||l>255)throw new Error("expand_message_xmd: invalid lenInBytes");const h=(0,t.concatBytes)(r,i(r.length,1)),p=i(0,f),d=i(n,2),y=new Array(l),g=u((0,t.concatBytes)(p,e,d,i(0,1),h));y[0]=u((0,t.concatBytes)(g,i(1,1),h));for(let s=1;s<=l;s++){const e=[o(g,y[s-1]),i(s+1,1),h];y[s]=u((0,t.concatBytes)(...e))}return(0,t.concatBytes)(...y).slice(0,n)}function c(e,r,n,o,u){if((0,t.abytes)(e),s(n),(r=a(r)).length>255){const e=Math.ceil(2*o/8);r=u.create({dkLen:e}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(r).digest()}if(n>65535||r.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return u.create({dkLen:n}).update(e).update(i(n,2)).update(r).update(i(r.length,1)).digest()}function f(e,i,o){(0,t._validateObject)(o,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:a,k:f,m:l,hash:h,expand:p,DST:d}=o;if(!(0,t.isHash)(o.hash))throw new Error("expected valid hash");(0,t.abytes)(e),s(i);const y=a.toString(2).length,g=Math.ceil((y+f)/8),m=i*l*g;let b;if("xmd"===p)b=u(e,d,m,h);else if("xof"===p)b=c(e,d,m,f,h);else{if("_internal_pass"!==p)throw new Error('expand must be "xmd" or "xof"');b=e}const w=new Array(i);for(let t=0;t<i;t++){const e=new Array(l);for(let i=0;i<l;i++){const o=g*(i+t*l),s=b.subarray(o,o+g);e[i]=(0,r.mod)(n(s),a)}w[t]=e}return w}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-")}(sf)),sf}function uf(){return of||(of=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.encodeToCurve=e.hashToCurve=e.secp256k1_hasher=e.schnorr=e.secp256k1=void 0;const t=Du(),r=Ru(),n=rf(),i=af(),o=Jc(),s=tf(),a=Wc(),u={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},c={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},f=BigInt(0),l=BigInt(1),h=BigInt(2);const p=(0,o.Field)(u.p,{sqrt:function(e){const t=u.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),a=BigInt(23),c=BigInt(44),f=BigInt(88),l=e*e*e%t,d=l*l*e%t,y=(0,o.pow2)(d,r,t)*d%t,g=(0,o.pow2)(y,r,t)*d%t,m=(0,o.pow2)(g,h,t)*l%t,b=(0,o.pow2)(m,i,t)*m%t,w=(0,o.pow2)(b,s,t)*b%t,v=(0,o.pow2)(w,c,t)*w%t,E=(0,o.pow2)(v,f,t)*v%t,_=(0,o.pow2)(E,c,t)*w%t,S=(0,o.pow2)(_,r,t)*d%t,k=(0,o.pow2)(S,a,t)*b%t,A=(0,o.pow2)(k,n,t)*l%t,I=(0,o.pow2)(A,h,t);if(!p.eql(p.sqr(I),e))throw new Error("Cannot find square root");return I}});e.secp256k1=(0,n.createCurve)({...u,Fp:p,lowS:!0,endo:c},t.sha256);const d={};function y(e,...r){let n=d[e];if(void 0===n){const r=(0,t.sha256)((0,a.utf8ToBytes)(e));n=(0,a.concatBytes)(r,r),d[e]=n}return(0,t.sha256)((0,a.concatBytes)(n,...r))}const g=e=>e.toBytes(!0).slice(1),m=e.secp256k1.Point,b=e=>e%h===f;function w(e){const{Fn:t,BASE:r}=m,n=(0,s._normFnElement)(t,e),i=r.multiply(n);return{scalar:b(i.y)?n:t.neg(n),bytes:g(i)}}function v(e){const t=p;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const r=t.create(e*e),n=t.create(r*e+BigInt(7));let i=t.sqrt(n);b(i)||(i=t.neg(i));const o=m.fromAffine({x:e,y:i});return o.assertValidity(),o}const E=a.bytesToNumberBE;function _(...e){return m.Fn.create(E(y("BIP0340/challenge",...e)))}function S(e){return w(e).bytes}function k(e,t,n=(0,r.randomBytes)(32)){const{Fn:i}=m,o=(0,a.ensureBytes)("message",e),{bytes:s,scalar:u}=w(t),c=(0,a.ensureBytes)("auxRand",n,32),f=i.toBytes(u^E(y("BIP0340/aux",c))),l=y("BIP0340/nonce",f,s,o),{bytes:h,scalar:p}=w(l),d=_(h,s,o),g=new Uint8Array(64);if(g.set(h,0),g.set(i.toBytes(i.create(p+d*u)),32),!A(g,o,s))throw new Error("sign: Invalid signature produced");return g}function A(e,t,r){const{Fn:n,BASE:i}=m,o=(0,a.ensureBytes)("signature",e,64),s=(0,a.ensureBytes)("message",t),c=(0,a.ensureBytes)("publicKey",r,32);try{const e=v(E(c)),t=E(o.subarray(0,32));if(!(0,a.inRange)(t,l,u.p))return!1;const r=E(o.subarray(32,64));if(!(0,a.inRange)(r,l,u.n))return!1;const f=_(n.toBytes(t),g(e),s),h=i.multiplyUnsafe(r).add(e.multiplyUnsafe(n.neg(f))),{x:p,y:d}=h.toAffine();return!(h.is0()||!b(d)||p!==t)}catch{return!1}}e.schnorr=(()=>{const t=(e=(0,r.randomBytes)(48))=>(0,o.mapHashToField)(e,u.n);return e.secp256k1.utils.randomSecretKey,{keygen:function(e){const r=t(e);return{secretKey:r,publicKey:S(r)}},getPublicKey:S,sign:k,verify:A,Point:m,utils:{randomSecretKey:t,randomPrivateKey:t,taggedHash:y,lift_x:v,pointToBytes:g,numberToBytesBE:a.numberToBytesBE,bytesToNumberBE:a.bytesToNumberBE,mod:o.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const I=(0,i.isogenyMap)(p,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(e=>BigInt(e)))),T=(0,s.mapToCurveSimpleSWU)(p,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:p.create(BigInt("-11"))});e.secp256k1_hasher=(0,i.createHasher)(e.secp256k1.Point,e=>{const{x:t,y:r}=T(p.create(e[0]));return I(t,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:p.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve}(jc)),jc}var cf,ff={};function lf(){if(cf)return ff;cf=1,Object.defineProperty(ff,"__esModule",{value:!0}),ff.isHash=ff.validateObject=ff.memoized=ff.notImplemented=ff.createHmacDrbg=ff.bitMask=ff.bitSet=ff.bitGet=ff.bitLen=ff.aInRange=ff.inRange=ff.asciiToBytes=ff.copyBytes=ff.equalBytes=ff.ensureBytes=ff.numberToVarBytesBE=ff.numberToBytesLE=ff.numberToBytesBE=ff.bytesToNumberLE=ff.bytesToNumberBE=ff.hexToNumber=ff.numberToHexUnpadded=ff.abool=ff.utf8ToBytes=ff.randomBytes=ff.isBytes=ff.hexToBytes=ff.concatBytes=ff.bytesToUtf8=ff.bytesToHex=ff.anumber=ff.abytes=void 0;const e=Wc();return ff.abytes=e.abytes,ff.anumber=e.anumber,ff.bytesToHex=e.bytesToHex,ff.bytesToUtf8=e.bytesToUtf8,ff.concatBytes=e.concatBytes,ff.hexToBytes=e.hexToBytes,ff.isBytes=e.isBytes,ff.randomBytes=e.randomBytes,ff.utf8ToBytes=e.utf8ToBytes,ff.abool=e.abool,ff.numberToHexUnpadded=e.numberToHexUnpadded,ff.hexToNumber=e.hexToNumber,ff.bytesToNumberBE=e.bytesToNumberBE,ff.bytesToNumberLE=e.bytesToNumberLE,ff.numberToBytesBE=e.numberToBytesBE,ff.numberToBytesLE=e.numberToBytesLE,ff.numberToVarBytesBE=e.numberToVarBytesBE,ff.ensureBytes=e.ensureBytes,ff.equalBytes=e.equalBytes,ff.copyBytes=e.copyBytes,ff.asciiToBytes=e.asciiToBytes,ff.inRange=e.inRange,ff.aInRange=e.aInRange,ff.bitLen=e.bitLen,ff.bitGet=e.bitGet,ff.bitSet=e.bitSet,ff.bitMask=e.bitMask,ff.createHmacDrbg=e.createHmacDrbg,ff.notImplemented=e.notImplemented,ff.memoized=e.memoized,ff.validateObject=e.validateObject,ff.isHash=e.isHash,ff}function hf(e){if(!Number.isSafeInteger(e)||e<0||e>4294967295)throw new Error("wrong u32 integer:"+e);return e}function pf(e){return hf(e),!(e&e-1)&&0!==e}function df(e,t){hf(e);let r=0;for(let n=0;n<t;n++,e>>>=1)r=r<<1|1&e;return r}function yf(e){return hf(e),31-Math.clz32(e)}function gf(e){const t=e.length;if(t<2||!pf(t))throw new Error("n must be a power of 2 and greater than 1. Got "+t);const r=yf(t);for(let n=0;n<t;n++){const t=df(n,r);if(n<t){const r=e[n];e[n]=e[t],e[t]=r}}return e}const mf=(e,t)=>{const{N:r,roots:n,dit:i,invertButterflies:o=!1,skipStages:s=0,brp:a=!0}=t,u=yf(r);if(!pf(r))throw new Error("FFT: Polynomial size should be power of two");const c=i!==o;return t=>{if(t.length!==r)throw new Error("FFT: wrong Polynomial length");i&&a&&gf(t);for(let a=0,f=1;a<u-s;a++){const l=i?a+1+s:u-a,h=1<<l,p=h>>1,d=r>>l;for(let s=0;s<r;s+=h)for(let a=0,u=f++;a<p;a++){const f=s+a,l=s+a+p,h=n[o?i?r-u:u:a*d],y=t[l],g=t[f];if(c){const r=e.mul(y,h);t[f]=e.add(g,r),t[l]=e.sub(g,r)}else o?(t[f]=e.add(y,g),t[l]=e.mul(e.sub(y,g),h)):(t[f]=e.add(g,y),t[l]=e.mul(e.sub(g,y),h))}}return!i&&a&&gf(t),t}},bf=BigInt(0),wf=BigInt(1);function vf(e,t=""){if("boolean"!=typeof e){throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e)}return e}function Ef(e,t,r=""){const n=_a(e),i=e?.length,o=void 0!==t;if(!n||o&&i!==t){throw new Error((r&&`"${r}" `)+"expected Uint8Array"+(o?` of length ${t}`:"")+", got "+(n?`length=${i}`:"type="+typeof e))}return e}function _f(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function Sf(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?bf:BigInt("0x"+e)}function kf(e){return Sf(Ua(e))}function Af(e){return ka(e),Sf(Ua(Uint8Array.from(e).reverse()))}function If(e,t){return Ma(e.toString(16).padStart(2*t,"0"))}function Tf(e,t){return If(e,t).reverse()}function xf(e,t,r){let n;if("string"==typeof t)try{n=Ma(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else{if(!_a(t))throw new Error(e+" must be hex string or Uint8Array");n=Uint8Array.from(t)}return n.length,n}const Of=e=>"bigint"==typeof e&&bf<=e;function Bf(e,t,r,n){if(!function(e,t,r){return Of(e)&&Of(t)&&Of(r)&&t<=e&&e<r}(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Pf(e){let t;for(t=0;e>bf;e>>=wf,t+=1);return t}const Uf=e=>(wf<<BigInt(e))-wf;function Lf(e,t,r={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function n(t,r,n){const i=e[t];if(n&&void 0===i)return;const o=typeof i;if(o!==r||null===i)throw new Error(`param "${t}" is invalid: expected ${r}, got ${o}`)}Object.entries(t).forEach(([e,t])=>n(e,t,!1)),Object.entries(r).forEach(([e,t])=>n(e,t,!0))}function Nf(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(void 0!==i)return i;const o=e(r,...n);return t.set(r,o),o}}const Rf=BigInt(0),Cf=BigInt(1),Hf=BigInt(2),Kf=BigInt(3),zf=BigInt(4),Mf=BigInt(5),Df=BigInt(7),jf=BigInt(8),Ff=BigInt(9),Vf=BigInt(16);function qf(e,t){const r=e%t;return r>=Rf?r:t+r}function Wf(e,t,r){let n=e;for(;t-- >Rf;)n*=n,n%=r;return n}function $f(e,t){if(e===Rf)throw new Error("invert: expected non-zero number");if(t<=Rf)throw new Error("invert: expected positive modulus, got "+t);let r=qf(e,t),n=t,i=Rf,o=Cf;for(;r!==Rf;){const e=n%r,t=i-o*(n/r);n=r,r=e,i=o,o=t}if(n!==Cf)throw new Error("invert: does not exist");return qf(i,t)}function Gf(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Xf(e,t){const r=(e.ORDER+Cf)/zf,n=e.pow(t,r);return Gf(e,n,t),n}function Yf(e,t){const r=(e.ORDER-Mf)/jf,n=e.mul(t,Hf),i=e.pow(n,r),o=e.mul(t,i),s=e.mul(e.mul(o,Hf),i),a=e.mul(o,e.sub(s,e.ONE));return Gf(e,a,t),a}function Zf(e){if(e<Kf)throw new Error("sqrt is not defined for small field");let t=e-Cf,r=0;for(;t%Hf===Rf;)t/=Hf,r++;let n=Hf;const i=nl(e);for(;1===tl(i,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===r)return Xf;let o=i.pow(n,t);const s=(t+Cf)/Hf;return function(e,n){if(e.is0(n))return n;if(1!==tl(e,n))throw new Error("Cannot find square root");let i=r,a=e.mul(e.ONE,o),u=e.pow(n,t),c=e.pow(n,s);for(;!e.eql(u,e.ONE);){if(e.is0(u))return e.ZERO;let t=1,r=e.sqr(u);for(;!e.eql(r,e.ONE);)if(t++,r=e.sqr(r),t===i)throw new Error("Cannot find square root");const n=Cf<<BigInt(i-t-1),o=e.pow(a,n);i=t,a=e.sqr(o),u=e.mul(u,a),c=e.mul(c,o)}return c}}function Qf(e){return e%zf===Kf?Xf:e%jf===Mf?Yf:e%Vf===Ff?function(e){const t=nl(e),r=Zf(e),n=r(t,t.neg(t.ONE)),i=r(t,n),o=r(t,t.neg(n)),s=(e+Df)/Vf;return(e,t)=>{let r=e.pow(t,s),a=e.mul(r,n);const u=e.mul(r,i),c=e.mul(r,o),f=e.eql(e.sqr(a),t),l=e.eql(e.sqr(u),t);r=e.cmov(r,a,f),a=e.cmov(c,u,l);const h=e.eql(e.sqr(a),t),p=e.cmov(r,a,h);return Gf(e,p,t),p}}(e):Zf(e)}const Jf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function el(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),i=t.reduce((t,r,i)=>e.is0(r)?t:(n[i]=t,e.mul(t,r)),e.ONE),o=e.inv(i);return t.reduceRight((t,r,i)=>e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r)),o),n}function tl(e,t){const r=(e.ORDER-Cf)/Hf,n=e.pow(t,r),i=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function rl(e,t){void 0!==t&&Sa(t);const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function nl(e,t,r=!1,n={}){if(e<=Rf)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,o,s,a=!1;if("object"==typeof t&&null!=t){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(i=e.BITS),e.sqrt&&(o=e.sqrt),"boolean"==typeof e.isLE&&(r=e.isLE),"boolean"==typeof e.modFromBytes&&(a=e.modFromBytes),s=e.allowedLengths}else"number"==typeof t&&(i=t),n.sqrt&&(o=n.sqrt);const{nBitLength:u,nByteLength:c}=rl(e,i);if(c>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const l=Object.freeze({ORDER:e,isLE:r,BITS:u,BYTES:c,MASK:Uf(u),ZERO:Rf,ONE:Cf,allowedLengths:s,create:t=>qf(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return Rf<=t&&t<e},is0:e=>e===Rf,isValidNot0:e=>!l.is0(e)&&l.isValid(e),isOdd:e=>(e&Cf)===Cf,neg:t=>qf(-t,e),eql:(e,t)=>e===t,sqr:t=>qf(t*t,e),add:(t,r)=>qf(t+r,e),sub:(t,r)=>qf(t-r,e),mul:(t,r)=>qf(t*r,e),pow:(e,t)=>function(e,t,r){if(r<Rf)throw new Error("invalid exponent, negatives unsupported");if(r===Rf)return e.ONE;if(r===Cf)return t;let n=e.ONE,i=t;for(;r>Rf;)r&Cf&&(n=e.mul(n,i)),i=e.sqr(i),r>>=Cf;return n}(l,e,t),div:(t,r)=>qf(t*$f(r,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>$f(t,e),sqrt:o||(t=>(f||(f=Qf(e)),f(l,t))),toBytes:e=>r?Tf(e,c):If(e,c),fromBytes:(t,n=!0)=>{if(s){if(!s.includes(t.length)||t.length>c)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);const e=new Uint8Array(c);e.set(t,r?0:e.length-t.length),t=e}if(t.length!==c)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+t.length);let i=r?Af(t):kf(t);if(a&&(i=qf(i,e)),!n&&!l.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>el(l,e),cmov:(e,t,r)=>r?t:e});return Object.freeze(l)}function il(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function ol(e){const t=il(e);return t+Math.ceil(t/2)}const sl=BigInt(0),al=BigInt(1);function ul(e,t){const r=t.negate();return e?r:t}function cl(e,t){const r=el(e.Fp,t.map(e=>e.Z));return t.map((t,n)=>e.fromAffine(t.toAffine(r[n])))}function fl(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ll(e,t){fl(e,t);const r=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:Uf(e),maxNumber:r,shiftBy:BigInt(e)}}function hl(e,t,r){const{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r;let a=Number(e&i),u=e>>s;a>n&&(a-=o,u+=al);const c=t*n;return{nextN:u,offset:c+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:c}}const pl=new WeakMap,dl=new WeakMap;function yl(e){return dl.get(e)||1}function gl(e){if(e!==sl)throw new Error("invalid wNAF")}let ml=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,r=this.ZERO){let n=e;for(;t>sl;)t&al&&(r=r.add(n)),n=n.double(),t>>=al;return r}precomputeWindow(e,t){const{windows:r,windowSize:n}=ll(t,this.bits),i=[];let o=e,s=o;for(let a=0;a<r;a++){s=o,i.push(s);for(let e=1;e<n;e++)s=s.add(o),i.push(s);o=s.double()}return i}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let n=this.ZERO,i=this.BASE;const o=ll(e,this.bits);for(let s=0;s<o.windows;s++){const{nextN:e,offset:a,isZero:u,isNeg:c,isNegF:f,offsetF:l}=hl(r,s,o);r=e,u?i=i.add(ul(f,t[l])):n=n.add(ul(c,t[a]))}return gl(r),{p:n,f:i}}wNAFUnsafe(e,t,r,n=this.ZERO){const i=ll(e,this.bits);for(let o=0;o<i.windows&&r!==sl;o++){const{nextN:e,offset:s,isZero:a,isNeg:u}=hl(r,o,i);if(r=e,!a){const e=t[s];n=n.add(u?e.negate():e)}}return gl(r),n}getPrecomputes(e,t,r){let n=pl.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&("function"==typeof r&&(n=r(n)),pl.set(t,n))),n}cached(e,t,r){const n=yl(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)}unsafe(e,t,r,n){const i=yl(e);return 1===i?this._unsafeLadder(e,t,n):this.wNAFUnsafe(i,this.getPrecomputes(i,e,r),t,n)}createCache(e,t){fl(t,this.bits),dl.set(e,t),pl.delete(e)}hasCache(e){return 1!==yl(e)}};function bl(e,t,r,n){(function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)})})(r,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,r)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+r)})}(n,t);const i=r.length,o=n.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,a=Pf(BigInt(i));let u=1;a>12?u=a-3:a>4?u=a-2:a>0&&(u=2);const c=Uf(u),f=new Array(Number(c)+1).fill(s);let l=s;for(let h=Math.floor((t.BITS-1)/u)*u;h>=0;h-=u){f.fill(s);for(let t=0;t<o;t++){const e=n[t],i=Number(e>>BigInt(h)&c);f[i]=f[i].add(r[t])}let e=s;for(let t=f.length-1,r=s;t>0;t--)r=r.add(f[t]),e=e.add(r);if(l=l.add(e),0!==h)for(let t=0;t<u;t++)l=l.double()}return l}function wl(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){Lf(e,Jf.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return nl(e,{isLE:r})}const vl=(e,t)=>(e+(e>=0?t:-t)/Il)/t;function El(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function _l(e,t){const r={};for(let n of Object.keys(t))r[n]=void 0===e[n]?t[n]:e[n];return vf(r.lowS,"lowS"),vf(r.prehash,"prehash"),void 0!==r.format&&El(r.format),r}const Sl={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(e,t)=>{const{Err:r}=Sl;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(1&t.length)throw new r("tlv.encode: unpadded data");const n=t.length/2,i=_f(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const o=n>127?_f(i.length/2|128):"";return _f(e)+o+i+t},decode(e,t){const{Err:r}=Sl;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const i=t[n++];let o=0;if(!!(128&i)){const e=127&i;if(!e)throw new r("tlv.decode(long): indefinite length not supported");if(e>4)throw new r("tlv.decode(long): byte length is too big");const s=t.subarray(n,n+e);if(s.length!==e)throw new r("tlv.decode: length bytes not complete");if(0===s[0])throw new r("tlv.decode(long): zero leftmost byte");for(const t of s)o=o<<8|t;if(n+=e,o<128)throw new r("tlv.decode(long): not minimal encoding")}else o=i;const s=t.subarray(n,n+o);if(s.length!==o)throw new r("tlv.decode: wrong value length");return{v:s,l:t.subarray(n+o)}}},_int:{encode(e){const{Err:t}=Sl;if(e<kl)throw new t("integer: negative integers are not allowed");let r=_f(e);if(8&Number.parseInt(r[0],16)&&(r="00"+r),1&r.length)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=Sl;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return kf(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=Sl,i=xf("signature",e),{v:o,l:s}=n.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:u}=n.decode(2,o),{v:c,l:f}=n.decode(2,u);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){const{_tlv:t,_int:r}=Sl,n=t.encode(2,r.encode(e.r))+t.encode(2,r.encode(e.s));return t.encode(48,n)}},kl=BigInt(0),Al=BigInt(1),Il=BigInt(2),Tl=BigInt(3),xl=BigInt(4);function Ol(e,t){const{BYTES:r}=e;let n;if("bigint"==typeof t)n=t;else{let i=xf("private key",t);try{n=e.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Bl(e,t={}){const r=function(e,t,r={},n){if(void 0===n&&(n="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const e=t[a];if(!("bigint"==typeof e&&e>sl))throw new Error(`CURVE.${a} must be positive bigint`)}const i=wl(t.p,r.Fp,n),o=wl(t.n,r.Fn,n),s=["Gx","Gy","a","b"];for(const a of s)if(!i.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:i,Fn:o}}("weierstrass",e,t),{Fp:n,Fn:i}=r;let o=r.CURVE;const{h:s,n:a}=o;Lf(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:u}=t;if(u&&(!n.is0(o.a)||"bigint"!=typeof u.beta||!Array.isArray(u.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const c=Ul(n,i);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const l=t.toBytes||function(e,t,r){const{x:i,y:o}=t.toAffine(),s=n.toBytes(i);if(vf(r,"isCompressed"),r){f();return Va(Pl(!n.isOdd(o)),s)}return Va(Uint8Array.of(4),s,n.toBytes(o))},h=t.fromBytes||function(e){Ef(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:r}=c,i=e.length,o=e[0],s=e.subarray(1);if(i!==t||2!==o&&3!==o){if(i===r&&4===o){const e=n.BYTES,t=n.fromBytes(s.subarray(0,e)),r=n.fromBytes(s.subarray(e,2*e));if(!d(t,r))throw new Error("bad point: is not on curve");return{x:t,y:r}}throw new Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${r}`)}{const e=n.fromBytes(s);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=p(e);let r;try{r=n.sqrt(t)}catch(a){const e=a instanceof Error?": "+a.message:"";throw new Error("bad point: is not on curve, sqrt error"+e)}f();return!(1&~o)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}};function p(e){const t=n.sqr(e),r=n.mul(t,e);return n.add(n.add(r,n.mul(e,o.a)),o.b)}function d(e,t){const r=n.sqr(t),i=p(e);return n.eql(r,i)}if(!d(o.Gx,o.Gy))throw new Error("bad curve params: generator point");const y=n.mul(n.pow(o.a,Tl),xl),g=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(y,g)))throw new Error("bad curve params: a or b");function m(e,t,r=!1){if(!n.isValid(t)||r&&n.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function b(e){if(!(e instanceof S))throw new Error("ProjectivePoint expected")}function w(e){if(!u||!u.basises)throw new Error("no endo");return function(e,t,r){const[[n,i],[o,s]]=t,a=vl(s*e,r),u=vl(-i*e,r);let c=e-a*n-u*o,f=-a*i-u*s;const l=c<kl,h=f<kl;l&&(c=-c),h&&(f=-f);const p=Uf(Math.ceil(Pf(r)/2))+Al;if(c<kl||c>=p||f<kl||f>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:c,k2neg:h,k2:f}}(e,u.basises,i.ORDER)}const v=Nf((e,t)=>{const{X:r,Y:i,Z:o}=e;if(n.eql(o,n.ONE))return{x:r,y:i};const s=e.is0();null==t&&(t=s?n.ONE:n.inv(o));const a=n.mul(r,t),u=n.mul(i,t),c=n.mul(o,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),E=Nf(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:i}=e.toAffine();if(!n.isValid(r)||!n.isValid(i))throw new Error("bad point: x or y not field elements");if(!d(r,i))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function _(e,t,r,i,o){return r=new S(n.mul(r.X,e),r.Y,r.Z),t=ul(i,t),r=ul(o,r),t.add(r)}class S{constructor(e,t,r){this.X=m("x",e),this.Y=m("y",t,!0),this.Z=m("z",r),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof S)throw new Error("projective point not allowed");return n.is0(t)&&n.is0(r)?S.ZERO:new S(t,r,n.ONE)}static fromBytes(e){const t=S.fromAffine(h(Ef(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return S.fromBytes(xf("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return A.createCache(this,e),t||this.multiply(Tl),this}assertValidity(){E(this)}hasEvenY(){const{y:e}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(e)}equals(e){b(e);const{X:t,Y:r,Z:i}=this,{X:o,Y:s,Z:a}=e,u=n.eql(n.mul(t,a),n.mul(o,i)),c=n.eql(n.mul(r,a),n.mul(s,i));return u&&c}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){const{a:e,b:t}=o,r=n.mul(t,Tl),{X:i,Y:s,Z:a}=this;let u=n.ZERO,c=n.ZERO,f=n.ZERO,l=n.mul(i,i),h=n.mul(s,s),p=n.mul(a,a),d=n.mul(i,s);return d=n.add(d,d),f=n.mul(i,a),f=n.add(f,f),u=n.mul(e,f),c=n.mul(r,p),c=n.add(u,c),u=n.sub(h,c),c=n.add(h,c),c=n.mul(u,c),u=n.mul(d,u),f=n.mul(r,f),p=n.mul(e,p),d=n.sub(l,p),d=n.mul(e,d),d=n.add(d,f),f=n.add(l,l),l=n.add(f,l),l=n.add(l,p),l=n.mul(l,d),c=n.add(c,l),p=n.mul(s,a),p=n.add(p,p),l=n.mul(p,d),u=n.sub(u,l),f=n.mul(p,h),f=n.add(f,f),f=n.add(f,f),new S(u,c,f)}add(e){b(e);const{X:t,Y:r,Z:i}=this,{X:s,Y:a,Z:u}=e;let c=n.ZERO,f=n.ZERO,l=n.ZERO;const h=o.a,p=n.mul(o.b,Tl);let d=n.mul(t,s),y=n.mul(r,a),g=n.mul(i,u),m=n.add(t,r),w=n.add(s,a);m=n.mul(m,w),w=n.add(d,y),m=n.sub(m,w),w=n.add(t,i);let v=n.add(s,u);return w=n.mul(w,v),v=n.add(d,g),w=n.sub(w,v),v=n.add(r,i),c=n.add(a,u),v=n.mul(v,c),c=n.add(y,g),v=n.sub(v,c),l=n.mul(h,w),c=n.mul(p,g),l=n.add(c,l),c=n.sub(y,l),l=n.add(y,l),f=n.mul(c,l),y=n.add(d,d),y=n.add(y,d),g=n.mul(h,g),w=n.mul(p,w),y=n.add(y,g),g=n.sub(d,g),g=n.mul(h,g),w=n.add(w,g),d=n.mul(y,w),f=n.add(f,d),d=n.mul(v,w),c=n.mul(m,c),c=n.sub(c,d),d=n.mul(m,y),l=n.mul(v,l),l=n.add(l,d),new S(c,f,l)}subtract(e){return this.add(e.negate())}is0(){return this.equals(S.ZERO)}multiply(e){const{endo:r}=t;if(!i.isValidNot0(e))throw new Error("invalid scalar: out of range");let n,o;const s=e=>A.cached(this,e,e=>cl(S,e));if(r){const{k1neg:t,k1:i,k2neg:a,k2:u}=w(e),{p:c,f:f}=s(i),{p:l,f:h}=s(u);o=f.add(h),n=_(r.beta,c,l,t,a)}else{const{p:t,f:r}=s(e);n=t,o=r}return cl(S,[n,o])[0]}multiplyUnsafe(e){const{endo:r}=t,n=this;if(!i.isValid(e))throw new Error("invalid scalar: out of range");if(e===kl||n.is0())return S.ZERO;if(e===Al)return n;if(A.hasCache(this))return this.multiply(e);if(r){const{k1neg:t,k1:i,k2neg:o,k2:s}=w(e),{p1:a,p2:u}=function(e,t,r,n){let i=t,o=e.ZERO,s=e.ZERO;for(;r>sl||n>sl;)r&al&&(o=o.add(i)),n&al&&(s=s.add(i)),i=i.double(),r>>=al,n>>=al;return{p1:o,p2:s}}(S,n,i,s);return _(r.beta,a,u,t,o)}return A.unsafe(n,e)}multiplyAndAddUnsafe(e,t,r){const n=this.multiplyUnsafe(t).add(e.multiplyUnsafe(r));return n.is0()?void 0:n}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===Al||(e?e(S,this):A.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===Al?this:e?e(S,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return vf(e,"isCompressed"),this.assertValidity(),l(S,this,e)}toHex(e=!0){return Ua(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return cl(S,e)}static msm(e,t){return bl(S,i,e,t)}static fromPrivateKey(e){return S.BASE.multiply(Ol(i,e))}}S.BASE=new S(o.Gx,o.Gy,n.ONE),S.ZERO=new S(n.ZERO,n.ONE,n.ZERO),S.Fp=n,S.Fn=i;const k=i.BITS,A=new ml(S,t.endo?Math.ceil(k/2):k);return S.BASE.precompute(8),S}function Pl(e){return Uint8Array.of(e?2:3)}function Ul(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ll(e,t={}){const{Fn:r}=e,n=t.randomBytes||$a,i=Object.assign(Ul(e.Fp,r),{seed:ol(r.ORDER)});function o(e){try{return!!Ol(r,e)}catch{return!1}}function s(e=n(i.seed)){return function(e,t,r=!1){const n=e.length,i=il(t),o=ol(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);const s=qf(r?Af(e):kf(e),t-Cf)+Cf;return r?Tf(s,i):If(s,i)}(Ef(e,i.seed,"seed"),r.ORDER)}function a(t,n=!0){return e.BASE.multiply(Ol(r,t)).toBytes(n)}function u(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:n,publicKey:o,publicKeyUncompressed:s}=i;if(r.allowedLengths||n===o)return;const a=xf("key",t).length;return a===o||a===s}return Object.freeze({getPublicKey:a,getSharedSecret:function(t,n,i=!0){if(!0===u(t))throw new Error("first arg must be private key");if(!1===u(n))throw new Error("second arg must be public key");const o=Ol(r,t);return e.fromHex(n).multiply(o).toBytes(i)},keygen:function(e){const t=s(e);return{secretKey:t,publicKey:a(t)}},Point:e,utils:{isValidSecretKey:o,isValidPublicKey:function(t,r){const{publicKey:n,publicKeyUncompressed:o}=i;try{const i=t.length;return!(!0===r&&i!==n||!1===r&&i!==o)&&!!e.fromBytes(t)}catch{return!1}},randomSecretKey:s,isValidPrivateKey:o,randomPrivateKey:s,normPrivateKeyToScalar:e=>Ol(r,e),precompute:(t=8,r=e.BASE)=>r.precompute(t,!1)},lengths:i})}function Nl(e,t,r={}){Aa(t),Lf(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const n=r.randomBytes||$a,i=r.hmac||((e,...r)=>Nc(t,e,Va(...r))),{Fp:o,Fn:s}=e,{ORDER:a,BITS:u}=s,{keygen:c,getPublicKey:f,getSharedSecret:l,utils:h,lengths:p}=Ll(e,r),d={prehash:!1,lowS:"boolean"==typeof r.lowS&&r.lowS,format:void 0,extraEntropy:!1},y="compact";function g(e){return e>a>>Al}function m(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class b{constructor(e,t,r){this.r=m("r",e),this.s=m("s",t),null!=r&&(this.recovery=r),Object.freeze(this)}static fromBytes(e,t=y){let r;if(function(e,t){El(t);const r=p.signature;Ef(e,"compact"===t?r:"recovered"===t?r+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:r}=Sl.toSig(Ef(e));return new b(t,r)}"recovered"===t&&(r=e[0],t="compact",e=e.subarray(1));const n=s.BYTES,i=e.subarray(0,n),o=e.subarray(n,2*n);return new b(s.fromBytes(i),s.fromBytes(o),r)}static fromHex(e,t){return this.fromBytes(Ma(e),t)}addRecoveryBit(e){return new b(this.r,this.s,e)}recoverPublicKey(t){const r=o.ORDER,{r:n,s:i,recovery:u}=this;if(null==u||![0,1,2,3].includes(u))throw new Error("recovery id invalid");if(a*Il<r&&u>1)throw new Error("recovery id is ambiguous for h>1 curve");const c=2===u||3===u?n+a:n;if(!o.isValid(c))throw new Error("recovery id 2 or 3 invalid");const f=o.toBytes(c),l=e.fromBytes(Va(Pl(!(1&u)),f)),h=s.inv(c),p=v(xf("msgHash",t)),d=s.create(-p*h),y=s.create(i*h),g=e.BASE.multiplyUnsafe(d).add(l.multiplyUnsafe(y));if(g.is0())throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return g(this.s)}toBytes(e=y){if(El(e),"der"===e)return Ma(Sl.hexFromSig(this));const t=s.toBytes(this.r),r=s.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return Va(Uint8Array.of(this.recovery),t,r)}return Va(t,r)}toHex(e){return Ua(this.toBytes(e))}assertValidity(){}static fromCompact(e){return b.fromBytes(xf("sig",e),"compact")}static fromDER(e){return b.fromBytes(xf("sig",e),"der")}normalizeS(){return this.hasHighS()?new b(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ua(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ua(this.toBytes("compact"))}}const w=r.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=kf(e),r=8*e.length-u;return r>0?t>>BigInt(r):t},v=r.bits2int_modN||function(e){return s.create(w(e))},E=Uf(u);function _(e){return Bf("num < 2^"+u,e,kl,E),s.toBytes(e)}function S(e,r){return Ef(e,void 0,"message"),r?Ef(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:c,getPublicKey:f,getSharedSecret:l,utils:h,lengths:p,Point:e,sign:function(r,o,a={}){r=xf("message",r);const{seed:u,k2sig:c}=function(t,r,i){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{lowS:o,prehash:a,extraEntropy:u}=_l(i,d);t=S(t,a);const c=v(t),f=Ol(s,r),l=[_(f),_(c)];if(null!=u&&!1!==u){const e=!0===u?n(p.secretKey):u;l.push(xf("extraEntropy",e))}const h=Va(...l),y=c;return{seed:h,k2sig:function(t){const r=w(t);if(!s.isValidNot0(r))return;const n=s.inv(r),i=e.BASE.multiply(r).toAffine(),a=s.create(i.x);if(a===kl)return;const u=s.create(n*s.create(y+a*f));if(u===kl)return;let c=(i.x===a?0:2)|Number(i.y&Al),l=u;return o&&g(u)&&(l=s.neg(u),c^=1),new b(a,l,c)}}}(r,o,a);return function(e,t,r){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof r)throw new Error("hmacFn must be a function");const n=e=>new Uint8Array(e),i=e=>Uint8Array.of(e);let o=n(e),s=n(e),a=0;const u=()=>{o.fill(1),s.fill(0),a=0},c=(...e)=>r(s,o,...e),f=(e=n(0))=>{s=c(i(0),e),o=c(),0!==e.length&&(s=c(i(1),e),o=c())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const r=[];for(;e<t;){o=c();const t=o.slice();r.push(t),e+=o.length}return Va(...r)};return(e,t)=>{let r;for(u(),f(e);!(r=t(l()));)f();return u(),r}}(t.outputLen,s.BYTES,i)(u,c)},verify:function(t,r,n,i={}){const{lowS:o,prehash:a,format:u}=_l(i,d);if(n=xf("publicKey",n),r=S(xf("message",r),a),"strict"in i)throw new Error("options.strict was renamed to lowS");const c=void 0===u?function(e){let t;const r="string"==typeof e||_a(e),n=!r&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!r&&!n)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(n)t=new b(e.r,e.s);else if(r){try{t=b.fromBytes(xf("sig",e),"der")}catch(o){if(!(o instanceof Sl.Err))throw o}if(!t)try{t=b.fromBytes(xf("sig",e),"compact")}catch{return!1}}return t||!1}(t):b.fromBytes(xf("sig",t),u);if(!1===c)return!1;try{const t=e.fromBytes(n);if(o&&c.hasHighS())return!1;const{r:i,s:a}=c,u=v(r),f=s.inv(a),l=s.create(u*f),h=s.create(i*f),p=e.BASE.multiplyUnsafe(l).add(t.multiplyUnsafe(h));return!p.is0()&&s.create(p.x)===i}catch{return!1}},recoverPublicKey:function(e,t,r={}){const{prehash:n}=_l(r,d);return t=S(t,n),b.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:b,hash:t})}function Rl(e){const{CURVE:t,curveOpts:r}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp;let n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:r,Fn:nl(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Cl(e){const{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:i}=Rl(e);return function(e,t){const r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,rl(r.Fn.ORDER,r.Fn.BITS))})}(e,Nl(Bl(t,r),n,i))}const Hl={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},zl=BigInt(2);const Ml=nl(Hl.p,{sqrt:function(e){const t=Hl.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,f=c*c*e%t,l=Wf(f,r,t)*f%t,h=Wf(l,r,t)*f%t,p=Wf(h,zl,t)*c%t,d=Wf(p,i,t)*p%t,y=Wf(d,o,t)*d%t,g=Wf(y,a,t)*y%t,m=Wf(g,u,t)*g%t,b=Wf(m,a,t)*y%t,w=Wf(b,r,t)*f%t,v=Wf(w,s,t)*d%t,E=Wf(v,n,t)*c%t,_=Wf(E,zl,t);if(!Ml.eql(Ml.sqr(_),e))throw new Error("Cannot find square root");return _}}),Dl=function(e,t){const r=t=>Cl({...e,hash:t});return{...r(t),create:r}}({...Hl,Fp:Ml,lowS:!0,endo:Kl},ku);var jl,Fl={};function Vl(){if(jl)return Fl;let e,t,r,n,i,o,s;function a(t){return{lang:t?.lang??e?.lang,message:t?.message,abortEarly:t?.abortEarly??e?.abortEarly,abortPipeEarly:t?.abortPipeEarly??e?.abortPipeEarly}}function u(e){return t?.get(e)}function c(e){return r?.get(e)}function f(e,t){return n?.get(e)?.get(t)}function l(e){const t=typeof e;return"string"===t?`"${e}"`:"number"===t||"bigint"===t||"boolean"===t?`${e}`:"object"===t||"function"===t?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function h(e,t,r,n,i){const o=i&&"input"in i?i.input:r.value,s=i?.expected??e.expects??null,a=i?.received??l(o),h={kind:e.kind,type:e.type,input:o,expected:s,received:a,message:`Invalid ${t}: ${s?`Expected ${s} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:i?.path,issues:i?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p="schema"===e.kind,d=i?.message??e.message??f(e.reference,h.lang)??(p?c(h.lang):null)??n.message??u(h.lang);void 0!==d&&(h.message="function"==typeof d?d(h):d),p&&(r.typed=!1),r.issues?r.issues.push(h):r.issues=[h]}function p(e){return i||(i=new TextEncoder),i.encode(e).length}function d(e){o||(o=new Intl.Segmenter);const t=o.segment(e);let r=0;for(const n of t)r++;return r}function y(e,t){if("pipe"in e){const r=[];for(let n=e.pipe.length-1;n>=0;n--){const i=e.pipe[n];if("schema"===i.kind&&"pipe"in i)r.push(i);else if("metadata"===i.kind&&i.type===t)return i[t]}for(const e of r){const r=y(e,t);if(void 0!==r)return r}}}function g(e){return{version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},a())}}function m(e,t){s||(s=new Map),s.get(e)||s.set(e,new Intl.Segmenter(e,{granularity:"word"}));const r=s.get(e).segment(t);let n=0;for(const i of r)i.isWordLike&&n++;return n}jl=1;const b=/\D/gu;function w(e){const t=e.replace(b,"");let r=t.length,n=1,i=0;for(;r;){const e=+t[--r];n^=1,i+=n?[0,2,4,6,8,1,3,5,7,9][e]:e}return i%10==0}function v(e,t){return Object.hasOwn(e,t)&&"__proto__"!==t&&"prototype"!==t&&"constructor"!==t}function E(e,t){const r=[...new Set(e)];return r.length>1?`(${r.join(` ${t} `)})`:r[0]??"never"}function _(e){if(e.path){let t="";for(const r of e.path){if("string"!=typeof r.key&&"number"!=typeof r.key)return null;t+=t?`.${r.key}`:r.key}return t}return null}var S=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};const k=/^(?:[\da-z+/]{4})*(?:[\da-z+/]{2}==|[\da-z+/]{3}=)?$/iu,A=/^[A-Z]{6}(?!00)[\dA-Z]{2}(?:[\dA-Z]{3})?$/u,I=/^[a-z][\da-z]*$/u,T=/^[+-]?(?:\d*\.)?\d+$/u,x=/^\d+$/u,O=/^[\w+-]+(?:\.[\w+-]+)*@[\da-z]+(?:[.-][\da-z]+)*\.[a-z]{2,}$/iu,B=/^(?:[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|(?![\p{Emoji_Modifier_Base}\u{1F1E6}-\u{1F1FF}])\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|(?![\p{Emoji_Modifier_Base}\u{1F1E6}-\u{1F1FF}])\p{Emoji_Presentation}))*)+$/u,P=/^(?:0[hx])?[\da-fA-F]+$/u,U=/^#(?:[\da-fA-F]{3,4}|[\da-fA-F]{6}|[\da-fA-F]{8})$/u,L=/^\d{15}$|^\d{2}-\d{6}-\d{6}-\d$/u,N=/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$/u,R=/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,7}:|(?:[\da-f]{1,4}:){1,6}:[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,5}(?::[\da-f]{1,4}){1,2}|(?:[\da-f]{1,4}:){1,4}(?::[\da-f]{1,4}){1,3}|(?:[\da-f]{1,4}:){1,3}(?::[\da-f]{1,4}){1,4}|(?:[\da-f]{1,4}:){1,2}(?::[\da-f]{1,4}){1,5}|[\da-f]{1,4}:(?::[\da-f]{1,4}){1,6}|:(?:(?::[\da-f]{1,4}){1,7}|:)|fe80:(?::[\da-f]{0,4}){0,4}%[\da-z]+|::(?:f{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-f]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/iu,C=/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$|^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,7}:|(?:[\da-f]{1,4}:){1,6}:[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,5}(?::[\da-f]{1,4}){1,2}|(?:[\da-f]{1,4}:){1,4}(?::[\da-f]{1,4}){1,3}|(?:[\da-f]{1,4}:){1,3}(?::[\da-f]{1,4}){1,4}|(?:[\da-f]{1,4}:){1,2}(?::[\da-f]{1,4}){1,5}|[\da-f]{1,4}:(?::[\da-f]{1,4}){1,6}|:(?:(?::[\da-f]{1,4}){1,7}|:)|fe80:(?::[\da-f]{0,4}){0,4}%[\da-z]+|::(?:f{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-f]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/iu,H=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])$/u,K=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3]):[0-5]\d$/u,z=/^(?:0\d|1\d|2[0-3]):[0-5]\d$/u,M=/^(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}$/u,D=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?(?:Z|[+-](?:0\d|1\d|2[0-3])(?::?[0-5]\d)?)$/u,j=/^\d{4}-W(?:0[1-9]|[1-4]\d|5[0-3])$/u,F=/^(?:[\da-f]{2}:){5}[\da-f]{2}$|^(?:[\da-f]{2}-){5}[\da-f]{2}$|^(?:[\da-f]{4}\.){2}[\da-f]{4}$/iu,V=/^(?:[\da-f]{2}:){7}[\da-f]{2}$|^(?:[\da-f]{2}-){7}[\da-f]{2}$|^(?:[\da-f]{4}\.){3}[\da-f]{4}$|^(?:[\da-f]{4}:){3}[\da-f]{4}$/iu,q=/^(?:[\da-f]{2}:){5}[\da-f]{2}$|^(?:[\da-f]{2}-){5}[\da-f]{2}$|^(?:[\da-f]{4}\.){2}[\da-f]{4}$|^(?:[\da-f]{2}:){7}[\da-f]{2}$|^(?:[\da-f]{2}-){7}[\da-f]{2}$|^(?:[\da-f]{4}\.){3}[\da-f]{4}$|^(?:[\da-f]{4}:){3}[\da-f]{4}$/iu,W=/^[\w-]+$/u,$=/^(?:0o)?[0-7]+$/u,G=/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,X=/^[\da-z]+(?:[-_][\da-z]+)*$/u,Y=/^[\da-hjkmnp-tv-zA-HJKMNP-TV-Z]{26}$/u,Z=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu;const Q=/^(?:\d{14,19}|\d{4}(?: \d{3,6}){2,4}|\d{4}(?:-\d{3,6}){2,4})$/u,J=/[- ]/gu,ee=[/^3[47]\d{13}$/u,/^3(?:0[0-5]|[68]\d)\d{11,13}$/u,/^6(?:011|5\d{2})\d{12,15}$/u,/^(?:2131|1800|35\d{3})\d{11}$/u,/^5[1-5]\d{2}|(?:222\d|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)\d{12}$/u,/^(?:6[27]\d{14,17}|81\d{14,17})$/u,/^4\d{12}(?:\d{3,6})?$/u];const te={md4:32,md5:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8,adler32:8};function re(e,t){if(e.issues)for(const r of t)for(const t of e.issues){let e=!1;const n=Math.min(r.length,t.path?.length??0);for(let i=0;i<n;i++)if(r[i]!==t.path[i].key&&("$"!==r[i]||"array"!==t.path[i].type)){e=!0;break}if(!e)return!1}return!0}function ne(e,t,r){return"function"==typeof e.fallback?e.fallback(t,r):e.fallback}function ie(e,t,r){return"function"==typeof e.default?e.default(t,r):e.default}function oe(e,t){const r=[];for(const n in e)(""+ +n!==n||"string"!=typeof e[n]||!Object.is(e[e[n]],+n))&&r.push(e[n]);return{kind:"schema",type:"enum",reference:oe,expects:E(r.map(l),"|"),async:!1,enum:e,options:r,message:t,get"~standard"(){return g(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:h(this,"type",e,t),e}}}function se(e){return{kind:"schema",type:"function",reference:se,expects:"Function",async:!1,message:e,get"~standard"(){return g(this)},"~run"(e,t){return"function"==typeof e.value?e.typed=!0:h(this,"type",e,t),e}}}function ae(e,t){if(typeof e==typeof t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{value:e};if(e&&t&&e.constructor===Object&&t.constructor===Object){for(const r in t)if(r in e){const n=ae(e[r],t[r]);if(n.issue)return n;e[r]=n.value}else e[r]=t[r];return{value:e}}if(Array.isArray(e)&&Array.isArray(t)&&e.length===t.length){for(let r=0;r<e.length;r++){const n=ae(e[r],t[r]);if(n.issue)return n;e[r]=n.value}return{value:e}}}return{issue:!0}}function ue(e,t){return{kind:"schema",type:"non_optional",reference:ue,expects:"!undefined",async:!1,wrapped:e,message:t,get"~standard"(){return g(this)},"~run"(e,t){return void 0!==e.value&&(e=this.wrapped["~run"](e,t)),void 0===e.value&&h(this,"type",e,t),e}}}function ce(e,t){return{kind:"schema",type:"non_optional",reference:ce,expects:"!undefined",async:!0,wrapped:e,message:t,get"~standard"(){return g(this)},async"~run"(e,t){return void 0!==e.value&&(e=await this.wrapped["~run"](e,t)),void 0===e.value&&h(this,"type",e,t),e}}}function fe(e){return{kind:"schema",type:"null",reference:fe,expects:"null",async:!1,message:e,get"~standard"(){return g(this)},"~run"(e,t){return null===e.value?e.typed=!0:h(this,"type",e,t),e}}}function le(e,t){return{kind:"schema",type:"optional",reference:le,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return g(this)},"~run"(e,t){return void 0===e.value&&(void 0!==this.default&&(e.value=ie(this,e,t)),void 0===e.value)?(e.typed=!0,e):this.wrapped["~run"](e,t)}}}function he(e,t){return{kind:"schema",type:"optional",reference:he,expects:`(${e.expects} | undefined)`,async:!0,wrapped:e,default:t,get"~standard"(){return g(this)},async"~run"(e,t){return void 0===e.value&&(void 0!==this.default&&(e.value=await ie(this,e,t)),void 0===e.value)?(e.typed=!0,e):this.wrapped["~run"](e,t)}}}function pe(e,t){return{kind:"schema",type:"picklist",reference:pe,expects:E(e.map(l),"|"),async:!1,options:e,message:t,get"~standard"(){return g(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:h(this,"type",e,t),e}}}function de(e){return{kind:"schema",type:"undefined",reference:de,expects:"undefined",async:!1,message:e,get"~standard"(){return g(this)},"~run"(e,t){return void 0===e.value?e.typed=!0:h(this,"type",e,t),e}}}function ye(e){let t;if(e)for(const r of e)t?t.push(...r.issues):t=r.issues;return t}function ge(e){return{kind:"schema",type:"void",reference:ge,expects:"void",async:!1,message:e,get"~standard"(){return g(this)},"~run"(e,t){return void 0===e.value?e.typed=!0:h(this,"type",e,t),e}}}function me(e,t,r){const n=e["~run"]({value:t},a(r));if(n.issues)throw new S(n.issues);return n.value}async function be(e,t,r){const n=await e["~run"]({value:t},a(r));if(n.issues)throw new S(n.issues);return n.value}function we(e,t,r){const n=e["~run"]({value:t},a(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}async function ve(e,t,r){const n=await e["~run"]({value:t},a(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}return Fl.BASE64_REGEX=k,Fl.BIC_REGEX=A,Fl.CUID2_REGEX=I,Fl.DECIMAL_REGEX=T,Fl.DIGITS_REGEX=x,Fl.EMAIL_REGEX=O,Fl.EMOJI_REGEX=B,Fl.HEXADECIMAL_REGEX=P,Fl.HEX_COLOR_REGEX=U,Fl.IMEI_REGEX=L,Fl.IPV4_REGEX=N,Fl.IPV6_REGEX=R,Fl.IP_REGEX=C,Fl.ISO_DATE_REGEX=H,Fl.ISO_DATE_TIME_REGEX=K,Fl.ISO_TIMESTAMP_REGEX=D,Fl.ISO_TIME_REGEX=z,Fl.ISO_TIME_SECOND_REGEX=M,Fl.ISO_WEEK_REGEX=j,Fl.MAC48_REGEX=F,Fl.MAC64_REGEX=V,Fl.MAC_REGEX=q,Fl.NANO_ID_REGEX=W,Fl.OCTAL_REGEX=$,Fl.RFC_EMAIL_REGEX=G,Fl.SLUG_REGEX=X,Fl.ULID_REGEX=Y,Fl.UUID_REGEX=Z,Fl.ValiError=S,Fl._addIssue=h,Fl._getByteCount=p,Fl._getGraphemeCount=d,Fl._getLastMetadata=y,Fl._getStandardProps=g,Fl._getWordCount=m,Fl._isLuhnAlgo=w,Fl._isValidObjectKey=v,Fl._joinExpects=E,Fl._stringify=l,Fl.any=function e(){return{kind:"schema",type:"any",reference:e,expects:"any",async:!1,get"~standard"(){return g(this)},"~run":e=>(e.typed=!0,e)}},Fl.args=function e(t){return{kind:"transformation",type:"args",reference:e,async:!1,schema:t,"~run"(e,t){const r=e.value;return e.value=(...e)=>{const n=this.schema["~run"]({value:e},t);if(n.issues)throw new S(n.issues);return r(...n.value)},e}}},Fl.argsAsync=function e(t){return{kind:"transformation",type:"args",reference:e,async:!1,schema:t,"~run"(e,r){const n=e.value;return e.value=async(...e)=>{const i=await t["~run"]({value:e},r);if(i.issues)throw new S(i.issues);return n(...i.value)},e}}},Fl.array=function e(t,r){return{kind:"schema",type:"array",reference:e,expects:"Array",async:!1,item:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];for(let n=0;n<r.length;n++){const i=r[n],o=this.item["~run"]({value:i},t);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}}else h(this,"type",e,t);return e}}},Fl.arrayAsync=function e(t,r){return{kind:"schema",type:"array",reference:e,expects:"Array",async:!0,item:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];const n=await Promise.all(r.map(e=>this.item["~run"]({value:e},t)));for(let i=0;i<n.length;i++){const o=n[i];if(o.issues){const n={type:"array",origin:"value",input:r,key:i,value:r[i]};for(const t of o.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}}else h(this,"type",e,t);return e}}},Fl.assert=function(e,t){const r=e["~run"]({value:t},{abortEarly:!0}).issues;if(r)throw new S(r)},Fl.awaitAsync=function e(){return{kind:"transformation",type:"await",reference:e,async:!0,"~run":async e=>(e.value=await e.value,e)}},Fl.base64=function e(t){return{kind:"validation",type:"base64",reference:e,async:!1,expects:null,requirement:k,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"Base64",e,t),e}}},Fl.bic=function e(t){return{kind:"validation",type:"bic",reference:e,async:!1,expects:null,requirement:A,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"BIC",e,t),e}}},Fl.bigint=function e(t){return{kind:"schema",type:"bigint",reference:e,expects:"bigint",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return"bigint"==typeof e.value?e.typed=!0:h(this,"type",e,t),e}}},Fl.blob=function e(t){return{kind:"schema",type:"blob",reference:e,expects:"Blob",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return e.value instanceof Blob?e.typed=!0:h(this,"type",e,t),e}}},Fl.boolean=function e(t){return{kind:"schema",type:"boolean",reference:e,expects:"boolean",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return"boolean"==typeof e.value?e.typed=!0:h(this,"type",e,t),e}}},Fl.brand=function e(t){return{kind:"transformation",type:"brand",reference:e,async:!1,name:t,"~run":e=>e}},Fl.bytes=function e(t,r){return{kind:"validation",type:"bytes",reference:e,async:!1,expects:`${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=p(e.value);r!==this.requirement&&h(this,"bytes",e,t,{received:`${r}`})}return e}}},Fl.check=function e(t,r){return{kind:"validation",type:"check",reference:e,async:!1,expects:null,requirement:t,message:r,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"input",e,t),e}}},Fl.checkAsync=function e(t,r){return{kind:"validation",type:"check",reference:e,async:!0,expects:null,requirement:t,message:r,async"~run"(e,t){return e.typed&&!(await this.requirement(e.value))&&h(this,"input",e,t),e}}},Fl.checkItems=function e(t,r){return{kind:"validation",type:"check_items",reference:e,async:!1,expects:null,requirement:t,message:r,"~run"(e,t){if(e.typed)for(let r=0;r<e.value.length;r++){const n=e.value[r];this.requirement(n,r,e.value)||h(this,"item",e,t,{input:n,path:[{type:"array",origin:"value",input:e.value,key:r,value:n}]})}return e}}},Fl.checkItemsAsync=function e(t,r){return{kind:"validation",type:"check_items",reference:e,async:!0,expects:null,requirement:t,message:r,async"~run"(e,t){if(e.typed){const r=await Promise.all(e.value.map(this.requirement));for(let n=0;n<e.value.length;n++)if(!r[n]){const r=e.value[n];h(this,"item",e,t,{input:r,path:[{type:"array",origin:"value",input:e.value,key:n,value:r}]})}}return e}}},Fl.config=function(e,t){return{...e,get"~standard"(){return g(this)},"~run":(r,n)=>e["~run"](r,{...n,...t})}},Fl.creditCard=function e(t){return{kind:"validation",type:"credit_card",reference:e,async:!1,expects:null,requirement(e){let t;return Q.test(e)&&(t=e.replace(J,""))&&ee.some(e=>e.test(t))&&w(t)},message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"credit card",e,t),e}}},Fl.cuid2=function e(t){return{kind:"validation",type:"cuid2",reference:e,async:!1,expects:null,requirement:I,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"Cuid2",e,t),e}}},Fl.custom=function e(t,r){return{kind:"schema",type:"custom",reference:e,expects:"unknown",async:!1,check:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){return this.check(e.value)?e.typed=!0:h(this,"type",e,t),e}}},Fl.customAsync=function e(t,r){return{kind:"schema",type:"custom",reference:e,expects:"unknown",async:!0,check:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){return await this.check(e.value)?e.typed=!0:h(this,"type",e,t),e}}},Fl.date=function e(t){return{kind:"schema",type:"date",reference:e,expects:"Date",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return e.value instanceof Date?isNaN(e.value)?h(this,"type",e,t,{received:'"Invalid Date"'}):e.typed=!0:h(this,"type",e,t),e}}},Fl.decimal=function e(t){return{kind:"validation",type:"decimal",reference:e,async:!1,expects:null,requirement:T,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"decimal",e,t),e}}},Fl.deleteGlobalConfig=function(){e=void 0},Fl.deleteGlobalMessage=function(e){t?.delete(e)},Fl.deleteSchemaMessage=function(e){r?.delete(e)},Fl.deleteSpecificMessage=function(e,t){n?.get(e)?.delete(t)},Fl.description=function e(t){return{kind:"metadata",type:"description",reference:e,description:t}},Fl.digits=function e(t){return{kind:"validation",type:"digits",reference:e,async:!1,expects:null,requirement:x,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"digits",e,t),e}}},Fl.email=function e(t){return{kind:"validation",type:"email",reference:e,expects:null,async:!1,requirement:O,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"email",e,t),e}}},Fl.emoji=function e(t){return{kind:"validation",type:"emoji",reference:e,async:!1,expects:null,requirement:B,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"emoji",e,t),e}}},Fl.empty=function e(t){return{kind:"validation",type:"empty",reference:e,async:!1,expects:"0",message:t,"~run"(e,t){return e.typed&&e.value.length>0&&h(this,"length",e,t,{received:`${e.value.length}`}),e}}},Fl.endsWith=function e(t,r){return{kind:"validation",type:"ends_with",reference:e,async:!1,expects:`"${t}"`,requirement:t,message:r,"~run"(e,t){return e.typed&&!e.value.endsWith(this.requirement)&&h(this,"end",e,t,{received:`"${e.value.slice(-this.requirement.length)}"`}),e}}},Fl.entries=function e(t,r){return{kind:"validation",type:"entries",reference:e,async:!1,expects:`${t}`,requirement:t,message:r,"~run"(e,t){if(!e.typed)return e;const r=Object.keys(e.value).length;return e.typed&&r!==this.requirement&&h(this,"entries",e,t,{received:`${r}`}),e}}},Fl.entriesFromList=function(e,t){const r={};for(const n of e)r[n]=t;return r},Fl.entriesFromObjects=function(e){const t={};for(const r of e)Object.assign(t,r.entries);return t},Fl.enum=oe,Fl.enum_=oe,Fl.everyItem=function e(t,r){return{kind:"validation",type:"every_item",reference:e,async:!1,expects:null,requirement:t,message:r,"~run"(e,t){return e.typed&&!e.value.every(this.requirement)&&h(this,"item",e,t),e}}},Fl.exactOptional=function e(t,r){return{kind:"schema",type:"exact_optional",reference:e,expects:t.expects,async:!1,wrapped:t,default:r,get"~standard"(){return g(this)},"~run"(e,t){return this.wrapped["~run"](e,t)}}},Fl.exactOptionalAsync=function e(t,r){return{kind:"schema",type:"exact_optional",reference:e,expects:t.expects,async:!0,wrapped:t,default:r,get"~standard"(){return g(this)},async"~run"(e,t){return this.wrapped["~run"](e,t)}}},Fl.examples=function e(t){return{kind:"metadata",type:"examples",reference:e,examples:t}},Fl.excludes=function e(t,r){const n=l(t);return{kind:"validation",type:"excludes",reference:e,async:!1,expects:`!${n}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.includes(this.requirement)&&h(this,"content",e,t,{received:n}),e}}},Fl.fallback=function(e,t){return{...e,fallback:t,get"~standard"(){return g(this)},"~run"(t,r){const n=e["~run"](t,r);return n.issues?{typed:!0,value:ne(this,n,r)}:n}}},Fl.fallbackAsync=function(e,t){return{...e,fallback:t,async:!0,get"~standard"(){return g(this)},async"~run"(t,r){const n=await e["~run"](t,r);return n.issues?{typed:!0,value:await ne(this,n,r)}:n}}},Fl.file=function e(t){return{kind:"schema",type:"file",reference:e,expects:"File",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return e.value instanceof File?e.typed=!0:h(this,"type",e,t),e}}},Fl.filterItems=function e(t){return{kind:"transformation",type:"filter_items",reference:e,async:!1,operation:t,"~run"(e){return e.value=e.value.filter(this.operation),e}}},Fl.findItem=function e(t){return{kind:"transformation",type:"find_item",reference:e,async:!1,operation:t,"~run"(e){return e.value=e.value.find(this.operation),e}}},Fl.finite=function e(t){return{kind:"validation",type:"finite",reference:e,async:!1,expects:null,requirement:Number.isFinite,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"finite",e,t),e}}},Fl.flatten=function(e){const t={};for(const r of e)if(r.path){const e=_(r);e?(t.nested||(t.nested={}),t.nested[e]?t.nested[e].push(r.message):t.nested[e]=[r.message]):t.other?t.other.push(r.message):t.other=[r.message]}else t.root?t.root.push(r.message):t.root=[r.message];return t},Fl.flavor=function e(t){return{kind:"transformation",type:"flavor",reference:e,async:!1,name:t,"~run":e=>e}},Fl.forward=function(e,t){return{...e,"~run"(r,n){const i=r.issues&&[...r.issues];if((r=e["~run"](r,n)).issues)for(const e of r.issues)if(!i?.includes(e)){let n=r.value;for(const r of t){const t=n[r],i={type:"unknown",origin:"value",input:n,key:r,value:t};if(e.path?e.path.push(i):e.path=[i],!t)break;n=t}}return r}}},Fl.forwardAsync=function(e,t){return{...e,async:!0,async"~run"(r,n){const i=r.issues&&[...r.issues];if((r=await e["~run"](r,n)).issues)for(const e of r.issues)if(!i?.includes(e)){let n=r.value;for(const r of t){const t=n[r],i={type:"unknown",origin:"value",input:n,key:r,value:t};if(e.path?e.path.push(i):e.path=[i],!t)break;n=t}}return r}}},Fl.function=se,Fl.function_=se,Fl.getDefault=ie,Fl.getDefaults=function e(t){if("entries"in t){const r={};for(const n in t.entries)r[n]=e(t.entries[n]);return r}return"items"in t?t.items.map(e):ie(t)},Fl.getDefaultsAsync=async function e(t){return"entries"in t?Object.fromEntries(await Promise.all(Object.entries(t.entries).map(async([t,r])=>[t,await e(r)]))):"items"in t?Promise.all(t.items.map(e)):ie(t)},Fl.getDescription=function(e){return y(e,"description")},Fl.getDotPath=_,Fl.getExamples=function(e){const t=[];return function e(r){if("pipe"in r)for(const n of r.pipe)"schema"===n.kind&&"pipe"in n?e(n):"metadata"===n.kind&&"examples"===n.type&&t.push(...n.examples)}(e),t},Fl.getFallback=ne,Fl.getFallbacks=function e(t){if("entries"in t){const r={};for(const n in t.entries)r[n]=e(t.entries[n]);return r}return"items"in t?t.items.map(e):ne(t)},Fl.getFallbacksAsync=async function e(t){return"entries"in t?Object.fromEntries(await Promise.all(Object.entries(t.entries).map(async([t,r])=>[t,await e(r)]))):"items"in t?Promise.all(t.items.map(e)):ne(t)},Fl.getGlobalConfig=a,Fl.getGlobalMessage=u,Fl.getMetadata=function(e){const t={};return function e(r){if("pipe"in r)for(const n of r.pipe)"schema"===n.kind&&"pipe"in n?e(n):"metadata"===n.kind&&"metadata"===n.type&&Object.assign(t,n.metadata)}(e),t},Fl.getSchemaMessage=c,Fl.getSpecificMessage=f,Fl.getTitle=function(e){return y(e,"title")},Fl.graphemes=function e(t,r){return{kind:"validation",type:"graphemes",reference:e,async:!1,expects:`${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=d(e.value);r!==this.requirement&&h(this,"graphemes",e,t,{received:`${r}`})}return e}}},Fl.gtValue=function e(t,r){return{kind:"validation",type:"gt_value",reference:e,async:!1,expects:`>${t instanceof Date?t.toJSON():l(t)}`,requirement:t,message:r,"~run"(e,t){return e.typed&&!(e.value>this.requirement)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.hash=function e(t,r){return{kind:"validation",type:"hash",reference:e,expects:null,async:!1,requirement:RegExp(t.map(e=>`^[a-f0-9]{${te[e]}}$`).join("|"),"iu"),message:r,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"hash",e,t),e}}},Fl.hexColor=function e(t){return{kind:"validation",type:"hex_color",reference:e,async:!1,expects:null,requirement:U,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"hex color",e,t),e}}},Fl.hexadecimal=function e(t){return{kind:"validation",type:"hexadecimal",reference:e,async:!1,expects:null,requirement:P,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"hexadecimal",e,t),e}}},Fl.imei=function e(t){return{kind:"validation",type:"imei",reference:e,async:!1,expects:null,requirement:e=>L.test(e)&&w(e),message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"IMEI",e,t),e}}},Fl.includes=function e(t,r){const n=l(t);return{kind:"validation",type:"includes",reference:e,async:!1,expects:n,requirement:t,message:r,"~run"(e,t){return e.typed&&!e.value.includes(this.requirement)&&h(this,"content",e,t,{received:`!${n}`}),e}}},Fl.instance=function e(t,r){return{kind:"schema",type:"instance",reference:e,expects:t.name,async:!1,class:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){return e.value instanceof this.class?e.typed=!0:h(this,"type",e,t),e}}},Fl.integer=function e(t){return{kind:"validation",type:"integer",reference:e,async:!1,expects:null,requirement:Number.isInteger,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"integer",e,t),e}}},Fl.intersect=function e(t,r){return{kind:"schema",type:"intersect",reference:e,expects:E(t.map(e=>e.expects),"&"),async:!1,options:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){if(this.options.length){const r=e.value;let n;e.typed=!0;for(const i of this.options){const o=i["~run"]({value:r},t);if(o.issues&&(e.issues?e.issues.push(...o.issues):e.issues=o.issues,t.abortEarly)){e.typed=!1;break}o.typed||(e.typed=!1),e.typed&&(n?n.push(o.value):n=[o.value])}if(e.typed){e.value=n[0];for(let r=1;r<n.length;r++){const i=ae(e.value,n[r]);if(i.issue){h(this,"type",e,t,{received:"unknown"});break}e.value=i.value}}}else h(this,"type",e,t);return e}}},Fl.intersectAsync=function e(t,r){return{kind:"schema",type:"intersect",reference:e,expects:E(t.map(e=>e.expects),"&"),async:!0,options:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){if(this.options.length){const r=e.value;let n;e.typed=!0;const i=await Promise.all(this.options.map(e=>e["~run"]({value:r},t)));for(const o of i){if(o.issues&&(e.issues?e.issues.push(...o.issues):e.issues=o.issues,t.abortEarly)){e.typed=!1;break}o.typed||(e.typed=!1),e.typed&&(n?n.push(o.value):n=[o.value])}if(e.typed){e.value=n[0];for(let r=1;r<n.length;r++){const i=ae(e.value,n[r]);if(i.issue){h(this,"type",e,t,{received:"unknown"});break}e.value=i.value}}}else h(this,"type",e,t);return e}}},Fl.ip=function e(t){return{kind:"validation",type:"ip",reference:e,async:!1,expects:null,requirement:C,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"IP",e,t),e}}},Fl.ipv4=function e(t){return{kind:"validation",type:"ipv4",reference:e,async:!1,expects:null,requirement:N,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"IPv4",e,t),e}}},Fl.ipv6=function e(t){return{kind:"validation",type:"ipv6",reference:e,async:!1,expects:null,requirement:R,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"IPv6",e,t),e}}},Fl.is=function(e,t){return!e["~run"]({value:t},{abortEarly:!0}).issues},Fl.isOfKind=function(e,t){return t.kind===e},Fl.isOfType=function(e,t){return t.type===e},Fl.isValiError=function(e){return e instanceof S},Fl.isoDate=function e(t){return{kind:"validation",type:"iso_date",reference:e,async:!1,expects:null,requirement:H,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"date",e,t),e}}},Fl.isoDateTime=function e(t){return{kind:"validation",type:"iso_date_time",reference:e,async:!1,expects:null,requirement:K,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"date-time",e,t),e}}},Fl.isoTime=function e(t){return{kind:"validation",type:"iso_time",reference:e,async:!1,expects:null,requirement:z,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"time",e,t),e}}},Fl.isoTimeSecond=function e(t){return{kind:"validation",type:"iso_time_second",reference:e,async:!1,expects:null,requirement:M,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"time-second",e,t),e}}},Fl.isoTimestamp=function e(t){return{kind:"validation",type:"iso_timestamp",reference:e,async:!1,expects:null,requirement:D,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"timestamp",e,t),e}}},Fl.isoWeek=function e(t){return{kind:"validation",type:"iso_week",reference:e,async:!1,expects:null,requirement:j,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"week",e,t),e}}},Fl.keyof=function(e,t){return pe(Object.keys(e.entries),t)},Fl.lazy=function e(t){return{kind:"schema",type:"lazy",reference:e,expects:"unknown",async:!1,getter:t,get"~standard"(){return g(this)},"~run"(e,t){return this.getter(e.value)["~run"](e,t)}}},Fl.lazyAsync=function e(t){return{kind:"schema",type:"lazy",reference:e,expects:"unknown",async:!0,getter:t,get"~standard"(){return g(this)},async"~run"(e,t){return(await this.getter(e.value))["~run"](e,t)}}},Fl.length=function e(t,r){return{kind:"validation",type:"length",reference:e,async:!1,expects:`${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.length!==this.requirement&&h(this,"length",e,t,{received:`${e.value.length}`}),e}}},Fl.literal=function e(t,r){return{kind:"schema",type:"literal",reference:e,expects:l(t),async:!1,literal:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){return e.value===this.literal?e.typed=!0:h(this,"type",e,t),e}}},Fl.looseObject=function e(t,r){return{kind:"schema",type:"loose_object",reference:e,expects:"Object",async:!1,entries:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};for(const n in this.entries){const i=this.entries[n];if(n in r||("exact_optional"===i.type||"optional"===i.type||"nullish"===i.type)&&void 0!==i.default){const o=n in r?r[n]:ie(i),s=i["~run"]({value:o},t);if(s.issues){const i={type:"object",origin:"value",input:r,key:n,value:o};for(const t of s.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value[n]=s.value}else if(void 0!==i.fallback)e.value[n]=ne(i);else if("exact_optional"!==i.type&&"optional"!==i.type&&"nullish"!==i.type&&(h(this,"key",e,t,{input:void 0,expected:`"${n}"`,path:[{type:"object",origin:"key",input:r,key:n,value:r[n]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly)for(const t in r)v(r,t)&&!(t in this.entries)&&(e.value[t]=r[t])}else h(this,"type",e,t);return e}}},Fl.looseObjectAsync=function e(t,r){return{kind:"schema",type:"loose_object",reference:e,expects:"Object",async:!0,entries:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};const n=await Promise.all(Object.entries(this.entries).map(async([e,n])=>{if(e in r||("exact_optional"===n.type||"optional"===n.type||"nullish"===n.type)&&void 0!==n.default){const i=e in r?r[e]:await ie(n);return[e,i,n,await n["~run"]({value:i},t)]}return[e,r[e],n,null]}));for(const[i,o,s,a]of n)if(a){if(a.issues){const n={type:"object",origin:"value",input:r,key:i,value:o};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value[i]=a.value}else if(void 0!==s.fallback)e.value[i]=await ne(s);else if("exact_optional"!==s.type&&"optional"!==s.type&&"nullish"!==s.type&&(h(this,"key",e,t,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:o}]}),t.abortEarly))break;if(!e.issues||!t.abortEarly)for(const t in r)v(r,t)&&!(t in this.entries)&&(e.value[t]=r[t])}else h(this,"type",e,t);return e}}},Fl.looseTuple=function e(t,r){return{kind:"schema",type:"loose_tuple",reference:e,expects:"Array",async:!1,items:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];for(let n=0;n<this.items.length;n++){const i=r[n],o=this.items[n]["~run"]({value:i},t);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}if(!e.issues||!t.abortEarly)for(let t=this.items.length;t<r.length;t++)e.value.push(r[t])}else h(this,"type",e,t);return e}}},Fl.looseTupleAsync=function e(t,r){return{kind:"schema",type:"loose_tuple",reference:e,expects:"Array",async:!0,items:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];const n=await Promise.all(this.items.map(async(e,n)=>{const i=r[n];return[n,i,await e["~run"]({value:i},t)]}));for(const[i,o,s]of n){if(s.issues){const n={type:"array",origin:"value",input:r,key:i,value:o};for(const t of s.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value.push(s.value)}if(!e.issues||!t.abortEarly)for(let t=this.items.length;t<r.length;t++)e.value.push(r[t])}else h(this,"type",e,t);return e}}},Fl.ltValue=function e(t,r){return{kind:"validation",type:"lt_value",reference:e,async:!1,expects:`<${t instanceof Date?t.toJSON():l(t)}`,requirement:t,message:r,"~run"(e,t){return e.typed&&!(e.value<this.requirement)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.mac=function e(t){return{kind:"validation",type:"mac",reference:e,async:!1,expects:null,requirement:q,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"MAC",e,t),e}}},Fl.mac48=function e(t){return{kind:"validation",type:"mac48",reference:e,async:!1,expects:null,requirement:F,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"48-bit MAC",e,t),e}}},Fl.mac64=function e(t){return{kind:"validation",type:"mac64",reference:e,async:!1,expects:null,requirement:V,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"64-bit MAC",e,t),e}}},Fl.map=function e(t,r,n){return{kind:"schema",type:"map",reference:e,expects:"Map",async:!1,key:t,value:r,message:n,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r instanceof Map){e.typed=!0,e.value=new Map;for(const[n,i]of r){const o=this.key["~run"]({value:n},t);if(o.issues){const s={type:"map",origin:"key",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}const s=this.value["~run"]({value:i},t);if(s.issues){const o={type:"map",origin:"value",input:r,key:n,value:i};for(const t of s.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}(!o.typed||!s.typed)&&(e.typed=!1),e.value.set(o.value,s.value)}}else h(this,"type",e,t);return e}}},Fl.mapAsync=function e(t,r,n){return{kind:"schema",type:"map",reference:e,expects:"Map",async:!0,key:t,value:r,message:n,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r instanceof Map){e.typed=!0,e.value=new Map;const n=await Promise.all([...r].map(([e,r])=>Promise.all([e,r,this.key["~run"]({value:e},t),this.value["~run"]({value:r},t)])));for(const[i,o,s,a]of n){if(s.issues){const n={type:"map",origin:"key",input:r,key:i,value:o};for(const t of s.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}if(a.issues){const n={type:"map",origin:"value",input:r,key:i,value:o};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}(!s.typed||!a.typed)&&(e.typed=!1),e.value.set(s.value,a.value)}}else h(this,"type",e,t);return e}}},Fl.mapItems=function e(t){return{kind:"transformation",type:"map_items",reference:e,async:!1,operation:t,"~run"(e){return e.value=e.value.map(this.operation),e}}},Fl.maxBytes=function e(t,r){return{kind:"validation",type:"max_bytes",reference:e,async:!1,expects:`<=${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=p(e.value);r>this.requirement&&h(this,"bytes",e,t,{received:`${r}`})}return e}}},Fl.maxEntries=function e(t,r){return{kind:"validation",type:"max_entries",reference:e,async:!1,expects:`<=${t}`,requirement:t,message:r,"~run"(e,t){if(!e.typed)return e;const r=Object.keys(e.value).length;return e.typed&&r>this.requirement&&h(this,"entries",e,t,{received:`${r}`}),e}}},Fl.maxGraphemes=function e(t,r){return{kind:"validation",type:"max_graphemes",reference:e,async:!1,expects:`<=${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=d(e.value);r>this.requirement&&h(this,"graphemes",e,t,{received:`${r}`})}return e}}},Fl.maxLength=function e(t,r){return{kind:"validation",type:"max_length",reference:e,async:!1,expects:`<=${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.length>this.requirement&&h(this,"length",e,t,{received:`${e.value.length}`}),e}}},Fl.maxSize=function e(t,r){return{kind:"validation",type:"max_size",reference:e,async:!1,expects:`<=${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.size>this.requirement&&h(this,"size",e,t,{received:`${e.value.size}`}),e}}},Fl.maxValue=function e(t,r){return{kind:"validation",type:"max_value",reference:e,async:!1,expects:`<=${t instanceof Date?t.toJSON():l(t)}`,requirement:t,message:r,"~run"(e,t){return e.typed&&!(e.value<=this.requirement)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.maxWords=function e(t,r,n){return{kind:"validation",type:"max_words",reference:e,async:!1,expects:`<=${r}`,locales:t,requirement:r,message:n,"~run"(e,t){if(e.typed){const r=m(this.locales,e.value);r>this.requirement&&h(this,"words",e,t,{received:`${r}`})}return e}}},Fl.message=function(e,t){return{...e,get"~standard"(){return g(this)},"~run":(r,n)=>e["~run"](r,{...n,message:t})}},Fl.metadata=function e(t){return{kind:"metadata",type:"metadata",reference:e,metadata:t}},Fl.mimeType=function e(t,r){return{kind:"validation",type:"mime_type",reference:e,async:!1,expects:E(t.map(e=>`"${e}"`),"|"),requirement:t,message:r,"~run"(e,t){return e.typed&&!this.requirement.includes(e.value.type)&&h(this,"MIME type",e,t,{received:`"${e.value.type}"`}),e}}},Fl.minBytes=function e(t,r){return{kind:"validation",type:"min_bytes",reference:e,async:!1,expects:`>=${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=p(e.value);r<this.requirement&&h(this,"bytes",e,t,{received:`${r}`})}return e}}},Fl.minEntries=function e(t,r){return{kind:"validation",type:"min_entries",reference:e,async:!1,expects:`>=${t}`,requirement:t,message:r,"~run"(e,t){if(!e.typed)return e;const r=Object.keys(e.value).length;return e.typed&&r<this.requirement&&h(this,"entries",e,t,{received:`${r}`}),e}}},Fl.minGraphemes=function e(t,r){return{kind:"validation",type:"min_graphemes",reference:e,async:!1,expects:`>=${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=d(e.value);r<this.requirement&&h(this,"graphemes",e,t,{received:`${r}`})}return e}}},Fl.minLength=function e(t,r){return{kind:"validation",type:"min_length",reference:e,async:!1,expects:`>=${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.length<this.requirement&&h(this,"length",e,t,{received:`${e.value.length}`}),e}}},Fl.minSize=function e(t,r){return{kind:"validation",type:"min_size",reference:e,async:!1,expects:`>=${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.size<this.requirement&&h(this,"size",e,t,{received:`${e.value.size}`}),e}}},Fl.minValue=function e(t,r){return{kind:"validation",type:"min_value",reference:e,async:!1,expects:`>=${t instanceof Date?t.toJSON():l(t)}`,requirement:t,message:r,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.minWords=function e(t,r,n){return{kind:"validation",type:"min_words",reference:e,async:!1,expects:`>=${r}`,locales:t,requirement:r,message:n,"~run"(e,t){if(e.typed){const r=m(this.locales,e.value);r<this.requirement&&h(this,"words",e,t,{received:`${r}`})}return e}}},Fl.multipleOf=function e(t,r){return{kind:"validation",type:"multiple_of",reference:e,async:!1,expects:`%${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value%this.requirement!=0&&h(this,"multiple",e,t),e}}},Fl.nan=function e(t){return{kind:"schema",type:"nan",reference:e,expects:"NaN",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return Number.isNaN(e.value)?e.typed=!0:h(this,"type",e,t),e}}},Fl.nanoid=function e(t){return{kind:"validation",type:"nanoid",reference:e,async:!1,expects:null,requirement:W,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"Nano ID",e,t),e}}},Fl.never=function e(t){return{kind:"schema",type:"never",reference:e,expects:"never",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return h(this,"type",e,t),e}}},Fl.nonEmpty=function e(t){return{kind:"validation",type:"non_empty",reference:e,async:!1,expects:"!0",message:t,"~run"(e,t){return e.typed&&0===e.value.length&&h(this,"length",e,t,{received:"0"}),e}}},Fl.nonNullable=function e(t,r){return{kind:"schema",type:"non_nullable",reference:e,expects:"!null",async:!1,wrapped:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){return null!==e.value&&(e=this.wrapped["~run"](e,t)),null===e.value&&h(this,"type",e,t),e}}},Fl.nonNullableAsync=function e(t,r){return{kind:"schema",type:"non_nullable",reference:e,expects:"!null",async:!0,wrapped:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){return null!==e.value&&(e=await this.wrapped["~run"](e,t)),null===e.value&&h(this,"type",e,t),e}}},Fl.nonNullish=function e(t,r){return{kind:"schema",type:"non_nullish",reference:e,expects:"(!null & !undefined)",async:!1,wrapped:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){return null===e.value||void 0===e.value||(e=this.wrapped["~run"](e,t)),(null===e.value||void 0===e.value)&&h(this,"type",e,t),e}}},Fl.nonNullishAsync=function e(t,r){return{kind:"schema",type:"non_nullish",reference:e,expects:"(!null & !undefined)",async:!0,wrapped:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){return null===e.value||void 0===e.value||(e=await this.wrapped["~run"](e,t)),(null===e.value||void 0===e.value)&&h(this,"type",e,t),e}}},Fl.nonOptional=ue,Fl.nonOptionalAsync=ce,Fl.normalize=function e(t){return{kind:"transformation",type:"normalize",reference:e,async:!1,form:t,"~run"(e){return e.value=e.value.normalize(this.form),e}}},Fl.notBytes=function e(t,r){return{kind:"validation",type:"not_bytes",reference:e,async:!1,expects:`!${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=p(e.value);r===this.requirement&&h(this,"bytes",e,t,{received:`${r}`})}return e}}},Fl.notEntries=function e(t,r){return{kind:"validation",type:"not_entries",reference:e,async:!1,expects:`!${t}`,requirement:t,message:r,"~run"(e,t){if(!e.typed)return e;const r=Object.keys(e.value).length;return e.typed&&r===this.requirement&&h(this,"entries",e,t,{received:`${r}`}),e}}},Fl.notGraphemes=function e(t,r){return{kind:"validation",type:"not_graphemes",reference:e,async:!1,expects:`!${t}`,requirement:t,message:r,"~run"(e,t){if(e.typed){const r=d(e.value);r===this.requirement&&h(this,"graphemes",e,t,{received:`${r}`})}return e}}},Fl.notLength=function e(t,r){return{kind:"validation",type:"not_length",reference:e,async:!1,expects:`!${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.length===this.requirement&&h(this,"length",e,t,{received:`${e.value.length}`}),e}}},Fl.notSize=function e(t,r){return{kind:"validation",type:"not_size",reference:e,async:!1,expects:`!${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.size===this.requirement&&h(this,"size",e,t,{received:`${e.value.size}`}),e}}},Fl.notValue=function e(t,r){return{kind:"validation",type:"not_value",reference:e,async:!1,expects:t instanceof Date?`!${t.toJSON()}`:`!${l(t)}`,requirement:t,message:r,"~run"(e,t){return e.typed&&this.requirement<=e.value&&this.requirement>=e.value&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.notValues=function e(t,r){return{kind:"validation",type:"not_values",reference:e,async:!1,expects:`!${E(t.map(e=>e instanceof Date?e.toJSON():l(e)),"|")}`,requirement:t,message:r,"~run"(e,t){return e.typed&&this.requirement.some(t=>t<=e.value&&t>=e.value)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.notWords=function e(t,r,n){return{kind:"validation",type:"not_words",reference:e,async:!1,expects:`!${r}`,locales:t,requirement:r,message:n,"~run"(e,t){if(e.typed){const r=m(this.locales,e.value);r===this.requirement&&h(this,"words",e,t,{received:`${r}`})}return e}}},Fl.null=fe,Fl.null_=fe,Fl.nullable=function e(t,r){return{kind:"schema",type:"nullable",reference:e,expects:`(${t.expects} | null)`,async:!1,wrapped:t,default:r,get"~standard"(){return g(this)},"~run"(e,t){return null===e.value&&(void 0!==this.default&&(e.value=ie(this,e,t)),null===e.value)?(e.typed=!0,e):this.wrapped["~run"](e,t)}}},Fl.nullableAsync=function e(t,r){return{kind:"schema",type:"nullable",reference:e,expects:`(${t.expects} | null)`,async:!0,wrapped:t,default:r,get"~standard"(){return g(this)},async"~run"(e,t){return null===e.value&&(void 0!==this.default&&(e.value=await ie(this,e,t)),null===e.value)?(e.typed=!0,e):this.wrapped["~run"](e,t)}}},Fl.nullish=function e(t,r){return{kind:"schema",type:"nullish",reference:e,expects:`(${t.expects} | null | undefined)`,async:!1,wrapped:t,default:r,get"~standard"(){return g(this)},"~run"(e,t){return null!==e.value&&void 0!==e.value||(void 0!==this.default&&(e.value=ie(this,e,t)),null!==e.value&&void 0!==e.value)?this.wrapped["~run"](e,t):(e.typed=!0,e)}}},Fl.nullishAsync=function e(t,r){return{kind:"schema",type:"nullish",reference:e,expects:`(${t.expects} | null | undefined)`,async:!0,wrapped:t,default:r,get"~standard"(){return g(this)},async"~run"(e,t){return null!==e.value&&void 0!==e.value||(void 0!==this.default&&(e.value=await ie(this,e,t)),null!==e.value&&void 0!==e.value)?this.wrapped["~run"](e,t):(e.typed=!0,e)}}},Fl.number=function e(t){return{kind:"schema",type:"number",reference:e,expects:"number",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return"number"!=typeof e.value||isNaN(e.value)?h(this,"type",e,t):e.typed=!0,e}}},Fl.object=function e(t,r){return{kind:"schema",type:"object",reference:e,expects:"Object",async:!1,entries:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};for(const n in this.entries){const i=this.entries[n];if(n in r||("exact_optional"===i.type||"optional"===i.type||"nullish"===i.type)&&void 0!==i.default){const o=n in r?r[n]:ie(i),s=i["~run"]({value:o},t);if(s.issues){const i={type:"object",origin:"value",input:r,key:n,value:o};for(const t of s.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value[n]=s.value}else if(void 0!==i.fallback)e.value[n]=ne(i);else if("exact_optional"!==i.type&&"optional"!==i.type&&"nullish"!==i.type&&(h(this,"key",e,t,{input:void 0,expected:`"${n}"`,path:[{type:"object",origin:"key",input:r,key:n,value:r[n]}]}),t.abortEarly))break}}else h(this,"type",e,t);return e}}},Fl.objectAsync=function e(t,r){return{kind:"schema",type:"object",reference:e,expects:"Object",async:!0,entries:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};const n=await Promise.all(Object.entries(this.entries).map(async([e,n])=>{if(e in r||("exact_optional"===n.type||"optional"===n.type||"nullish"===n.type)&&void 0!==n.default){const i=e in r?r[e]:await ie(n);return[e,i,n,await n["~run"]({value:i},t)]}return[e,r[e],n,null]}));for(const[i,o,s,a]of n)if(a){if(a.issues){const n={type:"object",origin:"value",input:r,key:i,value:o};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value[i]=a.value}else if(void 0!==s.fallback)e.value[i]=await ne(s);else if("exact_optional"!==s.type&&"optional"!==s.type&&"nullish"!==s.type&&(h(this,"key",e,t,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:o}]}),t.abortEarly))break}else h(this,"type",e,t);return e}}},Fl.objectWithRest=function e(t,r,n){return{kind:"schema",type:"object_with_rest",reference:e,expects:"Object",async:!1,entries:t,rest:r,message:n,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};for(const n in this.entries){const i=this.entries[n];if(n in r||("exact_optional"===i.type||"optional"===i.type||"nullish"===i.type)&&void 0!==i.default){const o=n in r?r[n]:ie(i),s=i["~run"]({value:o},t);if(s.issues){const i={type:"object",origin:"value",input:r,key:n,value:o};for(const t of s.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value[n]=s.value}else if(void 0!==i.fallback)e.value[n]=ne(i);else if("exact_optional"!==i.type&&"optional"!==i.type&&"nullish"!==i.type&&(h(this,"key",e,t,{input:void 0,expected:`"${n}"`,path:[{type:"object",origin:"key",input:r,key:n,value:r[n]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly)for(const n in r)if(v(r,n)&&!(n in this.entries)){const i=this.rest["~run"]({value:r[n]},t);if(i.issues){const o={type:"object",origin:"value",input:r,key:n,value:r[n]};for(const t of i.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||(e.issues=i.issues),t.abortEarly){e.typed=!1;break}}i.typed||(e.typed=!1),e.value[n]=i.value}}else h(this,"type",e,t);return e}}},Fl.objectWithRestAsync=function e(t,r,n){return{kind:"schema",type:"object_with_rest",reference:e,expects:"Object",async:!0,entries:t,rest:r,message:n,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};const[n,i]=await Promise.all([Promise.all(Object.entries(this.entries).map(async([e,n])=>{if(e in r||("exact_optional"===n.type||"optional"===n.type||"nullish"===n.type)&&void 0!==n.default){const i=e in r?r[e]:await ie(n);return[e,i,n,await n["~run"]({value:i},t)]}return[e,r[e],n,null]})),Promise.all(Object.entries(r).filter(([e])=>v(r,e)&&!(e in this.entries)).map(async([e,r])=>[e,r,await this.rest["~run"]({value:r},t)]))]);for(const[o,s,a,u]of n)if(u){if(u.issues){const n={type:"object",origin:"value",input:r,key:o,value:s};for(const t of u.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=u.issues),t.abortEarly){e.typed=!1;break}}u.typed||(e.typed=!1),e.value[o]=u.value}else if(void 0!==a.fallback)e.value[o]=await ne(a);else if("exact_optional"!==a.type&&"optional"!==a.type&&"nullish"!==a.type&&(h(this,"key",e,t,{input:void 0,expected:`"${o}"`,path:[{type:"object",origin:"key",input:r,key:o,value:s}]}),t.abortEarly))break;if(!e.issues||!t.abortEarly)for(const[o,s,a]of i){if(a.issues){const n={type:"object",origin:"value",input:r,key:o,value:s};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value[o]=a.value}}else h(this,"type",e,t);return e}}},Fl.octal=function e(t){return{kind:"validation",type:"octal",reference:e,async:!1,expects:null,requirement:$,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"octal",e,t),e}}},Fl.omit=function(e,t){const r={...e.entries};for(const n of t)delete r[n];return{...e,entries:r,get"~standard"(){return g(this)}}},Fl.optional=le,Fl.optionalAsync=he,Fl.parse=me,Fl.parseAsync=be,Fl.parseJson=function e(t,r){return{kind:"transformation",type:"parse_json",reference:e,config:t,message:r,async:!1,"~run"(e,t){try{e.value=JSON.parse(e.value,this.config?.reviver)}catch(r){if(!(r instanceof Error))throw r;h(this,"JSON",e,t,{received:`"${r.message}"`}),e.typed=!1}return e}}},Fl.parser=function(e,t){const r=r=>me(e,r,t);return r.schema=e,r.config=t,r},Fl.parserAsync=function(e,t){const r=r=>be(e,r,t);return r.schema=e,r.config=t,r},Fl.partial=function(e,t){const r={};for(const n in e.entries)r[n]=!t||t.includes(n)?le(e.entries[n]):e.entries[n];return{...e,entries:r,get"~standard"(){return g(this)}}},Fl.partialAsync=function(e,t){const r={};for(const n in e.entries)r[n]=!t||t.includes(n)?he(e.entries[n]):e.entries[n];return{...e,entries:r,get"~standard"(){return g(this)}}},Fl.partialCheck=function e(t,r,n){return{kind:"validation",type:"partial_check",reference:e,async:!1,expects:null,paths:t,requirement:r,message:n,"~run"(e,r){return(e.typed||re(e,t))&&!this.requirement(e.value)&&h(this,"input",e,r),e}}},Fl.partialCheckAsync=function e(t,r,n){return{kind:"validation",type:"partial_check",reference:e,async:!0,expects:null,paths:t,requirement:r,message:n,async"~run"(e,r){return(e.typed||re(e,t))&&!(await this.requirement(e.value))&&h(this,"input",e,r),e}}},Fl.pick=function(e,t){const r={};for(const n of t)r[n]=e.entries[n];return{...e,entries:r,get"~standard"(){return g(this)}}},Fl.picklist=pe,Fl.pipe=function(...e){return{...e[0],pipe:e,get"~standard"(){return g(this)},"~run"(t,r){for(const n of e)if("metadata"!==n.kind){if(t.issues&&("schema"===n.kind||"transformation"===n.kind)){t.typed=!1;break}(!t.issues||!r.abortEarly&&!r.abortPipeEarly)&&(t=n["~run"](t,r))}return t}}},Fl.pipeAsync=function(...e){return{...e[0],pipe:e,async:!0,get"~standard"(){return g(this)},async"~run"(t,r){for(const n of e)if("metadata"!==n.kind){if(t.issues&&("schema"===n.kind||"transformation"===n.kind)){t.typed=!1;break}(!t.issues||!r.abortEarly&&!r.abortPipeEarly)&&(t=await n["~run"](t,r))}return t}}},Fl.promise=function e(t){return{kind:"schema",type:"promise",reference:e,expects:"Promise",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return e.value instanceof Promise?e.typed=!0:h(this,"type",e,t),e}}},Fl.rawCheck=function e(t){return{kind:"validation",type:"raw_check",reference:e,async:!1,expects:null,"~run"(e,r){return t({dataset:e,config:r,addIssue:t=>h(this,t?.label??"input",e,r,t)}),e}}},Fl.rawCheckAsync=function e(t){return{kind:"validation",type:"raw_check",reference:e,async:!0,expects:null,async"~run"(e,r){return await t({dataset:e,config:r,addIssue:t=>h(this,t?.label??"input",e,r,t)}),e}}},Fl.rawTransform=function e(t){return{kind:"transformation",type:"raw_transform",reference:e,async:!1,"~run"(e,r){const n=t({dataset:e,config:r,addIssue:t=>h(this,t?.label??"input",e,r,t),NEVER:null});return e.issues?e.typed=!1:e.value=n,e}}},Fl.rawTransformAsync=function e(t){return{kind:"transformation",type:"raw_transform",reference:e,async:!0,async"~run"(e,r){const n=await t({dataset:e,config:r,addIssue:t=>h(this,t?.label??"input",e,r,t),NEVER:null});return e.issues?e.typed=!1:e.value=n,e}}},Fl.readonly=function e(){return{kind:"transformation",type:"readonly",reference:e,async:!1,"~run":e=>e}},Fl.record=function e(t,r,n){return{kind:"schema",type:"record",reference:e,expects:"Object",async:!1,key:t,value:r,message:n,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};for(const n in r)if(v(r,n)){const i=r[n],o=this.key["~run"]({value:n},t);if(o.issues){const s={type:"object",origin:"key",input:r,key:n,value:i};for(const t of o.issues)t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}const s=this.value["~run"]({value:i},t);if(s.issues){const o={type:"object",origin:"value",input:r,key:n,value:i};for(const t of s.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}(!o.typed||!s.typed)&&(e.typed=!1),o.typed&&(e.value[o.value]=s.value)}}else h(this,"type",e,t);return e}}},Fl.recordAsync=function e(t,r,n){return{kind:"schema",type:"record",reference:e,expects:"Object",async:!0,key:t,value:r,message:n,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};const n=await Promise.all(Object.entries(r).filter(([e])=>v(r,e)).map(([e,r])=>Promise.all([e,r,this.key["~run"]({value:e},t),this.value["~run"]({value:r},t)])));for(const[i,o,s,a]of n){if(s.issues){const n={type:"object",origin:"key",input:r,key:i,value:o};for(const t of s.issues)t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}if(a.issues){const n={type:"object",origin:"value",input:r,key:i,value:o};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}(!s.typed||!a.typed)&&(e.typed=!1),s.typed&&(e.value[s.value]=a.value)}}else h(this,"type",e,t);return e}}},Fl.reduceItems=function e(t,r){return{kind:"transformation",type:"reduce_items",reference:e,async:!1,operation:t,initial:r,"~run"(e){return e.value=e.value.reduce(this.operation,this.initial),e}}},Fl.regex=function e(t,r){return{kind:"validation",type:"regex",reference:e,async:!1,expects:`${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"format",e,t),e}}},Fl.required=function(e,t,r){const n=Array.isArray(t)?t:void 0,i=Array.isArray(t)?r:t,o={};for(const s in e.entries)o[s]=!n||n.includes(s)?ue(e.entries[s],i):e.entries[s];return{...e,entries:o,get"~standard"(){return g(this)}}},Fl.requiredAsync=function(e,t,r){const n=Array.isArray(t)?t:void 0,i=Array.isArray(t)?r:t,o={};for(const s in e.entries)o[s]=!n||n.includes(s)?ce(e.entries[s],i):e.entries[s];return{...e,entries:o,get"~standard"(){return g(this)}}},Fl.returns=function e(t){return{kind:"transformation",type:"returns",reference:e,async:!1,schema:t,"~run"(e,t){const r=e.value;return e.value=(...e)=>{const n=this.schema["~run"]({value:r(...e)},t);if(n.issues)throw new S(n.issues);return n.value},e}}},Fl.returnsAsync=function e(t){return{kind:"transformation",type:"returns",reference:e,async:!1,schema:t,"~run"(e,t){const r=e.value;return e.value=async(...e)=>{const n=await this.schema["~run"]({value:await r(...e)},t);if(n.issues)throw new S(n.issues);return n.value},e}}},Fl.rfcEmail=function e(t){return{kind:"validation",type:"rfc_email",reference:e,expects:null,async:!1,requirement:G,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"email",e,t),e}}},Fl.safeInteger=function e(t){return{kind:"validation",type:"safe_integer",reference:e,async:!1,expects:null,requirement:Number.isSafeInteger,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"safe integer",e,t),e}}},Fl.safeParse=we,Fl.safeParseAsync=ve,Fl.safeParser=function(e,t){const r=r=>we(e,r,t);return r.schema=e,r.config=t,r},Fl.safeParserAsync=function(e,t){const r=r=>ve(e,r,t);return r.schema=e,r.config=t,r},Fl.set=function e(t,r){return{kind:"schema",type:"set",reference:e,expects:"Set",async:!1,value:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r instanceof Set){e.typed=!0,e.value=new Set;for(const n of r){const i=this.value["~run"]({value:n},t);if(i.issues){const o={type:"set",origin:"value",input:r,key:null,value:n};for(const t of i.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||(e.issues=i.issues),t.abortEarly){e.typed=!1;break}}i.typed||(e.typed=!1),e.value.add(i.value)}}else h(this,"type",e,t);return e}}},Fl.setAsync=function e(t,r){return{kind:"schema",type:"set",reference:e,expects:"Set",async:!0,value:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r instanceof Set){e.typed=!0,e.value=new Set;const n=await Promise.all([...r].map(async e=>[e,await this.value["~run"]({value:e},t)]));for(const[i,o]of n){if(o.issues){const n={type:"set",origin:"value",input:r,key:null,value:i};for(const t of o.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.add(o.value)}}else h(this,"type",e,t);return e}}},Fl.setGlobalConfig=function(t){e={...e,...t}},Fl.setGlobalMessage=function(e,r){t||(t=new Map),t.set(r,e)},Fl.setSchemaMessage=function(e,t){r||(r=new Map),r.set(t,e)},Fl.setSpecificMessage=function(e,t,r){n||(n=new Map),n.get(e)||n.set(e,new Map),n.get(e).set(r,t)},Fl.size=function e(t,r){return{kind:"validation",type:"size",reference:e,async:!1,expects:`${t}`,requirement:t,message:r,"~run"(e,t){return e.typed&&e.value.size!==this.requirement&&h(this,"size",e,t,{received:`${e.value.size}`}),e}}},Fl.slug=function e(t){return{kind:"validation",type:"slug",reference:e,async:!1,expects:null,requirement:X,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"slug",e,t),e}}},Fl.someItem=function e(t,r){return{kind:"validation",type:"some_item",reference:e,async:!1,expects:null,requirement:t,message:r,"~run"(e,t){return e.typed&&!e.value.some(this.requirement)&&h(this,"item",e,t),e}}},Fl.sortItems=function e(t){return{kind:"transformation",type:"sort_items",reference:e,async:!1,operation:t,"~run"(e){return e.value=e.value.sort(this.operation),e}}},Fl.startsWith=function e(t,r){return{kind:"validation",type:"starts_with",reference:e,async:!1,expects:`"${t}"`,requirement:t,message:r,"~run"(e,t){return e.typed&&!e.value.startsWith(this.requirement)&&h(this,"start",e,t,{received:`"${e.value.slice(0,this.requirement.length)}"`}),e}}},Fl.strictObject=function e(t,r){return{kind:"schema",type:"strict_object",reference:e,expects:"Object",async:!1,entries:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};for(const n in this.entries){const i=this.entries[n];if(n in r||("exact_optional"===i.type||"optional"===i.type||"nullish"===i.type)&&void 0!==i.default){const o=n in r?r[n]:ie(i),s=i["~run"]({value:o},t);if(s.issues){const i={type:"object",origin:"value",input:r,key:n,value:o};for(const t of s.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value[n]=s.value}else if(void 0!==i.fallback)e.value[n]=ne(i);else if("exact_optional"!==i.type&&"optional"!==i.type&&"nullish"!==i.type&&(h(this,"key",e,t,{input:void 0,expected:`"${n}"`,path:[{type:"object",origin:"key",input:r,key:n,value:r[n]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly)for(const n in r)if(!(n in this.entries)){h(this,"key",e,t,{input:n,expected:"never",path:[{type:"object",origin:"key",input:r,key:n,value:r[n]}]});break}}else h(this,"type",e,t);return e}}},Fl.strictObjectAsync=function e(t,r){return{kind:"schema",type:"strict_object",reference:e,expects:"Object",async:!0,entries:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};const n=await Promise.all(Object.entries(this.entries).map(async([e,n])=>{if(e in r||("exact_optional"===n.type||"optional"===n.type||"nullish"===n.type)&&void 0!==n.default){const i=e in r?r[e]:await ie(n);return[e,i,n,await n["~run"]({value:i},t)]}return[e,r[e],n,null]}));for(const[i,o,s,a]of n)if(a){if(a.issues){const n={type:"object",origin:"value",input:r,key:i,value:o};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value[i]=a.value}else if(void 0!==s.fallback)e.value[i]=await ne(s);else if("exact_optional"!==s.type&&"optional"!==s.type&&"nullish"!==s.type&&(h(this,"key",e,t,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:o}]}),t.abortEarly))break;if(!e.issues||!t.abortEarly)for(const i in r)if(!(i in this.entries)){h(this,"key",e,t,{input:i,expected:"never",path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]});break}}else h(this,"type",e,t);return e}}},Fl.strictTuple=function e(t,r){return{kind:"schema",type:"strict_tuple",reference:e,expects:"Array",async:!1,items:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];for(let n=0;n<this.items.length;n++){const i=r[n],o=this.items[n]["~run"]({value:i},t);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}(!e.issues||!t.abortEarly)&&this.items.length<r.length&&h(this,"type",e,t,{input:r[this.items.length],expected:"never",path:[{type:"array",origin:"value",input:r,key:this.items.length,value:r[this.items.length]}]})}else h(this,"type",e,t);return e}}},Fl.strictTupleAsync=function e(t,r){return{kind:"schema",type:"strict_tuple",reference:e,expects:"Array",async:!0,items:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];const n=await Promise.all(this.items.map(async(e,n)=>{const i=r[n];return[n,i,await e["~run"]({value:i},t)]}));for(const[i,o,s]of n){if(s.issues){const n={type:"array",origin:"value",input:r,key:i,value:o};for(const t of s.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value.push(s.value)}(!e.issues||!t.abortEarly)&&this.items.length<r.length&&h(this,"type",e,t,{input:r[this.items.length],expected:"never",path:[{type:"array",origin:"value",input:r,key:this.items.length,value:r[this.items.length]}]})}else h(this,"type",e,t);return e}}},Fl.string=function e(t){return{kind:"schema",type:"string",reference:e,expects:"string",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return"string"==typeof e.value?e.typed=!0:h(this,"type",e,t),e}}},Fl.stringifyJson=function e(t,r){return{kind:"transformation",type:"stringify_json",reference:e,message:r,config:t,async:!1,"~run"(e,t){try{const r=JSON.stringify(e.value,this.config?.replacer,this.config?.space);void 0===r&&(h(this,"JSON",e,t),e.typed=!1),e.value=r}catch(r){if(!(r instanceof Error))throw r;h(this,"JSON",e,t,{received:`"${r.message}"`}),e.typed=!1}return e}}},Fl.summarize=function(e){let t="";for(const r of e){t&&(t+="\n"),t+=`× ${r.message}`;const e=_(r);e&&(t+=`\n → at ${e}`)}return t},Fl.symbol=function e(t){return{kind:"schema",type:"symbol",reference:e,expects:"symbol",async:!1,message:t,get"~standard"(){return g(this)},"~run"(e,t){return"symbol"==typeof e.value?e.typed=!0:h(this,"type",e,t),e}}},Fl.title=function e(t){return{kind:"metadata",type:"title",reference:e,title:t}},Fl.toBigint=function e(t){return{kind:"transformation",type:"to_bigint",reference:e,async:!1,message:t,"~run"(e,t){try{e.value=BigInt(e.value)}catch{h(this,"bigint",e,t),e.typed=!1}return e}}},Fl.toBoolean=function e(){return{kind:"transformation",type:"to_boolean",reference:e,async:!1,"~run":e=>(e.value=!!e.value,e)}},Fl.toDate=function e(t){return{kind:"transformation",type:"to_date",reference:e,async:!1,message:t,"~run"(e,t){try{e.value=new Date(e.value),isNaN(e.value)&&(h(this,"date",e,t,{received:'"Invalid Date"'}),e.typed=!1)}catch{h(this,"date",e,t),e.typed=!1}return e}}},Fl.toLowerCase=function e(){return{kind:"transformation",type:"to_lower_case",reference:e,async:!1,"~run":e=>(e.value=e.value.toLowerCase(),e)}},Fl.toMaxValue=function e(t){return{kind:"transformation",type:"to_max_value",reference:e,async:!1,requirement:t,"~run"(e){return e.value=e.value>this.requirement?this.requirement:e.value,e}}},Fl.toMinValue=function e(t){return{kind:"transformation",type:"to_min_value",reference:e,async:!1,requirement:t,"~run"(e){return e.value=e.value<this.requirement?this.requirement:e.value,e}}},Fl.toNumber=function e(t){return{kind:"transformation",type:"to_number",reference:e,async:!1,message:t,"~run"(e,t){try{e.value=Number(e.value),isNaN(e.value)&&(h(this,"number",e,t),e.typed=!1)}catch{h(this,"number",e,t),e.typed=!1}return e}}},Fl.toString=function e(t){return{kind:"transformation",type:"to_string",reference:e,async:!1,message:t,"~run"(e,t){try{e.value=String(e.value)}catch{h(this,"string",e,t),e.typed=!1}return e}}},Fl.toUpperCase=function e(){return{kind:"transformation",type:"to_upper_case",reference:e,async:!1,"~run":e=>(e.value=e.value.toUpperCase(),e)}},Fl.transform=function e(t){return{kind:"transformation",type:"transform",reference:e,async:!1,operation:t,"~run"(e){return e.value=this.operation(e.value),e}}},Fl.transformAsync=function e(t){return{kind:"transformation",type:"transform",reference:e,async:!0,operation:t,async"~run"(e){return e.value=await this.operation(e.value),e}}},Fl.trim=function e(){return{kind:"transformation",type:"trim",reference:e,async:!1,"~run":e=>(e.value=e.value.trim(),e)}},Fl.trimEnd=function e(){return{kind:"transformation",type:"trim_end",reference:e,async:!1,"~run":e=>(e.value=e.value.trimEnd(),e)}},Fl.trimStart=function e(){return{kind:"transformation",type:"trim_start",reference:e,async:!1,"~run":e=>(e.value=e.value.trimStart(),e)}},Fl.tuple=function e(t,r){return{kind:"schema",type:"tuple",reference:e,expects:"Array",async:!1,items:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];for(let n=0;n<this.items.length;n++){const i=r[n],o=this.items[n]["~run"]({value:i},t);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}}else h(this,"type",e,t);return e}}},Fl.tupleAsync=function e(t,r){return{kind:"schema",type:"tuple",reference:e,expects:"Array",async:!0,items:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];const n=await Promise.all(this.items.map(async(e,n)=>{const i=r[n];return[n,i,await e["~run"]({value:i},t)]}));for(const[i,o,s]of n){if(s.issues){const n={type:"array",origin:"value",input:r,key:i,value:o};for(const t of s.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value.push(s.value)}}else h(this,"type",e,t);return e}}},Fl.tupleWithRest=function e(t,r,n){return{kind:"schema",type:"tuple_with_rest",reference:e,expects:"Array",async:!1,items:t,rest:r,message:n,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];for(let n=0;n<this.items.length;n++){const i=r[n],o=this.items[n]["~run"]({value:i},t);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}if(!e.issues||!t.abortEarly)for(let n=this.items.length;n<r.length;n++){const i=r[n],o=this.rest["~run"]({value:i},t);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const t of o.issues)t.path?t.path.unshift(s):t.path=[s],e.issues?.push(t);if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}}else h(this,"type",e,t);return e}}},Fl.tupleWithRestAsync=function e(t,r,n){return{kind:"schema",type:"tuple_with_rest",reference:e,expects:"Array",async:!0,items:t,rest:r,message:n,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(Array.isArray(r)){e.typed=!0,e.value=[];const[n,i]=await Promise.all([Promise.all(this.items.map(async(e,n)=>{const i=r[n];return[n,i,await e["~run"]({value:i},t)]})),Promise.all(r.slice(this.items.length).map(async(e,r)=>[r+this.items.length,e,await this.rest["~run"]({value:e},t)]))]);for(const[o,s,a]of n){if(a.issues){const n={type:"array",origin:"value",input:r,key:o,value:s};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value.push(a.value)}if(!e.issues||!t.abortEarly)for(const[o,s,a]of i){if(a.issues){const n={type:"array",origin:"value",input:r,key:o,value:s};for(const t of a.issues)t.path?t.path.unshift(n):t.path=[n],e.issues?.push(t);if(e.issues||(e.issues=a.issues),t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value.push(a.value)}}else h(this,"type",e,t);return e}}},Fl.ulid=function e(t){return{kind:"validation",type:"ulid",reference:e,async:!1,expects:null,requirement:Y,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"ULID",e,t),e}}},Fl.undefined=de,Fl.undefined_=de,Fl.undefinedable=function e(t,r){return{kind:"schema",type:"undefinedable",reference:e,expects:`(${t.expects} | undefined)`,async:!1,wrapped:t,default:r,get"~standard"(){return g(this)},"~run"(e,t){return void 0===e.value&&(void 0!==this.default&&(e.value=ie(this,e,t)),void 0===e.value)?(e.typed=!0,e):this.wrapped["~run"](e,t)}}},Fl.undefinedableAsync=function e(t,r){return{kind:"schema",type:"undefinedable",reference:e,expects:`(${t.expects} | undefined)`,async:!0,wrapped:t,default:r,get"~standard"(){return g(this)},async"~run"(e,t){return void 0===e.value&&(void 0!==this.default&&(e.value=await ie(this,e,t)),void 0===e.value)?(e.typed=!0,e):this.wrapped["~run"](e,t)}}},Fl.union=function e(t,r){return{kind:"schema",type:"union",reference:e,expects:E(t.map(e=>e.expects),"|"),async:!1,options:t,message:r,get"~standard"(){return g(this)},"~run"(e,t){let r,n,i;for(const o of this.options){const s=o["~run"]({value:e.value},t);if(s.typed){if(!s.issues){r=s;break}n?n.push(s):n=[s]}else i?i.push(s):i=[s]}if(r)return r;if(n){if(1===n.length)return n[0];h(this,"type",e,t,{issues:ye(n)}),e.typed=!0}else{if(1===i?.length)return i[0];h(this,"type",e,t,{issues:ye(i)})}return e}}},Fl.unionAsync=function e(t,r){return{kind:"schema",type:"union",reference:e,expects:E(t.map(e=>e.expects),"|"),async:!0,options:t,message:r,get"~standard"(){return g(this)},async"~run"(e,t){let r,n,i;for(const o of this.options){const s=await o["~run"]({value:e.value},t);if(s.typed){if(!s.issues){r=s;break}n?n.push(s):n=[s]}else i?i.push(s):i=[s]}if(r)return r;if(n){if(1===n.length)return n[0];h(this,"type",e,t,{issues:ye(n)}),e.typed=!0}else{if(1===i?.length)return i[0];h(this,"type",e,t,{issues:ye(i)})}return e}}},Fl.unknown=function e(){return{kind:"schema",type:"unknown",reference:e,expects:"unknown",async:!1,get"~standard"(){return g(this)},"~run":e=>(e.typed=!0,e)}},Fl.unwrap=function(e){return e.wrapped},Fl.url=function e(t){return{kind:"validation",type:"url",reference:e,async:!1,expects:null,requirement(e){try{return new URL(e),!0}catch{return!1}},message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&h(this,"URL",e,t),e}}},Fl.uuid=function e(t){return{kind:"validation",type:"uuid",reference:e,async:!1,expects:null,requirement:Z,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&h(this,"UUID",e,t),e}}},Fl.value=function e(t,r){return{kind:"validation",type:"value",reference:e,async:!1,expects:t instanceof Date?t.toJSON():l(t),requirement:t,message:r,"~run"(e,t){return e.typed&&!(this.requirement<=e.value&&this.requirement>=e.value)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.values=function e(t,r){return{kind:"validation",type:"values",reference:e,async:!1,expects:`${E(t.map(e=>e instanceof Date?e.toJSON():l(e)),"|")}`,requirement:t,message:r,"~run"(e,t){return e.typed&&!this.requirement.some(t=>t<=e.value&&t>=e.value)&&h(this,"value",e,t,{received:e.value instanceof Date?e.value.toJSON():l(e.value)}),e}}},Fl.variant=function e(t,r,n){return{kind:"schema",type:"variant",reference:e,expects:"Object",async:!1,key:t,options:r,message:n,get"~standard"(){return g(this)},"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){let n,i=0,o=this.key,s=[];const a=(e,u)=>{for(const c of e.options){if("variant"===c.type)a(c,new Set(u).add(c.key));else{let e=!0,a=0;for(const t of u){const n=c.entries[t];if(t in r?n["~run"]({typed:!1,value:r[t]},{abortEarly:!0}).issues:"exact_optional"!==n.type&&"optional"!==n.type&&"nullish"!==n.type){e=!1,o!==t&&(i<a||i===a&&t in r&&!(o in r))&&(i=a,o=t,s=[]),o===t&&s.push(c.entries[t].expects);break}a++}if(e){const e=c["~run"]({value:r},t);(!n||!n.typed&&e.typed)&&(n=e)}}if(n&&!n.issues)break}};if(a(this,new Set([this.key])),n)return n;h(this,"type",e,t,{input:r[o],expected:E(s,"|"),path:[{type:"object",origin:"value",input:r,key:o,value:r[o]}]})}else h(this,"type",e,t);return e}}},Fl.variantAsync=function e(t,r,n){return{kind:"schema",type:"variant",reference:e,expects:"Object",async:!0,key:t,options:r,message:n,get"~standard"(){return g(this)},async"~run"(e,t){const r=e.value;if(r&&"object"==typeof r){let n,i=0,o=this.key,s=[];const a=async(e,u)=>{for(const c of e.options){if("variant"===c.type)await a(c,new Set(u).add(c.key));else{let e=!0,a=0;for(const t of u){const n=c.entries[t];if(t in r?(await n["~run"]({typed:!1,value:r[t]},{abortEarly:!0})).issues:"exact_optional"!==n.type&&"optional"!==n.type&&"nullish"!==n.type){e=!1,o!==t&&(i<a||i===a&&t in r&&!(o in r))&&(i=a,o=t,s=[]),o===t&&s.push(c.entries[t].expects);break}a++}if(e){const e=await c["~run"]({value:r},t);(!n||!n.typed&&e.typed)&&(n=e)}}if(n&&!n.issues)break}};if(await a(this,new Set([this.key])),n)return n;h(this,"type",e,t,{input:r[o],expected:E(s,"|"),path:[{type:"object",origin:"value",input:r,key:o,value:r[o]}]})}else h(this,"type",e,t);return e}}},Fl.void=ge,Fl.void_=ge,Fl.words=function e(t,r,n){return{kind:"validation",type:"words",reference:e,async:!1,expects:`${r}`,locales:t,requirement:r,message:n,"~run"(e,t){if(e.typed){const r=m(this.locales,e.value);r!==this.requirement&&h(this,"words",e,t,{received:`${r}`})}return e}}},Fl}function ql(e,t){for(var r=0;r<t.length;r++){const n=t[r];if("string"!=typeof n&&!Array.isArray(n))for(const t in n)if("default"!==t&&!(t in e)){const r=Object.getOwnPropertyDescriptor(n,t);r&&Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}for(var Wl={},$l={byteLength:function(e){var t=Jl(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=Jl(e),i=n[0],o=n[1],s=new Yl(function(e,t,r){return 3*(t+r)/4-r}(0,i,o)),a=0,u=o>0?i-4:i;for(r=0;r<u;r+=4)t=Xl[e.charCodeAt(r)]<<18|Xl[e.charCodeAt(r+1)]<<12|Xl[e.charCodeAt(r+2)]<<6|Xl[e.charCodeAt(r+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=255&t;return 2===o&&(t=Xl[e.charCodeAt(r)]<<2|Xl[e.charCodeAt(r+1)]>>4,s[a++]=255&t),1===o&&(t=Xl[e.charCodeAt(r)]<<10|Xl[e.charCodeAt(r+1)]<<4|Xl[e.charCodeAt(r+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t),s},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(th(e,s,s+o>a?a:s+o));return 1===n?(t=e[r-1],i.push(Gl[t>>2]+Gl[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(Gl[t>>10]+Gl[t>>4&63]+Gl[t<<2&63]+"=")),i.join("")}},Gl=[],Xl=[],Yl=typeof Uint8Array<"u"?Uint8Array:Array,Zl="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ql=0;Ql<64;++Ql)Gl[Ql]=Zl[Ql],Xl[Zl.charCodeAt(Ql)]=Ql;function Jl(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function eh(e){return Gl[e>>18&63]+Gl[e>>12&63]+Gl[e>>6&63]+Gl[63&e]}function th(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(eh(n));return i.join("")}Xl[45]=62,Xl[95]=63;var rh={read:function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,f=-7,l=r?i-1:0,h=r?-1:1,p=e[t+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},write:function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<<c)-1,l=f>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?h/u:h*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*y}};!function(e){const t=$l,r=rh,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=c,e.SlowBuffer=function(e){return+e!=e&&(e=0),c.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i;const{Uint8Array:o,ArrayBuffer:s,SharedArrayBuffer:a}=globalThis;function u(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new o(e);return Object.setPrototypeOf(t,c.prototype),t}function c(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return h(e)}return f(e,t,r)}function f(e,t,r){if("string"==typeof e)return function(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!c.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|g(e,t);let n=u(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(s.isView(e))return function(e){if(Y(e,o)){const t=new o(e);return d(t.buffer,t.byteOffset,t.byteLength)}return p(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(Y(e,s)||e&&Y(e.buffer,s)||typeof a<"u"&&(Y(e,a)||e&&Y(e.buffer,a)))return d(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return c.from(n,t,r);const i=function(e){if(c.isBuffer(e)){const t=0|y(e.length),r=u(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||Z(e.length)?u(0):p(e);if("Buffer"===e.type&&Array.isArray(e.data))return p(e.data)}(e);if(i)return i;if(typeof Symbol<"u"&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return c.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function h(e){return l(e),u(e<0?0:0|y(e))}function p(e){const t=e.length<0?0:0|y(e.length),r=u(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function d(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new o(e):void 0===r?new o(e,t):new o(e,t,r),Object.setPrototypeOf(n,c.prototype),n}function y(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function g(e,t){if(c.isBuffer(e))return e.length;if(s.isView(e)||Y(e,s))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return $(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:$(e).length;t=(""+t).toLowerCase(),i=!0}}function m(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0)||(r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return P(this,t,r);case"utf8":case"utf-8":return T(this,t,r);case"ascii":return O(this,t,r);case"latin1":case"binary":return B(this,t,r);case"base64":return I(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function b(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function w(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Z(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:v(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof o.prototype.indexOf?i?o.prototype.indexOf.call(e,t,r):o.prototype.lastIndexOf.call(e,t,r):v(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function v(e,t,r,n,i){let o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){let n=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(c(e,o+n)!==c(t,n)){r=!1;break}if(r)return o}return-1}function E(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=t.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(Z(n))return s;e[r+s]=n}return s}function _(e,t,r,n){return X($(t,e.length-r),e,r,n)}function S(e,t,r,n){return X(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function k(e,t,r,n){return X(G(t),e,r,n)}function A(e,t,r,n){return X(function(e,t){let r,n,i;const o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function I(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function T(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let o=null,s=t>239?4:t>223?3:t>191?2:1;if(i+s<=r){let r,n,a,u;switch(s){case 1:t<128&&(o=t);break;case 2:r=e[i+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(o=u));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(e){const t=e.length;if(t<=x)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=x));return r}(n)}c.TYPED_ARRAY_SUPPORT=function(){try{const e=new o(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,o.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch{return!1}}(),!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&"function"==typeof console.error&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),c.poolSize=8192,c.from=function(e,t,r){return f(e,t,r)},Object.setPrototypeOf(c.prototype,o.prototype),Object.setPrototypeOf(c,o),c.alloc=function(e,t,r){return function(e,t,r){return l(e),e<=0?u(e):void 0!==t?"string"==typeof r?u(e).fill(t,r):u(e).fill(t):u(e)}(e,t,r)},c.allocUnsafe=function(e){return h(e)},c.allocUnsafeSlow=function(e){return h(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==c.prototype},c.compare=function(e,t){if(Y(e,o)&&(e=c.from(e,e.offset,e.byteLength)),Y(t,o)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=c.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(Y(t,o))i+t.length>n.length?(c.isBuffer(t)||(t=c.from(t)),t.copy(n,i)):o.prototype.set.call(n,t,i);else{if(!c.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},c.byteLength=g,c.prototype._isBuffer=!0,c.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)b(this,t,t+1);return this},c.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)b(this,t,t+3),b(this,t+1,t+2);return this},c.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)b(this,t,t+7),b(this,t+1,t+6),b(this,t+2,t+5),b(this,t+3,t+4);return this},c.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?T(this,0,e):m.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(c.prototype[n]=c.prototype.inspect),c.prototype.compare=function(e,t,r,n,i){if(Y(e,o)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const u=Math.min(s,a),f=this.slice(n,i),l=e.slice(t,r);for(let o=0;o<u;++o)if(f[o]!==l[o]){s=f[o],a=l[o];break}return s<a?-1:a<s?1:0},c.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},c.prototype.indexOf=function(e,t,r){return w(this,e,t,r,!0)},c.prototype.lastIndexOf=function(e,t,r){return w(this,e,t,r,!1)},c.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return E(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":case"latin1":case"binary":return S(this,e,t,r);case"base64":return k(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const x=4096;function O(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function B(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function P(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=t;o<r;++o)i+=Q[e[o]];return i}function U(e,t,r){const n=e.slice(t,r);let i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function L(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,r,n,i,o){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function R(e,t,r,n,i){F(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function H(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function K(e,t,n,i,o){return t=+t,n>>>=0,o||H(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function z(e,t,n,i,o){return t=+t,n>>>=0,o||H(e,0,n,8),r.write(e,t,n,i,52,8),n+8}c.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,c.prototype),n},c.prototype.readUintLE=c.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return n},c.prototype.readUintBE=c.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},c.prototype.readUint8=c.prototype.readUInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),this[e]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readBigUInt64LE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),c.prototype.readBigUInt64BE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)}),c.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=t,i=1,o=this[e+--n];for(;n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},c.prototype.readInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||L(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt16BE=function(e,t){e>>>=0,t||L(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readBigInt64LE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),c.prototype.readBigInt64BE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&q(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)}),c.prototype.readFloatLE=function(e,t){return e>>>=0,t||L(e,4,this.length),r.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||L(e,4,this.length),r.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||L(e,8,this.length),r.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||L(e,8,this.length),r.read(this,e,!1,52,8)},c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){N(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){N(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},c.prototype.writeUint8=c.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigUInt64LE=J(function(e,t=0){return R(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=J(function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=0,o=1,s=0;for(this[t]=255&e;++i<r&&(o*=256);)e<0&&0===s&&0!==this[t+i-1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},c.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===s&&0!==this[t+i+1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},c.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigInt64LE=J(function(e,t=0){return R(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=J(function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeFloatLE=function(e,t,r){return K(this,e,t,!0,r)},c.prototype.writeFloatBE=function(e,t,r){return K(this,e,t,!1,r)},c.prototype.writeDoubleLE=function(e,t,r){return z(this,e,t,!0,r)},c.prototype.writeDoubleBE=function(e,t,r){return z(this,e,t,!1,r)},c.prototype.copy=function(e,t,r,n){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!n&&0!==n&&(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof o.prototype.copyWithin?this.copyWithin(t,r,n):o.prototype.set.call(e,this.subarray(r,n),t),i},c.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const o=c.isBuffer(e)?e:c.from(e,n),s=o.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=o[i%s]}return this};const M={};function D(e,t,r){M[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function j(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,o){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new M.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,r){V(t,"offset"),(void 0===e[t]||void 0===e[t+r])&&q(t,e.length-(r+1))}(n,i,o)}function V(e,t){if("number"!=typeof e)throw new M.ERR_INVALID_ARG_TYPE(t,"number",e)}function q(e,t,r){throw Math.floor(e)!==e?(V(e,r),new M.ERR_OUT_OF_RANGE("offset","an integer",e)):t<0?new M.ERR_BUFFER_OUT_OF_BOUNDS:new M.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),D("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=j(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=j(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);const W=/[^+/0-9A-Za-z-_]/g;function $(e,t){let r;t=t||1/0;const n=e.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(W,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function X(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Y(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Z(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return typeof BigInt>"u"?ee:e}function ee(){throw new Error("BigInt not supported")}}(Wl);const nh=Wl.Buffer,ih=Wl.Buffer;function oh(e){let t=e.length;for(;--t>=0;)e[t]=0}const sh=256,ah=286,uh=30,ch=15,fh=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),lh=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),hh=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),ph=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),dh=new Array(576);oh(dh);const yh=new Array(60);oh(yh);const gh=new Array(512);oh(gh);const mh=new Array(256);oh(mh);const bh=new Array(29);oh(bh);const wh=new Array(uh);function vh(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}let Eh,_h,Sh;function kh(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}oh(wh);const Ah=e=>e<256?gh[e]:gh[256+(e>>>7)],Ih=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},Th=(e,t,r)=>{e.bi_valid>16-r?(e.bi_buf|=t<<e.bi_valid&65535,Ih(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=r-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)},xh=(e,t,r)=>{Th(e,r[2*t],r[2*t+1])},Oh=(e,t)=>{let r=0;do{r|=1&e,e>>>=1,r<<=1}while(--t>0);return r>>>1},Bh=(e,t,r)=>{const n=new Array(16);let i,o,s=0;for(i=1;i<=ch;i++)s=s+r[i-1]<<1,n[i]=s;for(o=0;o<=t;o++){let t=e[2*o+1];0!==t&&(e[2*o]=Oh(n[t]++,t))}},Ph=e=>{let t;for(t=0;t<ah;t++)e.dyn_ltree[2*t]=0;for(t=0;t<uh;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.sym_next=e.matches=0},Uh=e=>{e.bi_valid>8?Ih(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},Lh=(e,t,r,n)=>{const i=2*t,o=2*r;return e[i]<e[o]||e[i]===e[o]&&n[t]<=n[r]},Nh=(e,t,r)=>{const n=e.heap[r];let i=r<<1;for(;i<=e.heap_len&&(i<e.heap_len&&Lh(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Lh(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n},Rh=(e,t,r)=>{let n,i,o,s,a=0;if(0!==e.sym_next)do{n=255&e.pending_buf[e.sym_buf+a++],n+=(255&e.pending_buf[e.sym_buf+a++])<<8,i=e.pending_buf[e.sym_buf+a++],0===n?xh(e,i,t):(o=mh[i],xh(e,o+sh+1,t),s=fh[o],0!==s&&(i-=bh[o],Th(e,i,s)),n--,o=Ah(n),xh(e,o,r),s=lh[o],0!==s&&(n-=wh[o],Th(e,n,s)))}while(a<e.sym_next);xh(e,256,t)},Ch=(e,t)=>{const r=t.dyn_tree,n=t.stat_desc.static_tree,i=t.stat_desc.has_stree,o=t.stat_desc.elems;let s,a,u,c=-1;for(e.heap_len=0,e.heap_max=573,s=0;s<o;s++)0!==r[2*s]?(e.heap[++e.heap_len]=c=s,e.depth[s]=0):r[2*s+1]=0;for(;e.heap_len<2;)u=e.heap[++e.heap_len]=c<2?++c:0,r[2*u]=1,e.depth[u]=0,e.opt_len--,i&&(e.static_len-=n[2*u+1]);for(t.max_code=c,s=e.heap_len>>1;s>=1;s--)Nh(e,r,s);u=o;do{s=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Nh(e,r,1),a=e.heap[1],e.heap[--e.heap_max]=s,e.heap[--e.heap_max]=a,r[2*u]=r[2*s]+r[2*a],e.depth[u]=(e.depth[s]>=e.depth[a]?e.depth[s]:e.depth[a])+1,r[2*s+1]=r[2*a+1]=u,e.heap[1]=u++,Nh(e,r,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],((e,t)=>{const r=t.dyn_tree,n=t.max_code,i=t.stat_desc.static_tree,o=t.stat_desc.has_stree,s=t.stat_desc.extra_bits,a=t.stat_desc.extra_base,u=t.stat_desc.max_length;let c,f,l,h,p,d,y=0;for(h=0;h<=ch;h++)e.bl_count[h]=0;for(r[2*e.heap[e.heap_max]+1]=0,c=e.heap_max+1;c<573;c++)f=e.heap[c],h=r[2*r[2*f+1]+1]+1,h>u&&(h=u,y++),r[2*f+1]=h,!(f>n)&&(e.bl_count[h]++,p=0,f>=a&&(p=s[f-a]),d=r[2*f],e.opt_len+=d*(h+p),o&&(e.static_len+=d*(i[2*f+1]+p)));if(0!==y){do{for(h=u-1;0===e.bl_count[h];)h--;e.bl_count[h]--,e.bl_count[h+1]+=2,e.bl_count[u]--,y-=2}while(y>0);for(h=u;0!==h;h--)for(f=e.bl_count[h];0!==f;)l=e.heap[--c],!(l>n)&&(r[2*l+1]!==h&&(e.opt_len+=(h-r[2*l+1])*r[2*l],r[2*l+1]=h),f--)}})(e,t),Bh(r,c,e.bl_count)},Hh=(e,t,r)=>{let n,i,o=-1,s=t[1],a=0,u=7,c=4;for(0===s&&(u=138,c=3),t[2*(r+1)+1]=65535,n=0;n<=r;n++)i=s,s=t[2*(n+1)+1],!(++a<u&&i===s)&&(a<c?e.bl_tree[2*i]+=a:0!==i?(i!==o&&e.bl_tree[2*i]++,e.bl_tree[32]++):a<=10?e.bl_tree[34]++:e.bl_tree[36]++,a=0,o=i,0===s?(u=138,c=3):i===s?(u=6,c=3):(u=7,c=4))},Kh=(e,t,r)=>{let n,i,o=-1,s=t[1],a=0,u=7,c=4;for(0===s&&(u=138,c=3),n=0;n<=r;n++)if(i=s,s=t[2*(n+1)+1],!(++a<u&&i===s)){if(a<c)do{xh(e,i,e.bl_tree)}while(0!==--a);else 0!==i?(i!==o&&(xh(e,i,e.bl_tree),a--),xh(e,16,e.bl_tree),Th(e,a-3,2)):a<=10?(xh(e,17,e.bl_tree),Th(e,a-3,3)):(xh(e,18,e.bl_tree),Th(e,a-11,7));a=0,o=i,0===s?(u=138,c=3):i===s?(u=6,c=3):(u=7,c=4)}};let zh=!1;const Mh=(e,t,r,n)=>{Th(e,0+(n?1:0),3),Uh(e),Ih(e,r),Ih(e,~r),r&&e.pending_buf.set(e.window.subarray(t,t+r),e.pending),e.pending+=r};var Dh=e=>{zh||((()=>{let e,t,r,n,i;const o=new Array(16);for(r=0,n=0;n<28;n++)for(bh[n]=r,e=0;e<1<<fh[n];e++)mh[r++]=n;for(mh[r-1]=n,i=0,n=0;n<16;n++)for(wh[n]=i,e=0;e<1<<lh[n];e++)gh[i++]=n;for(i>>=7;n<uh;n++)for(wh[n]=i<<7,e=0;e<1<<lh[n]-7;e++)gh[256+i++]=n;for(t=0;t<=ch;t++)o[t]=0;for(e=0;e<=143;)dh[2*e+1]=8,e++,o[8]++;for(;e<=255;)dh[2*e+1]=9,e++,o[9]++;for(;e<=279;)dh[2*e+1]=7,e++,o[7]++;for(;e<=287;)dh[2*e+1]=8,e++,o[8]++;for(Bh(dh,287,o),e=0;e<uh;e++)yh[2*e+1]=5,yh[2*e]=Oh(e,5);Eh=new vh(dh,fh,257,ah,ch),_h=new vh(yh,lh,0,uh,ch),Sh=new vh(new Array(0),hh,0,19,7)})(),zh=!0),e.l_desc=new kh(e.dyn_ltree,Eh),e.d_desc=new kh(e.dyn_dtree,_h),e.bl_desc=new kh(e.bl_tree,Sh),e.bi_buf=0,e.bi_valid=0,Ph(e)},jh=(e,t,r,n)=>{let i,o,s=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,r=4093624447;for(t=0;t<=31;t++,r>>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<sh;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),Ch(e,e.l_desc),Ch(e,e.d_desc),s=(e=>{let t;for(Hh(e,e.dyn_ltree,e.l_desc.max_code),Hh(e,e.dyn_dtree,e.d_desc.max_code),Ch(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*ph[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),i=e.opt_len+3+7>>>3,o=e.static_len+3+7>>>3,o<=i&&(i=o)):i=o=r+5,r+4<=i&&-1!==t?Mh(e,t,r,n):4===e.strategy||o===i?(Th(e,2+(n?1:0),3),Rh(e,dh,yh)):(Th(e,4+(n?1:0),3),((e,t,r,n)=>{let i;for(Th(e,t-257,5),Th(e,r-1,5),Th(e,n-4,4),i=0;i<n;i++)Th(e,e.bl_tree[2*ph[i]+1],3);Kh(e,e.dyn_ltree,t-1),Kh(e,e.dyn_dtree,r-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,s+1),Rh(e,e.dyn_ltree,e.dyn_dtree)),Ph(e),n&&Uh(e)},Fh=(e,t,r)=>(e.pending_buf[e.sym_buf+e.sym_next++]=t,e.pending_buf[e.sym_buf+e.sym_next++]=t>>8,e.pending_buf[e.sym_buf+e.sym_next++]=r,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(mh[r]+sh+1)]++,e.dyn_dtree[2*Ah(t)]++),e.sym_next===e.sym_end),Vh=e=>{Th(e,2,3),xh(e,256,dh),(e=>{16===e.bi_valid?(Ih(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)})(e)},qh={_tr_init:Dh,_tr_stored_block:Mh,_tr_flush_block:jh,_tr_tally:Fh,_tr_align:Vh};var Wh=(e,t,r,n)=>{let i=65535&e,o=e>>>16&65535,s=0;for(;0!==r;){s=r>2e3?2e3:r,r-=s;do{i=i+t[n++]|0,o=o+i|0}while(--s);i%=65521,o%=65521}return i|o<<16};const $h=new Uint32Array((()=>{let e,t=[];for(var r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t})());var Gh=(e,t,r,n)=>{const i=$h,o=n+r;e^=-1;for(let s=n;s<o;s++)e=e>>>8^i[255&(e^t[s])];return-1^e},Xh={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Yh={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Zh,_tr_stored_block:Qh,_tr_flush_block:Jh,_tr_tally:ep,_tr_align:tp}=qh,{Z_NO_FLUSH:rp,Z_PARTIAL_FLUSH:np,Z_FULL_FLUSH:ip,Z_FINISH:op,Z_BLOCK:sp,Z_OK:ap,Z_STREAM_END:up,Z_STREAM_ERROR:cp,Z_DATA_ERROR:fp,Z_BUF_ERROR:lp,Z_DEFAULT_COMPRESSION:hp,Z_FILTERED:pp,Z_HUFFMAN_ONLY:dp,Z_RLE:yp,Z_FIXED:gp,Z_DEFAULT_STRATEGY:mp,Z_UNKNOWN:bp,Z_DEFLATED:wp}=Yh,vp=258,Ep=262,_p=42,Sp=113,kp=666,Ap=(e,t)=>(e.msg=Xh[t],t),Ip=e=>2*e-(e>4?9:0),Tp=e=>{let t=e.length;for(;--t>=0;)e[t]=0},xp=e=>{let t,r,n,i=e.w_size;t=e.hash_size,n=t;do{r=e.head[--n],e.head[n]=r>=i?r-i:0}while(--t);t=i,n=t;do{r=e.prev[--n],e.prev[n]=r>=i?r-i:0}while(--t)};let Op=(e,t,r)=>(t<<e.hash_shift^r)&e.hash_mask;const Bp=e=>{const t=e.state;let r=t.pending;r>e.avail_out&&(r=e.avail_out),0!==r&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+r),e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0))},Pp=(e,t)=>{Jh(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,Bp(e.strm)},Up=(e,t)=>{e.pending_buf[e.pending++]=t},Lp=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},Np=(e,t,r,n)=>{let i=e.avail_in;return i>n&&(i=n),0===i?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),r),1===e.state.wrap?e.adler=Wh(e.adler,t,i,r):2===e.state.wrap&&(e.adler=Gh(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)},Rp=(e,t)=>{let r,n,i=e.max_chain_length,o=e.strstart,s=e.prev_length,a=e.nice_match;const u=e.strstart>e.w_size-Ep?e.strstart-(e.w_size-Ep):0,c=e.window,f=e.w_mask,l=e.prev,h=e.strstart+vp;let p=c[o+s-1],d=c[o+s];e.prev_length>=e.good_match&&(i>>=2),a>e.lookahead&&(a=e.lookahead);do{if(r=t,c[r+s]===d&&c[r+s-1]===p&&c[r]===c[o]&&c[++r]===c[o+1]){o+=2,r++;do{}while(c[++o]===c[++r]&&c[++o]===c[++r]&&c[++o]===c[++r]&&c[++o]===c[++r]&&c[++o]===c[++r]&&c[++o]===c[++r]&&c[++o]===c[++r]&&c[++o]===c[++r]&&o<h);if(n=vp-(h-o),o=h-vp,n>s){if(e.match_start=t,s=n,n>=a)break;p=c[o+s-1],d=c[o+s]}}}while((t=l[t&f])>u&&0!==--i);return s<=e.lookahead?s:e.lookahead},Cp=e=>{const t=e.w_size;let r,n,i;do{if(n=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-Ep)&&(e.window.set(e.window.subarray(t,t+t-n),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,e.insert>e.strstart&&(e.insert=e.strstart),xp(e),n+=t),0===e.strm.avail_in)break;if(r=Np(e.strm,e.window,e.strstart+e.lookahead,n),e.lookahead+=r,e.lookahead+e.insert>=3)for(i=e.strstart-e.insert,e.ins_h=e.window[i],e.ins_h=Op(e,e.ins_h,e.window[i+1]);e.insert&&(e.ins_h=Op(e,e.ins_h,e.window[i+3-1]),e.prev[i&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=i,i++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<Ep&&0!==e.strm.avail_in)},Hp=(e,t)=>{let r,n,i,o=e.pending_buf_size-5>e.w_size?e.w_size:e.pending_buf_size-5,s=0,a=e.strm.avail_in;do{if(r=65535,i=e.bi_valid+42>>3,e.strm.avail_out<i||(i=e.strm.avail_out-i,n=e.strstart-e.block_start,r>n+e.strm.avail_in&&(r=n+e.strm.avail_in),r>i&&(r=i),r<o&&(0===r&&t!==op||t===rp||r!==n+e.strm.avail_in)))break;s=t===op&&r===n+e.strm.avail_in?1:0,Qh(e,0,0,s),e.pending_buf[e.pending-4]=r,e.pending_buf[e.pending-3]=r>>8,e.pending_buf[e.pending-2]=~r,e.pending_buf[e.pending-1]=~r>>8,Bp(e.strm),n&&(n>r&&(n=r),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+n),e.strm.next_out),e.strm.next_out+=n,e.strm.avail_out-=n,e.strm.total_out+=n,e.block_start+=n,r-=n),r&&(Np(e.strm,e.strm.output,e.strm.next_out,r),e.strm.next_out+=r,e.strm.avail_out-=r,e.strm.total_out+=r)}while(0===s);return a-=e.strm.avail_in,a&&(a>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=a&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-a,e.strm.next_in),e.strstart),e.strstart+=a,e.insert+=a>e.w_size-e.insert?e.w_size-e.insert:a),e.block_start=e.strstart),e.high_water<e.strstart&&(e.high_water=e.strstart),s?4:t!==rp&&t!==op&&0===e.strm.avail_in&&e.strstart===e.block_start?2:(i=e.window_size-e.strstart,e.strm.avail_in>i&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,i+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),i>e.strm.avail_in&&(i=e.strm.avail_in),i&&(Np(e.strm,e.window,e.strstart,i),e.strstart+=i,e.insert+=i>e.w_size-e.insert?e.w_size-e.insert:i),e.high_water<e.strstart&&(e.high_water=e.strstart),i=e.bi_valid+42>>3,i=e.pending_buf_size-i>65535?65535:e.pending_buf_size-i,o=i>e.w_size?e.w_size:i,n=e.strstart-e.block_start,(n>=o||(n||t===op)&&t!==rp&&0===e.strm.avail_in&&n<=i)&&(r=n>i?i:n,s=t===op&&0===e.strm.avail_in&&r===n?1:0,Qh(e,e.block_start,r,s),e.block_start+=r,Bp(e.strm)),s?3:1)},Kp=(e,t)=>{let r,n;for(;;){if(e.lookahead<Ep){if(Cp(e),e.lookahead<Ep&&t===rp)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=Op(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==r&&e.strstart-r<=e.w_size-Ep&&(e.match_length=Rp(e,r)),e.match_length>=3)if(n=ep(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=Op(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!==--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=Op(e,e.ins_h,e.window[e.strstart+1]);else n=ep(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(Pp(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===op?(Pp(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Pp(e,!1),0===e.strm.avail_out)?1:2},zp=(e,t)=>{let r,n,i;for(;;){if(e.lookahead<Ep){if(Cp(e),e.lookahead<Ep&&t===rp)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=Op(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==r&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-Ep&&(e.match_length=Rp(e,r),e.match_length<=5&&(e.strategy===pp||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-3,n=ep(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=i&&(e.ins_h=Op(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!==--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,n&&(Pp(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(n=ep(e,0,e.window[e.strstart-1]),n&&Pp(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=ep(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===op?(Pp(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Pp(e,!1),0===e.strm.avail_out)?1:2};function Mp(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}const Dp=[new Mp(0,0,0,0,Hp),new Mp(4,4,8,4,Kp),new Mp(4,5,16,8,Kp),new Mp(4,6,32,32,Kp),new Mp(4,4,16,16,zp),new Mp(8,16,32,32,zp),new Mp(8,16,128,128,zp),new Mp(8,32,128,256,zp),new Mp(32,128,258,1024,zp),new Mp(32,258,258,4096,zp)];function jp(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=wp,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),Tp(this.dyn_ltree),Tp(this.dyn_dtree),Tp(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),Tp(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Tp(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Fp=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.status!==_p&&57!==t.status&&69!==t.status&&73!==t.status&&91!==t.status&&103!==t.status&&t.status!==Sp&&t.status!==kp?1:0},Vp=e=>{if(Fp(e))return Ap(e,cp);e.total_in=e.total_out=0,e.data_type=bp;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=2===t.wrap?57:t.wrap?_p:Sp,e.adler=2===t.wrap?0:1,t.last_flush=-2,Zh(t),ap},qp=e=>{const t=Vp(e);return t===ap&&(e=>{e.window_size=2*e.w_size,Tp(e.head),e.max_lazy_match=Dp[e.level].max_lazy,e.good_match=Dp[e.level].good_length,e.nice_match=Dp[e.level].nice_length,e.max_chain_length=Dp[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0})(e.state),t},Wp=(e,t,r,n,i,o)=>{if(!e)return cp;let s=1;if(t===hp&&(t=6),n<0?(s=0,n=-n):n>15&&(s=2,n-=16),i<1||i>9||r!==wp||n<8||n>15||t<0||t>9||o<0||o>gp||8===n&&1!==s)return Ap(e,cp);8===n&&(n=9);const a=new jp;return e.state=a,a.strm=e,a.status=_p,a.wrap=s,a.gzhead=null,a.w_bits=n,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=i+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+3-1)/3),a.window=new Uint8Array(2*a.w_size),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<i+6,a.pending_buf_size=4*a.lit_bufsize,a.pending_buf=new Uint8Array(a.pending_buf_size),a.sym_buf=a.lit_bufsize,a.sym_end=3*(a.lit_bufsize-1),a.level=t,a.strategy=o,a.method=r,qp(e)};var $p=(e,t)=>Wp(e,t,wp,15,8,mp),Gp=(e,t)=>Fp(e)||2!==e.state.wrap?cp:(e.state.gzhead=t,ap),Xp=(e,t)=>{if(Fp(e)||t>sp||t<0)return e?Ap(e,cp):cp;const r=e.state;if(!e.output||0!==e.avail_in&&!e.input||r.status===kp&&t!==op)return Ap(e,0===e.avail_out?lp:cp);const n=r.last_flush;if(r.last_flush=t,0!==r.pending){if(Bp(e),0===e.avail_out)return r.last_flush=-1,ap}else if(0===e.avail_in&&Ip(t)<=Ip(n)&&t!==op)return Ap(e,lp);if(r.status===kp&&0!==e.avail_in)return Ap(e,lp);if(r.status===_p&&0===r.wrap&&(r.status=Sp),r.status===_p){let t=wp+(r.w_bits-8<<4)<<8,n=-1;if(n=r.strategy>=dp||r.level<2?0:r.level<6?1:6===r.level?2:3,t|=n<<6,0!==r.strstart&&(t|=32),t+=31-t%31,Lp(r,t),0!==r.strstart&&(Lp(r,e.adler>>>16),Lp(r,65535&e.adler)),e.adler=1,r.status=Sp,Bp(e),0!==r.pending)return r.last_flush=-1,ap}if(57===r.status)if(e.adler=0,Up(r,31),Up(r,139),Up(r,8),r.gzhead)Up(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Up(r,255&r.gzhead.time),Up(r,r.gzhead.time>>8&255),Up(r,r.gzhead.time>>16&255),Up(r,r.gzhead.time>>24&255),Up(r,9===r.level?2:r.strategy>=dp||r.level<2?4:0),Up(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Up(r,255&r.gzhead.extra.length),Up(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(e.adler=Gh(e.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69;else if(Up(r,0),Up(r,0),Up(r,0),Up(r,0),Up(r,0),Up(r,9===r.level?2:r.strategy>=dp||r.level<2?4:0),Up(r,3),r.status=Sp,Bp(e),0!==r.pending)return r.last_flush=-1,ap;if(69===r.status){if(r.gzhead.extra){let t=r.pending,n=(65535&r.gzhead.extra.length)-r.gzindex;for(;r.pending+n>r.pending_buf_size;){let i=r.pending_buf_size-r.pending;if(r.pending_buf.set(r.gzhead.extra.subarray(r.gzindex,r.gzindex+i),r.pending),r.pending=r.pending_buf_size,r.gzhead.hcrc&&r.pending>t&&(e.adler=Gh(e.adler,r.pending_buf,r.pending-t,t)),r.gzindex+=i,Bp(e),0!==r.pending)return r.last_flush=-1,ap;t=0,n-=i}let i=new Uint8Array(r.gzhead.extra);r.pending_buf.set(i.subarray(r.gzindex,r.gzindex+n),r.pending),r.pending+=n,r.gzhead.hcrc&&r.pending>t&&(e.adler=Gh(e.adler,r.pending_buf,r.pending-t,t)),r.gzindex=0}r.status=73}if(73===r.status){if(r.gzhead.name){let t,n=r.pending;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>n&&(e.adler=Gh(e.adler,r.pending_buf,r.pending-n,n)),Bp(e),0!==r.pending)return r.last_flush=-1,ap;n=0}t=r.gzindex<r.gzhead.name.length?255&r.gzhead.name.charCodeAt(r.gzindex++):0,Up(r,t)}while(0!==t);r.gzhead.hcrc&&r.pending>n&&(e.adler=Gh(e.adler,r.pending_buf,r.pending-n,n)),r.gzindex=0}r.status=91}if(91===r.status){if(r.gzhead.comment){let t,n=r.pending;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>n&&(e.adler=Gh(e.adler,r.pending_buf,r.pending-n,n)),Bp(e),0!==r.pending)return r.last_flush=-1,ap;n=0}t=r.gzindex<r.gzhead.comment.length?255&r.gzhead.comment.charCodeAt(r.gzindex++):0,Up(r,t)}while(0!==t);r.gzhead.hcrc&&r.pending>n&&(e.adler=Gh(e.adler,r.pending_buf,r.pending-n,n))}r.status=103}if(103===r.status){if(r.gzhead.hcrc){if(r.pending+2>r.pending_buf_size&&(Bp(e),0!==r.pending))return r.last_flush=-1,ap;Up(r,255&e.adler),Up(r,e.adler>>8&255),e.adler=0}if(r.status=Sp,Bp(e),0!==r.pending)return r.last_flush=-1,ap}if(0!==e.avail_in||0!==r.lookahead||t!==rp&&r.status!==kp){let n=0===r.level?Hp(r,t):r.strategy===dp?((e,t)=>{let r;for(;;){if(0===e.lookahead&&(Cp(e),0===e.lookahead)){if(t===rp)return 1;break}if(e.match_length=0,r=ep(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(Pp(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===op?(Pp(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Pp(e,!1),0===e.strm.avail_out)?1:2})(r,t):r.strategy===yp?((e,t)=>{let r,n,i,o;const s=e.window;for(;;){if(e.lookahead<=vp){if(Cp(e),e.lookahead<=vp&&t===rp)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(i=e.strstart-1,n=s[i],n===s[++i]&&n===s[++i]&&n===s[++i])){o=e.strstart+vp;do{}while(n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&i<o);e.match_length=vp-(o-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(r=ep(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=ep(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(Pp(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===op?(Pp(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Pp(e,!1),0===e.strm.avail_out)?1:2})(r,t):Dp[r.level].func(r,t);if((3===n||4===n)&&(r.status=kp),1===n||3===n)return 0===e.avail_out&&(r.last_flush=-1),ap;if(2===n&&(t===np?tp(r):t!==sp&&(Qh(r,0,0,!1),t===ip&&(Tp(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),Bp(e),0===e.avail_out))return r.last_flush=-1,ap}return t!==op?ap:r.wrap<=0?up:(2===r.wrap?(Up(r,255&e.adler),Up(r,e.adler>>8&255),Up(r,e.adler>>16&255),Up(r,e.adler>>24&255),Up(r,255&e.total_in),Up(r,e.total_in>>8&255),Up(r,e.total_in>>16&255),Up(r,e.total_in>>24&255)):(Lp(r,e.adler>>>16),Lp(r,65535&e.adler)),Bp(e),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?ap:up)},Yp=e=>{if(Fp(e))return cp;const t=e.state.status;return e.state=null,t===Sp?Ap(e,fp):ap},Zp=(e,t)=>{let r=t.length;if(Fp(e))return cp;const n=e.state,i=n.wrap;if(2===i||1===i&&n.status!==_p||n.lookahead)return cp;if(1===i&&(e.adler=Wh(e.adler,t,r,0)),n.wrap=0,r>=n.w_size){0===i&&(Tp(n.head),n.strstart=0,n.block_start=0,n.insert=0);let e=new Uint8Array(n.w_size);e.set(t.subarray(r-n.w_size,r),0),t=e,r=n.w_size}const o=e.avail_in,s=e.next_in,a=e.input;for(e.avail_in=r,e.next_in=0,e.input=t,Cp(n);n.lookahead>=3;){let e=n.strstart,t=n.lookahead-2;do{n.ins_h=Op(n,n.ins_h,n.window[e+3-1]),n.prev[e&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=e,e++}while(--t);n.strstart=e,n.lookahead=2,Cp(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,e.next_in=s,e.input=a,e.avail_in=o,n.wrap=i,ap},Qp={deflateInit:$p,deflateInit2:Wp,deflateReset:qp,deflateResetKeep:Vp,deflateSetHeader:Gp,deflate:Xp,deflateEnd:Yp,deflateSetDictionary:Zp,deflateInfo:"pako deflate (from Nodeca project)"};const Jp=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var ed=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const r=t.shift();if(r){if("object"!=typeof r)throw new TypeError(r+"must be non-object");for(const t in r)Jp(r,t)&&(e[t]=r[t])}}return e},td=e=>{let t=0;for(let n=0,i=e.length;n<i;n++)t+=e[n].length;const r=new Uint8Array(t);for(let n=0,i=0,o=e.length;n<o;n++){let t=e[n];r.set(t,i),i+=t.length}return r};let rd=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{rd=!1}const nd=new Uint8Array(256);for(let _R=0;_R<256;_R++)nd[_R]=_R>=252?6:_R>=248?5:_R>=240?4:_R>=224?3:_R>=192?2:1;nd[254]=nd[254]=1;var id=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,r,n,i,o,s=e.length,a=0;for(i=0;i<s;i++)r=e.charCodeAt(i),55296==(64512&r)&&i+1<s&&(n=e.charCodeAt(i+1),56320==(64512&n)&&(r=65536+(r-55296<<10)+(n-56320),i++)),a+=r<128?1:r<2048?2:r<65536?3:4;for(t=new Uint8Array(a),o=0,i=0;o<a;i++)r=e.charCodeAt(i),55296==(64512&r)&&i+1<s&&(n=e.charCodeAt(i+1),56320==(64512&n)&&(r=65536+(r-55296<<10)+(n-56320),i++)),r<128?t[o++]=r:r<2048?(t[o++]=192|r>>>6,t[o++]=128|63&r):r<65536?(t[o++]=224|r>>>12,t[o++]=128|r>>>6&63,t[o++]=128|63&r):(t[o++]=240|r>>>18,t[o++]=128|r>>>12&63,t[o++]=128|r>>>6&63,t[o++]=128|63&r);return t},od=(e,t)=>{const r=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let n,i;const o=new Array(2*r);for(i=0,n=0;n<r;){let t=e[n++];if(t<128){o[i++]=t;continue}let s=nd[t];if(s>4)o[i++]=65533,n+=s-1;else{for(t&=2===s?31:3===s?15:7;s>1&&n<r;)t=t<<6|63&e[n++],s--;s>1?o[i++]=65533:t<65536?o[i++]=t:(t-=65536,o[i++]=55296|t>>10&1023,o[i++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&rd)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let r="";for(let n=0;n<t;n++)r+=String.fromCharCode(e[n]);return r})(o,i)},sd=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let r=t-1;for(;r>=0&&128==(192&e[r]);)r--;return r<0||0===r?t:r+nd[e[r]]>t?r:t};var ad=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const ud=Object.prototype.toString,{Z_NO_FLUSH:cd,Z_SYNC_FLUSH:fd,Z_FULL_FLUSH:ld,Z_FINISH:hd,Z_OK:pd,Z_STREAM_END:dd,Z_DEFAULT_COMPRESSION:yd,Z_DEFAULT_STRATEGY:gd,Z_DEFLATED:md}=Yh;function bd(e){this.options=ed({level:yd,method:md,chunkSize:16384,windowBits:15,memLevel:8,strategy:gd},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new ad,this.strm.avail_out=0;let r=Qp.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(r!==pd)throw new Error(Xh[r]);if(t.header&&Qp.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?id(t.dictionary):"[object ArrayBuffer]"===ud.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,r=Qp.deflateSetDictionary(this.strm,e),r!==pd)throw new Error(Xh[r]);this._dict_set=!0}}function wd(e,t){const r=new bd(t);if(r.push(e,!0),r.err)throw r.msg||Xh[r.err];return r.result}bd.prototype.push=function(e,t){const r=this.strm,n=this.options.chunkSize;let i,o;if(this.ended)return!1;for(o=t===~~t?t:!0===t?hd:cd,"string"==typeof e?r.input=id(e):"[object ArrayBuffer]"===ud.call(e)?r.input=new Uint8Array(e):r.input=e,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(o===fd||o===ld)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if(i=Qp.deflate(r,o),i===dd)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=Qp.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===pd;if(0!==r.avail_out){if(o>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},bd.prototype.onData=function(e){this.chunks.push(e)},bd.prototype.onEnd=function(e){e===pd&&(this.result=td(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var vd=function(e,t){return(t=t||{}).raw=!0,wd(e,t)},Ed=function(e,t){return(t=t||{}).gzip=!0,wd(e,t)},_d={Deflate:bd,deflate:wd,deflateRaw:vd,gzip:Ed};const Sd=16209;var kd=function(e,t){let r,n,i,o,s,a,u,c,f,l,h,p,d,y,g,m,b,w,v,E,_,S,k,A;const I=e.state;r=e.next_in,k=e.input,n=r+(e.avail_in-5),i=e.next_out,A=e.output,o=i-(t-e.avail_out),s=i+(e.avail_out-257),a=I.dmax,u=I.wsize,c=I.whave,f=I.wnext,l=I.window,h=I.hold,p=I.bits,d=I.lencode,y=I.distcode,g=(1<<I.lenbits)-1,m=(1<<I.distbits)-1;e:do{p<15&&(h+=k[r++]<<p,p+=8,h+=k[r++]<<p,p+=8),b=d[h&g];t:for(;;){if(w=b>>>24,h>>>=w,p-=w,w=b>>>16&255,0===w)A[i++]=65535&b;else{if(!(16&w)){if(64&w){if(32&w){I.mode=16191;break e}e.msg="invalid literal/length code",I.mode=Sd;break e}b=d[(65535&b)+(h&(1<<w)-1)];continue t}for(v=65535&b,w&=15,w&&(p<w&&(h+=k[r++]<<p,p+=8),v+=h&(1<<w)-1,h>>>=w,p-=w),p<15&&(h+=k[r++]<<p,p+=8,h+=k[r++]<<p,p+=8),b=y[h&m];;){if(w=b>>>24,h>>>=w,p-=w,w=b>>>16&255,16&w){if(E=65535&b,w&=15,p<w&&(h+=k[r++]<<p,p+=8,p<w&&(h+=k[r++]<<p,p+=8)),E+=h&(1<<w)-1,E>a){e.msg="invalid distance too far back",I.mode=Sd;break e}if(h>>>=w,p-=w,w=i-o,E>w){if(w=E-w,w>c&&I.sane){e.msg="invalid distance too far back",I.mode=Sd;break e}if(_=0,S=l,0===f){if(_+=u-w,w<v){v-=w;do{A[i++]=l[_++]}while(--w);_=i-E,S=A}}else if(f<w){if(_+=u+f-w,w-=f,w<v){v-=w;do{A[i++]=l[_++]}while(--w);if(_=0,f<v){w=f,v-=w;do{A[i++]=l[_++]}while(--w);_=i-E,S=A}}}else if(_+=f-w,w<v){v-=w;do{A[i++]=l[_++]}while(--w);_=i-E,S=A}for(;v>2;)A[i++]=S[_++],A[i++]=S[_++],A[i++]=S[_++],v-=3;v&&(A[i++]=S[_++],v>1&&(A[i++]=S[_++]))}else{_=i-E;do{A[i++]=A[_++],A[i++]=A[_++],A[i++]=A[_++],v-=3}while(v>2);v&&(A[i++]=A[_++],v>1&&(A[i++]=A[_++]))}break}if(64&w){e.msg="invalid distance code",I.mode=Sd;break e}b=y[(65535&b)+(h&(1<<w)-1)]}}break}}while(r<n&&i<s);v=p>>3,r-=v,p-=v<<3,h&=(1<<p)-1,e.next_in=r,e.next_out=i,e.avail_in=r<n?n-r+5:5-(r-n),e.avail_out=i<s?s-i+257:257-(i-s),I.hold=h,I.bits=p};const Ad=15,Id=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Td=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),xd=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),Od=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var Bd=(e,t,r,n,i,o,s,a)=>{const u=a.bits;let c,f,l,h,p,d,y=0,g=0,m=0,b=0,w=0,v=0,E=0,_=0,S=0,k=0,A=null;const I=new Uint16Array(16),T=new Uint16Array(16);let x,O,B,P=null;for(y=0;y<=Ad;y++)I[y]=0;for(g=0;g<n;g++)I[t[r+g]]++;for(w=u,b=Ad;b>=1&&0===I[b];b--);if(w>b&&(w=b),0===b)return i[o++]=20971520,i[o++]=20971520,a.bits=1,0;for(m=1;m<b&&0===I[m];m++);for(w<m&&(w=m),_=1,y=1;y<=Ad;y++)if(_<<=1,_-=I[y],_<0)return-1;if(_>0&&(0===e||1!==b))return-1;for(T[1]=0,y=1;y<Ad;y++)T[y+1]=T[y]+I[y];for(g=0;g<n;g++)0!==t[r+g]&&(s[T[t[r+g]]++]=g);if(0===e?(A=P=s,d=20):1===e?(A=Id,P=Td,d=257):(A=xd,P=Od,d=0),k=0,g=0,y=m,p=o,v=w,E=0,l=-1,S=1<<w,h=S-1,1===e&&S>852||2===e&&S>592)return 1;for(;;){x=y-E,s[g]+1<d?(O=0,B=s[g]):s[g]>=d?(O=P[s[g]-d],B=A[s[g]-d]):(O=96,B=0),c=1<<y-E,f=1<<v,m=f;do{f-=c,i[p+(k>>E)+f]=x<<24|O<<16|B}while(0!==f);for(c=1<<y-1;k&c;)c>>=1;if(0!==c?(k&=c-1,k+=c):k=0,g++,0===--I[y]){if(y===b)break;y=t[r+s[g]]}if(y>w&&(k&h)!==l){for(0===E&&(E=w),p+=m,v=y-E,_=1<<v;v+E<b&&(_-=I[v+E],!(_<=0));)v++,_<<=1;if(S+=1<<v,1===e&&S>852||2===e&&S>592)return 1;l=k&h,i[l]=w<<24|v<<16|p-o}}return 0!==k&&(i[p+k]=y-E<<24|64<<16),a.bits=w,0};const{Z_FINISH:Pd,Z_BLOCK:Ud,Z_TREES:Ld,Z_OK:Nd,Z_STREAM_END:Rd,Z_NEED_DICT:Cd,Z_STREAM_ERROR:Hd,Z_DATA_ERROR:Kd,Z_MEM_ERROR:zd,Z_BUF_ERROR:Md,Z_DEFLATED:Dd}=Yh,jd=16180,Fd=16190,Vd=16191,qd=16192,Wd=16194,$d=16199,Gd=16200,Xd=16206,Yd=16209,Zd=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function Qd(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Jd=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode<jd||t.mode>16211?1:0},ey=e=>{if(Jd(e))return Hd;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=jd,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,Nd},ty=e=>{if(Jd(e))return Hd;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,ey(e)},ry=(e,t)=>{let r;if(Jd(e))return Hd;const n=e.state;return t<0?(r=0,t=-t):(r=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?Hd:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,ty(e))},ny=(e,t)=>{if(!e)return Hd;const r=new Qd;e.state=r,r.strm=e,r.window=null,r.mode=jd;const n=ry(e,t);return n!==Nd&&(e.state=null),n};let iy,oy,sy=!0;const ay=e=>{if(sy){iy=new Int32Array(512),oy=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Bd(1,e.lens,0,288,iy,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Bd(2,e.lens,0,32,oy,0,e.work,{bits:5}),sy=!1}e.lencode=iy,e.lenbits=9,e.distcode=oy,e.distbits=5},uy=(e,t,r,n)=>{let i;const o=e.state;return null===o.window&&(o.wsize=1<<o.wbits,o.wnext=0,o.whave=0,o.window=new Uint8Array(o.wsize)),n>=o.wsize?(o.window.set(t.subarray(r-o.wsize,r),0),o.wnext=0,o.whave=o.wsize):(i=o.wsize-o.wnext,i>n&&(i=n),o.window.set(t.subarray(r-n,r-n+i),o.wnext),(n-=i)?(o.window.set(t.subarray(r-n,r),0),o.wnext=n,o.whave=o.wsize):(o.wnext+=i,o.wnext===o.wsize&&(o.wnext=0),o.whave<o.wsize&&(o.whave+=i))),0};var cy=e=>ny(e,15),fy=(e,t)=>{let r,n,i,o,s,a,u,c,f,l,h,p,d,y,g,m,b,w,v,E,_,S,k=0;const A=new Uint8Array(4);let I,T;const x=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Jd(e)||!e.output||!e.input&&0!==e.avail_in)return Hd;r=e.state,r.mode===Vd&&(r.mode=qd),s=e.next_out,i=e.output,u=e.avail_out,o=e.next_in,n=e.input,a=e.avail_in,c=r.hold,f=r.bits,l=a,h=u,S=Nd;e:for(;;)switch(r.mode){case jd:if(0===r.wrap){r.mode=qd;break}for(;f<16;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(2&r.wrap&&35615===c){0===r.wbits&&(r.wbits=15),r.check=0,A[0]=255&c,A[1]=c>>>8&255,r.check=Gh(r.check,A,2,0),c=0,f=0,r.mode=16181;break}if(r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",r.mode=Yd;break}if((15&c)!==Dd){e.msg="unknown compression method",r.mode=Yd;break}if(c>>>=4,f-=4,_=8+(15&c),0===r.wbits&&(r.wbits=_),_>15||_>r.wbits){e.msg="invalid window size",r.mode=Yd;break}r.dmax=1<<r.wbits,r.flags=0,e.adler=r.check=1,r.mode=512&c?16189:Vd,c=0,f=0;break;case 16181:for(;f<16;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(r.flags=c,(255&r.flags)!==Dd){e.msg="unknown compression method",r.mode=Yd;break}if(57344&r.flags){e.msg="unknown header flags set",r.mode=Yd;break}r.head&&(r.head.text=c>>8&1),512&r.flags&&4&r.wrap&&(A[0]=255&c,A[1]=c>>>8&255,r.check=Gh(r.check,A,2,0)),c=0,f=0,r.mode=16182;case 16182:for(;f<32;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}r.head&&(r.head.time=c),512&r.flags&&4&r.wrap&&(A[0]=255&c,A[1]=c>>>8&255,A[2]=c>>>16&255,A[3]=c>>>24&255,r.check=Gh(r.check,A,4,0)),c=0,f=0,r.mode=16183;case 16183:for(;f<16;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}r.head&&(r.head.xflags=255&c,r.head.os=c>>8),512&r.flags&&4&r.wrap&&(A[0]=255&c,A[1]=c>>>8&255,r.check=Gh(r.check,A,2,0)),c=0,f=0,r.mode=16184;case 16184:if(1024&r.flags){for(;f<16;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}r.length=c,r.head&&(r.head.extra_len=c),512&r.flags&&4&r.wrap&&(A[0]=255&c,A[1]=c>>>8&255,r.check=Gh(r.check,A,2,0)),c=0,f=0}else r.head&&(r.head.extra=null);r.mode=16185;case 16185:if(1024&r.flags&&(p=r.length,p>a&&(p=a),p&&(r.head&&(_=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(o,o+p),_)),512&r.flags&&4&r.wrap&&(r.check=Gh(r.check,n,p,o)),a-=p,o+=p,r.length-=p),r.length))break e;r.length=0,r.mode=16186;case 16186:if(2048&r.flags){if(0===a)break e;p=0;do{_=n[o+p++],r.head&&_&&r.length<65536&&(r.head.name+=String.fromCharCode(_))}while(_&&p<a);if(512&r.flags&&4&r.wrap&&(r.check=Gh(r.check,n,p,o)),a-=p,o+=p,_)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=16187;case 16187:if(4096&r.flags){if(0===a)break e;p=0;do{_=n[o+p++],r.head&&_&&r.length<65536&&(r.head.comment+=String.fromCharCode(_))}while(_&&p<a);if(512&r.flags&&4&r.wrap&&(r.check=Gh(r.check,n,p,o)),a-=p,o+=p,_)break e}else r.head&&(r.head.comment=null);r.mode=16188;case 16188:if(512&r.flags){for(;f<16;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(4&r.wrap&&c!==(65535&r.check)){e.msg="header crc mismatch",r.mode=Yd;break}c=0,f=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=Vd;break;case 16189:for(;f<32;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}e.adler=r.check=Zd(c),c=0,f=0,r.mode=Fd;case Fd:if(0===r.havedict)return e.next_out=s,e.avail_out=u,e.next_in=o,e.avail_in=a,r.hold=c,r.bits=f,Cd;e.adler=r.check=1,r.mode=Vd;case Vd:if(t===Ud||t===Ld)break e;case qd:if(r.last){c>>>=7&f,f-=7&f,r.mode=Xd;break}for(;f<3;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}switch(r.last=1&c,c>>>=1,f-=1,3&c){case 0:r.mode=16193;break;case 1:if(ay(r),r.mode=$d,t===Ld){c>>>=2,f-=2;break e}break;case 2:r.mode=16196;break;case 3:e.msg="invalid block type",r.mode=Yd}c>>>=2,f-=2;break;case 16193:for(c>>>=7&f,f-=7&f;f<32;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",r.mode=Yd;break}if(r.length=65535&c,c=0,f=0,r.mode=Wd,t===Ld)break e;case Wd:r.mode=16195;case 16195:if(p=r.length,p){if(p>a&&(p=a),p>u&&(p=u),0===p)break e;i.set(n.subarray(o,o+p),s),a-=p,o+=p,u-=p,s+=p,r.length-=p;break}r.mode=Vd;break;case 16196:for(;f<14;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(r.nlen=257+(31&c),c>>>=5,f-=5,r.ndist=1+(31&c),c>>>=5,f-=5,r.ncode=4+(15&c),c>>>=4,f-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=Yd;break}r.have=0,r.mode=16197;case 16197:for(;r.have<r.ncode;){for(;f<3;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}r.lens[x[r.have++]]=7&c,c>>>=3,f-=3}for(;r.have<19;)r.lens[x[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,I={bits:r.lenbits},S=Bd(0,r.lens,0,19,r.lencode,0,r.work,I),r.lenbits=I.bits,S){e.msg="invalid code lengths set",r.mode=Yd;break}r.have=0,r.mode=16198;case 16198:for(;r.have<r.nlen+r.ndist;){for(;k=r.lencode[c&(1<<r.lenbits)-1],g=k>>>24,m=k>>>16&255,b=65535&k,!(g<=f);){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(b<16)c>>>=g,f-=g,r.lens[r.have++]=b;else{if(16===b){for(T=g+2;f<T;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(c>>>=g,f-=g,0===r.have){e.msg="invalid bit length repeat",r.mode=Yd;break}_=r.lens[r.have-1],p=3+(3&c),c>>>=2,f-=2}else if(17===b){for(T=g+3;f<T;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}c>>>=g,f-=g,_=0,p=3+(7&c),c>>>=3,f-=3}else{for(T=g+7;f<T;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}c>>>=g,f-=g,_=0,p=11+(127&c),c>>>=7,f-=7}if(r.have+p>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=Yd;break}for(;p--;)r.lens[r.have++]=_}}if(r.mode===Yd)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=Yd;break}if(r.lenbits=9,I={bits:r.lenbits},S=Bd(1,r.lens,0,r.nlen,r.lencode,0,r.work,I),r.lenbits=I.bits,S){e.msg="invalid literal/lengths set",r.mode=Yd;break}if(r.distbits=6,r.distcode=r.distdyn,I={bits:r.distbits},S=Bd(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,I),r.distbits=I.bits,S){e.msg="invalid distances set",r.mode=Yd;break}if(r.mode=$d,t===Ld)break e;case $d:r.mode=Gd;case Gd:if(a>=6&&u>=258){e.next_out=s,e.avail_out=u,e.next_in=o,e.avail_in=a,r.hold=c,r.bits=f,kd(e,h),s=e.next_out,i=e.output,u=e.avail_out,o=e.next_in,n=e.input,a=e.avail_in,c=r.hold,f=r.bits,r.mode===Vd&&(r.back=-1);break}for(r.back=0;k=r.lencode[c&(1<<r.lenbits)-1],g=k>>>24,m=k>>>16&255,b=65535&k,!(g<=f);){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(m&&!(240&m)){for(w=g,v=m,E=b;k=r.lencode[E+((c&(1<<w+v)-1)>>w)],g=k>>>24,m=k>>>16&255,b=65535&k,!(w+g<=f);){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}c>>>=w,f-=w,r.back+=w}if(c>>>=g,f-=g,r.back+=g,r.length=b,0===m){r.mode=16205;break}if(32&m){r.back=-1,r.mode=Vd;break}if(64&m){e.msg="invalid literal/length code",r.mode=Yd;break}r.extra=15&m,r.mode=16201;case 16201:if(r.extra){for(T=r.extra;f<T;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}r.length+=c&(1<<r.extra)-1,c>>>=r.extra,f-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=16202;case 16202:for(;k=r.distcode[c&(1<<r.distbits)-1],g=k>>>24,m=k>>>16&255,b=65535&k,!(g<=f);){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(!(240&m)){for(w=g,v=m,E=b;k=r.distcode[E+((c&(1<<w+v)-1)>>w)],g=k>>>24,m=k>>>16&255,b=65535&k,!(w+g<=f);){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}c>>>=w,f-=w,r.back+=w}if(c>>>=g,f-=g,r.back+=g,64&m){e.msg="invalid distance code",r.mode=Yd;break}r.offset=b,r.extra=15&m,r.mode=16203;case 16203:if(r.extra){for(T=r.extra;f<T;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}r.offset+=c&(1<<r.extra)-1,c>>>=r.extra,f-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=Yd;break}r.mode=16204;case 16204:if(0===u)break e;if(p=h-u,r.offset>p){if(p=r.offset-p,p>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=Yd;break}p>r.wnext?(p-=r.wnext,d=r.wsize-p):d=r.wnext-p,p>r.length&&(p=r.length),y=r.window}else y=i,d=s-r.offset,p=r.length;p>u&&(p=u),u-=p,r.length-=p;do{i[s++]=y[d++]}while(--p);0===r.length&&(r.mode=Gd);break;case 16205:if(0===u)break e;i[s++]=r.length,u--,r.mode=Gd;break;case Xd:if(r.wrap){for(;f<32;){if(0===a)break e;a--,c|=n[o++]<<f,f+=8}if(h-=u,e.total_out+=h,r.total+=h,4&r.wrap&&h&&(e.adler=r.check=r.flags?Gh(r.check,i,h,s-h):Wh(r.check,i,h,s-h)),h=u,4&r.wrap&&(r.flags?c:Zd(c))!==r.check){e.msg="incorrect data check",r.mode=Yd;break}c=0,f=0}r.mode=16207;case 16207:if(r.wrap&&r.flags){for(;f<32;){if(0===a)break e;a--,c+=n[o++]<<f,f+=8}if(4&r.wrap&&c!==(4294967295&r.total)){e.msg="incorrect length check",r.mode=Yd;break}c=0,f=0}r.mode=16208;case 16208:S=Rd;break e;case Yd:S=Kd;break e;case 16210:return zd;default:return Hd}return e.next_out=s,e.avail_out=u,e.next_in=o,e.avail_in=a,r.hold=c,r.bits=f,(r.wsize||h!==e.avail_out&&r.mode<Yd&&(r.mode<Xd||t!==Pd))&&uy(e,e.output,e.next_out,h-e.avail_out),l-=e.avail_in,h-=e.avail_out,e.total_in+=l,e.total_out+=h,r.total+=h,4&r.wrap&&h&&(e.adler=r.check=r.flags?Gh(r.check,i,h,e.next_out-h):Wh(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Vd?128:0)+(r.mode===$d||r.mode===Wd?256:0),(0===l&&0===h||t===Pd)&&S===Nd&&(S=Md),S},ly=e=>{if(Jd(e))return Hd;let t=e.state;return t.window&&(t.window=null),e.state=null,Nd},hy=(e,t)=>{if(Jd(e))return Hd;const r=e.state;return 2&r.wrap?(r.head=t,t.done=!1,Nd):Hd},py=(e,t)=>{const r=t.length;let n,i,o;return Jd(e)||(n=e.state,0!==n.wrap&&n.mode!==Fd)?Hd:n.mode===Fd&&(i=1,i=Wh(i,t,r,0),i!==n.check)?Kd:(o=uy(e,t,r,r),o?(n.mode=16210,zd):(n.havedict=1,Nd))},dy={inflateReset:ty,inflateReset2:ry,inflateResetKeep:ey,inflateInit:cy,inflateInit2:ny,inflate:fy,inflateEnd:ly,inflateGetHeader:hy,inflateSetDictionary:py,inflateInfo:"pako inflate (from Nodeca project)"};var yy=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const gy=Object.prototype.toString,{Z_NO_FLUSH:my,Z_FINISH:by,Z_OK:wy,Z_STREAM_END:vy,Z_NEED_DICT:Ey,Z_STREAM_ERROR:_y,Z_DATA_ERROR:Sy,Z_MEM_ERROR:ky}=Yh;function Ay(e){this.options=ed({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&!(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new ad,this.strm.avail_out=0;let r=dy.inflateInit2(this.strm,t.windowBits);if(r!==wy)throw new Error(Xh[r]);if(this.header=new yy,dy.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=id(t.dictionary):"[object ArrayBuffer]"===gy.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(r=dy.inflateSetDictionary(this.strm,t.dictionary),r!==wy)))throw new Error(Xh[r])}function Iy(e,t){const r=new Ay(t);if(r.push(e),r.err)throw r.msg||Xh[r.err];return r.result}Ay.prototype.push=function(e,t){const r=this.strm,n=this.options.chunkSize,i=this.options.dictionary;let o,s,a;if(this.ended)return!1;for(s=t===~~t?t:!0===t?by:my,"[object ArrayBuffer]"===gy.call(e)?r.input=new Uint8Array(e):r.input=e,r.next_in=0,r.avail_in=r.input.length;;){for(0===r.avail_out&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),o=dy.inflate(r,s),o===Ey&&i&&(o=dy.inflateSetDictionary(r,i),o===wy?o=dy.inflate(r,s):o===Sy&&(o=Ey));r.avail_in>0&&o===vy&&r.state.wrap>0&&0!==e[r.next_in];)dy.inflateReset(r),o=dy.inflate(r,s);switch(o){case _y:case Sy:case Ey:case ky:return this.onEnd(o),this.ended=!0,!1}if(a=r.avail_out,r.next_out&&(0===r.avail_out||o===vy))if("string"===this.options.to){let e=sd(r.output,r.next_out),t=r.next_out-e,i=od(r.output,e);r.next_out=t,r.avail_out=n-t,t&&r.output.set(r.output.subarray(e,e+t),0),this.onData(i)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(o!==wy||0!==a){if(o===vy)return o=dy.inflateEnd(this.strm),this.onEnd(o),this.ended=!0,!0;if(0===r.avail_in)break}}return!0},Ay.prototype.onData=function(e){this.chunks.push(e)},Ay.prototype.onEnd=function(e){e===wy&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=td(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Ty=function(e,t){return(t=t||{}).raw=!0,Iy(e,t)},xy={Inflate:Ay,inflate:Iy,inflateRaw:Ty,ungzip:Iy};const{Deflate:Oy,deflate:By,deflateRaw:Py,gzip:Uy}=_d,{Inflate:Ly,inflate:Ny,inflateRaw:Ry,ungzip:Cy}=xy;var Hy={Deflate:Oy,deflate:By,deflateRaw:Py,gzip:Uy,Inflate:Ly,inflate:Ny,inflateRaw:Ry,ungzip:Cy,constants:Yh};function Ky(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function zy(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var My,Dy={};var jy=function(){if(My)return Dy;My=1,Object.defineProperty(Dy,"__esModule",{value:!0}),Dy.bech32m=Dy.bech32=void 0;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",t={};for(let c=0;c<32;c++){const r=e.charAt(c);t[r]=c}function r(e){const t=e>>25;return(33554431&e)<<5^996825010&-(1&t)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function n(e){let t=1;for(let n=0;n<e.length;++n){const i=e.charCodeAt(n);if(i<33||i>126)return"Invalid prefix ("+e+")";t=r(t)^i>>5}t=r(t);for(let n=0;n<e.length;++n){const i=e.charCodeAt(n);t=r(t)^31&i}return t}function i(e,t,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let u=0;u<e.length;++u)for(i=i<<t|e[u],o+=t;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=t)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function o(e){return i(e,8,5,!0)}function s(e){const t=i(e,5,8,!1);if(Array.isArray(t))return t}function a(e){const t=i(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function u(i){let u;function c(e,i){if(i=i||90,e.length<8)return e+" too short";if(e.length>i)return"Exceeds length limit";const o=e.toLowerCase(),s=e.toUpperCase();if(e!==o&&e!==s)return"Mixed-case string "+e;const a=(e=o).lastIndexOf("1");if(-1===a)return"No separator character for "+e;if(0===a)return"Missing prefix for "+e;const c=e.slice(0,a),f=e.slice(a+1);if(f.length<6)return"Data too short";let l=n(c);if("string"==typeof l)return l;const h=[];for(let n=0;n<f.length;++n){const e=f.charAt(n),i=t[e];if(void 0===i)return"Unknown character "+e;l=r(l)^i,!(n+6>=f.length)&&h.push(i)}return l!==u?"Invalid checksum for "+e:{prefix:c,words:h}}return u="bech32"===i?1:734539939,{decodeUnsafe:function(e,t){const r=c(e,t);if("object"==typeof r)return r},decode:function(e,t){const r=c(e,t);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,i,o){if(o=o||90,t.length+7+i.length>o)throw new TypeError("Exceeds length limit");let s=n(t=t.toLowerCase());if("string"==typeof s)throw new Error(s);let a=t+"1";for(let n=0;n<i.length;++n){const t=i[n];if(t>>5)throw new Error("Non 5-bit word");s=r(s)^t,a+=e.charAt(t)}for(let e=0;e<6;++e)s=r(s);s^=u;for(let r=0;r<6;++r){a+=e.charAt(s>>5*(5-r)&31)}return a},toWords:o,fromWordsUnsafe:s,fromWords:a}}return Dy.bech32=u("bech32"),Dy.bech32m=u("bech32m"),Dy}();const Fy=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let a=0;a<t.length;a++)t[a]=255;for(let a=0;a<e.length;a++){const r=e.charAt(a),n=r.charCodeAt(0);if(255!==t[n])throw new TypeError(r+" is ambiguous");t[n]=a}const r=e.length,n=e.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let o=0,s=0,a=0;for(;e[o]===n;)s++,o++;const u=(e.length-o)*i+1>>>0,c=new Uint8Array(u);for(;o<e.length;){const n=e.charCodeAt(o);if(n>255)return;let i=t[n];if(255===i)return;let s=0;for(let e=u-1;(0!==i||s<a)&&-1!==e;e--,s++)i+=r*c[e]>>>0,c[e]=i%256>>>0,i=i/256>>>0;if(0!==i)throw new Error("Non-zero carry");a=s,o++}let f=u-a;for(;f!==u&&0===c[f];)f++;const l=new Uint8Array(s+(u-f));let h=s;for(;f!==u;)l[h++]=c[f++];return l}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let i=0,s=0,a=0;const u=t.length;for(;a!==u&&0===t[a];)a++,i++;const c=(u-a)*o+1>>>0,f=new Uint8Array(c);for(;a!==u;){let e=t[a],n=0;for(let t=c-1;(0!==e||n<s)&&-1!==t;t--,n++)e+=256*f[t]>>>0,f[t]=e%r>>>0,e=e/r>>>0;if(0!==e)throw new Error("Non-zero carry");s=n,a++}let l=c-s;for(;l!==c&&0===f[l];)l++;let h=n.repeat(i);for(;l<c;++l)h+=e.charAt(f[l]);return h},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const Vy=function(e){function t(t){var r=t.slice(0,-4),n=t.slice(-4),i=e(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(t){var r=Uint8Array.from(t),n=e(r),i=r.length+4,o=new Uint8Array(i);return o.set(r,0),o.set(n.subarray(0,4),r.length),Fy.encode(o)},decode:function(e){var r=t(Fy.decode(e));if(null==r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(e){var r=Fy.decodeUnsafe(e);if(null!=r)return t(r)}}}(function(e){return Iu(Iu(e))});var qy,Wy,$y,Gy,Xy,Yy,Zy,Qy;function Jy(){if(Wy)return qy;Wy=1;var e={Array:function(e){return null!=e&&e.constructor===Array},Boolean:function(e){return"boolean"==typeof e},Function:function(e){return"function"==typeof e},Nil:function(e){return null==e},Number:function(e){return"number"==typeof e},Object:function(e){return"object"==typeof e},String:function(e){return"string"==typeof e},"":function(){return!0}};for(var t in e.Null=e.Nil,e)e[t].toJSON=function(e){return e}.bind(null,t);return qy=e}function eg(){if(Gy)return $y;Gy=1;var e=Jy();function t(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function r(r){return e.Nil(r)?"":t(r.constructor)}function n(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function i(r){return e.Function(r)?r.toJSON?r.toJSON():t(r):e.Array(r)?"Array":r&&e.Object(r)?"Object":void 0!==r?r:""}function o(t,r,n){var o=function(t){return e.Function(t)?"":e.String(t)?JSON.stringify(t):t&&e.Object(t)?"":t}(r);return"Expected "+i(t)+", got"+(""!==n?" "+n:"")+(""!==o?" "+o:"")}function s(e,t,i){i=i||r(t),this.message=o(e,t,i),n(this,s),this.__type=e,this.__value=t,this.__valueTypeName=i}function a(e,t,a,u,c){e?(c=c||r(u),this.message=function(e,t,r,n,s){var a='" of type ';return"key"===t&&(a='" with key type '),o('property "'+i(r)+a+i(e),n,s)}(e,a,t,u,c)):this.message='Unexpected property "'+t+'"',n(this,s),this.__label=a,this.__property=t,this.__type=e,this.__value=u,this.__valueTypeName=c}return s.prototype=Object.create(Error.prototype),s.prototype.constructor=s,a.prototype=Object.create(Error.prototype),a.prototype.constructor=s,$y={TfTypeError:s,TfPropertyTypeError:a,tfCustomError:function(e,t){return new s(e,{},t)},tfSubError:function(e,t,r){return e instanceof a?(t=t+"."+e.__property,e=new a(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof s&&(e=new a(e.__type,t,r,e.__value,e.__valueTypeName)),n(e),e},tfJSON:i,getValueTypeName:r}}function tg(){if(Qy)return Zy;Qy=1;var e=eg(),t=Jy(),r=e.tfJSON,n=e.TfTypeError,i=e.TfPropertyTypeError,o=e.tfSubError,s=e.getValueTypeName,a={arrayOf:function(e,n){function i(r,i){return!(!t.Array(r)||t.Nil(r)||void 0!==n.minLength&&r.length<n.minLength||void 0!==n.maxLength&&r.length>n.maxLength||void 0!==n.length&&r.length!==n.length)&&r.every(function(t,r){try{return c(e,t,i)}catch(n){throw o(n,r)}})}return e=u(e),n=n||{},i.toJSON=function(){var t="["+r(e)+"]";return void 0!==n.length?t+="{"+n.length+"}":(void 0!==n.minLength||void 0!==n.maxLength)&&(t+="{"+(void 0===n.minLength?0:n.minLength)+","+(void 0===n.maxLength?1/0:n.maxLength)+"}"),t},i},maybe:function e(n){function i(r,i){return t.Nil(r)||n(r,i,e)}return n=u(n),i.toJSON=function(){return"?"+r(n)},i},map:function(e,n){function i(r,i){if(!t.Object(r)||t.Nil(r))return!1;for(var s in r){try{n&&c(n,s,i)}catch(u){throw o(u,s,"key")}try{var a=r[s];c(e,a,i)}catch(u){throw o(u,s)}}return!0}return e=u(e),n&&(n=u(n)),i.toJSON=n?function(){return"{"+r(n)+": "+r(e)+"}"}:function(){return"{"+r(e)+"}"},i},object:function(e){var n={};for(var s in e)n[s]=u(e[s]);function a(e,r){if(!t.Object(e)||t.Nil(e))return!1;var s;try{for(s in n){c(n[s],e[s],r)}}catch(a){throw o(a,s)}if(r)for(s in e)if(!n[s])throw new i(void 0,s);return!0}return a.toJSON=function(){return r(n)},a},anyOf:function(){var e=[].slice.call(arguments).map(u);function t(t,r){return e.some(function(e){try{return c(e,t,r)}catch{return!1}})}return t.toJSON=function(){return e.map(r).join("|")},t},allOf:function(){var e=[].slice.call(arguments).map(u);function t(t,r){return e.every(function(e){try{return c(e,t,r)}catch{return!1}})}return t.toJSON=function(){return e.map(r).join(" & ")},t},quacksLike:function(e){function t(t){return e===s(t)}return t.toJSON=function(){return e},t},tuple:function(){var e=[].slice.call(arguments).map(u);function n(r,n){return!(t.Nil(r)||t.Nil(r.length)||n&&r.length!==e.length)&&e.every(function(e,t){try{return c(e,r[t],n)}catch(i){throw o(i,t)}})}return n.toJSON=function(){return"("+e.map(r).join(", ")+")"},n},value:function(e){function t(t){return t===e}return t.toJSON=function(){return e},t}};function u(e){if(t.String(e))return"?"===e[0]?a.maybe(e.slice(1)):t[e]||a.quacksLike(e);if(e&&t.Object(e)){if(t.Array(e)){if(1!==e.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return a.arrayOf(e[0])}return a.object(e)}return t.Function(e)?e:a.value(e)}function c(e,r,i,o){if(t.Function(e)){if(e(r,i))return!0;throw new n(o||e,r)}return c(u(e),r,i)}for(var f in a.oneOf=a.anyOf,t)c[f]=t[f];for(f in a)c[f]=a[f];var l=function(){if(Yy)return Xy;Yy=1;var e=Jy(),t=eg();function r(e){return nh.isBuffer(e)}function n(e){return"string"==typeof e&&/^([0-9a-f]{2})+$/i.test(e)}function i(e,r){var n=e.toJSON();function i(i){if(!e(i))return!1;if(i.length===r)return!0;throw t.tfCustomError(n+"(Length: "+r+")",n+"(Length: "+i.length+")")}return i.toJSON=function(){return n},i}var o=i.bind(null,e.Array),s=i.bind(null,r),a=i.bind(null,n),u=i.bind(null,e.String),c=Math.pow(2,53)-1,f={ArrayN:o,Buffer:r,BufferN:s,Finite:function(e){return"number"==typeof e&&isFinite(e)},Hex:n,HexN:a,Int8:function(e){return e<<24>>24===e},Int16:function(e){return e<<16>>16===e},Int32:function(e){return(0|e)===e},Int53:function(e){return"number"==typeof e&&e>=-c&&e<=c&&Math.floor(e)===e},Range:function(t,r,n){function i(e,i){return n(e,i)&&e>t&&e<r}return n=n||e.Number,i.toJSON=function(){return`${n.toJSON()} between [${t}, ${r}]`},i},StringN:u,UInt8:function(e){return(255&e)===e},UInt16:function(e){return(65535&e)===e},UInt32:function(e){return e>>>0===e},UInt53:function(e){return"number"==typeof e&&e>=0&&e<=c&&Math.floor(e)===e}};for(var l in f)f[l].toJSON=function(e){return e}.bind(null,l);return Xy=f}();for(f in l)c[f]=l[f];return c.compile=u,c.TfTypeError=n,c.TfPropertyTypeError=i,Zy=c}const rg=Ky(tg()),ng="0123456789abcdefABCDEF";ng.split("").map(e=>e.codePointAt(0)),Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=ng.indexOf(r);return n<0?void 0:n<16?n:n-6}),new TextEncoder,new TextDecoder;function ig(e){"number"==typeof e?function(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!=0)throw new RangeError("value out of range")}(e):(e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")})(e)}function og(e,t,r){ig(e),void 0===r&&(r=0),void 0===t&&(t=new Uint8Array(ag(e)));let n=0;return e<253?(t.set([Number(e)],r),n=1):e<=65535?(t.set([253],r),function(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);"LE"===n?(e[t]=255&r,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=255&r)}(t,r+1,Number(e),"LE"),n=3):e<=4294967295?(t.set([254],r),function(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);"LE"===n?(e[t]=255&r,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r)}(t,r+1,Number(e),"LE"),n=5):(t.set([255],r),function(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 18446744073709551615. Received ${r}`);"LE"===n?(e[t]=Number(0xffn&r),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(0xffn&r))}(t,r+1,BigInt(e),"LE"),n=9),{buffer:t,bytes:n}}function sg(e,t){void 0===t&&(t=0);const r=e.at(t);if(void 0===r)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(253===r){const r=function(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}}(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}if(254===r){const r=function(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}}(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}{const r=function(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0n;return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),r}{let r=0n;return r=(r<<8n)+BigInt(e[t]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+7]),r}}(e,t+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function ag(e){return ig(e),e<253?1:e<=65535?3:e<=4294967295?5:9}var ug,cg={},fg={},lg={},hg={},pg={},dg={};function yg(){return ug||(ug=1,e=dg,Object.defineProperty(e,"__esModule",{value:!0}),(t=e.GlobalTypes||(e.GlobalTypes={}))[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],function(e){e[e.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",e[e.WITNESS_UTXO=1]="WITNESS_UTXO",e[e.PARTIAL_SIG=2]="PARTIAL_SIG",e[e.SIGHASH_TYPE=3]="SIGHASH_TYPE",e[e.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=6]="BIP32_DERIVATION",e[e.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",e[e.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",e[e.POR_COMMITMENT=9]="POR_COMMITMENT",e[e.TAP_KEY_SIG=19]="TAP_KEY_SIG",e[e.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",e[e.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",e[e.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",e[e.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"}(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],function(e){e[e.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=2]="BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",e[e.TAP_TREE=6]="TAP_TREE",e[e.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"}(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]),dg;var e,t}var gg,mg={};function bg(){if(gg)return mg;gg=1,Object.defineProperty(mg,"__esModule",{value:!0});const e=yg();return mg.decode=function(t){if(t.key[0]!==e.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+t.key.toString("hex"));if(79!==t.key.length||![2,3].includes(t.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+t.key.toString("hex"));if(t.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const r=t.key.slice(1),n={masterFingerprint:t.value.slice(0,4),extendedPubkey:r,path:"m"};for(const e of(e=>[...Array(e).keys()])(t.value.length/4-1)){const r=t.value.readUInt32LE(4*e+4),i=!!(2147483648&r),o=2147483647&r;n.path+="/"+o.toString(10)+(i?"'":"")}return n},mg.encode=function(t){const r=nh.from([e.GlobalTypes.GLOBAL_XPUB]),n=nh.concat([r,t.extendedPubkey]),i=t.path.split("/"),o=nh.allocUnsafe(4*i.length);t.masterFingerprint.copy(o,0);let s=4;return i.slice(1).forEach(e=>{const t="'"===e.slice(-1);let r=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(r+=2147483648),o.writeUInt32LE(r,s),s+=4}),{key:n,value:o}},mg.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",mg.check=function(e){const t=e.extendedPubkey,r=e.masterFingerprint,n=e.path;return nh.isBuffer(t)&&78===t.length&&[2,3].indexOf(t[45])>-1&&nh.isBuffer(r)&&4===r.length&&"string"==typeof n&&!!n.match(/^m(\/\d+'?)*$/)},mg.canAddToArray=function(e,t,r){const n=t.extendedPubkey.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.extendedPubkey.equals(t.extendedPubkey)).length)},mg}var wg,vg={};var Eg,_g={};var Sg,kg={};var Ag,Ig={};var Tg,xg={};function Og(){if(Tg)return xg;Tg=1,Object.defineProperty(xg,"__esModule",{value:!0});const e=yg();return xg.decode=function(t){if(t.key[0]!==e.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+t.key.toString("hex"));if(34!==t.key.length&&66!==t.key.length||![2,3,4].includes(t.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1),signature:t.value}},xg.encode=function(t){const r=nh.from([e.InputTypes.PARTIAL_SIG]);return{key:nh.concat([r,t.pubkey]),value:t.signature}},xg.expected="{ pubkey: Buffer; signature: Buffer; }",xg.check=function(e){return nh.isBuffer(e.pubkey)&&nh.isBuffer(e.signature)&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&function(e){if(!nh.isBuffer(e)||e.length<9||48!==e[0]||e.length!==e[1]+3||2!==e[2])return!1;const t=e[3];if(t>33||t<1||2!==e[3+t+1])return!1;const r=e[3+t+2];return!(r>33||r<1||e.length!==3+t+2+r+2)}(e.signature)},xg.canAddToArray=function(e,t,r){const n=t.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.pubkey.equals(t.pubkey)).length)},xg}var Bg,Pg={};var Ug,Lg={};var Ng,Rg={};var Cg,Hg={};var Kg,zg={};var Mg,Dg={};var jg,Fg,Vg,qg={},Wg={},$g={};function Gg(){if(jg)return $g;jg=1,Object.defineProperty($g,"__esModule",{value:!0});function e(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function t(t){return e(t),t<253?1:t<=65535?3:t<=4294967295?5:9}return $g.encode=function r(n,i,o){if(e(n),i||(i=nh.allocUnsafe(t(n))),!nh.isBuffer(i))throw new TypeError("buffer must be a Buffer instance");return o||(o=0),n<253?(i.writeUInt8(n,o),Object.assign(r,{bytes:1})):n<=65535?(i.writeUInt8(253,o),i.writeUInt16LE(n,o+1),Object.assign(r,{bytes:3})):n<=4294967295?(i.writeUInt8(254,o),i.writeUInt32LE(n,o+1),Object.assign(r,{bytes:5})):(i.writeUInt8(255,o),i.writeUInt32LE(n>>>0,o+1),i.writeUInt32LE(n/4294967296|0,o+5),Object.assign(r,{bytes:9})),i},$g.decode=function t(r,n){if(!nh.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");n||(n=0);const i=r.readUInt8(n);if(i<253)return Object.assign(t,{bytes:1}),i;if(253===i)return Object.assign(t,{bytes:3}),r.readUInt16LE(n+1);if(254===i)return Object.assign(t,{bytes:5}),r.readUInt32LE(n+1);{Object.assign(t,{bytes:9});const i=r.readUInt32LE(n+1),o=4294967296*r.readUInt32LE(n+5)+i;return e(o),o}},$g.encodingLength=t,$g}function Xg(){if(Fg)return Wg;Fg=1,Object.defineProperty(Wg,"__esModule",{value:!0});const e=Gg();function t(t){const r=t.key.length,n=t.value.length,i=e.encodingLength(r),o=e.encodingLength(n),s=nh.allocUnsafe(i+r+o+n);return e.encode(r,s,0),t.key.copy(s,i),e.encode(n,s,i+r),t.value.copy(s,i+r+o),s}function r(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}return Wg.range=e=>[...Array(e).keys()],Wg.reverseBuffer=function(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e},Wg.keyValsToBuffer=function(e){const r=e.map(t);return r.push(nh.from([0])),nh.concat(r)},Wg.keyValToBuffer=t,Wg.readUInt64LE=function(e,t){const n=e.readUInt32LE(t);let i=e.readUInt32LE(t+4);return i*=4294967296,r(i+n,9007199254740991),i+n},Wg.writeUInt64LE=function(e,t,n){return r(t,9007199254740991),e.writeInt32LE(-1&t,n),e.writeUInt32LE(Math.floor(t/4294967296),n+4),n+8},Wg}var Yg,Zg={};var Qg,Jg={};function em(){if(Qg)return Jg;Qg=1,Object.defineProperty(Jg,"__esModule",{value:!0});const e=e=>33===e.length&&[2,3].includes(e[0])||65===e.length&&4===e[0];return Jg.makeConverter=function(t,r=e){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+e.key.toString("hex"));const n=e.key.slice(1);if(!r(n))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+e.key.toString("hex"));if(e.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:e.value.slice(0,4),pubkey:n,path:"m"};for(const t of(e=>[...Array(e).keys()])(e.value.length/4-1)){const r=e.value.readUInt32LE(4*t+4),n=!!(2147483648&r),o=2147483647&r;i.path+="/"+o.toString(10)+(n?"'":"")}return i},encode:function(e){const r=nh.from([t]),n=nh.concat([r,e.pubkey]),i=e.path.split("/"),o=nh.allocUnsafe(4*i.length);e.masterFingerprint.copy(o,0);let s=4;return i.slice(1).forEach(e=>{const t="'"===e.slice(-1);let r=2147483647&parseInt(t?e.slice(0,-1):e,10);t&&(r+=2147483648),o.writeUInt32LE(r,s),s+=4}),{key:n,value:o}},check:function(e){return nh.isBuffer(e.pubkey)&&nh.isBuffer(e.masterFingerprint)&&"string"==typeof e.path&&r(e.pubkey)&&4===e.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(e,t,r){const n=t.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.pubkey.equals(t.pubkey)).length)}}},Jg}var tm,rm={};var nm,im={};var om,sm={};var am,um={};var cm,fm,lm,hm={};function pm(){if(fm)return pg;fm=1,Object.defineProperty(pg,"__esModule",{value:!0});const e=yg(),t=bg(),r=function(){if(wg)return vg;wg=1,Object.defineProperty(vg,"__esModule",{value:!0});const e=yg();return vg.encode=function(t){return{key:nh.from([e.GlobalTypes.UNSIGNED_TX]),value:t.toBuffer()}},vg}(),n=function(){if(Eg)return _g;Eg=1,Object.defineProperty(_g,"__esModule",{value:!0});const e=yg();return _g.decode=function(t){if(t.key[0]!==e.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+t.key.toString("hex"));return t.value},_g.encode=function(t){return{key:nh.from([e.InputTypes.FINAL_SCRIPTSIG]),value:t}},_g.expected="Buffer",_g.check=function(e){return nh.isBuffer(e)},_g.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptSig},_g}(),i=function(){if(Sg)return kg;Sg=1,Object.defineProperty(kg,"__esModule",{value:!0});const e=yg();return kg.decode=function(t){if(t.key[0]!==e.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+t.key.toString("hex"));return t.value},kg.encode=function(t){return{key:nh.from([e.InputTypes.FINAL_SCRIPTWITNESS]),value:t}},kg.expected="Buffer",kg.check=function(e){return nh.isBuffer(e)},kg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.finalScriptWitness},kg}(),o=function(){if(Ag)return Ig;Ag=1,Object.defineProperty(Ig,"__esModule",{value:!0});const e=yg();return Ig.decode=function(t){if(t.key[0]!==e.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+t.key.toString("hex"));return t.value},Ig.encode=function(t){return{key:nh.from([e.InputTypes.NON_WITNESS_UTXO]),value:t}},Ig.expected="Buffer",Ig.check=function(e){return nh.isBuffer(e)},Ig.canAdd=function(e,t){return!!e&&!!t&&void 0===e.nonWitnessUtxo},Ig}(),s=Og(),a=function(){if(Bg)return Pg;Bg=1,Object.defineProperty(Pg,"__esModule",{value:!0});const e=yg();return Pg.decode=function(t){if(t.key[0]!==e.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+t.key.toString("hex"));return t.value.toString("utf8")},Pg.encode=function(t){return{key:nh.from([e.InputTypes.POR_COMMITMENT]),value:nh.from(t,"utf8")}},Pg.expected="string",Pg.check=function(e){return"string"==typeof e},Pg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.porCommitment},Pg}(),u=function(){if(Ug)return Lg;Ug=1,Object.defineProperty(Lg,"__esModule",{value:!0});const e=yg();return Lg.decode=function(t){if(t.key[0]!==e.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+t.key.toString("hex"));return t.value.readUInt32LE(0)},Lg.encode=function(t){const r=nh.from([e.InputTypes.SIGHASH_TYPE]),n=nh.allocUnsafe(4);return n.writeUInt32LE(t,0),{key:r,value:n}},Lg.expected="number",Lg.check=function(e){return"number"==typeof e},Lg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.sighashType},Lg}(),c=function(){if(Ng)return Rg;Ng=1,Object.defineProperty(Rg,"__esModule",{value:!0});const e=yg();function t(e){return nh.isBuffer(e)&&(64===e.length||65===e.length)}return Rg.decode=function(r){if(r.key[0]!==e.InputTypes.TAP_KEY_SIG||1!==r.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+r.key.toString("hex"));if(!t(r.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return r.value},Rg.encode=function(t){return{key:nh.from([e.InputTypes.TAP_KEY_SIG]),value:t}},Rg.expected="Buffer",Rg.check=t,Rg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapKeySig},Rg}(),f=function(){if(Cg)return Hg;Cg=1,Object.defineProperty(Hg,"__esModule",{value:!0});const e=yg();return Hg.decode=function(t){if(t.key[0]!==e.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+t.key.toString("hex"));if((t.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+t.key.toString("hex"));const r=t.value[t.value.length-1];if((254&t.key[1])!==r)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+t.key.toString("hex"));const n=t.value.slice(0,-1);return{controlBlock:t.key.slice(1),script:n,leafVersion:r}},Hg.encode=function(t){const r=nh.from([e.InputTypes.TAP_LEAF_SCRIPT]),n=nh.from([t.leafVersion]);return{key:nh.concat([r,t.controlBlock]),value:nh.concat([t.script,n])}},Hg.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",Hg.check=function(e){return nh.isBuffer(e.controlBlock)&&(e.controlBlock.length-1)%32==0&&(254&e.controlBlock[0])===e.leafVersion&&nh.isBuffer(e.script)},Hg.canAddToArray=function(e,t,r){const n=t.controlBlock.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.controlBlock.equals(t.controlBlock)).length)},Hg}(),l=function(){if(Kg)return zg;Kg=1,Object.defineProperty(zg,"__esModule",{value:!0});const e=yg();function t(e){return nh.isBuffer(e)&&32===e.length}return zg.decode=function(r){if(r.key[0]!==e.InputTypes.TAP_MERKLE_ROOT||1!==r.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+r.key.toString("hex"));if(!t(r.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return r.value},zg.encode=function(t){return{key:nh.from([e.InputTypes.TAP_MERKLE_ROOT]),value:t}},zg.expected="Buffer",zg.check=t,zg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapMerkleRoot},zg}(),h=function(){if(Mg)return Dg;Mg=1,Object.defineProperty(Dg,"__esModule",{value:!0});const e=yg();return Dg.decode=function(t){if(t.key[0]!==e.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+t.key.toString("hex"));if(65!==t.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+t.key.toString("hex"));if(64!==t.value.length&&65!==t.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1,33),leafHash:t.key.slice(33),signature:t.value}},Dg.encode=function(t){const r=nh.from([e.InputTypes.TAP_SCRIPT_SIG]);return{key:nh.concat([r,t.pubkey,t.leafHash]),value:t.signature}},Dg.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",Dg.check=function(e){return nh.isBuffer(e.pubkey)&&nh.isBuffer(e.leafHash)&&nh.isBuffer(e.signature)&&32===e.pubkey.length&&32===e.leafHash.length&&(64===e.signature.length||65===e.signature.length)},Dg.canAddToArray=function(e,t,r){const n=t.pubkey.toString("hex")+t.leafHash.toString("hex");return!r.has(n)&&(r.add(n),0===e.filter(e=>e.pubkey.equals(t.pubkey)&&e.leafHash.equals(t.leafHash)).length)},Dg}(),p=function(){if(Vg)return qg;Vg=1,Object.defineProperty(qg,"__esModule",{value:!0});const e=yg(),t=Xg(),r=Gg();return qg.decode=function(n){if(n.key[0]!==e.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+n.key.toString("hex"));const i=t.readUInt64LE(n.value,0);let o=8;const s=r.decode(n.value,o);o+=r.encodingLength(s);const a=n.value.slice(o);if(a.length!==s)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:a,value:i}},qg.encode=function(n){const{script:i,value:o}=n,s=r.encodingLength(i.length),a=nh.allocUnsafe(8+s+i.length);return t.writeUInt64LE(a,o,0),r.encode(i.length,a,8),i.copy(a,8+s),{key:nh.from([e.InputTypes.WITNESS_UTXO]),value:a}},qg.expected="{ script: Buffer; value: number; }",qg.check=function(e){return nh.isBuffer(e.script)&&"number"==typeof e.value},qg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.witnessUtxo},qg}(),d=function(){if(Yg)return Zg;Yg=1,Object.defineProperty(Zg,"__esModule",{value:!0});const e=yg(),t=Gg();return Zg.decode=function(r){if(r.key[0]!==e.OutputTypes.TAP_TREE||1!==r.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+r.key.toString("hex"));let n=0;const i=[];for(;n<r.value.length;){const e=r.value[n++],o=r.value[n++],s=t.decode(r.value,n);n+=t.encodingLength(s),i.push({depth:e,leafVersion:o,script:r.value.slice(n,n+s)}),n+=s}return{leaves:i}},Zg.encode=function(r){const n=nh.from([e.OutputTypes.TAP_TREE]),i=[].concat(...r.leaves.map(e=>[nh.of(e.depth,e.leafVersion),t.encode(e.script.length),e.script]));return{key:n,value:nh.concat(i)}},Zg.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",Zg.check=function(e){return Array.isArray(e.leaves)&&e.leaves.every(e=>e.depth>=0&&e.depth<=128&&(254&e.leafVersion)===e.leafVersion&&nh.isBuffer(e.script))},Zg.canAdd=function(e,t){return!!e&&!!t&&void 0===e.tapTree},Zg}(),y=em(),g=(tm||(tm=1,Object.defineProperty(rm,"__esModule",{value:!0}),rm.makeChecker=function(e){return function(t){let r;if(e.includes(t.key[0])&&(r=t.key.slice(1),33!==r.length&&65!==r.length||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+t.key.toString("hex"));return r}}),rm),m=(nm||(nm=1,Object.defineProperty(im,"__esModule",{value:!0}),im.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:nh.from([e]),value:t}},check:function(e){return nh.isBuffer(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.redeemScript}}}),im),b=function(){if(om)return sm;om=1,Object.defineProperty(sm,"__esModule",{value:!0});const e=Gg(),t=em(),r=e=>32===e.length;return sm.makeConverter=function(n){const i=t.makeConverter(n,r);return{decode:function(t){const r=e.decode(t.value),n=e.encodingLength(r),o=i.decode({key:t.key,value:t.value.slice(n+32*r)}),s=new Array(r);for(let e=0,i=n;e<r;e++,i+=32)s[e]=t.value.slice(i,i+32);return Object.assign({},o,{leafHashes:s})},encode:function(t){const r=i.encode(t),n=e.encodingLength(t.leafHashes.length),o=nh.allocUnsafe(n);e.encode(t.leafHashes.length,o);const s=nh.concat([o,...t.leafHashes,r.value]);return Object.assign({},r,{value:s})},check:function(e){return Array.isArray(e.leafHashes)&&e.leafHashes.every(e=>nh.isBuffer(e)&&32===e.length)&&i.check(e)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:i.canAddToArray}},sm}(),w=(am||(am=1,Object.defineProperty(um,"__esModule",{value:!0}),um.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e||1!==t.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+t.key.toString("hex"));if(32!==t.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return t.value},encode:function(t){return{key:nh.from([e]),value:t}},check:function(e){return nh.isBuffer(e)&&32===e.length},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.tapInternalKey}}}),um),v=(cm||(cm=1,Object.defineProperty(hm,"__esModule",{value:!0}),hm.makeConverter=function(e){return{decode:function(t){if(t.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+t.key.toString("hex"));return t.value},encode:function(t){return{key:nh.from([e]),value:t}},check:function(e){return nh.isBuffer(e)},expected:"Buffer",canAdd:function(e,t){return!!e&&!!t&&void 0===e.witnessScript}}}),hm),E={unsignedTx:r,globalXpub:t,checkPubkey:g.makeChecker([])};pg.globals=E;const _={nonWitnessUtxo:o,partialSig:s,sighashType:u,finalScriptSig:n,finalScriptWitness:i,porCommitment:a,witnessUtxo:p,bip32Derivation:y.makeConverter(e.InputTypes.BIP32_DERIVATION),redeemScript:m.makeConverter(e.InputTypes.REDEEM_SCRIPT),witnessScript:v.makeConverter(e.InputTypes.WITNESS_SCRIPT),checkPubkey:g.makeChecker([e.InputTypes.PARTIAL_SIG,e.InputTypes.BIP32_DERIVATION]),tapKeySig:c,tapScriptSig:h,tapLeafScript:f,tapBip32Derivation:b.makeConverter(e.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:w.makeConverter(e.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:l};pg.inputs=_;const S={bip32Derivation:y.makeConverter(e.OutputTypes.BIP32_DERIVATION),redeemScript:m.makeConverter(e.OutputTypes.REDEEM_SCRIPT),witnessScript:v.makeConverter(e.OutputTypes.WITNESS_SCRIPT),checkPubkey:g.makeChecker([e.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:b.makeConverter(e.OutputTypes.TAP_BIP32_DERIVATION),tapTree:d,tapInternalKey:w.makeConverter(e.OutputTypes.TAP_INTERNAL_KEY)};return pg.outputs=S,pg}var dm,ym,gm,mm={};function bm(){return ym||(ym=1,function(e){function t(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),t(function(){if(lm)return hg;lm=1,Object.defineProperty(hg,"__esModule",{value:!0});const e=pm(),t=Xg(),r=Gg(),n=yg();function i(e,t,r){if(!t.equals(nh.from([r])))throw new Error(`Format Error: Invalid ${e} key: ${t.toString("hex")}`)}function o(r,{globalMapKeyVals:o,inputKeyVals:s,outputKeyVals:a}){const u={unsignedTx:r};let c=0;for(const t of o)switch(t.key[0]){case n.GlobalTypes.UNSIGNED_TX:if(i("global",t.key,n.GlobalTypes.UNSIGNED_TX),c>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");c++;break;case n.GlobalTypes.GLOBAL_XPUB:void 0===u.globalXpub&&(u.globalXpub=[]),u.globalXpub.push(e.globals.globalXpub.decode(t));break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(t)}const f=s.length,l=a.length,h=[],p=[];for(const d of t.range(f)){const t={};for(const r of s[d])switch(e.inputs.checkPubkey(r),r.key[0]){case n.InputTypes.NON_WITNESS_UTXO:if(i("input",r.key,n.InputTypes.NON_WITNESS_UTXO),void 0!==t.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");t.nonWitnessUtxo=e.inputs.nonWitnessUtxo.decode(r);break;case n.InputTypes.WITNESS_UTXO:if(i("input",r.key,n.InputTypes.WITNESS_UTXO),void 0!==t.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");t.witnessUtxo=e.inputs.witnessUtxo.decode(r);break;case n.InputTypes.PARTIAL_SIG:void 0===t.partialSig&&(t.partialSig=[]),t.partialSig.push(e.inputs.partialSig.decode(r));break;case n.InputTypes.SIGHASH_TYPE:if(i("input",r.key,n.InputTypes.SIGHASH_TYPE),void 0!==t.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");t.sighashType=e.inputs.sighashType.decode(r);break;case n.InputTypes.REDEEM_SCRIPT:if(i("input",r.key,n.InputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");t.redeemScript=e.inputs.redeemScript.decode(r);break;case n.InputTypes.WITNESS_SCRIPT:if(i("input",r.key,n.InputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");t.witnessScript=e.inputs.witnessScript.decode(r);break;case n.InputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(e.inputs.bip32Derivation.decode(r));break;case n.InputTypes.FINAL_SCRIPTSIG:i("input",r.key,n.InputTypes.FINAL_SCRIPTSIG),t.finalScriptSig=e.inputs.finalScriptSig.decode(r);break;case n.InputTypes.FINAL_SCRIPTWITNESS:i("input",r.key,n.InputTypes.FINAL_SCRIPTWITNESS),t.finalScriptWitness=e.inputs.finalScriptWitness.decode(r);break;case n.InputTypes.POR_COMMITMENT:i("input",r.key,n.InputTypes.POR_COMMITMENT),t.porCommitment=e.inputs.porCommitment.decode(r);break;case n.InputTypes.TAP_KEY_SIG:i("input",r.key,n.InputTypes.TAP_KEY_SIG),t.tapKeySig=e.inputs.tapKeySig.decode(r);break;case n.InputTypes.TAP_SCRIPT_SIG:void 0===t.tapScriptSig&&(t.tapScriptSig=[]),t.tapScriptSig.push(e.inputs.tapScriptSig.decode(r));break;case n.InputTypes.TAP_LEAF_SCRIPT:void 0===t.tapLeafScript&&(t.tapLeafScript=[]),t.tapLeafScript.push(e.inputs.tapLeafScript.decode(r));break;case n.InputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(e.inputs.tapBip32Derivation.decode(r));break;case n.InputTypes.TAP_INTERNAL_KEY:i("input",r.key,n.InputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=e.inputs.tapInternalKey.decode(r);break;case n.InputTypes.TAP_MERKLE_ROOT:i("input",r.key,n.InputTypes.TAP_MERKLE_ROOT),t.tapMerkleRoot=e.inputs.tapMerkleRoot.decode(r);break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(r)}h.push(t)}for(const d of t.range(l)){const t={};for(const r of a[d])switch(e.outputs.checkPubkey(r),r.key[0]){case n.OutputTypes.REDEEM_SCRIPT:if(i("output",r.key,n.OutputTypes.REDEEM_SCRIPT),void 0!==t.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");t.redeemScript=e.outputs.redeemScript.decode(r);break;case n.OutputTypes.WITNESS_SCRIPT:if(i("output",r.key,n.OutputTypes.WITNESS_SCRIPT),void 0!==t.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");t.witnessScript=e.outputs.witnessScript.decode(r);break;case n.OutputTypes.BIP32_DERIVATION:void 0===t.bip32Derivation&&(t.bip32Derivation=[]),t.bip32Derivation.push(e.outputs.bip32Derivation.decode(r));break;case n.OutputTypes.TAP_INTERNAL_KEY:i("output",r.key,n.OutputTypes.TAP_INTERNAL_KEY),t.tapInternalKey=e.outputs.tapInternalKey.decode(r);break;case n.OutputTypes.TAP_TREE:i("output",r.key,n.OutputTypes.TAP_TREE),t.tapTree=e.outputs.tapTree.decode(r);break;case n.OutputTypes.TAP_BIP32_DERIVATION:void 0===t.tapBip32Derivation&&(t.tapBip32Derivation=[]),t.tapBip32Derivation.push(e.outputs.tapBip32Derivation.decode(r));break;default:t.unknownKeyVals||(t.unknownKeyVals=[]),t.unknownKeyVals.push(r)}p.push(t)}return{globalMap:u,inputs:h,outputs:p}}return hg.psbtFromBuffer=function(e,i){let s=0;function a(){const t=r.decode(e,s);s+=r.encodingLength(t);const n=e.slice(s,s+t);return s+=t,n}function u(){return{key:a(),value:a()}}function c(){if(s>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const t=0===e.readUInt8(s);return t&&s++,t}if(1886610036!==function(){const t=e.readUInt32BE(s);return s+=4,t}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const t=e.readUInt8(s);return s+=1,t}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const f=[],l={};for(;!c();){const e=u(),t=e.key.toString("hex");if(l[t])throw new Error("Format Error: Keys must be unique for global keymap: key "+t);l[t]=1,f.push(e)}const h=f.filter(e=>e.key[0]===n.GlobalTypes.UNSIGNED_TX);if(1!==h.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const p=i(h[0].value),{inputCount:d,outputCount:y}=p.getInputOutputCounts(),g=[],m=[];for(const r of t.range(d)){const e={},t=[];for(;!c();){const n=u(),i=n.key.toString("hex");if(e[i])throw new Error("Format Error: Keys must be unique for each input: input index "+r+" key "+i);e[i]=1,t.push(n)}g.push(t)}for(const r of t.range(y)){const e={},t=[];for(;!c();){const n=u(),i=n.key.toString("hex");if(e[i])throw new Error("Format Error: Keys must be unique for each output: output index "+r+" key "+i);e[i]=1,t.push(n)}m.push(t)}return o(p,{globalMapKeyVals:f,inputKeyVals:g,outputKeyVals:m})},hg.checkKeyBuffer=i,hg.psbtFromKeyVals=o,hg}()),t(function(){if(dm)return mm;dm=1,Object.defineProperty(mm,"__esModule",{value:!0});const e=pm(),t=Xg();mm.psbtToBuffer=function({globalMap:e,inputs:r,outputs:n}){const{globalKeyVals:o,inputKeyVals:s,outputKeyVals:a}=i({globalMap:e,inputs:r,outputs:n}),u=t.keyValsToBuffer(o),c=e=>0===e.length?[nh.from([0])]:e.map(t.keyValsToBuffer),f=c(s),l=c(a),h=nh.allocUnsafe(5);return h.writeUIntBE(482972169471,0,5),nh.concat([h,u].concat(f,l))};const r=(e,t)=>e.key.compare(t.key);function n(e,t){const n=new Set,i=Object.entries(e).reduce((e,[r,i])=>{if("unknownKeyVals"===r)return e;const o=t[r];if(void 0===o)return e;const s=(Array.isArray(i)?i:[i]).map(o.encode);return s.map(e=>e.key.toString("hex")).forEach(e=>{if(n.has(e))throw new Error("Serialize Error: Duplicate key: "+e);n.add(e)}),e.concat(s)},[]),o=e.unknownKeyVals?e.unknownKeyVals.filter(e=>!n.has(e.key.toString("hex"))):[];return i.concat(o).sort(r)}function i({globalMap:t,inputs:r,outputs:i}){return{globalKeyVals:n(t,e.globals),inputKeyVals:r.map(t=>n(t,e.inputs)),outputKeyVals:i.map(t=>n(t,e.outputs))}}return mm.psbtToKeyVals=i,mm}())}(lg)),lg}var wm,vm,Em={};function _m(){return wm||(wm=1,function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=pm();function r(e,t){const r=e[t];if(void 0===r)throw new Error(`No input #${t}`);return r}function n(e,t){const r=e[t];if(void 0===r)throw new Error(`No output #${t}`);return r}function i(e,t,r,n){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function o(e){return(r,n)=>{for(const o of Object.keys(r)){const s=r[o],{canAdd:a,canAddToArray:u,check:c,expected:f}=t[e+"s"][o]||{};if(c)if(!!u){if(!Array.isArray(s)||n[o]&&!Array.isArray(n[o]))throw new Error(`Key type ${o} must be an array`);s.every(c)||i(e,o,f,s);const t=n[o]||[],r=new Set;if(!s.every(e=>u(t,e,r)))throw new Error("Can not add duplicate data to array");n[o]=t.concat(s)}else{if(c(s)||i(e,o,f,s),!a(n,s))throw new Error(`Can not add duplicate data to ${e}`);n[o]=s}}}}e.checkForInput=r,e.checkForOutput=n,e.checkHasKey=function(e,t,r){if(e.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&0!==t.filter(t=>t.key.equals(e.key)).length)throw new Error(`Duplicate Key: ${e.key.toString("hex")}`)},e.getEnumLength=function(e){let t=0;return Object.keys(e).forEach(e=>{Number(isNaN(Number(e)))&&t++}),t},e.inputCheckUncleanFinalized=function(e,t){let r=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const e=!!t.redeemScript,n=!!t.witnessScript,i=!e||!!t.finalScriptSig,o=!n||!!t.finalScriptWitness,s=!!t.finalScriptSig||!!t.finalScriptWitness;r=i&&o&&s}if(!1===r)throw new Error(`Input #${e} has too much or too little data to clean`)},e.updateGlobal=o("global"),e.updateInput=o("input"),e.updateOutput=o("output"),e.addInputAttributes=function(t,n){const i=r(t,t.length-1);e.updateInput(n,i)},e.addOutputAttributes=function(t,r){const i=n(t,t.length-1);e.updateOutput(r,i)},e.defaultVersionSetter=function(e,t){if(!nh.isBuffer(t)||t.length<4)throw new Error("Set Version: Invalid Transaction");return t.writeUInt32LE(e,0),t},e.defaultLocktimeSetter=function(e,t){if(!nh.isBuffer(t)||t.length<4)throw new Error("Set Locktime: Invalid Transaction");return t.writeUInt32LE(e,t.length-4),t}}(Em)),Em}var Sm,km=function(){if(vm)return cg;vm=1,Object.defineProperty(cg,"__esModule",{value:!0});const e=function(){if(gm)return fg;gm=1,Object.defineProperty(fg,"__esModule",{value:!0});const e=bm();function t(e,t,r){return n=>{if(e.has(n))return;const i=r.filter(e=>e.key.toString("hex")===n)[0];t.push(i),e.add(n)}}function r(e){return e.globalMap.unsignedTx}function n(e){const t=new Set;return e.forEach(e=>{const r=e.key.toString("hex");if(t.has(r))throw new Error("Combine: KeyValue Map keys should be unique");t.add(r)}),t}return fg.combine=function(i){const o=i[0],s=e.psbtToKeyVals(o),a=i.slice(1);if(0===a.length)throw new Error("Combine: Nothing to combine");const u=r(o);if(void 0===u)throw new Error("Combine: Self missing transaction");const c=n(s.globalKeyVals),f=s.inputKeyVals.map(n),l=s.outputKeyVals.map(n);for(const h of a){const i=r(h);if(void 0===i||!i.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const o=e.psbtToKeyVals(h);n(o.globalKeyVals).forEach(t(c,s.globalKeyVals,o.globalKeyVals)),o.inputKeyVals.map(n).forEach((e,r)=>e.forEach(t(f[r],s.inputKeyVals[r],o.inputKeyVals[r]))),o.outputKeyVals.map(n).forEach((e,r)=>e.forEach(t(l[r],s.outputKeyVals[r],o.outputKeyVals[r])))}return e.psbtFromKeyVals(u,{globalMapKeyVals:s.globalKeyVals,inputKeyVals:s.inputKeyVals,outputKeyVals:s.outputKeyVals})},fg}(),t=bm(),r=yg(),n=_m();return cg.Psbt=class{constructor(e){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:e}}static fromBase64(e,t){const r=nh.from(e,"base64");return this.fromBuffer(r,t)}static fromHex(e,t){const r=nh.from(e,"hex");return this.fromBuffer(r,t)}static fromBuffer(e,r){const n=t.psbtFromBuffer(e,r),i=new this(n.globalMap.unsignedTx);return Object.assign(i,n),i}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return t.psbtToBuffer(this)}updateGlobal(e){return n.updateGlobal(e,this.globalMap),this}updateInput(e,t){const r=n.checkForInput(this.inputs,e);return n.updateInput(t,r),this}updateOutput(e,t){const r=n.checkForOutput(this.outputs,e);return n.updateOutput(t,r),this}addUnknownKeyValToGlobal(e){return n.checkHasKey(e,this.globalMap.unknownKeyVals,n.getEnumLength(r.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(e),this}addUnknownKeyValToInput(e,t){const i=n.checkForInput(this.inputs,e);return n.checkHasKey(t,i.unknownKeyVals,n.getEnumLength(r.InputTypes)),i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(t),this}addUnknownKeyValToOutput(e,t){const i=n.checkForOutput(this.outputs,e);return n.checkHasKey(t,i.unknownKeyVals,n.getEnumLength(r.OutputTypes)),i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(t),this}addInput(e){this.globalMap.unsignedTx.addInput(e),this.inputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach(e=>this.addUnknownKeyValToInput(r,e)),n.addInputAttributes(this.inputs,e),this}addOutput(e){this.globalMap.unsignedTx.addOutput(e),this.outputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach(e=>this.addUnknownKeyValToOutput(r,e)),n.addOutputAttributes(this.outputs,e),this}clearFinalizedInput(e){const t=n.checkForInput(this.inputs,e);n.inputCheckUncleanFinalized(e,t);for(const r of Object.keys(t))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(r)||delete t[r];return this}combine(...t){const r=e.combine([this].concat(t));return Object.assign(this,r),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}},cg}(),Am=Gg(),Im=_m(),Tm={};var xm=function(){if(Sm)return Tm;Sm=1;var e=uf(),t=Jc(),r=lf();function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var i=n(t),o=n(r);const s=e.secp256k1.ProjectivePoint,a="Expected Private",u="Expected Point",c="Expected Tweak",f="Expected Signature",l="Expected Extra Data (32 bytes)",h="Expected Scalar",p=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230,175,72,160,59,191,210,94,140,208,54,65,65]),d=new Uint8Array(32),y=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,69,81,35,25,80,183,95,196,64,45,161,114,47,201,186,238]),g=BigInt(1);function m(e,t){for(let r=0;r<32;++r)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function b(e){return 0===m(e,d)}function w(e){return!(!(e instanceof Uint8Array)||32!==e.length||m(e,p)>=0)}function v(e){return e instanceof Uint8Array&&64===e.length&&m(e.subarray(0,32),p)<0&&m(e.subarray(32,64),p)<0}function E(e){return function(e){return e instanceof Uint8Array}(e)&&64===e.length&&m(e.subarray(0,32),y)<0}function _(e){return e instanceof Uint8Array&&32===e.length}function S(e){return void 0===e||e instanceof Uint8Array&&32===e.length}function k(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e&&Number.isSafeInteger(e)&&e>=0)t=BigInt(e);else if("string"==typeof e){if(64!==e.length)throw new Error("Expected 32 bytes of private scalar");t=o.hexToNumber(e)}else{if(!(e instanceof Uint8Array))throw new TypeError("Expected valid private scalar");if(32!==e.length)throw new Error("Expected 32 bytes of private scalar");t=o.bytesToNumberBE(e)}if(t<0)throw new Error("Expected private scalar >= 0");return t}function A(t){return e.secp256k1.utils.normPrivateKeyToScalar(t)}function I(e,t,r){const n=B(e),i=k(t),o=s.BASE.multiplyAndAddUnsafe(n,i,g);if(!o)throw new Error("Tweaked point at infinity");return o.toRawBytes(r)}function T(e,t){return void 0===e?void 0===t||L(t):!!e}function x(e){try{return e()}catch{return null}}function O(t){return e.schnorr.utils.lift_x(o.bytesToNumberBE(t))}function B(e){return 32===e.length?O(e):s.fromHex(e)}function P(e,t){if(32===e.length!==t)return!1;try{return t?!!O(e):!!s.fromHex(e)}catch{return!1}}function U(e){return P(e,!1)}function L(e){return P(e,!1)&&33===e.length}function N(t){return e.secp256k1.utils.isValidPrivateKey(t)}function R(e){return P(e,!0)}function C(e){if(!U(e))throw new Error(u);return e.slice(1,33)}function H(t,r){if(!N(t))throw new Error(a);return x(()=>e.secp256k1.getPublicKey(t,T(r)))}return Tm.isPoint=U,Tm.isPointCompressed=L,Tm.isPrivate=N,Tm.isXOnlyPoint=R,Tm.pointAdd=function(e,t,r){if(!U(e)||!U(t))throw new Error(u);return x(()=>{const n=B(e),i=B(t);return n.equals(i.negate())?null:n.add(i).toRawBytes(T(r,e))})},Tm.pointAddScalar=function(e,t,r){if(!U(e))throw new Error(u);if(!w(t))throw new Error(c);return x(()=>I(e,t,T(r,e)))},Tm.pointCompress=function(e,t){if(!U(e))throw new Error(u);return B(e).toRawBytes(T(t,e))},Tm.pointFromScalar=H,Tm.pointMultiply=function(e,t,r){if(!U(e))throw new Error(u);if(!w(t))throw new Error(c);return x(()=>function(e,t,r){const n=B(e),i="string"==typeof t?t:o.bytesToHex(t),s=o.hexToNumber(i);return n.multiply(s).toRawBytes(r)}(e,t,T(r,e)))},Tm.privateAdd=function(t,r){if(!N(t))throw new Error(a);if(!w(r))throw new Error(c);return x(()=>function(t,r){const n=A(t),s=k(r),a=o.numberToBytesBE(i.mod(n+s,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(a)?a:null}(t,r))},Tm.privateNegate=function(t){if(!N(t))throw new Error(a);return function(t){const r=A(t),n=o.numberToBytesBE(e.secp256k1.CURVE.n-r,32);return e.secp256k1.utils.isValidPrivateKey(n)?n:null}(t)},Tm.privateSub=function(t,r){if(!N(t))throw new Error(a);if(!w(r))throw new Error(c);return x(()=>function(t,r){const n=A(t),s=k(r),a=o.numberToBytesBE(i.mod(n-s,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(a)?a:null}(t,r))},Tm.recover=function(t,r,n,i){if(!_(t))throw new Error("Expected Hash");if(!v(r)||!function(e){return!(b(e.subarray(0,32))||b(e.subarray(32,64)))}(r))throw new Error(f);if(2&n&&!E(r))throw new Error("Bad Recovery Id");if(!R(r.subarray(0,32)))throw new Error(f);const o=e.secp256k1.Signature.fromCompact(r).addRecoveryBit(n).recoverPublicKey(t);if(!o)throw new Error(f);return o.toRawBytes(T(i))},Tm.sign=function(t,r,n){if(!N(r))throw new Error(a);if(!_(t))throw new Error(h);if(!S(n))throw new Error(l);return e.secp256k1.sign(t,r,{extraEntropy:n}).toCompactRawBytes()},Tm.signRecoverable=function(t,r,n){if(!N(r))throw new Error(a);if(!_(t))throw new Error(h);if(!S(n))throw new Error(l);const i=e.secp256k1.sign(t,r,{extraEntropy:n});return{signature:i.toCompactRawBytes(),recoveryId:i.recovery}},Tm.signSchnorr=function(t,r,n){if(!N(r))throw new Error(a);if(!_(t))throw new Error(h);if(!S(n))throw new Error(l);return e.schnorr.sign(t,r,n)},Tm.verify=function(t,r,n,i){if(!U(r))throw new Error(u);if(!v(n))throw new Error(f);if(!_(t))throw new Error(h);return e.secp256k1.verify(n,t,r,{lowS:i})},Tm.verifySchnorr=function(t,r,n){if(!R(r))throw new Error(u);if(!v(n))throw new Error(f);if(!_(t))throw new Error(h);return e.schnorr.verify(n,t,r)},Tm.xOnlyPointAddTweak=function(e,t){if(!R(e))throw new Error(u);if(!w(t))throw new Error(c);return x(()=>{const r=I(e,t,!0);return{parity:r[0]%2==1?1:0,xOnlyPubkey:r.slice(1)}})},Tm.xOnlyPointFromPoint=C,Tm.xOnlyPointFromScalar=function(e){if(!N(e))throw new Error(a);return C(H(e))},Tm}();const Om=ql({__proto__:null,default:Ky(xm)},[xm]);var Bm,Pm={},Um={},Lm={};function Nm(){if(Bm)return Lm;Bm=1,Object.defineProperty(Lm,"__esModule",{value:!0}),Lm.hash160=function(e){return(0,t.ripemd160)((0,r.sha256)(e))},Lm.hash256=function(e){return(0,r.sha256)(e)},Lm.hmacSHA512=function(t,r){return(0,e.hmac)(n.sha512,t,r)};const e=Vu(),t=Yu(),r=Ju(),n=rc();return Lm}var Rm={};const Cm="0123456789abcdefABCDEF",Hm=Cm.split("").map(e=>e.codePointAt(0)),Km=Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=Cm.indexOf(r);return n<0?void 0:n<16?n:n-6}),zm=new TextEncoder,Mm=new TextDecoder;const Dm=Object.freeze(Object.defineProperty({__proto__:null,compare:function(e,t){const r=Math.min(e.length,t.length);for(let n=0;n<r;++n)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return e.length===t.length?0:e.length>t.length?1:-1},concat:function(e){const t=e.reduce((e,t)=>e+t.length,0),r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.length;return r},fromBase64:function(e){const t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r},fromHex:function(e){const t=zm.encode(e||""),r=new Uint8Array(Math.floor(t.length/2));let n;for(n=0;n<r.length;n++){const e=Km[t[2*n]],i=Km[t[2*n+1]];if(void 0===e||void 0===i)break;r[n]=e<<4|i}return n===r.length?r:r.slice(0,n)},fromUtf8:function(e){return zm.encode(e)},readInt16:function(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){const r=e[t]+(e[t+1]<<8);return e[t+1]<=127?r:r-65536}{const r=(e[t]<<8)+e[t+1];return e[t]<=127?r:r-65536}},readInt32:function(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){const r=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0);return e[t+3]<=127?r:r-4294967296}{const r=(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];return e[t]<=127?r:r-4294967296}},readInt64:function(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");let n=0n;if("LE"===(r=r.toUpperCase()))return n=(n<<8n)+BigInt(e[t+7]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t]),e[t+7]<=127?n:n-0x10000000000000000n;{let r=0n;return r=(r<<8n)+BigInt(e[t]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+7]),e[t]<=127?r:r-0x10000000000000000n}},readInt8:function(e,t){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");const r=e[t];return r<=127?r:r-256},readUInt16:function(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}},readUInt32:function(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}},readUInt64:function(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0n;return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),r}{let r=0n;return r=(r<<8n)+BigInt(e[t]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+7]),r}},readUInt8:function(e,t){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");return e[t]},toBase64:function(e){return btoa(String.fromCharCode(...e))},toHex:function(e){const t=e||new Uint8Array;return t.length>512?function(e){const t=new Uint8Array(2*e.length);for(let r=0;r<e.length;++r)t[2*r]=Hm[e[r]>>4],t[2*r+1]=Hm[15&e[r]];return Mm.decode(t)}(t):function(e){let t="";for(let r=0;r<e.length;++r)t+=Cm[Km[Hm[e[r]>>4]]],t+=Cm[Km[Hm[15&e[r]]]];return t}(t)},toUtf8:function(e){return Mm.decode(e)},writeInt16:function(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>32767||r<-32768)throw new Error(`The value of "value" is out of range. It must be >= -32768 and <= 32767. Received ${r}`);return"LE"===(n=n.toUpperCase())?(e[t]=255&r,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=255&r),t+2},writeInt32:function(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>2147483647||r<-2147483648)throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${r}`);return"LE"===(n=n.toUpperCase())?(e[t]=255&r,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r),t+4},writeInt64:function(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>0x7fffffffffffffffn||r<-0x8000000000000000n)throw new Error(`The value of "value" is out of range. It must be >= -9223372036854775808 and <= 9223372036854775807. Received ${r}`);return"LE"===(n=n.toUpperCase())?(e[t]=Number(0xffn&r),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(0xffn&r)),t+8},writeInt8:function(e,t,r){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>127||r<-128)throw new Error(`The value of "value" is out of range. It must be >= -128 and <= 127. Received ${r}`);return e[t]=r,t+1},writeUInt16:function(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);return"LE"===n?(e[t]=255&r,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=255&r),t+2},writeUInt32:function(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);return"LE"===n?(e[t]=255&r,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r),t+4},writeUInt64:function(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 18446744073709551615. Received ${r}`);return"LE"===n?(e[t]=Number(0xffn&r),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(0xffn&r)),t+8},writeUInt8:function(e,t,r){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${r}`);return e[t]=r,t+1}},Symbol.toStringTag,{value:"Module"})),jm=zy(Dm);var Fm;function Vm(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function qm(e){if(!Vm(e))throw new Error("Uint8Array expected")}function Wm(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function $m(e){if("function"!=typeof e)throw new Error("function expected");return!0}function Gm(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function Xm(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Ym(e){if(!Array.isArray(e))throw new Error("array expected")}function Zm(e,t){if(!Wm(!0,t))throw new Error(`${e}: array of strings expected`)}function Qm(e,t){if(!Wm(!1,t))throw new Error(`${e}: array of numbers expected`)}function Jm(...e){const t=e=>e,r=(e,t)=>r=>e(t(r));return{encode:e.map(e=>e.encode).reduceRight(r,t),decode:e.map(e=>e.decode).reduce(r,t)}}function eb(e){const t="string"==typeof e?e.split(""):e,r=t.length;Zm("alphabet",t);const n=new Map(t.map((e,t)=>[e,t]));return{encode:n=>(Ym(n),n.map(n=>{if(!Number.isSafeInteger(n)||n<0||n>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${n}". Allowed: ${e}`);return t[n]})),decode:t=>(Ym(t),t.map(t=>{Gm("alphabet.decode",t);const r=n.get(t);if(void 0===r)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return r}))}}function tb(e=""){return Gm("join",e),{encode:t=>(Zm("join.decode",t),t.join(e)),decode:t=>(Gm("join.decode",t),t.split(e))}}function rb(e,t="="){return Xm(e),Gm("padding",t),{encode(r){for(Zm("padding.encode",r);r.length*e%8;)r.push(t);return r},decode(r){Zm("padding.decode",r);let n=r.length;if(n*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if((n-1)*e%8==0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function nb(e){return $m(e),{encode:e=>e,decode:t=>e(t)}}function ib(e,t,r){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Ym(e),!e.length)return[];let n=0;const i=[],o=Array.from(e,e=>{if(Xm(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,a=!0;for(let i=n;i<s;i++){const s=o[i],u=t*e,c=u+s;if(!Number.isSafeInteger(c)||u/t!==e||c-s!==u)throw new Error("convertRadix: carry overflow");const f=c/r;e=c%r;const l=Math.floor(f);if(o[i]=l,!Number.isSafeInteger(l)||l*r+e!==c)throw new Error("convertRadix: carry overflow");a&&(l?a=!1:n=i)}if(i.push(e),a)break}for(let a=0;a<e.length-1&&0===e[a];a++)i.push(0);return i.reverse()}const ob=(e,t)=>0===t?e:ob(t,e%t),sb=(e,t)=>e+(t-ob(e,t)),ab=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function ub(e,t,r,n){if(Ym(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(sb(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${sb(t,r)}`);let i=0,o=0;const s=ab[t],a=ab[r]-1,u=[];for(const c of e){if(Xm(c),c>=s)throw new Error(`convertRadix2: invalid data word=${c} from=${t}`);if(i=i<<t|c,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=r;o-=r)u.push((i>>o-r&a)>>>0);const e=ab[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<r-o&a,!n&&o>=t)throw new Error("Excess padding");if(!n&&i>0)throw new Error(`Non-zero padding: ${i}`);return n&&o>0&&u.push(i>>>0),u}function cb(e){Xm(e);return{encode:t=>{if(!Vm(t))throw new Error("radix.encode input should be Uint8Array");return ib(Array.from(t),256,e)},decode:t=>(Qm("radix.decode",t),Uint8Array.from(ib(t,e,256)))}}function fb(e,t=!1){if(Xm(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(sb(8,e)>32||sb(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Vm(r))throw new Error("radix2.encode input should be Uint8Array");return ub(Array.from(r),8,e,!t)},decode:r=>(Qm("radix2.decode",r),Uint8Array.from(ub(r,e,8,t)))}}function lb(e){return $m(e),function(...t){try{return e.apply(null,t)}catch{}}}function hb(e,t){return Xm(e),$m(t),{encode(r){if(!Vm(r))throw new Error("checksum.encode: input should be Uint8Array");const n=t(r).slice(0,e),i=new Uint8Array(r.length+e);return i.set(r),i.set(n,r.length),i},decode(r){if(!Vm(r))throw new Error("checksum.decode: input should be Uint8Array");const n=r.slice(0,-e),i=r.slice(-e),o=t(n).slice(0,e);for(let t=0;t<e;t++)if(o[t]!==i[t])throw new Error("Invalid checksum");return n}}}const pb={alphabet:eb,chain:Jm,checksum:hb,convertRadix:ib,convertRadix2:ub,radix:cb,radix2:fb,join:tb,padding:rb},db=Jm(fb(4),eb("0123456789ABCDEF"),tb("")),yb=Jm(fb(5),eb("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),rb(5),tb("")),gb=Jm(fb(5),eb("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),tb("")),mb=Jm(fb(5),eb("0123456789ABCDEFGHIJKLMNOPQRSTUV"),rb(5),tb("")),bb=Jm(fb(5),eb("0123456789ABCDEFGHIJKLMNOPQRSTUV"),tb("")),wb=Jm(fb(5),eb("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),tb(""),nb(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),vb="function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64,Eb=(e,t)=>{Gm("base64",e);const r=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=t?"base64url":"base64";if(e.length>0&&!r.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:n,lastChunkHandling:"strict"})},_b=vb?{encode:e=>(qm(e),e.toBase64()),decode:e=>Eb(e,!1)}:Jm(fb(6),eb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),rb(6),tb("")),Sb=Jm(fb(6),eb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),tb("")),kb=vb?{encode:e=>(qm(e),e.toBase64({alphabet:"base64url"})),decode:e=>Eb(e,!0)}:Jm(fb(6),eb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),rb(6),tb("")),Ab=Jm(fb(6),eb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),tb("")),Ib=e=>Jm(cb(58),eb(e),tb("")),Tb=Ib("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),xb=Ib("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Ob=Ib("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),Bb=[0,2,3,5,6,7,9,10,11],Pb={encode(e){let t="";for(let r=0;r<e.length;r+=8){const n=e.subarray(r,r+8);t+=Tb.encode(n).padStart(Bb[n.length],"1")}return t},decode(e){let t=[];for(let r=0;r<e.length;r+=11){const n=e.slice(r,r+11),i=Bb.indexOf(n.length),o=Tb.decode(n);for(let e=0;e<o.length-i;e++)if(0!==o[e])throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(o.slice(o.length-i)))}return Uint8Array.from(t)}},Ub=e=>Jm(hb(4,t=>e(e(t))),Tb),Lb=Ub,Nb=Jm(eb("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),tb("")),Rb=[996825010,642813549,513874426,1027748829,705979059];function Cb(e){const t=e>>25;let r=(33554431&e)<<5;for(let n=0;n<Rb.length;n++)1==(t>>n&1)&&(r^=Rb[n]);return r}function Hb(e,t,r=1){const n=e.length;let i=1;for(let o=0;o<n;o++){const t=e.charCodeAt(o);if(t<33||t>126)throw new Error(`Invalid prefix (${e})`);i=Cb(i)^t>>5}i=Cb(i);for(let o=0;o<n;o++)i=Cb(i)^31&e.charCodeAt(o);for(let o of t)i=Cb(i)^o;for(let o=0;o<6;o++)i=Cb(i);return i^=r,Nb.encode(ub([i%ab[30]],30,5,!1))}function Kb(e){const t="bech32"===e?1:734539939,r=fb(5),n=r.decode,i=r.encode,o=lb(n);function s(e,r,n=90){Gm("bech32.encode prefix",e),Vm(r)&&(r=Array.from(r)),Qm("bech32.encode",r);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const o=i+7+r.length;if(!1!==n&&o>n)throw new TypeError(`Length ${o} exceeds limit ${n}`);const s=e.toLowerCase(),a=Hb(s,r,t);return`${s}1${Nb.encode(r)}${a}`}function a(e,r=90){Gm("bech32.decode input",e);const n=e.length;if(n<8||!1!==r&&n>r)throw new TypeError(`invalid string length: ${n} (${e}). Expected (8..${r})`);const i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=i.lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=i.slice(0,o),a=i.slice(o+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const u=Nb.decode(a).slice(0,-6),c=Hb(s,u,t);if(!a.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:s,words:u}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:r}=a(e,!1);return{prefix:t,words:r,bytes:n(r)}},decodeUnsafe:lb(a),fromWords:n,fromWordsUnsafe:o,toWords:i}}const zb=Kb("bech32"),Mb=Kb("bech32m"),Db={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},jb={encode:e=>(qm(e),e.toHex()),decode:e=>(Gm("hex",e),Uint8Array.fromHex(e))},Fb="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex?jb:Jm(fb(4),eb("0123456789abcdef"),tb(""),nb(e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),Vb={utf8:Db,hex:Fb,base16:db,base32:yb,base64:_b,base64url:kb,base58:Tb,base58xmr:Pb},qb="Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr",Wb=(e,t)=>{if("string"!=typeof e||!Vb.hasOwnProperty(e))throw new TypeError(qb);if(!Vm(t))throw new TypeError("bytesToString() expects Uint8Array");return Vb[e].encode(t)},$b=Wb,Gb=(e,t)=>{if(!Vb.hasOwnProperty(e))throw new TypeError(qb);if("string"!=typeof t)throw new TypeError("stringToBytes() expects string");return Vb[e].decode(t)},Xb=Gb,Yb=zy(Object.freeze(Object.defineProperty({__proto__:null,base16:db,base32:yb,base32crockford:wb,base32hex:mb,base32hexnopad:bb,base32nopad:gb,base58:Tb,base58check:Lb,base58flickr:xb,base58xmr:Pb,base58xrp:Ob,base64:_b,base64nopad:Sb,base64url:kb,base64urlnopad:Ab,bech32:zb,bech32m:Mb,bytes:Xb,bytesToString:Wb,createBase58check:Ub,hex:Fb,str:$b,stringToBytes:Gb,utf8:Db,utils:pb},Symbol.toStringTag,{value:"Module"})));var Zb,Qb={};function Jb(){return Zb||(Zb=1,function(e){var t=Qb&&Qb.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),r=Qb&&Qb.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=Qb&&Qb.__importStar||function(){var e=function(t){return(e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(t)};return function(n){if(n&&n.__esModule)return n;var i={};if(null!=n)for(var o=e(n),s=0;s<o.length;s++)"default"!==o[s]&&t(i,n,o[s]);return r(i,n),i}}();Object.defineProperty(e,"__esModule",{value:!0}),e.Bip32PathSchema=e.NetworkSchema=e.Buffer33Bytes=e.Buffer256Bit=e.Uint31Schema=e.Uint32Schema=void 0;const i=n(Vl());e.Uint32Schema=i.pipe(i.number(),i.integer(),i.minValue(0),i.maxValue(4294967295)),e.Uint31Schema=i.pipe(i.number(),i.integer(),i.minValue(0),i.maxValue(2147483647));const o=i.pipe(i.number(),i.integer(),i.minValue(0),i.maxValue(255));e.Buffer256Bit=i.pipe(i.instance(Uint8Array),i.length(32)),e.Buffer33Bytes=i.pipe(i.instance(Uint8Array),i.length(33));const s=i.object({public:e.Uint32Schema,private:e.Uint32Schema});e.NetworkSchema=i.object({wif:o,bip32:s,messagePrefix:i.string(),bech32:i.string(),bech32Opnet:i.optional(i.string()),pubKeyHash:o,scriptHash:o}),e.Bip32PathSchema=i.pipe(i.string(),i.regex(/^(m\/)?(\d+'?\/)*\d+'?$/))}(Qb)),Qb}var ew,tw,rw,nw,iw,ow={},sw={},aw={},uw={},cw={};function fw(){if(tw)return uw;tw=1;var e=uw&&uw.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(uw,"__esModule",{value:!0});var t=e((ew||(ew=1,Object.defineProperty(cw,"__esModule",{value:!0}),cw.default=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let a=0;a<t.length;a++)t[a]=255;for(let a=0;a<e.length;a++){const r=e.charAt(a),n=r.charCodeAt(0);if(255!==t[n])throw new TypeError(r+" is ambiguous");t[n]=a}const r=e.length,n=e.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let o=0,s=0,a=0;for(;e[o]===n;)s++,o++;const u=(e.length-o)*i+1>>>0,c=new Uint8Array(u);for(;o<e.length;){const n=e.charCodeAt(o);if(n>255)return;let i=t[n];if(255===i)return;let s=0;for(let e=u-1;(0!==i||s<a)&&-1!==e;e--,s++)i+=r*c[e]>>>0,c[e]=i%256>>>0,i=i/256>>>0;if(0!==i)throw new Error("Non-zero carry");a=s,o++}let f=u-a;for(;f!==u&&0===c[f];)f++;const l=new Uint8Array(s+(u-f));let h=s;for(;f!==u;)l[h++]=c[f++];return l}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let i=0,s=0,a=0;const u=t.length;for(;a!==u&&0===t[a];)a++,i++;const c=(u-a)*o+1>>>0,f=new Uint8Array(c);for(;a!==u;){let e=t[a],n=0;for(let t=c-1;(0!==e||n<s)&&-1!==t;t--,n++)e+=256*f[t]>>>0,f[t]=e%r>>>0,e=e/r>>>0;if(0!==e)throw new Error("Non-zero carry");s=n,a++}let l=c-s;for(;l!==c&&0===f[l];)l++;let h=n.repeat(i);for(;l<c;++l)h+=e.charAt(f[l]);return h},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base"+r+" character")}}}),cw));return uw.default=(0,t.default)("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),uw}function lw(){if(nw)return sw;nw=1;var e=sw&&sw.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(sw,"__esModule",{value:!0});var t=Ju(),r=e(function(){if(rw)return aw;rw=1;var e=aw&&aw.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(aw,"__esModule",{value:!0}),aw.default=function(e){function r(t){var r=t.slice(0,-4),n=t.slice(-4),i=e(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(r){var n=Uint8Array.from(r),i=e(n),o=n.length+4,s=new Uint8Array(o);return s.set(n,0),s.set(i.subarray(0,4),n.length),t.default.encode(s)},decode:function(e){var n=r(t.default.decode(e));if(null==n)throw new Error("Invalid checksum");return n},decodeUnsafe:function(e){var n=t.default.decodeUnsafe(e);if(null!=n)return r(n)}}};var t=e(fw());return aw}());return sw.default=(0,r.default)(function(e){return(0,t.sha256)((0,t.sha256)(e))}),sw}var hw,pw,dw={};function yw(){return hw||(hw=1,Object.defineProperty(dw,"__esModule",{value:!0}),dw.REGTEST=dw.TESTNET=dw.BITCOIN=void 0,dw.BITCOIN={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},dw.TESTNET={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},dw.REGTEST={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}),dw}function gw(){if(pw)return Um;pw=1;var e=Um&&Um.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=Um&&Um.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=Um&&Um.__importStar||function(){var r=function(e){return(r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)};return function(n){if(n&&n.__esModule)return n;var i={};if(null!=n)for(var o=r(n),s=0;s<o.length;s++)"default"!==o[s]&&e(i,n,o[s]);return t(i,n),i}}();Object.defineProperty(Um,"__esModule",{value:!0}),Um.BIP32Factory=function(e){(0,i.testEcc)(e);const t=2147483648;class r{__D;__Q;lowR=!1;constructor(e,t){this.__D=e,this.__Q=t}get publicKey(){return void 0===this.__Q&&(this.__Q=e.pointFromScalar(this.__D,!0)),this.__Q}get privateKey(){return this.__D}sign(t,r){if(!this.privateKey)throw new Error("Missing private key");if(void 0===r&&(r=this.lowR),r){let r=e.sign(t,this.privateKey);const n=new Uint8Array(32);let i=0;for(;r[0]>127;)i++,f.writeUInt32(n,0,i,"LE"),r=e.sign(t,this.privateKey,n);return r}return e.sign(t,this.privateKey)}signSchnorr(t){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return e.signSchnorr(t,this.privateKey)}verify(t,r){return e.verify(t,this.publicKey,r)}verifySchnorr(t,r){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(t,this.publicKey.subarray(1,33),r)}}class o extends r{chainCode;network;__DEPTH;__INDEX;__PARENT_FINGERPRINT;constructor(e,t,r,n,i=0,o=0,s=0){super(e,t),this.chainCode=r,this.network=n,this.__DEPTH=i,this.__INDEX=o,this.__PARENT_FINGERPRINT=s,a.parse(u.NetworkSchema,n)}get depth(){return this.__DEPTH}get index(){return this.__INDEX}get parentFingerprint(){return this.__PARENT_FINGERPRINT}get identifier(){return n.hash160(this.publicKey)}get fingerprint(){return this.identifier.slice(0,4)}get compressed(){return!0}isNeutered(){return void 0===this.__D}neutered(){return d(this.publicKey,this.chainCode,this.network,this.depth,this.index,this.parentFingerprint)}toBase58(){const e=this.network,t=this.isNeutered()?e.bip32.public:e.bip32.private,r=new Uint8Array(78);return f.writeUInt32(r,0,t,"BE"),f.writeUInt8(r,4,this.depth),f.writeUInt32(r,5,this.parentFingerprint,"BE"),f.writeUInt32(r,9,this.index,"BE"),r.set(this.chainCode,13),this.isNeutered()?r.set(this.publicKey,45):(f.writeUInt8(r,45,0),r.set(this.privateKey,46)),p.encode(r)}toWIF(){if(!this.privateKey)throw new TypeError("Missing private key");return c.encode({version:this.network.wif,privateKey:this.privateKey,compressed:!0})}derive(r){a.parse(u.Uint32Schema,r);const i=r>=t,o=new Uint8Array(37);if(i){if(this.isNeutered())throw new TypeError("Missing private key for hardened child key");o[0]=0,o.set(this.privateKey,1),f.writeUInt32(o,33,r,"BE")}else o.set(this.publicKey,0),f.writeUInt32(o,33,r,"BE");const s=n.hmacSHA512(this.chainCode,o),c=s.slice(0,32),l=s.slice(32);if(!e.isPrivate(c))return this.derive(r+1);let p;if(this.isNeutered()){const t=e.pointAddScalar(this.publicKey,c,!0);if(null===t)return this.derive(r+1);p=d(t,l,this.network,this.depth+1,r,f.readUInt32(this.fingerprint,0,"BE"))}else{const t=e.privateAdd(this.privateKey,c);if(null==t)return this.derive(r+1);p=h(t,l,this.network,this.depth+1,r,f.readUInt32(this.fingerprint,0,"BE"))}return p}deriveHardened(e){if("number"==typeof a.parse(u.Uint31Schema,e))return this.derive(e+t);throw new TypeError("Expected UInt31, got "+e)}derivePath(e){a.parse(u.Bip32PathSchema,e);let t=e.split("/");if("m"===t[0]){if(this.parentFingerprint)throw new TypeError("Expected master, got child");t=t.slice(1)}return t.reduce((e,t)=>{let r;return"'"===t.slice(-1)?(r=parseInt(t.slice(0,-1),10),e.deriveHardened(r)):(r=parseInt(t,10),e.derive(r))},this)}tweak(e){return this.privateKey?this.tweakFromPrivateKey(e):this.tweakFromPublicKey(e)}tweakFromPublicKey(t){const n=32===(i=this.publicKey).length?i:i.slice(1,33);var i;if(!e.xOnlyPointAddTweak)throw new Error("xOnlyPointAddTweak not supported by ecc library");const o=e.xOnlyPointAddTweak(n,t);if(!o||null===o.xOnlyPubkey)throw new Error("Cannot tweak public key!");const s=Uint8Array.from([0===o.parity?2:3]),a=f.concat([s,o.xOnlyPubkey]);return new r(void 0,a)}tweakFromPrivateKey(t){const n=3===this.publicKey[0]||4===this.publicKey[0]&&!(1&~this.publicKey[64]),i=(()=>{if(n){if(e.privateNegate)return e.privateNegate(this.privateKey);throw new Error("privateNegate not supported by ecc library")}return this.privateKey})(),o=e.privateAdd(i,t);if(!o)throw new Error("Invalid tweaked private key!");return new r(o,void 0)}}function s(e,t,r){return h(e,t,r)}function h(t,r,n,i,s,c){if(a.parse(u.Buffer256Bit,t),a.parse(u.Buffer256Bit,r),n=n||l.BITCOIN,!e.isPrivate(t))throw new TypeError("Private key not in range [1, n)");return new o(t,void 0,r,n,i,s,c)}function d(t,r,n,i,s,c){if(a.parse(u.Buffer33Bytes,t),a.parse(u.Buffer256Bit,r),n=n||l.BITCOIN,!e.isPoint(t))throw new TypeError("Point is not on the curve");return new o(void 0,t,r,n,i,s,c)}return{fromSeed:function(e,t){if(a.parse(a.instance(Uint8Array),e),e.length<16)throw new TypeError("Seed should be at least 128 bits");if(e.length>64)throw new TypeError("Seed should be at most 512 bits");t=t||l.BITCOIN;const r=n.hmacSHA512(f.fromUtf8("Bitcoin seed"),e);return s(r.slice(0,32),r.slice(32),t)},fromBase58:function(e,t){const r=p.decode(e);if(78!==r.length)throw new TypeError("Invalid buffer length");t=t||l.BITCOIN;const n=f.readUInt32(r,0,"BE");if(n!==t.bip32.private&&n!==t.bip32.public)throw new TypeError("Invalid network version");const i=r[4],o=f.readUInt32(r,5,"BE");if(0===i&&0!==o)throw new TypeError("Invalid parent fingerprint");const s=f.readUInt32(r,9,"BE");if(0===i&&0!==s)throw new TypeError("Invalid index");const a=r.slice(13,45);let u;if(n===t.bip32.private){if(0!==r[45])throw new TypeError("Invalid private key");u=h(r.slice(46,78),a,t,i,s,o)}else u=d(r.slice(45,78),a,t,i,s,o);return u},fromPublicKey:function(e,t,r){return d(e,t,r)},fromPrivateKey:s}};const n=r(Nm()),i=function(){if(Fm)return Rm;Fm=1;var e=Rm&&Rm.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=Rm&&Rm.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=Rm&&Rm.__importStar||function(){var r=function(e){return(r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)};return function(n){if(n&&n.__esModule)return n;var i={};if(null!=n)for(var o=r(n),s=0;s<o.length;s++)"default"!==o[s]&&e(i,n,o[s]);return t(i,n),i}}();Object.defineProperty(Rm,"__esModule",{value:!0}),Rm.testEcc=function(e){if(o(e.isPoint(i("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),o(!e.isPoint(i("030000000000000000000000000000000000000000000000000000000000000005"))),o(e.isPrivate(i("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),o(e.isPrivate(i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),o(!e.isPrivate(i("0000000000000000000000000000000000000000000000000000000000000000"))),o(!e.isPrivate(i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),o(!e.isPrivate(i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),o(0===n.compare(e.pointFromScalar(i("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af")),i("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),e.xOnlyPointAddTweak){o(null===e.xOnlyPointAddTweak(i("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")));let t=e.xOnlyPointAddTweak(i("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),i("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));o(0===n.compare(t.xOnlyPubkey,i("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&1===t.parity),t=e.xOnlyPointAddTweak(i("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),i("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47"))}o(0===n.compare(e.pointAddScalar(i("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),i("0000000000000000000000000000000000000000000000000000000000000003")),i("02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5"))),o(0===n.compare(e.privateAdd(i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),i("0000000000000000000000000000000000000000000000000000000000000002")),i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),e.privateNegate&&(o(0===n.compare(e.privateNegate(i("0000000000000000000000000000000000000000000000000000000000000001")),i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),o(0===n.compare(e.privateNegate(i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e")),i("0000000000000000000000000000000000000000000000000000000000000003"))),o(0===n.compare(e.privateNegate(i("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af")),i("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792")))),o(0===n.compare(e.sign(i("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),i("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")),i("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),o(e.verify(i("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),i("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),i("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&o(0===n.compare(e.signSchnorr(i("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),i("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),i("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906")),i("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&o(e.verifySchnorr(i("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),i("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),i("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))};const n=r(jm),i=e=>n.fromHex(e);function o(e){if(!e)throw new Error("ecc library invalid")}return Rm}(),o=Yb,s=Ju(),a=r(Vl()),u=Jb(),c=r(function(){if(iw)return ow;iw=1;var e=ow&&ow.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ow,"__esModule",{value:!0}),ow.encode=ow.decode=ow.encodeRaw=ow.decodeRaw=void 0;var t=e(lw());function r(e,t){if(void 0!==t&&e[0]!==t)throw new Error("Invalid network version");if(33===e.length)return{version:e[0],privateKey:e.slice(1,33),compressed:!1};if(34!==e.length)throw new Error("Invalid WIF length");if(1!==e[33])throw new Error("Invalid compression flag");return{version:e[0],privateKey:e.slice(1,33),compressed:!0}}function n(e,t,r){if(32!==t.length)throw new TypeError("Invalid privateKey length");var n=new Uint8Array(r?34:33);return new DataView(n.buffer).setUint8(0,e),n.set(t,1),r&&(n[33]=1),n}return ow.decodeRaw=r,ow.encodeRaw=n,ow.decode=function(e,n){return r(t.default.decode(e),n)},ow.encode=function(e){return t.default.encode(n(e.version,e.privateKey,e.compressed))},ow}()),f=r(jm),l=yw(),h=(0,o.base58check)(s.sha256),p={encode:e=>h.encode(e),decode:e=>h.decode(e)};return Um}var mw={},bw={};const ww=function(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))};function vw(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}function Ew(e){if("object"!=typeof e||null===e||nc(e))throw new Error("expected opts to be an object")}function _w(e){Ew(e),void 0!==e.context&&oc(e.context,void 0,"opts.context")}function Sw(e){_w(e),!1!==e.extraEntropy&&void 0!==e.extraEntropy&&oc(e.extraEntropy,void 0,"opts.extraEntropy")}function kw(e,...t){const r=e=>"number"==typeof e?e:e.bytesLen,n=t.reduce((e,t)=>e+r(t),0);return{bytesLen:n,encode:i=>{const o=new Uint8Array(n);for(let n=0,s=0;n<t.length;n++){const a=t[n],u=r(a),c="number"==typeof a?i[n]:a.encode(i[n]);oc(c,u,e),o.set(c,s),"number"!=typeof a&&c.fill(0),s+=u}return o},decode:i=>{oc(i,n,e);const o=[];for(const e of t){const t=r(e),n=i.subarray(0,t);o.push("number"==typeof e?n:e.decode(n)),i=i.subarray(t)}return o}}}function Aw(e,t){const r=t*e.bytesLen;return{bytesLen:r,encode:n=>{if(n.length!==t)throw new Error(`vecCoder.encode: wrong length=${n.length}. Expected: ${t}`);const i=new Uint8Array(r);for(let t=0,r=0;t<n.length;t++){const o=e.encode(n[t]);i.set(o,r),o.fill(0),r+=o.length}return i},decode:t=>{oc(t,r);const n=[];for(let r=0;r<t.length;r+=e.bytesLen)n.push(e.decode(t.subarray(r,r+e.bytesLen)));return n}}}function Iw(...e){for(const t of e)if(Array.isArray(t))for(const e of t)e.fill(0);else t.fill(0)}function Tw(e){return(1<<e)-1}const xw=Uint8Array.of();function Ow(e,t=xw){if(oc(e),oc(t),t.length>255)throw new Error("context should be less than 255 bytes");return fc(new Uint8Array([0,t.length]),t,e)}const Bw=Uint8Array.from([6,9,96,134,72,1,101,3,4,2]);function Pw(e,t=0){if(!e.oid||!vw(e.oid.subarray(0,10),Bw))throw new Error("hash.oid is invalid: expected NIST hash");const r=8*e.outputLen/2;if(t>r)throw new Error("Pre-hash security strength too low: "+r+", required: "+t)}function Uw(e,t,r=xw){if(oc(t),oc(r),r.length>255)throw new Error("context should be less than 255 bytes");const n=e(t);return fc(new Uint8Array([1,r.length]),r,e.oid,n)}const Lw=Object.freeze(Object.defineProperty({__proto__:null,EMPTY:xw,abytes:oc,checkHash:Pw,cleanBytes:Iw,concatBytes:fc,copyBytes:function(e){return Uint8Array.from(e)},equalBytes:vw,getMask:Tw,getMessage:Ow,getMessagePrehash:Uw,randomBytes:ww,splitCoder:kw,validateOpts:Ew,validateSigOpts:Sw,validateVerOpts:_w,vecCoder:Aw},Symbol.toStringTag,{value:"Module"})),Nw=zy(Lw);var Rw={};const Cw=e=>(t,r)=>{r||(r=e.blockLen);const n=new Uint8Array(t.length+2);n.set(t);const i=t.length,o=new Uint8Array(r);let s=e.create({}),a=0,u=0;return{stats:()=>({calls:a,xofs:u}),get:(t,r)=>(n[i+0]=t,n[i+1]=r,s.destroy(),s=e.create({}).update(n),a++,()=>(u++,s.xofInto(o))),clean:()=>{s.destroy(),Iw(o,n)}}},Hw=Cw(Pc),Kw=Cw(Uc);function zw(e){Ew(e),void 0!==e.externalMu&&function(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e)}(e.externalMu,"opts.externalMu")}const Mw=256,Dw=8380417,jw=13,Fw=0|Math.floor(95232),Vw=0|Math.floor(261888),qw={2:{K:4,L:4,D:jw,GAMMA1:2**17,GAMMA2:Fw,TAU:39,ETA:2,OMEGA:80},3:{K:6,L:5,D:jw,GAMMA1:2**19,GAMMA2:Vw,TAU:49,ETA:4,OMEGA:55},5:{K:8,L:7,D:jw,GAMMA1:2**19,GAMMA2:Vw,TAU:60,ETA:2,OMEGA:75}},Ww=e=>new Int32Array(e),{mod:$w,smod:Gw,NTT:Xw,bitsCoder:Yw}=(e=>{const{newPoly:t,N:r,Q:n,F:i,ROOT_OF_UNITY:o,brvBits:s}=e,a=(e,t=n)=>{const r=e%t|0;return 0|(r>=0?r:t+r)};const u=function(){const e=t(r);for(let t=0;t<r;t++){const r=df(t,s),i=BigInt(o)**BigInt(r)%BigInt(n);e[t]=0|Number(i)}return e}(),c={add:(e,t)=>0|a((0|e)+(0|t)),sub:(e,t)=>0|a((0|e)-(0|t)),mul:(e,t)=>0|a((0|e)*(0|t)),inv:e=>{throw new Error("not implemented")}},f={N:r,roots:u,invertButterflies:!0,skipStages:0,brp:!1},l=mf(c,{dit:!1,...f}),h=mf(c,{dit:!0,...f});return{mod:a,smod:(e,t=n)=>{const r=0|a(e,t);return 0|(r>t>>1?r-t:r)},nttZetas:u,NTT:{encode:e=>l(e),decode:e=>{h(e);for(let t=0;t<e.length;t++)e[t]=a(i*e[t]);return e}},bitsCoder:(e,n)=>{const i=Tw(e),o=e*(r/8);return{bytesLen:o,encode:t=>{const r=new Uint8Array(o);for(let o=0,s=0,a=0,u=0;o<t.length;o++)for(s|=(n.encode(t[o])&i)<<a,a+=e;a>=8;a-=8,s>>=8)r[u++]=s&Tw(a);return r},decode:o=>{const s=t(r);for(let t=0,r=0,a=0,u=0;t<o.length;t++)for(r|=o[t]<<a,a+=8;a>=e;a-=e,r>>=e)s[u++]=n.decode(r&i);return s}}}}})({N:Mw,Q:Dw,F:8347681,ROOT_OF_UNITY:1753,newPoly:Ww,brvBits:8}),Zw=e=>e,Qw=(e,t=Zw,r=Zw)=>Yw(e,{encode:e=>t(r(e)),decode:e=>r(t(e))}),Jw=(e,t)=>{for(let r=0;r<e.length;r++)e[r]=$w(e[r]+t[r]);return e},ev=(e,t)=>{for(let r=0;r<e.length;r++)e[r]=$w(e[r]-t[r]);return e},tv=e=>{for(let t=0;t<Mw;t++)e[t]<<=jw;return e},rv=(e,t)=>{for(let r=0;r<Mw;r++)if(Math.abs(Gw(e[r]))>=t)return!0;return!1},nv=(e,t)=>{const r=Ww(Mw);for(let n=0;n<e.length;n++)r[n]=$w(e[n]*t[n]);return r};function iv(e){const t=Ww(Mw);for(let r=0;r<Mw;){const n=e();if(n.length%3)throw new Error("RejNTTPoly: unaligned block");for(let e=0;r<Mw&&e<=n.length-3;e+=3){const i=8388607&(n[e+0]|n[e+1]<<8|n[e+2]<<16);i<Dw&&(t[r++]=i)}}return t}function ov(e){const{K:t,L:r,GAMMA1:n,GAMMA2:i,TAU:o,ETA:s,OMEGA:a}=e,{CRH_BYTES:u,TR_BYTES:c,C_TILDE_BYTES:f,XOF128:l,XOF256:h,securityLevel:p}=e;if(![2,4].includes(s))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(n))throw new Error("Wrong GAMMA1");if(![Fw,Vw].includes(i))throw new Error("Wrong GAMMA2");const d=o*s,y=e=>{const t=$w(e),r=0|Gw(t,2*i);return t-r===Dw-1?{r1:0,r0:r-1|0}:{r1:0|Math.floor((t-r)/(2*i)),r0:r}},g=e=>y(e).r1,m=e=>y(e).r0,b=(e,t)=>e<=i||e>Dw-i||e===Dw-i&&0===t?0:1,w=(e,t)=>{const r=Math.floor((Dw-1)/(2*i)),{r1:n,r0:o}=y(t);return 1===e?o>0?0|$w(n+1,r):0|$w(n-1,r):0|n},v=e=>{const t=$w(e),r=0|Gw(t,8192);return{r1:0|Math.floor((t-r)/8192),r0:r}},E={bytesLen:a+t,encode:e=>{if(!1===e)throw new Error("hint.encode: hint is false");const r=new Uint8Array(a+t);for(let n=0,i=0;n<t;n++){for(let t=0;t<Mw;t++)0!==e[n][t]&&(r[i++]=t);r[a+n]=i}return r},decode:e=>{const r=[];let n=0;for(let i=0;i<t;i++){const t=Ww(Mw);if(e[a+i]<n||e[a+i]>a)return!1;for(let r=n;r<e[a+i];r++){if(r>n&&e[r]<=e[r-1])return!1;t[e[r]]=1}n=e[a+i],r.push(t)}for(let t=n;t<a;t++)if(0!==e[t])return!1;return r}},_=Qw(2===s?3:4,e=>s-e,e=>{if(!(-s<=e&&e<=s))throw new Error(`malformed key s1/s3 ${e} outside of ETA range [${-s}, ${s}]`);return e}),S=Qw(13,e=>4096-e),k=Qw(10),A=Qw(n===1<<17?18:20,e=>Gw(n-e)),I=Aw(Qw(i===Fw?6:4),t),T=kw("publicKey",32,Aw(k,t)),x=kw("secretKey",32,32,c,Aw(_,r),Aw(_,t),Aw(S,t)),O=kw("signature",f,Aw(A,r),E),B=2===s?e=>e<15&&2-e%5:e=>e<9&&4-e;function P(e){const t=Ww(Mw);for(let r=0;r<Mw;){const n=e();for(let e=0;r<Mw&&e<n.length;e+=1){const i=B(15&n[e]),o=B(n[e]>>4&15);!1!==i&&(t[r++]=i),r<Mw&&!1!==o&&(t[r++]=o)}}return t}const U=e=>{const t=Ww(Mw),r=Uc.create({}).update(e),n=new Uint8Array(Uc.blockLen);r.xofInto(n);const i=n.slice(0,8);for(let s=Mw-o,a=8,u=0,c=0;s<Mw;s++){let e=s+1;for(;e>s;)e=n[a++],!(a<Uc.blockLen)&&(r.xofInto(n),a=0);t[s]=t[e],t[e]=1-((i[u]>>c++&1)<<1),c>=8&&(u++,c=0)}return t},L=e=>{const t=Ww(Mw),r=Ww(Mw);for(let n=0;n<e.length;n++){const{r0:i,r1:o}=v(e[n]);t[n]=i,r[n]=o}return{r0:t,r1:r}},N=(e,t)=>{for(let r=0;r<Mw;r++)e[r]=w(t[r],e[r]);return e},R=(e,t)=>{const r=Ww(Mw);let n=0;for(let i=0;i<Mw;i++){const o=b(e[i],t[i]);r[i]=o,n+=o}return{v:r,cnt:n}},C=kw("seed",32,64,32),H={info:{type:"internal-ml-dsa"},lengths:{secretKey:x.bytesLen,publicKey:T.bytesLen,seed:32,signature:O.bytesLen,signRand:32},keygen:e=>{const n=new Uint8Array(34),i=void 0===e;i&&(e=ww(32)),oc(e,32,"seed"),n.set(e),i&&Iw(e),n[32]=t,n[33]=r;const[o,s,a]=C.decode(Uc(n,{dkLen:C.bytesLen})),u=h(s),f=[];for(let t=0;t<r;t++)f.push(P(u.get(255&t,t>>8&255)));const p=[];for(let c=r;c<r+t;c++)p.push(P(u.get(255&c,c>>8&255)));const d=f.map(e=>Xw.encode(e.slice())),y=[],g=[],m=l(o),b=Ww(Mw);for(let c=0;c<t;c++){Iw(b);for(let n=0;n<r;n++){const e=iv(m.get(n,c));Jw(b,nv(e,d[n]))}Xw.decode(b);const{r0:e,r1:t}=L(Jw(b,p[c]));y.push(e),g.push(t)}const w=T.encode([o,g]),v=Uc(w,{dkLen:c}),E=x.encode([o,a,v,f,p,y]);return m.clean(),u.clean(),Iw(o,s,a,f,p,d,b,y,g,v,n),{publicKey:w,secretKey:E}},getPublicKey:e=>{const[n,i,o,s,a,u]=x.decode(e),c=l(n),f=s.map(e=>Xw.encode(e.slice())),h=[],p=Ww(Mw);for(let l=0;l<t;l++){p.fill(0);for(let t=0;t<r;t++){const e=iv(c.get(t,l));Jw(p,nv(e,f[t]))}Xw.decode(p),Jw(p,a[l]);const{r1:e}=L(p);h.push(e)}return c.clean(),Iw(p,f,u,s,a),T.encode([n,h])},sign:(e,o,s={})=>{Sw(s),zw(s);let{extraEntropy:c,externalMu:p=!1}=s;const[y,b,w,v,E,_]=x.decode(o),S=[],k=l(y);for(let n=0;n<t;n++){const e=[];for(let t=0;t<r;t++)e.push(iv(k.get(t,n)));S.push(e)}k.clean();for(let t=0;t<r;t++)Xw.encode(v[t]);for(let r=0;r<t;r++)Xw.encode(E[r]),Xw.encode(_[r]);const T=p?e:Uc.create({dkLen:u}).update(w).update(e).digest(),B=!1===c?new Uint8Array(32):void 0===c?ww(32):c;oc(B,32,"extraEntropy");const P=Uc.create({dkLen:u}).update(b).update(B).update(T).digest();oc(P,u);const L=h(P,A.bytesLen);e:for(let u=0;;){const e=[];for(let t=0;t<r;t++,u++)e.push(A.decode(L.get(255&u,u>>8)()));const o=e.map(e=>Xw.encode(e.slice())),s=[];for(let n=0;n<t;n++){const e=Ww(Mw);for(let t=0;t<r;t++)Jw(e,nv(S[n][t],o[t]));Xw.decode(e),s.push(e)}const c=s.map(e=>e.map(g)),l=Uc.create({dkLen:f}).update(T).update(I.encode(c)).digest(),h=Xw.encode(U(l)),p=v.map(e=>nv(e,h));for(let t=0;t<r;t++)if(Jw(Xw.decode(p[t]),e[t]),rv(p[t],n-d))continue e;let y=0;const b=[];for(let r=0;r<t;r++){const e=Xw.decode(nv(E[r],h)),t=ev(s[r],e).map(m);if(rv(t,i-d))continue e;const n=Xw.decode(nv(_[r],h));if(rv(n,i))continue e;Jw(t,n);const o=R(t,c[r]);b.push(o.v),y+=o.cnt}if(y>a)continue;L.clean();const w=O.encode([l,p,b]);return Iw(l,p,b,h,c,s,o,e,P,T,v,E,_,...S),w}throw new Error("Unreachable code path reached, report this error")},verify:(e,i,o,s={})=>{zw(s);const{externalMu:h=!1}=s,[p,y]=T.decode(o),g=Uc(o,{dkLen:c});if(e.length!==O.bytesLen)return!1;const[m,b,w]=O.decode(e);if(!1===w)return!1;for(let t=0;t<r;t++)if(rv(b[t],n-d))return!1;const v=h?i:Uc.create({dkLen:u}).update(g).update(i).digest(),E=Xw.encode(U(m)),_=b.map(e=>e.slice());for(let t=0;t<r;t++)Xw.encode(_[t]);const S=[],k=l(p);for(let n=0;n<t;n++){const e=nv(Xw.encode(tv(y[n])),E),t=Ww(Mw);for(let o=0;o<r;o++){const e=iv(k.get(o,n));Jw(t,nv(e,_[o]))}const i=Xw.decode(ev(t,e));S.push(N(i,w[n]))}k.clean();const A=Uc.create({dkLen:f}).update(v).update(I.encode(S)).digest();for(const t of w)if(!(t.reduce((e,t)=>e+t,0)<=a))return!1;for(const t of b)if(rv(t,n-d))return!1;return vw(m,A)}};return{info:{type:"ml-dsa"},internal:H,securityLevel:p,keygen:H.keygen,lengths:H.lengths,getPublicKey:H.getPublicKey,sign:(e,t,r={})=>{Sw(r);const n=Ow(e,r.context),i=H.sign(n,t,r);return Iw(n),i},verify:(e,t,r,n={})=>(_w(n),H.verify(e,Ow(t,n.context),r)),prehash:e=>(Pw(e,p),{info:{type:"hashml-dsa"},securityLevel:p,lengths:H.lengths,keygen:H.keygen,getPublicKey:H.getPublicKey,sign:(t,r,n={})=>{Sw(n);const i=Uw(e,t,n.context),o=H.sign(i,r,n);return Iw(i),o},verify:(t,r,n,i={})=>(_w(i),H.verify(t,Uw(e,r,i.context),n))})}}const sv=ov({...qw[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:Hw,XOF256:Kw,securityLevel:128}),av=ov({...qw[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:Hw,XOF256:Kw,securityLevel:192}),uv=ov({...qw[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:Hw,XOF256:Kw,securityLevel:256}),cv=zy(Object.freeze(Object.defineProperty({__proto__:null,PARAMS:qw,ml_dsa44:sv,ml_dsa65:av,ml_dsa87:uv},Symbol.toStringTag,{value:"Module"})));var fv,lv;function hv(){if(fv)return Rw;fv=1,Object.defineProperty(Rw,"__esModule",{value:!0}),Rw.DEFAULT_SECURITY_LEVEL=Rw.MLDSASecurityLevel=void 0,Rw.getMLDSAConfig=function(e,t){const r=i[e];if(!r)throw new TypeError(`Invalid ML-DSA security level: ${e}. Must be MLDSASecurityLevel.LEVEL2 (44), LEVEL3 (65), or LEVEL5 (87)`);return{...r,network:t}},Rw.findNetworkByVersion=function(e){const r=[t.BITCOIN,t.TESTNET,t.REGTEST];for(const t of r){if(e===t.bip32.private)return{network:t,isPrivate:!0};if(e===t.bip32.public)return{network:t,isPrivate:!1}}return null};const e=cv,t=yw();var r,n;(n=r||(Rw.MLDSASecurityLevel=r={}))[n.LEVEL2=44]="LEVEL2",n[n.LEVEL3=65]="LEVEL3",n[n.LEVEL5=87]="LEVEL5";const i={[r.LEVEL2]:{level:r.LEVEL2,privateKeySize:2560,publicKeySize:1312,signatureSize:2420,algorithm:e.ml_dsa44},[r.LEVEL3]:{level:r.LEVEL3,privateKeySize:4032,publicKeySize:1952,signatureSize:3309,algorithm:e.ml_dsa65},[r.LEVEL5]:{level:r.LEVEL5,privateKeySize:4896,publicKeySize:2592,signatureSize:4627,algorithm:e.ml_dsa87}};return Rw.DEFAULT_SECURITY_LEVEL=r.LEVEL2,Rw}var pv,dv,yv,gv={};function mv(){if(pv)return gv;var e,t,r;return pv=1,Object.defineProperty(gv,"__esModule",{value:!0}),gv.QuantumDerivationPath=gv.DerivationPath=void 0,gv.getQuantumPath=function(e=0,t=0,r=!1){return`m/360'/${e}'/${r?1:0}'/${t}`},gv.getBitcoinPath=function(e,t=0,r=0,n=!1){return`m/${e}'/0'/${t}'/${n?1:0}/${r}`},(t=e||(gv.DerivationPath=e={})).BIP44="m/44'/0'/0'/0/0",t.BIP49="m/49'/0'/0'/0/0",t.BIP84="m/84'/0'/0'/0/0",t.BIP86="m/86'/0'/0'/0/0",t.BIP360="m/360'/0'/0'/0/0",function(e){e.STANDARD="m/360'/0'/0'/0/0",e.CHANGE="m/360'/0'/0'/1/0",e.ACCOUNT_0_ADDRESS_0="m/360'/0'/0'/0/0",e.ACCOUNT_0_ADDRESS_1="m/360'/0'/0'/0/1",e.ACCOUNT_1_ADDRESS_0="m/360'/1'/0'/0/0"}(r||(gv.QuantumDerivationPath=r={})),gv}function bv(){return dv||(dv=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getBitcoinPath=e.getQuantumPath=e.QuantumDerivationPath=e.DerivationPath=e.getMLDSAConfig=e.DEFAULT_SECURITY_LEVEL=e.MLDSASecurityLevel=e.QuantumBIP32Factory=void 0;var t=function(){if(lv)return bw;lv=1;var e=bw&&bw.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=bw&&bw.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=bw&&bw.__importStar||function(){var r=function(e){return(r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)};return function(n){if(n&&n.__esModule)return n;var i={};if(null!=n)for(var o=r(n),s=0;s<o.length;s++)"default"!==o[s]&&e(i,n,o[s]);return t(i,n),i}}();Object.defineProperty(bw,"__esModule",{value:!0}),bw.QuantumBIP32Factory=void 0;const n=Nw,i=r(Nm()),o=r(jm),s=r(Vl()),a=Jb(),u=Yb,c=Ju(),f=hv(),l=yw(),h=(0,u.base58check)(c.sha256),p=e=>h.encode(e),d=e=>h.decode(e),y=2147483648;class g{_privateKey;_publicKey;config;constructor(e,t,r){this._privateKey=e,this._publicKey=t,this.config=r}get publicKey(){if(!this._publicKey)throw new Error("Public key not available");return this._publicKey}get privateKey(){return this._privateKey}sign(e){if(!this._privateKey)throw new Error("Missing private key");return this.config.algorithm.sign(e,this._privateKey,{extraEntropy:(0,n.randomBytes)(32)})}verify(e,t){return this.config.algorithm.verify(t,e,this._publicKey)}}class m extends g{chainCode;_depth;_index;_parentFingerprint;constructor(e,t,r,n,i=0,o=0,s=0){super(e,t,n),this.chainCode=r,this._depth=i,this._index=o,this._parentFingerprint=s}get depth(){return this._depth}get index(){return this._index}get parentFingerprint(){return this._parentFingerprint}get identifier(){return i.hash160(this.publicKey)}get fingerprint(){return this.identifier.slice(0,4)}get securityLevel(){return this.config.level}get network(){return this.config.network}isNeutered(){return void 0===this._privateKey}neutered(){return new m(void 0,this.publicKey,this.chainCode,this.config,this.depth,this.index,this.parentFingerprint)}toBase58(){const e=this.isNeutered()?this.config.network.bip32.public:this.config.network.bip32.private,t=!this.isNeutered(),r=45+(t?this.config.privateKeySize:this.config.publicKeySize),n=new Uint8Array(r);let i=0;return o.writeUInt32(n,i,e,"BE"),i+=4,o.writeUInt8(n,i,this.depth),i+=1,o.writeUInt32(n,i,this.parentFingerprint,"BE"),i+=4,o.writeUInt32(n,i,this.index,"BE"),i+=4,n.set(this.chainCode,i),i+=32,t?n.set(this._privateKey,i):n.set(this._publicKey,i),p(n)}derive(e){if(s.parse(a.Uint32Schema,e),this.isNeutered())throw new TypeError("Cannot derive child keys without private key");let t;if(e>=y){const r=i.hash256(this._privateKey);t=new Uint8Array(37),t[0]=0,t.set(r,1),o.writeUInt32(t,33,e,"BE")}else{const r=i.hash256(this._privateKey);t=new Uint8Array(36),t.set(r,0),o.writeUInt32(t,32,e,"BE")}const r=i.hmacSHA512(this.chainCode,t),n=r.slice(0,32),u=r.slice(32),{secretKey:c,publicKey:f}=this.config.algorithm.keygen(n);return new m(c,f,u,this.config,this.depth+1,e,o.readUInt32(this.fingerprint,0,"BE"))}deriveHardened(e){try{s.parse(a.Uint31Schema,e)}catch{throw new TypeError("Expected UInt31, got "+e)}return this.derive(e+y)}derivePath(e){s.parse(a.Bip32PathSchema,e);let t=e.split("/");if("m"===t[0]){if(this.parentFingerprint)throw new TypeError("Expected master, got child");t=t.slice(1)}return t.reduce((e,t)=>{let r;return"'"===t.slice(-1)?(r=parseInt(t.slice(0,-1),10),e.deriveHardened(r)):(r=parseInt(t,10),e.derive(r))},this)}}return bw.QuantumBIP32Factory={fromSeed:function(e,t,r){if(s.parse(s.instance(Uint8Array),e),e.length<16)throw new TypeError("Seed should be at least 128 bits");if(e.length>64)throw new TypeError("Seed should be at most 512 bits");const n=(0,f.getMLDSAConfig)(r||f.MLDSASecurityLevel.LEVEL2,t||l.BITCOIN),a=i.hmacSHA512(o.fromUtf8("Bitcoin seed"),e),u=a.slice(0,32),c=a.slice(32),{secretKey:h,publicKey:p}=n.algorithm.keygen(u);return new m(h,p,c,n,0,0,0)},fromBase58:function(e){const t=d(e),r=o.readUInt32(t,0,"BE"),n=(0,f.findNetworkByVersion)(r);if(!n)throw new TypeError("Unknown network version");const{network:i,isPrivate:s}=n,a=t.length-45;let u;if(s)if(2560===a)u=f.MLDSASecurityLevel.LEVEL2;else if(4032===a)u=f.MLDSASecurityLevel.LEVEL3;else{if(4896!==a)throw new TypeError(`Invalid private key size: ${a}`);u=f.MLDSASecurityLevel.LEVEL5}else if(1312===a)u=f.MLDSASecurityLevel.LEVEL2;else if(1952===a)u=f.MLDSASecurityLevel.LEVEL3;else{if(2592!==a)throw new TypeError(`Invalid public key size: ${a}`);u=f.MLDSASecurityLevel.LEVEL5}const c=(0,f.getMLDSAConfig)(u,i),l=s?45+c.privateKeySize:45+c.publicKeySize;if(t.length!==l)throw new TypeError(`Invalid buffer length: expected ${l}, got ${t.length}`);let h=4;const p=t[h];h+=1;const y=o.readUInt32(t,h,"BE");if(0===p&&0!==y)throw new TypeError("Invalid parent fingerprint");h+=4;const g=o.readUInt32(t,h,"BE");if(0===p&&0!==g)throw new TypeError("Invalid index");h+=4;const b=t.slice(h,h+32);if(h+=32,s){const e=t.slice(h,h+c.privateKeySize),r=c.algorithm.getPublicKey(e);return new m(e,r,b,c,p,g,y)}{const e=t.slice(h,h+c.publicKeySize);return new m(void 0,e,b,c,p,g,y)}},fromPublicKey:function(e,t,r,n){const i=(0,f.getMLDSAConfig)(n||f.MLDSASecurityLevel.LEVEL2,r||l.BITCOIN);if(e.length!==i.publicKeySize)throw new TypeError(`Invalid public key length for ML-DSA-${n}: expected ${i.publicKeySize}, got ${e.length}`);if(32!==t.length)throw new TypeError(`Invalid chain code length: expected 32, got ${t.length}`);return new m(void 0,e,t,i,0,0,0)},fromPrivateKey:function(e,t,r,n){const i=(0,f.getMLDSAConfig)(n||f.MLDSASecurityLevel.LEVEL2,r||l.BITCOIN);if(e.length!==i.privateKeySize)throw new TypeError(`Invalid private key length for ML-DSA-${n}: expected ${i.privateKeySize}, got ${e.length}`);if(32!==t.length)throw new TypeError(`Invalid chain code length: expected 32, got ${t.length}`);const o=i.algorithm.getPublicKey(e);return new m(e,o,t,i,0,0,0)}},bw}();Object.defineProperty(e,"QuantumBIP32Factory",{enumerable:!0,get:function(){return t.QuantumBIP32Factory}});var r=hv();Object.defineProperty(e,"MLDSASecurityLevel",{enumerable:!0,get:function(){return r.MLDSASecurityLevel}}),Object.defineProperty(e,"DEFAULT_SECURITY_LEVEL",{enumerable:!0,get:function(){return r.DEFAULT_SECURITY_LEVEL}}),Object.defineProperty(e,"getMLDSAConfig",{enumerable:!0,get:function(){return r.getMLDSAConfig}});var n=mv();Object.defineProperty(e,"DerivationPath",{enumerable:!0,get:function(){return n.DerivationPath}}),Object.defineProperty(e,"QuantumDerivationPath",{enumerable:!0,get:function(){return n.QuantumDerivationPath}}),Object.defineProperty(e,"getQuantumPath",{enumerable:!0,get:function(){return n.getQuantumPath}}),Object.defineProperty(e,"getBitcoinPath",{enumerable:!0,get:function(){return n.getBitcoinPath}})}(mw)),mw}var wv=(yv||(yv=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getBitcoinPath=e.getQuantumPath=e.QuantumDerivationPath=e.DerivationPath=e.getMLDSAConfig=e.DEFAULT_SECURITY_LEVEL=e.MLDSASecurityLevel=e.QuantumBIP32Factory=e.REGTEST=e.TESTNET=e.BITCOIN=e.BIP32Factory=e.default=void 0;var t=gw();Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.BIP32Factory}}),Object.defineProperty(e,"BIP32Factory",{enumerable:!0,get:function(){return t.BIP32Factory}});var r=yw();Object.defineProperty(e,"BITCOIN",{enumerable:!0,get:function(){return r.BITCOIN}}),Object.defineProperty(e,"TESTNET",{enumerable:!0,get:function(){return r.TESTNET}}),Object.defineProperty(e,"REGTEST",{enumerable:!0,get:function(){return r.REGTEST}});var n=bv();Object.defineProperty(e,"QuantumBIP32Factory",{enumerable:!0,get:function(){return n.QuantumBIP32Factory}}),Object.defineProperty(e,"MLDSASecurityLevel",{enumerable:!0,get:function(){return n.MLDSASecurityLevel}}),Object.defineProperty(e,"DEFAULT_SECURITY_LEVEL",{enumerable:!0,get:function(){return n.DEFAULT_SECURITY_LEVEL}}),Object.defineProperty(e,"getMLDSAConfig",{enumerable:!0,get:function(){return n.getMLDSAConfig}});var i=mv();Object.defineProperty(e,"DerivationPath",{enumerable:!0,get:function(){return i.DerivationPath}}),Object.defineProperty(e,"QuantumDerivationPath",{enumerable:!0,get:function(){return i.QuantumDerivationPath}}),Object.defineProperty(e,"getQuantumPath",{enumerable:!0,get:function(){return i.getQuantumPath}}),Object.defineProperty(e,"getBitcoinPath",{enumerable:!0,get:function(){return i.getBitcoinPath}})}(Pm)),Pm);const vv=Ky(wv);var Ev,_v={},Sv={},kv={};var Av,Iv={};function Tv(e,t,r,n){if(!e)throw new Error(`${t} (${r}: ${n})`)}const xv=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof globalThis<"u")return globalThis;throw new Error("unable to locate global object")}(),Ov=xv.crypto||xv.msCrypto;function Bv(e){switch(e){case"sha256":return Iu.create();case"sha512":return Hc.create()}Tv(!1,"invalid hashing algorithm name","algorithm",e)}function Pv(e,t){const r={sha256:Iu,sha512:Hc}[e];return Tv(null!=r,"invalid hmac algorithm","algorithm",e),Nc.create(r,t)}function Uv(e,t,r,n,i){const o={sha256:Iu,sha512:Hc}[i];return Tv(null!=o,"invalid pbkdf2 algorithm","algorithm",i),Cc(o,e,t,{c:r,dkLen:n})}function Lv(e){if(null==Ov)throw new Error("platform does not support secure random numbers");if(!Number.isInteger(e)||e<=0||e>1024)throw new Error(`invalid length: ${e}`);const t=new Uint8Array(e);return Ov.getRandomValues(t),t}const Nv={createHash:Bv,createHmac:Pv,pbkdf2Sync:Uv,randomBytes:Lv},Rv=zy(Object.freeze(Object.defineProperty({__proto__:null,createHash:Bv,createHmac:Pv,default:Nv,pbkdf2Sync:Uv,randomBytes:Lv},Symbol.toStringTag,{value:"Module"})));var Cv,Hv,Kv,zv;var Mv,Dv,jv,Fv,Vv,qv,Wv,$v,Gv,Xv,Yv,Zv,Qv={exports:{}},Jv={};function eE(){return Mv||(Mv=1,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});for(var t={},r={byteLength:function(e){var t=u(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=u(e),s=n[0],a=n[1],c=new o(function(e,t,r){return 3*(t+r)/4-r}(0,s,a)),f=0,l=a>0?s-4:s;for(r=0;r<l;r+=4)t=i[e.charCodeAt(r)]<<18|i[e.charCodeAt(r+1)]<<12|i[e.charCodeAt(r+2)]<<6|i[e.charCodeAt(r+3)],c[f++]=t>>16&255,c[f++]=t>>8&255,c[f++]=255&t;return 2===a&&(t=i[e.charCodeAt(r)]<<2|i[e.charCodeAt(r+1)]>>4,c[f++]=255&t),1===a&&(t=i[e.charCodeAt(r)]<<10|i[e.charCodeAt(r+1)]<<4|i[e.charCodeAt(r+2)]>>2,c[f++]=t>>8&255,c[f++]=255&t),c},fromByteArray:function(e){for(var t,r=e.length,i=r%3,o=[],s=16383,a=0,u=r-i;a<u;a+=s)o.push(f(e,a,a+s>u?u:a+s));return 1===i?(t=e[r-1],o.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],o.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"=")),o.join("")}},n=[],i=[],o=typeof Uint8Array<"u"?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0;a<64;++a)n[a]=s[a],i[s.charCodeAt(a)]=a;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function c(e){return n[e>>18&63]+n[e>>12&63]+n[e>>6&63]+n[63&e]}function f(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(c(n));return i.join("")}i[45]=62,i[95]=63;var l={read:function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,f=-7,l=r?i-1:0,h=r?-1:1,p=e[t+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},write:function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<<c)-1,l=f>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?h/u:h*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*y}};!function(e){const t=r,n=l,i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=f,e.SlowBuffer=function(e){return+e!=e&&(e=0),f.alloc(+e)},e.INSPECT_MAX_BYTES=50;const o=2147483647;e.kMaxLength=o;const{Uint8Array:s,ArrayBuffer:a,SharedArrayBuffer:u}=globalThis;function c(e){if(e>o)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new s(e);return Object.setPrototypeOf(t,f.prototype),t}function f(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return d(e)}return h(e,t,r)}function h(e,t,r){if("string"==typeof e)return function(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!f.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|b(e,t);let n=c(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(a.isView(e))return function(e){if(Q(e,s)){const t=new s(e);return g(t.buffer,t.byteOffset,t.byteLength)}return y(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(Q(e,a)||e&&Q(e.buffer,a)||typeof u<"u"&&(Q(e,u)||e&&Q(e.buffer,u)))return g(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return f.from(n,t,r);const i=function(e){if(f.isBuffer(e)){const t=0|m(e.length),r=c(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||J(e.length)?c(0):y(e);if("Buffer"===e.type&&Array.isArray(e.data))return y(e.data)}(e);if(i)return i;if(typeof Symbol<"u"&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return f.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function p(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function d(e){return p(e),c(e<0?0:0|m(e))}function y(e){const t=e.length<0?0:0|m(e.length),r=c(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function g(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new s(e):void 0===r?new s(e,t):new s(e,t,r),Object.setPrototypeOf(n,f.prototype),n}function m(e){if(e>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|e}function b(e,t){if(f.isBuffer(e))return e.length;if(a.isView(e)||Q(e,a))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return X(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(e).length;default:if(i)return n?-1:X(e).length;t=(""+t).toLowerCase(),i=!0}}function w(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0)||(r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return L(this,t,r);case"utf8":case"utf-8":return O(this,t,r);case"ascii":return P(this,t,r);case"latin1":case"binary":return U(this,t,r);case"base64":return x(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function v(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function E(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=f.from(t,n)),f.isBuffer(t))return 0===t.length?-1:_(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof s.prototype.indexOf?i?s.prototype.indexOf.call(e,t,r):s.prototype.lastIndexOf.call(e,t,r):_(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function _(e,t,r,n,i){let o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){let n=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(c(e,o+n)!==c(t,n)){r=!1;break}if(r)return o}return-1}function S(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=t.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(J(n))return s;e[r+s]=n}return s}function k(e,t,r,n){return Z(X(t,e.length-r),e,r,n)}function A(e,t,r,n){return Z(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function I(e,t,r,n){return Z(Y(t),e,r,n)}function T(e,t,r,n){return Z(function(e,t){let r,n,i;const o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function x(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function O(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let o=null,s=t>239?4:t>223?3:t>191?2:1;if(i+s<=r){let r,n,a,u;switch(s){case 1:t<128&&(o=t);break;case 2:r=e[i+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(o=u));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(e){const t=e.length;if(t<=B)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=B));return r}(n)}f.TYPED_ARRAY_SUPPORT=function(){try{const e=new s(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,s.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch{return!1}}(),!f.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&"function"==typeof console.error&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}}),f.poolSize=8192,f.from=function(e,t,r){return h(e,t,r)},Object.setPrototypeOf(f.prototype,s.prototype),Object.setPrototypeOf(f,s),f.alloc=function(e,t,r){return function(e,t,r){return p(e),e<=0?c(e):void 0!==t?"string"==typeof r?c(e).fill(t,r):c(e).fill(t):c(e)}(e,t,r)},f.allocUnsafe=function(e){return d(e)},f.allocUnsafeSlow=function(e){return d(e)},f.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==f.prototype},f.compare=function(e,t){if(Q(e,s)&&(e=f.from(e,e.offset,e.byteLength)),Q(t,s)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(e)||!f.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},f.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return f.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=f.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(Q(t,s))i+t.length>n.length?(f.isBuffer(t)||(t=f.from(t)),t.copy(n,i)):s.prototype.set.call(n,t,i);else{if(!f.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},f.byteLength=b,f.prototype._isBuffer=!0,f.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)v(this,t,t+1);return this},f.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)v(this,t,t+3),v(this,t+1,t+2);return this},f.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)v(this,t,t+7),v(this,t+1,t+6),v(this,t+2,t+5),v(this,t+3,t+4);return this},f.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?O(this,0,e):w.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(e){if(!f.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===f.compare(this,e)},f.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},i&&(f.prototype[i]=f.prototype.inspect),f.prototype.compare=function(e,t,r,n,i){if(Q(e,s)&&(e=f.from(e,e.offset,e.byteLength)),!f.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let o=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const u=Math.min(o,a),c=this.slice(n,i),l=e.slice(t,r);for(let s=0;s<u;++s)if(c[s]!==l[s]){o=c[s],a=l[s];break}return o<a?-1:a<o?1:0},f.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},f.prototype.indexOf=function(e,t,r){return E(this,e,t,r,!0)},f.prototype.lastIndexOf=function(e,t,r){return E(this,e,t,r,!1)},f.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return S(this,e,t,r);case"utf8":case"utf-8":return k(this,e,t,r);case"ascii":case"latin1":case"binary":return A(this,e,t,r);case"base64":return I(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const B=4096;function P(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function U(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function L(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=t;o<r;++o)i+=ee[e[o]];return i}function N(e,t,r){const n=e.slice(t,r);let i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function R(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function C(e,t,r,n,i,o){if(!f.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function H(e,t,r,n,i){q(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function K(e,t,r,n,i){q(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function z(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function M(e,t,r,i,o){return t=+t,r>>>=0,o||z(e,0,r,4),n.write(e,t,r,i,23,4),r+4}function D(e,t,r,i,o){return t=+t,r>>>=0,o||z(e,0,r,8),n.write(e,t,r,i,52,8),r+8}f.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,f.prototype),n},f.prototype.readUintLE=f.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return n},f.prototype.readUintBE=f.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},f.prototype.readUint8=f.prototype.readUInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),this[e]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]|this[e+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]<<8|this[e+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},f.prototype.readBigUInt64LE=te(function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&$(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),f.prototype.readBigUInt64BE=te(function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&$(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)}),f.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},f.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=t,i=1,o=this[e+--n];for(;n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},f.prototype.readInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},f.prototype.readInt16LE=function(e,t){e>>>=0,t||R(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt16BE=function(e,t){e>>>=0,t||R(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},f.prototype.readInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},f.prototype.readBigInt64LE=te(function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&$(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),f.prototype.readBigInt64BE=te(function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];(void 0===t||void 0===r)&&$(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)}),f.prototype.readFloatLE=function(e,t){return e>>>=0,t||R(e,4,this.length),n.read(this,e,!0,23,4)},f.prototype.readFloatBE=function(e,t){return e>>>=0,t||R(e,4,this.length),n.read(this,e,!1,23,4)},f.prototype.readDoubleLE=function(e,t){return e>>>=0,t||R(e,8,this.length),n.read(this,e,!0,52,8)},f.prototype.readDoubleBE=function(e,t){return e>>>=0,t||R(e,8,this.length),n.read(this,e,!1,52,8)},f.prototype.writeUintLE=f.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){C(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){C(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},f.prototype.writeUint8=f.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,255,0),this[t]=255&e,t+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},f.prototype.writeBigUInt64LE=te(function(e,t=0){return H(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeBigUInt64BE=te(function(e,t=0){return K(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);C(this,e,t,r,n-1,-n)}let i=0,o=1,s=0;for(this[t]=255&e;++i<r&&(o*=256);)e<0&&0===s&&0!==this[t+i-1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},f.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);C(this,e,t,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===s&&0!==this[t+i+1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},f.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},f.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},f.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},f.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},f.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},f.prototype.writeBigInt64LE=te(function(e,t=0){return H(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeBigInt64BE=te(function(e,t=0){return K(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeFloatLE=function(e,t,r){return M(this,e,t,!0,r)},f.prototype.writeFloatBE=function(e,t,r){return M(this,e,t,!1,r)},f.prototype.writeDoubleLE=function(e,t,r){return D(this,e,t,!0,r)},f.prototype.writeDoubleBE=function(e,t,r){return D(this,e,t,!1,r)},f.prototype.copy=function(e,t,r,n){if(!f.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!n&&0!==n&&(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof s.prototype.copyWithin?this.copyWithin(t,r,n):s.prototype.set.call(e,this.subarray(r,n),t),i},f.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const o=f.isBuffer(e)?e:f.from(e,n),s=o.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=o[i%s]}return this};const j={};function F(e,t,r){j[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function V(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function q(e,t,r,n,i,o){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new j.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,r){W(t,"offset"),(void 0===e[t]||void 0===e[t+r])&&$(t,e.length-(r+1))}(n,i,o)}function W(e,t){if("number"!=typeof e)throw new j.ERR_INVALID_ARG_TYPE(t,"number",e)}function $(e,t,r){throw Math.floor(e)!==e?(W(e,r),new j.ERR_OUT_OF_RANGE("offset","an integer",e)):t<0?new j.ERR_BUFFER_OUT_OF_BOUNDS:new j.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}F("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),F("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),F("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=V(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=V(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);const G=/[^+/0-9A-Za-z-_]/g;function X(e,t){let r;t=t||1/0;const n=e.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(G,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Z(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function J(e){return e!=e}const ee=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function te(e){return typeof BigInt>"u"?re:e}function re(){throw new Error("BigInt not supported")}}(t);const h=t.Buffer;e.Blob=t.Blob,e.BlobOptions=t.BlobOptions,e.Buffer=t.Buffer,e.File=t.File,e.FileOptions=t.FileOptions,e.INSPECT_MAX_BYTES=t.INSPECT_MAX_BYTES,e.SlowBuffer=t.SlowBuffer,e.TranscodeEncoding=t.TranscodeEncoding,e.atob=t.atob,e.btoa=t.btoa,e.constants=t.constants,e.default=h,e.isAscii=t.isAscii,e.isUtf8=t.isUtf8,e.kMaxLength=t.kMaxLength,e.kStringMaxLength=t.kStringMaxLength,e.resolveObjectURL=t.resolveObjectURL,e.transcode=t.transcode}(Jv)),Jv}function tE(){return Dv||(Dv=1,function(e,t){var r=eE(),n=r.Buffer;function i(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o),o.prototype=Object.create(n.prototype),i(n,o),o.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=n(e);return void 0!==t?"string"==typeof r?i.fill(t,r):i.fill(t):i.fill(0),i},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}(Qv,Qv.exports)),Qv.exports}function rE(){if(qv)return Vv;qv=1;var e=function(){if(Fv)return jv;Fv=1;var e=tE().Buffer;return jv=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(255!==r[s])throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,u=t.charAt(0),c=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return e.alloc(0);for(var n=0,i=0,o=0;t[n]===u;)i++,n++;for(var s=(t.length-n)*c+1>>>0,f=new Uint8Array(s);n<t.length;){var l=t.charCodeAt(n);if(l>255)return;var h=r[l];if(255===h)return;for(var p=0,d=s-1;(0!==h||p<o)&&-1!==d;d--,p++)h+=a*f[d]>>>0,f[d]=h%256>>>0,h=h/256>>>0;if(0!==h)throw new Error("Non-zero carry");o=p,n++}for(var y=s-o;y!==s&&0===f[y];)y++;var g=e.allocUnsafe(i+(s-y));g.fill(0,0,i);for(var m=i;y!==s;)g[m++]=f[y++];return g}return{encode:function(r){if((Array.isArray(r)||r instanceof Uint8Array)&&(r=e.from(r)),!e.isBuffer(r))throw new TypeError("Expected Buffer");if(0===r.length)return"";for(var n=0,i=0,o=0,s=r.length;o!==s&&0===r[o];)o++,n++;for(var c=(s-o)*f+1>>>0,l=new Uint8Array(c);o!==s;){for(var h=r[o],p=0,d=c-1;(0!==h||p<i)&&-1!==d;d--,p++)h+=256*l[d]>>>0,l[d]=h%a>>>0,h=h/a>>>0;if(0!==h)throw new Error("Non-zero carry");i=p,o++}for(var y=c-i;y!==c&&0===l[y];)y++;for(var g=u.repeat(n);y<c;++y)g+=t.charAt(l[y]);return g},decodeUnsafe:l,decode:function(e){var t=l(e);if(t)return t;throw new Error("Non-base"+a+" character")}}},jv}();return Vv=e("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")}function nE(){if(Xv)return Gv;Xv=1;var e=(zv||(zv=1,Kv=Rv.createHash),Kv),t=function(){if($v)return Wv;$v=1;var e=rE(),t=tE().Buffer;return Wv=function(r){function n(e){var t=e.slice(0,-4),n=e.slice(-4),i=r(t);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return t}return{encode:function(n){var i=r(n);return e.encode(t.concat([n,i],n.length+4))},decode:function(t){var r=n(e.decode(t));if(!r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(t){var r=e.decodeUnsafe(t);if(r)return n(r)}}},Wv}();return Gv=t(function(t){var r=e("sha256").update(t).digest();return e("sha256").update(r).digest()})}var iE,oE,sE,aE={};function uE(){if(oE)return Sv;oE=1,Object.defineProperty(Sv,"__esModule",{value:!0}),Sv.ECPairFactory=Sv.networks=void 0;const e=(Ev||(Ev=1,Object.defineProperty(kv,"__esModule",{value:!0}),kv.testnet=kv.bitcoin=void 0,kv.bitcoin={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},kv.testnet={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}),kv);Sv.networks=e;const t=function(){return Av||(Av=1,e=Iv,Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=tg(),e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe),Iv;var e}(),r=(Hv||(Hv=1,Cv=Rv.randomBytes),Cv),n=function(){if(Zv)return Yv;Zv=1;var e=nE();function t(e,t){if(void 0!==t&&e[0]!==t)throw new Error("Invalid network version");if(33===e.length)return{version:e[0],privateKey:e.slice(1,33),compressed:!1};if(34!==e.length)throw new Error("Invalid WIF length");if(1!==e[33])throw new Error("Invalid compression flag");return{version:e[0],privateKey:e.slice(1,33),compressed:!0}}function r(e,t,r){var n=new nh(r?34:33);return n.writeUInt8(e,0),t.copy(n,1),r&&(n[33]=1),n}return Yv={decode:function(r,n){return t(e.decode(r),n)},decodeRaw:t,encode:function(t,n,i){return"number"==typeof t?e.encode(r(t,n,i)):e.encode(r(t.version,t.privateKey,t.compressed))},encodeRaw:r},Yv}(),i=function(){if(iE)return aE;iE=1,Object.defineProperty(aE,"__esModule",{value:!0}),aE.testEcc=void 0;const e=e=>nh.from(e,"hex");function t(e){if(!e)throw new Error("ecc library invalid")}return aE.testEcc=function(r){t(r.isPoint(e("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),t(!r.isPoint(e("030000000000000000000000000000000000000000000000000000000000000005"))),t(r.isPrivate(e("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),t(r.isPrivate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),t(!r.isPrivate(e("0000000000000000000000000000000000000000000000000000000000000000"))),t(!r.isPrivate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),t(!r.isPrivate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),t(nh.from(r.privateAdd(e("0000000000000000000000000000000000000000000000000000000000000001"),e("0000000000000000000000000000000000000000000000000000000000000000"))).equals(e("0000000000000000000000000000000000000000000000000000000000000001"))),t(null===r.privateAdd(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),e("0000000000000000000000000000000000000000000000000000000000000003"))),t(nh.from(r.privateAdd(e("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),e("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(e("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),t(nh.from(r.privateNegate(e("0000000000000000000000000000000000000000000000000000000000000001"))).equals(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),t(nh.from(r.privateNegate(e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(e("0000000000000000000000000000000000000000000000000000000000000003"))),t(nh.from(r.privateNegate(e("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(e("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),t(nh.from(r.pointCompress(e("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(e("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),t(nh.from(r.pointCompress(e("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(e("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),t(nh.from(r.pointCompress(e("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(e("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),t(nh.from(r.pointCompress(e("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(e("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),t(nh.from(r.pointFromScalar(e("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(e("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),t(null===r.xOnlyPointAddTweak(e("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")));let n=r.xOnlyPointAddTweak(e("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),e("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));t(nh.from(n.xOnlyPubkey).equals(e("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&1===n.parity),n=r.xOnlyPointAddTweak(e("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),e("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),t(nh.from(n.xOnlyPubkey).equals(e("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&0===n.parity),t(nh.from(r.sign(e("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),e("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(e("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),t(r.verify(e("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),e("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),e("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),r.signSchnorr&&t(nh.from(r.signSchnorr(e("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),e("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),e("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(e("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),r.verifySchnorr&&t(r.verifySchnorr(e("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),e("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),e("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))},aE}(),o=t.typeforce.maybe(t.typeforce.compile({compressed:t.maybe(t.Boolean),network:t.maybe(t.Network)}));return Sv.ECPairFactory=function(s){function a(e,r){if(t.typeforce(t.Buffer256bit,e),!s.isPrivate(e))throw new TypeError("Private key not in range [1, n)");return t.typeforce(o,r),new c(e,void 0,r)}function u(e,r){return t.typeforce(s.isPoint,e),t.typeforce(o,r),new c(void 0,e,r)}(0,i.testEcc)(s);class c{__D;__Q;compressed;network;lowR;constructor(t,r,n){this.__D=t,this.__Q=r,this.lowR=!1,void 0===n&&(n={}),this.compressed=void 0===n.compressed||n.compressed,this.network=n.network||e.bitcoin,void 0!==r&&(this.__Q=nh.from(s.pointCompress(r,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const e=s.pointFromScalar(this.__D,this.compressed);this.__Q=nh.from(e)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return n.encode(this.network.wif,this.__D,this.compressed)}tweak(e){return this.privateKey?this.tweakFromPrivateKey(e):this.tweakFromPublicKey(e)}sign(e,t){if(!this.__D)throw new Error("Missing private key");if(void 0===t&&(t=this.lowR),!1===t)return nh.from(s.sign(e,this.__D));{let t=s.sign(e,this.__D);const r=nh.alloc(32,0);let n=0;for(;t[0]>127;)n++,r.writeUIntLE(n,0,6),t=s.sign(e,this.__D,r);return nh.from(t)}}signSchnorr(e){if(!this.privateKey)throw new Error("Missing private key");if(!s.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return nh.from(s.signSchnorr(e,this.privateKey))}verify(e,t){return s.verify(e,this.publicKey,t)}verifySchnorr(e,t){if(!s.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return s.verifySchnorr(e,this.publicKey.subarray(1,33),t)}tweakFromPublicKey(e){const t=(e=>32===e.length?e:e.slice(1,33))(this.publicKey),r=s.xOnlyPointAddTweak(t,e);if(!r||null===r.xOnlyPubkey)throw new Error("Cannot tweak public key!");const n=nh.from([0===r.parity?2:3]);return u(nh.concat([n,r.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(e){const t=3!==this.publicKey[0]&&(4!==this.publicKey[0]||1&~this.publicKey[64])?this.privateKey:s.privateNegate(this.privateKey),r=s.privateAdd(t,e);if(!r)throw new Error("Invalid tweaked private key!");return a(nh.from(r),{network:this.network,compressed:this.compressed})}}return{isPoint:function(e){return s.isPoint(e)},fromPrivateKey:a,fromPublicKey:u,fromWIF:function(r,i){const o=n.decode(r),s=o.version;if(t.Array(i)){if(!(i=i.filter(e=>s===e.wif).pop()))throw new Error("Unknown network version")}else if(i=i||e.bitcoin,s!==i.wif)throw new Error("Invalid network version");return a(o.privateKey,{compressed:o.compressed,network:i})},makeRandom:function(e){t.typeforce(o,e),void 0===e&&(e={});const n=e.rng||r;let i;do{i=n(32),t.typeforce(t.Buffer256bit,i)}while(!s.isPrivate(i));return a(i,e)}}},Sv}var cE=(sE||(sE=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=uE();Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"ECPairFactory",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"networks",{enumerable:!0,get:function(){return t.networks}})}(_v)),_v);function fE(e,t){e=e.replace("#","");const r=parseInt(e,16),n=Math.round(2.55*t),i=(r>>16)+n,o=(r>>8&255)+n,s=(255&r)+n;return(16777216+65536*(i<255?i<1?0:i:255)+256*(o<255?o<1?0:o:255)+(s<255?s<1?0:s:255)).toString(16).slice(1)}const lE=(e=0)=>t=>`[${t+e}m`,hE=(e=0)=>t=>`[${38+e};5;${t}m`,pE=(e=0)=>(t,r,n)=>`[${38+e};2;${t};${r};${n}m`,dE={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(dE.modifier);Object.keys(dE.color),Object.keys(dE.bgColor);const yE=function(){const e=new Map;for(const[t,r]of Object.entries(dE)){for(const[t,n]of Object.entries(r))dE[t]={open:`[${n[0]}m`,close:`[${n[1]}m`},r[t]=dE[t],e.set(n[0],n[1]);Object.defineProperty(dE,t,{value:r,enumerable:!1})}return Object.defineProperty(dE,"codes",{value:e,enumerable:!1}),dE.color.close="",dE.bgColor.close="",dE.color.ansi=lE(),dE.color.ansi256=hE(),dE.color.ansi16m=pE(),dE.bgColor.ansi=lE(10),dE.bgColor.ansi256=hE(10),dE.bgColor.ansi16m=pE(10),Object.defineProperties(dE,{rgbToAnsi256:{value:(e,t,r)=>e===t&&t===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(r/255*5),enumerable:!1},hexToRgb:{value(e){const t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[r]=t;3===r.length&&(r=[...r].map(e=>e+e).join(""));const n=Number.parseInt(r,16);return[n>>16&255,n>>8&255,255&n]},enumerable:!1},hexToAnsi256:{value:e=>dE.rgbToAnsi256(...dE.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return e-8+90;let t,r,n;if(e>=232)t=(10*(e-232)+8)/255,r=t,n=t;else{const i=(e-=16)%36;t=Math.floor(e/36)/5,r=Math.floor(i/6)/5,n=i%6/5}const i=2*Math.max(t,r,n);if(0===i)return 30;let o=30+(Math.round(n)<<2|Math.round(r)<<1|Math.round(t));return 2===i&&(o+=60),o},enumerable:!1},rgbToAnsi:{value:(e,t,r)=>dE.ansi256ToAnsi(dE.rgbToAnsi256(e,t,r)),enumerable:!1},hexToAnsi:{value:e=>dE.ansi256ToAnsi(dE.hexToAnsi256(e)),enumerable:!1}}),dE}(),gE=(()=>{if(!("navigator"in globalThis))return 0;if(globalThis.navigator.userAgentData){const e=navigator.userAgentData.brands.find(({brand:e})=>"Chromium"===e);if(e&&e.version>93)return 3}return/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)?1:0})(),mE=0!==gE&&{level:gE},bE={stdout:mE,stderr:mE};function wE(e,t,r){let n=e.indexOf(t);if(-1===n)return e;const i=t.length;let o=0,s="";do{s+=e.slice(o,n)+t+r,o=n+i,n=e.indexOf(t,o)}while(-1!==n);return s+=e.slice(o),s}const{stdout:vE,stderr:EE}=bE,_E=Symbol("GENERATOR"),SE=Symbol("STYLER"),kE=Symbol("IS_EMPTY"),AE=["ansi","ansi","ansi256","ansi16m"],IE=Object.create(null);class TE{constructor(e){return xE(e)}}const xE=e=>{const t=(...e)=>e.join(" ");return((e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const r=vE?vE.level:0;e.level=void 0===t.level?r:t.level})(t,e),Object.setPrototypeOf(t,OE.prototype),t};function OE(e){return xE(e)}Object.setPrototypeOf(OE.prototype,Function.prototype);for(const[_R,SR]of Object.entries(yE))IE[_R]={get(){const e=NE(this,LE(SR.open,SR.close,this[SE]),this[kE]);return Object.defineProperty(this,_R,{value:e}),e}};IE.visible={get(){const e=NE(this,this[SE],!0);return Object.defineProperty(this,"visible",{value:e}),e}};const BE=(e,t,r,...n)=>"rgb"===e?"ansi16m"===t?yE[r].ansi16m(...n):"ansi256"===t?yE[r].ansi256(yE.rgbToAnsi256(...n)):yE[r].ansi(yE.rgbToAnsi(...n)):"hex"===e?BE("rgb",t,r,...yE.hexToRgb(...n)):yE[r][e](...n),PE=["rgb","hex","ansi256"];for(const _R of PE){IE[_R]={get(){const{level:e}=this;return function(...t){const r=LE(BE(_R,AE[e],"color",...t),yE.color.close,this[SE]);return NE(this,r,this[kE])}}};IE["bg"+_R[0].toUpperCase()+_R.slice(1)]={get(){const{level:e}=this;return function(...t){const r=LE(BE(_R,AE[e],"bgColor",...t),yE.bgColor.close,this[SE]);return NE(this,r,this[kE])}}}}const UE=Object.defineProperties(()=>{},{...IE,level:{enumerable:!0,get(){return this[_E].level},set(e){this[_E].level=e}}}),LE=(e,t,r)=>{let n,i;return void 0===r?(n=e,i=t):(n=r.openAll+e,i=t+r.closeAll),{open:e,close:t,openAll:n,closeAll:i,parent:r}},NE=(e,t,r)=>{const n=(...e)=>RE(n,1===e.length?""+e[0]:e.join(" "));return Object.setPrototypeOf(n,UE),n[_E]=e,n[SE]=t,n[kE]=r,n},RE=(e,t)=>{if(e.level<=0||!t)return e[kE]?"":t;let r=e[SE];if(void 0===r)return t;const{openAll:n,closeAll:i}=r;if(t.includes(""))for(;void 0!==r;)t=wE(t,r.close,r.open),r=r.parent;const o=t.indexOf("\n");return-1!==o&&(t=function(e,t,r,n){let i=0,o="";do{const s="\r"===e[n-1];o+=e.slice(i,s?n-1:n)+t+(s?"\r\n":"\n")+r,i=n+1,n=e.indexOf("\n",i)}while(-1!==n);return o+=e.slice(i),o}(t,i,n,o)),n+t+i};Object.defineProperties(OE.prototype,IE),OE(),OE({level:EE?EE.level:0});var CE,HE,KE,zE,ME,DE,jE,FE,VE,qE,WE,$E,GE,XE,YE,ZE,QE,JE,e_,t_=function(e,t,r,n){if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:t.get(e)};class r_{constructor(e=new TE){this.chalk=e,this.moduleName="",this.logColor="#00bfff",this.enableLogs=!0,this.hideLogs=!1,CE.set(this,"#ff00ff"),HE.set(this,fE(t_(this,CE,"f"),75)),KE.set(this,"#9400d3"),zE.set(this,fE(t_(this,KE,"f"),15)),ME.set(this,fE(t_(this,zE,"f"),15)),DE.set(this,"#7cfc00"),jE.set(this,fE(t_(this,DE,"f"),15)),FE.set(this,"#ffdead"),VE.set(this,fE(t_(this,FE,"f"),15)),qE.set(this,"#ff8c00"),WE.set(this,fE(t_(this,qE,"f"),15)),$E.set(this,"#ff4500"),GE.set(this,fE(t_(this,$E,"f"),15)),XE.set(this,"#ffffff"),YE.set(this,fE(t_(this,XE,"f"),15)),ZE.set(this,"#8b0000"),QE.set(this,fE(t_(this,ZE,"f"),15)),this.prefix="",this.moduleName=this.constructor.name}setLogPrefix(e){this.prefix=e}getStartPrefix(){return this.prefix}disable(){this.enableLogs=!1}enable(){this.enableLogs=!0}fancyLog(e,t,r,n,i){this.enableLogs&&console.log(this.chalk.hex(t_(this,CE,"f"))(`${this.getStartPrefix()}[${this.moduleName} INFO]: `)+this.chalk.hex(t_(this,XE,"f"))(e)+" "+this.chalk.hex(t_(this,WE,"f"))(t)+" "+this.chalk.hex(t_(this,XE,"f"))(r)+" "+this.chalk.hex(t_(this,ME,"f"))(n)+" "+this.chalk.hex(t_(this,XE,"f"))(i))}log(...e){if(this.enableLogs&&!this.hideLogs){const t=fE(this.logColor,15);console.log(this.chalk.hex(this.logColor)(`${this.getStartPrefix()}[${this.moduleName} LOG]: `)+this.chalk.hex(t)(...e))}}lightOrangeLog(...e){this.enableLogs&&(this.hideLogs||console.log(this.chalk.hex(t_(this,WE,"f"))(`${this.getStartPrefix()}[${this.moduleName} LOG]: `)+this.chalk.hex(t_(this,XE,"f"))(...e)))}error(...e){this.enableLogs&&console.log(this.chalk.hex(t_(this,$E,"f"))(`${this.getStartPrefix()}[${this.moduleName} ERROR]: `)+this.chalk.hex(t_(this,GE,"f"))(...e))}warn(...e){this.enableLogs&&console.log(this.chalk.hex(t_(this,qE,"f"))(`${this.getStartPrefix()}[${this.moduleName} WARN]: `)+this.chalk.hex(t_(this,WE,"f"))(...e))}debug(...e){this.enableLogs&&(this.hideLogs||console.log(this.chalk.hex(t_(this,FE,"f"))(`${this.getStartPrefix()}[${this.moduleName} DEBUG]: `)+this.chalk.hex(t_(this,VE,"f"))(...e)))}success(...e){this.enableLogs&&(this.hideLogs||console.log(this.chalk.hex(t_(this,DE,"f"))(`${this.getStartPrefix()}[${this.moduleName} SUCCESS]: `)+this.chalk.hex(t_(this,jE,"f"))(...e)))}fail(...e){this.enableLogs&&(this.hideLogs||console.log(this.chalk.hex(t_(this,$E,"f"))(`${this.getStartPrefix()}[${this.moduleName} FAIL]: `)+this.chalk.hex(t_(this,GE,"f"))(...e)))}debugBright(...e){this.enableLogs&&(this.hideLogs||console.log(this.chalk.hex(t_(this,KE,"f"))(`${this.getStartPrefix()}[${this.moduleName} DEBUG]: `)+this.chalk.hex(t_(this,zE,"f"))(...e)))}important(...e){this.enableLogs&&console.log(this.chalk.hex(t_(this,CE,"f"))(`${this.getStartPrefix()}[${this.moduleName} IMPORTANT]: `)+this.chalk.hex(t_(this,HE,"f"))(...e))}panic(...e){this.enableLogs&&console.log(this.chalk.hex(t_(this,ZE,"f"))(`${this.getStartPrefix()}[${this.moduleName} HELP PANIC]: `)+this.chalk.hex(t_(this,QE,"f"))(...e))}info(...e){this.enableLogs&&console.log(this.chalk.hex(t_(this,CE,"f"))(`${this.getStartPrefix()}[${this.moduleName} INFO]: `)+this.chalk.hex(t_(this,XE,"f"))(...e))}securityNotice(...e){this.enableLogs&&console.log(this.chalk.hex("#22d8e6")(`${this.getStartPrefix()}[${this.moduleName} SECURITY NOTICE]: `)+this.chalk.hex("#22e3e6")(...e))}traceLog(...e){this.enableLogs&&console.log(this.chalk.hex("#ffffff")(`${this.getStartPrefix()}[${this.moduleName} TRACE LOG]: `)+this.chalk.hex(t_(this,YE,"f"))(...e))}}CE=new WeakMap,HE=new WeakMap,KE=new WeakMap,zE=new WeakMap,ME=new WeakMap,DE=new WeakMap,jE=new WeakMap,FE=new WeakMap,VE=new WeakMap,qE=new WeakMap,WE=new WeakMap,$E=new WeakMap,GE=new WeakMap,XE=new WeakMap,YE=new WeakMap,ZE=new WeakMap,QE=new WeakMap;class n_ extends r_{constructor(){super()}}(e_=JE||(JE={}))[e_.NONE=0]="NONE",e_[e_.ERROR=1]="ERROR",e_[e_.WARN=2]="WARN",e_[e_.INFO=3]="INFO",e_[e_.DEBUG=4]="DEBUG",e_[e_.TRACE=5]="TRACE",e_[e_.ALL=6]="ALL";var i_={},o_={};const s_=JSON.parse('["abdikace","abeceda","adresa","agrese","akce","aktovka","alej","alkohol","amputace","ananas","andulka","anekdota","anketa","antika","anulovat","archa","arogance","asfalt","asistent","aspirace","astma","astronom","atlas","atletika","atol","autobus","azyl","babka","bachor","bacil","baculka","badatel","bageta","bagr","bahno","bakterie","balada","baletka","balkon","balonek","balvan","balza","bambus","bankomat","barbar","baret","barman","baroko","barva","baterka","batoh","bavlna","bazalka","bazilika","bazuka","bedna","beran","beseda","bestie","beton","bezinka","bezmoc","beztak","bicykl","bidlo","biftek","bikiny","bilance","biograf","biolog","bitva","bizon","blahobyt","blatouch","blecha","bledule","blesk","blikat","blizna","blokovat","bloudit","blud","bobek","bobr","bodlina","bodnout","bohatost","bojkot","bojovat","bokorys","bolest","borec","borovice","bota","boubel","bouchat","bouda","boule","bourat","boxer","bradavka","brambora","branka","bratr","brepta","briketa","brko","brloh","bronz","broskev","brunetka","brusinka","brzda","brzy","bublina","bubnovat","buchta","buditel","budka","budova","bufet","bujarost","bukvice","buldok","bulva","bunda","bunkr","burza","butik","buvol","buzola","bydlet","bylina","bytovka","bzukot","capart","carevna","cedr","cedule","cejch","cejn","cela","celer","celkem","celnice","cenina","cennost","cenovka","centrum","cenzor","cestopis","cetka","chalupa","chapadlo","charita","chata","chechtat","chemie","chichot","chirurg","chlad","chleba","chlubit","chmel","chmura","chobot","chochol","chodba","cholera","chomout","chopit","choroba","chov","chrapot","chrlit","chrt","chrup","chtivost","chudina","chutnat","chvat","chvilka","chvost","chyba","chystat","chytit","cibule","cigareta","cihelna","cihla","cinkot","cirkus","cisterna","citace","citrus","cizinec","cizost","clona","cokoliv","couvat","ctitel","ctnost","cudnost","cuketa","cukr","cupot","cvaknout","cval","cvik","cvrkot","cyklista","daleko","dareba","datel","datum","dcera","debata","dechovka","decibel","deficit","deflace","dekl","dekret","demokrat","deprese","derby","deska","detektiv","dikobraz","diktovat","dioda","diplom","disk","displej","divadlo","divoch","dlaha","dlouho","dluhopis","dnes","dobro","dobytek","docent","dochutit","dodnes","dohled","dohoda","dohra","dojem","dojnice","doklad","dokola","doktor","dokument","dolar","doleva","dolina","doma","dominant","domluvit","domov","donutit","dopad","dopis","doplnit","doposud","doprovod","dopustit","dorazit","dorost","dort","dosah","doslov","dostatek","dosud","dosyta","dotaz","dotek","dotknout","doufat","doutnat","dovozce","dozadu","doznat","dozorce","drahota","drak","dramatik","dravec","draze","drdol","drobnost","drogerie","drozd","drsnost","drtit","drzost","duben","duchovno","dudek","duha","duhovka","dusit","dusno","dutost","dvojice","dvorec","dynamit","ekolog","ekonomie","elektron","elipsa","email","emise","emoce","empatie","epizoda","epocha","epopej","epos","esej","esence","eskorta","eskymo","etiketa","euforie","evoluce","exekuce","exkurze","expedice","exploze","export","extrakt","facka","fajfka","fakulta","fanatik","fantazie","farmacie","favorit","fazole","federace","fejeton","fenka","fialka","figurant","filozof","filtr","finance","finta","fixace","fjord","flanel","flirt","flotila","fond","fosfor","fotbal","fotka","foton","frakce","freska","fronta","fukar","funkce","fyzika","galeje","garant","genetika","geolog","gilotina","glazura","glejt","golem","golfista","gotika","graf","gramofon","granule","grep","gril","grog","groteska","guma","hadice","hadr","hala","halenka","hanba","hanopis","harfa","harpuna","havran","hebkost","hejkal","hejno","hejtman","hektar","helma","hematom","herec","herna","heslo","hezky","historik","hladovka","hlasivky","hlava","hledat","hlen","hlodavec","hloh","hloupost","hltat","hlubina","hluchota","hmat","hmota","hmyz","hnis","hnojivo","hnout","hoblina","hoboj","hoch","hodiny","hodlat","hodnota","hodovat","hojnost","hokej","holinka","holka","holub","homole","honitba","honorace","horal","horda","horizont","horko","horlivec","hormon","hornina","horoskop","horstvo","hospoda","hostina","hotovost","houba","houf","houpat","houska","hovor","hradba","hranice","hravost","hrazda","hrbolek","hrdina","hrdlo","hrdost","hrnek","hrobka","hromada","hrot","hrouda","hrozen","hrstka","hrubost","hryzat","hubenost","hubnout","hudba","hukot","humr","husita","hustota","hvozd","hybnost","hydrant","hygiena","hymna","hysterik","idylka","ihned","ikona","iluze","imunita","infekce","inflace","inkaso","inovace","inspekce","internet","invalida","investor","inzerce","ironie","jablko","jachta","jahoda","jakmile","jakost","jalovec","jantar","jarmark","jaro","jasan","jasno","jatka","javor","jazyk","jedinec","jedle","jednatel","jehlan","jekot","jelen","jelito","jemnost","jenom","jepice","jeseter","jevit","jezdec","jezero","jinak","jindy","jinoch","jiskra","jistota","jitrnice","jizva","jmenovat","jogurt","jurta","kabaret","kabel","kabinet","kachna","kadet","kadidlo","kahan","kajak","kajuta","kakao","kaktus","kalamita","kalhoty","kalibr","kalnost","kamera","kamkoliv","kamna","kanibal","kanoe","kantor","kapalina","kapela","kapitola","kapka","kaple","kapota","kapr","kapusta","kapybara","karamel","karotka","karton","kasa","katalog","katedra","kauce","kauza","kavalec","kazajka","kazeta","kazivost","kdekoliv","kdesi","kedluben","kemp","keramika","kino","klacek","kladivo","klam","klapot","klasika","klaun","klec","klenba","klepat","klesnout","klid","klima","klisna","klobouk","klokan","klopa","kloub","klubovna","klusat","kluzkost","kmen","kmitat","kmotr","kniha","knot","koalice","koberec","kobka","kobliha","kobyla","kocour","kohout","kojenec","kokos","koktejl","kolaps","koleda","kolize","kolo","komando","kometa","komik","komnata","komora","kompas","komunita","konat","koncept","kondice","konec","konfese","kongres","konina","konkurs","kontakt","konzerva","kopanec","kopie","kopnout","koprovka","korbel","korektor","kormidlo","koroptev","korpus","koruna","koryto","korzet","kosatec","kostka","kotel","kotleta","kotoul","koukat","koupelna","kousek","kouzlo","kovboj","koza","kozoroh","krabice","krach","krajina","kralovat","krasopis","kravata","kredit","krejcar","kresba","kreveta","kriket","kritik","krize","krkavec","krmelec","krmivo","krocan","krok","kronika","kropit","kroupa","krovka","krtek","kruhadlo","krupice","krutost","krvinka","krychle","krypta","krystal","kryt","kudlanka","kufr","kujnost","kukla","kulajda","kulich","kulka","kulomet","kultura","kuna","kupodivu","kurt","kurzor","kutil","kvalita","kvasinka","kvestor","kynolog","kyselina","kytara","kytice","kytka","kytovec","kyvadlo","labrador","lachtan","ladnost","laik","lakomec","lamela","lampa","lanovka","lasice","laso","lastura","latinka","lavina","lebka","leckdy","leden","lednice","ledovka","ledvina","legenda","legie","legrace","lehce","lehkost","lehnout","lektvar","lenochod","lentilka","lepenka","lepidlo","letadlo","letec","letmo","letokruh","levhart","levitace","levobok","libra","lichotka","lidojed","lidskost","lihovina","lijavec","lilek","limetka","linie","linka","linoleum","listopad","litina","litovat","lobista","lodivod","logika","logoped","lokalita","loket","lomcovat","lopata","lopuch","lord","losos","lotr","loudal","louh","louka","louskat","lovec","lstivost","lucerna","lucifer","lump","lusk","lustrace","lvice","lyra","lyrika","lysina","madam","madlo","magistr","mahagon","majetek","majitel","majorita","makak","makovice","makrela","malba","malina","malovat","malvice","maminka","mandle","manko","marnost","masakr","maskot","masopust","matice","matrika","maturita","mazanec","mazivo","mazlit","mazurka","mdloba","mechanik","meditace","medovina","melasa","meloun","mentolka","metla","metoda","metr","mezera","migrace","mihnout","mihule","mikina","mikrofon","milenec","milimetr","milost","mimika","mincovna","minibar","minomet","minulost","miska","mistr","mixovat","mladost","mlha","mlhovina","mlok","mlsat","mluvit","mnich","mnohem","mobil","mocnost","modelka","modlitba","mohyla","mokro","molekula","momentka","monarcha","monokl","monstrum","montovat","monzun","mosaz","moskyt","most","motivace","motorka","motyka","moucha","moudrost","mozaika","mozek","mozol","mramor","mravenec","mrkev","mrtvola","mrzet","mrzutost","mstitel","mudrc","muflon","mulat","mumie","munice","muset","mutace","muzeum","muzikant","myslivec","mzda","nabourat","nachytat","nadace","nadbytek","nadhoz","nadobro","nadpis","nahlas","nahnat","nahodile","nahradit","naivita","najednou","najisto","najmout","naklonit","nakonec","nakrmit","nalevo","namazat","namluvit","nanometr","naoko","naopak","naostro","napadat","napevno","naplnit","napnout","naposled","naprosto","narodit","naruby","narychlo","nasadit","nasekat","naslepo","nastat","natolik","navenek","navrch","navzdory","nazvat","nebe","nechat","necky","nedaleko","nedbat","neduh","negace","nehet","nehoda","nejen","nejprve","neklid","nelibost","nemilost","nemoc","neochota","neonka","nepokoj","nerost","nerv","nesmysl","nesoulad","netvor","neuron","nevina","nezvykle","nicota","nijak","nikam","nikdy","nikl","nikterak","nitro","nocleh","nohavice","nominace","nora","norek","nositel","nosnost","nouze","noviny","novota","nozdra","nuda","nudle","nuget","nutit","nutnost","nutrie","nymfa","obal","obarvit","obava","obdiv","obec","obehnat","obejmout","obezita","obhajoba","obilnice","objasnit","objekt","obklopit","oblast","oblek","obliba","obloha","obluda","obnos","obohatit","obojek","obout","obrazec","obrna","obruba","obrys","obsah","obsluha","obstarat","obuv","obvaz","obvinit","obvod","obvykle","obyvatel","obzor","ocas","ocel","ocenit","ochladit","ochota","ochrana","ocitnout","odboj","odbyt","odchod","odcizit","odebrat","odeslat","odevzdat","odezva","odhadce","odhodit","odjet","odjinud","odkaz","odkoupit","odliv","odluka","odmlka","odolnost","odpad","odpis","odplout","odpor","odpustit","odpykat","odrazka","odsoudit","odstup","odsun","odtok","odtud","odvaha","odveta","odvolat","odvracet","odznak","ofina","ofsajd","ohlas","ohnisko","ohrada","ohrozit","ohryzek","okap","okenice","oklika","okno","okouzlit","okovy","okrasa","okres","okrsek","okruh","okupant","okurka","okusit","olejnina","olizovat","omak","omeleta","omezit","omladina","omlouvat","omluva","omyl","onehdy","opakovat","opasek","operace","opice","opilost","opisovat","opora","opozice","opravdu","oproti","orbital","orchestr","orgie","orlice","orloj","ortel","osada","oschnout","osika","osivo","oslava","oslepit","oslnit","oslovit","osnova","osoba","osolit","ospalec","osten","ostraha","ostuda","ostych","osvojit","oteplit","otisk","otop","otrhat","otrlost","otrok","otruby","otvor","ovanout","ovar","oves","ovlivnit","ovoce","oxid","ozdoba","pachatel","pacient","padouch","pahorek","pakt","palanda","palec","palivo","paluba","pamflet","pamlsek","panenka","panika","panna","panovat","panstvo","pantofle","paprika","parketa","parodie","parta","paruka","paryba","paseka","pasivita","pastelka","patent","patrona","pavouk","pazneht","pazourek","pecka","pedagog","pejsek","peklo","peloton","penalta","pendrek","penze","periskop","pero","pestrost","petarda","petice","petrolej","pevnina","pexeso","pianista","piha","pijavice","pikle","piknik","pilina","pilnost","pilulka","pinzeta","pipeta","pisatel","pistole","pitevna","pivnice","pivovar","placenta","plakat","plamen","planeta","plastika","platit","plavidlo","plaz","plech","plemeno","plenta","ples","pletivo","plevel","plivat","plnit","plno","plocha","plodina","plomba","plout","pluk","plyn","pobavit","pobyt","pochod","pocit","poctivec","podat","podcenit","podepsat","podhled","podivit","podklad","podmanit","podnik","podoba","podpora","podraz","podstata","podvod","podzim","poezie","pohanka","pohnutka","pohovor","pohroma","pohyb","pointa","pojistka","pojmout","pokazit","pokles","pokoj","pokrok","pokuta","pokyn","poledne","polibek","polknout","poloha","polynom","pomalu","pominout","pomlka","pomoc","pomsta","pomyslet","ponechat","ponorka","ponurost","popadat","popel","popisek","poplach","poprosit","popsat","popud","poradce","porce","porod","porucha","poryv","posadit","posed","posila","poskok","poslanec","posoudit","pospolu","postava","posudek","posyp","potah","potkan","potlesk","potomek","potrava","potupa","potvora","poukaz","pouto","pouzdro","povaha","povidla","povlak","povoz","povrch","povstat","povyk","povzdech","pozdrav","pozemek","poznatek","pozor","pozvat","pracovat","prahory","praktika","prales","praotec","praporek","prase","pravda","princip","prkno","probudit","procento","prodej","profese","prohra","projekt","prolomit","promile","pronikat","propad","prorok","prosba","proton","proutek","provaz","prskavka","prsten","prudkost","prut","prvek","prvohory","psanec","psovod","pstruh","ptactvo","puberta","puch","pudl","pukavec","puklina","pukrle","pult","pumpa","punc","pupen","pusa","pusinka","pustina","putovat","putyka","pyramida","pysk","pytel","racek","rachot","radiace","radnice","radon","raft","ragby","raketa","rakovina","rameno","rampouch","rande","rarach","rarita","rasovna","rastr","ratolest","razance","razidlo","reagovat","reakce","recept","redaktor","referent","reflex","rejnok","reklama","rekord","rekrut","rektor","reputace","revize","revma","revolver","rezerva","riskovat","riziko","robotika","rodokmen","rohovka","rokle","rokoko","romaneto","ropovod","ropucha","rorejs","rosol","rostlina","rotmistr","rotoped","rotunda","roubenka","roucho","roup","roura","rovina","rovnice","rozbor","rozchod","rozdat","rozeznat","rozhodce","rozinka","rozjezd","rozkaz","rozloha","rozmar","rozpad","rozruch","rozsah","roztok","rozum","rozvod","rubrika","ruchadlo","rukavice","rukopis","ryba","rybolov","rychlost","rydlo","rypadlo","rytina","ryzost","sadista","sahat","sako","samec","samizdat","samota","sanitka","sardinka","sasanka","satelit","sazba","sazenice","sbor","schovat","sebranka","secese","sedadlo","sediment","sedlo","sehnat","sejmout","sekera","sekta","sekunda","sekvoje","semeno","seno","servis","sesadit","seshora","seskok","seslat","sestra","sesuv","sesypat","setba","setina","setkat","setnout","setrvat","sever","seznam","shoda","shrnout","sifon","silnice","sirka","sirotek","sirup","situace","skafandr","skalisko","skanzen","skaut","skeptik","skica","skladba","sklenice","sklo","skluz","skoba","skokan","skoro","skripta","skrz","skupina","skvost","skvrna","slabika","sladidlo","slanina","slast","slavnost","sledovat","slepec","sleva","slezina","slib","slina","sliznice","slon","sloupek","slovo","sluch","sluha","slunce","slupka","slza","smaragd","smetana","smilstvo","smlouva","smog","smrad","smrk","smrtka","smutek","smysl","snad","snaha","snob","sobota","socha","sodovka","sokol","sopka","sotva","souboj","soucit","soudce","souhlas","soulad","soumrak","souprava","soused","soutok","souviset","spalovna","spasitel","spis","splav","spodek","spojenec","spolu","sponzor","spornost","spousta","sprcha","spustit","sranda","sraz","srdce","srna","srnec","srovnat","srpen","srst","srub","stanice","starosta","statika","stavba","stehno","stezka","stodola","stolek","stopa","storno","stoupat","strach","stres","strhnout","strom","struna","studna","stupnice","stvol","styk","subjekt","subtropy","suchar","sudost","sukno","sundat","sunout","surikata","surovina","svah","svalstvo","svetr","svatba","svazek","svisle","svitek","svoboda","svodidlo","svorka","svrab","sykavka","sykot","synek","synovec","sypat","sypkost","syrovost","sysel","sytost","tabletka","tabule","tahoun","tajemno","tajfun","tajga","tajit","tajnost","taktika","tamhle","tampon","tancovat","tanec","tanker","tapeta","tavenina","tazatel","technika","tehdy","tekutina","telefon","temnota","tendence","tenista","tenor","teplota","tepna","teprve","terapie","termoska","textil","ticho","tiskopis","titulek","tkadlec","tkanina","tlapka","tleskat","tlukot","tlupa","tmel","toaleta","topinka","topol","torzo","touha","toulec","tradice","traktor","tramp","trasa","traverza","trefit","trest","trezor","trhavina","trhlina","trochu","trojice","troska","trouba","trpce","trpitel","trpkost","trubec","truchlit","truhlice","trus","trvat","tudy","tuhnout","tuhost","tundra","turista","turnaj","tuzemsko","tvaroh","tvorba","tvrdost","tvrz","tygr","tykev","ubohost","uboze","ubrat","ubrousek","ubrus","ubytovna","ucho","uctivost","udivit","uhradit","ujednat","ujistit","ujmout","ukazatel","uklidnit","uklonit","ukotvit","ukrojit","ulice","ulita","ulovit","umyvadlo","unavit","uniforma","uniknout","upadnout","uplatnit","uplynout","upoutat","upravit","uran","urazit","usednout","usilovat","usmrtit","usnadnit","usnout","usoudit","ustlat","ustrnout","utahovat","utkat","utlumit","utonout","utopenec","utrousit","uvalit","uvolnit","uvozovka","uzdravit","uzel","uzenina","uzlina","uznat","vagon","valcha","valoun","vana","vandal","vanilka","varan","varhany","varovat","vcelku","vchod","vdova","vedro","vegetace","vejce","velbloud","veletrh","velitel","velmoc","velryba","venkov","veranda","verze","veselka","veskrze","vesnice","vespodu","vesta","veterina","veverka","vibrace","vichr","videohra","vidina","vidle","vila","vinice","viset","vitalita","vize","vizitka","vjezd","vklad","vkus","vlajka","vlak","vlasec","vlevo","vlhkost","vliv","vlnovka","vloupat","vnucovat","vnuk","voda","vodivost","vodoznak","vodstvo","vojensky","vojna","vojsko","volant","volba","volit","volno","voskovka","vozidlo","vozovna","vpravo","vrabec","vracet","vrah","vrata","vrba","vrcholek","vrhat","vrstva","vrtule","vsadit","vstoupit","vstup","vtip","vybavit","vybrat","vychovat","vydat","vydra","vyfotit","vyhledat","vyhnout","vyhodit","vyhradit","vyhubit","vyjasnit","vyjet","vyjmout","vyklopit","vykonat","vylekat","vymazat","vymezit","vymizet","vymyslet","vynechat","vynikat","vynutit","vypadat","vyplatit","vypravit","vypustit","vyrazit","vyrovnat","vyrvat","vyslovit","vysoko","vystavit","vysunout","vysypat","vytasit","vytesat","vytratit","vyvinout","vyvolat","vyvrhel","vyzdobit","vyznat","vzadu","vzbudit","vzchopit","vzdor","vzduch","vzdychat","vzestup","vzhledem","vzkaz","vzlykat","vznik","vzorek","vzpoura","vztah","vztek","xylofon","zabrat","zabydlet","zachovat","zadarmo","zadusit","zafoukat","zahltit","zahodit","zahrada","zahynout","zajatec","zajet","zajistit","zaklepat","zakoupit","zalepit","zamezit","zamotat","zamyslet","zanechat","zanikat","zaplatit","zapojit","zapsat","zarazit","zastavit","zasunout","zatajit","zatemnit","zatknout","zaujmout","zavalit","zavelet","zavinit","zavolat","zavrtat","zazvonit","zbavit","zbrusu","zbudovat","zbytek","zdaleka","zdarma","zdatnost","zdivo","zdobit","zdroj","zdvih","zdymadlo","zelenina","zeman","zemina","zeptat","zezadu","zezdola","zhatit","zhltnout","zhluboka","zhotovit","zhruba","zima","zimnice","zjemnit","zklamat","zkoumat","zkratka","zkumavka","zlato","zlehka","zloba","zlom","zlost","zlozvyk","zmapovat","zmar","zmatek","zmije","zmizet","zmocnit","zmodrat","zmrzlina","zmutovat","znak","znalost","znamenat","znovu","zobrazit","zotavit","zoubek","zoufale","zplodit","zpomalit","zprava","zprostit","zprudka","zprvu","zrada","zranit","zrcadlo","zrnitost","zrno","zrovna","zrychlit","zrzavost","zticha","ztratit","zubovina","zubr","zvednout","zvenku","zvesela","zvon","zvrat","zvukovod","zvyk"]'),a_=JSON.parse('["的","一","是","在","不","了","有","和","人","这","中","大","为","上","个","国","我","以","要","他","时","来","用","们","生","到","作","地","于","出","就","分","对","成","会","可","主","发","年","动","同","工","也","能","下","过","子","说","产","种","面","而","方","后","多","定","行","学","法","所","民","得","经","十","三","之","进","着","等","部","度","家","电","力","里","如","水","化","高","自","二","理","起","小","物","现","实","加","量","都","两","体","制","机","当","使","点","从","业","本","去","把","性","好","应","开","它","合","还","因","由","其","些","然","前","外","天","政","四","日","那","社","义","事","平","形","相","全","表","间","样","与","关","各","重","新","线","内","数","正","心","反","你","明","看","原","又","么","利","比","或","但","质","气","第","向","道","命","此","变","条","只","没","结","解","问","意","建","月","公","无","系","军","很","情","者","最","立","代","想","已","通","并","提","直","题","党","程","展","五","果","料","象","员","革","位","入","常","文","总","次","品","式","活","设","及","管","特","件","长","求","老","头","基","资","边","流","路","级","少","图","山","统","接","知","较","将","组","见","计","别","她","手","角","期","根","论","运","农","指","几","九","区","强","放","决","西","被","干","做","必","战","先","回","则","任","取","据","处","队","南","给","色","光","门","即","保","治","北","造","百","规","热","领","七","海","口","东","导","器","压","志","世","金","增","争","济","阶","油","思","术","极","交","受","联","什","认","六","共","权","收","证","改","清","美","再","采","转","更","单","风","切","打","白","教","速","花","带","安","场","身","车","例","真","务","具","万","每","目","至","达","走","积","示","议","声","报","斗","完","类","八","离","华","名","确","才","科","张","信","马","节","话","米","整","空","元","况","今","集","温","传","土","许","步","群","广","石","记","需","段","研","界","拉","林","律","叫","且","究","观","越","织","装","影","算","低","持","音","众","书","布","复","容","儿","须","际","商","非","验","连","断","深","难","近","矿","千","周","委","素","技","备","半","办","青","省","列","习","响","约","支","般","史","感","劳","便","团","往","酸","历","市","克","何","除","消","构","府","称","太","准","精","值","号","率","族","维","划","选","标","写","存","候","毛","亲","快","效","斯","院","查","江","型","眼","王","按","格","养","易","置","派","层","片","始","却","专","状","育","厂","京","识","适","属","圆","包","火","住","调","满","县","局","照","参","红","细","引","听","该","铁","价","严","首","底","液","官","德","随","病","苏","失","尔","死","讲","配","女","黄","推","显","谈","罪","神","艺","呢","席","含","企","望","密","批","营","项","防","举","球","英","氧","势","告","李","台","落","木","帮","轮","破","亚","师","围","注","远","字","材","排","供","河","态","封","另","施","减","树","溶","怎","止","案","言","士","均","武","固","叶","鱼","波","视","仅","费","紧","爱","左","章","早","朝","害","续","轻","服","试","食","充","兵","源","判","护","司","足","某","练","差","致","板","田","降","黑","犯","负","击","范","继","兴","似","余","坚","曲","输","修","故","城","夫","够","送","笔","船","占","右","财","吃","富","春","职","觉","汉","画","功","巴","跟","虽","杂","飞","检","吸","助","升","阳","互","初","创","抗","考","投","坏","策","古","径","换","未","跑","留","钢","曾","端","责","站","简","述","钱","副","尽","帝","射","草","冲","承","独","令","限","阿","宣","环","双","请","超","微","让","控","州","良","轴","找","否","纪","益","依","优","顶","础","载","倒","房","突","坐","粉","敌","略","客","袁","冷","胜","绝","析","块","剂","测","丝","协","诉","念","陈","仍","罗","盐","友","洋","错","苦","夜","刑","移","频","逐","靠","混","母","短","皮","终","聚","汽","村","云","哪","既","距","卫","停","烈","央","察","烧","迅","境","若","印","洲","刻","括","激","孔","搞","甚","室","待","核","校","散","侵","吧","甲","游","久","菜","味","旧","模","湖","货","损","预","阻","毫","普","稳","乙","妈","植","息","扩","银","语","挥","酒","守","拿","序","纸","医","缺","雨","吗","针","刘","啊","急","唱","误","训","愿","审","附","获","茶","鲜","粮","斤","孩","脱","硫","肥","善","龙","演","父","渐","血","欢","械","掌","歌","沙","刚","攻","谓","盾","讨","晚","粒","乱","燃","矛","乎","杀","药","宁","鲁","贵","钟","煤","读","班","伯","香","介","迫","句","丰","培","握","兰","担","弦","蛋","沉","假","穿","执","答","乐","谁","顺","烟","缩","征","脸","喜","松","脚","困","异","免","背","星","福","买","染","井","概","慢","怕","磁","倍","祖","皇","促","静","补","评","翻","肉","践","尼","衣","宽","扬","棉","希","伤","操","垂","秋","宜","氢","套","督","振","架","亮","末","宪","庆","编","牛","触","映","雷","销","诗","座","居","抓","裂","胞","呼","娘","景","威","绿","晶","厚","盟","衡","鸡","孙","延","危","胶","屋","乡","临","陆","顾","掉","呀","灯","岁","措","束","耐","剧","玉","赵","跳","哥","季","课","凯","胡","额","款","绍","卷","齐","伟","蒸","殖","永","宗","苗","川","炉","岩","弱","零","杨","奏","沿","露","杆","探","滑","镇","饭","浓","航","怀","赶","库","夺","伊","灵","税","途","灭","赛","归","召","鼓","播","盘","裁","险","康","唯","录","菌","纯","借","糖","盖","横","符","私","努","堂","域","枪","润","幅","哈","竟","熟","虫","泽","脑","壤","碳","欧","遍","侧","寨","敢","彻","虑","斜","薄","庭","纳","弹","饲","伸","折","麦","湿","暗","荷","瓦","塞","床","筑","恶","户","访","塔","奇","透","梁","刀","旋","迹","卡","氯","遇","份","毒","泥","退","洗","摆","灰","彩","卖","耗","夏","择","忙","铜","献","硬","予","繁","圈","雪","函","亦","抽","篇","阵","阴","丁","尺","追","堆","雄","迎","泛","爸","楼","避","谋","吨","野","猪","旗","累","偏","典","馆","索","秦","脂","潮","爷","豆","忽","托","惊","塑","遗","愈","朱","替","纤","粗","倾","尚","痛","楚","谢","奋","购","磨","君","池","旁","碎","骨","监","捕","弟","暴","割","贯","殊","释","词","亡","壁","顿","宝","午","尘","闻","揭","炮","残","冬","桥","妇","警","综","招","吴","付","浮","遭","徐","您","摇","谷","赞","箱","隔","订","男","吹","园","纷","唐","败","宋","玻","巨","耕","坦","荣","闭","湾","键","凡","驻","锅","救","恩","剥","凝","碱","齿","截","炼","麻","纺","禁","废","盛","版","缓","净","睛","昌","婚","涉","筒","嘴","插","岸","朗","庄","街","藏","姑","贸","腐","奴","啦","惯","乘","伙","恢","匀","纱","扎","辩","耳","彪","臣","亿","璃","抵","脉","秀","萨","俄","网","舞","店","喷","纵","寸","汗","挂","洪","贺","闪","柬","爆","烯","津","稻","墙","软","勇","像","滚","厘","蒙","芳","肯","坡","柱","荡","腿","仪","旅","尾","轧","冰","贡","登","黎","削","钻","勒","逃","障","氨","郭","峰","币","港","伏","轨","亩","毕","擦","莫","刺","浪","秘","援","株","健","售","股","岛","甘","泡","睡","童","铸","汤","阀","休","汇","舍","牧","绕","炸","哲","磷","绩","朋","淡","尖","启","陷","柴","呈","徒","颜","泪","稍","忘","泵","蓝","拖","洞","授","镜","辛","壮","锋","贫","虚","弯","摩","泰","幼","廷","尊","窗","纲","弄","隶","疑","氏","宫","姐","震","瑞","怪","尤","琴","循","描","膜","违","夹","腰","缘","珠","穷","森","枝","竹","沟","催","绳","忆","邦","剩","幸","浆","栏","拥","牙","贮","礼","滤","钠","纹","罢","拍","咱","喊","袖","埃","勤","罚","焦","潜","伍","墨","欲","缝","姓","刊","饱","仿","奖","铝","鬼","丽","跨","默","挖","链","扫","喝","袋","炭","污","幕","诸","弧","励","梅","奶","洁","灾","舟","鉴","苯","讼","抱","毁","懂","寒","智","埔","寄","届","跃","渡","挑","丹","艰","贝","碰","拔","爹","戴","码","梦","芽","熔","赤","渔","哭","敬","颗","奔","铅","仲","虎","稀","妹","乏","珍","申","桌","遵","允","隆","螺","仓","魏","锐","晓","氮","兼","隐","碍","赫","拨","忠","肃","缸","牵","抢","博","巧","壳","兄","杜","讯","诚","碧","祥","柯","页","巡","矩","悲","灌","龄","伦","票","寻","桂","铺","圣","恐","恰","郑","趣","抬","荒","腾","贴","柔","滴","猛","阔","辆","妻","填","撤","储","签","闹","扰","紫","砂","递","戏","吊","陶","伐","喂","疗","瓶","婆","抚","臂","摸","忍","虾","蜡","邻","胸","巩","挤","偶","弃","槽","劲","乳","邓","吉","仁","烂","砖","租","乌","舰","伴","瓜","浅","丙","暂","燥","橡","柳","迷","暖","牌","秧","胆","详","簧","踏","瓷","谱","呆","宾","糊","洛","辉","愤","竞","隙","怒","粘","乃","绪","肩","籍","敏","涂","熙","皆","侦","悬","掘","享","纠","醒","狂","锁","淀","恨","牲","霸","爬","赏","逆","玩","陵","祝","秒","浙","貌","役","彼","悉","鸭","趋","凤","晨","畜","辈","秩","卵","署","梯","炎","滩","棋","驱","筛","峡","冒","啥","寿","译","浸","泉","帽","迟","硅","疆","贷","漏","稿","冠","嫩","胁","芯","牢","叛","蚀","奥","鸣","岭","羊","凭","串","塘","绘","酵","融","盆","锡","庙","筹","冻","辅","摄","袭","筋","拒","僚","旱","钾","鸟","漆","沈","眉","疏","添","棒","穗","硝","韩","逼","扭","侨","凉","挺","碗","栽","炒","杯","患","馏","劝","豪","辽","勃","鸿","旦","吏","拜","狗","埋","辊","掩","饮","搬","骂","辞","勾","扣","估","蒋","绒","雾","丈","朵","姆","拟","宇","辑","陕","雕","偿","蓄","崇","剪","倡","厅","咬","驶","薯","刷","斥","番","赋","奉","佛","浇","漫","曼","扇","钙","桃","扶","仔","返","俗","亏","腔","鞋","棱","覆","框","悄","叔","撞","骗","勘","旺","沸","孤","吐","孟","渠","屈","疾","妙","惜","仰","狠","胀","谐","抛","霉","桑","岗","嘛","衰","盗","渗","脏","赖","涌","甜","曹","阅","肌","哩","厉","烃","纬","毅","昨","伪","症","煮","叹","钉","搭","茎","笼","酷","偷","弓","锥","恒","杰","坑","鼻","翼","纶","叙","狱","逮","罐","络","棚","抑","膨","蔬","寺","骤","穆","冶","枯","册","尸","凸","绅","坯","牺","焰","轰","欣","晋","瘦","御","锭","锦","丧","旬","锻","垄","搜","扑","邀","亭","酯","迈","舒","脆","酶","闲","忧","酚","顽","羽","涨","卸","仗","陪","辟","惩","杭","姚","肚","捉","飘","漂","昆","欺","吾","郎","烷","汁","呵","饰","萧","雅","邮","迁","燕","撒","姻","赴","宴","烦","债","帐","斑","铃","旨","醇","董","饼","雏","姿","拌","傅","腹","妥","揉","贤","拆","歪","葡","胺","丢","浩","徽","昂","垫","挡","览","贪","慰","缴","汪","慌","冯","诺","姜","谊","凶","劣","诬","耀","昏","躺","盈","骑","乔","溪","丛","卢","抹","闷","咨","刮","驾","缆","悟","摘","铒","掷","颇","幻","柄","惠","惨","佳","仇","腊","窝","涤","剑","瞧","堡","泼","葱","罩","霍","捞","胎","苍","滨","俩","捅","湘","砍","霞","邵","萄","疯","淮","遂","熊","粪","烘","宿","档","戈","驳","嫂","裕","徙","箭","捐","肠","撑","晒","辨","殿","莲","摊","搅","酱","屏","疫","哀","蔡","堵","沫","皱","畅","叠","阁","莱","敲","辖","钩","痕","坝","巷","饿","祸","丘","玄","溜","曰","逻","彭","尝","卿","妨","艇","吞","韦","怨","矮","歇"]'),u_=JSON.parse('["的","一","是","在","不","了","有","和","人","這","中","大","為","上","個","國","我","以","要","他","時","來","用","們","生","到","作","地","於","出","就","分","對","成","會","可","主","發","年","動","同","工","也","能","下","過","子","說","產","種","面","而","方","後","多","定","行","學","法","所","民","得","經","十","三","之","進","著","等","部","度","家","電","力","裡","如","水","化","高","自","二","理","起","小","物","現","實","加","量","都","兩","體","制","機","當","使","點","從","業","本","去","把","性","好","應","開","它","合","還","因","由","其","些","然","前","外","天","政","四","日","那","社","義","事","平","形","相","全","表","間","樣","與","關","各","重","新","線","內","數","正","心","反","你","明","看","原","又","麼","利","比","或","但","質","氣","第","向","道","命","此","變","條","只","沒","結","解","問","意","建","月","公","無","系","軍","很","情","者","最","立","代","想","已","通","並","提","直","題","黨","程","展","五","果","料","象","員","革","位","入","常","文","總","次","品","式","活","設","及","管","特","件","長","求","老","頭","基","資","邊","流","路","級","少","圖","山","統","接","知","較","將","組","見","計","別","她","手","角","期","根","論","運","農","指","幾","九","區","強","放","決","西","被","幹","做","必","戰","先","回","則","任","取","據","處","隊","南","給","色","光","門","即","保","治","北","造","百","規","熱","領","七","海","口","東","導","器","壓","志","世","金","增","爭","濟","階","油","思","術","極","交","受","聯","什","認","六","共","權","收","證","改","清","美","再","採","轉","更","單","風","切","打","白","教","速","花","帶","安","場","身","車","例","真","務","具","萬","每","目","至","達","走","積","示","議","聲","報","鬥","完","類","八","離","華","名","確","才","科","張","信","馬","節","話","米","整","空","元","況","今","集","溫","傳","土","許","步","群","廣","石","記","需","段","研","界","拉","林","律","叫","且","究","觀","越","織","裝","影","算","低","持","音","眾","書","布","复","容","兒","須","際","商","非","驗","連","斷","深","難","近","礦","千","週","委","素","技","備","半","辦","青","省","列","習","響","約","支","般","史","感","勞","便","團","往","酸","歷","市","克","何","除","消","構","府","稱","太","準","精","值","號","率","族","維","劃","選","標","寫","存","候","毛","親","快","效","斯","院","查","江","型","眼","王","按","格","養","易","置","派","層","片","始","卻","專","狀","育","廠","京","識","適","屬","圓","包","火","住","調","滿","縣","局","照","參","紅","細","引","聽","該","鐵","價","嚴","首","底","液","官","德","隨","病","蘇","失","爾","死","講","配","女","黃","推","顯","談","罪","神","藝","呢","席","含","企","望","密","批","營","項","防","舉","球","英","氧","勢","告","李","台","落","木","幫","輪","破","亞","師","圍","注","遠","字","材","排","供","河","態","封","另","施","減","樹","溶","怎","止","案","言","士","均","武","固","葉","魚","波","視","僅","費","緊","愛","左","章","早","朝","害","續","輕","服","試","食","充","兵","源","判","護","司","足","某","練","差","致","板","田","降","黑","犯","負","擊","范","繼","興","似","餘","堅","曲","輸","修","故","城","夫","夠","送","筆","船","佔","右","財","吃","富","春","職","覺","漢","畫","功","巴","跟","雖","雜","飛","檢","吸","助","昇","陽","互","初","創","抗","考","投","壞","策","古","徑","換","未","跑","留","鋼","曾","端","責","站","簡","述","錢","副","盡","帝","射","草","衝","承","獨","令","限","阿","宣","環","雙","請","超","微","讓","控","州","良","軸","找","否","紀","益","依","優","頂","礎","載","倒","房","突","坐","粉","敵","略","客","袁","冷","勝","絕","析","塊","劑","測","絲","協","訴","念","陳","仍","羅","鹽","友","洋","錯","苦","夜","刑","移","頻","逐","靠","混","母","短","皮","終","聚","汽","村","雲","哪","既","距","衛","停","烈","央","察","燒","迅","境","若","印","洲","刻","括","激","孔","搞","甚","室","待","核","校","散","侵","吧","甲","遊","久","菜","味","舊","模","湖","貨","損","預","阻","毫","普","穩","乙","媽","植","息","擴","銀","語","揮","酒","守","拿","序","紙","醫","缺","雨","嗎","針","劉","啊","急","唱","誤","訓","願","審","附","獲","茶","鮮","糧","斤","孩","脫","硫","肥","善","龍","演","父","漸","血","歡","械","掌","歌","沙","剛","攻","謂","盾","討","晚","粒","亂","燃","矛","乎","殺","藥","寧","魯","貴","鐘","煤","讀","班","伯","香","介","迫","句","豐","培","握","蘭","擔","弦","蛋","沉","假","穿","執","答","樂","誰","順","煙","縮","徵","臉","喜","松","腳","困","異","免","背","星","福","買","染","井","概","慢","怕","磁","倍","祖","皇","促","靜","補","評","翻","肉","踐","尼","衣","寬","揚","棉","希","傷","操","垂","秋","宜","氫","套","督","振","架","亮","末","憲","慶","編","牛","觸","映","雷","銷","詩","座","居","抓","裂","胞","呼","娘","景","威","綠","晶","厚","盟","衡","雞","孫","延","危","膠","屋","鄉","臨","陸","顧","掉","呀","燈","歲","措","束","耐","劇","玉","趙","跳","哥","季","課","凱","胡","額","款","紹","卷","齊","偉","蒸","殖","永","宗","苗","川","爐","岩","弱","零","楊","奏","沿","露","桿","探","滑","鎮","飯","濃","航","懷","趕","庫","奪","伊","靈","稅","途","滅","賽","歸","召","鼓","播","盤","裁","險","康","唯","錄","菌","純","借","糖","蓋","橫","符","私","努","堂","域","槍","潤","幅","哈","竟","熟","蟲","澤","腦","壤","碳","歐","遍","側","寨","敢","徹","慮","斜","薄","庭","納","彈","飼","伸","折","麥","濕","暗","荷","瓦","塞","床","築","惡","戶","訪","塔","奇","透","梁","刀","旋","跡","卡","氯","遇","份","毒","泥","退","洗","擺","灰","彩","賣","耗","夏","擇","忙","銅","獻","硬","予","繁","圈","雪","函","亦","抽","篇","陣","陰","丁","尺","追","堆","雄","迎","泛","爸","樓","避","謀","噸","野","豬","旗","累","偏","典","館","索","秦","脂","潮","爺","豆","忽","托","驚","塑","遺","愈","朱","替","纖","粗","傾","尚","痛","楚","謝","奮","購","磨","君","池","旁","碎","骨","監","捕","弟","暴","割","貫","殊","釋","詞","亡","壁","頓","寶","午","塵","聞","揭","炮","殘","冬","橋","婦","警","綜","招","吳","付","浮","遭","徐","您","搖","谷","贊","箱","隔","訂","男","吹","園","紛","唐","敗","宋","玻","巨","耕","坦","榮","閉","灣","鍵","凡","駐","鍋","救","恩","剝","凝","鹼","齒","截","煉","麻","紡","禁","廢","盛","版","緩","淨","睛","昌","婚","涉","筒","嘴","插","岸","朗","莊","街","藏","姑","貿","腐","奴","啦","慣","乘","夥","恢","勻","紗","扎","辯","耳","彪","臣","億","璃","抵","脈","秀","薩","俄","網","舞","店","噴","縱","寸","汗","掛","洪","賀","閃","柬","爆","烯","津","稻","牆","軟","勇","像","滾","厘","蒙","芳","肯","坡","柱","盪","腿","儀","旅","尾","軋","冰","貢","登","黎","削","鑽","勒","逃","障","氨","郭","峰","幣","港","伏","軌","畝","畢","擦","莫","刺","浪","秘","援","株","健","售","股","島","甘","泡","睡","童","鑄","湯","閥","休","匯","舍","牧","繞","炸","哲","磷","績","朋","淡","尖","啟","陷","柴","呈","徒","顏","淚","稍","忘","泵","藍","拖","洞","授","鏡","辛","壯","鋒","貧","虛","彎","摩","泰","幼","廷","尊","窗","綱","弄","隸","疑","氏","宮","姐","震","瑞","怪","尤","琴","循","描","膜","違","夾","腰","緣","珠","窮","森","枝","竹","溝","催","繩","憶","邦","剩","幸","漿","欄","擁","牙","貯","禮","濾","鈉","紋","罷","拍","咱","喊","袖","埃","勤","罰","焦","潛","伍","墨","欲","縫","姓","刊","飽","仿","獎","鋁","鬼","麗","跨","默","挖","鏈","掃","喝","袋","炭","污","幕","諸","弧","勵","梅","奶","潔","災","舟","鑑","苯","訟","抱","毀","懂","寒","智","埔","寄","屆","躍","渡","挑","丹","艱","貝","碰","拔","爹","戴","碼","夢","芽","熔","赤","漁","哭","敬","顆","奔","鉛","仲","虎","稀","妹","乏","珍","申","桌","遵","允","隆","螺","倉","魏","銳","曉","氮","兼","隱","礙","赫","撥","忠","肅","缸","牽","搶","博","巧","殼","兄","杜","訊","誠","碧","祥","柯","頁","巡","矩","悲","灌","齡","倫","票","尋","桂","鋪","聖","恐","恰","鄭","趣","抬","荒","騰","貼","柔","滴","猛","闊","輛","妻","填","撤","儲","簽","鬧","擾","紫","砂","遞","戲","吊","陶","伐","餵","療","瓶","婆","撫","臂","摸","忍","蝦","蠟","鄰","胸","鞏","擠","偶","棄","槽","勁","乳","鄧","吉","仁","爛","磚","租","烏","艦","伴","瓜","淺","丙","暫","燥","橡","柳","迷","暖","牌","秧","膽","詳","簧","踏","瓷","譜","呆","賓","糊","洛","輝","憤","競","隙","怒","粘","乃","緒","肩","籍","敏","塗","熙","皆","偵","懸","掘","享","糾","醒","狂","鎖","淀","恨","牲","霸","爬","賞","逆","玩","陵","祝","秒","浙","貌","役","彼","悉","鴨","趨","鳳","晨","畜","輩","秩","卵","署","梯","炎","灘","棋","驅","篩","峽","冒","啥","壽","譯","浸","泉","帽","遲","矽","疆","貸","漏","稿","冠","嫩","脅","芯","牢","叛","蝕","奧","鳴","嶺","羊","憑","串","塘","繪","酵","融","盆","錫","廟","籌","凍","輔","攝","襲","筋","拒","僚","旱","鉀","鳥","漆","沈","眉","疏","添","棒","穗","硝","韓","逼","扭","僑","涼","挺","碗","栽","炒","杯","患","餾","勸","豪","遼","勃","鴻","旦","吏","拜","狗","埋","輥","掩","飲","搬","罵","辭","勾","扣","估","蔣","絨","霧","丈","朵","姆","擬","宇","輯","陝","雕","償","蓄","崇","剪","倡","廳","咬","駛","薯","刷","斥","番","賦","奉","佛","澆","漫","曼","扇","鈣","桃","扶","仔","返","俗","虧","腔","鞋","棱","覆","框","悄","叔","撞","騙","勘","旺","沸","孤","吐","孟","渠","屈","疾","妙","惜","仰","狠","脹","諧","拋","黴","桑","崗","嘛","衰","盜","滲","臟","賴","湧","甜","曹","閱","肌","哩","厲","烴","緯","毅","昨","偽","症","煮","嘆","釘","搭","莖","籠","酷","偷","弓","錐","恆","傑","坑","鼻","翼","綸","敘","獄","逮","罐","絡","棚","抑","膨","蔬","寺","驟","穆","冶","枯","冊","屍","凸","紳","坯","犧","焰","轟","欣","晉","瘦","禦","錠","錦","喪","旬","鍛","壟","搜","撲","邀","亭","酯","邁","舒","脆","酶","閒","憂","酚","頑","羽","漲","卸","仗","陪","闢","懲","杭","姚","肚","捉","飄","漂","昆","欺","吾","郎","烷","汁","呵","飾","蕭","雅","郵","遷","燕","撒","姻","赴","宴","煩","債","帳","斑","鈴","旨","醇","董","餅","雛","姿","拌","傅","腹","妥","揉","賢","拆","歪","葡","胺","丟","浩","徽","昂","墊","擋","覽","貪","慰","繳","汪","慌","馮","諾","姜","誼","兇","劣","誣","耀","昏","躺","盈","騎","喬","溪","叢","盧","抹","悶","諮","刮","駕","纜","悟","摘","鉺","擲","頗","幻","柄","惠","慘","佳","仇","臘","窩","滌","劍","瞧","堡","潑","蔥","罩","霍","撈","胎","蒼","濱","倆","捅","湘","砍","霞","邵","萄","瘋","淮","遂","熊","糞","烘","宿","檔","戈","駁","嫂","裕","徙","箭","捐","腸","撐","曬","辨","殿","蓮","攤","攪","醬","屏","疫","哀","蔡","堵","沫","皺","暢","疊","閣","萊","敲","轄","鉤","痕","壩","巷","餓","禍","丘","玄","溜","曰","邏","彭","嘗","卿","妨","艇","吞","韋","怨","矮","歇"]'),c_=JSON.parse('["가격","가끔","가난","가능","가득","가르침","가뭄","가방","가상","가슴","가운데","가을","가이드","가입","가장","가정","가족","가죽","각오","각자","간격","간부","간섭","간장","간접","간판","갈등","갈비","갈색","갈증","감각","감기","감소","감수성","감자","감정","갑자기","강남","강당","강도","강력히","강변","강북","강사","강수량","강아지","강원도","강의","강제","강조","같이","개구리","개나리","개방","개별","개선","개성","개인","객관적","거실","거액","거울","거짓","거품","걱정","건강","건물","건설","건조","건축","걸음","검사","검토","게시판","게임","겨울","견해","결과","결국","결론","결석","결승","결심","결정","결혼","경계","경고","경기","경력","경복궁","경비","경상도","경영","경우","경쟁","경제","경주","경찰","경치","경향","경험","계곡","계단","계란","계산","계속","계약","계절","계층","계획","고객","고구려","고궁","고급","고등학생","고무신","고민","고양이","고장","고전","고집","고춧가루","고통","고향","곡식","골목","골짜기","골프","공간","공개","공격","공군","공급","공기","공동","공무원","공부","공사","공식","공업","공연","공원","공장","공짜","공책","공통","공포","공항","공휴일","과목","과일","과장","과정","과학","관객","관계","관광","관념","관람","관련","관리","관습","관심","관점","관찰","광경","광고","광장","광주","괴로움","굉장히","교과서","교문","교복","교실","교양","교육","교장","교직","교통","교환","교훈","구경","구름","구멍","구별","구분","구석","구성","구속","구역","구입","구청","구체적","국가","국기","국내","국립","국물","국민","국수","국어","국왕","국적","국제","국회","군대","군사","군인","궁극적","권리","권위","권투","귀국","귀신","규정","규칙","균형","그날","그냥","그늘","그러나","그룹","그릇","그림","그제서야","그토록","극복","극히","근거","근교","근래","근로","근무","근본","근원","근육","근처","글씨","글자","금강산","금고","금년","금메달","금액","금연","금요일","금지","긍정적","기간","기관","기념","기능","기독교","기둥","기록","기름","기법","기본","기분","기쁨","기숙사","기술","기억","기업","기온","기운","기원","기적","기준","기침","기혼","기획","긴급","긴장","길이","김밥","김치","김포공항","깍두기","깜빡","깨달음","깨소금","껍질","꼭대기","꽃잎","나들이","나란히","나머지","나물","나침반","나흘","낙엽","난방","날개","날씨","날짜","남녀","남대문","남매","남산","남자","남편","남학생","낭비","낱말","내년","내용","내일","냄비","냄새","냇물","냉동","냉면","냉방","냉장고","넥타이","넷째","노동","노란색","노력","노인","녹음","녹차","녹화","논리","논문","논쟁","놀이","농구","농담","농민","농부","농업","농장","농촌","높이","눈동자","눈물","눈썹","뉴욕","느낌","늑대","능동적","능력","다방","다양성","다음","다이어트","다행","단계","단골","단독","단맛","단순","단어","단위","단점","단체","단추","단편","단풍","달걀","달러","달력","달리","닭고기","담당","담배","담요","담임","답변","답장","당근","당분간","당연히","당장","대규모","대낮","대단히","대답","대도시","대략","대량","대륙","대문","대부분","대신","대응","대장","대전","대접","대중","대책","대출","대충","대통령","대학","대한민국","대합실","대형","덩어리","데이트","도대체","도덕","도둑","도망","도서관","도심","도움","도입","도자기","도저히","도전","도중","도착","독감","독립","독서","독일","독창적","동화책","뒷모습","뒷산","딸아이","마누라","마늘","마당","마라톤","마련","마무리","마사지","마약","마요네즈","마을","마음","마이크","마중","마지막","마찬가지","마찰","마흔","막걸리","막내","막상","만남","만두","만세","만약","만일","만점","만족","만화","많이","말기","말씀","말투","맘대로","망원경","매년","매달","매력","매번","매스컴","매일","매장","맥주","먹이","먼저","먼지","멀리","메일","며느리","며칠","면담","멸치","명단","명령","명예","명의","명절","명칭","명함","모금","모니터","모델","모든","모범","모습","모양","모임","모조리","모집","모퉁이","목걸이","목록","목사","목소리","목숨","목적","목표","몰래","몸매","몸무게","몸살","몸속","몸짓","몸통","몹시","무관심","무궁화","무더위","무덤","무릎","무슨","무엇","무역","무용","무조건","무지개","무척","문구","문득","문법","문서","문제","문학","문화","물가","물건","물결","물고기","물론","물리학","물음","물질","물체","미국","미디어","미사일","미술","미역","미용실","미움","미인","미팅","미혼","민간","민족","민주","믿음","밀가루","밀리미터","밑바닥","바가지","바구니","바나나","바늘","바닥","바닷가","바람","바이러스","바탕","박물관","박사","박수","반대","반드시","반말","반발","반성","반응","반장","반죽","반지","반찬","받침","발가락","발걸음","발견","발달","발레","발목","발바닥","발생","발음","발자국","발전","발톱","발표","밤하늘","밥그릇","밥맛","밥상","밥솥","방금","방면","방문","방바닥","방법","방송","방식","방안","방울","방지","방학","방해","방향","배경","배꼽","배달","배드민턴","백두산","백색","백성","백인","백제","백화점","버릇","버섯","버튼","번개","번역","번지","번호","벌금","벌레","벌써","범위","범인","범죄","법률","법원","법적","법칙","베이징","벨트","변경","변동","변명","변신","변호사","변화","별도","별명","별일","병실","병아리","병원","보관","보너스","보라색","보람","보름","보상","보안","보자기","보장","보전","보존","보통","보편적","보험","복도","복사","복숭아","복습","볶음","본격적","본래","본부","본사","본성","본인","본질","볼펜","봉사","봉지","봉투","부근","부끄러움","부담","부동산","부문","부분","부산","부상","부엌","부인","부작용","부장","부정","부족","부지런히","부친","부탁","부품","부회장","북부","북한","분노","분량","분리","분명","분석","분야","분위기","분필","분홍색","불고기","불과","불교","불꽃","불만","불법","불빛","불안","불이익","불행","브랜드","비극","비난","비닐","비둘기","비디오","비로소","비만","비명","비밀","비바람","비빔밥","비상","비용","비율","비중","비타민","비판","빌딩","빗물","빗방울","빗줄기","빛깔","빨간색","빨래","빨리","사건","사계절","사나이","사냥","사람","사랑","사립","사모님","사물","사방","사상","사생활","사설","사슴","사실","사업","사용","사월","사장","사전","사진","사촌","사춘기","사탕","사투리","사흘","산길","산부인과","산업","산책","살림","살인","살짝","삼계탕","삼국","삼십","삼월","삼촌","상관","상금","상대","상류","상반기","상상","상식","상업","상인","상자","상점","상처","상추","상태","상표","상품","상황","새벽","색깔","색연필","생각","생명","생물","생방송","생산","생선","생신","생일","생활","서랍","서른","서명","서민","서비스","서양","서울","서적","서점","서쪽","서클","석사","석유","선거","선물","선배","선생","선수","선원","선장","선전","선택","선풍기","설거지","설날","설렁탕","설명","설문","설사","설악산","설치","설탕","섭씨","성공","성당","성명","성별","성인","성장","성적","성질","성함","세금","세미나","세상","세월","세종대왕","세탁","센터","센티미터","셋째","소규모","소극적","소금","소나기","소년","소득","소망","소문","소설","소속","소아과","소용","소원","소음","소중히","소지품","소질","소풍","소형","속담","속도","속옷","손가락","손길","손녀","손님","손등","손목","손뼉","손실","손질","손톱","손해","솔직히","솜씨","송아지","송이","송편","쇠고기","쇼핑","수건","수년","수단","수돗물","수동적","수면","수명","수박","수상","수석","수술","수시로","수업","수염","수영","수입","수준","수집","수출","수컷","수필","수학","수험생","수화기","숙녀","숙소","숙제","순간","순서","순수","순식간","순위","숟가락","술병","술집","숫자","스님","스물","스스로","스승","스웨터","스위치","스케이트","스튜디오","스트레스","스포츠","슬쩍","슬픔","습관","습기","승객","승리","승부","승용차","승진","시각","시간","시골","시금치","시나리오","시댁","시리즈","시멘트","시민","시부모","시선","시설","시스템","시아버지","시어머니","시월","시인","시일","시작","시장","시절","시점","시중","시즌","시집","시청","시합","시험","식구","식기","식당","식량","식료품","식물","식빵","식사","식생활","식초","식탁","식품","신고","신규","신념","신문","신발","신비","신사","신세","신용","신제품","신청","신체","신화","실감","실내","실력","실례","실망","실수","실습","실시","실장","실정","실질적","실천","실체","실컷","실태","실패","실험","실현","심리","심부름","심사","심장","심정","심판","쌍둥이","씨름","씨앗","아가씨","아나운서","아드님","아들","아쉬움","아스팔트","아시아","아울러","아저씨","아줌마","아직","아침","아파트","아프리카","아픔","아홉","아흔","악기","악몽","악수","안개","안경","안과","안내","안녕","안동","안방","안부","안주","알루미늄","알코올","암시","암컷","압력","앞날","앞문","애인","애정","액수","앨범","야간","야단","야옹","약간","약국","약속","약수","약점","약품","약혼녀","양념","양력","양말","양배추","양주","양파","어둠","어려움","어른","어젯밤","어쨌든","어쩌다가","어쩐지","언니","언덕","언론","언어","얼굴","얼른","얼음","얼핏","엄마","업무","업종","업체","엉덩이","엉망","엉터리","엊그제","에너지","에어컨","엔진","여건","여고생","여관","여군","여권","여대생","여덟","여동생","여든","여론","여름","여섯","여성","여왕","여인","여전히","여직원","여학생","여행","역사","역시","역할","연결","연구","연극","연기","연락","연설","연세","연속","연습","연애","연예인","연인","연장","연주","연출","연필","연합","연휴","열기","열매","열쇠","열심히","열정","열차","열흘","염려","엽서","영국","영남","영상","영양","영역","영웅","영원히","영하","영향","영혼","영화","옆구리","옆방","옆집","예감","예금","예방","예산","예상","예선","예술","예습","예식장","예약","예전","예절","예정","예컨대","옛날","오늘","오락","오랫동안","오렌지","오로지","오른발","오븐","오십","오염","오월","오전","오직","오징어","오페라","오피스텔","오히려","옥상","옥수수","온갖","온라인","온몸","온종일","온통","올가을","올림픽","올해","옷차림","와이셔츠","와인","완성","완전","왕비","왕자","왜냐하면","왠지","외갓집","외국","외로움","외삼촌","외출","외침","외할머니","왼발","왼손","왼쪽","요금","요일","요즘","요청","용기","용서","용어","우산","우선","우승","우연히","우정","우체국","우편","운동","운명","운반","운전","운행","울산","울음","움직임","웃어른","웃음","워낙","원고","원래","원서","원숭이","원인","원장","원피스","월급","월드컵","월세","월요일","웨이터","위반","위법","위성","위원","위험","위협","윗사람","유난히","유럽","유명","유물","유산","유적","유치원","유학","유행","유형","육군","육상","육십","육체","은행","음력","음료","음반","음성","음식","음악","음주","의견","의논","의문","의복","의식","의심","의외로","의욕","의원","의학","이것","이곳","이념","이놈","이달","이대로","이동","이렇게","이력서","이론적","이름","이민","이발소","이별","이불","이빨","이상","이성","이슬","이야기","이용","이웃","이월","이윽고","이익","이전","이중","이튿날","이틀","이혼","인간","인격","인공","인구","인근","인기","인도","인류","인물","인생","인쇄","인연","인원","인재","인종","인천","인체","인터넷","인하","인형","일곱","일기","일단","일대","일등","일반","일본","일부","일상","일생","일손","일요일","일월","일정","일종","일주일","일찍","일체","일치","일행","일회용","임금","임무","입대","입력","입맛","입사","입술","입시","입원","입장","입학","자가용","자격","자극","자동","자랑","자부심","자식","자신","자연","자원","자율","자전거","자정","자존심","자판","작가","작년","작성","작업","작용","작은딸","작품","잔디","잔뜩","잔치","잘못","잠깐","잠수함","잠시","잠옷","잠자리","잡지","장관","장군","장기간","장래","장례","장르","장마","장면","장모","장미","장비","장사","장소","장식","장애인","장인","장점","장차","장학금","재능","재빨리","재산","재생","재작년","재정","재채기","재판","재학","재활용","저것","저고리","저곳","저녁","저런","저렇게","저번","저울","저절로","저축","적극","적당히","적성","적용","적응","전개","전공","전기","전달","전라도","전망","전문","전반","전부","전세","전시","전용","전자","전쟁","전주","전철","전체","전통","전혀","전후","절대","절망","절반","절약","절차","점검","점수","점심","점원","점점","점차","접근","접시","접촉","젓가락","정거장","정도","정류장","정리","정말","정면","정문","정반대","정보","정부","정비","정상","정성","정오","정원","정장","정지","정치","정확히","제공","제과점","제대로","제목","제발","제법","제삿날","제안","제일","제작","제주도","제출","제품","제한","조각","조건","조금","조깅","조명","조미료","조상","조선","조용히","조절","조정","조직","존댓말","존재","졸업","졸음","종교","종로","종류","종소리","종업원","종종","종합","좌석","죄인","주관적","주름","주말","주머니","주먹","주문","주민","주방","주변","주식","주인","주일","주장","주전자","주택","준비","줄거리","줄기","줄무늬","중간","중계방송","중국","중년","중단","중독","중반","중부","중세","중소기업","중순","중앙","중요","중학교","즉석","즉시","즐거움","증가","증거","증권","증상","증세","지각","지갑","지경","지극히","지금","지급","지능","지름길","지리산","지방","지붕","지식","지역","지우개","지원","지적","지점","지진","지출","직선","직업","직원","직장","진급","진동","진로","진료","진리","진짜","진찰","진출","진통","진행","질문","질병","질서","짐작","집단","집안","집중","짜증","찌꺼기","차남","차라리","차량","차림","차별","차선","차츰","착각","찬물","찬성","참가","참기름","참새","참석","참여","참외","참조","찻잔","창가","창고","창구","창문","창밖","창작","창조","채널","채점","책가방","책방","책상","책임","챔피언","처벌","처음","천국","천둥","천장","천재","천천히","철도","철저히","철학","첫날","첫째","청년","청바지","청소","청춘","체계","체력","체온","체육","체중","체험","초등학생","초반","초밥","초상화","초순","초여름","초원","초저녁","초점","초청","초콜릿","촛불","총각","총리","총장","촬영","최근","최상","최선","최신","최악","최종","추석","추억","추진","추천","추측","축구","축소","축제","축하","출근","출발","출산","출신","출연","출입","출장","출판","충격","충고","충돌","충분히","충청도","취업","취직","취향","치약","친구","친척","칠십","칠월","칠판","침대","침묵","침실","칫솔","칭찬","카메라","카운터","칼국수","캐릭터","캠퍼스","캠페인","커튼","컨디션","컬러","컴퓨터","코끼리","코미디","콘서트","콜라","콤플렉스","콩나물","쾌감","쿠데타","크림","큰길","큰딸","큰소리","큰아들","큰어머니","큰일","큰절","클래식","클럽","킬로","타입","타자기","탁구","탁자","탄생","태권도","태양","태풍","택시","탤런트","터널","터미널","테니스","테스트","테이블","텔레비전","토론","토마토","토요일","통계","통과","통로","통신","통역","통일","통장","통제","통증","통합","통화","퇴근","퇴원","퇴직금","튀김","트럭","특급","특별","특성","특수","특징","특히","튼튼히","티셔츠","파란색","파일","파출소","판결","판단","판매","판사","팔십","팔월","팝송","패션","팩스","팩시밀리","팬티","퍼센트","페인트","편견","편의","편지","편히","평가","평균","평생","평소","평양","평일","평화","포스터","포인트","포장","포함","표면","표정","표준","표현","품목","품질","풍경","풍속","풍습","프랑스","프린터","플라스틱","피곤","피망","피아노","필름","필수","필요","필자","필통","핑계","하느님","하늘","하드웨어","하룻밤","하반기","하숙집","하순","하여튼","하지만","하천","하품","하필","학과","학교","학급","학기","학년","학력","학번","학부모","학비","학생","학술","학습","학용품","학원","학위","학자","학점","한계","한글","한꺼번에","한낮","한눈","한동안","한때","한라산","한마디","한문","한번","한복","한식","한여름","한쪽","할머니","할아버지","할인","함께","함부로","합격","합리적","항공","항구","항상","항의","해결","해군","해답","해당","해물","해석","해설","해수욕장","해안","핵심","핸드백","햄버거","햇볕","햇살","행동","행복","행사","행운","행위","향기","향상","향수","허락","허용","헬기","현관","현금","현대","현상","현실","현장","현재","현지","혈액","협력","형부","형사","형수","형식","형제","형태","형편","혜택","호기심","호남","호랑이","호박","호텔","호흡","혹시","홀로","홈페이지","홍보","홍수","홍차","화면","화분","화살","화요일","화장","화학","확보","확인","확장","확정","환갑","환경","환영","환율","환자","활기","활동","활발히","활용","활짝","회견","회관","회복","회색","회원","회장","회전","횟수","횡단보도","효율적","후반","후춧가루","훈련","훨씬","휴식","휴일","흉내","흐름","흑백","흑인","흔적","흔히","흥미","흥분","희곡","희망","희생","흰색","힘껏"]'),f_=JSON.parse('["abaisser","abandon","abdiquer","abeille","abolir","aborder","aboutir","aboyer","abrasif","abreuver","abriter","abroger","abrupt","absence","absolu","absurde","abusif","abyssal","académie","acajou","acarien","accabler","accepter","acclamer","accolade","accroche","accuser","acerbe","achat","acheter","aciduler","acier","acompte","acquérir","acronyme","acteur","actif","actuel","adepte","adéquat","adhésif","adjectif","adjuger","admettre","admirer","adopter","adorer","adoucir","adresse","adroit","adulte","adverbe","aérer","aéronef","affaire","affecter","affiche","affreux","affubler","agacer","agencer","agile","agiter","agrafer","agréable","agrume","aider","aiguille","ailier","aimable","aisance","ajouter","ajuster","alarmer","alchimie","alerte","algèbre","algue","aliéner","aliment","alléger","alliage","allouer","allumer","alourdir","alpaga","altesse","alvéole","amateur","ambigu","ambre","aménager","amertume","amidon","amiral","amorcer","amour","amovible","amphibie","ampleur","amusant","analyse","anaphore","anarchie","anatomie","ancien","anéantir","angle","angoisse","anguleux","animal","annexer","annonce","annuel","anodin","anomalie","anonyme","anormal","antenne","antidote","anxieux","apaiser","apéritif","aplanir","apologie","appareil","appeler","apporter","appuyer","aquarium","aqueduc","arbitre","arbuste","ardeur","ardoise","argent","arlequin","armature","armement","armoire","armure","arpenter","arracher","arriver","arroser","arsenic","artériel","article","aspect","asphalte","aspirer","assaut","asservir","assiette","associer","assurer","asticot","astre","astuce","atelier","atome","atrium","atroce","attaque","attentif","attirer","attraper","aubaine","auberge","audace","audible","augurer","aurore","automne","autruche","avaler","avancer","avarice","avenir","averse","aveugle","aviateur","avide","avion","aviser","avoine","avouer","avril","axial","axiome","badge","bafouer","bagage","baguette","baignade","balancer","balcon","baleine","balisage","bambin","bancaire","bandage","banlieue","bannière","banquier","barbier","baril","baron","barque","barrage","bassin","bastion","bataille","bateau","batterie","baudrier","bavarder","belette","bélier","belote","bénéfice","berceau","berger","berline","bermuda","besace","besogne","bétail","beurre","biberon","bicycle","bidule","bijou","bilan","bilingue","billard","binaire","biologie","biopsie","biotype","biscuit","bison","bistouri","bitume","bizarre","blafard","blague","blanchir","blessant","blinder","blond","bloquer","blouson","bobard","bobine","boire","boiser","bolide","bonbon","bondir","bonheur","bonifier","bonus","bordure","borne","botte","boucle","boueux","bougie","boulon","bouquin","bourse","boussole","boutique","boxeur","branche","brasier","brave","brebis","brèche","breuvage","bricoler","brigade","brillant","brioche","brique","brochure","broder","bronzer","brousse","broyeur","brume","brusque","brutal","bruyant","buffle","buisson","bulletin","bureau","burin","bustier","butiner","butoir","buvable","buvette","cabanon","cabine","cachette","cadeau","cadre","caféine","caillou","caisson","calculer","calepin","calibre","calmer","calomnie","calvaire","camarade","caméra","camion","campagne","canal","caneton","canon","cantine","canular","capable","caporal","caprice","capsule","capter","capuche","carabine","carbone","caresser","caribou","carnage","carotte","carreau","carton","cascade","casier","casque","cassure","causer","caution","cavalier","caverne","caviar","cédille","ceinture","céleste","cellule","cendrier","censurer","central","cercle","cérébral","cerise","cerner","cerveau","cesser","chagrin","chaise","chaleur","chambre","chance","chapitre","charbon","chasseur","chaton","chausson","chavirer","chemise","chenille","chéquier","chercher","cheval","chien","chiffre","chignon","chimère","chiot","chlorure","chocolat","choisir","chose","chouette","chrome","chute","cigare","cigogne","cimenter","cinéma","cintrer","circuler","cirer","cirque","citerne","citoyen","citron","civil","clairon","clameur","claquer","classe","clavier","client","cligner","climat","clivage","cloche","clonage","cloporte","cobalt","cobra","cocasse","cocotier","coder","codifier","coffre","cogner","cohésion","coiffer","coincer","colère","colibri","colline","colmater","colonel","combat","comédie","commande","compact","concert","conduire","confier","congeler","connoter","consonne","contact","convexe","copain","copie","corail","corbeau","cordage","corniche","corpus","correct","cortège","cosmique","costume","coton","coude","coupure","courage","couteau","couvrir","coyote","crabe","crainte","cravate","crayon","créature","créditer","crémeux","creuser","crevette","cribler","crier","cristal","critère","croire","croquer","crotale","crucial","cruel","crypter","cubique","cueillir","cuillère","cuisine","cuivre","culminer","cultiver","cumuler","cupide","curatif","curseur","cyanure","cycle","cylindre","cynique","daigner","damier","danger","danseur","dauphin","débattre","débiter","déborder","débrider","débutant","décaler","décembre","déchirer","décider","déclarer","décorer","décrire","décupler","dédale","déductif","déesse","défensif","défiler","défrayer","dégager","dégivrer","déglutir","dégrafer","déjeuner","délice","déloger","demander","demeurer","démolir","dénicher","dénouer","dentelle","dénuder","départ","dépenser","déphaser","déplacer","déposer","déranger","dérober","désastre","descente","désert","désigner","désobéir","dessiner","destrier","détacher","détester","détourer","détresse","devancer","devenir","deviner","devoir","diable","dialogue","diamant","dicter","différer","digérer","digital","digne","diluer","dimanche","diminuer","dioxyde","directif","diriger","discuter","disposer","dissiper","distance","divertir","diviser","docile","docteur","dogme","doigt","domaine","domicile","dompter","donateur","donjon","donner","dopamine","dortoir","dorure","dosage","doseur","dossier","dotation","douanier","double","douceur","douter","doyen","dragon","draper","dresser","dribbler","droiture","duperie","duplexe","durable","durcir","dynastie","éblouir","écarter","écharpe","échelle","éclairer","éclipse","éclore","écluse","école","économie","écorce","écouter","écraser","écrémer","écrivain","écrou","écume","écureuil","édifier","éduquer","effacer","effectif","effigie","effort","effrayer","effusion","égaliser","égarer","éjecter","élaborer","élargir","électron","élégant","éléphant","élève","éligible","élitisme","éloge","élucider","éluder","emballer","embellir","embryon","émeraude","émission","emmener","émotion","émouvoir","empereur","employer","emporter","emprise","émulsion","encadrer","enchère","enclave","encoche","endiguer","endosser","endroit","enduire","énergie","enfance","enfermer","enfouir","engager","engin","englober","énigme","enjamber","enjeu","enlever","ennemi","ennuyeux","enrichir","enrobage","enseigne","entasser","entendre","entier","entourer","entraver","énumérer","envahir","enviable","envoyer","enzyme","éolien","épaissir","épargne","épatant","épaule","épicerie","épidémie","épier","épilogue","épine","épisode","épitaphe","époque","épreuve","éprouver","épuisant","équerre","équipe","ériger","érosion","erreur","éruption","escalier","espadon","espèce","espiègle","espoir","esprit","esquiver","essayer","essence","essieu","essorer","estime","estomac","estrade","étagère","étaler","étanche","étatique","éteindre","étendoir","éternel","éthanol","éthique","ethnie","étirer","étoffer","étoile","étonnant","étourdir","étrange","étroit","étude","euphorie","évaluer","évasion","éventail","évidence","éviter","évolutif","évoquer","exact","exagérer","exaucer","exceller","excitant","exclusif","excuse","exécuter","exemple","exercer","exhaler","exhorter","exigence","exiler","exister","exotique","expédier","explorer","exposer","exprimer","exquis","extensif","extraire","exulter","fable","fabuleux","facette","facile","facture","faiblir","falaise","fameux","famille","farceur","farfelu","farine","farouche","fasciner","fatal","fatigue","faucon","fautif","faveur","favori","fébrile","féconder","fédérer","félin","femme","fémur","fendoir","féodal","fermer","féroce","ferveur","festival","feuille","feutre","février","fiasco","ficeler","fictif","fidèle","figure","filature","filetage","filière","filleul","filmer","filou","filtrer","financer","finir","fiole","firme","fissure","fixer","flairer","flamme","flasque","flatteur","fléau","flèche","fleur","flexion","flocon","flore","fluctuer","fluide","fluvial","folie","fonderie","fongible","fontaine","forcer","forgeron","formuler","fortune","fossile","foudre","fougère","fouiller","foulure","fourmi","fragile","fraise","franchir","frapper","frayeur","frégate","freiner","frelon","frémir","frénésie","frère","friable","friction","frisson","frivole","froid","fromage","frontal","frotter","fruit","fugitif","fuite","fureur","furieux","furtif","fusion","futur","gagner","galaxie","galerie","gambader","garantir","gardien","garnir","garrigue","gazelle","gazon","géant","gélatine","gélule","gendarme","général","génie","genou","gentil","géologie","géomètre","géranium","germe","gestuel","geyser","gibier","gicler","girafe","givre","glace","glaive","glisser","globe","gloire","glorieux","golfeur","gomme","gonfler","gorge","gorille","goudron","gouffre","goulot","goupille","gourmand","goutte","graduel","graffiti","graine","grand","grappin","gratuit","gravir","grenat","griffure","griller","grimper","grogner","gronder","grotte","groupe","gruger","grutier","gruyère","guépard","guerrier","guide","guimauve","guitare","gustatif","gymnaste","gyrostat","habitude","hachoir","halte","hameau","hangar","hanneton","haricot","harmonie","harpon","hasard","hélium","hématome","herbe","hérisson","hermine","héron","hésiter","heureux","hiberner","hibou","hilarant","histoire","hiver","homard","hommage","homogène","honneur","honorer","honteux","horde","horizon","horloge","hormone","horrible","houleux","housse","hublot","huileux","humain","humble","humide","humour","hurler","hydromel","hygiène","hymne","hypnose","idylle","ignorer","iguane","illicite","illusion","image","imbiber","imiter","immense","immobile","immuable","impact","impérial","implorer","imposer","imprimer","imputer","incarner","incendie","incident","incliner","incolore","indexer","indice","inductif","inédit","ineptie","inexact","infini","infliger","informer","infusion","ingérer","inhaler","inhiber","injecter","injure","innocent","inoculer","inonder","inscrire","insecte","insigne","insolite","inspirer","instinct","insulter","intact","intense","intime","intrigue","intuitif","inutile","invasion","inventer","inviter","invoquer","ironique","irradier","irréel","irriter","isoler","ivoire","ivresse","jaguar","jaillir","jambe","janvier","jardin","jauger","jaune","javelot","jetable","jeton","jeudi","jeunesse","joindre","joncher","jongler","joueur","jouissif","journal","jovial","joyau","joyeux","jubiler","jugement","junior","jupon","juriste","justice","juteux","juvénile","kayak","kimono","kiosque","label","labial","labourer","lacérer","lactose","lagune","laine","laisser","laitier","lambeau","lamelle","lampe","lanceur","langage","lanterne","lapin","largeur","larme","laurier","lavabo","lavoir","lecture","légal","léger","légume","lessive","lettre","levier","lexique","lézard","liasse","libérer","libre","licence","licorne","liège","lièvre","ligature","ligoter","ligue","limer","limite","limonade","limpide","linéaire","lingot","lionceau","liquide","lisière","lister","lithium","litige","littoral","livreur","logique","lointain","loisir","lombric","loterie","louer","lourd","loutre","louve","loyal","lubie","lucide","lucratif","lueur","lugubre","luisant","lumière","lunaire","lundi","luron","lutter","luxueux","machine","magasin","magenta","magique","maigre","maillon","maintien","mairie","maison","majorer","malaxer","maléfice","malheur","malice","mallette","mammouth","mandater","maniable","manquant","manteau","manuel","marathon","marbre","marchand","mardi","maritime","marqueur","marron","marteler","mascotte","massif","matériel","matière","matraque","maudire","maussade","mauve","maximal","méchant","méconnu","médaille","médecin","méditer","méduse","meilleur","mélange","mélodie","membre","mémoire","menacer","mener","menhir","mensonge","mentor","mercredi","mérite","merle","messager","mesure","métal","météore","méthode","métier","meuble","miauler","microbe","miette","mignon","migrer","milieu","million","mimique","mince","minéral","minimal","minorer","minute","miracle","miroiter","missile","mixte","mobile","moderne","moelleux","mondial","moniteur","monnaie","monotone","monstre","montagne","monument","moqueur","morceau","morsure","mortier","moteur","motif","mouche","moufle","moulin","mousson","mouton","mouvant","multiple","munition","muraille","murène","murmure","muscle","muséum","musicien","mutation","muter","mutuel","myriade","myrtille","mystère","mythique","nageur","nappe","narquois","narrer","natation","nation","nature","naufrage","nautique","navire","nébuleux","nectar","néfaste","négation","négliger","négocier","neige","nerveux","nettoyer","neurone","neutron","neveu","niche","nickel","nitrate","niveau","noble","nocif","nocturne","noirceur","noisette","nomade","nombreux","nommer","normatif","notable","notifier","notoire","nourrir","nouveau","novateur","novembre","novice","nuage","nuancer","nuire","nuisible","numéro","nuptial","nuque","nutritif","obéir","objectif","obliger","obscur","observer","obstacle","obtenir","obturer","occasion","occuper","océan","octobre","octroyer","octupler","oculaire","odeur","odorant","offenser","officier","offrir","ogive","oiseau","oisillon","olfactif","olivier","ombrage","omettre","onctueux","onduler","onéreux","onirique","opale","opaque","opérer","opinion","opportun","opprimer","opter","optique","orageux","orange","orbite","ordonner","oreille","organe","orgueil","orifice","ornement","orque","ortie","osciller","osmose","ossature","otarie","ouragan","ourson","outil","outrager","ouvrage","ovation","oxyde","oxygène","ozone","paisible","palace","palmarès","palourde","palper","panache","panda","pangolin","paniquer","panneau","panorama","pantalon","papaye","papier","papoter","papyrus","paradoxe","parcelle","paresse","parfumer","parler","parole","parrain","parsemer","partager","parure","parvenir","passion","pastèque","paternel","patience","patron","pavillon","pavoiser","payer","paysage","peigne","peintre","pelage","pélican","pelle","pelouse","peluche","pendule","pénétrer","pénible","pensif","pénurie","pépite","péplum","perdrix","perforer","période","permuter","perplexe","persil","perte","peser","pétale","petit","pétrir","peuple","pharaon","phobie","phoque","photon","phrase","physique","piano","pictural","pièce","pierre","pieuvre","pilote","pinceau","pipette","piquer","pirogue","piscine","piston","pivoter","pixel","pizza","placard","plafond","plaisir","planer","plaque","plastron","plateau","pleurer","plexus","pliage","plomb","plonger","pluie","plumage","pochette","poésie","poète","pointe","poirier","poisson","poivre","polaire","policier","pollen","polygone","pommade","pompier","ponctuel","pondérer","poney","portique","position","posséder","posture","potager","poteau","potion","pouce","poulain","poumon","pourpre","poussin","pouvoir","prairie","pratique","précieux","prédire","préfixe","prélude","prénom","présence","prétexte","prévoir","primitif","prince","prison","priver","problème","procéder","prodige","profond","progrès","proie","projeter","prologue","promener","propre","prospère","protéger","prouesse","proverbe","prudence","pruneau","psychose","public","puceron","puiser","pulpe","pulsar","punaise","punitif","pupitre","purifier","puzzle","pyramide","quasar","querelle","question","quiétude","quitter","quotient","racine","raconter","radieux","ragondin","raideur","raisin","ralentir","rallonge","ramasser","rapide","rasage","ratisser","ravager","ravin","rayonner","réactif","réagir","réaliser","réanimer","recevoir","réciter","réclamer","récolter","recruter","reculer","recycler","rédiger","redouter","refaire","réflexe","réformer","refrain","refuge","régalien","région","réglage","régulier","réitérer","rejeter","rejouer","relatif","relever","relief","remarque","remède","remise","remonter","remplir","remuer","renard","renfort","renifler","renoncer","rentrer","renvoi","replier","reporter","reprise","reptile","requin","réserve","résineux","résoudre","respect","rester","résultat","rétablir","retenir","réticule","retomber","retracer","réunion","réussir","revanche","revivre","révolte","révulsif","richesse","rideau","rieur","rigide","rigoler","rincer","riposter","risible","risque","rituel","rival","rivière","rocheux","romance","rompre","ronce","rondin","roseau","rosier","rotatif","rotor","rotule","rouge","rouille","rouleau","routine","royaume","ruban","rubis","ruche","ruelle","rugueux","ruiner","ruisseau","ruser","rustique","rythme","sabler","saboter","sabre","sacoche","safari","sagesse","saisir","salade","salive","salon","saluer","samedi","sanction","sanglier","sarcasme","sardine","saturer","saugrenu","saumon","sauter","sauvage","savant","savonner","scalpel","scandale","scélérat","scénario","sceptre","schéma","science","scinder","score","scrutin","sculpter","séance","sécable","sécher","secouer","sécréter","sédatif","séduire","seigneur","séjour","sélectif","semaine","sembler","semence","séminal","sénateur","sensible","sentence","séparer","séquence","serein","sergent","sérieux","serrure","sérum","service","sésame","sévir","sevrage","sextuple","sidéral","siècle","siéger","siffler","sigle","signal","silence","silicium","simple","sincère","sinistre","siphon","sirop","sismique","situer","skier","social","socle","sodium","soigneux","soldat","soleil","solitude","soluble","sombre","sommeil","somnoler","sonde","songeur","sonnette","sonore","sorcier","sortir","sosie","sottise","soucieux","soudure","souffle","soulever","soupape","source","soutirer","souvenir","spacieux","spatial","spécial","sphère","spiral","stable","station","sternum","stimulus","stipuler","strict","studieux","stupeur","styliste","sublime","substrat","subtil","subvenir","succès","sucre","suffixe","suggérer","suiveur","sulfate","superbe","supplier","surface","suricate","surmener","surprise","sursaut","survie","suspect","syllabe","symbole","symétrie","synapse","syntaxe","système","tabac","tablier","tactile","tailler","talent","talisman","talonner","tambour","tamiser","tangible","tapis","taquiner","tarder","tarif","tartine","tasse","tatami","tatouage","taupe","taureau","taxer","témoin","temporel","tenaille","tendre","teneur","tenir","tension","terminer","terne","terrible","tétine","texte","thème","théorie","thérapie","thorax","tibia","tiède","timide","tirelire","tiroir","tissu","titane","titre","tituber","toboggan","tolérant","tomate","tonique","tonneau","toponyme","torche","tordre","tornade","torpille","torrent","torse","tortue","totem","toucher","tournage","tousser","toxine","traction","trafic","tragique","trahir","train","trancher","travail","trèfle","tremper","trésor","treuil","triage","tribunal","tricoter","trilogie","triomphe","tripler","triturer","trivial","trombone","tronc","tropical","troupeau","tuile","tulipe","tumulte","tunnel","turbine","tuteur","tutoyer","tuyau","tympan","typhon","typique","tyran","ubuesque","ultime","ultrason","unanime","unifier","union","unique","unitaire","univers","uranium","urbain","urticant","usage","usine","usuel","usure","utile","utopie","vacarme","vaccin","vagabond","vague","vaillant","vaincre","vaisseau","valable","valise","vallon","valve","vampire","vanille","vapeur","varier","vaseux","vassal","vaste","vecteur","vedette","végétal","véhicule","veinard","véloce","vendredi","vénérer","venger","venimeux","ventouse","verdure","vérin","vernir","verrou","verser","vertu","veston","vétéran","vétuste","vexant","vexer","viaduc","viande","victoire","vidange","vidéo","vignette","vigueur","vilain","village","vinaigre","violon","vipère","virement","virtuose","virus","visage","viseur","vision","visqueux","visuel","vital","vitesse","viticole","vitrine","vivace","vivipare","vocation","voguer","voile","voisin","voiture","volaille","volcan","voltiger","volume","vorace","vortex","voter","vouloir","voyage","voyelle","wagon","xénon","yacht","zèbre","zénith","zeste","zoologie"]'),l_=JSON.parse('["abaco","abbaglio","abbinato","abete","abisso","abolire","abrasivo","abrogato","accadere","accenno","accusato","acetone","achille","acido","acqua","acre","acrilico","acrobata","acuto","adagio","addebito","addome","adeguato","aderire","adipe","adottare","adulare","affabile","affetto","affisso","affranto","aforisma","afoso","africano","agave","agente","agevole","aggancio","agire","agitare","agonismo","agricolo","agrumeto","aguzzo","alabarda","alato","albatro","alberato","albo","albume","alce","alcolico","alettone","alfa","algebra","aliante","alibi","alimento","allagato","allegro","allievo","allodola","allusivo","almeno","alogeno","alpaca","alpestre","altalena","alterno","alticcio","altrove","alunno","alveolo","alzare","amalgama","amanita","amarena","ambito","ambrato","ameba","america","ametista","amico","ammasso","ammenda","ammirare","ammonito","amore","ampio","ampliare","amuleto","anacardo","anagrafe","analista","anarchia","anatra","anca","ancella","ancora","andare","andrea","anello","angelo","angolare","angusto","anima","annegare","annidato","anno","annuncio","anonimo","anticipo","anzi","apatico","apertura","apode","apparire","appetito","appoggio","approdo","appunto","aprile","arabica","arachide","aragosta","araldica","arancio","aratura","arazzo","arbitro","archivio","ardito","arenile","argento","argine","arguto","aria","armonia","arnese","arredato","arringa","arrosto","arsenico","arso","artefice","arzillo","asciutto","ascolto","asepsi","asettico","asfalto","asino","asola","aspirato","aspro","assaggio","asse","assoluto","assurdo","asta","astenuto","astice","astratto","atavico","ateismo","atomico","atono","attesa","attivare","attorno","attrito","attuale","ausilio","austria","autista","autonomo","autunno","avanzato","avere","avvenire","avviso","avvolgere","azione","azoto","azzimo","azzurro","babele","baccano","bacino","baco","badessa","badilata","bagnato","baita","balcone","baldo","balena","ballata","balzano","bambino","bandire","baraonda","barbaro","barca","baritono","barlume","barocco","basilico","basso","batosta","battuto","baule","bava","bavosa","becco","beffa","belgio","belva","benda","benevole","benigno","benzina","bere","berlina","beta","bibita","bici","bidone","bifido","biga","bilancia","bimbo","binocolo","biologo","bipede","bipolare","birbante","birra","biscotto","bisesto","bisnonno","bisonte","bisturi","bizzarro","blando","blatta","bollito","bonifico","bordo","bosco","botanico","bottino","bozzolo","braccio","bradipo","brama","branca","bravura","bretella","brevetto","brezza","briglia","brillante","brindare","broccolo","brodo","bronzina","brullo","bruno","bubbone","buca","budino","buffone","buio","bulbo","buono","burlone","burrasca","bussola","busta","cadetto","caduco","calamaro","calcolo","calesse","calibro","calmo","caloria","cambusa","camerata","camicia","cammino","camola","campale","canapa","candela","cane","canino","canotto","cantina","capace","capello","capitolo","capogiro","cappero","capra","capsula","carapace","carcassa","cardo","carisma","carovana","carretto","cartolina","casaccio","cascata","caserma","caso","cassone","castello","casuale","catasta","catena","catrame","cauto","cavillo","cedibile","cedrata","cefalo","celebre","cellulare","cena","cenone","centesimo","ceramica","cercare","certo","cerume","cervello","cesoia","cespo","ceto","chela","chiaro","chicca","chiedere","chimera","china","chirurgo","chitarra","ciao","ciclismo","cifrare","cigno","cilindro","ciottolo","circa","cirrosi","citrico","cittadino","ciuffo","civetta","civile","classico","clinica","cloro","cocco","codardo","codice","coerente","cognome","collare","colmato","colore","colposo","coltivato","colza","coma","cometa","commando","comodo","computer","comune","conciso","condurre","conferma","congelare","coniuge","connesso","conoscere","consumo","continuo","convegno","coperto","copione","coppia","copricapo","corazza","cordata","coricato","cornice","corolla","corpo","corredo","corsia","cortese","cosmico","costante","cottura","covato","cratere","cravatta","creato","credere","cremoso","crescita","creta","criceto","crinale","crisi","critico","croce","cronaca","crostata","cruciale","crusca","cucire","cuculo","cugino","cullato","cupola","curatore","cursore","curvo","cuscino","custode","dado","daino","dalmata","damerino","daniela","dannoso","danzare","datato","davanti","davvero","debutto","decennio","deciso","declino","decollo","decreto","dedicato","definito","deforme","degno","delegare","delfino","delirio","delta","demenza","denotato","dentro","deposito","derapata","derivare","deroga","descritto","deserto","desiderio","desumere","detersivo","devoto","diametro","dicembre","diedro","difeso","diffuso","digerire","digitale","diluvio","dinamico","dinnanzi","dipinto","diploma","dipolo","diradare","dire","dirotto","dirupo","disagio","discreto","disfare","disgelo","disposto","distanza","disumano","dito","divano","divelto","dividere","divorato","doblone","docente","doganale","dogma","dolce","domato","domenica","dominare","dondolo","dono","dormire","dote","dottore","dovuto","dozzina","drago","druido","dubbio","dubitare","ducale","duna","duomo","duplice","duraturo","ebano","eccesso","ecco","eclissi","economia","edera","edicola","edile","editoria","educare","egemonia","egli","egoismo","egregio","elaborato","elargire","elegante","elencato","eletto","elevare","elfico","elica","elmo","elsa","eluso","emanato","emblema","emesso","emiro","emotivo","emozione","empirico","emulo","endemico","enduro","energia","enfasi","enoteca","entrare","enzima","epatite","epilogo","episodio","epocale","eppure","equatore","erario","erba","erboso","erede","eremita","erigere","ermetico","eroe","erosivo","errante","esagono","esame","esanime","esaudire","esca","esempio","esercito","esibito","esigente","esistere","esito","esofago","esortato","esoso","espanso","espresso","essenza","esso","esteso","estimare","estonia","estroso","esultare","etilico","etnico","etrusco","etto","euclideo","europa","evaso","evidenza","evitato","evoluto","evviva","fabbrica","faccenda","fachiro","falco","famiglia","fanale","fanfara","fango","fantasma","fare","farfalla","farinoso","farmaco","fascia","fastoso","fasullo","faticare","fato","favoloso","febbre","fecola","fede","fegato","felpa","feltro","femmina","fendere","fenomeno","fermento","ferro","fertile","fessura","festivo","fetta","feudo","fiaba","fiducia","fifa","figurato","filo","finanza","finestra","finire","fiore","fiscale","fisico","fiume","flacone","flamenco","flebo","flemma","florido","fluente","fluoro","fobico","focaccia","focoso","foderato","foglio","folata","folclore","folgore","fondente","fonetico","fonia","fontana","forbito","forchetta","foresta","formica","fornaio","foro","fortezza","forzare","fosfato","fosso","fracasso","frana","frassino","fratello","freccetta","frenata","fresco","frigo","frollino","fronde","frugale","frutta","fucilata","fucsia","fuggente","fulmine","fulvo","fumante","fumetto","fumoso","fune","funzione","fuoco","furbo","furgone","furore","fuso","futile","gabbiano","gaffe","galateo","gallina","galoppo","gambero","gamma","garanzia","garbo","garofano","garzone","gasdotto","gasolio","gastrico","gatto","gaudio","gazebo","gazzella","geco","gelatina","gelso","gemello","gemmato","gene","genitore","gennaio","genotipo","gergo","ghepardo","ghiaccio","ghisa","giallo","gilda","ginepro","giocare","gioiello","giorno","giove","girato","girone","gittata","giudizio","giurato","giusto","globulo","glutine","gnomo","gobba","golf","gomito","gommone","gonfio","gonna","governo","gracile","grado","grafico","grammo","grande","grattare","gravoso","grazia","greca","gregge","grifone","grigio","grinza","grotta","gruppo","guadagno","guaio","guanto","guardare","gufo","guidare","ibernato","icona","identico","idillio","idolo","idra","idrico","idrogeno","igiene","ignaro","ignorato","ilare","illeso","illogico","illudere","imballo","imbevuto","imbocco","imbuto","immane","immerso","immolato","impacco","impeto","impiego","importo","impronta","inalare","inarcare","inattivo","incanto","incendio","inchino","incisivo","incluso","incontro","incrocio","incubo","indagine","india","indole","inedito","infatti","infilare","inflitto","ingaggio","ingegno","inglese","ingordo","ingrosso","innesco","inodore","inoltrare","inondato","insano","insetto","insieme","insonnia","insulina","intasato","intero","intonaco","intuito","inumidire","invalido","invece","invito","iperbole","ipnotico","ipotesi","ippica","iride","irlanda","ironico","irrigato","irrorare","isolato","isotopo","isterico","istituto","istrice","italia","iterare","labbro","labirinto","lacca","lacerato","lacrima","lacuna","laddove","lago","lampo","lancetta","lanterna","lardoso","larga","laringe","lastra","latenza","latino","lattuga","lavagna","lavoro","legale","leggero","lembo","lentezza","lenza","leone","lepre","lesivo","lessato","lesto","letterale","leva","levigato","libero","lido","lievito","lilla","limatura","limitare","limpido","lineare","lingua","liquido","lira","lirica","lisca","lite","litigio","livrea","locanda","lode","logica","lombare","londra","longevo","loquace","lorenzo","loto","lotteria","luce","lucidato","lumaca","luminoso","lungo","lupo","luppolo","lusinga","lusso","lutto","macabro","macchina","macero","macinato","madama","magico","maglia","magnete","magro","maiolica","malafede","malgrado","malinteso","malsano","malto","malumore","mana","mancia","mandorla","mangiare","manifesto","mannaro","manovra","mansarda","mantide","manubrio","mappa","maratona","marcire","maretta","marmo","marsupio","maschera","massaia","mastino","materasso","matricola","mattone","maturo","mazurca","meandro","meccanico","mecenate","medesimo","meditare","mega","melassa","melis","melodia","meninge","meno","mensola","mercurio","merenda","merlo","meschino","mese","messere","mestolo","metallo","metodo","mettere","miagolare","mica","micelio","michele","microbo","midollo","miele","migliore","milano","milite","mimosa","minerale","mini","minore","mirino","mirtillo","miscela","missiva","misto","misurare","mitezza","mitigare","mitra","mittente","mnemonico","modello","modifica","modulo","mogano","mogio","mole","molosso","monastero","monco","mondina","monetario","monile","monotono","monsone","montato","monviso","mora","mordere","morsicato","mostro","motivato","motosega","motto","movenza","movimento","mozzo","mucca","mucosa","muffa","mughetto","mugnaio","mulatto","mulinello","multiplo","mummia","munto","muovere","murale","musa","muscolo","musica","mutevole","muto","nababbo","nafta","nanometro","narciso","narice","narrato","nascere","nastrare","naturale","nautica","naviglio","nebulosa","necrosi","negativo","negozio","nemmeno","neofita","neretto","nervo","nessuno","nettuno","neutrale","neve","nevrotico","nicchia","ninfa","nitido","nobile","nocivo","nodo","nome","nomina","nordico","normale","norvegese","nostrano","notare","notizia","notturno","novella","nucleo","nulla","numero","nuovo","nutrire","nuvola","nuziale","oasi","obbedire","obbligo","obelisco","oblio","obolo","obsoleto","occasione","occhio","occidente","occorrere","occultare","ocra","oculato","odierno","odorare","offerta","offrire","offuscato","oggetto","oggi","ognuno","olandese","olfatto","oliato","oliva","ologramma","oltre","omaggio","ombelico","ombra","omega","omissione","ondoso","onere","onice","onnivoro","onorevole","onta","operato","opinione","opposto","oracolo","orafo","ordine","orecchino","orefice","orfano","organico","origine","orizzonte","orma","ormeggio","ornativo","orologio","orrendo","orribile","ortensia","ortica","orzata","orzo","osare","oscurare","osmosi","ospedale","ospite","ossa","ossidare","ostacolo","oste","otite","otre","ottagono","ottimo","ottobre","ovale","ovest","ovino","oviparo","ovocito","ovunque","ovviare","ozio","pacchetto","pace","pacifico","padella","padrone","paese","paga","pagina","palazzina","palesare","pallido","palo","palude","pandoro","pannello","paolo","paonazzo","paprica","parabola","parcella","parere","pargolo","pari","parlato","parola","partire","parvenza","parziale","passivo","pasticca","patacca","patologia","pattume","pavone","peccato","pedalare","pedonale","peggio","peloso","penare","pendice","penisola","pennuto","penombra","pensare","pentola","pepe","pepita","perbene","percorso","perdonato","perforare","pergamena","periodo","permesso","perno","perplesso","persuaso","pertugio","pervaso","pesatore","pesista","peso","pestifero","petalo","pettine","petulante","pezzo","piacere","pianta","piattino","piccino","picozza","piega","pietra","piffero","pigiama","pigolio","pigro","pila","pilifero","pillola","pilota","pimpante","pineta","pinna","pinolo","pioggia","piombo","piramide","piretico","pirite","pirolisi","pitone","pizzico","placebo","planare","plasma","platano","plenario","pochezza","poderoso","podismo","poesia","poggiare","polenta","poligono","pollice","polmonite","polpetta","polso","poltrona","polvere","pomice","pomodoro","ponte","popoloso","porfido","poroso","porpora","porre","portata","posa","positivo","possesso","postulato","potassio","potere","pranzo","prassi","pratica","precluso","predica","prefisso","pregiato","prelievo","premere","prenotare","preparato","presenza","pretesto","prevalso","prima","principe","privato","problema","procura","produrre","profumo","progetto","prolunga","promessa","pronome","proposta","proroga","proteso","prova","prudente","prugna","prurito","psiche","pubblico","pudica","pugilato","pugno","pulce","pulito","pulsante","puntare","pupazzo","pupilla","puro","quadro","qualcosa","quasi","querela","quota","raccolto","raddoppio","radicale","radunato","raffica","ragazzo","ragione","ragno","ramarro","ramingo","ramo","randagio","rantolare","rapato","rapina","rappreso","rasatura","raschiato","rasente","rassegna","rastrello","rata","ravveduto","reale","recepire","recinto","recluta","recondito","recupero","reddito","redimere","regalato","registro","regola","regresso","relazione","remare","remoto","renna","replica","reprimere","reputare","resa","residente","responso","restauro","rete","retina","retorica","rettifica","revocato","riassunto","ribadire","ribelle","ribrezzo","ricarica","ricco","ricevere","riciclato","ricordo","ricreduto","ridicolo","ridurre","rifasare","riflesso","riforma","rifugio","rigare","rigettato","righello","rilassato","rilevato","rimanere","rimbalzo","rimedio","rimorchio","rinascita","rincaro","rinforzo","rinnovo","rinomato","rinsavito","rintocco","rinuncia","rinvenire","riparato","ripetuto","ripieno","riportare","ripresa","ripulire","risata","rischio","riserva","risibile","riso","rispetto","ristoro","risultato","risvolto","ritardo","ritegno","ritmico","ritrovo","riunione","riva","riverso","rivincita","rivolto","rizoma","roba","robotico","robusto","roccia","roco","rodaggio","rodere","roditore","rogito","rollio","romantico","rompere","ronzio","rosolare","rospo","rotante","rotondo","rotula","rovescio","rubizzo","rubrica","ruga","rullino","rumine","rumoroso","ruolo","rupe","russare","rustico","sabato","sabbiare","sabotato","sagoma","salasso","saldatura","salgemma","salivare","salmone","salone","saltare","saluto","salvo","sapere","sapido","saporito","saraceno","sarcasmo","sarto","sassoso","satellite","satira","satollo","saturno","savana","savio","saziato","sbadiglio","sbalzo","sbancato","sbarra","sbattere","sbavare","sbendare","sbirciare","sbloccato","sbocciato","sbrinare","sbruffone","sbuffare","scabroso","scadenza","scala","scambiare","scandalo","scapola","scarso","scatenare","scavato","scelto","scenico","scettro","scheda","schiena","sciarpa","scienza","scindere","scippo","sciroppo","scivolo","sclerare","scodella","scolpito","scomparto","sconforto","scoprire","scorta","scossone","scozzese","scriba","scrollare","scrutinio","scuderia","scultore","scuola","scuro","scusare","sdebitare","sdoganare","seccatura","secondo","sedano","seggiola","segnalato","segregato","seguito","selciato","selettivo","sella","selvaggio","semaforo","sembrare","seme","seminato","sempre","senso","sentire","sepolto","sequenza","serata","serbato","sereno","serio","serpente","serraglio","servire","sestina","setola","settimana","sfacelo","sfaldare","sfamato","sfarzoso","sfaticato","sfera","sfida","sfilato","sfinge","sfocato","sfoderare","sfogo","sfoltire","sforzato","sfratto","sfruttato","sfuggito","sfumare","sfuso","sgabello","sgarbato","sgonfiare","sgorbio","sgrassato","sguardo","sibilo","siccome","sierra","sigla","signore","silenzio","sillaba","simbolo","simpatico","simulato","sinfonia","singolo","sinistro","sino","sintesi","sinusoide","sipario","sisma","sistole","situato","slitta","slogatura","sloveno","smarrito","smemorato","smentito","smeraldo","smilzo","smontare","smottato","smussato","snellire","snervato","snodo","sobbalzo","sobrio","soccorso","sociale","sodale","soffitto","sogno","soldato","solenne","solido","sollazzo","solo","solubile","solvente","somatico","somma","sonda","sonetto","sonnifero","sopire","soppeso","sopra","sorgere","sorpasso","sorriso","sorso","sorteggio","sorvolato","sospiro","sosta","sottile","spada","spalla","spargere","spatola","spavento","spazzola","specie","spedire","spegnere","spelatura","speranza","spessore","spettrale","spezzato","spia","spigoloso","spillato","spinoso","spirale","splendido","sportivo","sposo","spranga","sprecare","spronato","spruzzo","spuntino","squillo","sradicare","srotolato","stabile","stacco","staffa","stagnare","stampato","stantio","starnuto","stasera","statuto","stelo","steppa","sterzo","stiletto","stima","stirpe","stivale","stizzoso","stonato","storico","strappo","stregato","stridulo","strozzare","strutto","stuccare","stufo","stupendo","subentro","succoso","sudore","suggerito","sugo","sultano","suonare","superbo","supporto","surgelato","surrogato","sussurro","sutura","svagare","svedese","sveglio","svelare","svenuto","svezia","sviluppo","svista","svizzera","svolta","svuotare","tabacco","tabulato","tacciare","taciturno","tale","talismano","tampone","tannino","tara","tardivo","targato","tariffa","tarpare","tartaruga","tasto","tattico","taverna","tavolata","tazza","teca","tecnico","telefono","temerario","tempo","temuto","tendone","tenero","tensione","tentacolo","teorema","terme","terrazzo","terzetto","tesi","tesserato","testato","tetro","tettoia","tifare","tigella","timbro","tinto","tipico","tipografo","tiraggio","tiro","titanio","titolo","titubante","tizio","tizzone","toccare","tollerare","tolto","tombola","tomo","tonfo","tonsilla","topazio","topologia","toppa","torba","tornare","torrone","tortora","toscano","tossire","tostatura","totano","trabocco","trachea","trafila","tragedia","tralcio","tramonto","transito","trapano","trarre","trasloco","trattato","trave","treccia","tremolio","trespolo","tributo","tricheco","trifoglio","trillo","trincea","trio","tristezza","triturato","trivella","tromba","trono","troppo","trottola","trovare","truccato","tubatura","tuffato","tulipano","tumulto","tunisia","turbare","turchino","tuta","tutela","ubicato","uccello","uccisore","udire","uditivo","uffa","ufficio","uguale","ulisse","ultimato","umano","umile","umorismo","uncinetto","ungere","ungherese","unicorno","unificato","unisono","unitario","unte","uovo","upupa","uragano","urgenza","urlo","usanza","usato","uscito","usignolo","usuraio","utensile","utilizzo","utopia","vacante","vaccinato","vagabondo","vagliato","valanga","valgo","valico","valletta","valoroso","valutare","valvola","vampata","vangare","vanitoso","vano","vantaggio","vanvera","vapore","varano","varcato","variante","vasca","vedetta","vedova","veduto","vegetale","veicolo","velcro","velina","velluto","veloce","venato","vendemmia","vento","verace","verbale","vergogna","verifica","vero","verruca","verticale","vescica","vessillo","vestale","veterano","vetrina","vetusto","viandante","vibrante","vicenda","vichingo","vicinanza","vidimare","vigilia","vigneto","vigore","vile","villano","vimini","vincitore","viola","vipera","virgola","virologo","virulento","viscoso","visione","vispo","vissuto","visura","vita","vitello","vittima","vivanda","vivido","viziare","voce","voga","volatile","volere","volpe","voragine","vulcano","zampogna","zanna","zappato","zattera","zavorra","zefiro","zelante","zelo","zenzero","zerbino","zibetto","zinco","zircone","zitto","zolla","zotico","zucchero","zufolo","zulu","zuppa"]'),h_=JSON.parse('["ábaco","abdomen","abeja","abierto","abogado","abono","aborto","abrazo","abrir","abuelo","abuso","acabar","academia","acceso","acción","aceite","acelga","acento","aceptar","ácido","aclarar","acné","acoger","acoso","activo","acto","actriz","actuar","acudir","acuerdo","acusar","adicto","admitir","adoptar","adorno","aduana","adulto","aéreo","afectar","afición","afinar","afirmar","ágil","agitar","agonía","agosto","agotar","agregar","agrio","agua","agudo","águila","aguja","ahogo","ahorro","aire","aislar","ajedrez","ajeno","ajuste","alacrán","alambre","alarma","alba","álbum","alcalde","aldea","alegre","alejar","alerta","aleta","alfiler","alga","algodón","aliado","aliento","alivio","alma","almeja","almíbar","altar","alteza","altivo","alto","altura","alumno","alzar","amable","amante","amapola","amargo","amasar","ámbar","ámbito","ameno","amigo","amistad","amor","amparo","amplio","ancho","anciano","ancla","andar","andén","anemia","ángulo","anillo","ánimo","anís","anotar","antena","antiguo","antojo","anual","anular","anuncio","añadir","añejo","año","apagar","aparato","apetito","apio","aplicar","apodo","aporte","apoyo","aprender","aprobar","apuesta","apuro","arado","araña","arar","árbitro","árbol","arbusto","archivo","arco","arder","ardilla","arduo","área","árido","aries","armonía","arnés","aroma","arpa","arpón","arreglo","arroz","arruga","arte","artista","asa","asado","asalto","ascenso","asegurar","aseo","asesor","asiento","asilo","asistir","asno","asombro","áspero","astilla","astro","astuto","asumir","asunto","atajo","ataque","atar","atento","ateo","ático","atleta","átomo","atraer","atroz","atún","audaz","audio","auge","aula","aumento","ausente","autor","aval","avance","avaro","ave","avellana","avena","avestruz","avión","aviso","ayer","ayuda","ayuno","azafrán","azar","azote","azúcar","azufre","azul","baba","babor","bache","bahía","baile","bajar","balanza","balcón","balde","bambú","banco","banda","baño","barba","barco","barniz","barro","báscula","bastón","basura","batalla","batería","batir","batuta","baúl","bazar","bebé","bebida","bello","besar","beso","bestia","bicho","bien","bingo","blanco","bloque","blusa","boa","bobina","bobo","boca","bocina","boda","bodega","boina","bola","bolero","bolsa","bomba","bondad","bonito","bono","bonsái","borde","borrar","bosque","bote","botín","bóveda","bozal","bravo","brazo","brecha","breve","brillo","brinco","brisa","broca","broma","bronce","brote","bruja","brusco","bruto","buceo","bucle","bueno","buey","bufanda","bufón","búho","buitre","bulto","burbuja","burla","burro","buscar","butaca","buzón","caballo","cabeza","cabina","cabra","cacao","cadáver","cadena","caer","café","caída","caimán","caja","cajón","cal","calamar","calcio","caldo","calidad","calle","calma","calor","calvo","cama","cambio","camello","camino","campo","cáncer","candil","canela","canguro","canica","canto","caña","cañón","caoba","caos","capaz","capitán","capote","captar","capucha","cara","carbón","cárcel","careta","carga","cariño","carne","carpeta","carro","carta","casa","casco","casero","caspa","castor","catorce","catre","caudal","causa","cazo","cebolla","ceder","cedro","celda","célebre","celoso","célula","cemento","ceniza","centro","cerca","cerdo","cereza","cero","cerrar","certeza","césped","cetro","chacal","chaleco","champú","chancla","chapa","charla","chico","chiste","chivo","choque","choza","chuleta","chupar","ciclón","ciego","cielo","cien","cierto","cifra","cigarro","cima","cinco","cine","cinta","ciprés","circo","ciruela","cisne","cita","ciudad","clamor","clan","claro","clase","clave","cliente","clima","clínica","cobre","cocción","cochino","cocina","coco","código","codo","cofre","coger","cohete","cojín","cojo","cola","colcha","colegio","colgar","colina","collar","colmo","columna","combate","comer","comida","cómodo","compra","conde","conejo","conga","conocer","consejo","contar","copa","copia","corazón","corbata","corcho","cordón","corona","correr","coser","cosmos","costa","cráneo","cráter","crear","crecer","creído","crema","cría","crimen","cripta","crisis","cromo","crónica","croqueta","crudo","cruz","cuadro","cuarto","cuatro","cubo","cubrir","cuchara","cuello","cuento","cuerda","cuesta","cueva","cuidar","culebra","culpa","culto","cumbre","cumplir","cuna","cuneta","cuota","cupón","cúpula","curar","curioso","curso","curva","cutis","dama","danza","dar","dardo","dátil","deber","débil","década","decir","dedo","defensa","definir","dejar","delfín","delgado","delito","demora","denso","dental","deporte","derecho","derrota","desayuno","deseo","desfile","desnudo","destino","desvío","detalle","detener","deuda","día","diablo","diadema","diamante","diana","diario","dibujo","dictar","diente","dieta","diez","difícil","digno","dilema","diluir","dinero","directo","dirigir","disco","diseño","disfraz","diva","divino","doble","doce","dolor","domingo","don","donar","dorado","dormir","dorso","dos","dosis","dragón","droga","ducha","duda","duelo","dueño","dulce","dúo","duque","durar","dureza","duro","ébano","ebrio","echar","eco","ecuador","edad","edición","edificio","editor","educar","efecto","eficaz","eje","ejemplo","elefante","elegir","elemento","elevar","elipse","élite","elixir","elogio","eludir","embudo","emitir","emoción","empate","empeño","empleo","empresa","enano","encargo","enchufe","encía","enemigo","enero","enfado","enfermo","engaño","enigma","enlace","enorme","enredo","ensayo","enseñar","entero","entrar","envase","envío","época","equipo","erizo","escala","escena","escolar","escribir","escudo","esencia","esfera","esfuerzo","espada","espejo","espía","esposa","espuma","esquí","estar","este","estilo","estufa","etapa","eterno","ética","etnia","evadir","evaluar","evento","evitar","exacto","examen","exceso","excusa","exento","exigir","exilio","existir","éxito","experto","explicar","exponer","extremo","fábrica","fábula","fachada","fácil","factor","faena","faja","falda","fallo","falso","faltar","fama","familia","famoso","faraón","farmacia","farol","farsa","fase","fatiga","fauna","favor","fax","febrero","fecha","feliz","feo","feria","feroz","fértil","fervor","festín","fiable","fianza","fiar","fibra","ficción","ficha","fideo","fiebre","fiel","fiera","fiesta","figura","fijar","fijo","fila","filete","filial","filtro","fin","finca","fingir","finito","firma","flaco","flauta","flecha","flor","flota","fluir","flujo","flúor","fobia","foca","fogata","fogón","folio","folleto","fondo","forma","forro","fortuna","forzar","fosa","foto","fracaso","frágil","franja","frase","fraude","freír","freno","fresa","frío","frito","fruta","fuego","fuente","fuerza","fuga","fumar","función","funda","furgón","furia","fusil","fútbol","futuro","gacela","gafas","gaita","gajo","gala","galería","gallo","gamba","ganar","gancho","ganga","ganso","garaje","garza","gasolina","gastar","gato","gavilán","gemelo","gemir","gen","género","genio","gente","geranio","gerente","germen","gesto","gigante","gimnasio","girar","giro","glaciar","globo","gloria","gol","golfo","goloso","golpe","goma","gordo","gorila","gorra","gota","goteo","gozar","grada","gráfico","grano","grasa","gratis","grave","grieta","grillo","gripe","gris","grito","grosor","grúa","grueso","grumo","grupo","guante","guapo","guardia","guerra","guía","guiño","guion","guiso","guitarra","gusano","gustar","haber","hábil","hablar","hacer","hacha","hada","hallar","hamaca","harina","haz","hazaña","hebilla","hebra","hecho","helado","helio","hembra","herir","hermano","héroe","hervir","hielo","hierro","hígado","higiene","hijo","himno","historia","hocico","hogar","hoguera","hoja","hombre","hongo","honor","honra","hora","hormiga","horno","hostil","hoyo","hueco","huelga","huerta","hueso","huevo","huida","huir","humano","húmedo","humilde","humo","hundir","huracán","hurto","icono","ideal","idioma","ídolo","iglesia","iglú","igual","ilegal","ilusión","imagen","imán","imitar","impar","imperio","imponer","impulso","incapaz","índice","inerte","infiel","informe","ingenio","inicio","inmenso","inmune","innato","insecto","instante","interés","íntimo","intuir","inútil","invierno","ira","iris","ironía","isla","islote","jabalí","jabón","jamón","jarabe","jardín","jarra","jaula","jazmín","jefe","jeringa","jinete","jornada","joroba","joven","joya","juerga","jueves","juez","jugador","jugo","juguete","juicio","junco","jungla","junio","juntar","júpiter","jurar","justo","juvenil","juzgar","kilo","koala","labio","lacio","lacra","lado","ladrón","lagarto","lágrima","laguna","laico","lamer","lámina","lámpara","lana","lancha","langosta","lanza","lápiz","largo","larva","lástima","lata","látex","latir","laurel","lavar","lazo","leal","lección","leche","lector","leer","legión","legumbre","lejano","lengua","lento","leña","león","leopardo","lesión","letal","letra","leve","leyenda","libertad","libro","licor","líder","lidiar","lienzo","liga","ligero","lima","límite","limón","limpio","lince","lindo","línea","lingote","lino","linterna","líquido","liso","lista","litera","litio","litro","llaga","llama","llanto","llave","llegar","llenar","llevar","llorar","llover","lluvia","lobo","loción","loco","locura","lógica","logro","lombriz","lomo","lonja","lote","lucha","lucir","lugar","lujo","luna","lunes","lupa","lustro","luto","luz","maceta","macho","madera","madre","maduro","maestro","mafia","magia","mago","maíz","maldad","maleta","malla","malo","mamá","mambo","mamut","manco","mando","manejar","manga","maniquí","manjar","mano","manso","manta","mañana","mapa","máquina","mar","marco","marea","marfil","margen","marido","mármol","marrón","martes","marzo","masa","máscara","masivo","matar","materia","matiz","matriz","máximo","mayor","mazorca","mecha","medalla","medio","médula","mejilla","mejor","melena","melón","memoria","menor","mensaje","mente","menú","mercado","merengue","mérito","mes","mesón","meta","meter","método","metro","mezcla","miedo","miel","miembro","miga","mil","milagro","militar","millón","mimo","mina","minero","mínimo","minuto","miope","mirar","misa","miseria","misil","mismo","mitad","mito","mochila","moción","moda","modelo","moho","mojar","molde","moler","molino","momento","momia","monarca","moneda","monja","monto","moño","morada","morder","moreno","morir","morro","morsa","mortal","mosca","mostrar","motivo","mover","móvil","mozo","mucho","mudar","mueble","muela","muerte","muestra","mugre","mujer","mula","muleta","multa","mundo","muñeca","mural","muro","músculo","museo","musgo","música","muslo","nácar","nación","nadar","naipe","naranja","nariz","narrar","nasal","natal","nativo","natural","náusea","naval","nave","navidad","necio","néctar","negar","negocio","negro","neón","nervio","neto","neutro","nevar","nevera","nicho","nido","niebla","nieto","niñez","niño","nítido","nivel","nobleza","noche","nómina","noria","norma","norte","nota","noticia","novato","novela","novio","nube","nuca","núcleo","nudillo","nudo","nuera","nueve","nuez","nulo","número","nutria","oasis","obeso","obispo","objeto","obra","obrero","observar","obtener","obvio","oca","ocaso","océano","ochenta","ocho","ocio","ocre","octavo","octubre","oculto","ocupar","ocurrir","odiar","odio","odisea","oeste","ofensa","oferta","oficio","ofrecer","ogro","oído","oír","ojo","ola","oleada","olfato","olivo","olla","olmo","olor","olvido","ombligo","onda","onza","opaco","opción","ópera","opinar","oponer","optar","óptica","opuesto","oración","orador","oral","órbita","orca","orden","oreja","órgano","orgía","orgullo","oriente","origen","orilla","oro","orquesta","oruga","osadía","oscuro","osezno","oso","ostra","otoño","otro","oveja","óvulo","óxido","oxígeno","oyente","ozono","pacto","padre","paella","página","pago","país","pájaro","palabra","palco","paleta","pálido","palma","paloma","palpar","pan","panal","pánico","pantera","pañuelo","papá","papel","papilla","paquete","parar","parcela","pared","parir","paro","párpado","parque","párrafo","parte","pasar","paseo","pasión","paso","pasta","pata","patio","patria","pausa","pauta","pavo","payaso","peatón","pecado","pecera","pecho","pedal","pedir","pegar","peine","pelar","peldaño","pelea","peligro","pellejo","pelo","peluca","pena","pensar","peñón","peón","peor","pepino","pequeño","pera","percha","perder","pereza","perfil","perico","perla","permiso","perro","persona","pesa","pesca","pésimo","pestaña","pétalo","petróleo","pez","pezuña","picar","pichón","pie","piedra","pierna","pieza","pijama","pilar","piloto","pimienta","pino","pintor","pinza","piña","piojo","pipa","pirata","pisar","piscina","piso","pista","pitón","pizca","placa","plan","plata","playa","plaza","pleito","pleno","plomo","pluma","plural","pobre","poco","poder","podio","poema","poesía","poeta","polen","policía","pollo","polvo","pomada","pomelo","pomo","pompa","poner","porción","portal","posada","poseer","posible","poste","potencia","potro","pozo","prado","precoz","pregunta","premio","prensa","preso","previo","primo","príncipe","prisión","privar","proa","probar","proceso","producto","proeza","profesor","programa","prole","promesa","pronto","propio","próximo","prueba","público","puchero","pudor","pueblo","puerta","puesto","pulga","pulir","pulmón","pulpo","pulso","puma","punto","puñal","puño","pupa","pupila","puré","quedar","queja","quemar","querer","queso","quieto","química","quince","quitar","rábano","rabia","rabo","ración","radical","raíz","rama","rampa","rancho","rango","rapaz","rápido","rapto","rasgo","raspa","rato","rayo","raza","razón","reacción","realidad","rebaño","rebote","recaer","receta","rechazo","recoger","recreo","recto","recurso","red","redondo","reducir","reflejo","reforma","refrán","refugio","regalo","regir","regla","regreso","rehén","reino","reír","reja","relato","relevo","relieve","relleno","reloj","remar","remedio","remo","rencor","rendir","renta","reparto","repetir","reposo","reptil","res","rescate","resina","respeto","resto","resumen","retiro","retorno","retrato","reunir","revés","revista","rey","rezar","rico","riego","rienda","riesgo","rifa","rígido","rigor","rincón","riñón","río","riqueza","risa","ritmo","rito","rizo","roble","roce","rociar","rodar","rodeo","rodilla","roer","rojizo","rojo","romero","romper","ron","ronco","ronda","ropa","ropero","rosa","rosca","rostro","rotar","rubí","rubor","rudo","rueda","rugir","ruido","ruina","ruleta","rulo","rumbo","rumor","ruptura","ruta","rutina","sábado","saber","sabio","sable","sacar","sagaz","sagrado","sala","saldo","salero","salir","salmón","salón","salsa","salto","salud","salvar","samba","sanción","sandía","sanear","sangre","sanidad","sano","santo","sapo","saque","sardina","sartén","sastre","satán","sauna","saxofón","sección","seco","secreto","secta","sed","seguir","seis","sello","selva","semana","semilla","senda","sensor","señal","señor","separar","sepia","sequía","ser","serie","sermón","servir","sesenta","sesión","seta","setenta","severo","sexo","sexto","sidra","siesta","siete","siglo","signo","sílaba","silbar","silencio","silla","símbolo","simio","sirena","sistema","sitio","situar","sobre","socio","sodio","sol","solapa","soldado","soledad","sólido","soltar","solución","sombra","sondeo","sonido","sonoro","sonrisa","sopa","soplar","soporte","sordo","sorpresa","sorteo","sostén","sótano","suave","subir","suceso","sudor","suegra","suelo","sueño","suerte","sufrir","sujeto","sultán","sumar","superar","suplir","suponer","supremo","sur","surco","sureño","surgir","susto","sutil","tabaco","tabique","tabla","tabú","taco","tacto","tajo","talar","talco","talento","talla","talón","tamaño","tambor","tango","tanque","tapa","tapete","tapia","tapón","taquilla","tarde","tarea","tarifa","tarjeta","tarot","tarro","tarta","tatuaje","tauro","taza","tazón","teatro","techo","tecla","técnica","tejado","tejer","tejido","tela","teléfono","tema","temor","templo","tenaz","tender","tener","tenis","tenso","teoría","terapia","terco","término","ternura","terror","tesis","tesoro","testigo","tetera","texto","tez","tibio","tiburón","tiempo","tienda","tierra","tieso","tigre","tijera","tilde","timbre","tímido","timo","tinta","tío","típico","tipo","tira","tirón","titán","títere","título","tiza","toalla","tobillo","tocar","tocino","todo","toga","toldo","tomar","tono","tonto","topar","tope","toque","tórax","torero","tormenta","torneo","toro","torpedo","torre","torso","tortuga","tos","tosco","toser","tóxico","trabajo","tractor","traer","tráfico","trago","traje","tramo","trance","trato","trauma","trazar","trébol","tregua","treinta","tren","trepar","tres","tribu","trigo","tripa","triste","triunfo","trofeo","trompa","tronco","tropa","trote","trozo","truco","trueno","trufa","tubería","tubo","tuerto","tumba","tumor","túnel","túnica","turbina","turismo","turno","tutor","ubicar","úlcera","umbral","unidad","unir","universo","uno","untar","uña","urbano","urbe","urgente","urna","usar","usuario","útil","utopía","uva","vaca","vacío","vacuna","vagar","vago","vaina","vajilla","vale","válido","valle","valor","válvula","vampiro","vara","variar","varón","vaso","vecino","vector","vehículo","veinte","vejez","vela","velero","veloz","vena","vencer","venda","veneno","vengar","venir","venta","venus","ver","verano","verbo","verde","vereda","verja","verso","verter","vía","viaje","vibrar","vicio","víctima","vida","vídeo","vidrio","viejo","viernes","vigor","vil","villa","vinagre","vino","viñedo","violín","viral","virgo","virtud","visor","víspera","vista","vitamina","viudo","vivaz","vivero","vivir","vivo","volcán","volumen","volver","voraz","votar","voto","voz","vuelo","vulgar","yacer","yate","yegua","yema","yerno","yeso","yodo","yoga","yogur","zafiro","zanja","zapato","zarza","zona","zorro","zumo","zurdo"]'),p_=JSON.parse('["あいこくしん","あいさつ","あいだ","あおぞら","あかちゃん","あきる","あけがた","あける","あこがれる","あさい","あさひ","あしあと","あじわう","あずかる","あずき","あそぶ","あたえる","あたためる","あたりまえ","あたる","あつい","あつかう","あっしゅく","あつまり","あつめる","あてな","あてはまる","あひる","あぶら","あぶる","あふれる","あまい","あまど","あまやかす","あまり","あみもの","あめりか","あやまる","あゆむ","あらいぐま","あらし","あらすじ","あらためる","あらゆる","あらわす","ありがとう","あわせる","あわてる","あんい","あんがい","あんこ","あんぜん","あんてい","あんない","あんまり","いいだす","いおん","いがい","いがく","いきおい","いきなり","いきもの","いきる","いくじ","いくぶん","いけばな","いけん","いこう","いこく","いこつ","いさましい","いさん","いしき","いじゅう","いじょう","いじわる","いずみ","いずれ","いせい","いせえび","いせかい","いせき","いぜん","いそうろう","いそがしい","いだい","いだく","いたずら","いたみ","いたりあ","いちおう","いちじ","いちど","いちば","いちぶ","いちりゅう","いつか","いっしゅん","いっせい","いっそう","いったん","いっち","いってい","いっぽう","いてざ","いてん","いどう","いとこ","いない","いなか","いねむり","いのち","いのる","いはつ","いばる","いはん","いびき","いひん","いふく","いへん","いほう","いみん","いもうと","いもたれ","いもり","いやがる","いやす","いよかん","いよく","いらい","いらすと","いりぐち","いりょう","いれい","いれもの","いれる","いろえんぴつ","いわい","いわう","いわかん","いわば","いわゆる","いんげんまめ","いんさつ","いんしょう","いんよう","うえき","うえる","うおざ","うがい","うかぶ","うかべる","うきわ","うくらいな","うくれれ","うけたまわる","うけつけ","うけとる","うけもつ","うける","うごかす","うごく","うこん","うさぎ","うしなう","うしろがみ","うすい","うすぎ","うすぐらい","うすめる","うせつ","うちあわせ","うちがわ","うちき","うちゅう","うっかり","うつくしい","うったえる","うつる","うどん","うなぎ","うなじ","うなずく","うなる","うねる","うのう","うぶげ","うぶごえ","うまれる","うめる","うもう","うやまう","うよく","うらがえす","うらぐち","うらない","うりあげ","うりきれ","うるさい","うれしい","うれゆき","うれる","うろこ","うわき","うわさ","うんこう","うんちん","うんてん","うんどう","えいえん","えいが","えいきょう","えいご","えいせい","えいぶん","えいよう","えいわ","えおり","えがお","えがく","えきたい","えくせる","えしゃく","えすて","えつらん","えのぐ","えほうまき","えほん","えまき","えもじ","えもの","えらい","えらぶ","えりあ","えんえん","えんかい","えんぎ","えんげき","えんしゅう","えんぜつ","えんそく","えんちょう","えんとつ","おいかける","おいこす","おいしい","おいつく","おうえん","おうさま","おうじ","おうせつ","おうたい","おうふく","おうべい","おうよう","おえる","おおい","おおう","おおどおり","おおや","おおよそ","おかえり","おかず","おがむ","おかわり","おぎなう","おきる","おくさま","おくじょう","おくりがな","おくる","おくれる","おこす","おこなう","おこる","おさえる","おさない","おさめる","おしいれ","おしえる","おじぎ","おじさん","おしゃれ","おそらく","おそわる","おたがい","おたく","おだやか","おちつく","おっと","おつり","おでかけ","おとしもの","おとなしい","おどり","おどろかす","おばさん","おまいり","おめでとう","おもいで","おもう","おもたい","おもちゃ","おやつ","おやゆび","およぼす","おらんだ","おろす","おんがく","おんけい","おんしゃ","おんせん","おんだん","おんちゅう","おんどけい","かあつ","かいが","がいき","がいけん","がいこう","かいさつ","かいしゃ","かいすいよく","かいぜん","かいぞうど","かいつう","かいてん","かいとう","かいふく","がいへき","かいほう","かいよう","がいらい","かいわ","かえる","かおり","かかえる","かがく","かがし","かがみ","かくご","かくとく","かざる","がぞう","かたい","かたち","がちょう","がっきゅう","がっこう","がっさん","がっしょう","かなざわし","かのう","がはく","かぶか","かほう","かほご","かまう","かまぼこ","かめれおん","かゆい","かようび","からい","かるい","かろう","かわく","かわら","がんか","かんけい","かんこう","かんしゃ","かんそう","かんたん","かんち","がんばる","きあい","きあつ","きいろ","ぎいん","きうい","きうん","きえる","きおう","きおく","きおち","きおん","きかい","きかく","きかんしゃ","ききて","きくばり","きくらげ","きけんせい","きこう","きこえる","きこく","きさい","きさく","きさま","きさらぎ","ぎじかがく","ぎしき","ぎじたいけん","ぎじにってい","ぎじゅつしゃ","きすう","きせい","きせき","きせつ","きそう","きぞく","きぞん","きたえる","きちょう","きつえん","ぎっちり","きつつき","きつね","きてい","きどう","きどく","きない","きなが","きなこ","きぬごし","きねん","きのう","きのした","きはく","きびしい","きひん","きふく","きぶん","きぼう","きほん","きまる","きみつ","きむずかしい","きめる","きもだめし","きもち","きもの","きゃく","きやく","ぎゅうにく","きよう","きょうりゅう","きらい","きらく","きりん","きれい","きれつ","きろく","ぎろん","きわめる","ぎんいろ","きんかくじ","きんじょ","きんようび","ぐあい","くいず","くうかん","くうき","くうぐん","くうこう","ぐうせい","くうそう","ぐうたら","くうふく","くうぼ","くかん","くきょう","くげん","ぐこう","くさい","くさき","くさばな","くさる","くしゃみ","くしょう","くすのき","くすりゆび","くせげ","くせん","ぐたいてき","くださる","くたびれる","くちこみ","くちさき","くつした","ぐっすり","くつろぐ","くとうてん","くどく","くなん","くねくね","くのう","くふう","くみあわせ","くみたてる","くめる","くやくしょ","くらす","くらべる","くるま","くれる","くろう","くわしい","ぐんかん","ぐんしょく","ぐんたい","ぐんて","けあな","けいかく","けいけん","けいこ","けいさつ","げいじゅつ","けいたい","げいのうじん","けいれき","けいろ","けおとす","けおりもの","げきか","げきげん","げきだん","げきちん","げきとつ","げきは","げきやく","げこう","げこくじょう","げざい","けさき","げざん","けしき","けしごむ","けしょう","げすと","けたば","けちゃっぷ","けちらす","けつあつ","けつい","けつえき","けっこん","けつじょ","けっせき","けってい","けつまつ","げつようび","げつれい","けつろん","げどく","けとばす","けとる","けなげ","けなす","けなみ","けぬき","げねつ","けねん","けはい","げひん","けぶかい","げぼく","けまり","けみかる","けむし","けむり","けもの","けらい","けろけろ","けわしい","けんい","けんえつ","けんお","けんか","げんき","けんげん","けんこう","けんさく","けんしゅう","けんすう","げんそう","けんちく","けんてい","けんとう","けんない","けんにん","げんぶつ","けんま","けんみん","けんめい","けんらん","けんり","こあくま","こいぬ","こいびと","ごうい","こうえん","こうおん","こうかん","ごうきゅう","ごうけい","こうこう","こうさい","こうじ","こうすい","ごうせい","こうそく","こうたい","こうちゃ","こうつう","こうてい","こうどう","こうない","こうはい","ごうほう","ごうまん","こうもく","こうりつ","こえる","こおり","ごかい","ごがつ","ごかん","こくご","こくさい","こくとう","こくない","こくはく","こぐま","こけい","こける","ここのか","こころ","こさめ","こしつ","こすう","こせい","こせき","こぜん","こそだて","こたい","こたえる","こたつ","こちょう","こっか","こつこつ","こつばん","こつぶ","こてい","こてん","ことがら","ことし","ことば","ことり","こなごな","こねこね","このまま","このみ","このよ","ごはん","こひつじ","こふう","こふん","こぼれる","ごまあぶら","こまかい","ごますり","こまつな","こまる","こむぎこ","こもじ","こもち","こもの","こもん","こやく","こやま","こゆう","こゆび","こよい","こよう","こりる","これくしょん","ころっけ","こわもて","こわれる","こんいん","こんかい","こんき","こんしゅう","こんすい","こんだて","こんとん","こんなん","こんびに","こんぽん","こんまけ","こんや","こんれい","こんわく","ざいえき","さいかい","さいきん","ざいげん","ざいこ","さいしょ","さいせい","ざいたく","ざいちゅう","さいてき","ざいりょう","さうな","さかいし","さがす","さかな","さかみち","さがる","さぎょう","さくし","さくひん","さくら","さこく","さこつ","さずかる","ざせき","さたん","さつえい","ざつおん","ざっか","ざつがく","さっきょく","ざっし","さつじん","ざっそう","さつたば","さつまいも","さてい","さといも","さとう","さとおや","さとし","さとる","さのう","さばく","さびしい","さべつ","さほう","さほど","さます","さみしい","さみだれ","さむけ","さめる","さやえんどう","さゆう","さよう","さよく","さらだ","ざるそば","さわやか","さわる","さんいん","さんか","さんきゃく","さんこう","さんさい","ざんしょ","さんすう","さんせい","さんそ","さんち","さんま","さんみ","さんらん","しあい","しあげ","しあさって","しあわせ","しいく","しいん","しうち","しえい","しおけ","しかい","しかく","じかん","しごと","しすう","じだい","したうけ","したぎ","したて","したみ","しちょう","しちりん","しっかり","しつじ","しつもん","してい","してき","してつ","じてん","じどう","しなぎれ","しなもの","しなん","しねま","しねん","しのぐ","しのぶ","しはい","しばかり","しはつ","しはらい","しはん","しひょう","しふく","じぶん","しへい","しほう","しほん","しまう","しまる","しみん","しむける","じむしょ","しめい","しめる","しもん","しゃいん","しゃうん","しゃおん","じゃがいも","しやくしょ","しゃくほう","しゃけん","しゃこ","しゃざい","しゃしん","しゃせん","しゃそう","しゃたい","しゃちょう","しゃっきん","じゃま","しゃりん","しゃれい","じゆう","じゅうしょ","しゅくはく","じゅしん","しゅっせき","しゅみ","しゅらば","じゅんばん","しょうかい","しょくたく","しょっけん","しょどう","しょもつ","しらせる","しらべる","しんか","しんこう","じんじゃ","しんせいじ","しんちく","しんりん","すあげ","すあし","すあな","ずあん","すいえい","すいか","すいとう","ずいぶん","すいようび","すうがく","すうじつ","すうせん","すおどり","すきま","すくう","すくない","すける","すごい","すこし","ずさん","すずしい","すすむ","すすめる","すっかり","ずっしり","ずっと","すてき","すてる","すねる","すのこ","すはだ","すばらしい","ずひょう","ずぶぬれ","すぶり","すふれ","すべて","すべる","ずほう","すぼん","すまい","すめし","すもう","すやき","すらすら","するめ","すれちがう","すろっと","すわる","すんぜん","すんぽう","せあぶら","せいかつ","せいげん","せいじ","せいよう","せおう","せかいかん","せきにん","せきむ","せきゆ","せきらんうん","せけん","せこう","せすじ","せたい","せたけ","せっかく","せっきゃく","ぜっく","せっけん","せっこつ","せっさたくま","せつぞく","せつだん","せつでん","せっぱん","せつび","せつぶん","せつめい","せつりつ","せなか","せのび","せはば","せびろ","せぼね","せまい","せまる","せめる","せもたれ","せりふ","ぜんあく","せんい","せんえい","せんか","せんきょ","せんく","せんげん","ぜんご","せんさい","せんしゅ","せんすい","せんせい","せんぞ","せんたく","せんちょう","せんてい","せんとう","せんぬき","せんねん","せんぱい","ぜんぶ","ぜんぽう","せんむ","せんめんじょ","せんもん","せんやく","せんゆう","せんよう","ぜんら","ぜんりゃく","せんれい","せんろ","そあく","そいとげる","そいね","そうがんきょう","そうき","そうご","そうしん","そうだん","そうなん","そうび","そうめん","そうり","そえもの","そえん","そがい","そげき","そこう","そこそこ","そざい","そしな","そせい","そせん","そそぐ","そだてる","そつう","そつえん","そっかん","そつぎょう","そっけつ","そっこう","そっせん","そっと","そとがわ","そとづら","そなえる","そなた","そふぼ","そぼく","そぼろ","そまつ","そまる","そむく","そむりえ","そめる","そもそも","そよかぜ","そらまめ","そろう","そんかい","そんけい","そんざい","そんしつ","そんぞく","そんちょう","ぞんび","ぞんぶん","そんみん","たあい","たいいん","たいうん","たいえき","たいおう","だいがく","たいき","たいぐう","たいけん","たいこ","たいざい","だいじょうぶ","だいすき","たいせつ","たいそう","だいたい","たいちょう","たいてい","だいどころ","たいない","たいねつ","たいのう","たいはん","だいひょう","たいふう","たいへん","たいほ","たいまつばな","たいみんぐ","たいむ","たいめん","たいやき","たいよう","たいら","たいりょく","たいる","たいわん","たうえ","たえる","たおす","たおる","たおれる","たかい","たかね","たきび","たくさん","たこく","たこやき","たさい","たしざん","だじゃれ","たすける","たずさわる","たそがれ","たたかう","たたく","ただしい","たたみ","たちばな","だっかい","だっきゃく","だっこ","だっしゅつ","だったい","たてる","たとえる","たなばた","たにん","たぬき","たのしみ","たはつ","たぶん","たべる","たぼう","たまご","たまる","だむる","ためいき","ためす","ためる","たもつ","たやすい","たよる","たらす","たりきほんがん","たりょう","たりる","たると","たれる","たれんと","たろっと","たわむれる","だんあつ","たんい","たんおん","たんか","たんき","たんけん","たんご","たんさん","たんじょうび","だんせい","たんそく","たんたい","だんち","たんてい","たんとう","だんな","たんにん","だんねつ","たんのう","たんぴん","だんぼう","たんまつ","たんめい","だんれつ","だんろ","だんわ","ちあい","ちあん","ちいき","ちいさい","ちえん","ちかい","ちから","ちきゅう","ちきん","ちけいず","ちけん","ちこく","ちさい","ちしき","ちしりょう","ちせい","ちそう","ちたい","ちたん","ちちおや","ちつじょ","ちてき","ちてん","ちぬき","ちぬり","ちのう","ちひょう","ちへいせん","ちほう","ちまた","ちみつ","ちみどろ","ちめいど","ちゃんこなべ","ちゅうい","ちゆりょく","ちょうし","ちょさくけん","ちらし","ちらみ","ちりがみ","ちりょう","ちるど","ちわわ","ちんたい","ちんもく","ついか","ついたち","つうか","つうじょう","つうはん","つうわ","つかう","つかれる","つくね","つくる","つけね","つける","つごう","つたえる","つづく","つつじ","つつむ","つとめる","つながる","つなみ","つねづね","つのる","つぶす","つまらない","つまる","つみき","つめたい","つもり","つもる","つよい","つるぼ","つるみく","つわもの","つわり","てあし","てあて","てあみ","ていおん","ていか","ていき","ていけい","ていこく","ていさつ","ていし","ていせい","ていたい","ていど","ていねい","ていひょう","ていへん","ていぼう","てうち","ておくれ","てきとう","てくび","でこぼこ","てさぎょう","てさげ","てすり","てそう","てちがい","てちょう","てつがく","てつづき","でっぱ","てつぼう","てつや","でぬかえ","てぬき","てぬぐい","てのひら","てはい","てぶくろ","てふだ","てほどき","てほん","てまえ","てまきずし","てみじか","てみやげ","てらす","てれび","てわけ","てわたし","でんあつ","てんいん","てんかい","てんき","てんぐ","てんけん","てんごく","てんさい","てんし","てんすう","でんち","てんてき","てんとう","てんない","てんぷら","てんぼうだい","てんめつ","てんらんかい","でんりょく","でんわ","どあい","といれ","どうかん","とうきゅう","どうぐ","とうし","とうむぎ","とおい","とおか","とおく","とおす","とおる","とかい","とかす","ときおり","ときどき","とくい","とくしゅう","とくてん","とくに","とくべつ","とけい","とける","とこや","とさか","としょかん","とそう","とたん","とちゅう","とっきゅう","とっくん","とつぜん","とつにゅう","とどける","ととのえる","とない","となえる","となり","とのさま","とばす","どぶがわ","とほう","とまる","とめる","ともだち","ともる","どようび","とらえる","とんかつ","どんぶり","ないかく","ないこう","ないしょ","ないす","ないせん","ないそう","なおす","ながい","なくす","なげる","なこうど","なさけ","なたでここ","なっとう","なつやすみ","ななおし","なにごと","なにもの","なにわ","なのか","なふだ","なまいき","なまえ","なまみ","なみだ","なめらか","なめる","なやむ","ならう","ならび","ならぶ","なれる","なわとび","なわばり","にあう","にいがた","にうけ","におい","にかい","にがて","にきび","にくしみ","にくまん","にげる","にさんかたんそ","にしき","にせもの","にちじょう","にちようび","にっか","にっき","にっけい","にっこう","にっさん","にっしょく","にっすう","にっせき","にってい","になう","にほん","にまめ","にもつ","にやり","にゅういん","にりんしゃ","にわとり","にんい","にんか","にんき","にんげん","にんしき","にんずう","にんそう","にんたい","にんち","にんてい","にんにく","にんぷ","にんまり","にんむ","にんめい","にんよう","ぬいくぎ","ぬかす","ぬぐいとる","ぬぐう","ぬくもり","ぬすむ","ぬまえび","ぬめり","ぬらす","ぬんちゃく","ねあげ","ねいき","ねいる","ねいろ","ねぐせ","ねくたい","ねくら","ねこぜ","ねこむ","ねさげ","ねすごす","ねそべる","ねだん","ねつい","ねっしん","ねつぞう","ねったいぎょ","ねぶそく","ねふだ","ねぼう","ねほりはほり","ねまき","ねまわし","ねみみ","ねむい","ねむたい","ねもと","ねらう","ねわざ","ねんいり","ねんおし","ねんかん","ねんきん","ねんぐ","ねんざ","ねんし","ねんちゃく","ねんど","ねんぴ","ねんぶつ","ねんまつ","ねんりょう","ねんれい","のいず","のおづま","のがす","のきなみ","のこぎり","のこす","のこる","のせる","のぞく","のぞむ","のたまう","のちほど","のっく","のばす","のはら","のべる","のぼる","のみもの","のやま","のらいぬ","のらねこ","のりもの","のりゆき","のれん","のんき","ばあい","はあく","ばあさん","ばいか","ばいく","はいけん","はいご","はいしん","はいすい","はいせん","はいそう","はいち","ばいばい","はいれつ","はえる","はおる","はかい","ばかり","はかる","はくしゅ","はけん","はこぶ","はさみ","はさん","はしご","ばしょ","はしる","はせる","ぱそこん","はそん","はたん","はちみつ","はつおん","はっかく","はづき","はっきり","はっくつ","はっけん","はっこう","はっさん","はっしん","はったつ","はっちゅう","はってん","はっぴょう","はっぽう","はなす","はなび","はにかむ","はぶらし","はみがき","はむかう","はめつ","はやい","はやし","はらう","はろうぃん","はわい","はんい","はんえい","はんおん","はんかく","はんきょう","ばんぐみ","はんこ","はんしゃ","はんすう","はんだん","ぱんち","ぱんつ","はんてい","はんとし","はんのう","はんぱ","はんぶん","はんぺん","はんぼうき","はんめい","はんらん","はんろん","ひいき","ひうん","ひえる","ひかく","ひかり","ひかる","ひかん","ひくい","ひけつ","ひこうき","ひこく","ひさい","ひさしぶり","ひさん","びじゅつかん","ひしょ","ひそか","ひそむ","ひたむき","ひだり","ひたる","ひつぎ","ひっこし","ひっし","ひつじゅひん","ひっす","ひつぜん","ぴったり","ぴっちり","ひつよう","ひてい","ひとごみ","ひなまつり","ひなん","ひねる","ひはん","ひびく","ひひょう","ひほう","ひまわり","ひまん","ひみつ","ひめい","ひめじし","ひやけ","ひやす","ひよう","びょうき","ひらがな","ひらく","ひりつ","ひりょう","ひるま","ひるやすみ","ひれい","ひろい","ひろう","ひろき","ひろゆき","ひんかく","ひんけつ","ひんこん","ひんしゅ","ひんそう","ぴんち","ひんぱん","びんぼう","ふあん","ふいうち","ふうけい","ふうせん","ぷうたろう","ふうとう","ふうふ","ふえる","ふおん","ふかい","ふきん","ふくざつ","ふくぶくろ","ふこう","ふさい","ふしぎ","ふじみ","ふすま","ふせい","ふせぐ","ふそく","ぶたにく","ふたん","ふちょう","ふつう","ふつか","ふっかつ","ふっき","ふっこく","ぶどう","ふとる","ふとん","ふのう","ふはい","ふひょう","ふへん","ふまん","ふみん","ふめつ","ふめん","ふよう","ふりこ","ふりる","ふるい","ふんいき","ぶんがく","ぶんぐ","ふんしつ","ぶんせき","ふんそう","ぶんぽう","へいあん","へいおん","へいがい","へいき","へいげん","へいこう","へいさ","へいしゃ","へいせつ","へいそ","へいたく","へいてん","へいねつ","へいわ","へきが","へこむ","べにいろ","べにしょうが","へらす","へんかん","べんきょう","べんごし","へんさい","へんたい","べんり","ほあん","ほいく","ぼうぎょ","ほうこく","ほうそう","ほうほう","ほうもん","ほうりつ","ほえる","ほおん","ほかん","ほきょう","ぼきん","ほくろ","ほけつ","ほけん","ほこう","ほこる","ほしい","ほしつ","ほしゅ","ほしょう","ほせい","ほそい","ほそく","ほたて","ほたる","ぽちぶくろ","ほっきょく","ほっさ","ほったん","ほとんど","ほめる","ほんい","ほんき","ほんけ","ほんしつ","ほんやく","まいにち","まかい","まかせる","まがる","まける","まこと","まさつ","まじめ","ますく","まぜる","まつり","まとめ","まなぶ","まぬけ","まねく","まほう","まもる","まゆげ","まよう","まろやか","まわす","まわり","まわる","まんが","まんきつ","まんぞく","まんなか","みいら","みうち","みえる","みがく","みかた","みかん","みけん","みこん","みじかい","みすい","みすえる","みせる","みっか","みつかる","みつける","みてい","みとめる","みなと","みなみかさい","みねらる","みのう","みのがす","みほん","みもと","みやげ","みらい","みりょく","みわく","みんか","みんぞく","むいか","むえき","むえん","むかい","むかう","むかえ","むかし","むぎちゃ","むける","むげん","むさぼる","むしあつい","むしば","むじゅん","むしろ","むすう","むすこ","むすぶ","むすめ","むせる","むせん","むちゅう","むなしい","むのう","むやみ","むよう","むらさき","むりょう","むろん","めいあん","めいうん","めいえん","めいかく","めいきょく","めいさい","めいし","めいそう","めいぶつ","めいれい","めいわく","めぐまれる","めざす","めした","めずらしい","めだつ","めまい","めやす","めんきょ","めんせき","めんどう","もうしあげる","もうどうけん","もえる","もくし","もくてき","もくようび","もちろん","もどる","もらう","もんく","もんだい","やおや","やける","やさい","やさしい","やすい","やすたろう","やすみ","やせる","やそう","やたい","やちん","やっと","やっぱり","やぶる","やめる","ややこしい","やよい","やわらかい","ゆうき","ゆうびんきょく","ゆうべ","ゆうめい","ゆけつ","ゆしゅつ","ゆせん","ゆそう","ゆたか","ゆちゃく","ゆでる","ゆにゅう","ゆびわ","ゆらい","ゆれる","ようい","ようか","ようきゅう","ようじ","ようす","ようちえん","よかぜ","よかん","よきん","よくせい","よくぼう","よけい","よごれる","よさん","よしゅう","よそう","よそく","よっか","よてい","よどがわく","よねつ","よやく","よゆう","よろこぶ","よろしい","らいう","らくがき","らくご","らくさつ","らくだ","らしんばん","らせん","らぞく","らたい","らっか","られつ","りえき","りかい","りきさく","りきせつ","りくぐん","りくつ","りけん","りこう","りせい","りそう","りそく","りてん","りねん","りゆう","りゅうがく","りよう","りょうり","りょかん","りょくちゃ","りょこう","りりく","りれき","りろん","りんご","るいけい","るいさい","るいじ","るいせき","るすばん","るりがわら","れいかん","れいぎ","れいせい","れいぞうこ","れいとう","れいぼう","れきし","れきだい","れんあい","れんけい","れんこん","れんさい","れんしゅう","れんぞく","れんらく","ろうか","ろうご","ろうじん","ろうそく","ろくが","ろこつ","ろじうら","ろしゅつ","ろせん","ろてん","ろめん","ろれつ","ろんぎ","ろんぱ","ろんぶん","ろんり","わかす","わかめ","わかやま","わかれる","わしつ","わじまし","わすれもの","わらう","われる"]'),d_=JSON.parse('["abacate","abaixo","abalar","abater","abduzir","abelha","aberto","abismo","abotoar","abranger","abreviar","abrigar","abrupto","absinto","absoluto","absurdo","abutre","acabado","acalmar","acampar","acanhar","acaso","aceitar","acelerar","acenar","acervo","acessar","acetona","achatar","acidez","acima","acionado","acirrar","aclamar","aclive","acolhida","acomodar","acoplar","acordar","acumular","acusador","adaptar","adega","adentro","adepto","adequar","aderente","adesivo","adeus","adiante","aditivo","adjetivo","adjunto","admirar","adorar","adquirir","adubo","adverso","advogado","aeronave","afastar","aferir","afetivo","afinador","afivelar","aflito","afluente","afrontar","agachar","agarrar","agasalho","agenciar","agilizar","agiota","agitado","agora","agradar","agreste","agrupar","aguardar","agulha","ajoelhar","ajudar","ajustar","alameda","alarme","alastrar","alavanca","albergue","albino","alcatra","aldeia","alecrim","alegria","alertar","alface","alfinete","algum","alheio","aliar","alicate","alienar","alinhar","aliviar","almofada","alocar","alpiste","alterar","altitude","alucinar","alugar","aluno","alusivo","alvo","amaciar","amador","amarelo","amassar","ambas","ambiente","ameixa","amenizar","amido","amistoso","amizade","amolador","amontoar","amoroso","amostra","amparar","ampliar","ampola","anagrama","analisar","anarquia","anatomia","andaime","anel","anexo","angular","animar","anjo","anomalia","anotado","ansioso","anterior","anuidade","anunciar","anzol","apagador","apalpar","apanhado","apego","apelido","apertada","apesar","apetite","apito","aplauso","aplicada","apoio","apontar","aposta","aprendiz","aprovar","aquecer","arame","aranha","arara","arcada","ardente","areia","arejar","arenito","aresta","argiloso","argola","arma","arquivo","arraial","arrebate","arriscar","arroba","arrumar","arsenal","arterial","artigo","arvoredo","asfaltar","asilado","aspirar","assador","assinar","assoalho","assunto","astral","atacado","atadura","atalho","atarefar","atear","atender","aterro","ateu","atingir","atirador","ativo","atoleiro","atracar","atrevido","atriz","atual","atum","auditor","aumentar","aura","aurora","autismo","autoria","autuar","avaliar","avante","avaria","avental","avesso","aviador","avisar","avulso","axila","azarar","azedo","azeite","azulejo","babar","babosa","bacalhau","bacharel","bacia","bagagem","baiano","bailar","baioneta","bairro","baixista","bajular","baleia","baliza","balsa","banal","bandeira","banho","banir","banquete","barato","barbado","baronesa","barraca","barulho","baseado","bastante","batata","batedor","batida","batom","batucar","baunilha","beber","beijo","beirada","beisebol","beldade","beleza","belga","beliscar","bendito","bengala","benzer","berimbau","berlinda","berro","besouro","bexiga","bezerro","bico","bicudo","bienal","bifocal","bifurcar","bigorna","bilhete","bimestre","bimotor","biologia","biombo","biosfera","bipolar","birrento","biscoito","bisneto","bispo","bissexto","bitola","bizarro","blindado","bloco","bloquear","boato","bobagem","bocado","bocejo","bochecha","boicotar","bolada","boletim","bolha","bolo","bombeiro","bonde","boneco","bonita","borbulha","borda","boreal","borracha","bovino","boxeador","branco","brasa","braveza","breu","briga","brilho","brincar","broa","brochura","bronzear","broto","bruxo","bucha","budismo","bufar","bule","buraco","busca","busto","buzina","cabana","cabelo","cabide","cabo","cabrito","cacau","cacetada","cachorro","cacique","cadastro","cadeado","cafezal","caiaque","caipira","caixote","cajado","caju","calafrio","calcular","caldeira","calibrar","calmante","calota","camada","cambista","camisa","camomila","campanha","camuflar","canavial","cancelar","caneta","canguru","canhoto","canivete","canoa","cansado","cantar","canudo","capacho","capela","capinar","capotar","capricho","captador","capuz","caracol","carbono","cardeal","careca","carimbar","carneiro","carpete","carreira","cartaz","carvalho","casaco","casca","casebre","castelo","casulo","catarata","cativar","caule","causador","cautelar","cavalo","caverna","cebola","cedilha","cegonha","celebrar","celular","cenoura","censo","centeio","cercar","cerrado","certeiro","cerveja","cetim","cevada","chacota","chaleira","chamado","chapada","charme","chatice","chave","chefe","chegada","cheiro","cheque","chicote","chifre","chinelo","chocalho","chover","chumbo","chutar","chuva","cicatriz","ciclone","cidade","cidreira","ciente","cigana","cimento","cinto","cinza","ciranda","circuito","cirurgia","citar","clareza","clero","clicar","clone","clube","coado","coagir","cobaia","cobertor","cobrar","cocada","coelho","coentro","coeso","cogumelo","coibir","coifa","coiote","colar","coleira","colher","colidir","colmeia","colono","coluna","comando","combinar","comentar","comitiva","comover","complexo","comum","concha","condor","conectar","confuso","congelar","conhecer","conjugar","consumir","contrato","convite","cooperar","copeiro","copiador","copo","coquetel","coragem","cordial","corneta","coronha","corporal","correio","cortejo","coruja","corvo","cosseno","costela","cotonete","couro","couve","covil","cozinha","cratera","cravo","creche","credor","creme","crer","crespo","criada","criminal","crioulo","crise","criticar","crosta","crua","cruzeiro","cubano","cueca","cuidado","cujo","culatra","culminar","culpar","cultura","cumprir","cunhado","cupido","curativo","curral","cursar","curto","cuspir","custear","cutelo","damasco","datar","debater","debitar","deboche","debulhar","decalque","decimal","declive","decote","decretar","dedal","dedicado","deduzir","defesa","defumar","degelo","degrau","degustar","deitado","deixar","delator","delegado","delinear","delonga","demanda","demitir","demolido","dentista","depenado","depilar","depois","depressa","depurar","deriva","derramar","desafio","desbotar","descanso","desenho","desfiado","desgaste","desigual","deslize","desmamar","desova","despesa","destaque","desviar","detalhar","detentor","detonar","detrito","deusa","dever","devido","devotado","dezena","diagrama","dialeto","didata","difuso","digitar","dilatado","diluente","diminuir","dinastia","dinheiro","diocese","direto","discreta","disfarce","disparo","disquete","dissipar","distante","ditador","diurno","diverso","divisor","divulgar","dizer","dobrador","dolorido","domador","dominado","donativo","donzela","dormente","dorsal","dosagem","dourado","doutor","drenagem","drible","drogaria","duelar","duende","dueto","duplo","duquesa","durante","duvidoso","eclodir","ecoar","ecologia","edificar","edital","educado","efeito","efetivar","ejetar","elaborar","eleger","eleitor","elenco","elevador","eliminar","elogiar","embargo","embolado","embrulho","embutido","emenda","emergir","emissor","empatia","empenho","empinado","empolgar","emprego","empurrar","emulador","encaixe","encenado","enchente","encontro","endeusar","endossar","enfaixar","enfeite","enfim","engajado","engenho","englobar","engomado","engraxar","enguia","enjoar","enlatar","enquanto","enraizar","enrolado","enrugar","ensaio","enseada","ensino","ensopado","entanto","enteado","entidade","entortar","entrada","entulho","envergar","enviado","envolver","enxame","enxerto","enxofre","enxuto","epiderme","equipar","ereto","erguido","errata","erva","ervilha","esbanjar","esbelto","escama","escola","escrita","escuta","esfinge","esfolar","esfregar","esfumado","esgrima","esmalte","espanto","espelho","espiga","esponja","espreita","espumar","esquerda","estaca","esteira","esticar","estofado","estrela","estudo","esvaziar","etanol","etiqueta","euforia","europeu","evacuar","evaporar","evasivo","eventual","evidente","evoluir","exagero","exalar","examinar","exato","exausto","excesso","excitar","exclamar","executar","exemplo","exibir","exigente","exonerar","expandir","expelir","expirar","explanar","exposto","expresso","expulsar","externo","extinto","extrato","fabricar","fabuloso","faceta","facial","fada","fadiga","faixa","falar","falta","familiar","fandango","fanfarra","fantoche","fardado","farelo","farinha","farofa","farpa","fartura","fatia","fator","favorita","faxina","fazenda","fechado","feijoada","feirante","felino","feminino","fenda","feno","fera","feriado","ferrugem","ferver","festejar","fetal","feudal","fiapo","fibrose","ficar","ficheiro","figurado","fileira","filho","filme","filtrar","firmeza","fisgada","fissura","fita","fivela","fixador","fixo","flacidez","flamingo","flanela","flechada","flora","flutuar","fluxo","focal","focinho","fofocar","fogo","foguete","foice","folgado","folheto","forjar","formiga","forno","forte","fosco","fossa","fragata","fralda","frango","frasco","fraterno","freira","frente","fretar","frieza","friso","fritura","fronha","frustrar","fruteira","fugir","fulano","fuligem","fundar","fungo","funil","furador","furioso","futebol","gabarito","gabinete","gado","gaiato","gaiola","gaivota","galega","galho","galinha","galocha","ganhar","garagem","garfo","gargalo","garimpo","garoupa","garrafa","gasoduto","gasto","gata","gatilho","gaveta","gazela","gelado","geleia","gelo","gemada","gemer","gemido","generoso","gengiva","genial","genoma","genro","geologia","gerador","germinar","gesso","gestor","ginasta","gincana","gingado","girafa","girino","glacial","glicose","global","glorioso","goela","goiaba","golfe","golpear","gordura","gorjeta","gorro","gostoso","goteira","governar","gracejo","gradual","grafite","gralha","grampo","granada","gratuito","graveto","graxa","grego","grelhar","greve","grilo","grisalho","gritaria","grosso","grotesco","grudado","grunhido","gruta","guache","guarani","guaxinim","guerrear","guiar","guincho","guisado","gula","guloso","guru","habitar","harmonia","haste","haver","hectare","herdar","heresia","hesitar","hiato","hibernar","hidratar","hiena","hino","hipismo","hipnose","hipoteca","hoje","holofote","homem","honesto","honrado","hormonal","hospedar","humorado","iate","ideia","idoso","ignorado","igreja","iguana","ileso","ilha","iludido","iluminar","ilustrar","imagem","imediato","imenso","imersivo","iminente","imitador","imortal","impacto","impedir","implante","impor","imprensa","impune","imunizar","inalador","inapto","inativo","incenso","inchar","incidir","incluir","incolor","indeciso","indireto","indutor","ineficaz","inerente","infantil","infestar","infinito","inflamar","informal","infrator","ingerir","inibido","inicial","inimigo","injetar","inocente","inodoro","inovador","inox","inquieto","inscrito","inseto","insistir","inspetor","instalar","insulto","intacto","integral","intimar","intocado","intriga","invasor","inverno","invicto","invocar","iogurte","iraniano","ironizar","irreal","irritado","isca","isento","isolado","isqueiro","italiano","janeiro","jangada","janta","jararaca","jardim","jarro","jasmim","jato","javali","jazida","jejum","joaninha","joelhada","jogador","joia","jornal","jorrar","jovem","juba","judeu","judoca","juiz","julgador","julho","jurado","jurista","juro","justa","labareda","laboral","lacre","lactante","ladrilho","lagarta","lagoa","laje","lamber","lamentar","laminar","lampejo","lanche","lapidar","lapso","laranja","lareira","largura","lasanha","lastro","lateral","latido","lavanda","lavoura","lavrador","laxante","lazer","lealdade","lebre","legado","legendar","legista","leigo","leiloar","leitura","lembrete","leme","lenhador","lentilha","leoa","lesma","leste","letivo","letreiro","levar","leveza","levitar","liberal","libido","liderar","ligar","ligeiro","limitar","limoeiro","limpador","linda","linear","linhagem","liquidez","listagem","lisura","litoral","livro","lixa","lixeira","locador","locutor","lojista","lombo","lona","longe","lontra","lorde","lotado","loteria","loucura","lousa","louvar","luar","lucidez","lucro","luneta","lustre","lutador","luva","macaco","macete","machado","macio","madeira","madrinha","magnata","magreza","maior","mais","malandro","malha","malote","maluco","mamilo","mamoeiro","mamute","manada","mancha","mandato","manequim","manhoso","manivela","manobrar","mansa","manter","manusear","mapeado","maquinar","marcador","maresia","marfim","margem","marinho","marmita","maroto","marquise","marreco","martelo","marujo","mascote","masmorra","massagem","mastigar","matagal","materno","matinal","matutar","maxilar","medalha","medida","medusa","megafone","meiga","melancia","melhor","membro","memorial","menino","menos","mensagem","mental","merecer","mergulho","mesada","mesclar","mesmo","mesquita","mestre","metade","meteoro","metragem","mexer","mexicano","micro","migalha","migrar","milagre","milenar","milhar","mimado","minerar","minhoca","ministro","minoria","miolo","mirante","mirtilo","misturar","mocidade","moderno","modular","moeda","moer","moinho","moita","moldura","moleza","molho","molinete","molusco","montanha","moqueca","morango","morcego","mordomo","morena","mosaico","mosquete","mostarda","motel","motim","moto","motriz","muda","muito","mulata","mulher","multar","mundial","munido","muralha","murcho","muscular","museu","musical","nacional","nadador","naja","namoro","narina","narrado","nascer","nativa","natureza","navalha","navegar","navio","neblina","nebuloso","negativa","negociar","negrito","nervoso","neta","neural","nevasca","nevoeiro","ninar","ninho","nitidez","nivelar","nobreza","noite","noiva","nomear","nominal","nordeste","nortear","notar","noticiar","noturno","novelo","novilho","novo","nublado","nudez","numeral","nupcial","nutrir","nuvem","obcecado","obedecer","objetivo","obrigado","obscuro","obstetra","obter","obturar","ocidente","ocioso","ocorrer","oculista","ocupado","ofegante","ofensiva","oferenda","oficina","ofuscado","ogiva","olaria","oleoso","olhar","oliveira","ombro","omelete","omisso","omitir","ondulado","oneroso","ontem","opcional","operador","oponente","oportuno","oposto","orar","orbitar","ordem","ordinal","orfanato","orgasmo","orgulho","oriental","origem","oriundo","orla","ortodoxo","orvalho","oscilar","ossada","osso","ostentar","otimismo","ousadia","outono","outubro","ouvido","ovelha","ovular","oxidar","oxigenar","pacato","paciente","pacote","pactuar","padaria","padrinho","pagar","pagode","painel","pairar","paisagem","palavra","palestra","palheta","palito","palmada","palpitar","pancada","panela","panfleto","panqueca","pantanal","papagaio","papelada","papiro","parafina","parcial","pardal","parede","partida","pasmo","passado","pastel","patamar","patente","patinar","patrono","paulada","pausar","peculiar","pedalar","pedestre","pediatra","pedra","pegada","peitoral","peixe","pele","pelicano","penca","pendurar","peneira","penhasco","pensador","pente","perceber","perfeito","pergunta","perito","permitir","perna","perplexo","persiana","pertence","peruca","pescado","pesquisa","pessoa","petiscar","piada","picado","piedade","pigmento","pilastra","pilhado","pilotar","pimenta","pincel","pinguim","pinha","pinote","pintar","pioneiro","pipoca","piquete","piranha","pires","pirueta","piscar","pistola","pitanga","pivete","planta","plaqueta","platina","plebeu","plumagem","pluvial","pneu","poda","poeira","poetisa","polegada","policiar","poluente","polvilho","pomar","pomba","ponderar","pontaria","populoso","porta","possuir","postal","pote","poupar","pouso","povoar","praia","prancha","prato","praxe","prece","predador","prefeito","premiar","prensar","preparar","presilha","pretexto","prevenir","prezar","primata","princesa","prisma","privado","processo","produto","profeta","proibido","projeto","prometer","propagar","prosa","protetor","provador","publicar","pudim","pular","pulmonar","pulseira","punhal","punir","pupilo","pureza","puxador","quadra","quantia","quarto","quase","quebrar","queda","queijo","quente","querido","quimono","quina","quiosque","rabanada","rabisco","rachar","racionar","radial","raiar","rainha","raio","raiva","rajada","ralado","ramal","ranger","ranhura","rapadura","rapel","rapidez","raposa","raquete","raridade","rasante","rascunho","rasgar","raspador","rasteira","rasurar","ratazana","ratoeira","realeza","reanimar","reaver","rebaixar","rebelde","rebolar","recado","recente","recheio","recibo","recordar","recrutar","recuar","rede","redimir","redonda","reduzida","reenvio","refinar","refletir","refogar","refresco","refugiar","regalia","regime","regra","reinado","reitor","rejeitar","relativo","remador","remendo","remorso","renovado","reparo","repelir","repleto","repolho","represa","repudiar","requerer","resenha","resfriar","resgatar","residir","resolver","respeito","ressaca","restante","resumir","retalho","reter","retirar","retomada","retratar","revelar","revisor","revolta","riacho","rica","rigidez","rigoroso","rimar","ringue","risada","risco","risonho","robalo","rochedo","rodada","rodeio","rodovia","roedor","roleta","romano","roncar","rosado","roseira","rosto","rota","roteiro","rotina","rotular","rouco","roupa","roxo","rubro","rugido","rugoso","ruivo","rumo","rupestre","russo","sabor","saciar","sacola","sacudir","sadio","safira","saga","sagrada","saibro","salada","saleiro","salgado","saliva","salpicar","salsicha","saltar","salvador","sambar","samurai","sanar","sanfona","sangue","sanidade","sapato","sarda","sargento","sarjeta","saturar","saudade","saxofone","sazonal","secar","secular","seda","sedento","sediado","sedoso","sedutor","segmento","segredo","segundo","seiva","seleto","selvagem","semanal","semente","senador","senhor","sensual","sentado","separado","sereia","seringa","serra","servo","setembro","setor","sigilo","silhueta","silicone","simetria","simpatia","simular","sinal","sincero","singular","sinopse","sintonia","sirene","siri","situado","soberano","sobra","socorro","sogro","soja","solda","soletrar","solteiro","sombrio","sonata","sondar","sonegar","sonhador","sono","soprano","soquete","sorrir","sorteio","sossego","sotaque","soterrar","sovado","sozinho","suavizar","subida","submerso","subsolo","subtrair","sucata","sucesso","suco","sudeste","sufixo","sugador","sugerir","sujeito","sulfato","sumir","suor","superior","suplicar","suposto","suprimir","surdina","surfista","surpresa","surreal","surtir","suspiro","sustento","tabela","tablete","tabuada","tacho","tagarela","talher","talo","talvez","tamanho","tamborim","tampa","tangente","tanto","tapar","tapioca","tardio","tarefa","tarja","tarraxa","tatuagem","taurino","taxativo","taxista","teatral","tecer","tecido","teclado","tedioso","teia","teimar","telefone","telhado","tempero","tenente","tensor","tentar","termal","terno","terreno","tese","tesoura","testado","teto","textura","texugo","tiara","tigela","tijolo","timbrar","timidez","tingido","tinteiro","tiragem","titular","toalha","tocha","tolerar","tolice","tomada","tomilho","tonel","tontura","topete","tora","torcido","torneio","torque","torrada","torto","tostar","touca","toupeira","toxina","trabalho","tracejar","tradutor","trafegar","trajeto","trama","trancar","trapo","traseiro","tratador","travar","treino","tremer","trepidar","trevo","triagem","tribo","triciclo","tridente","trilogia","trindade","triplo","triturar","triunfal","trocar","trombeta","trova","trunfo","truque","tubular","tucano","tudo","tulipa","tupi","turbo","turma","turquesa","tutelar","tutorial","uivar","umbigo","unha","unidade","uniforme","urologia","urso","urtiga","urubu","usado","usina","usufruir","vacina","vadiar","vagaroso","vaidoso","vala","valente","validade","valores","vantagem","vaqueiro","varanda","vareta","varrer","vascular","vasilha","vassoura","vazar","vazio","veado","vedar","vegetar","veicular","veleiro","velhice","veludo","vencedor","vendaval","venerar","ventre","verbal","verdade","vereador","vergonha","vermelho","verniz","versar","vertente","vespa","vestido","vetorial","viaduto","viagem","viajar","viatura","vibrador","videira","vidraria","viela","viga","vigente","vigiar","vigorar","vilarejo","vinco","vinheta","vinil","violeta","virada","virtude","visitar","visto","vitral","viveiro","vizinho","voador","voar","vogal","volante","voleibol","voltagem","volumoso","vontade","vulto","vuvuzela","xadrez","xarope","xeque","xeretar","xerife","xingar","zangado","zarpar","zebu","zelador","zombar","zoologia","zumbido"]'),y_=JSON.parse('["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"]');var g_,m_;function b_(){if(g_)return o_;g_=1,Object.defineProperty(o_,"__esModule",{value:!0});const e={};let t;o_.wordlists=e,o_._default=t;try{o_._default=t=s_,e.czech=t}catch{}try{o_._default=t=a_,e.chinese_simplified=t}catch{}try{o_._default=t=u_,e.chinese_traditional=t}catch{}try{o_._default=t=c_,e.korean=t}catch{}try{o_._default=t=f_,e.french=t}catch{}try{o_._default=t=l_,e.italian=t}catch{}try{o_._default=t=h_,e.spanish=t}catch{}try{o_._default=t=p_,e.japanese=t,e.JA=t}catch{}try{o_._default=t=d_,e.portuguese=t}catch{}try{o_._default=t=y_,e.english=t,e.EN=t}catch{}return o_}var w_=function(){if(m_)return i_;m_=1,Object.defineProperty(i_,"__esModule",{value:!0});const e=Ju(),t=rc(),r=Mc(),n=Ru(),i=b_();let o=i._default;const s="Invalid mnemonic",a="Invalid entropy",u="A wordlist is required but a default could not be found.\nPlease pass a 2048 word array explicitly.";function c(e){return(e||"").normalize("NFKD")}function f(e,t,r){for(;e.length<r;)e=t+e;return e}function l(e){return parseInt(e,2)}function h(e){return e.map(e=>f(e.toString(2),"0",8)).join("")}function p(t){const r=8*t.length/32,n=e.sha256(Uint8Array.from(t));return h(Array.from(n)).slice(0,r)}function d(e){return"mnemonic"+(e||"")}function y(e,t){if(!(t=t||o))throw new Error(u);const r=c(e).split(" ");if(r.length%3!=0)throw new Error(s);const n=r.map(e=>{const r=t.indexOf(e);if(-1===r)throw new Error(s);return f(r.toString(2),"0",11)}).join(""),i=32*Math.floor(n.length/33),h=n.slice(0,i),d=n.slice(i),y=h.match(/(.{1,8})/g).map(l);if(y.length<16)throw new Error(a);if(y.length>32)throw new Error(a);if(y.length%4!=0)throw new Error(a);const g=nh.from(y);if(p(g)!==d)throw new Error("Invalid mnemonic checksum");return g.toString("hex")}function g(e,t){if(nh.isBuffer(e)||(e=nh.from(e,"hex")),!(t=t||o))throw new Error(u);if(e.length<16)throw new TypeError(a);if(e.length>32)throw new TypeError(a);if(e.length%4!=0)throw new TypeError(a);const r=(h(Array.from(e))+p(e)).match(/(.{1,11})/g).map(e=>{const r=l(e);return t[r]});return"あいこくしん"===t[0]?r.join(" "):r.join(" ")}i_.mnemonicToSeedSync=function(e,n){const i=Uint8Array.from(nh.from(c(e),"utf8")),o=Uint8Array.from(nh.from(d(c(n)),"utf8")),s=r.pbkdf2(t.sha512,i,o,{c:2048,dkLen:64});return nh.from(s)},i_.mnemonicToSeed=function(e,n){const i=Uint8Array.from(nh.from(c(e),"utf8")),o=Uint8Array.from(nh.from(d(c(n)),"utf8"));return r.pbkdf2Async(t.sha512,i,o,{c:2048,dkLen:64}).then(e=>nh.from(e))},i_.mnemonicToEntropy=y,i_.entropyToMnemonic=g,i_.generateMnemonic=function(e,t,r){if((e=e||128)%32!=0)throw new TypeError(a);return g((t=t||(e=>nh.from(n.randomBytes(e))))(e/8),r)},i_.validateMnemonic=function(e,t){try{y(e,t)}catch{return!1}return!0},i_.setDefaultWordlist=function(e){const t=i.wordlists[e];if(!t)throw new Error('Could not find wordlist for language "'+e+'"');o=t},i_.getDefaultWordlist=function(){if(!o)throw new Error("No Default Wordlist set");return Object.keys(i.wordlists).filter(e=>"JA"!==e&&"EN"!==e&&i.wordlists[e].every((e,t)=>e===o[t]))[0]};var m=b_();return i_.wordlists=m.wordlists,i_}(),v_={exports:{}},E_={exports:{}};function __(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var S_,k_,A_={exports:{}},I_=A_.exports={};function T_(){throw new Error("setTimeout has not been defined")}function x_(){throw new Error("clearTimeout has not been defined")}function O_(e){if(S_===setTimeout)return setTimeout(e,0);if((S_===T_||!S_)&&setTimeout)return S_=setTimeout,setTimeout(e,0);try{return S_(e,0)}catch{try{return S_.call(null,e,0)}catch{return S_.call(this,e,0)}}}!function(){try{S_="function"==typeof setTimeout?setTimeout:T_}catch{S_=T_}try{k_="function"==typeof clearTimeout?clearTimeout:x_}catch{k_=x_}}();var B_,P_=[],U_=!1,L_=-1;function N_(){!U_||!B_||(U_=!1,B_.length?P_=B_.concat(P_):L_=-1,P_.length&&R_())}function R_(){if(!U_){var e=O_(N_);U_=!0;for(var t=P_.length;t;){for(B_=P_,P_=[];++L_<t;)B_&&B_[L_].run();L_=-1,t=P_.length}B_=null,U_=!1,function(e){if(k_===clearTimeout)return clearTimeout(e);if((k_===x_||!k_)&&clearTimeout)return k_=clearTimeout,clearTimeout(e);try{return k_(e)}catch{try{return k_.call(null,e)}catch{return k_.call(this,e)}}}(e)}}function C_(e,t){this.fun=e,this.array=t}function H_(){}I_.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];P_.push(new C_(e,t)),1===P_.length&&!U_&&O_(R_)},C_.prototype.run=function(){this.fun.apply(null,this.array)},I_.title="browser",I_.browser=!0,I_.env={},I_.argv=[],I_.version="",I_.versions={},I_.on=H_,I_.addListener=H_,I_.once=H_,I_.off=H_,I_.removeListener=H_,I_.removeAllListeners=H_,I_.emit=H_,I_.prependListener=H_,I_.prependOnceListener=H_,I_.listeners=function(e){return[]},I_.binding=function(e){throw new Error("process.binding is not supported")},I_.cwd=function(){return"/"},I_.chdir=function(e){throw new Error("process.chdir is not supported")},I_.umask=function(){return 0};const K_=__(A_.exports);var z_,M_,D_,j_,F_,V_,q_,W_,$_,G_,X_,Y_,Z_,Q_,J_,eS,tS,rS,nS,iS,oS,sS,aS,uS,cS,fS,lS,hS,pS,dS,yS,gS,mS,bS,wS,vS,ES,_S,SS,kS,AS,IS,TS,xS,OS,BS,PS,US,LS,NS,RS,CS,HS,KS,zS,MS,DS,jS,FS,VS,qS,WS,$S,GS,XS,YS,ZS,QS,JS,ek,tk,rk,nk,ik,ok,sk,ak,uk,ck,fk,lk,hk,pk,dk,yk,gk,mk,bk,wk,vk,Ek={},_k={};function Sk(){return M_||(M_=1,z_=function(){if("function"!=typeof Symbol||"function"!=typeof Object.getOwnPropertySymbols)return!1;if("symbol"==typeof Symbol.iterator)return!0;var e={},t=Symbol("test"),r=Object(t);if("string"==typeof t||"[object Symbol]"!==Object.prototype.toString.call(t)||"[object Symbol]"!==Object.prototype.toString.call(r))return!1;for(var n in e[t]=42,e)return!1;if("function"==typeof Object.keys&&0!==Object.keys(e).length||"function"==typeof Object.getOwnPropertyNames&&0!==Object.getOwnPropertyNames(e).length)return!1;var i=Object.getOwnPropertySymbols(e);if(1!==i.length||i[0]!==t||!Object.prototype.propertyIsEnumerable.call(e,t))return!1;if("function"==typeof Object.getOwnPropertyDescriptor){var o=Object.getOwnPropertyDescriptor(e,t);if(42!==o.value||!0!==o.enumerable)return!1}return!0}),z_}function kk(){if(j_)return D_;j_=1;var e=Sk();return D_=function(){return e()&&!!Symbol.toStringTag}}function Ak(){return V_||(V_=1,F_=Object),F_}function Ik(){return W_||(W_=1,q_=Error),q_}function Tk(){return G_||(G_=1,$_=EvalError),$_}function xk(){return Y_||(Y_=1,X_=RangeError),X_}function Ok(){return Q_||(Q_=1,Z_=ReferenceError),Z_}function Bk(){return eS||(eS=1,J_=SyntaxError),J_}function Pk(){return rS||(rS=1,tS=TypeError),tS}function Uk(){return iS||(iS=1,nS=URIError),nS}function Lk(){return sS||(sS=1,oS=Math.abs),oS}function Nk(){return uS||(uS=1,aS=Math.floor),aS}function Rk(){return fS||(fS=1,cS=Math.max),cS}function Ck(){return hS||(hS=1,lS=Math.min),lS}function Hk(){return dS||(dS=1,pS=Math.pow),pS}function Kk(){return gS||(gS=1,yS=Math.round),yS}function zk(){return bS||(bS=1,mS=Number.isNaN||function(e){return e!=e}),mS}function Mk(){if(vS)return wS;vS=1;var e=zk();return wS=function(t){return e(t)||0===t?t:t<0?-1:1}}function Dk(){return _S||(_S=1,ES=Object.getOwnPropertyDescriptor),ES}function jk(){if(kS)return SS;kS=1;var e=Dk();if(e)try{e([],"length")}catch{e=null}return SS=e}function Fk(){if(IS)return AS;IS=1;var e=Object.defineProperty||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return AS=e}function Vk(){return BS||(BS=1,OS=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),OS}function qk(){return US?PS:(US=1,PS=Ak().getPrototypeOf||null)}function Wk(){if(CS)return RS;CS=1;var e=function(){if(NS)return LS;NS=1;var e=Object.prototype.toString,t=Math.max,r=function(e,t){for(var r=[],n=0;n<e.length;n+=1)r[n]=e[n];for(var i=0;i<t.length;i+=1)r[i+e.length]=t[i];return r};return LS=function(n){var i=this;if("function"!=typeof i||"[object Function]"!==e.apply(i))throw new TypeError("Function.prototype.bind called on incompatible "+i);for(var o,s=function(e){for(var t=[],r=1,n=0;r<e.length;r+=1,n+=1)t[n]=e[r];return t}(arguments),a=t(0,i.length-s.length),u=[],c=0;c<a;c++)u[c]="$"+c;if(o=Function("binder","return function ("+function(e,t){for(var r="",n=0;n<e.length;n+=1)r+=e[n],n+1<e.length&&(r+=t);return r}(u,",")+"){ return binder.apply(this,arguments); }")(function(){if(this instanceof o){var e=i.apply(this,r(s,arguments));return Object(e)===e?e:this}return i.apply(n,r(s,arguments))}),i.prototype){var f=function(){};f.prototype=i.prototype,o.prototype=new f,f.prototype=null}return o},LS}();return RS=Function.prototype.bind||e}function $k(){return KS||(KS=1,HS=Function.prototype.call),HS}function Gk(){return MS||(MS=1,zS=Function.prototype.apply),zS}function Xk(){if(VS)return FS;VS=1;var e=Wk(),t=Gk(),r=$k(),n=(jS||(jS=1,DS=typeof Reflect<"u"&&Reflect&&Reflect.apply),DS);return FS=n||e.call(r,t)}function Yk(){if(WS)return qS;WS=1;var e=Wk(),t=Pk(),r=$k(),n=Xk();return qS=function(i){if(i.length<1||"function"!=typeof i[0])throw new t("a function is required");return n(e,r,i)}}function Zk(){if(GS)return $S;GS=1;var e,t=Yk(),r=jk();try{e=[].__proto__===Array.prototype}catch(s){if(!s||"object"!=typeof s||!("code"in s)||"ERR_PROTO_ACCESS"!==s.code)throw s}var n=!!e&&r&&r(Object.prototype,"__proto__"),i=Object,o=i.getPrototypeOf;return $S=n&&"function"==typeof n.get?t([n.get]):"function"==typeof o&&function(e){return o(null==e?e:i(e))},$S}function Qk(){if(YS)return XS;YS=1;var e=Vk(),t=qk(),r=Zk();return XS=e?function(t){return e(t)}:t?function(e){if(!e||"object"!=typeof e&&"function"!=typeof e)throw new TypeError("getProto: not an object");return t(e)}:r?function(e){return r(e)}:null}function Jk(){if(QS)return ZS;QS=1;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=Wk();return ZS=r.call(e,t)}function eA(){if(ek)return JS;ek=1;var e,t=Ak(),r=Ik(),n=Tk(),i=xk(),o=Ok(),s=Bk(),a=Pk(),u=Uk(),c=Lk(),f=Nk(),l=Rk(),h=Ck(),p=Hk(),d=Kk(),y=Mk(),g=Function,m=function(e){try{return g('"use strict"; return ('+e+").constructor;")()}catch{}},b=jk(),w=Fk(),v=function(){throw new a},E=b?function(){try{return v}catch{try{return b(arguments,"callee").get}catch{return v}}}():v,_=function(){if(xS)return TS;xS=1;var e=typeof Symbol<"u"&&Symbol,t=Sk();return TS=function(){return"function"==typeof e&&"function"==typeof Symbol&&"symbol"==typeof e("foo")&&"symbol"==typeof Symbol("bar")&&t()}}()(),S=Qk(),k=qk(),A=Vk(),I=Gk(),T=$k(),x={},O=typeof Uint8Array>"u"||!S?e:S(Uint8Array),B={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":_&&S?S([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":x,"%AsyncGenerator%":x,"%AsyncGeneratorFunction%":x,"%AsyncIteratorPrototype%":x,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":r,"%eval%":eval,"%EvalError%":n,"%Float16Array%":typeof Float16Array>"u"?e:Float16Array,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":g,"%GeneratorFunction%":x,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":_&&S?S(S([][Symbol.iterator]())):e,"%JSON%":"object"==typeof JSON?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!_||!S?e:S((new Map)[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":t,"%Object.getOwnPropertyDescriptor%":b,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":i,"%ReferenceError%":o,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!_||!S?e:S((new Set)[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":_&&S?S(""[Symbol.iterator]()):e,"%Symbol%":_?Symbol:e,"%SyntaxError%":s,"%ThrowTypeError%":E,"%TypedArray%":O,"%TypeError%":a,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":u,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet,"%Function.prototype.call%":T,"%Function.prototype.apply%":I,"%Object.defineProperty%":w,"%Object.getPrototypeOf%":k,"%Math.abs%":c,"%Math.floor%":f,"%Math.max%":l,"%Math.min%":h,"%Math.pow%":p,"%Math.round%":d,"%Math.sign%":y,"%Reflect.getPrototypeOf%":A};if(S)try{null.error}catch(V){var P=S(S(V));B["%Error.prototype%"]=P}var U=function e(t){var r;if("%AsyncFunction%"===t)r=m("async function () {}");else if("%GeneratorFunction%"===t)r=m("function* () {}");else if("%AsyncGeneratorFunction%"===t)r=m("async function* () {}");else if("%AsyncGenerator%"===t){var n=e("%AsyncGeneratorFunction%");n&&(r=n.prototype)}else if("%AsyncIteratorPrototype%"===t){var i=e("%AsyncGenerator%");i&&S&&(r=S(i.prototype))}return B[t]=r,r},L={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},N=Wk(),R=Jk(),C=N.call(T,Array.prototype.concat),H=N.call(I,Array.prototype.splice),K=N.call(T,String.prototype.replace),z=N.call(T,String.prototype.slice),M=N.call(T,RegExp.prototype.exec),D=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,j=/\\(\\)?/g,F=function(e,t){var r,n=e;if(R(L,n)&&(n="%"+(r=L[n])[0]+"%"),R(B,n)){var i=B[n];if(i===x&&(i=U(n)),typeof i>"u"&&!t)throw new a("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:r,name:n,value:i}}throw new s("intrinsic "+e+" does not exist!")};return JS=function(e,t){if("string"!=typeof e||0===e.length)throw new a("intrinsic name must be a non-empty string");if(arguments.length>1&&"boolean"!=typeof t)throw new a('"allowMissing" argument must be a boolean');if(null===M(/^%?[^%]*%?$/,e))throw new s("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var r=function(e){var t=z(e,0,1),r=z(e,-1);if("%"===t&&"%"!==r)throw new s("invalid intrinsic syntax, expected closing `%`");if("%"===r&&"%"!==t)throw new s("invalid intrinsic syntax, expected opening `%`");var n=[];return K(e,D,function(e,t,r,i){n[n.length]=r?K(i,j,"$1"):t||e}),n}(e),n=r.length>0?r[0]:"",i=F("%"+n+"%",t),o=i.name,u=i.value,c=!1,f=i.alias;f&&(n=f[0],H(r,C([0,1],f)));for(var l=1,h=!0;l<r.length;l+=1){var p=r[l],d=z(p,0,1),y=z(p,-1);if(('"'===d||"'"===d||"`"===d||'"'===y||"'"===y||"`"===y)&&d!==y)throw new s("property names with quotes must have matching quotes");if(("constructor"===p||!h)&&(c=!0),R(B,o="%"+(n+="."+p)+"%"))u=B[o];else if(null!=u){if(!(p in u)){if(!t)throw new a("base intrinsic for "+e+" exists, but the property is not available.");return}if(b&&l+1>=r.length){var g=b(u,p);u=(h=!!g)&&"get"in g&&!("originalValue"in g.get)?g.get:u[p]}else h=R(u,p),u=u[p];h&&!c&&(B[o]=u)}}return u},JS}function tA(){if(rk)return tk;rk=1;var e=eA(),t=Yk(),r=t([e("%String.prototype.indexOf%")]);return tk=function(n,i){var o=e(n,!!i);return"function"==typeof o&&r(n,".prototype.")>-1?t([o]):o}}function rA(){if(ik)return nk;ik=1;var e=kk()(),t=tA()("Object.prototype.toString"),r=function(r){return!(e&&r&&"object"==typeof r&&Symbol.toStringTag in r)&&"[object Arguments]"===t(r)},n=function(e){return!!r(e)||null!==e&&"object"==typeof e&&"length"in e&&"number"==typeof e.length&&e.length>=0&&"[object Array]"!==t(e)&&"callee"in e&&"[object Function]"===t(e.callee)},i=function(){return r(arguments)}();return r.isLegacyArguments=n,nk=i?r:n}function nA(){if(uk)return ak;uk=1;var e=tA(),t=function(){if(sk)return ok;sk=1;var e,t=tA(),r=kk()(),n=Jk(),i=jk();if(r){var o=t("RegExp.prototype.exec"),s={},a=function(){throw s},u={toString:a,valueOf:a};"symbol"==typeof Symbol.toPrimitive&&(u[Symbol.toPrimitive]=a),e=function(e){if(!e||"object"!=typeof e)return!1;var t=i(e,"lastIndex");if(!t||!n(t,"value"))return!1;try{o(e,u)}catch(r){return r===s}}}else{var c=t("Object.prototype.toString");e=function(e){return!(!e||"object"!=typeof e&&"function"!=typeof e)&&"[object RegExp]"===c(e)}}return ok=e}(),r=e("RegExp.prototype.exec"),n=Pk();return ak=function(e){if(!t(e))throw new n("`regex` must be a RegExp");return function(t){return null!==r(e,t)}},ak}function iA(){if(fk)return ck;fk=1;const e=function*(){}.constructor;return ck=()=>e}function oA(){if(gk)return yk;gk=1;var e=function(){if(dk)return pk;dk=1;var e,t,r=Function.prototype.toString,n="object"==typeof Reflect&&null!==Reflect&&Reflect.apply;if("function"==typeof n&&"function"==typeof Object.defineProperty)try{e=Object.defineProperty({},"length",{get:function(){throw t}}),t={},n(function(){throw 42},null,e)}catch(h){h!==t&&(n=null)}else n=null;var i=/^\s*class\b/,o=function(e){try{var t=r.call(e);return i.test(t)}catch{return!1}},s=function(e){try{return!o(e)&&(r.call(e),!0)}catch{return!1}},a=Object.prototype.toString,u="function"==typeof Symbol&&!!Symbol.toStringTag,c=!(0 in[,]),f=function(){return!1};if("object"==typeof document){var l=document.all;a.call(l)===a.call(document.all)&&(f=function(e){if((c||!e)&&(typeof e>"u"||"object"==typeof e))try{var t=a.call(e);return("[object HTMLAllCollection]"===t||"[object HTML document.all class]"===t||"[object HTMLCollection]"===t||"[object Object]"===t)&&null==e("")}catch{}return!1})}return pk=n?function(r){if(f(r))return!0;if(!r||"function"!=typeof r&&"object"!=typeof r)return!1;try{n(r,null,e)}catch(i){if(i!==t)return!1}return!o(r)&&s(r)}:function(e){if(f(e))return!0;if(!e||"function"!=typeof e&&"object"!=typeof e)return!1;if(u)return s(e);if(o(e))return!1;var t=a.call(e);return!("[object Function]"!==t&&"[object GeneratorFunction]"!==t&&!/^\[object HTML/.test(t))&&s(e)}}(),t=Object.prototype.toString,r=Object.prototype.hasOwnProperty;return yk=function(n,i,o){if(!e(i))throw new TypeError("iterator must be a function");var s;arguments.length>=3&&(s=o),function(e){return"[object Array]"===t.call(e)}(n)?function(e,t,n){for(var i=0,o=e.length;i<o;i++)r.call(e,i)&&(null==n?t(e[i],i,e):t.call(n,e[i],i,e))}(n,i,s):"string"==typeof n?function(e,t,r){for(var n=0,i=e.length;n<i;n++)null==r?t(e.charAt(n),n,e):t.call(r,e.charAt(n),n,e)}(n,i,s):function(e,t,n){for(var i in e)r.call(e,i)&&(null==n?t(e[i],i,e):t.call(n,e[i],i,e))}(n,i,s)},yk}function sA(){return bk||(bk=1,mk=["Float16Array","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array"]),mk}function aA(){if(vk)return wk;vk=1;var e=sA(),t=globalThis;return wk=function(){for(var r=[],n=0;n<e.length;n++)"function"==typeof t[e[n]]&&(r[r.length]=e[n]);return r}}var uA,cA,fA,lA,hA,pA,dA,yA,gA,mA,bA,wA,vA,EA,_A,SA,kA,AA={exports:{}};function IA(){if(cA)return uA;cA=1;var e=Fk(),t=Bk(),r=Pk(),n=jk();return uA=function(i,o,s){if(!i||"object"!=typeof i&&"function"!=typeof i)throw new r("`obj` must be an object or a function`");if("string"!=typeof o&&"symbol"!=typeof o)throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&"boolean"!=typeof arguments[3]&&null!==arguments[3])throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&"boolean"!=typeof arguments[4]&&null!==arguments[4])throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&"boolean"!=typeof arguments[5]&&null!==arguments[5])throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&"boolean"!=typeof arguments[6])throw new r("`loose`, if provided, must be a boolean");var a=arguments.length>3?arguments[3]:null,u=arguments.length>4?arguments[4]:null,c=arguments.length>5?arguments[5]:null,f=arguments.length>6&&arguments[6],l=!!n&&n(i,o);if(e)e(i,o,{configurable:null===c&&l?l.configurable:!c,enumerable:null===a&&l?l.enumerable:!a,value:s,writable:null===u&&l?l.writable:!u});else{if(!f&&(a||u||c))throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.");i[o]=s}},uA}function TA(){if(lA)return fA;lA=1;var e=Fk(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return 1!==e([],"length",{value:1}).length}catch{return!0}},fA=t}function xA(){if(pA)return hA;pA=1;var e=eA(),t=IA(),r=TA()(),n=jk(),i=Pk(),o=e("%Math.floor%");return hA=function(e,s){if("function"!=typeof e)throw new i("`fn` is not a function");if("number"!=typeof s||s<0||s>4294967295||o(s)!==s)throw new i("`length` must be a positive 32-bit integer");var a=arguments.length>2&&!!arguments[2],u=!0,c=!0;if("length"in e&&n){var f=n(e,"length");f&&!f.configurable&&(u=!1),f&&!f.writable&&(c=!1)}return(u||c||!a)&&(r?t(e,"length",s,!0,!0):t(e,"length",s)),e},hA}function OA(){return gA||(gA=1,function(e){var t=xA(),r=Fk(),n=Yk(),i=function(){if(yA)return dA;yA=1;var e=Wk(),t=Gk(),r=Xk();return dA=function(){return r(e,t,arguments)},dA}();e.exports=function(e){var r=n(arguments),i=e.length-(arguments.length-1);return t(r,1+(i>0?i:0),!0)},r?r(e.exports,"apply",{value:i}):e.exports.apply=i}(AA)),AA.exports}function BA(){if(bA)return mA;bA=1;var e=oA(),t=aA(),r=OA(),n=tA(),i=jk(),o=Qk(),s=n("Object.prototype.toString"),a=kk()(),u=globalThis,c=t(),f=n("String.prototype.slice"),l=n("Array.prototype.indexOf",!0)||function(e,t){for(var r=0;r<e.length;r+=1)if(e[r]===t)return r;return-1},h={__proto__:null};e(c,a&&i&&o?function(e){var t=new u[e];if(Symbol.toStringTag in t&&o){var n=o(t),s=i(n,Symbol.toStringTag);if(!s&&n){var a=o(n);s=i(a,Symbol.toStringTag)}if(s&&s.get){var c=r(s.get);h["$"+e]=c}}}:function(e){var t=new u[e],n=t.slice||t.set;if(n){var i=r(n);h["$"+e]=i}});return mA=function(t){if(!t||"object"!=typeof t)return!1;if(!a){var r=f(s(t),8,-1);return l(c,r)>-1?r:"Object"===r&&function(t){var r=!1;return e(h,function(e,n){if(!r)try{e(t),r=f(n,1)}catch{}}),r}(t)}return i?function(t){var r=!1;return e(h,function(e,n){if(!r)try{"$"+e(t)===n&&(r=f(n,1))}catch{}}),r}(t):null}}function PA(){if(vA)return wA;vA=1;var e=BA();return wA=function(t){return!!e(t)}}function UA(){return EA||(EA=1,function(e){var t=rA(),r=function(){if(hk)return lk;hk=1;var e=tA(),t=nA()(/^\s*(?:function)?\*/),r=kk()(),n=Qk(),i=e("Object.prototype.toString"),o=e("Function.prototype.toString"),s=iA();return lk=function(e){if("function"!=typeof e)return!1;if(t(o(e)))return!0;if(!r)return"[object GeneratorFunction]"===i(e);if(!n)return!1;var a=s();return a&&n(e)===a.prototype}}(),n=BA(),i=PA();function o(e){return e.call.bind(e)}var s=typeof BigInt<"u",a=typeof Symbol<"u",u=o(Object.prototype.toString),c=o(Number.prototype.valueOf),f=o(String.prototype.valueOf),l=o(Boolean.prototype.valueOf);if(s)var h=o(BigInt.prototype.valueOf);if(a)var p=o(Symbol.prototype.valueOf);function d(e,t){if("object"!=typeof e)return!1;try{return t(e),!0}catch{return!1}}function y(e){return"[object Map]"===u(e)}function g(e){return"[object Set]"===u(e)}function m(e){return"[object WeakMap]"===u(e)}function b(e){return"[object WeakSet]"===u(e)}function w(e){return"[object ArrayBuffer]"===u(e)}function v(e){return!(typeof ArrayBuffer>"u")&&(w.working?w(e):e instanceof ArrayBuffer)}function E(e){return"[object DataView]"===u(e)}function _(e){return!(typeof DataView>"u")&&(E.working?E(e):e instanceof DataView)}e.isArgumentsObject=t,e.isGeneratorFunction=r,e.isTypedArray=i,e.isPromise=function(e){return typeof Promise<"u"&&e instanceof Promise||null!==e&&"object"==typeof e&&"function"==typeof e.then&&"function"==typeof e.catch},e.isArrayBufferView=function(e){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?ArrayBuffer.isView(e):i(e)||_(e)},e.isUint8Array=function(e){return"Uint8Array"===n(e)},e.isUint8ClampedArray=function(e){return"Uint8ClampedArray"===n(e)},e.isUint16Array=function(e){return"Uint16Array"===n(e)},e.isUint32Array=function(e){return"Uint32Array"===n(e)},e.isInt8Array=function(e){return"Int8Array"===n(e)},e.isInt16Array=function(e){return"Int16Array"===n(e)},e.isInt32Array=function(e){return"Int32Array"===n(e)},e.isFloat32Array=function(e){return"Float32Array"===n(e)},e.isFloat64Array=function(e){return"Float64Array"===n(e)},e.isBigInt64Array=function(e){return"BigInt64Array"===n(e)},e.isBigUint64Array=function(e){return"BigUint64Array"===n(e)},y.working=typeof Map<"u"&&y(new Map),e.isMap=function(e){return!(typeof Map>"u")&&(y.working?y(e):e instanceof Map)},g.working=typeof Set<"u"&&g(new Set),e.isSet=function(e){return!(typeof Set>"u")&&(g.working?g(e):e instanceof Set)},m.working=typeof WeakMap<"u"&&m(new WeakMap),e.isWeakMap=function(e){return!(typeof WeakMap>"u")&&(m.working?m(e):e instanceof WeakMap)},b.working=typeof WeakSet<"u"&&b(new WeakSet),e.isWeakSet=function(e){return b(e)},w.working=typeof ArrayBuffer<"u"&&w(new ArrayBuffer),e.isArrayBuffer=v,E.working=typeof ArrayBuffer<"u"&&typeof DataView<"u"&&E(new DataView(new ArrayBuffer(1),0,1)),e.isDataView=_;var S=typeof SharedArrayBuffer<"u"?SharedArrayBuffer:void 0;function k(e){return"[object SharedArrayBuffer]"===u(e)}function A(e){return!(typeof S>"u")&&(typeof k.working>"u"&&(k.working=k(new S)),k.working?k(e):e instanceof S)}function I(e){return d(e,c)}function T(e){return d(e,f)}function x(e){return d(e,l)}function O(e){return s&&d(e,h)}function B(e){return a&&d(e,p)}e.isSharedArrayBuffer=A,e.isAsyncFunction=function(e){return"[object AsyncFunction]"===u(e)},e.isMapIterator=function(e){return"[object Map Iterator]"===u(e)},e.isSetIterator=function(e){return"[object Set Iterator]"===u(e)},e.isGeneratorObject=function(e){return"[object Generator]"===u(e)},e.isWebAssemblyCompiledModule=function(e){return"[object WebAssembly.Module]"===u(e)},e.isNumberObject=I,e.isStringObject=T,e.isBooleanObject=x,e.isBigIntObject=O,e.isSymbolObject=B,e.isBoxedPrimitive=function(e){return I(e)||T(e)||x(e)||O(e)||B(e)},e.isAnyArrayBuffer=function(e){return typeof Uint8Array<"u"&&(v(e)||A(e))},["isProxy","isExternal","isModuleNamespaceObject"].forEach(function(t){Object.defineProperty(e,t,{enumerable:!1,value:function(){throw new Error(t+" is not supported in userland")}})})}(_k)),_k}function LA(){return kA||(kA=1,function(e){var t=Object.getOwnPropertyDescriptors||function(e){for(var t=Object.keys(e),r={},n=0;n<t.length;n++)r[t[n]]=Object.getOwnPropertyDescriptor(e,t[n]);return r},r=/%[sdj%]/g;e.format=function(e){if(!g(e)){for(var t=[],n=0;n<arguments.length;n++)t.push(s(arguments[n]));return t.join(" ")}n=1;for(var i=arguments,o=i.length,a=String(e).replace(r,function(e){if("%%"===e)return"%";if(n>=o)return e;switch(e){case"%s":return String(i[n++]);case"%d":return Number(i[n++]);case"%j":try{return JSON.stringify(i[n++])}catch{return"[Circular]"}default:return e}}),u=i[n];n<o;u=i[++n])d(u)||!w(u)?a+=" "+u:a+=" "+s(u);return a},e.deprecate=function(t,r){if(typeof K_<"u"&&!0===K_.noDeprecation)return t;if(typeof K_>"u")return function(){return e.deprecate(t,r).apply(this,arguments)};var n=!1;return function(){if(!n){if(K_.throwDeprecation)throw new Error(r);K_.traceDeprecation?console.trace(r):console.error(r),n=!0}return t.apply(this,arguments)}};var n={},i=/^$/;if(K_.env.NODE_DEBUG){var o=K_.env.NODE_DEBUG;o=o.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".*").replace(/,/g,"$|^").toUpperCase(),i=new RegExp("^"+o+"$","i")}function s(t,r){var n={seen:[],stylize:u};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),p(r)?n.showHidden=r:r&&e._extend(n,r),m(n.showHidden)&&(n.showHidden=!1),m(n.depth)&&(n.depth=2),m(n.colors)&&(n.colors=!1),m(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=a),c(n,t,n.depth)}function a(e,t){var r=s.styles[t];return r?"["+s.colors[r][0]+"m"+e+"["+s.colors[r][1]+"m":e}function u(e,t){return e}function c(t,r,n){if(t.customInspect&&r&&_(r.inspect)&&r.inspect!==e.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,t);return g(i)||(i=c(t,i,n)),i}var o=function(e,t){if(m(t))return e.stylize("undefined","undefined");if(g(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(y(t))return e.stylize(""+t,"number");if(p(t))return e.stylize(""+t,"boolean");if(d(t))return e.stylize("null","null")}(t,r);if(o)return o;var s=Object.keys(r),a=function(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(r)),E(r)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(r);if(0===s.length){if(_(r)){var u=r.name?": "+r.name:"";return t.stylize("[Function"+u+"]","special")}if(b(r))return t.stylize(RegExp.prototype.toString.call(r),"regexp");if(v(r))return t.stylize(Date.prototype.toString.call(r),"date");if(E(r))return f(r)}var w,S="",k=!1,A=["{","}"];(h(r)&&(k=!0,A=["[","]"]),_(r))&&(S=" [Function"+(r.name?": "+r.name:"")+"]");return b(r)&&(S=" "+RegExp.prototype.toString.call(r)),v(r)&&(S=" "+Date.prototype.toUTCString.call(r)),E(r)&&(S=" "+f(r)),0!==s.length||k&&0!=r.length?n<0?b(r)?t.stylize(RegExp.prototype.toString.call(r),"regexp"):t.stylize("[Object]","special"):(t.seen.push(r),w=k?function(e,t,r,n,i){for(var o=[],s=0,a=t.length;s<a;++s)I(t,String(s))?o.push(l(e,t,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(l(e,t,r,n,i,!0))}),o}(t,r,n,a,s):s.map(function(e){return l(t,r,n,a,e,k)}),t.seen.pop(),function(e,t,r){var n=e.reduce(function(e,t){return t.indexOf("\n"),e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}(w,S,A)):A[0]+S+A[1]}function f(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,r,n,i,o){var s,a,u;if((u=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?a=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(a=e.stylize("[Setter]","special")),I(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(u.value)<0?(a=d(r)?c(e,u.value,null):c(e,u.value,r-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").slice(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n")):a=e.stylize("[Circular]","special")),m(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.slice(1,-1),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function h(e){return Array.isArray(e)}function p(e){return"boolean"==typeof e}function d(e){return null===e}function y(e){return"number"==typeof e}function g(e){return"string"==typeof e}function m(e){return void 0===e}function b(e){return w(e)&&"[object RegExp]"===S(e)}function w(e){return"object"==typeof e&&null!==e}function v(e){return w(e)&&"[object Date]"===S(e)}function E(e){return w(e)&&("[object Error]"===S(e)||e instanceof Error)}function _(e){return"function"==typeof e}function S(e){return Object.prototype.toString.call(e)}function k(e){return e<10?"0"+e.toString(10):e.toString(10)}e.debuglog=function(t){if(t=t.toUpperCase(),!n[t])if(i.test(t)){var r=K_.pid;n[t]=function(){var n=e.format.apply(e,arguments);console.error("%s %d: %s",t,r,n)}}else n[t]=function(){};return n[t]},e.inspect=s,s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},s.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},e.types=UA(),e.isArray=h,e.isBoolean=p,e.isNull=d,e.isNullOrUndefined=function(e){return null==e},e.isNumber=y,e.isString=g,e.isSymbol=function(e){return"symbol"==typeof e},e.isUndefined=m,e.isRegExp=b,e.types.isRegExp=b,e.isObject=w,e.isDate=v,e.types.isDate=v,e.isError=E,e.types.isNativeError=E,e.isFunction=_,e.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||typeof e>"u"},e.isBuffer=(SA||(SA=1,_A=function(e){return e instanceof nh}),_A);var A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function I(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.log=function(){var t,r;console.log("%s - %s",(r=[k((t=new Date).getHours()),k(t.getMinutes()),k(t.getSeconds())].join(":"),[t.getDate(),A[t.getMonth()],r].join(" ")),e.format.apply(e,arguments))},e.inherits=iI(),e._extend=function(e,t){if(!t||!w(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e};var T=typeof Symbol<"u"?Symbol("util.promisify.custom"):void 0;function x(e,t){if(!e){var r=new Error("Promise was rejected with a falsy value");r.reason=e,e=r}return t(e)}e.promisify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');if(T&&e[T]){var r;if("function"!=typeof(r=e[T]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(r,T,{value:r,enumerable:!1,writable:!1,configurable:!0}),r}function r(){for(var t,r,n=new Promise(function(e,n){t=e,r=n}),i=[],o=0;o<arguments.length;o++)i.push(arguments[o]);i.push(function(e,n){e?r(e):t(n)});try{e.apply(this,i)}catch(s){r(s)}return n}return Object.setPrototypeOf(r,Object.getPrototypeOf(e)),T&&Object.defineProperty(r,T,{value:r,enumerable:!1,writable:!1,configurable:!0}),Object.defineProperties(r,t(e))},e.promisify.custom=T,e.callbackify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');function r(){for(var t=[],r=0;r<arguments.length;r++)t.push(arguments[r]);var n=t.pop();if("function"!=typeof n)throw new TypeError("The last argument must be of type Function");var i=this,o=function(){return n.apply(i,arguments)};e.apply(this,t).then(function(e){K_.nextTick(o.bind(null,null,e))},function(e){K_.nextTick(x.bind(null,e,o))})}return Object.setPrototypeOf(r,Object.getPrototypeOf(e)),Object.defineProperties(r,t(e)),r}}(Ek)),Ek}var NA,RA,CA,HA,KA,zA,MA,DA,jA,FA,VA,qA,WA,$A,GA,XA,YA,ZA,QA,JA,eI,tI,rI,nI={exports:{}};function iI(){if(RA)return E_.exports;RA=1;try{var e=LA();if("function"!=typeof e.inherits)throw"";E_.exports=e.inherits}catch{E_.exports=(NA||(NA=1,"function"==typeof Object.create?nI.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:nI.exports=function(e,t){if(t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}}),nI.exports)}return E_.exports}function oI(){if(zA)return KA;zA=1;var e=Pk(),t=tA()("TypedArray.prototype.buffer",!0),r=PA();return KA=t||function(t){if(!r(t))throw new e("Not a Typed Array");return t.buffer}}function sI(){if(DA)return MA;DA=1;var e=tE().Buffer,t=function(){if(HA)return CA;HA=1;var e={}.toString;return CA=Array.isArray||function(t){return"[object Array]"==e.call(t)}}(),r=oI(),n=ArrayBuffer.isView||function(e){try{return r(e),!0}catch{return!1}},i=typeof Uint8Array<"u",o=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",s=o&&(e.prototype instanceof Uint8Array||e.TYPED_ARRAY_SUPPORT);return MA=function(r,a){if(e.isBuffer(r))return r.constructor&&!("isBuffer"in r)?e.from(r):r;if("string"==typeof r)return e.from(r,a);if(o&&n(r)){if(0===r.byteLength)return e.alloc(0);if(s){var u=e.from(r.buffer,r.byteOffset,r.byteLength);if(u.byteLength===r.byteLength)return u}var c=r instanceof Uint8Array?r:new Uint8Array(r.buffer,r.byteOffset,r.byteLength),f=e.from(c);if(f.length===r.byteLength)return f}if(i&&r instanceof Uint8Array)return e.from(r);var l=t(r);if(l)for(var h=0;h<r.length;h+=1){var p=r[h];if("number"!=typeof p||p<0||p>255||~~p!==p)throw new RangeError("Array items must be numbers in the range 0-255.")}if(l||e.isBuffer(r)&&r.constructor&&"function"==typeof r.constructor.isBuffer&&r.constructor.isBuffer(r))return e.from(r);throw new TypeError('The "data" argument must be a string, an Array, a Buffer, a Uint8Array, or a DataView.')}}function aI(){if(FA)return jA;FA=1;var e=tE().Buffer,t=sI();function r(t,r){this._block=e.alloc(t),this._finalSize=r,this._blockSize=t,this._len=0}return r.prototype.update=function(e,r){e=t(e,r||"utf8");for(var n=this._block,i=this._blockSize,o=e.length,s=this._len,a=0;a<o;){for(var u=s%i,c=Math.min(o-a,i-u),f=0;f<c;f++)n[u+f]=e[a+f];a+=c,(s+=c)%i===0&&this._update(n)}return this._len+=o,this},r.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=8*this._len;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(4294967295&r)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},r.prototype._update=function(){throw new Error("_update must be implemented by subclass")},jA=r}function uI(){if(XA)return GA;XA=1;var e=iI(),t=aI(),r=tE().Buffer,n=[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],i=new Array(64);function o(){this.init(),this._w=i,t.call(this,64,56)}function s(e,t,r){return r^e&(t^r)}function a(e,t,r){return e&t|r&(e|t)}function u(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function c(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function f(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function l(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}return e(o,t),o.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},o.prototype._update=function(e){for(var t=this._w,r=0|this._a,i=0|this._b,o=0|this._c,h=0|this._d,p=0|this._e,d=0|this._f,y=0|this._g,g=0|this._h,m=0;m<16;++m)t[m]=e.readInt32BE(4*m);for(;m<64;++m)t[m]=l(t[m-2])+t[m-7]+f(t[m-15])+t[m-16]|0;for(var b=0;b<64;++b){var w=g+c(p)+s(p,d,y)+n[b]+t[b]|0,v=u(r)+a(r,i,o)|0;g=y,y=d,d=p,p=h+w|0,h=o,o=i,i=r,r=w+v|0}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=h+this._d|0,this._e=p+this._e|0,this._f=d+this._f|0,this._g=y+this._g|0,this._h=g+this._h|0},o.prototype._hash=function(){var e=r.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e},GA=o}function cI(){if(JA)return QA;JA=1;var e=iI(),t=aI(),r=tE().Buffer,n=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],i=new Array(160);function o(){this.init(),this._w=i,t.call(this,128,112)}function s(e,t,r){return r^e&(t^r)}function a(e,t,r){return e&t|r&(e|t)}function u(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function c(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function f(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function l(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function h(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function p(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function d(e,t){return e>>>0<t>>>0?1:0}return e(o,t),o.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},o.prototype._update=function(e){for(var t=this._w,r=0|this._ah,i=0|this._bh,o=0|this._ch,y=0|this._dh,g=0|this._eh,m=0|this._fh,b=0|this._gh,w=0|this._hh,v=0|this._al,E=0|this._bl,_=0|this._cl,S=0|this._dl,k=0|this._el,A=0|this._fl,I=0|this._gl,T=0|this._hl,x=0;x<32;x+=2)t[x]=e.readInt32BE(4*x),t[x+1]=e.readInt32BE(4*x+4);for(;x<160;x+=2){var O=t[x-30],B=t[x-30+1],P=f(O,B),U=l(B,O),L=h(O=t[x-4],B=t[x-4+1]),N=p(B,O),R=t[x-14],C=t[x-14+1],H=t[x-32],K=t[x-32+1],z=U+C|0,M=P+R+d(z,U)|0;M=(M=M+L+d(z=z+N|0,N)|0)+H+d(z=z+K|0,K)|0,t[x]=M,t[x+1]=z}for(var D=0;D<160;D+=2){M=t[D],z=t[D+1];var j=a(r,i,o),F=a(v,E,_),V=u(r,v),q=u(v,r),W=c(g,k),$=c(k,g),G=n[D],X=n[D+1],Y=s(g,m,b),Z=s(k,A,I),Q=T+$|0,J=w+W+d(Q,T)|0;J=(J=(J=J+Y+d(Q=Q+Z|0,Z)|0)+G+d(Q=Q+X|0,X)|0)+M+d(Q=Q+z|0,z)|0;var ee=q+F|0,te=V+j+d(ee,q)|0;w=b,T=I,b=m,I=A,m=g,A=k,g=y+J+d(k=S+Q|0,S)|0,y=o,S=_,o=i,_=E,i=r,E=v,r=J+te+d(v=Q+ee|0,Q)|0}this._al=this._al+v|0,this._bl=this._bl+E|0,this._cl=this._cl+_|0,this._dl=this._dl+S|0,this._el=this._el+k|0,this._fl=this._fl+A|0,this._gl=this._gl+I|0,this._hl=this._hl+T|0,this._ah=this._ah+r+d(this._al,v)|0,this._bh=this._bh+i+d(this._bl,E)|0,this._ch=this._ch+o+d(this._cl,_)|0,this._dh=this._dh+y+d(this._dl,S)|0,this._eh=this._eh+g+d(this._el,k)|0,this._fh=this._fh+m+d(this._fl,A)|0,this._gh=this._gh+b+d(this._gl,I)|0,this._hh=this._hh+w+d(this._hl,T)|0},o.prototype._hash=function(){var e=r.allocUnsafe(64);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e},QA=o}rI||(rI=1,function(e){e.exports=function(t){var r=t.toLowerCase(),n=e.exports[r];if(!n)throw new Error(r+" is not supported (we accept pull requests)");return new n},e.exports.sha=function(){if(qA)return VA;qA=1;var e=iI(),t=aI(),r=tE().Buffer,n=[1518500249,1859775393,-1894007588,-899497514],i=new Array(80);function o(){this.init(),this._w=i,t.call(this,64,56)}function s(e){return e<<5|e>>>27}function a(e){return e<<30|e>>>2}function u(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}return e(o,t),o.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},o.prototype._update=function(e){for(var t=this._w,r=0|this._a,i=0|this._b,o=0|this._c,c=0|this._d,f=0|this._e,l=0;l<16;++l)t[l]=e.readInt32BE(4*l);for(;l<80;++l)t[l]=t[l-3]^t[l-8]^t[l-14]^t[l-16];for(var h=0;h<80;++h){var p=~~(h/20),d=s(r)+u(p,i,o,c)+f+t[h]+n[p]|0;f=c,c=o,o=a(i),i=r,r=d}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=c+this._d|0,this._e=f+this._e|0},o.prototype._hash=function(){var e=r.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e},VA=o}(),e.exports.sha1=function(){if($A)return WA;$A=1;var e=iI(),t=aI(),r=tE().Buffer,n=[1518500249,1859775393,-1894007588,-899497514],i=new Array(80);function o(){this.init(),this._w=i,t.call(this,64,56)}function s(e){return e<<1|e>>>31}function a(e){return e<<5|e>>>27}function u(e){return e<<30|e>>>2}function c(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}return e(o,t),o.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},o.prototype._update=function(e){for(var t=this._w,r=0|this._a,i=0|this._b,o=0|this._c,f=0|this._d,l=0|this._e,h=0;h<16;++h)t[h]=e.readInt32BE(4*h);for(;h<80;++h)t[h]=s(t[h-3]^t[h-8]^t[h-14]^t[h-16]);for(var p=0;p<80;++p){var d=~~(p/20),y=a(r)+c(d,i,o,f)+l+t[p]+n[d]|0;l=f,f=o,o=u(i),i=r,r=y}this._a=r+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=f+this._d|0,this._e=l+this._e|0},o.prototype._hash=function(){var e=r.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e},WA=o}(),e.exports.sha224=function(){if(ZA)return YA;ZA=1;var e=iI(),t=uI(),r=aI(),n=tE().Buffer,i=new Array(64);function o(){this.init(),this._w=i,r.call(this,64,56)}return e(o,t),o.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},o.prototype._hash=function(){var e=n.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e},YA=o}(),e.exports.sha256=uI(),e.exports.sha384=function(){if(tI)return eI;tI=1;var e=iI(),t=cI(),r=aI(),n=tE().Buffer,i=new Array(160);function o(){this.init(),this._w=i,r.call(this,128,112)}return e(o,t),o.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},o.prototype._hash=function(){var e=n.allocUnsafe(48);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e},eI=o}(),e.exports.sha512=cI()}(v_));const fI={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bech32Opnet:"op",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},lI={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bech32Opnet:"opr",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},hI={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bech32Opnet:"opt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function pI(e){let t,r;try{t=jy.bech32.decode(e)}catch{}if(t){if(r=t.words[0],0!==r)throw new TypeError(e+" uses wrong encoding")}else if(t=jy.bech32m.decode(e),r=t.words[0],0===r)throw new TypeError(e+" uses wrong encoding");const n=jy.bech32.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:nh.from(n)}}function dI(e,t){const r=e.length,n=t.length;if(0===r)throw new Error("R length is zero");if(0===n)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(r>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(n>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");const i=nh.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+r]=2,i[5+r]=t.length,t.copy(i,6+r),i}const yI={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},gI={};for(const _R of Object.keys(yI)){const e=yI[_R];gI[e]=_R}function mI(e){return e<yI.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function bI(e,t){const r=e.readUInt8(t);let n,i;if(r<yI.OP_PUSHDATA1)n=r,i=1;else if(r===yI.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===yI.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==yI.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}function wI(e){let t=Math.abs(e);const r=function(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}(t),n=nh.allocUnsafe(r),i=e<0;for(let o=0;o<r;++o)n.writeUInt8(255&t,o),t>>=8;return 128&n[r-1]?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}const vI=Object.freeze(Object.defineProperty({__proto__:null,decode:function(e,t,r){t=t||4,r=void 0===r||r;const n=e.length;if(0===n)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(127&e[n-1])&&(n<=1||!(128&e[n-2])))throw new Error("Non-minimally encoded script number");if(5===n){const t=e.readUInt32LE(0),r=e.readUInt8(4);return 128&r?-(4294967296*(-129&r)+t):4294967296*r+t}let i=0;for(let o=0;o<n;++o)i|=e[o]<<8*o;return 128&e[n-1]?-(i&~(128<<8*(n-1))):i},encode:wI},Symbol.toStringTag,{value:"Module"})),EI=ih.alloc(32,0),_I=ih.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function SI(e,t){return e.length===t.length&&e.every((e,r)=>e.equals(t[r]))}function kI(e){if(!ih.isBuffer(e)||e.length<33)return!1;const t=e[0],r=e.subarray(1,33);if(0===r.compare(EI)||r.compare(_I)>=0)return!1;if((2===t||3===t)&&33===e.length)return!0;if(65!==e.length)return!1;const n=e.subarray(33);return!(0===n.compare(EI)||n.compare(_I)>=0)&&(4===t||6===t||7===t)}function AI(e){return rg.UInt53(e)&&e<=21e14}const II=254;function TI(e){if(!e||"object"!=typeof e||!("output"in e))return!1;const t=e;return!!ih.isBuffer(t.output)&&(void 0===t.version||(t.version&II)===t.version)}function xI(e){return globalThis.Array.isArray(e)?2===e.length&&e.every(e=>xI(e)):TI(e)}rg.BufferN(32),rg.BufferN(20);const OI=rg.BufferN(32),BI=rg.Number,PI=rg.Array;rg.Boolean;const UI=rg.String,LI=rg.Buffer,NI=rg.Hex,RI=rg.maybe,CI=rg.tuple,HI=rg.UInt8,KI=rg.UInt32;rg.Function;const zI=rg.BufferN,MI=rg.Null;rg.oneOf;const DI=Object.freeze(Object.defineProperty({__proto__:null,Array:PI,Buffer:LI,BufferN:zI,Hash256bit:OI,Hex:NI,Null:MI,Number:BI,Satoshi:AI,String:UI,TAPLEAF_VERSION_MASK:II,UInt32:KI,UInt8:HI,isPoint:kI,isTapleaf:TI,isTaptree:xI,maybe:RI,stacksEqual:SI,tuple:CI,typeforce:rg},Symbol.toStringTag,{value:"Module"})),{typeforce:jI}=DI,FI=nh.alloc(1,0);function VI(e){const t=-129&e;return t>0&&t<4}function qI(e){let t=0;for(;0===e[t];)++t;return t===e.length?FI:128&(e=e.subarray(t))[0]?nh.concat([FI,e],1+e.length):e}function WI(e){0===e[0]&&(e=e.subarray(1));const t=nh.alloc(32,0),r=Math.max(0,32-e.length);return e.copy(t,r),t}const $I=Object.freeze(Object.defineProperty({__proto__:null,decode:function(e){const t=e.readUInt8(e.length-1);if(!VI(t))throw new Error(`Invalid hashType ${t}`);const r=function(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");const t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");const r=e[5+t];if(0===r)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(r>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.subarray(4,4+t),s:e.subarray(6+t)}}(e.subarray(0,-1)),n=WI(r.r),i=WI(r.s);return{signature:nh.concat([n,i],64),hashType:t}},encode:function(e,t){if(jI({signature:zI(64),hashType:HI},{signature:e,hashType:t}),!VI(t))throw new Error(`Invalid hashType ${t}`);const r=nh.allocUnsafe(1);r.writeUInt8(t,0);const n=qI(e.subarray(0,32)),i=qI(e.subarray(32,64));return nh.concat([dI(n,i),r])},isDefinedHashType:VI},Symbol.toStringTag,{value:"Module"})),{typeforce:GI}=DI,XI=yI.OP_RESERVED;function YI(e){return LI(e)||function(e){return BI(e)&&(e===yI.OP_0||e>=yI.OP_1&&e<=yI.OP_16||e===yI.OP_1NEGATE)}(e)}function ZI(e){return PI(e)&&e.every(YI)}function QI(e){return e.length-e.filter(YI).length}function JI(e){if(0===e.length)return yI.OP_0;if(1===e.length){if(e[0]>=1&&e[0]<=16)return XI+e[0];if(129===e[0])return yI.OP_1NEGATE}}function eT(e){return nh.isBuffer(e)}function tT(e){return nh.isBuffer(e)}function rT(e){if(eT(e))return e;GI(PI,e);const t=e.reduce((e,t)=>tT(t)?1===t.length&&void 0!==JI(t)?e+1:e+mI(t.length)+t.length:e+1,0),r=nh.allocUnsafe(t);let n=0;if(e.forEach(e=>{if(tT(e)){const t=JI(e);if(void 0!==t)return r.writeUInt8(t,n),void(n+=1);n+=function(e,t,r){const n=mI(t);return 1===n?e.writeUInt8(t,r):2===n?(e.writeUInt8(yI.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):3===n?(e.writeUInt8(yI.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(yI.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}(r,e.length,n),e.copy(r,n),n+=e.length}else r.writeUInt8(e,n),n+=1}),n!==r.length)throw new Error("Could not decode chunks");return r}function nT(e){if(function(e){return PI(e)}(e))return e;GI(LI,e);const t=[];let r=0;for(;r<e.length;){const n=e[r];if(n>yI.OP_0&&n<=yI.OP_PUSHDATA4){const n=bI(e,r);if(null===n||(r+=n.size,r+n.number>e.length))return null;const i=e.subarray(r,r+n.number);r+=n.number;const o=JI(i);void 0!==o?t.push(o):t.push(i)}else t.push(n),r+=1}return t}function iT(e){if(eT(e)&&(e=nT(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(e=>{if(tT(e)){const t=JI(e);if(void 0===t)return e.toString("hex");e=t}return gI[e]}).join(" ")}function oT(e){return e=nT(e),GI(ZI,e),e.map(e=>tT(e)?e:e===yI.OP_0?nh.allocUnsafe(0):wI(e-XI))}function sT(e){return kI(e)}function aT(e){return!(!nh.isBuffer(e)||!VI(e[e.length-1]))&&function(e){if(e.length<8||e.length>72||48!==e[0]||e[1]!==e.length-2||2!==e[2])return!1;const t=e[3];if(0===t||5+t>=e.length||2!==e[4+t])return!1;const r=e[5+t];return!(0===r||6+t+r!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||r>1&&0===e[t+6]&&!(128&e[t+7]))}(e.subarray(0,-1))}const uT=vI,cT=$I,fT=Object.freeze(Object.defineProperty({__proto__:null,compile:rT,countNonPushOnlyOPs:QI,decompile:nT,fromASM:function(e){return GI(UI,e),rT(e.split(" ").map(e=>void 0!==yI[e]?yI[e]:(GI(NI,e),nh.from(e,"hex"))))},isCanonicalPubKey:sT,isCanonicalScriptSignature:aT,isPushOnly:ZI,number:uT,opcodes:yI,signature:cT,toASM:iT,toStack:oT},Symbol.toStringTag,{value:"Module"}));var lT,hT;function pT(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const e=r.call(this);return this[t]=e,e},set(e){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:e,writable:!0})}})}function dT(e){let t;return()=>(void 0!==t||(t=e()),t)}(hT=lT||(lT={})).P2PK="p2pk",hT.P2PKH="p2pkh",hT.P2SH="p2sh",hT.P2MS="p2ms",hT.P2WPKH="p2wpkh",hT.P2WSH="p2wsh",hT.P2TR="p2tr",hT.P2OP="p2op",hT.Embed="embed",hT.ScriptRedeem="scriptRedeem";const yT=yI;function gT(e,t){if(!e.address&&!e.output&&!e.program&&(typeof e.deploymentVersion>"u"||!e.hash160))throw new TypeError("At least one of address, output or program must be provided");t=Object.assign({validate:!0},t||{}),rg({address:rg.maybe(rg.String),output:rg.maybe(rg.Buffer),program:rg.maybe(rg.Buffer),network:rg.maybe(rg.Object),deploymentVersion:rg.maybe(rg.Number),hash160:rg.maybe(rg.BufferN(20))},e);const r=()=>{if(typeof e.deploymentVersion<"u"&&typeof e.hash160<"u"){if(20!==e.hash160.length)throw new TypeError("hash160 must be exactly 20 bytes");if(e.deploymentVersion<0||e.deploymentVersion>255)throw new TypeError("deploymentVersion must fit in one byte");return nh.concat([nh.of(e.deploymentVersion),e.hash160])}},n=dT(()=>pI(e.address)),i=e.network||fI,o={name:lT.P2OP,network:i,deploymentVersion:0};if(pT(o,"program",()=>{if(e.program)return e.program;const t=r();if(t)return t;if(e.output){if(e.output[0]!==yT.OP_16)throw new TypeError("Invalid P2OP script");let t,r=1;if(e.output[1]<76)t=e.output[1],r=2;else{if(76!==e.output[1])throw new TypeError("Unsupported push opcode in P2OP script");t=e.output[2],r=3}return e.output.subarray(r,r+t)}return e.address?n().data:void 0}),pT(o,"deploymentVersion",()=>{if(o.program)return o.program[0]}),pT(o,"hash160",()=>{if(o.program)return o.program.subarray(1)}),pT(o,"output",()=>{if(o.program)return rT([yT.OP_16,o.program])}),pT(o,"address",()=>{if(!o.program)return;if(!i.bech32Opnet)throw new TypeError("Network does not support opnet");const e=jy.bech32m.toWords(o.program);return e.unshift(16),jy.bech32m.encode(i.bech32Opnet,e)}),t.validate){let t=ih.alloc(0);if(e.address){const e=n();if(i.bech32Opnet!==e.prefix)throw new TypeError("Invalid prefix or network mismatch");if(16!==e.version)throw new TypeError("Invalid witness version for p2op");if(e.data.length<2||e.data.length>40)throw new TypeError("Invalid witness program length");t=e.data}if(e.program){if(t.length&&!t.equals(e.program))throw new TypeError("Program mismatch");t=e.program}if(!t.length&&void 0!==e.deploymentVersion&&e.hash160&&(t=r()),e.output){const e=o.program;if(t.length&&!t.equals(e))throw new TypeError("Program mismatch (output vs other source)");t=e}if(t.length<2||t.length>40)throw new TypeError(`Witness program must be 2–40 bytes. Was ${t.length} bytes`);if(void 0!==e.deploymentVersion&&e.deploymentVersion!==t[0])throw new TypeError("deploymentVersion mismatch");if(e.hash160&&!e.hash160.equals(t.subarray(1)))throw new TypeError("hash160 mismatch")}return Object.assign(o,e)}function mT(e,t,r=""){const n=function(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}(e),i=e?.length;if(!n||void 0!==t){throw new Error((r&&`"${r}" `)+"expected Uint8Array"+""+", got "+(n?`length=${i}`:"type="+typeof e))}return e}function bT(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function wT(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function vT(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ET(e,t){return e<<32-t|e>>>t}function _T(e,t){return e<<t|e>>>32-t>>>0}function ST(e,t={}){const r=(t,r)=>e(r).update(t).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=t=>e(t),Object.assign(r,t),Object.freeze(r)}const kT=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function AT(e,t,r){return e&t^~e&r}function IT(e,t,r){return e&t^e&r^t&r}let TT=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,r,n){this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=vT(this.buffer)}update(e){bT(this),mT(e);const{view:t,buffer:r,blockLen:n}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s===n){const t=vT(e);for(;n<=i-o;o+=n)this.process(t,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){bT(this),function(e,t){mT(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,wT(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let f=o;f<n;f++)t[f]=0;r.setBigUint64(n-8,BigInt(8*this.length),i),this.process(r,0);const s=vT(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)s.setUint32(4*f,c[f],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}};const xT=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),OT=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),BT=new Uint32Array(80);class PT extends TT{A=0|OT[0];B=0|OT[1];C=0|OT[2];D=0|OT[3];E=0|OT[4];constructor(){super(64,20,8,!1)}get(){const{A:e,B:t,C:r,D:n,E:i}=this;return[e,t,r,n,i]}set(e,t,r,n,i){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i}process(e,t){for(let a=0;a<16;a++,t+=4)BT[a]=e.getUint32(t,!1);for(let a=16;a<80;a++)BT[a]=_T(BT[a-3]^BT[a-8]^BT[a-14]^BT[a-16],1);let{A:r,B:n,C:i,D:o,E:s}=this;for(let a=0;a<80;a++){let e,t;a<20?(e=AT(n,i,o),t=1518500249):a<40?(e=n^i^o,t=1859775393):a<60?(e=IT(n,i,o),t=2400959708):(e=n^i^o,t=3395469782);const u=_T(r,5)+e+s+t+BT[a]|0;s=o,o=i,i=_T(n,30),n=r,r=u}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,this.set(r,n,i,o,s)}roundClean(){wT(BT)}destroy(){this.set(0,0,0,0,0),wT(this.buffer)}}const UT=ST(()=>new PT),LT=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),NT=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),RT=NT.map(e=>(9*e+5)%16),CT=(()=>{const e=[[NT],[RT]];for(let t=0;t<4;t++)for(let r of e)r.push(r[t].map(e=>LT[e]));return e})(),HT=CT[0],KT=CT[1],zT=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),MT=HT.map((e,t)=>e.map(e=>zT[t][e])),DT=KT.map((e,t)=>e.map(e=>zT[t][e])),jT=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),FT=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function VT(e,t,r,n){return 0===e?t^r^n:1===e?t&r|~t&n:2===e?(t|~r)^n:3===e?t&n|r&~n:t^(r|~n)}const qT=new Uint32Array(16);class WT extends TT{h0=1732584193;h1=-271733879;h2=-1732584194;h3=271733878;h4=-1009589776;constructor(){super(64,20,8,!0)}get(){const{h0:e,h1:t,h2:r,h3:n,h4:i}=this;return[e,t,r,n,i]}set(e,t,r,n,i){this.h0=0|e,this.h1=0|t,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(e,t){for(let h=0;h<16;h++,t+=4)qT[h]=e.getUint32(t,!0);let r=0|this.h0,n=r,i=0|this.h1,o=i,s=0|this.h2,a=s,u=0|this.h3,c=u,f=0|this.h4,l=f;for(let h=0;h<5;h++){const e=4-h,t=jT[h],p=FT[h],d=HT[h],y=KT[h],g=MT[h],m=DT[h];for(let n=0;n<16;n++){const e=_T(r+VT(h,i,s,u)+qT[d[n]]+t,g[n])+f|0;r=f,f=u,u=0|_T(s,10),s=i,i=e}for(let r=0;r<16;r++){const t=_T(n+VT(e,o,a,c)+qT[y[r]]+p,m[r])+l|0;n=l,l=c,c=0|_T(a,10),a=o,o=t}}this.set(this.h1+s+c|0,this.h2+u+l|0,this.h3+f+n|0,this.h4+r+o|0,this.h0+i+a|0)}roundClean(){wT(qT)}destroy(){this.destroyed=!0,wT(this.buffer),this.set(0,0,0,0,0)}}const $T=ST(()=>new WT),GT=Uint32Array.from([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]),XT=new Uint32Array(64);class YT extends TT{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let f=0;f<16;f++,t+=4)XT[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){const e=XT[f-15],t=XT[f-2],r=ET(e,7)^ET(e,18)^e>>>3,n=ET(t,17)^ET(t,19)^t>>>10;XT[f]=n+XT[f-7]+r+XT[f-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let f=0;f<64;f++){const e=c+(ET(s,6)^ET(s,11)^ET(s,25))+AT(s,a,u)+GT[f]+XT[f]|0,t=(ET(r,2)^ET(r,13)^ET(r,22))+IT(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+t|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){wT(XT)}destroy(){this.set(0,0,0,0,0,0,0,0),wT(this.buffer)}}class ZT extends YT{A=0|xT[0];B=0|xT[1];C=0|xT[2];D=0|xT[3];E=0|xT[4];F=0|xT[5];G=0|xT[6];H=0|xT[7];constructor(){super(32)}}const QT=ST(()=>new ZT,kT(1));function JT(e){return nh.from($T(Uint8Array.from(e)))}function ex(e){return nh.from(UT(Uint8Array.from(e)))}function tx(e){return nh.from(QT(Uint8Array.from(e)))}function rx(e){return nh.from($T(QT(Uint8Array.from(e))))}function nx(e){return nh.from(QT(QT(Uint8Array.from(e))))}const ix={"BIP0340/challenge":nh.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":nh.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":nh.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:nh.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:nh.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:nh.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:nh.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":nh.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":nh.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function ox(e,t){return tx(nh.concat([ix[e],t]))}const sx=Object.freeze(Object.defineProperty({__proto__:null,TAGGED_HASH_PREFIXES:ix,TAGS:["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],hash160:rx,hash256:nx,ripemd160:JT,sha1:ex,sha256:tx,taggedHash:ox},Symbol.toStringTag,{value:"Module"})),{p:ax,n:ux,Gx:cx,Gy:fx,b:lx}={p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n},hx=(e="")=>{throw new Error(e)},px=e=>"bigint"==typeof e,dx=e=>"string"==typeof e,yx=(e,t)=>!(e=>e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name)(e)||"number"==typeof t&&t>0&&e.length!==t?hx("Uint8Array expected"):e,gx=e=>new Uint8Array(e),mx=(e,t)=>e.toString(16).padStart(t,"0"),bx=e=>Array.from(yx(e)).map(e=>mx(e,2)).join(""),wx=48,vx=57,Ex=65,_x=70,Sx=97,kx=102,Ax=e=>e>=wx&&e<=vx?e-wx:e>=Ex&&e<=_x?e-(Ex-10):e>=Sx&&e<=kx?e-(Sx-10):void 0,Ix=e=>{const t="hex invalid";if(!dx(e))return hx(t);const r=e.length,n=r/2;if(r%2)return hx(t);const i=gx(n);for(let o=0,s=0;o<n;o++,s+=2){const r=Ax(e.charCodeAt(s)),n=Ax(e.charCodeAt(s+1));if(void 0===r||void 0===n)return hx(t);i[o]=16*r+n}return i},Tx=(e,t)=>yx(dx(e)?Ix(e):(e=>Uint8Array.from(e))(yx(e)),t),xx=(...e)=>{const t=gx(e.reduce((e,t)=>e+yx(t).length,0));let r=0;return e.forEach(e=>{t.set(e,r),r+=e.length}),t},Ox=BigInt,Bx=(e,t,r,n="bad number: out of range")=>px(e)&&t<=e&&e<r?e:hx(n),Px=(e,t=ax)=>{const r=e%t;return r>=0n?r:t+r},Ux=e=>e instanceof Kx?e:hx("Point expected"),Lx=e=>Px(Px(e*e)*e+lx),Nx=e=>Bx(e,0n,ax),Rx=e=>Bx(e,1n,ax),Cx=e=>0n==(1n&e),Hx=e=>Uint8Array.of(e);class Kx{static BASE;static ZERO;px;py;pz;constructor(e,t,r){this.px=Nx(e),this.py=Rx(t),this.pz=Nx(r),Object.freeze(this)}static fromBytes(e){let t;yx(e);const r=e[0],n=e.subarray(1),i=jx(n,0,32),o=e.length;if(33===o&&[2,3].includes(r)){let e=(e=>{const t=Lx(Rx(e));let r=1n;for(let n=t,i=(ax+1n)/4n;i>0n;i>>=1n)1n&i&&(r=r*n%ax),n=n*n%ax;return Px(r*r)===t?r:hx("sqrt invalid")})(i);const n=Cx(e);Cx(Ox(r))!==n&&(e=Px(-e)),t=new Kx(i,e,1n)}return 65===o&&4===r&&(t=new Kx(i,jx(n,32,64),1n)),t?t.assertValidity():hx("bad point: not on curve")}equals(e){const{px:t,py:r,pz:n}=this,{px:i,py:o,pz:s}=Ux(e),a=Px(t*s),u=Px(i*n),c=Px(r*s),f=Px(o*n);return a===u&&c===f}is0(){return this.equals(Mx)}negate(){return new Kx(this.px,Px(-this.py),this.pz)}double(){return this.add(this)}add(e){const{px:t,py:r,pz:n}=this,{px:i,py:o,pz:s}=Ux(e);let a=0n,u=0n,c=0n;const f=Px(3n*lx);let l=Px(t*i),h=Px(r*o),p=Px(n*s),d=Px(t+r),y=Px(i+o);d=Px(d*y),y=Px(l+h),d=Px(d-y),y=Px(t+n);let g=Px(i+s);return y=Px(y*g),g=Px(l+p),y=Px(y-g),g=Px(r+n),a=Px(o+s),g=Px(g*a),a=Px(h+p),g=Px(g-a),c=Px(0n*y),a=Px(f*p),c=Px(a+c),a=Px(h-c),c=Px(h+c),u=Px(a*c),h=Px(l+l),h=Px(h+l),p=Px(0n*p),y=Px(f*y),h=Px(h+p),p=Px(l-p),p=Px(0n*p),y=Px(y+p),l=Px(h*y),u=Px(u+l),l=Px(g*y),a=Px(d*a),a=Px(a-l),l=Px(d*h),c=Px(g*c),c=Px(c+l),new Kx(a,u,c)}multiply(e,t=!0){if(!t&&0n===e)return Mx;if((e=>{Bx(e,1n,ux)})(e),1n===e)return this;if(this.equals(zx))return Xx(e).p;let r=Mx,n=zx;for(let i=this;e>0n;i=i.double(),e>>=1n)1n&e?r=r.add(i):t&&(n=n.add(i));return r}toAffine(){const{px:e,py:t,pz:r}=this;if(this.equals(Mx))return{x:0n,y:0n};if(1n===r)return{x:e,y:t};const n=((e,t)=>{(0n===e||t<=0n)&&hx("no inverse n="+e+" mod="+t);let r=Px(e,t),n=t,i=0n,o=1n;for(;0n!==r;){const e=n%r,t=i-o*(n/r);n=r,r=e,i=o,o=t}return 1n===n?Px(i,t):hx("no inverse")})(r,ax);return 1n!==Px(r*n)&&hx("inverse invalid"),{x:Px(e*n),y:Px(t*n)}}assertValidity(){const{x:e,y:t}=this.toAffine();return Rx(e),Rx(t),Px(t*t)===Lx(e)?this:hx("bad point: not on curve")}toBytes(e=!0){const{x:t,y:r}=this.assertValidity().toAffine(),n=Vx(t);return e?xx((e=>Hx(Cx(e)?2:3))(r),n):xx(Hx(4),n,Vx(r))}static fromAffine(e){const{x:t,y:r}=e;return 0n===t&&0n===r?Mx:new Kx(t,r,1n)}toHex(e){return bx(this.toBytes(e))}static fromPrivateKey(e){return zx.multiply(qx(e))}static fromHex(e){return Kx.fromBytes(Tx(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(e){return this.toBytes(e)}}const zx=new Kx(cx,fx,1n),Mx=new Kx(0n,1n,0n);Kx.BASE=zx,Kx.ZERO=Mx;const Dx=e=>Ox("0x"+(bx(e)||"0")),jx=(e,t,r)=>Dx(e.subarray(t,r)),Fx=2n**256n,Vx=e=>Ix(mx(Bx(e,0n,Fx),64)),qx=e=>{const t=px(e)?e:Dx(Tx(e,32));return Bx(t,1n,ux,"private key invalid 3")},Wx=Math.ceil(32)+1;let $x;const Gx=(e,t)=>{const r=t.negate();return e?r:t},Xx=e=>{const t=$x||($x=(()=>{const e=[];let t=zx,r=t;for(let n=0;n<Wx;n++){r=t,e.push(r);for(let n=1;n<128;n++)r=r.add(t),e.push(r);t=r.double()}return e})());let r=Mx,n=zx;const i=Ox(255),o=Ox(8);for(let s=0;s<Wx;s++){let a=Number(e&i);e>>=o,a>128&&(a-=256,e+=1n);const u=128*s,c=u,f=u+Math.abs(a)-1,l=s%2!=0,h=a<0;0===a?n=n.add(Gx(l,t[c])):r=r.add(Gx(h,t[f]))}return{p:r,f:n}},Yx=e=>{const t=32===e.length?e:e.subarray(1,33);return nh.isBuffer(t)?t:nh.from(t)};function Zx(e){let t=e.toString(16);return t=t.padStart(64,"0"),t.length>64&&(t=t.slice(-64)),nh.from(t,"hex")}function Qx(e){if(32===e.length)return;if(![33,65].includes(e.length))return void console.warn(`Unsupported key length=${e.length}. Must be 33 (compressed) or 65 (uncompressed).`);let t;try{t=Kx.fromHex(e)}catch{throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}const r=Zx(t.x),n=Zx(t.y),i=t.y%2n==0n?6:7,o=nh.alloc(65);o[0]=i,r.copy(o,1),n.copy(o,33);return{hybrid:o,uncompressed:nh.concat([nh.from([4]),r,n])}}function Jx(e,t){if(e.equals(t))return!0;if(65===e.length&&65===t.length){const r=nh.from(e),n=nh.from(t);return(6===r[0]||7===r[0])&&(r[0]=4),(6===n[0]||7===n[0])&&(n[0]=4),r.equals(n)}return!1}const eO=yI;function tO(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({network:rg.maybe(rg.Object),address:rg.maybe(rg.String),hash:rg.maybe(rg.BufferN(20)),output:rg.maybe(rg.BufferN(25)),pubkey:rg.maybe(kI),signature:rg.maybe(aT),input:rg.maybe(rg.Buffer)},e);const r=dT(()=>{const t=nh.from(Vy.decode(e.address));return{version:t.readUInt8(0),hash:t.subarray(1)}}),n=dT(()=>nT(e.input)),i=e.network||fI,o={name:lT.P2PKH,network:i,hash:void 0};if(pT(o,"address",()=>{if(!o.hash)return;const e=nh.allocUnsafe(21);return e.writeUInt8(i.pubKeyHash,0),o.hash.copy(e,1),Vy.encode(e)}),pT(o,"hash",()=>e.output?e.output.subarray(3,23):e.address?r().hash:e.pubkey||o.pubkey?rx(e.pubkey||o.pubkey):void 0),pT(o,"output",()=>{if(o.hash)return rT([eO.OP_DUP,eO.OP_HASH160,o.hash,eO.OP_EQUALVERIFY,eO.OP_CHECKSIG])}),pT(o,"pubkey",()=>{if(e.input)return n()[1]}),pT(o,"signature",()=>{if(e.input)return n()[0]}),pT(o,"input",()=>{if(!e.pubkey||!e.signature)return;let t=e.pubkey;if(e.useHybrid||e.useUncompressed){const r=Qx(e.pubkey);r&&(t=e.useUncompressed?r.uncompressed:r.hybrid)}return rT([e.signature,t])}),pT(o,"witness",()=>{if(o.input)return[]}),t.validate){let t=nh.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");t=r().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(25!==e.output.length||e.output[0]!==eO.OP_DUP||e.output[1]!==eO.OP_HASH160||20!==e.output[2]||e.output[23]!==eO.OP_EQUALVERIFY||e.output[24]!==eO.OP_CHECKSIG)throw new TypeError("Output is invalid");const r=e.output.subarray(3,23);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.pubkey){const r=rx(e.pubkey);let n=t.length>0&&!t.equals(r);if(n&&(33===e.pubkey.length&&(2===e.pubkey[0]||3===e.pubkey[0])||65===e.pubkey.length&&4===e.pubkey[0])){const r=Qx(e.pubkey);if(r){const i=rx(r.uncompressed);if(t.equals(i))n=!1,e.useUncompressed=!0;else{const i=rx(r.hybrid);n=!t.equals(i),n||(e.useHybrid=!0)}}}if(n)throw new TypeError("Hash mismatch");t=r}if(e.input){const r=n();if(2!==r.length)throw new TypeError("Input is invalid");if(!aT(r[0]))throw new TypeError("Input has invalid signature");if(!kI(r[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(r[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(r[1]))throw new TypeError("Pubkey mismatch");const i=rx(r[1]);if(t.length>0&&!t.equals(i))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,e)}const rO=yI;function nO(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.input))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({network:rg.maybe(rg.Object),address:rg.maybe(rg.String),hash:rg.maybe(rg.BufferN(20)),output:rg.maybe(rg.BufferN(23)),redeem:rg.maybe({network:rg.maybe(rg.Object),output:rg.maybe(rg.Buffer),input:rg.maybe(rg.Buffer),witness:rg.maybe(rg.arrayOf(rg.Buffer))}),input:rg.maybe(rg.Buffer),witness:rg.maybe(rg.arrayOf(rg.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||fI);const n={network:r,name:lT.P2SH},i=dT(()=>{const t=nh.from(Vy.decode(e.address));return{version:t.readUInt8(0),hash:t.subarray(1)}}),o=dT(()=>nT(e.input)),s=dT(()=>{const t=o(),n=t[t.length-1];return{network:r,output:n===rO.OP_FALSE?nh.from([]):n,input:rT(t.slice(0,-1)),witness:e.witness||[]}});if(pT(n,"address",()=>{if(!n.hash)return;const e=nh.allocUnsafe(21);return e.writeUInt8(n.network.scriptHash,0),n.hash.copy(e,1),Vy.encode(e)}),pT(n,"hash",()=>e.output?e.output.subarray(2,22):e.address?i().hash:n.redeem&&n.redeem.output?rx(n.redeem.output):void 0),pT(n,"output",()=>{if(n.hash)return rT([rO.OP_HASH160,n.hash,rO.OP_EQUAL])}),pT(n,"redeem",()=>{if(e.input)return s()}),pT(n,"input",()=>{if(e.redeem&&e.redeem.input&&e.redeem.output)return rT([].concat(nT(e.redeem.input),e.redeem.output))}),pT(n,"witness",()=>n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0),pT(n,"name",()=>{const e=["p2sh"];return void 0!==n.redeem&&void 0!==n.redeem.name&&e.push(n.redeem.name),e.join("-")}),t.validate){let t=nh.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");t=i().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(23!==e.output.length||e.output[0]!==rO.OP_HASH160||20!==e.output[1]||e.output[22]!==rO.OP_EQUAL)throw new TypeError("Output is invalid");const r=e.output.subarray(2,22);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}const n=e=>{if(e.output){const r=nT(e.output);if(!r||r.length<1)throw new TypeError("Redeem.output too short");if(e.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(QI(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=rx(e.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.input){const t=e.input.length>0,r=e.witness&&e.witness.length>0;if(!t&&!r)throw new TypeError("Empty input");if(t&&r)throw new TypeError("Input and witness provided");if(t){if(!ZI(nT(e.input)))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const e=o();if(!e||e.length<1)throw new TypeError("Input too short");if(!nh.isBuffer(s().output))throw new TypeError("Input is invalid");n(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const t=s();if(e.redeem.output&&!e.redeem.output.equals(t.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(t.input))throw new TypeError("Redeem.input mismatch")}n(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!SI(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}const iO={};function oO(e){e?e!==iO.eccLib&&(function(e){uO("function"==typeof e.isXOnlyPoint),uO(e.isXOnlyPoint(aO("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),uO(e.isXOnlyPoint(aO("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),uO(e.isXOnlyPoint(aO("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),uO(e.isXOnlyPoint(aO("0000000000000000000000000000000000000000000000000000000000000001"))),uO(!e.isXOnlyPoint(aO("0000000000000000000000000000000000000000000000000000000000000000"))),uO(!e.isXOnlyPoint(aO("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),uO("function"==typeof e.xOnlyPointAddTweak),cO.forEach(t=>{const r=e.xOnlyPointAddTweak(aO(t.pubkey),aO(t.tweak));null===t.result?uO(null===r):(uO(null!==r),uO(r.parity===t.parity),uO(nh.from(r.xOnlyPubkey).equals(aO(t.result))))})}(e),iO.eccLib=e):iO.eccLib=e}function sO(){if(!iO.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return iO.eccLib}const aO=e=>nh.from(e,"hex");function uO(e){if(!e)throw new Error("ecc library invalid")}const cO=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}],{typeforce:fO}=DI;function lO(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function hO(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}function pO(e){const t=nh.allocUnsafe(e.length);return e.copy(t),t}let dO=class e{constructor(e,t=0){this.buffer=e,this.offset=t,fO(CI(LI,KI),[e,t])}static withCapacity(t){return new e(nh.alloc(t))}writeUInt8(e){this.offset=this.buffer.writeUInt8(e,this.offset)}writeInt32(e){this.offset=this.buffer.writeInt32LE(e,this.offset)}writeUInt32(e){this.offset=this.buffer.writeUInt32LE(e,this.offset)}writeUInt64(e){this.offset=function(e,t,r){return lO(t,9007199254740991),e.writeInt32LE(-1&t,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}(this.buffer,e,this.offset)}writeVarInt(e){const t=og(e,this.buffer,this.offset);this.offset+=t.bytes}writeSlice(e){if(this.buffer.length<this.offset+e.length)throw new Error("Cannot write slice out of bounds");this.offset+=e.copy(this.buffer,this.offset)}writeVarSlice(e){this.writeVarInt(e.length),this.writeSlice(e)}writeVector(e){this.writeVarInt(e.length),e.forEach(e=>this.writeVarSlice(e))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}};class yO{constructor(e,t=0){this.buffer=e,this.offset=t,fO(CI(LI,KI),[e,t])}readUInt8(){const e=this.buffer.readUInt8(this.offset);return this.offset++,e}readInt32(){const e=this.buffer.readInt32LE(this.offset);return this.offset+=4,e}readUInt32(){const e=this.buffer.readUInt32LE(this.offset);return this.offset+=4,e}readUInt64(){const e=function(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,lO(n+r,9007199254740991),n+r}(this.buffer,this.offset);return this.offset+=8,e}readVarInt(){const e=sg(this.buffer,this.offset);return this.offset+=e.bytes,e.numberValue||0}readSlice(e){if(this.buffer.length<this.offset+e)throw new Error("Cannot read slice out of bounds");const t=nh.from(this.buffer.subarray(this.offset,this.offset+e));return this.offset+=e,t}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const e=this.readVarInt(),t=[];for(let r=0;r<e;r++)t.push(this.readVarSlice());return t}}function gO(e,t){if(e.length<33)throw new TypeError(`The control-block length is too small. Got ${e.length}, expected min 33.`);const r=(e.length-33)/32;let n=t;for(let i=0;i<r;i++){const t=e.subarray(33+32*i,65+32*i);n=n.compare(t)<0?_O(n,t):_O(t,n)}return n}function mO(e){if(TI(e))return{hash:wO(e)};const t=[mO(e[0]),mO(e[1])];t.sort((e,t)=>e.hash.compare(t.hash));const[r,n]=t;return{hash:_O(r.hash,n.hash),left:r,right:n}}function bO(e,t){if((e=>"left"in e&&"right"in e)(e)){const r=bO(e.left,t);if(void 0!==r)return[...r,e.right.hash];const n=bO(e.right,t);if(void 0!==n)return[...n,e.left.hash]}else if(e.hash.equals(t))return[]}function wO(e){const t=e.version||192;return ox("TapLeaf",ih.concat([ih.from([t]),SO(e.output)]))}function vO(e,t){return ox("TapTweak",ih.concat(t?[e,t]:[e]))}function EO(e,t){if(!ih.isBuffer(e)||32!==e.length||t&&32!==t.length)return null;const r=vO(e,t),n=sO().xOnlyPointAddTweak(e,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:ih.from(n.xOnlyPubkey)}:null}function _O(e,t){return ox("TapBranch",ih.concat([e,t]))}function SO(e){const t=ag(e.length),r=ih.allocUnsafe(t);return og(e.length,r),ih.concat([r,e])}const kO=yI;function AO(e,t){if(!(e.address||e.output||e.pubkey||e.internalPubkey||e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({address:rg.maybe(rg.String),input:rg.maybe(rg.BufferN(0)),network:rg.maybe(rg.Object),output:rg.maybe(rg.BufferN(34)),internalPubkey:rg.maybe(rg.BufferN(32)),hash:rg.maybe(rg.BufferN(32)),pubkey:rg.maybe(rg.BufferN(32)),signature:rg.maybe(rg.anyOf(rg.BufferN(64),rg.BufferN(65))),witness:rg.maybe(rg.arrayOf(rg.Buffer)),scriptTree:rg.maybe(xI),redeem:rg.maybe({output:rg.maybe(rg.Buffer),redeemVersion:rg.maybe(rg.Number),witness:rg.maybe(rg.arrayOf(rg.Buffer))}),redeemVersion:rg.maybe(rg.Number)},e);const r=dT(()=>pI(e.address)),n=dT(()=>{if(e.witness&&e.witness.length)return e.witness.length>=2&&80===e.witness[e.witness.length-1][0]?e.witness.slice(0,-1):e.witness.slice()}),i=dT(()=>e.scriptTree?mO(e.scriptTree):e.hash?{hash:e.hash}:void 0),o=e.network||fI,s={name:lT.P2TR,network:o};if(pT(s,"address",()=>{if(!s.pubkey)return;const e=jy.bech32m.toWords(s.pubkey);return e.unshift(1),jy.bech32m.encode(o.bech32,e)}),pT(s,"hash",()=>{const e=i();if(e)return e.hash;const t=n();if(t&&t.length>1){const e=t[t.length-1],r=e[0]&II;return gO(e,wO({output:t[t.length-2],version:r}))}}),pT(s,"output",()=>{if(s.pubkey)return rT([kO.OP_1,s.pubkey])}),pT(s,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&void 0!==e.redeem.redeemVersion&&null!==e.redeem.redeemVersion?e.redeem.redeemVersion:192),pT(s,"redeem",()=>{const e=n();if(e&&!(e.length<2))return{output:e[e.length-2],witness:e.slice(0,-2),redeemVersion:e[e.length-1][0]&II}}),pT(s,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.subarray(2);if(e.address)return r().data;if(s.internalPubkey){const e=EO(s.internalPubkey,s.hash);if(e)return e.x}}),pT(s,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const t=n();return t&&t.length>1?t[t.length-1].subarray(1,33):void 0}),pT(s,"signature",()=>{if(e.signature)return e.signature;const t=n();return t&&1===t.length?t[0]:void 0}),pT(s,"witness",()=>{if(e.witness)return e.witness;const t=i();if(t&&e.redeem&&e.redeem.output&&e.internalPubkey){const r=bO(t,wO({output:e.redeem.output,version:s.redeemVersion}));if(!r)return;const n=EO(e.internalPubkey,t.hash);if(!n)return;const i=ih.concat([ih.from([s.redeemVersion|n.parity]),e.internalPubkey].concat(r));return[e.redeem.output,i]}return e.signature?[e.signature]:void 0}),t.validate){let t=ih.from([]);if(e.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(1!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.pubkey){if(t.length>0&&!t.equals(e.pubkey))throw new TypeError("Pubkey mismatch");t=e.pubkey}if(e.output){if(34!==e.output.length||e.output[0]!==kO.OP_1||32!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.subarray(2)))throw new TypeError("Pubkey mismatch");t=e.output.subarray(2)}if(e.internalPubkey){const r=EO(e.internalPubkey,s.hash);if(t.length>0&&!t.equals(r.x))throw new TypeError("Pubkey mismatch");t=r.x}const a=i();if(e.hash&&a&&!e.hash.equals(a.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&a){if(!bO(a,wO({output:e.redeem.output,version:s.redeemVersion})))throw new TypeError("Redeem script not in tree")}const u=n();if(e.redeem&&s.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==s.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(0===nT(e.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(s.redeem.output&&!e.redeem.output.equals(s.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&s.redeem.witness&&!SI(e.redeem.witness,s.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(1===u.length){if(e.signature&&!e.signature.equals(u[0]))throw new TypeError("Signature mismatch")}else{const r=u[u.length-1];if(r.length<33)throw new TypeError(`The control-block length is too small. Got ${r.length}, expected min 33.`);if((r.length-33)%32!=0)throw new TypeError(`The control-block length of ${r.length} is incorrect!`);const n=(r.length-33)/32;if(n>128)throw new TypeError(`The script path is too long. Got ${n}, expected max 128.`);const i=r.subarray(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(i))throw new TypeError("Internal pubkey mismatch");if(!sO().isXOnlyPoint(i))throw new TypeError("Invalid internalPubkey for p2tr witness");const o=r[0]&II,s=EO(i,gO(r,wO({output:u[u.length-2],version:o})));if(!s)throw new TypeError("Invalid outputKey for p2tr witness");if(t.length&&!t.equals(s.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(s.parity!==(1&r[0]))throw new Error("Incorrect parity")}}return Object.assign(s,e)}const IO=yI,TO=nh.alloc(0);function xO(e,t){if(!(e.address||e.hash||e.output||e.pubkey||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({address:rg.maybe(rg.String),hash:rg.maybe(rg.BufferN(20)),input:rg.maybe(rg.BufferN(0)),network:rg.maybe(rg.Object),output:rg.maybe(rg.BufferN(22)),pubkey:rg.maybe(kI),signature:rg.maybe(aT),witness:rg.maybe(rg.arrayOf(rg.Buffer))},e);const r=dT(()=>{const t=jy.bech32.decode(e.address),r=t.words.shift(),n=jy.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:nh.from(n)}}),n=e.network||fI,i={name:lT.P2WPKH,network:n};if(pT(i,"address",()=>{if(!i.hash)return;const e=jy.bech32.toWords(i.hash);return e.unshift(0),jy.bech32.encode(n.bech32,e)}),pT(i,"hash",()=>e.output?e.output.subarray(2,22):e.address?r().data:e.pubkey||i.pubkey?rx(e.pubkey||i.pubkey):void 0),pT(i,"output",()=>{if(i.hash)return rT([IO.OP_0,i.hash])}),pT(i,"pubkey",()=>e.pubkey?e.pubkey:e.witness?e.witness[1]:void 0),pT(i,"signature",()=>{if(e.witness)return e.witness[0]}),pT(i,"input",()=>{if(i.witness)return TO}),pT(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let t=nh.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(20!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(22!==e.output.length||e.output[0]!==IO.OP_0||20!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.subarray(2)))throw new TypeError("Hash mismatch");t=e.output.subarray(2)}if(e.pubkey){const r=rx(e.pubkey);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");if(t=r,!kI(e.pubkey)||33!==e.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(2!==e.witness.length)throw new TypeError("Witness is invalid");if(!aT(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!kI(e.witness[1])||33!==e.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const r=rx(e.witness[1]);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}const OO=yI,BO=nh.alloc(0);function PO(e){return!(!nh.isBuffer(e)||65!==e.length||4!==e[0]||!kI(e))}function UO(e,t){if(!(e.address||e.hash||e.output||e.redeem||e.witness))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({network:rg.maybe(rg.Object),address:rg.maybe(rg.String),hash:rg.maybe(rg.BufferN(32)),output:rg.maybe(rg.BufferN(34)),redeem:rg.maybe({input:rg.maybe(rg.Buffer),network:rg.maybe(rg.Object),output:rg.maybe(rg.Buffer),witness:rg.maybe(rg.arrayOf(rg.Buffer))}),input:rg.maybe(rg.BufferN(0)),witness:rg.maybe(rg.arrayOf(rg.Buffer))},e);const r=dT(()=>{const t=jy.bech32.decode(e.address),r=t.words.shift(),n=jy.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:nh.from(n)}}),n=dT(()=>nT(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||fI);const o={network:i,name:lT.P2WSH};if(pT(o,"address",()=>{if(!o.hash)return;const e=jy.bech32.toWords(o.hash);return e.unshift(0),jy.bech32.encode(i.bech32,e)}),pT(o,"hash",()=>e.output?e.output.subarray(2):e.address?r().data:o.redeem&&o.redeem.output?tx(o.redeem.output):void 0),pT(o,"output",()=>{if(o.hash)return rT([OO.OP_0,o.hash])}),pT(o,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:BO,witness:e.witness.slice(0,-1)}}),pT(o,"input",()=>{if(o.witness)return BO}),pT(o,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const t=oT(n());return o.redeem=Object.assign({witness:t},e.redeem),o.redeem.input=BO,[].concat(t,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),pT(o,"name",()=>{const e=["p2wsh"];return void 0!==o.redeem&&void 0!==o.redeem.name&&e.push(o.redeem.name),e.join("-")}),t.validate){let t=nh.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(34!==e.output.length||e.output[0]!==OO.OP_0||32!==e.output[1])throw new TypeError("Output is invalid");const r=e.output.subarray(2);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const r=nT(e.redeem.output);if(!r||r.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(QI(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=tx(e.redeem.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem.input&&!ZI(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!SI(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(PO)||e.redeem.output&&(nT(e.redeem.output)||[]).some(PO))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const t=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(t))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(PO)||(nT(t)||[]).some(PO))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)}const LO=e=>{try{const t=nh.from(e.subarray(2));if(t.length<2||t.length>40)throw new TypeError("Invalid program length for segwit address");const r=e[0]-80;if(r<2||r>16)throw new TypeError("Invalid version for segwit address");if(1===r)throw new TypeError("taproot");return!0}catch{}return!1};function NO(e,t){const r=nh.from(e.subarray(2));if(r.length<2||r.length>40)throw new TypeError("Invalid program length for segwit address");const n=e[0]-80;if(n<2||n>15)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError(`Invalid script for segwit address ${e[1]} !== ${r.length}`);return function(e,t,r,n){const i=jy.bech32.toWords(e);return i.unshift(t),16===t&&n?jy.bech32m.encode(n,i):0===t?jy.bech32.encode(r,i):jy.bech32m.encode(r,i)}(r,n,t.bech32,t.bech32Opnet)}function RO(e){const t=nh.from(Vy.decode(e));if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");return{version:t.readUInt8(0),hash:nh.from(t.subarray(1))}}function CO(e,t){t=t||fI;try{return tO({output:e,network:t}).address}catch{}try{return nO({output:e,network:t}).address}catch{}try{return xO({output:e,network:t}).address}catch{}try{return UO({output:e,network:t}).address}catch{}try{return AO({output:e,network:t}).address}catch{}try{return function(e,t){if(!nh.isBuffer(e))throw new TypeError("output must be a Buffer");if(!t.bech32Opnet)throw new Error("Network does not support opnet");const r=e[0];let n,i=1;if(e[1]<76)n=e[1],i=2;else{if(76!==e[1])throw new TypeError("Unsupported push opcode in script");n=e[2],i=3}const o=nh.from(e.subarray(i,i+n));if(o.length<2||o.length>40)throw new TypeError("Invalid program length for segwit address");const s=r===yI.OP_0?0:r>=yI.OP_1&&r<=yI.OP_16?r-(yI.OP_1-1):-1;if(s<15||s>16)throw new TypeError(`Invalid segwit version ${s}`);const a=[s,...jy.bech32m.toWords(o)];return jy.bech32m.encode(t.bech32Opnet,a)}(e,t)}catch{}try{return NO(e,t)}catch{}throw new Error(iT(e)+" has no matching Address")}function HO(e,t){let r,n;t=t||fI;try{r=RO(e)}catch{}if(r){if(r.version===t.pubKeyHash)return tO({hash:r.hash}).output;if(r.version===t.scriptHash)return nO({hash:r.hash}).output}else{try{n=pI(e)}catch{}if(n){if(n.prefix!==t.bech32&&t.bech32Opnet&&n.prefix!==t.bech32Opnet)throw new Error(e+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return xO({hash:n.data}).output;if(32===n.data.length)return UO({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return AO({pubkey:n.data}).output}else{if(16===n.version){if(!t.bech32Opnet)throw new Error(e+" has an invalid prefix");return gT({program:n.data,network:t}).output}if(n.version>=2&&n.version<=15&&n.data.length>=2&&n.data.length<=40)return 16!==n.version&&console.warn("WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit."),rT([n.version+80,n.data])}}}throw new TypeError(e+" has no matching Script")}const KO=yI;const zO=yI,MO=zO.OP_RESERVED;function DO(e,t){if(!(e.input||e.output||e.pubkeys&&void 0!==e.m||e.signatures))throw new TypeError("Not enough data");function r(e){return aT(e)||void 0!==(t.allowIncomplete&&e===zO.OP_0)}t=Object.assign({validate:!0},t||{}),rg({network:rg.maybe(rg.Object),m:rg.maybe(rg.Number),n:rg.maybe(rg.Number),output:rg.maybe(rg.Buffer),pubkeys:rg.maybe(rg.arrayOf(kI)),signatures:rg.maybe(rg.arrayOf(r)),input:rg.maybe(rg.Buffer)},e);const n={network:e.network||fI,name:lT.P2MS};let i=[],o=!1;function s(e){o||(o=!0,i=nT(e),n.m=i[0]-MO,n.n=i[i.length-2]-MO,n.pubkeys=i.slice(1,-2))}if(pT(n,"output",()=>{if(e.m&&n.n&&e.pubkeys)return rT([].concat(MO+e.m,e.pubkeys,MO+n.n,zO.OP_CHECKMULTISIG))}),pT(n,"m",()=>{if(n.output)return s(n.output),n.m}),pT(n,"n",()=>{if(n.pubkeys)return n.pubkeys.length}),pT(n,"pubkeys",()=>{if(e.output)return s(e.output),n.pubkeys}),pT(n,"signatures",()=>{if(!e.input)return;const t=nT(e.input);return null!=t?t.slice(1):void 0}),pT(n,"input",()=>{if(e.signatures)return rT([zO.OP_0].concat(e.signatures))}),pT(n,"witness",()=>{if(n.input)return[]}),pT(n,"name",()=>{if(n.m&&n.n)return`p2ms(${n.m} of ${n.n})`}),t.validate){if(e.output){if(s(e.output),!rg.Number(i[0]))throw new TypeError("Output is invalid");if(!rg.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==zO.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every(e=>kI(e)))throw new TypeError("Output is invalid");if(void 0!==e.m&&e.m!==n.m)throw new TypeError("m mismatch");if(void 0!==e.n&&e.n!==n.n)throw new TypeError("n mismatch");if(e.pubkeys&&!SI(e.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(void 0!==e.n&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=e.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==zO.OP_0)throw new TypeError("Input is invalid");if(0===n.signatures.length||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!SI(e.signatures,n.signatures))throw new TypeError("Signature mismatch");if(void 0!==e.m&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,e)}const jO=yI;function FO(e,t){if(!(e.input||e.output||e.pubkey||e.input||e.signature))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({network:rg.maybe(rg.Object),output:rg.maybe(rg.Buffer),pubkey:rg.maybe(kI),signature:rg.maybe(aT),input:rg.maybe(rg.Buffer)},e);const r=dT(()=>nT(e.input)),n=e.network||fI,i={name:lT.P2PK,network:n,pubkey:void 0};if(pT(i,"output",()=>{if(e.pubkey)return rT([e.pubkey,jO.OP_CHECKSIG])}),pT(i,"pubkey",()=>{if(e.output)return e.output.subarray(1,-1)}),pT(i,"signature",()=>{if(e.input)return r()[0]}),pT(i,"input",()=>{if(e.signature)return rT([e.signature])}),pT(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==jO.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!kI(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(i.input))throw new TypeError("Signature mismatch");if(e.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!aT(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}const VO=Object.freeze(Object.defineProperty({__proto__:null,LEAF_VERSION_TAPSCRIPT:192,MAX_TAPTREE_DEPTH:128,get PaymentType(){return lT},findScriptPath:bO,p2data:function(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rg({network:rg.maybe(rg.Object),output:rg.maybe(rg.Buffer),data:rg.maybe(rg.arrayOf(rg.Buffer))},e);const r=e.network||fI,n={name:lT.Embed,network:r,data:[]};if(pT(n,"output",()=>{if(e.data)return rT([KO.OP_RETURN].concat(e.data))}),pT(n,"data",()=>{if(!e.output)return;const t=nT(e.output);return null!=t?t.slice(1):void 0}),t.validate&&e.output){const t=nT(e.output);if(t[0]!==KO.OP_RETURN)throw new TypeError("Output is invalid");if(!t.slice(1).every(rg.Buffer))throw new TypeError("Output is invalid");if(e.data&&!SI(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)},p2ms:DO,p2op:gT,p2pk:FO,p2pkh:tO,p2sh:nO,p2tr:AO,p2wpkh:xO,p2wsh:UO,prop:pT,rootHashFromPath:gO,tapleafHash:wO,toHashTree:mO,tweakKey:EO,value:dT},Symbol.toStringTag,{value:"Module"})),{typeforce:qO}=DI;function WO(e){const t=e.length;return ag(t)+t}const $O=nh.allocUnsafe(0),GO=[],XO=nh.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),YO=nh.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),ZO=nh.from("ffffffffffffffff","hex"),QO={script:$O,valueBuffer:ZO};class JO{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(e,t){const r=new yO(e),n=new JO;n.version=r.readInt32();const i=r.readUInt8(),o=r.readUInt8();let s=!1;i===JO.ADVANCED_TRANSACTION_MARKER&&o===JO.ADVANCED_TRANSACTION_FLAG?s=!0:r.offset-=2;const a=r.readVarInt();for(let c=0;c<a;++c){const e=r.readSlice(32),t=r.readUInt32(),i=r.readVarSlice(),o=r.readUInt32();n.ins.push({hash:e,index:t,script:i,sequence:o,witness:GO})}const u=r.readVarInt();for(let c=0;c<u;++c)n.outs.push({value:r.readUInt64(),script:r.readVarSlice()});if(s){for(let e=0;e<a;++e)n.ins[e].witness=r.readVector();if(!n.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(n.locktime=r.readUInt32(),t)return n;if(r.offset!==e.length)throw new Error("Transaction has unexpected data");return n}static fromHex(e){return JO.fromBuffer(nh.from(e,"hex"),!1)}static isCoinbaseHash(e){qO(OI,e);for(let t=0;t<32;++t)if(0!==e[t])return!1;return!0}isCoinbase(){return 1===this.ins.length&&JO.isCoinbaseHash(this.ins[0].hash)}addInput(e,t,r,n){return qO(CI(OI,KI,RI(KI),RI(LI)),[e,t,r,n]),MI(r)&&(r=JO.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:t,script:n||$O,sequence:r,witness:GO})-1}addOutput(e,t){return qO(CI(LI,AI),[e,t]),this.outs.push({script:e,value:t})-1}hasWitnesses(){return this.ins.some(e=>0!==e.witness.length)}weight(){return 3*this.byteLength(!1)+this.byteLength(!0)}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(e=!0){const t=e&&this.hasWitnesses();return(t?10:8)+ag(this.ins.length)+ag(this.outs.length)+this.ins.reduce((e,t)=>e+40+WO(t.script),0)+this.outs.reduce((e,t)=>e+8+WO(t.script),0)+(t?this.ins.reduce((e,t)=>e+function(e){return ag(e.length)+e.reduce((e,t)=>e+WO(t),0)}(t.witness),0):0)}clone(){const e=new JO;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map(e=>({hash:e.hash,index:e.index,script:e.script,sequence:e.sequence,witness:e.witness})),e.outs=this.outs.map(e=>({script:e.script,value:e.value})),e}hashForSignature(e,t,r){if(qO(CI(KI,LI,BI),[e,t,r]),e>=this.ins.length)return YO;const n=nT(t);if(!n)throw new Error("Could not decompile prevOutScript");const i=rT(n.filter(e=>e!==yI.OP_CODESEPARATOR)),o=this.clone();if((31&r)===JO.SIGHASH_NONE)o.outs=[],o.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)});else if((31&r)===JO.SIGHASH_SINGLE){if(e>=this.outs.length)return YO;o.outs.length=e+1;for(let t=0;t<e;t++)o.outs[t]=QO;o.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)})}r&JO.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[e]],o.ins[0].script=i):(o.ins.forEach(e=>{e.script=$O}),o.ins[e].script=i);const s=nh.allocUnsafe(o.byteLength(!1)+4);return s.writeInt32LE(r,s.length-4),o.__toBuffer(s,0,!1),nx(s)}hashForWitnessV1(e,t,r,n,i,o){if(qO(CI(KI,qO.arrayOf(LI),qO.arrayOf(AI),KI),[e,t,r,n]),r.length!==this.ins.length||t.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const s=n===JO.SIGHASH_DEFAULT?JO.SIGHASH_ALL:n&JO.SIGHASH_OUTPUT_MASK,a=(n&JO.SIGHASH_INPUT_MASK)===JO.SIGHASH_ANYONECANPAY,u=s===JO.SIGHASH_NONE,c=s===JO.SIGHASH_SINGLE;let f=$O,l=$O,h=$O,p=$O,d=$O;if(!a){let e=dO.withCapacity(36*this.ins.length);this.ins.forEach(t=>{e.writeSlice(t.hash),e.writeUInt32(t.index)}),f=tx(e.end()),e=dO.withCapacity(8*this.ins.length),r.forEach(t=>e.writeUInt64(t)),l=tx(e.end()),e=dO.withCapacity(t.map(WO).reduce((e,t)=>e+t)),t.forEach(t=>e.writeVarSlice(t)),h=tx(e.end()),e=dO.withCapacity(4*this.ins.length),this.ins.forEach(t=>e.writeUInt32(t.sequence)),p=tx(e.end())}if(u||c){if(c&&e<this.outs.length){const t=this.outs[e],r=dO.withCapacity(8+WO(t.script));r.writeUInt64(t.value),r.writeVarSlice(t.script),d=tx(r.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const e=this.outs.map(e=>8+WO(e.script)).reduce((e,t)=>e+t),t=dO.withCapacity(e);this.outs.forEach(e=>{t.writeUInt64(e.value),t.writeVarSlice(e.script)}),d=tx(t.end())}const y=(i?2:0)+(o?1:0),g=174-(a?49:0)-(u?32:0)+(o?32:0)+(i?37:0),m=dO.withCapacity(g);if(m.writeUInt8(n),m.writeInt32(this.version),m.writeUInt32(this.locktime),m.writeSlice(f),m.writeSlice(l),m.writeSlice(h),m.writeSlice(p),u||c||m.writeSlice(d),m.writeUInt8(y),a){const n=this.ins[e];m.writeSlice(n.hash),m.writeUInt32(n.index),m.writeUInt64(r[e]),m.writeVarSlice(t[e]),m.writeUInt32(n.sequence)}else m.writeUInt32(e);if(o){const e=dO.withCapacity(WO(o));e.writeVarSlice(o),m.writeSlice(tx(e.end()))}return c&&m.writeSlice(d),i&&(m.writeSlice(i),m.writeUInt8(0),m.writeUInt32(4294967295)),ox("TapSighash",nh.concat([nh.from([0]),m.end()]))}hashForWitnessV0(e,t,r,n){qO(CI(KI,LI,AI,KI),[e,t,r,n]);let i,o=nh.from([]),s=XO,a=XO,u=XO;if(n&JO.SIGHASH_ANYONECANPAY||(o=nh.allocUnsafe(36*this.ins.length),i=new dO(o,0),this.ins.forEach(e=>{i.writeSlice(e.hash),i.writeUInt32(e.index)}),a=nx(o)),!(n&JO.SIGHASH_ANYONECANPAY)&&(31&n)!==JO.SIGHASH_SINGLE&&(31&n)!==JO.SIGHASH_NONE&&(o=nh.allocUnsafe(4*this.ins.length),i=new dO(o,0),this.ins.forEach(e=>{i.writeUInt32(e.sequence)}),u=nx(o)),(31&n)!==JO.SIGHASH_SINGLE&&(31&n)!==JO.SIGHASH_NONE){const e=this.outs.reduce((e,t)=>e+8+WO(t.script),0);o=nh.allocUnsafe(e),i=new dO(o,0),this.outs.forEach(e=>{i.writeUInt64(e.value),i.writeVarSlice(e.script)}),s=nx(o)}else if((31&n)===JO.SIGHASH_SINGLE&&e<this.outs.length){const t=this.outs[e];o=nh.allocUnsafe(8+WO(t.script)),i=new dO(o,0),i.writeUInt64(t.value),i.writeVarSlice(t.script),s=nx(o)}o=nh.allocUnsafe(156+WO(t)),i=new dO(o,0);const c=this.ins[e];return i.writeInt32(this.version),i.writeSlice(a),i.writeSlice(u),i.writeSlice(c.hash),i.writeUInt32(c.index),i.writeVarSlice(t),i.writeUInt64(r),i.writeUInt32(c.sequence),i.writeSlice(s),i.writeUInt32(this.locktime),i.writeUInt32(n),nx(o)}getHash(e){return e&&this.isCoinbase()?nh.alloc(32,0):nx(this.__toBuffer(void 0,void 0,e))}getId(){return hO(this.getHash(!1)).toString("hex")}toBuffer(e,t){return this.__toBuffer(e,t,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(e,t){qO(CI(BI,LI),[e,t]),this.ins[e].script=t}setWitness(e,t){qO(CI(BI,[LI]),[e,t]),this.ins[e].witness=t}__toBuffer(e,t,r=!1){e||(e=nh.allocUnsafe(this.byteLength(r)));const n=new dO(e,t||0);n.writeInt32(this.version);const i=r&&this.hasWitnesses();return i&&(n.writeUInt8(JO.ADVANCED_TRANSACTION_MARKER),n.writeUInt8(JO.ADVANCED_TRANSACTION_FLAG)),n.writeVarInt(this.ins.length),this.ins.forEach(e=>{n.writeSlice(e.hash),n.writeUInt32(e.index),n.writeVarSlice(e.script),n.writeUInt32(e.sequence)}),n.writeVarInt(this.outs.length),this.outs.forEach(e=>{!function(e){return"value"in e}(e)?n.writeSlice(e.valueBuffer):n.writeUInt64(e.value),n.writeVarSlice(e.script)}),i&&this.ins.forEach(e=>{n.writeVector(e.witness)}),n.writeUInt32(this.locktime),void 0!==t?e.subarray(t,n.offset):e}}function eB(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}JO.DEFAULT_SEQUENCE=4294967295,JO.SIGHASH_DEFAULT=0,JO.SIGHASH_ALL=1,JO.SIGHASH_NONE=2,JO.SIGHASH_SINGLE=3,JO.SIGHASH_ANYONECANPAY=128,JO.SIGHASH_OUTPUT_MASK=3,JO.SIGHASH_INPUT_MASK=128,JO.ADVANCED_TRANSACTION_MARKER=0,JO.ADVANCED_TRANSACTION_FLAG=1,JO.TRUC_VERSION=3,JO.TRUC_MAX_VSIZE=1e4,JO.TRUC_CHILD_MAX_VSIZE=1e3;const tB=eB(DO),rB=eB(FO),nB=eB(tO),iB=eB(xO),oB=eB(UO),sB=eB(nO),aB=eB(AO);function uB(e){let t=nh.allocUnsafe(0);function r(e){const r=t.length,n=Am.encodingLength(e);t=nh.concat([t,nh.allocUnsafe(n)]),Am.encode(e,t,r)}function n(e){r(e.length),function(e){t=nh.concat([t,nh.from(e)])}(e)}return r((i=e).length),i.forEach(n),t;var i}function cB(e,t){const r=nT(t);if(null===r)throw new Error("Unknown script error");const n=rx(e),i=Yx(e),o=Qx(e),s=o?.hybrid?rx(o.hybrid):void 0,a=o?.uncompressed?rx(o.uncompressed):void 0;return r.findIndex(t=>"number"!=typeof t&&(!!(Jx(t,e)||Jx(t,i)||t.equals(n)||o&&(Jx(t,o.uncompressed)||Jx(t,o.hybrid)||s&&t.equals(s)||a&&t.equals(a)))||void 0))}function fB(e,t){return-1!==cB(e,t)}function lB(e,t){return function(e){const{partialSig:t}=e;let r;if(t&&0!==t.length)r=t;else{if(!e.finalScriptSig&&!e.finalScriptWitness)return[];r=function(e){const t=e.finalScriptSig&&nT(e.finalScriptSig)||[],r=e.finalScriptWitness&&nT(e.finalScriptWitness)||[];return t.concat(r).filter(e=>nh.isBuffer(e)&&aT(e)).map(e=>({signature:e}))}(e)}return r.map(e=>e.signature)}(e).some(e=>hB(e,cT.decode,t))}function hB(e,t,r){const{hashType:n}=t(e),i=[];switch(n&JO.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case JO.SIGHASH_ALL:break;case JO.SIGHASH_SINGLE:case JO.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function pB(e,t,r){const n=function(e,t,r){const{tapScriptSig:n}=e;if(!n||!n.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const i=(e.tapLeafScript||[]).sort((e,t)=>e.controlBlock.length-t.controlBlock.length).find(e=>function(e,t,r){const n=wO({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&void 0!==t.find(e=>e.leafHash.equals(n))}(e,n,r));if(!i)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return i}(t,e,r);try{const e=function(e,t){const r=wO({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(e=>e.leafHash.equals(r)).map(e=>function(e,t){return Object.assign({positionInScript:cB(t.pubkey,e)},t)}(t.script,e)).sort((e,t)=>t.positionInScript-e.positionInScript).map(e=>e.signature)}(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:uB(e)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}function dB(e,t){const r=t?nh.from([t]):nh.from([]);return nh.concat([e,r])}function yB(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&aB(e.witnessUtxo.script))}function gB(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function mB(e,t,r){(function(e,t,r){const n=yB(e)&&SB(t),i=SB(e)&&yB(t),o=e===t&&yB(t)&&SB(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)})(e,t,r),function(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(e=>_B(e,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(e=>_B(e,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(t=>_B(t,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}(e,t,r)}function bB(e,t,r){(function(e,t,r){const n=gB(e)&&SB(t),i=SB(e)&&gB(t),o=e===t&&gB(t)&&SB(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)})(e,t,r),function(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const t=e.script,i=function(e,t){const r=t&&function(e=[]){return 1===e.length&&0===e[0].depth?{output:e[0].script,version:e[0].leafVersion}:function(e){let t;for(const r of e)if(t=EB(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}(e)}(t.leaves),{output:n}=AO({internalPubkey:e,scriptTree:r});if(!n)throw new Error("Failed to generate taproot script pubkey");return n}(r,n);if(t&&!t.equals(i))throw new Error("Error adding output. Script or address missmatch.")}}(e,t)}function wB(e,t){return function(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(e=>e.signature)),!t.length){const r=function(e){if(!e)return;const t=e.subarray(2);if(64===t.length||65===t.length)return t}(e.finalScriptWitness);r&&t.push(r)}return t}(e).some(e=>hB(e,vB,t))}function vB(e){return{signature:e.subarray(0,64),hashType:e.subarray(64)[0]||JO.SIGHASH_DEFAULT}}function EB(e,t,r=0){if(r>128)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if(TI(t))return;const n=EB(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=EB(e,t&&t[1],r+1);return i?[t&&t[0],i]:void 0}function _B(e,t){if(!t)return!0;const r=wO({output:e.script,version:e.leafVersion});return gO(e.controlBlock,r).equals(t)}function SB(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const kB=Am.decode,AB={network:fI,maximumFeeRate:5e3};let IB=class e{constructor(e={},t=new km.Psbt(new xB)){this.data=t,this.opts=Object.assign({},AB,e),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},3===e.version?this.setVersionTRUC():0===this.data.inputs.length&&this.setVersion(2);const r=(e,t,r,n)=>{Object.defineProperty(e,t,{enumerable:r,writable:n})};r(this,"__CACHE",!1,!0),r(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(e){this.setVersion(e)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(e){this.setLocktime(e)}get txInputs(){return this.__CACHE.__TX.ins.map(e=>({hash:pO(e.hash),index:e.index,sequence:e.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(e=>{let t;try{t=CO(e.script,this.opts.network)}catch{}return{script:pO(e.script),value:e.value,address:t}})}static fromBase64(e,t={}){const r=nh.from(e,"base64");return this.fromBuffer(r,t)}static fromHex(e,t={}){const r=nh.from(e,"hex");return this.fromBuffer(r,t)}static fromBuffer(t,r={}){const n=km.Psbt.fromBuffer(t,TB),i=new e(r,n);return function(e,t){e.ins.forEach(e=>{CB(t,e)})}(i.__CACHE.__TX,i.__CACHE),i}combine(...e){return this.data.combine(...e.map(e=>e.data)),this}clone(){const t=JSON.parse(JSON.stringify(this.opts));return e.fromBuffer(this.data.toBuffer(),t)}setMaximumFeeRate(e){LB(e),this.opts.maximumFeeRate=e}setVersion(e){LB(e),NB(this.data.inputs,"setVersion");const t=this.__CACHE;return t.__TX.version=e,t.__EXTRACTED_TX=void 0,this}setVersionTRUC(){return this.setVersion(JO.TRUC_VERSION)}setLocktime(e){LB(e),NB(this.data.inputs,"setLocktime");const t=this.__CACHE;return t.__TX.locktime=e,t.__EXTRACTED_TX=void 0,this}setInputSequence(e,t){LB(t),NB(this.data.inputs,"setInputSequence");const r=this.__CACHE;if(r.__TX.ins.length<=e)throw new Error("Input index too high");return r.__TX.ins[e].sequence=t,r.__EXTRACTED_TX=void 0,this}addInputs(e,t=!0){return e.forEach(e=>this.addInput(e,t)),this}addInput(e,t=!0){if(!e||void 0===e.hash||void 0===e.index)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");mB(e,e,"addInput"),t&&NB(this.data.inputs,"addInput"),e.witnessScript&&nP(e.witnessScript);const r=this.__CACHE;this.data.addInput(e);CB(r,r.__TX.ins[r.__TX.ins.length-1]);const n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&YB(this.__CACHE,i,n),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}addOutputs(e){return e.forEach(e=>this.addOutput(e)),this}addOutput(e){const t="address"in e,r="script"in e;if(arguments.length>1||!e||void 0===e.value||!t&&!r)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");if(NB(this.data.inputs,"addOutput"),t){const{address:t}=e,{network:r}=this.opts,n=HO(t,r);e=Object.assign({},e,{script:n})}bB(e,e,"addOutput");const n=this.__CACHE;return this.data.addOutput(e),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(e,t){if(t&&(this.data.inputs=this.data.inputs.filter(e=>!e.partialSig)),!this.data.inputs.every(PB))throw new Error("Not finalized");const r=this.__CACHE;if(e||function(e,t,r){const n=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),o=n*i;if(n>=r.maximumFeeRate)throw new Error(`Warning: You are paying around ${(o/1e8).toFixed(8)} in fees, which is ${n} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return ZB(this.data.inputs,n,r,!0,t),n}getFeeRate(e=!1){return MB("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE,e)}getFee(e=!1){return MB("__FEE","fee",this.data.inputs,this.__CACHE,e)}finalizeAllInputs(){return Im.checkForInput(this.data.inputs,0),oP(this.data.inputs.length).forEach(e=>this.finalizeInput(e)),this}finalizeInput(e,t,r){const n=Im.checkForInput(this.data.inputs,e);return yB(n)?this._finalizeTaprootInput(e,n,void 0,t):this._finalizeInput(e,n,t,r??!0)}finalizeTaprootInput(e,t,r=pB){const n=Im.checkForInput(this.data.inputs,e);if(yB(n))return this._finalizeTaprootInput(e,n,t,r);throw new Error(`Cannot finalize input #${e}. Not Taproot.`)}getInputType(e){const t=Im.checkForInput(this.data.inputs,e),r=rP(JB(e,t,this.__CACHE),e,"input",t.redeemScript||function(e){if(!e)return;const t=nT(e);if(!t)return;const r=t[t.length-1];if(nh.isBuffer(r)&&!tP(r)&&!function(e){return aT(e)}(r)&&nT(r))return r}(t.finalScriptSig),t.witnessScript||function(e){if(!e)return;const t=XB(e),r=t[t.length-1];if(!tP(r)&&nT(r))return r}(t.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+iP(r.meaningfulScript)}inputHasPubkey(e,t){return function(e,t,r,n){const i=JB(r,t,n),{meaningfulScript:o}=rP(i,r,"input",t.redeemScript,t.witnessScript);return fB(e,o)}(t,Im.checkForInput(this.data.inputs,e),e,this.__CACHE)}inputHasHDKey(e,t){const r=Im.checkForInput(this.data.inputs,e),n=UB(t);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}outputHasPubkey(e,t){return function(e,t,r,n){const i=n.__TX.outs[r].script,{meaningfulScript:o}=rP(i,r,"output",t.redeemScript,t.witnessScript);return fB(e,o)}(t,Im.checkForOutput(this.data.outputs,e),e,this.__CACHE)}outputHasHDKey(e,t){const r=Im.checkForOutput(this.data.outputs,e),n=UB(t);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}validateSignaturesOfAllInputs(e){return Im.checkForInput(this.data.inputs,0),oP(this.data.inputs.length).map(t=>this.validateSignaturesOfInput(t,e)).reduce((e,t)=>t&&e,!0)}validateSignaturesOfInput(e,t,r){return yB(this.data.inputs[e])?this.validateSignaturesOfTaprootInput(e,t,r):this._validateSignaturesOfInput(e,t,r)}signAllInputsHD(e,t=[JO.SIGHASH_ALL]){if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");const r=[];for(const n of oP(this.data.inputs.length))try{this.signInputHD(n,e,t),r.push(!0)}catch{r.push(!1)}if(r.every(e=>!e))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(e,t=[JO.SIGHASH_ALL]){return new Promise((r,n)=>{if(!e||!e.publicKey||!e.fingerprint)return n(new Error("Need HDSigner to sign input"));const i=[],o=[];for(const s of oP(this.data.inputs.length))o.push(this.signInputHDAsync(s,e,t).then(()=>{i.push(!0)},()=>{i.push(!1)}));return Promise.all(o).then(()=>{if(i.every(e=>!e))return n(new Error("No inputs were signed"));r()})})}signInputHD(e,t,r=[JO.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");return GB(e,this.data.inputs,t).forEach(t=>this.signInput(e,t,r)),this}signInputHDAsync(e,t,r=[JO.SIGHASH_ALL]){return new Promise((n,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const o=GB(e,this.data.inputs,t).map(t=>this.signInputAsync(e,t,r));return Promise.all(o).then(()=>{n()}).catch(i)})}signAllInputs(e,t){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");const r=[];for(const n of oP(this.data.inputs.length))try{this.signInput(n,e,t),r.push(!0)}catch{r.push(!1)}if(r.every(e=>!e))throw new Error("No inputs were signed");return this}signAllInputsAsync(e,t){return new Promise((r,n)=>{if(!e||!e.publicKey)return n(new Error("Need Signer to sign input"));const i=[],o=[];for(const[s]of this.data.inputs.entries())o.push(this.signInputAsync(s,e,t).then(()=>{i.push(!0)},()=>{i.push(!1)}));return Promise.all(o).then(()=>{if(i.every(e=>!e))return n(new Error("No inputs were signed"));r()})})}signInput(e,t,r){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=Im.checkForInput(this.data.inputs,e);return yB(n)?this._signTaprootInput(e,n,t,void 0,r):this._signInput(e,t,r)}signTaprootInput(e,t,r,n){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const i=Im.checkForInput(this.data.inputs,e);if(yB(i))return this._signTaprootInput(e,i,t,r,n);throw new Error(`Input #${e} is not of type Taproot.`)}signInputAsync(e,t,r){return Promise.resolve().then(()=>{if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=Im.checkForInput(this.data.inputs,e);return yB(n)?this._signTaprootInputAsync(e,n,t,void 0,r):this._signInputAsync(e,t,r)})}signTaprootInputAsync(e,t,r,n){return Promise.resolve().then(()=>{if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const i=Im.checkForInput(this.data.inputs,e);if(yB(i))return this._signTaprootInputAsync(e,i,t,r,n);throw new Error(`Input #${e} is not of type Taproot.`)})}toBuffer(){return OB(this.__CACHE),this.data.toBuffer()}toHex(){return OB(this.__CACHE),this.data.toHex()}toBase64(){return OB(this.__CACHE),this.data.toBase64()}updateGlobal(e){return this.data.updateGlobal(e),this}updateInput(e,t){return t.witnessScript&&nP(t.witnessScript),mB(this.data.inputs[e],t,"updateInput"),this.data.updateInput(e,t),t.nonWitnessUtxo&&YB(this.__CACHE,this.data.inputs[e],e),this}updateOutput(e,t){return bB(this.data.outputs[e],t,"updateOutput"),this.data.updateOutput(e,t),this}addUnknownKeyValToGlobal(e){return this.data.addUnknownKeyValToGlobal(e),this}addUnknownKeyValToInput(e,t){return this.data.addUnknownKeyValToInput(e,t),this}addUnknownKeyValToOutput(e,t){return this.data.addUnknownKeyValToOutput(e,t),this}clearFinalizedInput(e){return this.data.clearFinalizedInput(e),this}checkTaprootHashesForSig(e,t,r,n,i){if("function"!=typeof r.signSchnorr)throw new Error(`Need Schnorr Signer to sign taproot input #${e}.`);const o=nh.isBuffer(r.publicKey)?r.publicKey:nh.from(r.publicKey),s=WB(e,t,this.data.inputs,o,this.__CACHE,n,i);if(!s||!s.length)throw new Error(`Can not sign for input #${e} with the key ${o.toString("hex")}`);return s}_finalizeInput(e,t,r=DB,n=!0){const{script:i,isP2SH:o,isP2WSH:s,isSegwit:a}=function(e,t,r){const n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const o=QB(r,t,e),s=n.ins[e].index;i.script=o.outs[s].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);if(t.witnessScript||iB(i.script))i.isSegwit=!0;else try{const e=i.script;if(!e)throw new TypeError("Invalid script for segwit address");i.isSegwit=LO(e)}catch{}return i}(e,t,this.__CACHE);if(!i)throw new Error(`No script found for input #${e}`);!function(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(e=>{const{hashType:t}=cT.decode(e.signature);if(r!==t)throw new Error("Signature sighash does not match input sighash type")})}(t);const{finalScriptSig:u,finalScriptWitness:c}=r(e,t,i,a,o,s,n);if(u&&this.data.updateInput(e,{finalScriptSig:u}),c&&this.data.updateInput(e,{finalScriptWitness:c}),!u&&!c)throw new Error(`Unknown error finalizing input #${e}`);return this.data.clearFinalizedInput(e),this}_finalizeTaprootInput(e,t,r,n=pB){if(!t.witnessUtxo)throw new Error(`Cannot finalize input #${e}. Missing witness utxo.`);if(t.tapKeySig){const r=AO({output:t.witnessUtxo.script,signature:t.tapKeySig});if(!r.witness)throw new Error("Cannot finalize taproot key spend");const n=uB(r.witness);this.data.updateInput(e,{finalScriptWitness:n})}else{const{finalScriptWitness:i}=n(e,t,r);this.data.updateInput(e,{finalScriptWitness:i})}return this.data.clearFinalizedInput(e),this}_validateSignaturesOfInput(e,t,r){const n=this.data.inputs[e],i=(n||{}).partialSig;if(!n||!i||i.length<1)throw new Error("No signatures to validate");if("function"!=typeof t)throw new Error("Need validator function to validate signatures");const o=r?i.filter(e=>e.pubkey.equals(r)):i;if(o.length<1)throw new Error("No signatures for this pubkey");const s=[];let a,u,c;for(const f of o){const r=cT.decode(f.signature),{hash:i,script:o}=c===r.hashType&&a&&u?{hash:a,script:u}:FB(e,Object.assign({},n,{sighashType:r.hashType}),this.__CACHE,!0);c=r.hashType,a=i,u=o,RB(f.pubkey,o,"verify"),s.push(t(f.pubkey,i,r.signature))}return s.every(e=>e)}validateSignaturesOfTaprootInput(e,t,r){const n=this.data.inputs[e],i=(n||{}).tapKeySig,o=(n||{}).tapScriptSig;if(!n&&!i&&(!o||o.length))throw new Error("No signatures to validate");if("function"!=typeof t)throw new Error("Need validator function to validate signatures");const s=(r=r&&Yx(r))?WB(e,n,this.data.inputs,r,this.__CACHE):function(e,t,r,n){const i=[];if(t.tapInternalKey){const r=VB(e,t,n);r&&i.push(r)}if(t.tapScriptSig){const e=t.tapScriptSig.map(e=>e.pubkey);i.push(...e)}return i.map(i=>WB(e,t,r,i,n)).flat()}(e,n,this.data.inputs,this.__CACHE);if(!s.length)throw new Error("No signatures for this pubkey");const a=s.find(e=>!e.leafHash);let u=0;if(i&&a){if(!t(a.pubkey,a.hash,qB(i)))return!1;u++}if(o)for(const c of o){const e=s.find(e=>c.pubkey.equals(e.pubkey));if(e){if(!t(c.pubkey,e.hash,qB(c.signature)))return!1;u++}}return u>0}_signInput(e,t,r=[JO.SIGHASH_ALL]){const n=nh.isBuffer(t.publicKey)?t.publicKey:nh.from(t.publicKey),{hash:i,sighashType:o}=jB(this.data.inputs,e,n,this.__CACHE,r),s=t.sign(i),a=[{pubkey:n,signature:cT.encode(nh.isBuffer(s)?s:nh.from(s),o)}];return this.data.updateInput(e,{partialSig:a}),this}_signTaprootInput(e,t,r,n,i=[JO.SIGHASH_DEFAULT]){const o=nh.isBuffer(r.publicKey)?r.publicKey:nh.from(r.publicKey),s=this.checkTaprootHashesForSig(e,t,r,n,i),a=r.signSchnorr.bind(r),u=e=>nh.isBuffer(e)?e:nh.from(e),c=s.filter(e=>!e.leafHash).map(e=>dB(u(a(e.hash)),t.sighashType))[0],f=s.filter(e=>!!e.leafHash).map(e=>({pubkey:Yx(o),signature:dB(u(a(e.hash)),t.sighashType),leafHash:e.leafHash}));return c&&this.data.updateInput(e,{tapKeySig:c}),f.length&&this.data.updateInput(e,{tapScriptSig:f}),this}_signInputAsync(e,t,r=[JO.SIGHASH_ALL]){const n=nh.isBuffer(t.publicKey)?t.publicKey:nh.from(t.publicKey),{hash:i,sighashType:o}=jB(this.data.inputs,e,n,this.__CACHE,r);return Promise.resolve(t.sign(i)).then(t=>{const r=nh.isBuffer(t)?t:nh.from(t),i=[{pubkey:n,signature:cT.encode(r,o)}];this.data.updateInput(e,{partialSig:i})})}async _signTaprootInputAsync(e,t,r,n,i=[JO.SIGHASH_DEFAULT]){const o=nh.isBuffer(r.publicKey)?r.publicKey:nh.from(r.publicKey),s=this.checkTaprootHashesForSig(e,t,r,n,i),a=r.signSchnorr.bind(r),u=e=>nh.isBuffer(e)?e:nh.from(e),c=[],f=s.filter(e=>!e.leafHash)[0];if(f){const e=Promise.resolve(a(f.hash)).then(e=>({tapKeySig:dB(u(e),t.sighashType)}));c.push(e)}const l=s.filter(e=>!!e.leafHash);if(l.length){const e=l.map(async e=>{const r=await a(e.hash);return{tapScriptSig:[{pubkey:Yx(o),signature:dB(u(r),t.sighashType),leafHash:e.leafHash}]}});c.push(...e)}const h=await Promise.all(c);for(const p of h)this.data.updateInput(e,p)}};const TB=e=>new xB(e);class xB{constructor(e=nh.from([2,0,0,0,0,0,0,0,0,0])){this.tx=JO.fromBuffer(e),function(e){if(!e.ins.every(e=>e.script&&0===e.script.length&&e.witness&&0===e.witness.length))throw new Error("Format Error: Transaction ScriptSigs are not empty")}(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(e){if(void 0===e.hash||void 0===e.index||!nh.isBuffer(e.hash)&&"string"!=typeof e.hash||"number"!=typeof e.index)throw new Error("Error adding input.");const t="string"==typeof e.hash?hO(nh.from(e.hash,"hex")):e.hash;this.tx.addInput(t,e.index,e.sequence)}addOutput(e){if(void 0===e.script||void 0===e.value||!nh.isBuffer(e.script)||"number"!=typeof e.value)throw new Error("Error adding output.");this.tx.addOutput(e.script,e.value)}toBuffer(){return this.tx.toBuffer()}}function OB(e){if(e.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function BB(e,t,r){if(!t)return!1;let n;if(n=r?r.map(e=>{const r=function(e){if(65===e.length){const t=1&e[64],r=nh.from(e.subarray(0,33));return r[0]=2|t,r}return nh.from(e)}(e);return t.find(e=>e.pubkey.equals(r))}).filter(e=>!!e):t,n.length>e)throw new Error("Too many signatures");return n.length===e}function PB(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function UB(e){return t=>{const r=nh.isBuffer(e.fingerprint)?e.fingerprint:nh.from(e.fingerprint);if(!t.masterFingerprint.equals(r))return!1;const n=e.derivePath(t.path).publicKey;return!!(nh.isBuffer(n)?n:nh.from(n)).equals(t.pubkey)}}function LB(e){if("number"!=typeof e||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function NB(e,t){e.forEach(e=>{if(yB(e)?wB(e,t):lB(e,t))throw new Error("Can not modify transaction, signatures exist.")})}function RB(e,t,r){if(!fB(e,t))throw new Error(`Can not ${r} for this input with the key ${e.toString("hex")}`)}function CB(e,t){const r=`${hO(nh.from(t.hash)).toString("hex")}:${t.index}`;if(e.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[r]=1}function HB(e,t){return(r,n,i,o)=>{const s=e({redeem:{output:i}}).output;if(!n.equals(s))throw new Error(`${t} for ${o} #${r} doesn't match the scriptPubKey in the prevout`)}}const KB=HB(nO,"Redeem script"),zB=HB(UO,"Witness script");function MB(e,t,r,n,i=!1){if(!r.every(PB))throw new Error(`PSBT must be finalized to calculate ${t}`);if("__FEE_RATE"===e&&n.__FEE_RATE)return n.__FEE_RATE;if("__FEE"===e&&n.__FEE)return n.__FEE;let o,s=!0;n.__EXTRACTED_TX?(o=n.__EXTRACTED_TX,s=!1):o=n.__TX.clone(),ZB(r,o,n,s,i);const a="__FEE_RATE"===e?n.__FEE_RATE:n.__FEE;if(void 0===a)throw new Error(`Failed to calculate ${t}`);return a}function DB(e,t,r,n,i,o,s=!0,a){const u=iP(r);if(!function(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return BB(1,e.partialSig);case"multisig":{const r=DO({output:t});return BB(r.m,e.partialSig,r.pubkeys)}case"nonstandard":return!0;default:return!1}}(t,r,u)&&s)throw new Error(`Can not finalize input #${e}`);return function(e,t,r,n,i,o,s){let a,u;const c=function(e,t,r){let n;switch(t){case"multisig":{const t=function(e,t){return DO({output:e}).pubkeys.map(e=>(t.filter(t=>t.pubkey.equals(e))[0]||{}).signature).filter(e=>!!e)}(e,r);n=DO({output:e,signatures:t});break}case"pubkey":n=FO({output:e,signature:r[0].signature});break;case"pubkeyhash":n=tO({output:e,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=xO({output:e,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(e,t,r),f=o?UO({redeem:c}):null,l=i?nO({redeem:f||c}):null;return n?(u=uB(f?f.witness:c?c.witness:s??[nh.from([0])]),l&&(a=l?.input)):a=l?l?.input:c?c.input:Array.isArray(s)&&s[0]?s[0]:nh.from([1]),{finalScriptSig:a,finalScriptWitness:u}}(r,u,t.partialSig,n,i,o,a)}function jB(e,t,r,n,i){const o=Im.checkForInput(e,t),{hash:s,sighashType:a,script:u}=FB(t,o,n,!1,i);return RB(r,u,"sign"),{hash:s,sighashType:a}}function FB(e,t,r,n,i){const o=r.__TX,s=t.sighashType||JO.SIGHASH_ALL;let a,u;if($B(s,i),t.nonWitnessUtxo){const n=QB(r,t,e),i=o.ins[e].hash,s=n.getHash();if(!i.equals(s))throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const a=o.ins[e].index;u=n.outs[a]}else{if(!t.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=t.witnessUtxo}const{meaningfulScript:c,type:f}=rP(u.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(f)>=0)a=o.hashForWitnessV0(e,c,u.value,s);else if(iB(c)){const t=tO({hash:c.subarray(2)}).output;a=o.hashForWitnessV0(e,t,u.value,s)}else{if(void 0===t.nonWitnessUtxo&&!r.__UNSAFE_SIGN_NONSEGWIT)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: `+c.toString("hex"));!n&&r.__UNSAFE_SIGN_NONSEGWIT&&console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),a=o.hashForSignature(e,c,s)}return{script:c,sighashType:s,hash:a}}function VB(e,t,r){const{script:n}=eP(e,t,r);return aB(n)?nh.from(n.subarray(2,34)):null}function qB(e){return 64===e.length?e:nh.from(e.subarray(0,64))}function WB(e,t,r,n,i,o,s){const a=i.__TX,u=t.sighashType||JO.SIGHASH_DEFAULT;$B(u,s);const c=r.map((e,t)=>eP(t,e,i)),f=c.map(e=>e.script),l=c.map(e=>e.value),h=[];if(t.tapInternalKey&&!o){const r=VB(e,t,i)||nh.from([]);if(Yx(n).equals(r)){const t=a.hashForWitnessV1(e,f,l,u);h.push({pubkey:n,hash:t})}}const p=(t.tapLeafScript||[]).filter(e=>fB(n,e.script)).map(e=>{const t=wO({output:e.script,version:e.leafVersion});return Object.assign({hash:t},e)}).filter(e=>!o||o.equals(e.hash)).map(t=>{const r=a.hashForWitnessV1(e,f,l,u,t.hash);return{pubkey:n,hash:r,leafHash:t.hash}});return h.concat(p)}function $B(e,t){if(t&&t.indexOf(e)<0){const t=function(e){let t=e&JO.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&e){case JO.SIGHASH_ALL:t+="SIGHASH_ALL";break;case JO.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case JO.SIGHASH_NONE:t+="SIGHASH_NONE"}return t}(e);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${t}`)}}function GB(e,t,r){const n=Im.checkForInput(t,e);if(!n.bip32Derivation||0===n.bip32Derivation.length)throw new Error("Need bip32Derivation to sign with HD");const i=n.bip32Derivation.map(e=>{if(e.masterFingerprint.equals(r.fingerprint))return e}).filter(e=>!!e);if(0===i.length)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map(e=>{const t=r.derivePath(e.path);if(!e.pubkey.equals(t.publicKey))throw new Error("pubkey did not match bip32Derivation");return t})}function XB(e){let t=0;function r(){const r=kB(e,t);return t+=kB.bytes,r}function n(){return n=r(),t+=n,e.subarray(t-n,t);var n}return function(){const e=r(),t=[];for(let r=0;r<e;r++)t.push(n());return t}()}function YB(e,t,r){e.__NON_WITNESS_UTXO_BUF_CACHE[r]=t.nonWitnessUtxo,e.__NON_WITNESS_UTXO_TX_CACHE[r]=JO.fromBuffer(t.nonWitnessUtxo);const n=e,i=r;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const e=n.__NON_WITNESS_UTXO_BUF_CACHE[i],t=n.__NON_WITNESS_UTXO_TX_CACHE[i];if(void 0!==e)return e;{const e=t.toBuffer();return n.__NON_WITNESS_UTXO_BUF_CACHE[i]=e,e}},set(e){n.__NON_WITNESS_UTXO_BUF_CACHE[i]=e}})}function ZB(e,t,r,n,i){let o=0;e.forEach((e,i)=>{if(n&&e.finalScriptSig&&(t.ins[i].script=e.finalScriptSig),n&&e.finalScriptWitness&&(t.ins[i].witness=XB(e.finalScriptWitness)),e.witnessUtxo)o+=e.witnessUtxo.value;else if(e.nonWitnessUtxo){const n=QB(r,e,i),s=t.ins[i].index,a=n.outs[s];o+=a.value}});const s=t.outs.reduce((e,t)=>e+t.value,0),a=o-s;if(!i&&a<0)throw new Error(`Outputs are spending more than Inputs ${o} < ${s}`);const u=t.virtualSize();r.__FEE=a,r.__EXTRACTED_TX=t,r.__FEE_RATE=Math.floor(a/u)}function QB(e,t,r){const n=e.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||YB(e,t,r),n[r]}function JB(e,t,r){const{script:n}=eP(e,t,r);return n}function eP(e,t,r){if(void 0!==t.witnessUtxo)return{script:t.witnessUtxo.script,value:t.witnessUtxo.value};if(void 0!==t.nonWitnessUtxo){const n=QB(r,t,e).outs[r.__TX.ins[e].index];return{script:n.script,value:n.value}}throw new Error("Can't find pubkey in input without Utxo data")}function tP(e){return 33===e.length&&sT(e)}function rP(e,t,r,n,i){const o=sB(e),s=o&&n&&oB(n),a=oB(e);if(o&&void 0===n)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((a||s)&&void 0===i)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let u;return s?(u=i,KB(t,e,n,r),zB(t,n,i,r),nP(u)):a?(u=i,zB(t,e,i,r),nP(u)):o?(u=n,KB(t,e,n,r)):u=e,{meaningfulScript:u,type:s?"p2sh-p2wsh":o?"p2sh":a?"p2wsh":"raw"}}function nP(e){if(iB(e)||sB(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function iP(e){return iB(e)?"witnesspubkeyhash":nB(e)?"pubkeyhash":tB(e)?"multisig":rB(e)?"pubkey":"nonstandard"}function oP(e){return[...Array(e).keys()]}const sP={payments:VO,script:fT,crypto:sx};const aP={gzipSync:function(e,t={}){return nh.from(Hy.gzip(e,{level:t.level||6}))},gunzipSync:function(e){return nh.from(Hy.ungzip(e))},deflateSync:function(e,t={}){return nh.from(Hy.deflate(e,{level:t.level||6}))},inflateSync:function(e){return nh.from(Hy.inflate(e))}};class uP{static{this.zlibOptions={level:9,maxOutputLength:16777216}}static compress(e){return aP.gzipSync(e,uP.zlibOptions)}static decompress(e){return aP.gunzipSync(e,uP.zlibOptions)}}oO(Om);const cP="function"==typeof vv?vv:wv.BIP32Factory;if(!cP)throw new Error("Failed to load BIP32 library");const fP=Dl.Point,lP=fP.Fn.ORDER,hP=Da("TapTweak"),pP=ku(hP);class dP{static{this.BIP32=cP(Om)}static{this.ECPair=cE.ECPairFactory(Om)}static{fP.BASE.precompute(8)}static fromWIF(e,t=fI){return this.ECPair.fromWIF(e,t)}static fromPrivateKey(e,t=fI){return this.ECPair.fromPrivateKey(nh.isBuffer(e)?e:nh.from(e),{network:t})}static fromPublicKey(e,t=fI){const r=nh.isBuffer(e)?e:nh.from(e);return this.ECPair.fromPublicKey(r,{network:t})}static generateMultiSigAddress(e,t,r=fI){const n=this.verifyPubKeys(e,r);if(n.length!==e.length)throw new Error("Contains invalid public keys");const i=UO({redeem:DO({m:t,pubkeys:n,network:r}),network:r}).address;if(!i)throw new Error("Failed to generate address");return i}static verifyPubKeys(e,t=fI){return e.map(e=>{const r=dP.fromPublicKey(e,t);if(!r)throw new Error("Failed to regenerate key");return nh.from(r.publicKey)})}static getP2WPKHAddress(e,t=fI){const r=xO({pubkey:nh.from(e.publicKey),network:t});if(!r.address)throw new Error("Failed to generate wallet");return r.address}static tweakedPubKeyToAddress(e,t){e.startsWith("0x")&&(e=e.slice(2));let r=nh.from(e,"hex");return 32!==r.length&&(r=Yx(r)),dP.tweakedPubKeyBufferToAddress(r,t)}static tweakedPubKeyBufferToAddress(e,t){const{address:r}=AO({pubkey:nh.isBuffer(e)?e:nh.from(e),network:t});if(!r)throw new Error("Failed to generate Taproot address");return r}static p2op(e,t=fI,r=0){const n=nh.concat([nh.from([r]),sP.crypto.hash160(nh.from(e))]);if(n.length<2||n.length>40)throw new Error("Witness program must be 2-40 bytes.");return CO(rT([yI.OP_16,n]),t)}static xOnlyTweakedPubKeyToAddress(e,t){e.startsWith("0x")&&(e=e.slice(2));const r=nh.from(e,"hex"),{address:n}=AO({pubkey:r,network:t});if(!n)throw new Error("Failed to generate Taproot address");return n}static tweakPublicKey(e){"string"==typeof e&&e.startsWith("0x")&&(e=e.slice(2));const t=fP.fromHex(e),r=0n==(1n&t.y)?t:t.negate(),n=nh.from(r.toBytes(!0).subarray(1)),i=qf(kf(ku(Va(pP,pP,n))),lP),o=r.add(fP.BASE.multiply(i));return nh.from(o.toBytes(!0))}static tweakBatchSharedT(e,t){const r=fP.BASE.multiply(t);return e.map(e=>{const t=fP.fromHex(e);return(t.y%2n==0n?t:t.negate()).add(r).toBytes(!0)})}static generateWallet(e=fI,t=wv.MLDSASecurityLevel.LEVEL2){const r=this.ECPair.makeRandom({network:e}),n=this.getP2WPKHAddress(r,e);if(!n)throw new Error("Failed to generate wallet");const i=this.generateQuantumKeyPair(t,e);return{address:n,privateKey:r.toWIF(),publicKey:nh.from(r.publicKey).toString("hex"),quantumPrivateKey:nh.from(i.privateKey).toString("hex"),quantumPublicKey:nh.from(i.publicKey).toString("hex")}}static generateQuantumKeyPair(e=wv.MLDSASecurityLevel.LEVEL2,t=fI){const r=$a(64),n=wv.QuantumBIP32Factory.fromSeed(nh.from(r),t,e);if(!n.privateKey||!n.publicKey)throw new Error("Failed to generate quantum keypair");return{privateKey:nh.from(n.privateKey),publicKey:nh.from(n.publicKey)}}static verifyContractAddress(e,t=fI){return!!HO(e,t)}static getLegacySegwitAddress(e,t=fI){const r=nO({redeem:xO({pubkey:nh.from(e.publicKey),network:t}),network:t});if(!r.address)throw new Error("Failed to generate wallet");return r.address}static getLegacyAddress(e,t=fI){const r=tO({pubkey:nh.from(e.publicKey),network:t});if(!r.address)throw new Error("Failed to generate wallet");return r.address}static getP2PKH(e,t=fI){const r=tO({pubkey:nh.from(e),network:t});if(!r.address)throw new Error("Failed to generate wallet");return r.address}static getP2PKAddress(e,t=fI){const r=FO({pubkey:nh.from(e.publicKey),network:t});if(!r.output)throw new Error("Failed to generate wallet");return"0x"+r.output.toString("hex")}static generateRandomKeyPair(e=fI){return this.ECPair.makeRandom({network:e})}static fromSeed(e,t=fI){return this.BIP32.fromSeed(e,t)}static getTaprootAddress(e,t=fI){const{address:r}=AO({internalPubkey:Yx(nh.from(e.publicKey)),network:t});if(!r)throw new Error("Failed to generate sender address for transaction");return r}static getTaprootAddressFromAddress(e,t=fI){const{address:r}=AO({address:e,network:t});if(!r)throw new Error("Failed to generate sender address for transaction");return r}static fromSeedKeyPair(e,t=fI){const r=this.BIP32.fromSeed(e,t).privateKey;if(!r)throw new Error("Failed to generate key pair");return this.ECPair.fromPrivateKey(nh.from(r),{network:t})}}const yP=32,gP=64,mP=64;class bP{static{this.EXPECTED_BUFFER_LENGTH=32}static bufferToUint8Array(e){if(nh.isBuffer(e)){const t=e.byteLength,r=new ArrayBuffer(t),n=new Uint8Array(r);for(let i=0;i<t;++i)n[i]=e[i];return n}return e}static uint8ArrayToHex(e){return nh.from(e.buffer,0,e.byteLength).toString("hex")}static hexToUint8Array(e){e.startsWith("0x")&&(e=e.substring(2)),e.length%2!=0&&(e="0"+e);const t=e.length/2,r=new Uint8Array(t);for(let n=0;n<t;n++)r[n]=parseInt(e.substring(2*n,2*n+2),16);return r}static pointerToUint8Array(e){const t=e.toString(16).padStart(64,"0");return bP.hexToUint8Array(t)}static uint8ArrayToPointer(e){const t=bP.uint8ArrayToHex(e);return BigInt("0x"+t)}static valueToUint8Array(e,t=32){const r=e.toString(16).padStart(2*t,"0");return bP.hexToUint8Array(r)}static uint8ArrayToValue(e){const t=bP.uint8ArrayToHex(e);return BigInt(t?"0x"+t:0)}}const wP=/^[0-9a-fA-F]+$/;let vP=class e{static btcToSatoshi(e){return BigInt(1e8*e)}static rndBytes(){const t=e.getSafeRandomValues(64);return nh.from(t)}static getSafeRandomValues(e){if(typeof globalThis.window<"u"&&globalThis.window.crypto&&"function"==typeof globalThis.window.crypto.getRandomValues){const t=new Uint8Array(e);return window.crypto.getRandomValues(t),nh.from(t)}if(globalThis.crypto&&"function"==typeof globalThis.crypto.getRandomValues){const t=new Uint8Array(e);return globalThis.crypto.getRandomValues(t),nh.from(t)}throw console.log("No secure random number generator available. Please upgrade your environment.",globalThis.window.crypto,globalThis.crypto),new Error("No secure random number generator available. Please upgrade your environment.")}static isValidHex(e){return wP.test(e)}static opnetHash(e){const t=Bv("sha512");t.update(e);const r=t.digest();return`0x${nh.from(r).toString("hex")}`}};class EP{static isP2WDAUTXO(e){if(!e.witnessScript)return!1;const t=ih.isBuffer(e.witnessScript)?e.witnessScript:ih.from(e.witnessScript,"hex");return this.isP2WDAWitnessScript(t)}static isP2WDAWitnessScript(e){try{const t=nT(e);if(!t||7!==t.length)return!1;for(let e=0;e<5;e++)if(t[e]!==yI.OP_2DROP)return!1;return ih.isBuffer(t[5])&&33===t[5].length&&t[6]===yI.OP_CHECKSIG}catch{return!1}}static generateP2WDAAddress(e,t){if(33!==e.length)throw new Error("Public key must be 33 bytes (compressed)");const r=rT([yI.OP_2DROP,yI.OP_2DROP,yI.OP_2DROP,yI.OP_2DROP,yI.OP_2DROP,e,yI.OP_CHECKSIG]),n=UO({redeem:{output:r},network:t});if(!n.address||!n.output)throw new Error("Failed to generate P2WDA address");return{address:n.address,witnessScript:r,scriptPubKey:n.output}}static extractPublicKeyFromP2WDA(e){try{const t=nT(e);if(!t||7!==t.length)return null;for(let e=0;e<5;e++)if(t[e]!==yI.OP_2DROP)return null;return ih.isBuffer(t[5])&&33===t[5].length&&t[6]===yI.OP_CHECKSIG?t[5]:null}catch{return null}}static createSimpleP2WDAWitness(e,t){const r=[e];for(let n=0;n<10;n++)r.push(ih.alloc(0));return r.push(t),r}static validateP2WDASignature(e,t,r){return 64===t.length}static estimateP2WDAWitnessSize(e=0){return 72+e+39+12}static couldBeP2WDA(e){return 34===e.length&&0===e[0]&&32===e[1]}}oO(Om);var _P=(e=>(e.P2PKH="P2PKH",e.P2OP="P2OP",e.P2SH_OR_P2SH_P2WPKH="P2SH_OR_P2SH-P2WPKH",e.P2PK="P2PK",e.P2TR="P2TR",e.P2WPKH="P2WPKH",e.P2WSH="P2WSH",e.P2WDA="P2WDA",e))(_P||{});class SP{static isValidP2TRAddress(e,t){if(!e||e.length<50)return!1;let r=!1;try{HO(e,t),r=1===pI(e).version}catch{}return r}static isP2WPKHAddress(e,t){if(!e||e.length<20||e.length>50)return!1;let r=!1;try{const n=pI(e);HO(e,t),r=0===n.version&&20===n.data.length}catch{}return r}static isP2WDAWitnessScript(e){return EP.isP2WDAWitnessScript(e)}static isP2PKHOrP2SH(e,t){try{const r=RO(e);return r.version===t.pubKeyHash||r.version===t.scriptHash}catch{return!1}}static isValidPublicKey(e,t){try{if(e.startsWith("0x")&&(e=e.slice(2)),!vP.isValidHex(e))return!1;if(64===e.length)return!0;const r=nh.from(e,"hex");if(130===e.length&&6===r[0]||7===r[0])return!0;if(66===e.length||130===e.length)return dP.fromPublicKey(r,t),!0}catch{return!1}return!1}static isValidMLDSAPublicKey(e){try{let t;if(nh.isBuffer(e)||e instanceof Uint8Array)t=e.length;else{if(e.startsWith("0x")&&(e=e.slice(2)),!vP.isValidHex(e))return null;t=e.length/2}switch(t){case 1312:return wv.MLDSASecurityLevel.LEVEL2;case 1952:return wv.MLDSASecurityLevel.LEVEL3;case 2592:return wv.MLDSASecurityLevel.LEVEL5;default:return null}}catch{return null}}static isValidP2OPAddress(e,t){if(!e||e.length<20)return!1;try{const r=pI(e);return(r.prefix===t.bech32||r.prefix===t.bech32Opnet)&&(16===r.version&&21===r.data.length)}catch{return!1}}static requireRedeemScript(e,t){try{const r=RO(e);return r.version!==t.pubKeyHash&&r.version===t.scriptHash}catch{return!1}}static detectAddressType(e,t){if(SP.isValidPublicKey(e,t))return"P2PK";try{const r=RO(e);if(r.version===t.pubKeyHash)return"P2PKH";if(r.version===t.scriptHash)return"P2SH_OR_P2SH-P2WPKH"}catch{}try{const r=pI(e);if((r.prefix===t.bech32Opnet||r.prefix===t.bech32)&&16===r.version&&21===r.data.length)return"P2OP";if(r.prefix===t.bech32){if(0===r.version&&20===r.data.length)return"P2WPKH";if(0===r.version&&32===r.data.length)return"P2WSH";if(1===r.version&&32===r.data.length)return"P2TR"}}catch{}return null}static detectAddressTypeWithWitnessScript(e,t,r){const n=SP.detectAddressType(e,t);return"P2WSH"===n&&r&&SP.isP2WDAWitnessScript(r)?"P2WDA":n}static validateP2WDAAddress(e,t,r){try{if("P2WSH"!==SP.detectAddressType(e,t))return{isValid:!1,isPotentiallyP2WDA:!1,isDefinitelyP2WDA:!1,error:"Not a P2WSH address"};if(!r)return{isValid:!0,isPotentiallyP2WDA:!0,isDefinitelyP2WDA:!1};if(!SP.isP2WDAWitnessScript(r))return{isValid:!0,isPotentiallyP2WDA:!0,isDefinitelyP2WDA:!1,error:"Witness script does not match P2WDA pattern"};if(UO({redeem:{output:r},network:t}).address!==e)return{isValid:!1,isPotentiallyP2WDA:!1,isDefinitelyP2WDA:!1,error:"Witness script does not match address"};const n=EP.extractPublicKeyFromP2WDA(r);return n?{isValid:!0,isPotentiallyP2WDA:!0,isDefinitelyP2WDA:!0,publicKey:n}:{isValid:!1,isPotentiallyP2WDA:!1,isDefinitelyP2WDA:!1,error:"Failed to extract public key from witness script"}}catch(n){return{isValid:!1,isPotentiallyP2WDA:!1,isDefinitelyP2WDA:!1,error:n.message}}}}const kP=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;class AP{constructor(e=1e4){this.maxTries=e}findOrDeriveValidPoint(e,t=!0,r=this.maxTries){if(32!==e.length)throw new Error("xBytes must be exactly 32 bytes.");let n=this.bytesToBigInt(e)%kP,i=this.isValidX(n);if(t&&null===i)throw new Error("The given x is not a valid curve point.");let o=0;for(;null===i;)if(n=(n+1n)%kP,i=this.isValidX(n),o++,o>r)throw new Error(`Could not find a valid X point within ${r} increments.`);return{x:n,y1:i,y2:(kP-i)%kP}}getCanonicalY(e,t){return e<t?e:t}getHybridPublicKey(e,t){const r=t%2n==0n?6:7,n=this.bigIntTo32Bytes(e),i=this.bigIntTo32Bytes(t),o=new Uint8Array(65);return o[0]=r,o.set(n,1),o.set(i,33),o}isValidX(e){const t=(this.modPow(e,3n,kP)+7n)%kP;return this.sqrtModP(t,kP)}modPow(e,t,r){let n=1n,i=e%r,o=t;for(;o>0;)1n==(1n&o)&&(n=n*i%r),i=i*i%r,o>>=1n;return n}sqrtModP(e,t){const r=this.modPow(e,t+1n>>2n,t);return r*r%t!==e%t?null:r}bytesToBigInt(e){let t=0n;for(const r of e)t=t<<8n|BigInt(r);return t}bigIntTo32Bytes(e){const t=new Uint8Array(32);for(let r=31;r>=0;r--)t[r]=Number(0xffn&e),e>>=8n;return t}}const IP=new class{constructor(){this.deriver=new AP}generateHybridKeyFromHash(e){const t=this.deriver.findOrDeriveValidPoint(this.cloneBuffer(e),!1),r=this.deriver.getCanonicalY(t.y1,t.y2);return nh.from(this.deriver.getHybridPublicKey(t.x,r))}cloneBuffer(e){return nh.from(e)}};class TP{static{this.UNSPENDABLE_INTERNAL_KEY=nh.from("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex")}static{this.CSV_BLOCKS=75}static generateTimeLockAddress(e,t=fI,r=TP.CSV_BLOCKS){const n=this.generateTimeLockScript(e,r),i=sP.payments.p2wsh({redeem:{output:n},network:t});if(!i.address)throw new Error("Failed to generate P2WSH address");return{address:i.address,witnessScript:n}}static generateTimeLockAddressP2TR(e,t=fI,r=TP.CSV_BLOCKS){if(32!==e.length)throw new Error("Public key must be 32 bytes for Taproot");const n=this.generateTimeLockScript(e,r),i=sP.payments.p2tr({redeem:{output:n},network:t,internalPubkey:TP.UNSPENDABLE_INTERNAL_KEY});if(!i.address)throw new Error("Failed to generate P2TR address");return i.address}static generateTimeLockScript(e,t=TP.CSV_BLOCKS){return rT([uT.encode(t),yI.OP_CHECKSEQUENCEVERIFY,yI.OP_DROP,e,yI.OP_CHECKSIG])}}class xP extends Uint8Array{#e;#t;#r;#n;#i;#o;#s;#a;#u;#c;#f;#l;#h;#p;#d;#y=!1;#g;constructor(e,t){if(super(yP),e){if(t){if(![yP,33,65].includes(t.length))throw new Error(`Invalid public key length ${t.length}`);this.#d=new Uint8Array(t.length),this.#d.set(t)}this.setMldsaKey(e)}}get mldsaLevel(){return this.#p}set mldsaLevel(e){this.#p=e}get originalMDLSAPublicKey(){return this.#h}set originalMDLSAPublicKey(e){this.#h=new Uint8Array(e)}get originalPublicKey(){return this.ensureLegacyProcessed(),this.#n}get mldsaPublicKey(){return this.#u}get legacyPublicKey(){return this.ensureLegacyProcessed(),this.#g}get keyPair(){if(this.ensureLegacyProcessed(),!this.#i)throw new Error("Legacy public key not set for address");return this.#i}static dead(){return xP.fromString("0x0000000000000000000000000000000000000000000000000000000000000000","0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")}static fromString(e,t){if(!e)throw new Error("Invalid public key");if(e.startsWith("0x")&&(e=e.slice(2)),!vP.isValidHex(e))throw new Error('You must only pass public keys in hexadecimal format. If you have an address such as bc1q... you must convert it to a public key first. Please refer to await provider.getPublicKeyInfo("bc1q..."). If the public key associated with the address is not found, you must force the user to enter the destination public key. It looks like: 0x020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c.');let r;if(t){if(t.startsWith("0x")&&(t=t.slice(2)),!vP.isValidHex(t))throw new Error('You must only pass classical public keys in hexadecimal format. If you have an address such as bc1q... you must convert it to a public key first. Please refer to await provider.getPublicKeyInfo("bc1q..."). If the public key associated with the address is not found, you must force the user to enter the destination public key. It looks like: 0x020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c.');r=nh.from(t,"hex")}return new xP(nh.from(e,"hex"),r)}static wrap(e){return new xP(e)}static uncompressedToCompressed(e){const t=Uint8Array.from(e),r=t.slice(1,33),n=t.slice(33),i=nh.alloc(33);return i[0]=2+(1&n[n.length-1]),i.set(r,1),i}static fromBigInt(e,t){const r=xP.bigintToUint8Array(e),n=void 0!==t?xP.bigintToUint8Array(t):void 0;return new xP(r,n)}static fromUint64Array(e,t,r,n){const i=new Uint8Array(32),o=new DataView(i.buffer);return o.setBigUint64(0,e,!1),o.setBigUint64(8,t,!1),o.setBigUint64(16,r,!1),o.setBigUint64(24,n,!1),new xP(i)}static bigintToUint8Array(e){const t=new Uint8Array(32),r=new DataView(t.buffer);return r.setBigUint64(0,e>>192n&0xffffffffffffffffn,!1),r.setBigUint64(8,e>>128n&0xffffffffffffffffn,!1),r.setBigUint64(16,e>>64n&0xffffffffffffffffn,!1),r.setBigUint64(24,0xffffffffffffffffn&e,!1),t}toUint64Array(){if(void 0!==this.#l)return this.#l;const e=new DataView(this.buffer,this.byteOffset,32);return this.#l=[e.getBigUint64(0,!1),e.getBigUint64(8,!1),e.getBigUint64(16,!1),e.getBigUint64(24,!1)],this.#l}isDead(){for(let e=0;e<yP;e++)if(0!==this[e])return!1;return!0}toHex(){return"0x"+nh.from(this).toString("hex")}tweakedToHex(){const e=this.legacyPublicKey;if(!e)throw new Error("Legacy public key not set");return"0x"+nh.from(e).toString("hex")}toBuffer(){return nh.from(this)}tweakedPublicKeyToBuffer(){const e=this.legacyPublicKey;if(!e)throw new Error("Legacy public key not set");return nh.from(e)}toUncompressedHex(){if(this.ensureLegacyProcessed(),!this.#o)throw new Error("Legacy public key not set");return"0x"+this.#o.uncompressed.toString("hex")}toUncompressedBuffer(){if(this.ensureLegacyProcessed(),!this.#o)throw new Error("Legacy public key not set");return this.#o.uncompressed}toHybridPublicKeyHex(){if(this.ensureLegacyProcessed(),!this.#o)throw new Error("Legacy public key not set");return"0x"+this.#o.hybrid.toString("hex")}toHybridPublicKeyBuffer(){if(this.ensureLegacyProcessed(),!this.#o)throw new Error("Legacy public key not set");return this.#o.hybrid}originalPublicKeyBuffer(){if(this.ensureLegacyProcessed(),!this.#n)throw new Error("Legacy public key not set");return nh.from(this.#n)}toBigInt(){if(void 0!==this.#c)return this.#c;const e=new DataView(this.buffer,this.byteOffset,32);return this.#c=e.getBigUint64(0,!1)<<192n|e.getBigUint64(8,!1)<<128n|e.getBigUint64(16,!1)<<64n|e.getBigUint64(24,!1),this.#c}tweakedToBigInt(){if(!this.legacyPublicKey)throw new Error("Legacy public key not set");if(void 0!==this.#f)return this.#f;const e=new DataView(this.legacyPublicKey.buffer,this.byteOffset,32);return this.#f=e.getBigUint64(0,!1)<<192n|e.getBigUint64(8,!1)<<128n|e.getBigUint64(16,!1)<<64n|e.getBigUint64(24,!1),this.#f}equals(e){const t=this;if(e.length!==t.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}lessThan(e){const t=this;for(let r=0;r<yP;r++){const n=t[r],i=e[r];if(n<i)return!0;if(n>i)return!1}return!1}greaterThan(e){const t=this;for(let r=0;r<yP;r++){const n=t[r],i=e[r];if(n>i)return!0;if(n<i)return!1}return!1}set(e){this.setMldsaKey(e)}isValidLegacyPublicKey(e){const t=this.legacyPublicKey;if(!t)throw new Error("Legacy key not set.");return SP.isValidPublicKey(nh.from(t).toString("hex"),e)}p2pk(){return this.toHex()}p2wpkh(e){return dP.getP2WPKHAddress(this.keyPair,e)}p2pkh(e){return dP.getLegacyAddress(this.keyPair,e)}p2shp2wpkh(e){return dP.getLegacySegwitAddress(this.keyPair,e)}toString(){return this.toHex()}toJSON(){return this.toHex()}p2tr(e){if(this.#e&&this.#r===e)return this.#e;const t=this.legacyPublicKey;if(!t)throw new Error("Legacy public key not set");const r=dP.tweakedPubKeyBufferToAddress(t,e);if(r)return this.#r=e,this.#e=r,r;throw new Error("Legacy public key not set")}p2wda(e){if(this.#a&&this.#r===e)return this.#a;if(this.ensureLegacyProcessed(),!this.#n)throw new Error("Cannot create P2WDA address: public key not set");const t=nh.from(this.#n);if(33!==t.length)throw new Error("P2WDA requires a compressed public key (33 bytes)");try{const r=EP.generateP2WDAAddress(t,e);return this.#r=e,this.#a=r,{address:r.address,witnessScript:r.witnessScript}}catch(LU){throw new Error(`Failed to generate P2WDA address: ${LU.message}`)}}toCSV(e,t){const r=Number(e);if(r<1||r>65535)throw new Error("CSV block number must be between 1 and 65535");if(this.ensureLegacyProcessed(),!this.#n)throw new Error("Cannot create CSV address: public key not set");const n=nh.from(this.#n);return TP.generateTimeLockAddress(n,t,r)}toCSVTweaked(e,t){const r=Number(e);if(r<1||r>65535)throw new Error("CSV block number must be between 1 and 65535");if(this.ensureLegacyProcessed(),!this.#n)throw new Error("Cannot create CSV address: public key not set");return TP.generateTimeLockAddressP2TR(this.tweakedPublicKeyToBuffer(),t,r)}p2op(e){if(this.#t&&this.#r===e)return this.#t;const t=dP.p2op(this,e);if(t)return this.#r=e,this.#t=t,t;throw new Error("ML-DSA public key not set")}toTweakedHybridPublicKeyHex(){if(this.ensureLegacyProcessed(),this.ensureTweakedUncompressed(),!this.#s)throw new Error("Legacy public key not set");return"0x"+this.#s.toString("hex")}toTweakedHybridPublicKeyBuffer(){if(this.ensureLegacyProcessed(),this.ensureTweakedUncompressed(),!this.#s)throw new Error("Legacy public key not set");return this.#s}ensureTweakedUncompressed(){if(this.#s)return;const e=this.#g;if(e&&e.length===yP&&!this.#n)try{const t=nh.alloc(yP);t.set(e),this.#s=IP.generateHybridKeyFromHash(t)}catch{}}setMldsaKey(e){if(e.length===yP){const t=new Uint8Array(yP);t.set(e),super.set(t)}else{if(![1312,1952,2592].includes(e.length))throw new Error(`Invalid ML-DSA public key length: ${e.length}. Expected 1312 (ML-DSA-44/LEVEL2), 1952 (ML-DSA-65/LEVEL3), or 2592 (ML-DSA-87/LEVEL5) bytes.`);this.#u=new Uint8Array(e.length),this.#u.set(e);const t=ku(new Uint8Array(e)),r=new Uint8Array(yP);r.set(t),super.set(r)}}ensureLegacyProcessed(){if(this.#y)return;this.#y=!0;const e=this.#d;e&&(e.length===yP?this.#g=e:this.autoFormat(e))}autoFormat(e){const t=e[0];3===t||2===t||(4===t||6===t||7===t)&&(e=xP.uncompressedToCompressed(e)),this.#n=Uint8Array.from(e),this.#i=dP.fromPublicKey(this.#n),this.#o=Qx(this.#n);const r=Yx(dP.tweakPublicKey(nh.from(this.#n)));this.#s=IP.generateHybridKeyFromHash(r),this.#g=new Uint8Array(yP),this.#g.set(r)}}class OP{constructor(e){if(this._keys=[],this._values={},e instanceof OP)this.setAll(e);else if(e)for(const[t,r]of e)this.set(t,r)}get size(){return this._keys.length}setAll(e){this._keys=[...e._keys],this._values={...e._values}}addAll(e){for(const[t,r]of e.entries())this.set(t,r)}*keys(){yield*this._keys}*values(){for(const e of this._keys)yield this._values[e]}*entries(){for(const e of this._keys)yield[e,this._values[e]]}set(e,t){return this.has(e)||this._keys.push(e),this._values[e]=t,this}indexOf(e){if(!this.has(e))return-1;for(let t=0;t<this._keys.length;t++)if(this._keys[t]===e)return t;throw new Error("Key not found, this should not happen.")}get(e){return this._values[e]}has(e){return Object.prototype.hasOwnProperty.call(this._values,e)}delete(e){if(!this.has(e))return!1;const t=this.indexOf(e);return this._keys.splice(t,1),delete this._values[e],!0}clear(){this._keys=[],this._values={}}forEach(e,t){for(const r of this._keys)e.call(t,this._values[r],r,this)}*[Symbol.iterator](){for(const e of this._keys)yield[e,this._values[e]]}}class BP{constructor(e){if(this.items=new OP,e)for(const[t,r]of e)this.set(t,r)}get size(){return this.items.size}set(e,t){const r=e.toBigInt();return this.items.set(r,t),this}get(e){return this.items.get(e.toBigInt())}has(e){return this.items.has(e.toBigInt())}delete(e){const t=e.toBigInt();return this.items.delete(t)}clear(){this.items.clear()}indexOf(e){return this.items.indexOf(e.toBigInt())}*entries(){for(const[e,t]of this.items.entries())yield[xP.fromBigInt(e),t]}*keys(){for(const e of this.items.keys())yield xP.fromBigInt(e)}*values(){for(const e of this.items.values())yield e}forEach(e,t){for(const[r,n]of this.items.entries()){const i=xP.fromBigInt(r);e.call(t,n,i,this)}}*[Symbol.iterator](){yield*this.entries()}}class PP{constructor(e){if(this._keys=[],this._values=[],this.indexMap=new OP,e)for(const[t,r]of e)this.set(t,r)}get size(){return this._keys.length}set(e,t){const r=e.tweakedToBigInt(),n=this.indexMap.get(r);if(void 0!==n)this._values[n]=t;else{const n=this._keys.length;this._keys.push(e),this._values.push(t),this.indexMap.set(r,n)}return this}get(e){const t=e.tweakedToBigInt(),r=this.indexMap.get(t);if(void 0!==r)return this._values[r]}has(e){return this.indexMap.has(e.tweakedToBigInt())}delete(e){const t=e.tweakedToBigInt(),r=this.indexMap.get(t);if(void 0===r)return!1;this._keys.splice(r,1),this._values.splice(r,1),this.indexMap.clear();for(let n=0;n<this._keys.length;n++)this.indexMap.set(this._keys[n].tweakedToBigInt(),n);return!0}clear(){this.indexMap.clear(),this._keys=[],this._values=[]}indexOf(e){const t=this.indexMap.get(e.tweakedToBigInt());return void 0!==t?t:-1}*entries(){for(let e=0;e<this._keys.length;e++)yield[this._keys[e],this._values[e]]}*keys(){for(const e of this._keys)yield e}*values(){for(const e of this._values)yield e}forEach(e,t){for(let r=0;r<this._keys.length;r++)e.call(t,this._values[r],this._keys[r],this)}*[Symbol.iterator](){yield*this.entries()}}class UP{constructor(e){this.currentOffset=0,this.buffer=new DataView(e.buffer,e.byteOffset,e.byteLength)}static stringCompare(e,t){return e.localeCompare(t)}static bigintCompare(e,t){return e<t?-1:e>t?1:0}static numberCompare(e,t){return e<t?-1:e>t?1:0}setBuffer(e){this.buffer=new DataView(e.buffer,e.byteOffset,e.byteLength),this.currentOffset=0}get byteLength(){return this.buffer.byteLength}length(){return this.buffer.byteLength}bytesLeft(){return this.buffer.byteLength-this.currentOffset}readI8(){this.verifyEnd(this.currentOffset+1);const e=this.buffer.getInt8(this.currentOffset);return this.currentOffset+=1,e}readI16(e=!0){this.verifyEnd(this.currentOffset+2);const t=this.buffer.getInt16(this.currentOffset,!e);return this.currentOffset+=2,t}readI32(e=!0){this.verifyEnd(this.currentOffset+4);const t=this.buffer.getInt32(this.currentOffset,!e);return this.currentOffset+=4,t}readI64(e=!0){this.verifyEnd(this.currentOffset+8);const t=this.buffer.getBigInt64(this.currentOffset,!e);return this.currentOffset+=8,t}readU8(){this.verifyEnd(this.currentOffset+1);const e=this.buffer.getUint8(this.currentOffset);return this.currentOffset+=1,e}readU16(e=!0){this.verifyEnd(this.currentOffset+2);const t=this.buffer.getUint16(this.currentOffset,!e);return this.currentOffset+=2,t}readU32(e=!0){this.verifyEnd(this.currentOffset+4);const t=this.buffer.getUint32(this.currentOffset,!e);return this.currentOffset+=4,t}readU64(e=!0){this.verifyEnd(this.currentOffset+8);const t=this.buffer.getBigUint64(this.currentOffset,!e);return this.currentOffset+=8,t}readU128(e=!0){const t=this.readBytes(16);let r=t;return e||(r=this.reverseBytes(t)),BigInt("0x"+this.toHexString(r))}readU256(e=!0){const t=this.readBytes(32);let r=t;return e||(r=this.reverseBytes(t)),BigInt("0x"+this.toHexString(r))}readI128(e=!0){const t=this.readBytes(16);let r=t;e||(r=this.reverseBytes(t));let n=BigInt("0x"+this.toHexString(r));if(128&r[0]){n-=BigInt(1)<<BigInt(128)}return n}readBoolean(){return 0!==this.readU8()}readSelector(){return this.readU32(!0)}readBytes(e,t=!1){this.verifyEnd(this.currentOffset+e);let r=new Uint8Array(e);for(let n=0;n<e;n++){const e=this.buffer.getUint8(this.currentOffset++);if(t&&0===e){r=nh.from(r.subarray(0,n));break}r[n]=e}return r}readString(e){const t=new TextDecoder,r=this.readBytes(e,!1);return t.decode(r)}readStringWithLength(e=!0){const t=this.readU32(e);return this.readString(t)}readAddress(){const e=Array.from(this.readBytes(yP));return new xP(e)}readTweakedPublicKey(){return this.verifyEnd(this.currentOffset+yP),this.readBytes(yP)}readExtendedAddress(){this.verifyEnd(this.currentOffset+gP);const e=Array.from(this.readBytes(yP)),t=Array.from(this.readBytes(yP));return new xP(t,e)}readSchnorrSignature(){this.verifyEnd(this.currentOffset+gP+mP);return{address:this.readExtendedAddress(),signature:this.readBytes(mP)}}readBytesWithLength(e=0,t=!0){const r=this.readU32(t);if(e>0&&r>e)throw new Error("Data length exceeds maximum length.");return this.readBytes(r)}readArrayOfBuffer(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readBytesWithLength();return r}readAddressArray(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readAddress();return r}readU256Array(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readU256(e);return r}readU128Array(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readU128(e);return r}readU64Array(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readU64(e);return r}readU32Array(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readU32(e);return r}readU16Array(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readU16(e);return r}readU8Array(){const e=this.readU16(!0),t=new Array(e);for(let r=0;r<e;r++)t[r]=this.readU8();return t}readStringArray(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readStringWithLength(e);return r}readBytesArray(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readBytesWithLength(0,e);return r}readAddressValueTuple(e=!0){const t=this.readU16(e),r=new BP;for(let n=0;n<t;n++){const t=this.readAddress(),n=this.readU256(e);if(r.has(t))throw new Error("Duplicate address found in map");r.set(t,n)}return r}readExtendedAddressArray(e=!0){const t=this.readU16(e),r=new Array(t);for(let n=0;n<t;n++)r[n]=this.readExtendedAddress();return r}readExtendedAddressMapU256(e=!0){const t=this.readU16(e),r=new PP;for(let n=0;n<t;n++){const t=this.readExtendedAddress(),n=this.readU256(e);if(r.has(t))throw new Error("Duplicate tweaked address found in map");r.set(t,n)}return r}getOffset(){return this.currentOffset}setOffset(e){this.currentOffset=e}verifyEnd(e){if(e>this.buffer.byteLength)throw new Error(`Attempt to read beyond buffer length: requested up to byte offset ${e}, but buffer is only ${this.buffer.byteLength} bytes.`)}reverseBytes(e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e[e.length-1-r];return t}toHexString(e){return Array.from(e,e=>e.toString(16).padStart(2,"0")).join("")}}class LP{constructor(e=0){this.currentOffset=0,this.buffer=this.getDefaultBuffer(e)}static estimateArrayOfBufferLength(e){if(e.length>65535)throw new Error("Array size is too large");let t=2;for(let r=0;r<e.length;r++)t+=4+e[r].length;return t}writeU8(e){if(e>255)throw new Error("u8 value is too large.");this.allocSafe(1),this.buffer.setUint8(this.currentOffset++,e)}writeU16(e,t=!0){if(e>65535)throw new Error("u16 value is too large.");this.allocSafe(2),this.buffer.setUint16(this.currentOffset,e,!t),this.currentOffset+=2}writeU32(e,t=!0){if(e>4294967295)throw new Error("u32 value is too large.");this.allocSafe(4),this.buffer.setUint32(this.currentOffset,e,!t),this.currentOffset+=4}writeU64(e,t=!0){if(e>18446744073709551615n)throw new Error("u64 value is too large.");this.allocSafe(8),this.buffer.setBigUint64(this.currentOffset,e,!t),this.currentOffset+=8}writeI8(e){if(e<-128||e>127)throw new Error("i8 value is out of range.");this.allocSafe(1),this.buffer.setInt8(this.currentOffset,e),this.currentOffset+=1}writeI16(e,t=!0){if(e<-32768||e>32767)throw new Error("i16 value is out of range.");this.allocSafe(2),this.buffer.setInt16(this.currentOffset,e,!t),this.currentOffset+=2}writeI32(e,t=!0){if(e<-2147483648||e>2147483647)throw new Error("i32 value is out of range.");this.allocSafe(4),this.buffer.setInt32(this.currentOffset,e,!t),this.currentOffset+=4}writeI64(e,t=!0){if(e<-9223372036854775808n||e>9223372036854775807n)throw new Error("i64 value is out of range.");this.allocSafe(8),this.buffer.setBigInt64(this.currentOffset,e,!t),this.currentOffset+=8}writeSelector(e){this.writeU32(e,!0)}writeBoolean(e){this.writeU8(e?1:0)}writeI128(e,t=!0){if(e>170141183460469231731687303715884105727n||e<-170141183460469231731687303715884105728n)throw new Error("i128 value is too large.");this.allocSafe(16);const r=bP.valueToUint8Array(e,16);if(16!==r.byteLength)throw new Error(`Invalid i128 value: ${e}`);if(t)for(let n=0;n<r.byteLength;n++)this.writeU8(r[n]);else for(let n=r.byteLength-1;n>=0;n--)this.writeU8(r[n])}writeU256(e,t=!0){if(e>115792089237316195423570985008687907853269984665640564039457584007913129639935n&&e<0n)throw new Error("u256 value is too large or negative.");this.allocSafe(32);const r=bP.valueToUint8Array(e);if(32!==r.byteLength)throw new Error(`Invalid u256 value: ${e}`);if(t)for(let n=0;n<r.byteLength;n++)this.writeU8(r[n]);else for(let n=r.byteLength-1;n>=0;n--)this.writeU8(r[n])}writeU128(e,t=!0){if(e>340282366920938463463374607431768211455n&&e<0n)throw new Error("u128 value is too large or negative.");this.allocSafe(16);const r=bP.valueToUint8Array(e,16);if(16!==r.byteLength)throw new Error(`Invalid u128 value: ${e}`);if(t)for(let n=0;n<r.byteLength;n++)this.writeU8(r[n]);else for(let n=r.byteLength-1;n>=0;n--)this.writeU8(r[n])}writeBytes(e){this.allocSafe(e.byteLength);for(let t=0;t<e.byteLength;t++)this.writeU8(e[t])}writeString(e){const t=(new TextEncoder).encode(e);this.allocSafe(t.length),this.writeBytes(t)}writeStringWithLength(e){const t=(new TextEncoder).encode(e);this.allocSafe(4+t.length),this.writeU32(t.length),this.writeBytes(t)}writeAddress(e){this.verifyAddress(e),this.writeBytes(e)}writeTweakedPublicKey(e){const t=e.tweakedPublicKeyToBuffer();this.allocSafe(yP),this.writeBytes(t)}writeExtendedAddress(e){this.allocSafe(gP),this.writeTweakedPublicKey(e),this.writeBytes(e)}writeSchnorrSignature(e,t){if(t.length!==mP)throw new Error(`Invalid Schnorr signature length: expected 64, got ${t.length}`);this.allocSafe(128),this.writeExtendedAddress(e),this.writeBytes(t)}getBuffer(e=!0){const t=new Uint8Array(this.buffer.byteLength);for(let r=0;r<this.buffer.byteLength;r++)t[r]=this.buffer.getUint8(r);return e&&this.clear(),t}reset(){this.currentOffset=0,this.buffer=this.getDefaultBuffer(4)}toBytesReader(){return new UP(this.getBuffer())}getOffset(){return this.currentOffset}setOffset(e){this.currentOffset=e}clear(){this.currentOffset=0,this.buffer=this.getDefaultBuffer()}allocSafe(e){this.currentOffset+e>this.buffer.byteLength&&this.resize(e)}writeAddressValueTuple(e,t=!0){if(e.size>65535)throw new Error("Map size is too large");this.writeU16(e.size,t);const r=Array.from(e.keys());for(let n=0;n<r.length;n++){const i=r[n],o=e.get(i);if(null==o)throw new Error("Value not found");this.writeAddress(i),this.writeU256(o,t)}}writeExtendedAddressMapU256(e,t=!0){if(e.size>65535)throw new Error("Map size is too large");this.writeU16(e.size,t);for(const[r,n]of e.entries())this.writeExtendedAddress(r),this.writeU256(n,t)}writeBytesWithLength(e){this.writeU32(e.length),this.writeBytes(e)}writeArrayOfBuffer(e,t=!0){const r=LP.estimateArrayOfBufferLength(e);this.allocSafe(r),this.writeU16(e.length,t);for(let n=0;n<e.length;n++)this.writeU32(e[n].length,t),this.writeBytes(e[n])}writeAddressArray(e){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length);for(let t=0;t<e.length;t++)this.writeAddress(e[t])}writeExtendedAddressArray(e){if(e.length>65535)throw new Error("Array size is too large");this.allocSafe(2+e.length*gP),this.writeU16(e.length);for(let t=0;t<e.length;t++)this.writeExtendedAddress(e[t])}writeU32Array(e,t=!0){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length,t);for(let r=0;r<e.length;r++)this.writeU32(e[r],t)}writeU256Array(e,t=!0){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length,t);for(let r=0;r<e.length;r++)this.writeU256(e[r],t)}writeU128Array(e,t=!0){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length,t);for(let r=0;r<e.length;r++)this.writeU128(e[r],t)}writeStringArray(e){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length);for(let t=0;t<e.length;t++)this.writeStringWithLength(e[t])}writeU16Array(e,t=!0){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length,t);for(let r=0;r<e.length;r++)this.writeU16(e[r],t)}writeU8Array(e){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length);for(let t=0;t<e.length;t++)this.writeU8(e[t])}writeU64Array(e,t=!0){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length,t);for(let r=0;r<e.length;r++)this.writeU64(e[r],t)}writeBytesArray(e){if(e.length>65535)throw new Error("Array size is too large");this.writeU16(e.length);for(let t=0;t<e.length;t++)this.writeBytesWithLength(e[t])}verifyAddress(e){if(e.byteLength>yP)throw new Error(`Address is too long ${e.byteLength} > ${yP} bytes`)}resize(e){const t=new Uint8Array(this.buffer.byteLength+e);for(let r=0;r<this.buffer.byteLength;r++)t[r]=this.buffer.getUint8(r);this.buffer=new DataView(t.buffer,t.byteOffset,t.byteLength)}getDefaultBuffer(e=0){return new DataView(new ArrayBuffer(e))}}var NP=(e=>(e[e.ACCESS_LIST=1]="ACCESS_LIST",e[e.EPOCH_SUBMISSION=2]="EPOCH_SUBMISSION",e[e.MLDSA_LINK_PUBKEY=4]="MLDSA_LINK_PUBKEY",e))(NP||{}),RP=(e=>(e[e.ACCESS_LIST=1]="ACCESS_LIST",e[e.EPOCH_SUBMISSION=2]="EPOCH_SUBMISSION",e[e.MLDSA_LINK_PUBKEY=3]="MLDSA_LINK_PUBKEY",e))(RP||{});class CP{constructor(e,t,r=fI){this.network=fI,this.senderPubKey=e,this.contractSaltPubKey=t,this.network=r,this.xSenderPubKey=Yx(e)}static{this.DATA_CHUNK_SIZE=512}static{this.MAGIC=nh.from("op","utf-8")}buildHeader(e){let t=0;for(const n of e)t|=n;const r=nh.alloc(3);return r.writeUIntBE(t,0,3),nh.from([this.senderPubKey[0],...r])}getHeader(e,t=[]){const r=new LP(12);return r.writeBytes(this.buildHeader(t)),r.writeU64(e),nh.from(r.getBuffer())}splitBufferIntoChunks(e,t=CP.DATA_CHUNK_SIZE){const r=[];for(let n=0;n<e.length;n+=t){const i=Math.min(t,e.length-n),o=nh.alloc(i);for(let t=0;t<i;t++)o.writeUInt8(e[n+t],t);r.push([o])}return r}encodeFeature(e,t){switch(e.opcode){case NP.ACCESS_LIST:return this.encodeAccessListFeature(e,t);case NP.EPOCH_SUBMISSION:return this.encodeChallengeSubmission(e,t);case NP.MLDSA_LINK_PUBKEY:return this.encodeLinkRequest(e,t);default:throw new Error(`Unknown feature type: ${e.opcode}`)}}encodeAccessListFeature(e,t){const r=new LP;r.writeU16(Object.keys(e.data).length);for(const n in e.data){const t=xP.fromString(n),i=e.data[n];r.writeAddress(t),r.writeU32(i.length);for(const e of i){const t=nh.from(e,"base64");if(32!==t.length)throw new Error(`Invalid pointer length: ${t.length}`);r.writeBytes(t)}}t.writeBytesWithLength(uP.compress(nh.from(r.getBuffer())))}encodeChallengeSubmission(e,t){if("verifySignature"in e.data&&!e.data.verifySignature())throw new Error("Invalid signature in challenge submission feature");const r=new LP;r.writeBytes(e.data.publicKey.toBuffer()),r.writeBytes(e.data.solution),e.data.graffiti&&r.writeBytesWithLength(e.data.graffiti),t.writeBytesWithLength(r.getBuffer())}encodeLinkRequest(e,t){const r=e.data,n=new LP;if(n.writeU8(r.level),n.writeBytes(r.hashedPublicKey),n.writeBoolean(r.verifyRequest),r.verifyRequest){if(!r.publicKey||!r.mldsaSignature)throw new Error("MLDSA public key and signature required when verifyRequest is true");n.writeBytes(r.publicKey),n.writeBytes(r.mldsaSignature)}if(!r.legacySignature||64!==r.legacySignature.length)throw new Error("Legacy signature must be exactly 64 bytes");n.writeBytes(r.legacySignature),t.writeBytesWithLength(n.getBuffer())}}class HP extends CP{constructor(e,t,r=fI){super(e,t,r)}static getPubKeyAsBuffer(e,t){let r=nh.alloc(0);for(const i of e){if(!dP.fromPublicKey(i,t).compressed)throw new Error("Public key must be compressed");if(33!==i.byteLength)throw new Error(`Public key must be 33 bytes, got ${i.byteLength} bytes.`);r=nh.concat([r,i])}const n=uP.compress(r);return n.byteLength>=r.byteLength?r:n}compile(e,t,r,n,i=[]){if(!this.contractSaltPubKey)throw new Error("Contract salt public key not set");const o=this.splitBufferIntoChunks(e);if(!o.length)throw new Error("No data chunks found");const s=[],a=[];if(i&&i.length){const e=i.sort((e,t)=>e.priority-t.priority),t=new LP;for(let r=0;r<e.length;r++){const n=e[r];s.push(n.opcode),this.encodeFeature(n,t)}a.push(...this.splitBufferIntoChunks(nh.from(t.getBuffer())))}let u=[this.getHeader(n,s),yI.OP_TOALTSTACK,r.publicKey.toBuffer(),yI.OP_TOALTSTACK,r.solution,yI.OP_TOALTSTACK,this.xSenderPubKey,yI.OP_DUP,yI.OP_HASH256,nx(this.xSenderPubKey),yI.OP_EQUALVERIFY,yI.OP_CHECKSIGVERIFY,this.contractSaltPubKey,yI.OP_CHECKSIGVERIFY,yI.OP_HASH160,rx(t),yI.OP_EQUALVERIFY,yI.OP_DEPTH,yI.OP_1,yI.OP_NUMEQUAL,yI.OP_IF,CP.MAGIC];u=u.concat(...a,yI.OP_1NEGATE,...o,yI.OP_ELSE,yI.OP_1,yI.OP_ENDIF);const c=rT(u.flat());if(!nT(c))throw new Error("Failed to decompile script??");return c}}const KP=nh.from([0]);class zP extends CP{constructor(e,t,r=fI){super(e,t,r)}compile(e,t,r,n,i,o){const s=rT(this.getAsm(e,t,r,n,i,o));if(!nT(s))throw new Error("Failed to decompile script??");return s}getAsm(e,t,r,n,i,o){if(!this.contractSaltPubKey)throw new Error("Contract salt public key not set");const s=this.splitBufferIntoChunks(e),a=i?this.splitBufferIntoChunks(i):[],u=[],c=[];if(o&&o.length){const e=o.sort((e,t)=>e.priority-t.priority),t=new LP;for(let r=0;r<e.length;r++){const n=e[r];u.push(n.opcode),this.encodeFeature(n,t)}c.push(...this.splitBufferIntoChunks(nh.from(t.getBuffer())))}return[this.getHeader(n,u),yI.OP_TOALTSTACK,r.publicKey.toBuffer(),yI.OP_TOALTSTACK,r.solution,yI.OP_TOALTSTACK,this.xSenderPubKey,yI.OP_DUP,yI.OP_HASH256,nx(this.xSenderPubKey),yI.OP_EQUALVERIFY,yI.OP_CHECKSIGVERIFY,this.contractSaltPubKey,yI.OP_CHECKSIGVERIFY,yI.OP_HASH256,nx(t),yI.OP_EQUALVERIFY,yI.OP_DEPTH,yI.OP_1,yI.OP_NUMEQUAL,yI.OP_IF,CP.MAGIC,...c,yI.OP_0,...a,yI.OP_1NEGATE,...s,yI.OP_ELSE,yI.OP_1,yI.OP_ENDIF].flat()}}class MP extends n_{constructor(e,t=fI){if(super(),this.logColor="#4a90d9",33!==e.length)throw new Error("Public key must be 33 bytes (compressed)");this.publicKey=e,this.network=t}static{this.MAX_CHUNK_SIZE=80}static{this.MAX_STACK_ITEMS=100}static{this.MAX_WITNESS_SIZE=1650}static{this.MAX_STANDARD_WEIGHT=4e5}static{this.MIN_OUTPUT_VALUE=330n}static{this.BYTES_PER_COMMITMENT=23}static{this.SIG_CHECK_BYTES=35}static{this.WITNESS_FIXED_OVERHEAD=112}static{this.WITNESS_PER_CHUNK_OVERHEAD=MP.MAX_CHUNK_SIZE+1+MP.BYTES_PER_COMMITMENT}static{this.MAX_CHUNKS_PER_OUTPUT=Math.floor((MP.MAX_WITNESS_SIZE-MP.WITNESS_FIXED_OVERHEAD)/MP.WITNESS_PER_CHUNK_OVERHEAD)}static{this.INPUT_BASE_WEIGHT=164}static{this.INPUT_WITNESS_WEIGHT_MAX=MP.MAX_WITNESS_SIZE}static{this.WEIGHT_PER_INPUT=MP.INPUT_BASE_WEIGHT+MP.INPUT_WITNESS_WEIGHT_MAX}static calculateMaxInputsPerTx(){const e=MP.MAX_STANDARD_WEIGHT-40-200;return Math.floor(e/MP.WEIGHT_PER_INPUT)}static calculateMaxDataPerTx(){return MP.calculateMaxInputsPerTx()*MP.MAX_CHUNKS_PER_OUTPUT*MP.MAX_CHUNK_SIZE}static estimateOutputCount(e){return Math.ceil(e/(MP.MAX_CHUNKS_PER_OUTPUT*MP.MAX_CHUNK_SIZE))}static estimateChunkCount(e){return Math.ceil(e/MP.MAX_CHUNK_SIZE)}static validateHashCommittedScript(e){try{const t=nT(e);if(!t||t.length<5)return!1;const r=t.length-1;if(t[r]!==yI.OP_CHECKSIG)return!1;const n=t[r-1];if(!nh.isBuffer(n)||33!==n.length)return!1;const i=t.slice(0,-2);if(i.length%3!=0||0===i.length)return!1;for(let e=0;e<i.length;e+=3){const t=i[e+1];if(i[e]!==yI.OP_HASH160||!nh.isBuffer(t)||20!==t.length||i[e+2]!==yI.OP_EQUALVERIFY)return!1}return!0}catch{return!1}}static extractDataHashes(e){try{const t=nT(e);if(!t||!MP.validateHashCommittedScript(e))return null;const r=t.slice(0,-2),n=[];for(let e=0;e<r.length;e+=3)n.push(r[e+1]);return n.reverse()}catch{return null}}static extractPublicKey(e){try{const t=nT(e);return t&&MP.validateHashCommittedScript(e)?t[t.length-2]:null}catch{return null}}static verifyChunkCommitments(e,t){const r=MP.extractDataHashes(t);if(!r||r.length!==e.length)return!1;for(let n=0;n<e.length;n++){const t=rx(e[n]);if(!r[n].equals(t))return!1}return!0}static estimateFees(e,t,r=.7){const n=Math.ceil(e*r),i=MP.estimateOutputCount(n),o=MP.estimateChunkCount(n),s=127+(43*i+43),a=40+i*MP.WEIGHT_PER_INPUT+200,u=Math.ceil(a/4),c=BigInt(Math.ceil(s*t)),f=BigInt(Math.ceil(u*t)),l=c+f,h=BigInt(i)*MP.MIN_OUTPUT_VALUE;return{compressedSize:n,outputCount:i,chunkCount:o,setupVBytes:s,revealVBytes:u,setupFee:c,revealFee:f,totalFee:l,outputsValue:h,totalCost:l+h}}hashChunk(e){return rx(e)}generateWitnessScript(e){if(0===e.length)throw new Error("At least one data hash is required");if(e.length>MP.MAX_CHUNKS_PER_OUTPUT)throw new Error(`Too many chunks: ${e.length} exceeds limit of ${MP.MAX_CHUNKS_PER_OUTPUT}`);for(const r of e)if(20!==r.length)throw new Error(`HASH160 requires 20-byte hash, got ${r.length}`);const t=[];for(let r=e.length-1;r>=0;r--)t.push(yI.OP_HASH160),t.push(e[r]),t.push(yI.OP_EQUALVERIFY);return t.push(this.publicKey),t.push(yI.OP_CHECKSIG),rT(t)}generateP2WSHAddress(e){const t=UO({redeem:{output:e},network:this.network});if(!t.address||!t.output)throw new Error("Failed to generate P2WSH address");return{address:t.address,witnessScript:e,scriptPubKey:t.output}}prepareChunks(e,t=MP.MAX_CHUNK_SIZE){if(t>MP.MAX_CHUNK_SIZE)throw new Error(`Chunk size ${t} exceeds P2WSH stack item limit of ${MP.MAX_CHUNK_SIZE}`);if(0===e.length)throw new Error("Data cannot be empty");const r=[];let n=0;for(;n<e.length;){const i=Math.min(t,e.length-n);r.push(nh.from(e.subarray(n,n+i))),n+=i}const i=[];let o=0;for(;o<r.length;){const e=r.slice(o,o+MP.MAX_CHUNKS_PER_OUTPUT),t=e,n=t.map(e=>this.hashChunk(e)),s=this.generateWitnessScript(n),a=this.generateP2WSHAddress(s);i.push({address:a.address,witnessScript:a.witnessScript,scriptPubKey:a.scriptPubKey,dataHashes:n,dataChunks:t,chunkStartIndex:o}),o+=e.length}const s=r.length;return this.log(`Prepared ${i.length} P2WSH outputs with ${s} chunks (${e.length} bytes, ~${Math.ceil(e.length/i.length)} bytes/output)`),i}}class DP{static{this.MAXIMUM_SUPPORTED_SIGNATURE=255}static compile(e,t=0,r){if(t<2)throw new Error("Minimum signatures must be greater than 1");if(e.length<t)throw new Error("The amount of public keys is lower than the minimum required");if(t>DP.MAXIMUM_SUPPORTED_SIGNATURE)throw new Error(`The maximum amount of signatures is ${DP.MAXIMUM_SUPPORTED_SIGNATURE}`);const n=nh.alloc(1);n.writeUInt8(t),e=(e=e.filter((e,t,r)=>t===r.findIndex(t=>e.equals(t)))).sort((e,t)=>e.compare(t));let i=!1;const o=e.map(e=>{const t=Yx(e);return r&&!i&&(i=r.equals(t)),t});r&&!i&&o.push(r);const s=rT([yI.OP_0,...o.flatMap(e=>[e,yI.OP_CHECKSIGADD]),n,yI.OP_NUMEQUAL].flat());if(!nT(s))throw new Error("Failed to decompile script.");return s}}class jP extends CP{static{this.P2WDA_VERSION=1}constructor(e,t,r=fI){super(e,t,r)}static validateWitnessSize(e,t=10,r=80){const n=e+64,i=Math.ceil(.7*n);return Math.ceil(i/r)<=t}compile(e,t,r,n,i=[]){if(!this.contractSaltPubKey)throw new Error("Contract salt public key not set");if(32!==t.length)throw new Error("Contract secret must be exactly 32 bytes");const o=new LP;o.writeU8(jP.P2WDA_VERSION);const s=i.sort((e,t)=>e.priority-t.priority);return o.writeBytes(this.getHeader(n,s.map(e=>e.opcode))),o.writeBytes(t),o.writeBytes(r.publicKey.toBuffer()),o.writeBytes(r.solution),o.writeU32(e.length),o.writeBytes(e),this.writeFeatures(o,s),nh.from(o.getBuffer())}getHeader(e,t=[]){return super.getHeader(e,t)}writeFeatures(e,t){e.writeU16(t.length);for(const r of t)e.writeU8(r.opcode),this.encodeFeature(r,e)}}oO(Om);class FP{static{this.TAP_SCRIPT_VERSION=192}static getContractAddress(e){const t=e.network||fI,r=new zP(e.deployerPubKey,Yx(e.contractSaltPubKey),t).compile(e.bytecode,e.originalSalt,e.challenge,e.priorityFee,e.calldata,e.features),n=rT([Yx(e.deployerPubKey),yI.OP_CHECKSIG]),i=[{output:r,version:FP.TAP_SCRIPT_VERSION},{output:n,version:FP.TAP_SCRIPT_VERSION}];return FP.generateAddressFromScript(e,i)}static verifyControlBlock(e,t){const r=e.network||fI,n=new zP(e.deployerPubKey,Yx(e.contractSaltPubKey),r).compile(e.bytecode,e.originalSalt,e.challenge,e.priorityFee,e.calldata,e.features),i=rT([Yx(e.deployerPubKey),yI.OP_CHECKSIG]),o=[{output:n,version:FP.TAP_SCRIPT_VERSION},{output:i,version:FP.TAP_SCRIPT_VERSION}],s=AO({internalPubkey:Yx(e.deployerPubKey),network:r,scriptTree:o,redeem:{output:n,redeemVersion:FP.TAP_SCRIPT_VERSION}}).witness;return!(!s||0===s.length)&&s[s.length-1].equals(t)}static getContractSeed(e,t,r){const n=nx(t);return nx(nh.concat([e,r,n]))}static generateAddressFromScript(e,t){const r=e.network||fI;return AO({internalPubkey:Yx(e.deployerPubKey),network:r,scriptTree:t}).address}}oO(Om);class VP{static tweakSigner(e,t={}){let r=e.privateKey;if(!r)throw new Error("Private key is required for tweaking signer!");3===e.publicKey[0]&&(r=xm.privateNegate(r));const n=xm.privateAdd(r,vO(Yx(nh.from(e.publicKey)),t.tweakHash));if(!n)throw new Error("Invalid tweaked private key!");return dP.fromPrivateKey(nh.from(n),t.network)}}function qP(e){return"object"==typeof e&&null!==e&&"web3"in e&&"object"==typeof e.web3&&"getMLDSAPublicKey"in e.web3&&"signMLDSAMessage"in e.web3}const WP=new class{sha256(e){return tx(nh.from(e))}async trySignSchnorrWithOPWallet(e){const t=this.getOPWallet();if(!t)return null;const r="string"==typeof e?nh.from(e,"utf-8"):nh.from(e),n=this.sha256(r),i=n.toString("hex"),o=await t.web3.signSchnorr(i);return{signature:nh.from(o,"hex"),message:n}}async trySignMLDSAWithOPWallet(e){const t=this.getOPWallet();if(!t)return null;const r="string"==typeof e?nh.from(e,"utf-8"):nh.from(e),n=this.sha256(r),i=n.toString("hex"),o=await t.web3.signMLDSAMessage(i);return{signature:nh.from(o.signature,"hex"),message:n,publicKey:nh.from(o.publicKey,"hex"),securityLevel:o.securityLevel}}async signMessageAuto(e,t){if(!t){const t=await this.trySignSchnorrWithOPWallet(e);if(t)return t;throw new Error("No keypair provided and OP_WALLET is not available.")}return this.signMessage(t,e)}async tweakAndSignMessageAuto(e,t,r){if(!t){const t=await this.trySignSchnorrWithOPWallet(e);if(t)return t;throw new Error("No keypair provided and OP_WALLET is not available.")}if(!r)throw new Error("Network is required when signing with a local keypair.");return this.tweakAndSignMessage(t,e,r)}async signMLDSAMessageAuto(e,t){if(!t){const t=await this.trySignMLDSAWithOPWallet(e);if(t)return t;throw new Error("No ML-DSA keypair provided and OP_WALLET is not available.")}return this.signMLDSAMessage(t,e)}async verifyMLDSAWithOPWallet(e,t){const r=this.getOPWallet();if(!r)return null;const n="string"==typeof e?nh.from(e,"utf-8"):nh.from(e),i=this.sha256(n),o={signature:nh.from(t.signature).toString("hex"),publicKey:nh.from(t.publicKey).toString("hex"),securityLevel:t.securityLevel,messageHash:i.toString("hex")};return r.web3.verifyMLDSASignature(i.toString("hex"),o)}async getMLDSAPublicKeyFromOPWallet(){const e=this.getOPWallet();if(!e)return null;const t=await e.web3.getMLDSAPublicKey();return nh.from(t,"hex")}tweakAndSignMessage(e,t,r){const n=VP.tweakSigner(e,{network:r});return this.signMessage(n,t)}signMessage(e,t){if("string"==typeof t&&(t=nh.from(t,"utf-8")),!e.privateKey)throw new Error("Private key not found in keypair.");const r=this.sha256(t);return{signature:xm.signSchnorr(r,e.privateKey),message:r}}verifySignature(e,t,r){if("string"==typeof t&&(t=nh.from(t,"utf-8")),64!==r.length)throw new Error("Invalid signature length.");const n=this.sha256(t);return xm.verifySchnorr(n,Yx(nh.from(e)),r)}tweakAndVerifySignature(e,t,r){const n=dP.tweakPublicKey(nh.from(e));return this.verifySignature(n,t,r)}signMLDSAMessage(e,t){if("string"==typeof t&&(t=nh.from(t,"utf-8")),!e.privateKey)throw new Error("ML-DSA private key not found in keypair.");const r=this.sha256(t),n=e.sign(r);return{signature:nh.from(n),message:r,publicKey:nh.from(e.publicKey),securityLevel:e.securityLevel}}verifyMLDSASignature(e,t,r){"string"==typeof t&&(t=nh.from(t,"utf-8"));const n=this.sha256(t);return e.verify(n,r)}isOPWalletAvailable(){return null!==this.getOPWallet()}getOPWallet(){if(typeof window>"u")return null;const e=window;return e.opnet&&qP(e.opnet)?e.opnet:null}};oO(Om);class $P{constructor(e,t,r=fI,n=wv.MLDSASecurityLevel.LEVEL2,i){this.network=r,this._securityLevel=n;const o=e.startsWith("0x")?e.replace("0x",""):e;vP.isValidHex(o)?this._keypair=dP.fromPrivateKey(nh.from(o,"hex"),this.network):this._keypair=dP.fromWIF(o,this.network);const s=t.startsWith("0x")?t.replace("0x",""):t;if(vP.isValidHex(s)){const e=nh.from(s,"hex"),t=wv.getMLDSAConfig(n,this.network),r=t.privateKeySize,o=r+t.publicKeySize;let a;if(e.length===r)a=e;else{if(e.length!==o)throw new Error(`Invalid ML-DSA key length for security level ${n}. Expected ${r} bytes (private only) or ${o} bytes (private+public), got ${e.length} bytes.`);a=e.subarray(0,r)}if(i&&32!==i.length)throw new Error("Chain code must be 32 bytes");this._chainCode=i||nh.alloc(32),this._mldsaKeypair=wv.QuantumBIP32Factory.fromPrivateKey(a,this._chainCode,this.network,n)}else this._mldsaKeypair=wv.QuantumBIP32Factory.fromBase58(s),this._chainCode=nh.from(this._mldsaKeypair.chainCode),this._securityLevel=this._mldsaKeypair.securityLevel;this._bufferPubKey=this._keypair.publicKey,this._address=new xP(this._mldsaKeypair.publicKey,this._keypair.publicKey),this._p2tr=this._address.p2tr(this.network),this._p2wpkh=this._address.p2wpkh(this.network),this._legacy=this._address.p2pkh(this.network),this._segwitLegacy=this._address.p2shp2wpkh(this.network),this._p2wda=this._address.p2wda(this.network),this._tweakedKey=this._address.tweakedPublicKeyToBuffer()}get address(){return this._address}get tweakedPubKeyKey(){return this._tweakedKey}get keypair(){if(!this._keypair)throw new Error("Keypair not set");return this._keypair}get mldsaKeypair(){return this._mldsaKeypair}get securityLevel(){return this._securityLevel}get chainCode(){return this._chainCode}get p2wpkh(){return this._p2wpkh}get p2tr(){return this._p2tr}get p2wda(){return this._p2wda}get legacy(){return this._legacy}get addresses(){return[this.p2wpkh,this.p2tr,this.legacy,this.segwitLegacy]}get segwitLegacy(){return this._segwitLegacy}get publicKey(){if(!this._bufferPubKey)throw new Error("Public key not set");return this._bufferPubKey}get quantumPublicKey(){return nh.from(this._mldsaKeypair.publicKey)}get quantumPrivateKey(){if(!this._mldsaKeypair.privateKey)throw new Error("Quantum private key not set");return nh.from(this._mldsaKeypair.privateKey)}get quantumPublicKeyHex(){return nh.from(this._mldsaKeypair.publicKey).toString("hex")}get quantumPrivateKeyHex(){if(!this._mldsaKeypair.privateKey)throw new Error("Quantum private key not set");return nh.from(this._mldsaKeypair.privateKey).toString("hex")}get xOnly(){if(!this.keypair)throw new Error("Keypair not set");return Yx(this._bufferPubKey)}static fromWif(e,t,r=fI,n=wv.MLDSASecurityLevel.LEVEL2,i){return new $P(e,t,r,n,i)}static generate(e=fI,t=wv.MLDSASecurityLevel.LEVEL2){const r=dP.generateWallet(e,t);if(!r.quantumPrivateKey)throw new Error("Failed to generate quantum keys");return new $P(r.privateKey,r.quantumPrivateKey,e,t)}static fromPrivateKeys(e,t,r=fI,n=wv.MLDSASecurityLevel.LEVEL2,i){return new $P(e,t,r,n,i)}toWIF(){return this._keypair.toWIF()}toPrivateKeyHex(){if(!this._keypair.privateKey)throw new Error("Private key not available");return this._keypair.privateKey.toString("hex")}toPublicKeyHex(){return this._bufferPubKey.toString("hex")}toQuantumBase58(){return this._mldsaKeypair.toBase58()}derivePath(e){const t=this._mldsaKeypair.derivePath(e);if(!this._keypair.privateKey)throw new Error("Cannot derive from a watch-only wallet (no private key available)");const r=dP.BIP32.fromPrivateKey(this._keypair.privateKey,this._chainCode,this.network).derivePath(e);if(!r.privateKey)throw new Error("Failed to derive classical private key");if(!r.chainCode)throw new Error("Failed to derive classical chain code");return new $P(nh.from(r.privateKey).toString("hex"),t.toBase58(),this.network,this._securityLevel,nh.from(r.chainCode))}}var GP=(e=>(e[e.MINIMUM=128]="MINIMUM",e[e.LOW=160]="LOW",e[e.MEDIUM=192]="MEDIUM",e[e.HIGH=224]="HIGH",e[e.MAXIMUM=256]="MAXIMUM",e))(GP||{}),XP=(e=>(e[e.BIP44=44]="BIP44",e[e.BIP49=49]="BIP49",e[e.BIP84=84]="BIP84",e[e.BIP86=86]="BIP86",e))(XP||{});function YP(e,t,r,n,i){return`m/${e}'/${t}'/${r}'/${n}/${i}`}oO(Om);const ZP=wv.BIP32Factory(Om);class QP{constructor(e,t="",r=fI,n=wv.MLDSASecurityLevel.LEVEL2){if(!w_.validateMnemonic(e))throw new Error("Invalid mnemonic phrase");this._phrase=e,this._passphrase=t,this._network=r,this._securityLevel=n,this._seed=w_.mnemonicToSeedSync(this._phrase,this._passphrase),this._classicalRoot=ZP.fromSeed(this._seed,this._network),this._quantumRoot=wv.QuantumBIP32Factory.fromSeed(this._seed,this._network,this._securityLevel)}get phrase(){return this._phrase}get network(){return this._network}get securityLevel(){return this._securityLevel}get seed(){return nh.from(this._seed)}static generatePhrase(e=GP.MAXIMUM){return w_.generateMnemonic(e)}static generate(e=GP.MAXIMUM,t="",r=fI,n=wv.MLDSASecurityLevel.LEVEL2){const i=w_.generateMnemonic(e);return new QP(i,t,r,n)}static validate(e){return w_.validateMnemonic(e)}derive(e=0,t=0,r=!1,n=XP.BIP84){const i=this.buildClassicalPath(t,e,r,n),o=this._classicalRoot.derivePath(i);if(!o.privateKey)throw new Error(`Failed to derive classical private key at index ${e}`);const s=this.buildQuantumPath(t,e,r),a=this._quantumRoot.derivePath(s);if(!a.privateKey)throw new Error(`Failed to derive quantum private key at index ${e}`);return new $P(nh.from(o.privateKey).toString("hex"),nh.from(a.privateKey).toString("hex"),this._network,this._securityLevel,nh.from(this._quantumRoot.chainCode))}deriveOPWallet(e=_P.P2TR,t=0,r=0,n=!1){let i;switch(e){case _P.P2PKH:i=44;break;case _P.P2SH_OR_P2SH_P2WPKH:i=49;break;case _P.P2WPKH:i=84;break;case _P.P2TR:i=86;break;default:throw new Error(`Unsupported address type: ${e}`)}const o=this.getCoinType(),s=n?1:0,a=`m/${i}'/0'/${r}'/${s}/${t}`,u=this._classicalRoot.derivePath(a);if(!u.privateKey)throw new Error(`Failed to derive classical private key at path ${a}`);const c=`m/360'/${o}'/${r}'/${s}/${t}`,f=this._quantumRoot.derivePath(c);if(!f.privateKey)throw new Error(`Failed to derive quantum private key at path ${c}`);return new $P(nh.from(u.privateKey).toString("hex"),nh.from(f.privateKey).toString("hex"),this._network,this._securityLevel,nh.from(this._quantumRoot.chainCode))}deriveMultipleUnisat(e=_P.P2TR,t=5,r=0,n=0,i=!1){const o=[];for(let s=0;s<t;s++)o.push(this.deriveOPWallet(e,r+s,n,i));return o}deriveMultiple(e,t=0,r=0,n=!1,i=XP.BIP84){const o=[];for(let s=0;s<e;s++)o.push(this.derive(t+s,r,n,i));return o}deriveCustomPath(e,t){const r=this._classicalRoot.derivePath(e),n=this._quantumRoot.derivePath(t);if(!r.privateKey)throw new Error(`Failed to derive classical private key at path ${e}`);if(!n.privateKey)throw new Error(`Failed to derive quantum private key at path ${t}`);return new $P(nh.from(r.privateKey).toString("hex"),nh.from(n.privateKey).toString("hex"),this._network,this._securityLevel,nh.from(this._quantumRoot.chainCode))}getClassicalRoot(){return this._classicalRoot}getQuantumRoot(){return this._quantumRoot}buildClassicalPath(e,t,r,n=XP.BIP84){return YP(n,this.getCoinType(),e,r?1:0,t)}buildQuantumPath(e,t,r){return`m/360'/${this.getCoinType()}'/${e}'/${r?1:0}/${t}`}getCoinType(){return this._network.bech32===hI.bech32||this._network.bech32===lI.bech32?1:0}}function JP(e){switch(e){case 1312:return wv.MLDSASecurityLevel.LEVEL2;case 1952:return wv.MLDSASecurityLevel.LEVEL3;case 2592:return wv.MLDSASecurityLevel.LEVEL5;default:throw new Error(`Invalid MLDSA public key length: ${e}`)}}var eU=(e=>(e[e.GENERIC=0]="GENERIC",e[e.FUNDING=1]="FUNDING",e[e.DEPLOYMENT=2]="DEPLOYMENT",e[e.INTERACTION=3]="INTERACTION",e[e.MULTI_SIG=4]="MULTI_SIG",e[e.CUSTOM_CODE=5]="CUSTOM_CODE",e[e.CANCEL=6]="CANCEL",e[e.CONSOLIDATED_SETUP=7]="CONSOLIDATED_SETUP",e[e.CONSOLIDATED_REVEAL=8]="CONSOLIDATED_REVEAL",e))(eU||{}),tU=(e=>(e[e.Roswell=0]="Roswell",e[e.Rachel=1]="Rachel",e[e.Kecksburg=2]="Kecksburg",e[e.Phoenix=3]="Phoenix",e[e.Aurora=4]="Aurora",e[e.Rendlesham=5]="Rendlesham",e[e.Lazar=6]="Lazar",e[e.ShagHarbor=7]="ShagHarbor",e[e.Exeter=8]="Exeter",e[e.Stephenville=9]="Stephenville",e[e.Valensole=10]="Valensole",e[e.Socorro=11]="Socorro",e[e.Pascagoula=12]="Pascagoula",e[e.Tehran=13]="Tehran",e[e.Westall=14]="Westall",e[e.Hopkinsville=15]="Hopkinsville",e[e.Belgium=16]="Belgium",e[e.Breeze=17]="Breeze",e[e.Flatwoods=18]="Flatwoods",e[e.Maury=20]="Maury",e[e.Varginha=21]="Varginha",e[e.Trindade=22]="Trindade",e[e.Levelland=23]="Levelland",e[e.Wanaque=24]="Wanaque",e[e.Coyame=25]="Coyame",e[e.Delphos=26]="Delphos",e))(tU||{});const rU={CONSENSUS:tU.Roswell,CONSENSUS_NAME:"Roswell",ENABLED_AT_BLOCK:0n};tU.Roswell,tU.Roswell;function nU(e){let t=nh.allocUnsafe(0);function r(e){const r=t.length,n=ag(e);t=nh.concat([t,nh.allocUnsafe(n)]),og(e,t,r)}function n(e){r(e.length),function(e){t=nh.concat([t,nh.from(e)])}(e)}return r((i=e).length),i.forEach(n),t;var i}function iU(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&aB(e.witnessUtxo.script))}function oU(e,t){if(e.nonWitnessUtxo&&!e.redeemScript&&!e.witnessScript&&!e.witnessUtxo||e.redeemScript)return!0;const r=function(e){return e.redeemScript?e.redeemScript:e.witnessScript?e.witnessScript:e.witnessUtxo?e.witnessUtxo.script:(e.nonWitnessUtxo,null)}(e);return!!r&&sU(t,r)}function sU(e,t){return-1!==cB(e,t)}class aU extends n_{constructor(e){super(),this.logColor="#00ffe1",this.finalized=!1,this.signed=!1,this.scriptData=null,this.tapData=null,this.inputs=[],this.sequence=4294967293,this.tapLeafScript=null,this.isBrowser=!1,this.csvInputIndices=new Set,this.anchorInputIndices=new Set,this.regenerated=!1,this.ignoreSignatureErrors=!1,this.noSignatures=!1,this.txVersion=2,this._mldsaSigner=null,this._hashedPublicKey=null,this.addressRotationEnabled=!1,this.signerMap=new Map,this.inputSignerMap=new Map,this.tweakedSignerCache=new Map,this.customFinalizerP2SH=(e,t,r,n,i,o)=>{const s=this.inputs[e];if(i&&t.partialSig&&s&&s.redeemScript){return{finalScriptSig:rT([...t.partialSig.map(e=>e.signature)||[],s.redeemScript]),finalScriptWitness:void 0}}if(this.anchorInputIndices.has(e))return{finalScriptSig:void 0,finalScriptWitness:ih.from([0])};if(o&&n&&t.witnessScript){if(!t.partialSig||0===t.partialSig.length)throw new Error(`No signatures for P2WSH input #${e}`);if(EP.isP2WDAWitnessScript(t.witnessScript))return this.finalizeSecondaryP2WDA(e,t);if(this.csvInputIndices.has(e)){return{finalScriptSig:void 0,finalScriptWitness:nU([t.partialSig[0].signature,t.witnessScript])}}}return DB(e,t,r,n,i,o,!0,this.unlockScript)},this.signer=e.signer,this.network=e.network,this.noSignatures=e.noSignatures||!1,this.nonWitnessUtxo=e.nonWitnessUtxo,this.unlockScript=e.unlockScript,this.isBrowser=typeof window<"u",e.txVersion&&(this.txVersion=e.txVersion),e.mldsaSigner&&(this._mldsaSigner=e.mldsaSigner,this._hashedPublicKey=WP.sha256(this._mldsaSigner.publicKey)),e.addressRotation?.enabled&&(this.addressRotationEnabled=!0,this.signerMap=e.addressRotation.signerMap)}get mldsaSigner(){if(!this._mldsaSigner)throw new Error("MLDSA Signer is not set");return this._mldsaSigner}get hashedPublicKey(){if(!this._hashedPublicKey)throw new Error("Hashed public key is not set");return this._hashedPublicKey}static readScriptWitnessToWitnessStack(e){let t=0;function r(){const r=sg(e,t);return t+=r.bytes,r.numberValue||0}function n(){return function(r){const n=ih.from(e.subarray(t,t+r));return t+=r,n}(r())}return function(){const e=r(),t=[];for(let r=0;r<e;r++)t.push(n());return t}()}static preEstimateTaprootTransactionFees(e,t,r,n,i,o,s=32n,a=139n){const u=10n+41n*t+68n*r;return(3n*u+(u+(1n*t+n*i+s*t+a*t+o)))/4n*e}static signInput(e,t,r,n,i){i&&i[0]&&(t.sighashType=i[0]),e.signInput(r,n,i.length?i:void 0)}static calculateSignHash(e){if(!e)throw new Error("Sighash types are required");let t=0;for(const r of e)t|=r;return t||0}isAddressRotationEnabled(){return this.addressRotationEnabled}ignoreSignatureError(){this.ignoreSignatureErrors=!0}getScriptAddress(){if(!this.scriptData||!this.scriptData.address)throw new Error("Tap data is required");return this.scriptData.address}getTransaction(){return this.transaction.extractTransaction(!1)}getTapAddress(){if(!this.tapData||!this.tapData.address)throw new Error("Tap data is required");return this.tapData.address}disableRBF(){if(this.signed)throw new Error("Transaction is already signed");this.sequence=4294967295;for(const e of this.inputs)this.csvInputIndices.has(this.inputs.indexOf(e))||(e.sequence=4294967295)}getTweakerHash(){return this.tapData?.hash}preEstimateTransactionFees(e,t,r,n,i){const o=10n+41n*t+68n*r;return(3n*o+(o+(144n*n+34n*i+(1n+35n*i+1n+n))))/4n*e}getSignerForInput(e){if(this.addressRotationEnabled){const t=this.inputSignerMap.get(e);if(t)return t}return this.signer}registerInputSigner(e,t){if(!this.addressRotationEnabled)return;if(t.signer)return void this.inputSignerMap.set(e,t.signer);const r=t.scriptPubKey?.address;if(r&&this.signerMap.has(r)){const t=this.signerMap.get(r);if(t)return void this.inputSignerMap.set(e,t)}}internalPubKeyToXOnlyForInput(e){const t=this.getSignerForInput(e);return Yx(ih.from(t.publicKey))}getTweakedSignerForInput(e,t=!1){if(!this.addressRotationEnabled)return t?(this.tweakSigner(),this.tweakedSigner):this.getTweakedSigner(t);const r=2*e+(t?1:0);if(this.tweakedSignerCache.has(r))return this.tweakedSignerCache.get(r);const n=this.getSignerForInput(e),i=this.getTweakedSigner(t,n);return this.tweakedSignerCache.set(r,i),i}generateTapData(){return{internalPubkey:this.internalPubKeyToXOnly(),network:this.network,name:lT.P2TR}}generateScriptAddress(){return{internalPubkey:this.internalPubKeyToXOnly(),network:this.network,name:lT.P2TR}}getSignerKey(){return this.signer}async signInput(e,t,r,n,i=!1,o=!1){if(this.anchorInputIndices.has(r))return;const s=n.publicKey;let a=iU(t);i&&(a=!a);let u=!1,c=!1;if(a)try{await this.attemptSignTaproot(e,t,r,n,s),u=!0}catch(f){this.error(`Failed to sign Taproot script path input ${r} (reverse: ${i}): ${f.message}`),c=!0}else if(i||oU(t,s))try{await this.signNonTaprootInput(n,e,r),u=!0}catch(f){this.error(`Failed to sign non-Taproot input ${r}: ${f.stack}`),c=!0}if(!u){if(c&&o)throw new Error(`Failed to sign input ${r} with the provided signer.`);try{await this.signInput(e,t,r,n,!0,c)}catch{throw new Error(`Cannot sign input ${r} with the provided signer.`)}}}splitArray(e,t){if(t<=0)throw new Error("Chunk size must be greater than 0.");const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}async signInputs(e){"multiSignPsbt"in this.signer?await this.signInputsWalletBased(e):await this.signInputsNonWalletBased(e)}async signInputsNonWalletBased(e){const t=e.data.inputs,r=this.splitArray(t,20);if(!this.noSignatures)for(let i=0;i<r.length;i++){const t=r[i],o=[],s=20*i;for(let r=0;r<t.length;r++){const i=s+r,a=t[r];try{const t=this.getSignerForInput(i);o.push(this.signInput(e,a,i,t))}catch(n){this.log(`Failed to sign input ${i}: ${n.stack}`)}}await Promise.all(o)}for(let i=0;i<e.data.inputs.length;i++)e.finalizeInput(i,this.customFinalizerP2SH.bind(this));this.finalized=!0}internalPubKeyToXOnly(){return Yx(ih.from(this.signer.publicKey))}internalInit(){this.scriptData=AO(this.generateScriptAddress()),this.tapData=AO(this.generateTapData())}tweakSigner(){this.tweakedSigner||(this.tweakedSigner=this.getTweakedSigner(!0))}getTweakedSigner(e=!1,t=this.signer){const r={network:this.network};if(e&&(r.tweakHash=this.getTweakerHash()),"privateKey"in t)return VP.tweakSigner(t,r)}generateP2SHRedeemScript(e){return nO({redeem:UO({redeem:{output:e},network:this.network}),network:this.network}).output}generateP2SHRedeemScriptLegacy(e){const t=rx(this.signer.publicKey),r=rT([yI.OP_DUP,yI.OP_HASH160,t,yI.OP_EQUALVERIFY,yI.OP_CHECKSIG]),n=rx(r),i=rT([yI.OP_HASH160,n,yI.OP_EQUAL]),o=nO({redeem:UO({redeem:{output:r},network:this.network}),network:this.network});if(CO(i,this.network)===e&&o.redeem&&o.redeem.output)return{redeemScript:r,outputScript:o.redeem.output}}generateP2SHP2PKHRedeemScript(e,t){const r=this.addressRotationEnabled&&void 0!==t?this.getSignerForInput(t):this.signer,n=nO({redeem:xO({pubkey:ih.isBuffer(r.publicKey)?r.publicKey:ih.from(r.publicKey,"hex"),network:this.network}),network:this.network}),i=n.address;if(!n.redeem?.output)throw new Error("Failed to generate P2SH-P2WPKH redeem script");if(i===e&&n.redeem&&n.redeem.output&&n.output)return{redeemScript:n.redeem.output,outputScript:n.output}}generatePsbtInputExtended(e,t,r=!1){const n=ih.from(e.scriptPubKey.hex,"hex"),i={hash:e.transactionId,index:e.outputIndex,sequence:this.sequence,witnessUtxo:{value:Number(e.value),script:n}};if(nB(n)){if(!e.nonWitnessUtxo)throw new Error("Missing nonWitnessUtxo for P2PKH UTXO");i.nonWitnessUtxo=ih.isBuffer(e.nonWitnessUtxo)?e.nonWitnessUtxo:ih.from(e.nonWitnessUtxo,"hex")}else if(!iB(n)&&!LO(n))if(oB(n))this.processP2WSHInput(e,i,t);else if(sB(n)){let r;if(e.redeemScript)r=ih.isBuffer(e.redeemScript)?e.redeemScript:ih.from(e.redeemScript,"hex");else{if(!e.scriptPubKey.address)throw new Error("Missing redeemScript and no address to regenerate it for P2SH UTXO");const n=this.generateP2SHP2PKHRedeemScript(e.scriptPubKey.address,t);if(!n)throw new Error("Missing redeemScript for P2SH UTXO and unable to regenerate");r=n.redeemScript}i.redeemScript=r;const n=nO({redeem:{output:i.redeemScript}});if(!n.redeem)throw new Error("Failed to extract redeem script from P2SH UTXO");const o=n.redeem.output;if(!o)throw new Error("Failed to extract redeem output from P2SH UTXO");e.nonWitnessUtxo&&(i.nonWitnessUtxo=ih.isBuffer(e.nonWitnessUtxo)?e.nonWitnessUtxo:ih.from(e.nonWitnessUtxo,"hex")),iB(o)?Reflect.deleteProperty(i,"nonWitnessUtxo"):oB(o)?(Reflect.deleteProperty(i,"nonWitnessUtxo"),this.processP2WSHInput(e,i,t)):Reflect.deleteProperty(i,"witnessUtxo")}else if(aB(n)){if(this.sighashTypes){const e=aU.calculateSignHash(this.sighashTypes);e&&(i.sighashType=e)}this.addressRotationEnabled?i.tapInternalKey=this.internalPubKeyToXOnlyForInput(t):(this.tweakSigner(),i.tapInternalKey=this.internalPubKeyToXOnly())}else if((e=>4===e.length&&81===e[0]&&2===e[1]&&78===e[2]&&115===e[3])(n))this.anchorInputIndices.add(t),i.isPayToAnchor=!0;else if(rB(n)||tB(n)){if(!e.nonWitnessUtxo)throw new Error("Missing nonWitnessUtxo for P2PK or P2MS UTXO");i.nonWitnessUtxo=ih.isBuffer(e.nonWitnessUtxo)?e.nonWitnessUtxo:ih.from(e.nonWitnessUtxo,"hex")}else this.error(`Unknown or unsupported script type for output: ${e.scriptPubKey.hex}`);return 0===t&&(this.tapLeafScript&&(i.tapLeafScript=[this.tapLeafScript]),this.nonWitnessUtxo&&(i.nonWitnessUtxo=this.nonWitnessUtxo)),i}processP2WSHInput(e,t,r){if(!e.witnessScript)throw new Error("Missing witnessScript for P2WSH UTXO");t.witnessScript=ih.isBuffer(e.witnessScript)?e.witnessScript:ih.from(e.witnessScript,"hex");const n=nT(t.witnessScript);if(n&&this.isCSVScript(n)){const e=nT(t.witnessScript);if(e&&this.isCSVScript(e)){this.csvInputIndices.add(r);const n=this.extractCSVBlocks(e);t.sequence=this.setCSVSequence(n,this.sequence)}}}secondsToCSVTimeUnits(e){return Math.floor(e/512)}createTimeBasedCSV(e){const t=this.secondsToCSVTimeUnits(e);if(t>65535)throw new Error(`Time units ${t} exceeds maximum of 65,535`);return t|1<<22}isCSVEnabled(e){return!(e&1<<31)}extractCSVValue(e){return 65535&e}finalizeSecondaryP2WDA(e,t){if(!t.partialSig||0===t.partialSig.length)throw new Error(`No signature for P2WDA input #${e}`);if(!t.witnessScript)throw new Error(`No witness script for P2WDA input #${e}`);return{finalScriptSig:void 0,finalScriptWitness:nU(EP.createSimpleP2WDAWitness(t.partialSig[0].signature,t.witnessScript))}}async signInputsWalletBased(e){await this.signer.multiSignPsbt([e]);for(let t=0;t<e.data.inputs.length;t++)e.finalizeInput(t,this.customFinalizerP2SH.bind(this));this.finalized=!0}isCSVScript(e){return e.some(e=>e===yI.OP_CHECKSEQUENCEVERIFY)}setCSVSequence(e,t){if(this.txVersion<2)throw new Error("CSV requires transaction version 2 or higher");if(e>65535)throw new Error(`CSV blocks ${e} exceeds maximum of 65,535`);let r=65535&e;return!!(e&1<<22)&&(r|=1<<22),4294967293===t&&(r|=1<<25),r&=2147483647,r}getCSVType(e){return e&1<<22?1:0}extractCSVBlocks(e){for(let t=0;t<e.length;t++)if(e[t]===yI.OP_CHECKSEQUENCEVERIFY&&t>0){const r=e[t-1];if(ih.isBuffer(r))return uT.decode(r);if("number"==typeof r){if(r===yI.OP_0||r===yI.OP_FALSE)return 0;if(r===yI.OP_1NEGATE)return-1;if(r>=yI.OP_1&&r<=yI.OP_16)return r-yI.OP_1+1;throw new Error(`Unexpected raw number in script: ${r}`)}}return 0}async attemptSignTaproot(e,t,r,n,i){if(this.isTaprootScriptSpend(t,i))await this.signTaprootInput(n,e,r);else{let t;if(n!==this.signer?t=this.getTweakedSigner(!0,n):(this.tweakedSigner||this.tweakSigner(),t=this.tweakedSigner),t)try{await this.signTaprootInput(t,e,r)}catch{if(t=this.getTweakedSigner(!1,this.signer),!t)throw new Error(`Failed to obtain tweaked signer for input ${r}.`);await this.signTaprootInput(t,e,r)}else this.error(`Failed to obtain tweaked signer for input ${r}.`)}}isTaprootScriptSpend(e,t){if(e.tapLeafScript&&e.tapLeafScript.length>0)for(const r of e.tapLeafScript)if(sU(t,r.script))return!0;return!1}async signTaprootInput(e,t,r,n){if("signTaprootInput"in e)try{await e.signTaprootInput(t,r,n)}catch{throw new Error("Failed to sign Taproot input with provided signer.")}else t.signTaprootInput(r,e)}async signNonTaprootInput(e,t,r){"signInput"in e?await e.signInput(t,r):t.signInput(r,e)}}function uU(e,t){return JSON.stringify(e)===JSON.stringify(t)}function cU(e){return Uint8Array.from(nh.from(function(e){if(uU(e,fI))return"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";if(uU(e,hI))return"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";if(uU(e,lI))return"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206";throw new Error("Unsupported network for chain ID retrieval")}(e),"hex"))}const fU=Uint8Array.from(nh.from("e784995a412d773988c4b8e333d7b39dfb3cabf118d0d645411a916ca2407939","hex"));oO(Om);const lU=330n,hU=297n,pU=nh.from("51024e73","hex");class dU extends aU{constructor(e){if(super(e),this.logColor="#785def",this.debugFees=!1,this.overflowFees=0n,this.transactionFee=0n,this.estimatedFees=0n,this.updateInputs=[],this.outputs=[],this.feeOutput=null,this._maximumFeeRate=1e8,this.optionalOutputsAdded=!1,e.estimatedFees&&(this.estimatedFees=e.estimatedFees),this.signer=e.signer,this.network=e.network,this.feeRate=e.feeRate,this.priorityFee=e.priorityFee??0n,this.gasSatFee=e.gasSatFee??0n,this.utxos=e.utxos,this.optionalInputs=e.optionalInputs||[],this.to=e.to||void 0,this.debugFees=e.debugFees||!1,this.LOCK_LEAF_SCRIPT=this.defineLockScript(),e.note&&("string"==typeof e.note?this.note=nh.from(e.note,"utf8"):this.note=e.note),this.anchor=e.anchor??!1,this.isPubKeyDestination=!!this.to&&SP.isValidPublicKey(this.to,this.network),this.optionalOutputs=e.optionalOutputs,this.from=dU.getFrom(e.from,this.signer,this.network),this.totalInputAmount=this.calculateTotalUTXOAmount(),this.calculateTotalVOutAmount()<this.totalInputAmount)throw new Error("Vout value is less than the value to send");this.transaction=new IB({network:this.network,version:this.txVersion})}static{this.MINIMUM_DUST=330n}static getFrom(e,t,r){return e||dP.getTaprootAddress(t,r)}static witnessStackToScriptWitness(e){return nU(e)}addOPReturn(e){const t=rT([yI.OP_RETURN,e]);this.addOutput({value:0,script:t})}addAnchor(){this.addOutput({value:0,script:pU})}async getFundingTransactionParameters(){return this.estimatedFees||(this.estimatedFees=await this.estimateTransactionFees()),{utxos:this.utxos,to:this.getScriptAddress(),signer:this.signer,network:this.network,feeRate:this.feeRate,priorityFee:this.priorityFee??0n,gasSatFee:this.gasSatFee??0n,from:this.from,amount:this.estimatedFees,optionalOutputs:this.optionalOutputs,optionalInputs:this.optionalInputs,mldsaSigner:null}}setDestinationAddress(e){this.to=e}setMaximumFeeRate(e){this._maximumFeeRate=e}async signTransaction(){if(!this.utxos.length)throw new Error("No UTXOs specified");if(this.to&&!this.isPubKeyDestination&&!dP.verifyContractAddress(this.to,this.network))throw new Error("Invalid contract address. The contract address must be a taproot address.");if(this.signed)throw new Error("Transaction is already signed");if(this.signed=!0,await this.buildTransaction(),await this.internalBuildTransaction(this.transaction)){if(this.regenerated)throw new Error("Transaction was regenerated");return this.transaction.extractTransaction(!0,!0)}throw new Error("Could not sign transaction")}async generateTransactionMinimalSignatures(e=!1){if(this.to&&!this.isPubKeyDestination&&!dP.verifyContractAddress(this.to,this.network))throw new Error("Invalid contract address. The contract address must be a taproot address.");if(await this.buildTransaction(),0===this.transaction.data.inputs.length){const t=this.getInputs(),r=this.getOutputs();this.transaction.setMaximumFeeRate(this._maximumFeeRate),this.transaction.addInputs(t,e);for(let e=0;e<this.updateInputs.length;e++)this.transaction.updateInput(e,this.updateInputs[e]);this.transaction.addOutputs(r)}}async signPSBT(){if(await this.signTransaction())return this.transaction;throw new Error("Could not sign transaction")}addInput(e){this.inputs.push(e)}addOutput(e,t=!1){if(0===e.value){const t=e;if(!t.script||0===t.script.length)throw new Error("Output value is 0 and no script provided");if(t.script.length<2)throw new Error("Output script is too short");if(t.script[0]!==yI.OP_RETURN&&!t.script.equals(pU))throw new Error("Output script must start with OP_RETURN or be an ANCHOR when value is 0")}else if(!t&&e.value<dU.MINIMUM_DUST)throw new Error(`Output value is less than the minimum dust ${e.value} < ${dU.MINIMUM_DUST}`);this.outputs.push(e)}getTotalOutputValue(){return this.outputs.reduce((e,t)=>e+BigInt(t.value),0n)}toAddress(){return this.to}address(){return this.tapData?.address}async estimateTransactionFees(){await Promise.resolve();const e=new IB({network:this.network}),t=this.getInputs(),r=this.getOutputs();e.addInputs(t),e.addOutputs(r);const n=nh.alloc(64,0),i=nh.alloc(72,0),o=nh.alloc(33,2),s=(e,t)=>{if(t.isPayToAnchor||this.anchorInputIndices.has(e))return{finalScriptSig:void 0,finalScriptWitness:nh.from([0])};if(t.witnessScript&&EP.isP2WDAWitnessScript(t.witnessScript)){const e=[];for(let t=0;t<10;t++)e.push(nh.alloc(0));const r=nh.alloc(72,0);return{finalScriptWitness:dU.witnessStackToScriptWitness([...e,r,t.witnessScript])}}if(0===e&&this.tapLeafScript){const e=nh.alloc(32,0),t=this.tapLeafScript.script,r=nh.alloc(65,0);return{finalScriptWitness:dU.witnessStackToScriptWitness([e,n,n,t,r])}}if(t.witnessUtxo){const e=t.witnessUtxo.script,r=sP.script.decompile(e);if(r&&5===r.length&&r[0]===yI.OP_DUP&&r[1]===yI.OP_HASH160&&r[3]===yI.OP_EQUALVERIFY&&r[4]===yI.OP_CHECKSIG)return{finalScriptSig:sP.script.compile([i,o]),finalScriptWitness:void 0}}if(t.witnessScript){if(this.csvInputIndices.has(e))return{finalScriptWitness:dU.witnessStackToScriptWitness([i,t.witnessScript])};if(t.redeemScript){const e=[i,t.witnessScript];return{finalScriptSig:t.redeemScript,finalScriptWitness:dU.witnessStackToScriptWitness(e)}}const r=sP.script.decompile(t.witnessScript);if(r&&r.length>=4){const e=r[0],n=r[r.length-1];if("number"==typeof e&&e>=yI.OP_1&&n===yI.OP_CHECKMULTISIG){const r=e-yI.OP_1+1,n=[];for(let e=0;e<r;e++)n.push(i);return{finalScriptWitness:dU.witnessStackToScriptWitness([nh.alloc(0),...n,t.witnessScript])}}}return{finalScriptWitness:dU.witnessStackToScriptWitness([i,t.witnessScript])}}if(t.redeemScript){const e=sP.script.decompile(t.redeemScript);if(e&&2===e.length&&e[0]===yI.OP_0&&nh.isBuffer(e[1])&&20===e[1].length)return{finalScriptSig:t.redeemScript,finalScriptWitness:dU.witnessStackToScriptWitness([i,o])}}if(t.redeemScript&&!t.witnessScript&&!t.witnessUtxo)return{finalScriptSig:sP.script.compile([i,t.redeemScript]),finalScriptWitness:void 0};const r=t.witnessUtxo?.script;return r?t.tapInternalKey?{finalScriptWitness:dU.witnessStackToScriptWitness([n])}:22===r.length&&r[0]===yI.OP_0||22===t.redeemScript?.length&&t.redeemScript[0]===yI.OP_0?{finalScriptWitness:dU.witnessStackToScriptWitness([i,o])}:DB(e,t,r,!0,!!t.redeemScript,!!t.witnessScript):{finalScriptSig:void 0,finalScriptWitness:void 0}};try{for(let r=0;r<e.data.inputs.length;r++){const n=t[r];n&&e.finalizeInput(r,e=>s(e,n))}}catch(f){this.warn(`Could not finalize dummy tx: ${f.message}`)}const a=e.extractTransaction(!0,!0).virtualSize(),u=this.feeRate*a,c=BigInt(Math.ceil(u));return this.debugFees&&this.log(`Estimating fees: feeRate=${this.feeRate}, accurate_vSize=${a}, fee=${c}n`),c}async rebuildFromBase64(e){return this.transaction=IB.fromBase64(e,{network:this.network,version:this.txVersion}),this.signed=!1,this.sighashTypes=[JO.SIGHASH_ANYONECANPAY,JO.SIGHASH_ALL],await this.signPSBT()}setPSBT(e){this.transaction=e}getInputs(){return this.inputs}getOutputs(){const e=[...this.outputs];return this.feeOutput&&e.push(this.feeOutput),e}getOptionalOutputValue(){if(!this.optionalOutputs)return 0n;let e=0n;for(let t=0;t<this.optionalOutputs.length;t++)e+=BigInt(this.optionalOutputs[t].value);return e}async addRefundOutput(e,t=!1){this.note&&this.addOPReturn(this.note),this.anchor&&this.addAnchor();let r=-1n,n=0n,i=0;let o=0n;for(;i<5&&n!==r;){r=n,n=await this.estimateTransactionFees();const t=e+n;if(o=this.totalInputAmount-t,this.debugFees&&this.log(`Iteration ${i+1}: inputAmount=${this.totalInputAmount}, totalSpent=${t}, sendBackAmount=${o}`),o>=dU.MINIMUM_DUST){if(SP.isValidP2TRAddress(this.from,this.network))this.feeOutput={value:Number(o),address:this.from,tapInternalKey:this.internalPubKeyToXOnly()};else if(SP.isValidPublicKey(this.from,this.network)){const e=rT([nh.from(this.from.replace("0x",""),"hex"),yI.OP_CHECKSIG]);this.feeOutput={value:Number(o),script:e}}else this.feeOutput={value:Number(o),address:this.from};this.overflowFees=o}else{if(this.feeOutput=null,this.overflowFees=0n,o<0n&&5===i)throw new Error(`Insufficient funds: need ${t} sats but only have ${this.totalInputAmount} sats`);this.debugFees&&this.warn(`Amount to send back (${o} sat) is less than minimum dust...`)}i++}if(t&&o<0n)throw new Error(`Insufficient funds: need at least ${-o} more sats to cover fees.`);i>=5&&this.warn("Fee calculation did not stabilize after 5 iterations"),this.transactionFee=n,this.debugFees&&this.log(`Final fee: ${n} sats, Change output: ${this.feeOutput?`${this.feeOutput.value} sats`:"none"}`)}defineLockScript(){return rT([Yx(nh.from(this.signer.publicKey)),yI.OP_CHECKSIG])}addValueToToOutput(e){if(e<dU.MINIMUM_DUST)throw new Error(`Value to send is less than the minimum dust ${e} < ${dU.MINIMUM_DUST}`);for(const t of this.outputs)if("address"in t&&t.address===this.to)return void(t.value+=Number(e));throw new Error("Output not found")}generateLegacySignature(){if(this.tweakSigner(),!this.tweakedSigner)throw new Error("Tweaked signer is not defined");const e=Yx(this.tweakedSigner.publicKey),t=this.signer.publicKey;if(33!==t.length)throw new Error("Original public key must be compressed (33 bytes)");const r=cU(this.network),n=new LP;n.writeU8(wv.MLDSASecurityLevel.LEVEL2),n.writeBytes(this.hashedPublicKey),n.writeBytes(e),n.writeBytes(t),n.writeBytes(fU),n.writeBytes(r);const i=n.getBuffer(),o=WP.signMessage(this.tweakedSigner,i);if(!WP.verifySignature(e,i,o.signature))throw new Error("Could not verify generated legacy signature for MLDSA link request");return nh.from(o.signature)}generateMLDSASignature(){if(!this.mldsaSigner)throw new Error("MLDSA signer is not defined");if(this.tweakSigner(),!this.tweakedSigner)throw new Error("Tweaked signer is not defined");const e=Yx(this.tweakedSigner.publicKey),t=this.signer.publicKey;if(33!==t.length)throw new Error("Original public key must be compressed (33 bytes)");const r=cU(this.network),n=JP(this.mldsaSigner.publicKey.length);if(n!==wv.MLDSASecurityLevel.LEVEL2)throw new Error("Only MLDSA level 2 is supported for link requests");const i=new LP;i.writeU8(n),i.writeBytes(this.hashedPublicKey),i.writeBytes(this.mldsaSigner.publicKey),i.writeBytes(e),i.writeBytes(t),i.writeBytes(fU),i.writeBytes(r);const o=i.getBuffer(),s=WP.signMLDSAMessage(this.mldsaSigner,o);if(!WP.verifyMLDSASignature(this.mldsaSigner,o,s.signature))throw new Error("Could not verify generated MLDSA signature for link request");return nh.from(s.signature)}generateMLDSALinkRequest(e,t){const r=this.mldsaSigner,n=this.generateLegacySignature();let i=null;e.revealMLDSAPublicKey&&(i=this.generateMLDSASignature());const o={priority:RP.MLDSA_LINK_PUBKEY,opcode:NP.MLDSA_LINK_PUBKEY,data:{verifyRequest:!!e.revealMLDSAPublicKey,publicKey:r.publicKey,hashedPublicKey:this.hashedPublicKey,level:JP(r.publicKey.length),legacySignature:n,mldsaSignature:i}};t.push(o)}getTransactionOPNetFee(){const e=this.priorityFee+this.gasSatFee;return e>dU.MINIMUM_DUST?e:dU.MINIMUM_DUST}calculateTotalUTXOAmount(){let e=0n;for(const t of this.utxos)e+=t.value;for(const t of this.optionalInputs)e+=t.value;return e}calculateTotalVOutAmount(){let e=0n;for(const t of this.utxos)e+=t.value;for(const t of this.optionalInputs)e+=t.value;return e}addOptionalOutputsAndGetAmount(){if(!this.optionalOutputs||this.optionalOutputsAdded)return 0n;let e=0n;for(let t=0;t<this.optionalOutputs.length;t++)this.addOutput(this.optionalOutputs[t]),e+=BigInt(this.optionalOutputs[t].value);return this.optionalOutputsAdded=!0,e}addInputsFromUTXO(){if(this.utxos.length){if(this.totalInputAmount<dU.MINIMUM_DUST)throw new Error(`Total input amount is ${this.totalInputAmount} sat which is less than the minimum dust ${dU.MINIMUM_DUST} sat.`);for(let e=0;e<this.utxos.length;e++){const t=this.utxos[e];this.registerInputSigner(e,t);const r=this.generatePsbtInputExtended(t,e);this.addInput(r)}}if(this.optionalInputs)for(let e=this.utxos.length;e<this.optionalInputs.length+this.utxos.length;e++){const t=this.optionalInputs[e-this.utxos.length];this.registerInputSigner(e,t);const r=this.generatePsbtInputExtended(t,e,!0);this.addInput(r)}}internalInit(){this.verifyUTXOValidity(),super.internalInit()}updateInput(e){this.updateInputs.push(e)}addFeeToOutput(e,t,r,n){if(n){let n;n=e>627n?hU:e,this.addOutput({value:Number(n),address:t},!0),n===hU&&e-hU>lU&&this.addOutput({value:Number(e-n),address:r.address},!0)}else{const t=e<lU?lU:e;this.addOutput({value:Number(t),address:r.address},!0)}}getWitness(){if(!this.tapData||!this.tapData.witness)throw new Error("Witness is required");if(0===this.tapData.witness.length)throw new Error("Witness is empty");return this.tapData.witness[this.tapData.witness.length-1]}getTapOutput(){if(!this.tapData||!this.tapData.output)throw new Error("Tap data is required");return this.tapData.output}verifyUTXOValidity(){for(const e of this.utxos)if(!e.scriptPubKey)throw new Error("Address is required");for(const e of this.optionalInputs)if(!e.scriptPubKey)throw new Error("Address is required")}async setFeeOutput(e){const t=e.value;this.feeOutput=null;let r=0n,n=-1n;this.log(`setFeeOutput: Starting fee calculation for change. Initial available value: ${t} sats.`);for(let o=0;o<3&&r!==n;o++){n=r,r=await this.estimateTransactionFees();const i=BigInt(t)-r;this.debugFees&&this.log(` -> Iteration ${o+1}: Estimated fee is ${r} sats. Value left for change: ${i} sats.`),i>=dU.MINIMUM_DUST?(this.feeOutput={...e,value:Number(i)},this.overflowFees=i):(this.feeOutput=null,this.overflowFees=0n,r=await this.estimateTransactionFees(),this.debugFees&&this.log(` -> Change is less than dust. Final fee without change output: ${r} sats.`))}const i=BigInt(t)-r;if(i<0)throw new Error(`setFeeOutput: Insufficient funds to pay the fees. Required fee: ${r}, Available: ${t}. Total input: ${this.totalInputAmount} sat`);i>=dU.MINIMUM_DUST?(this.feeOutput={...e,value:Number(i)},this.overflowFees=i,this.debugFees&&this.log(`setFeeOutput: Final change output set to ${i} sats. Final fee: ${r} sats.`)):(this.warn(`Amount to send back (${i} sat) is less than the minimum dust (${dU.MINIMUM_DUST} sat), it will be consumed in fees instead.`),this.feeOutput=null,this.overflowFees=0n)}async internalBuildTransaction(e,t=!1){if(0===e.data.inputs.length){const r=this.getInputs(),n=this.getOutputs();e.setMaximumFeeRate(this._maximumFeeRate),e.addInputs(r,t);for(let t=0;t<this.updateInputs.length;t++)e.updateInput(t,this.updateInputs[t]);e.addOutputs(n)}try{return await this.signInputs(e),this.finalized&&(this.transactionFee=BigInt(e.getFee())),!0}catch(LU){const t=LU;this.error(`[internalBuildTransaction] Something went wrong while getting building the transaction: ${t.stack}`)}return!1}}class yU extends dU{constructor(e){if(super(e),this.targetScriptRedeem=null,this.leftOverFundsScriptRedeem=null,this.customFinalizer=(e,t)=>{if(!this.tapLeafScript)throw new Error("Tap leaf script is required");if(!this.contractSecret)throw new Error("Contract secret is required");const r=this.getScriptSolution(t).concat(this.tapLeafScript.script).concat(this.tapLeafScript.controlBlock);return{finalScriptWitness:dU.witnessStackToScriptWitness(r)}},!e.calldata)throw new Error("Calldata is required");if(!e.challenge)throw new Error("Challenge solution is required");this.challenge=e.challenge,this.LOCK_LEAF_SCRIPT=this.defineLockScript(),this.disableAutoRefund=e.disableAutoRefund||!1,this.epochChallenge=TP.generateTimeLockAddress(this.challenge.publicKey.originalPublicKeyBuffer(),this.network),this.calldata=uP.compress(e.calldata),this.randomBytes=e.randomBytes||vP.rndBytes(),this.scriptSigner=this.generateKeyPairFromSeed(),this.calldataGenerator=new HP(nh.from(this.signer.publicKey),this.scriptSignerXOnlyPubKey(),this.network)}static{this.MAXIMUM_CALLDATA_SIZE=1048576}exportCompiledTargetScript(){return this.compiledTargetScript}getContractSecret(){return this.contractSecret}getRndBytes(){return this.randomBytes}getChallenge(){return this.challenge}scriptSignerXOnlyPubKey(){return Yx(nh.from(this.scriptSigner.publicKey))}generateKeyPairFromSeed(){return dP.fromSeedKeyPair(this.randomBytes,this.network)}async buildTransaction(){const e=this.scriptSigner?this.targetScriptRedeem:this.leftOverFundsScriptRedeem;if(!e)throw new Error("Left over funds script redeem is required");if(!e.redeemVersion)throw new Error("Left over funds script redeem version is required");if(!e.output)throw new Error("Left over funds script redeem output is required");this.tapLeafScript={leafVersion:e.redeemVersion,script:e.output,controlBlock:this.getWitness()},this.regenerated||this.addInputsFromUTXO(),await this.createMineableRewardOutputs()}async signInputs(e){this.scriptSigner?"multiSignPsbt"in this.signer?await this.signInputsWalletBased(e):await this.signInputsNonWalletBased(e):await super.signInputs(e)}generateScriptAddress(){return{internalPubkey:this.internalPubKeyToXOnly(),network:this.network,scriptTree:this.scriptTree,name:lT.P2TR}}generateTapData(){const e=this.scriptSigner?this.targetScriptRedeem:this.leftOverFundsScriptRedeem;if(!e)throw new Error("Left over funds script redeem is required");if(!this.scriptTree)throw new Error("Script tree is required");return{internalPubkey:this.internalPubKeyToXOnly(),network:this.network,scriptTree:this.scriptTree,redeem:e,name:lT.P2TR}}getScriptSolution(e){if(!e.tapScriptSig)throw new Error("Tap script signature is required");return[this.contractSecret,e.tapScriptSig[0].signature,e.tapScriptSig[1].signature]}getScriptTree(){if(!this.calldata)throw new Error("Calldata is required");return this.generateRedeemScripts(),[{output:this.compiledTargetScript,version:192},{output:this.LOCK_LEAF_SCRIPT,version:192}]}async signInputsWalletBased(e){const t=this.signer;await this.signInput(e,e.data.inputs[0],0,this.scriptSigner),await t.multiSignPsbt([e]);for(let r=0;r<e.data.inputs.length;r++)if(0===r)e.finalizeInput(r,this.customFinalizer.bind(this));else try{e.finalizeInput(r,this.customFinalizerP2SH.bind(this))}catch{e.finalizeInput(r)}}async signInputsNonWalletBased(e){for(let t=0;t<e.data.inputs.length;t++)if(0===t)await this.signInput(e,e.data.inputs[t],t,this.scriptSigner),await this.signInput(e,e.data.inputs[t],t,this.getSignerKey()),e.finalizeInput(0,this.customFinalizer.bind(this));else{await this.signInput(e,e.data.inputs[t],t,this.signer);try{e.finalizeInput(t,this.customFinalizerP2SH.bind(this))}catch{e.finalizeInput(t)}}}async createMineableRewardOutputs(){if(!this.to)throw new Error("To address is required");const e=this.getTransactionOPNetFee();this.addFeeToOutput(e,this.to,this.epochChallenge,!1);const t=e<lU?lU:e,r=this.addOptionalOutputsAndGetAmount();this.disableAutoRefund||await this.addRefundOutput(t+r)}getPubKeys(){const e=[nh.from(this.signer.publicKey)];return this.scriptSigner&&e.push(nh.from(this.scriptSigner.publicKey)),e}generateRedeemScripts(){this.targetScriptRedeem={name:lT.P2TR,output:this.compiledTargetScript,redeemVersion:192},this.leftOverFundsScriptRedeem={name:lT.P2TR,output:this.LOCK_LEAF_SCRIPT,redeemVersion:192}}}class gU extends dU{constructor(e){if(super(e),this.type=eU.DEPLOYMENT,this.tapLeafScript=null,this.deploymentVersion=0,this.targetScriptRedeem=null,this.leftOverFundsScriptRedeem=null,this.customFinalizer=(e,t)=>{if(!this.tapLeafScript)throw new Error("Tap leaf script is required");if(!t.tapScriptSig)throw new Error("Tap script signature is required");const r=[this.randomBytes,t.tapScriptSig[0].signature,t.tapScriptSig[1].signature].concat(this.tapLeafScript.script).concat(this.tapLeafScript.controlBlock);return{finalScriptWitness:dU.witnessStackToScriptWitness(r)}},!this.hashedPublicKey)throw new Error("MLDSA signer must be defined to deploy a contract.");if(this.bytecode=uP.compress(nh.concat([KP,e.bytecode])),this.verifyBytecode(),e.calldata&&(this.calldata=e.calldata,this.verifyCalldata()),!e.challenge)throw new Error("Challenge solution is required");if(this.randomBytes=e.randomBytes||vP.rndBytes(),this.challenge=e.challenge,this.LOCK_LEAF_SCRIPT=this.defineLockScript(),this.epochChallenge=TP.generateTimeLockAddress(this.challenge.publicKey.originalPublicKeyBuffer(),this.network),this.contractSeed=this.getContractSeed(),this.contractSigner=dP.fromSeedKeyPair(this.contractSeed,this.network),this.deploymentGenerator=new zP(nh.from(this.signer.publicKey),this.contractSignerXOnlyPubKey(),this.network),e.compiledTargetScript)if(nh.isBuffer(e.compiledTargetScript))this.compiledTargetScript=e.compiledTargetScript;else{if("string"!=typeof e.compiledTargetScript)throw new Error("Invalid compiled target script format.");this.compiledTargetScript=nh.from(e.compiledTargetScript,"hex")}else this.compiledTargetScript=this.deploymentGenerator.compile(this.bytecode,this.randomBytes,this.challenge,this.priorityFee,this.calldata,this.generateFeatures(e));this.scriptTree=this.getScriptTree(),this.internalInit(),this._contractPubKey="0x"+this.contractSeed.toString("hex"),this._contractAddress=new xP(this.contractSeed)}static{this.MAXIMUM_CONTRACT_SIZE=131072}get contractPubKey(){return this._contractPubKey}get contractAddress(){return this._contractAddress}get p2trAddress(){return this.to||this.getScriptAddress()}exportCompiledTargetScript(){return this.compiledTargetScript}getRndBytes(){return this.randomBytes}getChallenge(){return this.challenge}getContractAddress(){return this._computedAddress||(this._computedAddress=dP.p2op(this.contractSeed,this.network,this.deploymentVersion)),this._computedAddress}contractSignerXOnlyPubKey(){return Yx(nh.from(this.contractSigner.publicKey))}async buildTransaction(){this.to||(this.to=this.getScriptAddress());const e=this.contractSigner?this.targetScriptRedeem:this.leftOverFundsScriptRedeem;if(!e)throw new Error("Left over funds script redeem is required");if(!e.redeemVersion)throw new Error("Left over funds script redeem version is required");if(!e.output)throw new Error("Left over funds script redeem output is required");this.tapLeafScript={leafVersion:e.redeemVersion,script:e.output,controlBlock:this.getWitness()},this.addInputsFromUTXO();const t=this.getTransactionOPNetFee();this.addFeeToOutput(t,this.getContractAddress(),this.epochChallenge,!0),await this.addRefundOutput(t+this.addOptionalOutputsAndGetAmount())}async signInputsWalletBased(e){const t=this.signer;await this.signInput(e,e.data.inputs[0],0,this.contractSigner),await t.multiSignPsbt([e]);for(let r=0;r<e.data.inputs.length;r++)if(0===r)e.finalizeInput(r,this.customFinalizer.bind(this));else try{e.finalizeInput(r,this.customFinalizerP2SH.bind(this))}catch{e.finalizeInput(r)}}async signInputs(e){if(this.contractSigner)if("multiSignPsbt"in this.signer)await this.signInputsWalletBased(e);else for(let t=0;t<e.data.inputs.length;t++)if(0===t)e.signInput(0,this.contractSigner),e.signInput(0,this.getSignerKey()),e.finalizeInput(0,this.customFinalizer.bind(this));else{e.signInput(t,this.getSignerKey());try{e.finalizeInput(t,this.customFinalizerP2SH.bind(this))}catch{e.finalizeInput(t)}}else await super.signInputs(e)}generateScriptAddress(){return{name:lT.P2TR,internalPubkey:this.internalPubKeyToXOnly(),network:this.network,scriptTree:this.scriptTree}}generateTapData(){const e=this.contractSigner?this.targetScriptRedeem:this.leftOverFundsScriptRedeem;if(!e)throw new Error("Left over funds script redeem is required");if(!this.scriptTree)throw new Error("Script tree is required");return{name:lT.P2TR,internalPubkey:this.internalPubKeyToXOnly(),network:this.network,scriptTree:this.scriptTree,redeem:e}}generateFeatures(e){const t=[],r=e.challenge.getSubmission();if(r&&t.push({priority:RP.MLDSA_LINK_PUBKEY,opcode:NP.EPOCH_SUBMISSION,data:r}),e.revealMLDSAPublicKey&&!e.linkMLDSAPublicKeyToAddress)throw new Error("To reveal the MLDSA public key, you must set linkMLDSAPublicKeyToAddress to true.");return e.linkMLDSAPublicKeyToAddress&&this.generateMLDSALinkRequest(e,t),t}verifyCalldata(){if(this.calldata&&this.calldata.length>yU.MAXIMUM_CALLDATA_SIZE)throw new Error("Calldata size overflow.")}verifyBytecode(){if(!this.bytecode)throw new Error("Bytecode is required");if(this.bytecode.length>gU.MAXIMUM_CONTRACT_SIZE)throw new Error("Contract size overflow.")}getContractSeed(){if(!this.bytecode)throw new Error("Bytecode is required");const e=this.internalPubKeyToXOnly(),t=nx(this.randomBytes),r=nx(this.bytecode);return nx(nh.concat([e,t,r]))}getPubKeys(){const e=[nh.from(this.signer.publicKey)];return this.contractSigner&&e.push(nh.from(this.contractSigner.publicKey)),e}generateRedeemScripts(){this.targetScriptRedeem={name:lT.P2TR,output:this.compiledTargetScript,redeemVersion:192},this.leftOverFundsScriptRedeem={name:lT.P2TR,output:this.getLeafScript(),redeemVersion:192}}getLeafScript(){return this.LOCK_LEAF_SCRIPT}getScriptTree(){if(!this.bytecode)throw new Error("Contract bytecode is required");return this.generateRedeemScripts(),[{output:this.compiledTargetScript,version:192},{output:this.getLeafScript(),version:192}]}}class mU extends dU{constructor(e){if(super(e),this.type=eU.INTERACTION,this.p2wdaInputIndices=new Set,this.compiledOperationData=null,!e.to)throw new Error("Contract address (to) is required");if(!e.contract)throw new Error("Contract secret is required");if(!e.calldata)throw new Error("Calldata is required");if(!e.challenge)throw new Error("Challenge solution is required");if(this.disableAutoRefund=e.disableAutoRefund||!1,this.contractAddress=e.to,this.contractSecret=ih.from(e.contract.replace("0x",""),"hex"),this.calldata=uP.compress(e.calldata),this.challenge=e.challenge,this.randomBytes=e.randomBytes||vP.rndBytes(),this.scriptSigner=this.generateKeyPairFromSeed(),this.p2wdaGenerator=new jP(ih.from(this.signer.publicKey),this.scriptSignerXOnlyPubKey(),this.network),32!==this.contractSecret.length)throw new Error("Invalid contract secret length. Expected 32 bytes.");if(this.epochChallenge=TP.generateTimeLockAddress(this.challenge.publicKey.originalPublicKeyBuffer(),this.network),this.validateP2WDAInputs(),e.compiledTargetScript)if(ih.isBuffer(e.compiledTargetScript))this.compiledOperationData=e.compiledTargetScript;else{if("string"!=typeof e.compiledTargetScript)throw new Error("Invalid compiled target script format.");this.compiledOperationData=ih.from(e.compiledTargetScript,"hex")}else this.compiledOperationData=this.p2wdaGenerator.compile(this.calldata,this.contractSecret,this.challenge,this.priorityFee,this.generateFeatures(e));this.validateOperationDataSize(),this.internalInit()}static{this.MAX_WITNESS_FIELDS=10}static{this.MAX_BYTES_PER_WITNESS=80}getRndBytes(){return this.randomBytes}getChallenge(){return this.challenge}getContractSecret(){return this.contractSecret}async buildTransaction(){this.regenerated||this.addInputsFromUTXO(),await this.createMineableRewardOutputs()}async createMineableRewardOutputs(){if(!this.to)throw new Error("To address is required");const e=this.getTransactionOPNetFee();this.addFeeToOutput(e,this.to,this.epochChallenge,!1);const t=this.addOptionalOutputsAndGetAmount();this.disableAutoRefund||await this.addRefundOutput(e+t)}async signInputs(e){for(let t=0;t<e.data.inputs.length;t++)await this.signInput(e,e.data.inputs[t],t,this.signer);for(let t=0;t<e.data.inputs.length;t++)this.p2wdaInputIndices.has(t)?0===t?e.finalizeInput(t,this.finalizePrimaryP2WDA.bind(this)):e.finalizeInput(t,this.finalizeSecondaryP2WDA.bind(this)):e.finalizeInput(t,this.customFinalizerP2SH.bind(this));this.finalized=!0}generateFeatures(e){const t=[];e.loadedStorage&&t.push({priority:RP.ACCESS_LIST,opcode:NP.ACCESS_LIST,data:e.loadedStorage});const r=e.challenge.getSubmission();return r&&t.push({priority:RP.EPOCH_SUBMISSION,opcode:NP.EPOCH_SUBMISSION,data:r}),t}generateKeyPairFromSeed(){return dP.fromSeedKeyPair(this.randomBytes,this.network)}scriptSignerXOnlyPubKey(){return Yx(ih.from(this.scriptSigner.publicKey))}validateP2WDAInputs(){if(0===this.utxos.length||!EP.isP2WDAUTXO(this.utxos[0]))throw new Error("Input 0 must be a P2WDA UTXO");for(let e=0;e<this.utxos.length;e++)EP.isP2WDAUTXO(this.utxos[e])&&this.p2wdaInputIndices.add(e);for(let e=0;e<this.optionalInputs.length;e++){const t=this.utxos.length+e;EP.isP2WDAUTXO(this.optionalInputs[e])&&this.p2wdaInputIndices.add(t)}}validateOperationDataSize(){if(!this.compiledOperationData)throw new Error("Operation data not compiled");const e=this.compiledOperationData.length;if(!jP.validateWitnessSize(e)){const t=e+64,r=Math.ceil(.7*t),n=Math.ceil(r/mU.MAX_BYTES_PER_WITNESS);throw new Error(`Please dont use P2WDA for this operation. Data too large. Raw size: ${e} bytes, estimated compressed: ${r} bytes, needs ${n} witness fields, max is ${mU.MAX_WITNESS_FIELDS}`)}}finalizePrimaryP2WDA(e,t){if(!t.partialSig||0===t.partialSig.length)throw new Error(`No signature for P2WDA input #${e}`);if(!t.witnessScript)throw new Error(`No witness script for P2WDA input #${e}`);if(!this.compiledOperationData)throw new Error("Operation data not compiled");const r=t.partialSig[0].signature,n=ih.concat([r,this.compiledOperationData]),i=WP.signMessage(this.signer,n),o=ih.from(i.signature),s=ih.concat([o,this.compiledOperationData]),a=uP.compress(s),u=this.splitIntoWitnessChunks(a);if(u.length>mU.MAX_WITNESS_FIELDS)throw new Error(`Compressed data needs ${u.length} witness fields, max is ${mU.MAX_WITNESS_FIELDS}`);const c=[r];for(let f=0;f<mU.MAX_WITNESS_FIELDS;f++)c.push(f<u.length?u[f]:ih.alloc(0));return c.push(t.witnessScript),{finalScriptSig:void 0,finalScriptWitness:dU.witnessStackToScriptWitness(c)}}splitIntoWitnessChunks(e){const t=[];let r=0;for(;r<e.length;){const n=Math.min(mU.MAX_BYTES_PER_WITNESS,e.length-r);t.push(ih.from(e.subarray(r,r+n))),r+=n}return t}}class bU extends dU{constructor(e){if(!e.refundVault)throw new Error("Refund vault is required");if(!e.requestedAmount)throw new Error("Requested amount is required");if(!e.receiver)throw new Error("Receiver is required");if(super({...e,signer:dP.fromPrivateKey(tx(nh.from("aaaaaaaa","utf-8"))),priorityFee:0n,gasSatFee:0n}),this.type=eU.MULTI_SIG,this.targetScriptRedeem=null,this.leftOverFundsScriptRedeem=null,this.originalInputCount=0,this.sighashTypes=bU.signHashTypesArray,this.customFinalizer=(e,t)=>{if(!this.tapLeafScript)throw new Error("Tap leaf script is required");const r=this.getScriptSolution(t).concat(this.tapLeafScript.script).concat(this.tapLeafScript.controlBlock);return{finalScriptWitness:dU.witnessStackToScriptWitness(r)}},!e.pubkeys)throw new Error("Pubkeys are required");e.psbt&&(this.log("Using provided PSBT."),this.transaction=e.psbt,this.originalInputCount=this.transaction.data.inputs.length),this.refundVault=e.refundVault,this.requestedAmount=e.requestedAmount,this.receiver=e.receiver,this.publicKeys=e.pubkeys,this.minimumSignatures=e.minimumSignatures,this.compiledTargetScript=DP.compile(e.pubkeys,this.minimumSignatures),this.scriptTree=this.getScriptTree(),this.internalInit()}static{this.LOCK_LEAF_SCRIPT=rT([yI.OP_XOR,yI.OP_NOP,yI.OP_CODESEPARATOR])}static{this.signHashTypesArray=[]}static{this.numsPoint=nh.from("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex")}static fromBase64(e){const t=IB.fromBase64(e.psbt,{network:e.network});return new bU({...e,psbt:t})}static verifyIfSigned(e,t){let r=!1;for(let n=1;n<e.data.inputs.length;n++){const i=e.data.inputs[n];if(!i.finalScriptWitness)continue;const o=dU.readScriptWitnessToWitnessStack(i.finalScriptWitness);if(!(o.length<3))for(let e=0;e<o.length-2;e+=3)if(o[e+2].equals(t)){r=!0;break}}return r}static signPartial(e,t,r,n){let i=!1,o=!0;for(let a=r;a<e.data.inputs.length;a++){const u=e.data.inputs[a];u.tapInternalKey||(u.tapInternalKey=Yx(bU.numsPoint));const c=[];if(u.finalScriptWitness){const e=dU.readScriptWitnessToWitnessStack(u.finalScriptWitness);u.tapLeafScript=[{leafVersion:192,script:e[e.length-2],controlBlock:e[e.length-1]}];for(let t=0;t<e.length-2;t+=3)c.push({signature:e[t],leafHash:e[t+1],pubkey:e[t+2]});u.tapScriptSig=(u.tapScriptSig||[]).concat(c)}Reflect.deleteProperty(u,"finalScriptWitness");const f=bU.signHashTypesArray?[bU.calculateSignHash(bU.signHashTypesArray)]:[];try{bU.signInput(e,u,a,t,f),i=!0}catch(s){console.log(s)}if(i){if(!u.tapScriptSig)throw new Error("No new signatures for input");u.tapScriptSig.length!==n[a-r]&&(o=!1)}}return{signed:i,final:!!i&&o}}static{this.partialFinalizer=(e,t,r,n,i)=>{if(!t.tapLeafScript||!t.tapLeafScript[0].script||!t.tapLeafScript[0].controlBlock)throw new Error("Tap leaf script is required");if(!t.tapScriptSig)throw new Error(`No new signatures for input ${e}.`);let o=[];if(i){for(const e of n){let r=!1;for(const n of t.tapScriptSig)n.pubkey.equals(Yx(e))&&(o.push(n.signature),r=!0);r||o.push(nh.alloc(0))}o=o.reverse()}else o=t.tapScriptSig.map(e=>[e.signature,e.leafHash,e.pubkey]).flat();r.length>0&&(o=o.concat(r));const s=o.concat(t.tapLeafScript[0].script).concat(t.tapLeafScript[0].controlBlock);return{finalScriptWitness:dU.witnessStackToScriptWitness(s)}}}static dedupeSignatures(e,t){const r=new Map;for(const n of e)r.set(n.pubkey.toString("hex"),n);for(const n of t)r.has(n.pubkey.toString("hex"))||r.set(n.pubkey.toString("hex"),n);return Array.from(r.values())}static attemptFinalizeInputs(e,t,r,n){let i=0;for(let o=t;o<e.data.inputs.length;o++)try{const s=e.data.inputs[o];s.tapInternalKey||(s.tapInternalKey=Yx(bU.numsPoint));const a=[];if(s.finalScriptWitness){const e=dU.readScriptWitnessToWitnessStack(s.finalScriptWitness);for(let t=0;t<e.length-2;t+=3)a.push({signature:e[t],leafHash:e[t+1],pubkey:e[t+2]});s.tapLeafScript=[{leafVersion:192,script:e[e.length-2],controlBlock:e[e.length-1]}],s.tapScriptSig=bU.dedupeSignatures(s.tapScriptSig||[],a)}Reflect.deleteProperty(s,"finalScriptWitness"),e.finalizeInput(o,(e,i)=>bU.partialFinalizer(e,i,[],r[o-t],n)),i++}catch{}return i===e.data.inputs.length-t}finalizeTransactionInputs(){let e=!1;try{for(let e=this.originalInputCount;e<this.transaction.data.inputs.length;e++)this.transaction.finalizeInput(e,this.customFinalizer.bind(this));e=!0}catch(e_){this.error(`Error finalizing transaction inputs: ${e_.stack}`)}return e}async signPSBT(){if(await this.signTransaction())return this.transaction;throw new Error("Could not sign transaction")}async buildTransaction(){const e=this.targetScriptRedeem;if(!e)throw new Error("Left over funds script redeem is required");if(!e.redeemVersion)throw new Error("Left over funds script redeem version is required");if(!e.output)throw new Error("Left over funds script redeem output is required");this.tapLeafScript={leafVersion:e.redeemVersion,script:e.output,controlBlock:this.getWitness()},this.addInputsFromUTXO();const t=this.calculateOutputLeftAmountFromVaults(this.utxos);if(t<0)throw new Error(`Output value left is negative ${t}.`);this.addOutput({address:this.refundVault,value:Number(t)}),this.addOutput({address:this.receiver,value:Number(this.requestedAmount)})}async internalBuildTransaction(e,t=!1){const r=this.getInputs(),n=this.getOutputs();e.setMaximumFeeRate(this._maximumFeeRate),e.addInputs(r,t);for(let o=0;o<this.updateInputs.length;o++)e.updateInput(o,this.updateInputs[o]);e.addOutputs(n);try{return await this.signInputs(e),this.finalizeTransactionInputs()}catch(i){const e=i;this.error(`[internalBuildTransaction] Something went wrong while getting building the transaction: ${e.stack}`)}return!1}async signInputs(e){}generateScriptAddress(){return{internalPubkey:Yx(bU.numsPoint),network:this.network,scriptTree:this.scriptTree,name:lT.P2TR}}generateTapData(){const e=this.targetScriptRedeem;if(!e)throw new Error("Left over funds script redeem is required");if(!this.scriptTree)throw new Error("Script tree is required");return{internalPubkey:Yx(bU.numsPoint),network:this.network,scriptTree:this.scriptTree,redeem:e,name:lT.P2TR}}getScriptSolution(e){return e.tapScriptSig?e.tapScriptSig.map(e=>e.signature):[]}getScriptTree(){return this.generateRedeemScripts(),[{output:this.compiledTargetScript,version:192},{output:bU.LOCK_LEAF_SCRIPT,version:192}]}getTotalOutputAmount(e){let t=0n;for(const r of e)t+=r.value;return t}calculateOutputLeftAmountFromVaults(e){return this.getTotalOutputAmount(e)-this.requestedAmount}generateRedeemScripts(){this.targetScriptRedeem={name:lT.P2TR,output:this.compiledTargetScript,redeemVersion:192},this.leftOverFundsScriptRedeem={name:lT.P2TR,output:bU.LOCK_LEAF_SCRIPT,redeemVersion:192}}}function wU(e){return nh.from(e.replace("0x",""),"hex")}class vU{static{this.BLOCKS_PER_EPOCH=5n}static bufferToUint8Array(e){return new Uint8Array(e)}static uint8ArrayToBuffer(e){return nh.from(e)}static sha1(e){return ex(nh.isBuffer(e)?e:nh.from(e))}static calculatePreimage(e,t,r){if(32!==e.length||32!==t.length||32!==r.length)throw new Error("All inputs must be 32 bytes");const n=nh.alloc(32);for(let i=0;i<32;i++)n[i]=e[i]^t[i]^r[i];return n}static countMatchingBits(e,t){let r=0;if(e.length!==t.length)throw new Error("Hashes must be of the same length");const n=Math.min(e.length,t.length);for(let i=0;i<n;i++){const n=e[i],o=t[i];if(n===o)r+=8;else for(let e=7;e>=0;e--){if((n>>e&1)!=(o>>e&1))return r;r++}}return r}static verifySolution(e,t=!1){try{const t=e.verification,r=this.calculatePreimage(t.targetChecksum,e.publicKey.toBuffer(),e.salt),n=this.sha1(r),i=this.uint8ArrayToBuffer(n);if(!i.equals(e.solution)||this.countMatchingBits(i,t.targetHash)!==e.difficulty)return!1;const o=e.epochNumber*this.BLOCKS_PER_EPOCH,s=o+this.BLOCKS_PER_EPOCH-1n;return!(t.startBlock!==o||t.endBlock!==s)}catch(LU){return t&&console.error("Verification error:",LU),!1}}static getMiningTargetBlock(e){return 0n===e?null:e*this.BLOCKS_PER_EPOCH-1n}static validateEpochWinner(e){try{const t=BigInt(e.epochNumber),r=xP.fromString(e.mldsaPublicKey,e.legacyPublicKey),n=wU(e.solution),i=wU(e.salt),o=e.difficulty,s={epochHash:wU(e.verification.epochHash),epochRoot:wU(e.verification.epochRoot),targetHash:wU(e.verification.targetHash),targetChecksum:wU(e.verification.targetChecksum),startBlock:BigInt(e.verification.startBlock),endBlock:BigInt(e.verification.endBlock),proofs:Object.freeze(e.verification.proofs.map(e=>wU(e)))},a=this.calculatePreimage(s.targetChecksum,r.toBuffer(),i),u=this.sha1(a),c=this.uint8ArrayToBuffer(u);if(!c.equals(n)||this.countMatchingBits(c,s.targetHash)!==o)return!1;const f=t*this.BLOCKS_PER_EPOCH,l=f+this.BLOCKS_PER_EPOCH-1n;return!(s.startBlock!==f||s.endBlock!==l)}catch{return!1}}static validateChallengeSolution(e){return this.verifySolution(e)}static calculateSolution(e,t,r){const n=this.calculatePreimage(e,t,r),i=this.sha1(this.bufferToUint8Array(n));return this.uint8ArrayToBuffer(i)}static checkDifficulty(e,t,r){const n=this.countMatchingBits(e,t);return{valid:n>=r,difficulty:n}}}Symbol.iterator;Symbol.iterator;Symbol.iterator;var EU=(e=>(e.Mainnet="mainnet",e.Testnet="testnet",e.Regtest="regtest",e))(EU||{});class _U{constructor(){this._size=0,this.capacity=_U.INITIAL_CAPACITY,this.#e=new Array(this.capacity),this.#t=new Array(this.capacity),this.deleted=new Array(this.capacity).fill(!1)}static{this.INITIAL_CAPACITY=16}static{this.LOAD_FACTOR=.75}#e;#t;get size(){return this._size}set(e,t){let r=!0;const n=this.findInsertIndex(e);return(void 0===this.#e[n]||this.deleted[n])&&(this._size++,r=!1),this.#e[n]=e,this.#t[n]=t,this.deleted[n]=!1,this._size>this.capacity*_U.LOAD_FACTOR&&this.resize(),r}get(e){const t=this.findIndex(e);return-1===t?void 0:this.#t[t]}has(e){return-1!==this.findIndex(e)}indexOf(e){return this.findIndex(e)}delete(e){const t=this.findIndex(e);return-1!==t&&(this.#e[t]=void 0,this.#t[t]=void 0,this.deleted[t]=!0,this._size--,!0)}clear(){this.#e=new Array(this.capacity),this.#t=new Array(this.capacity),this.deleted=new Array(this.capacity).fill(!1),this._size=0}*entries(){for(let e=0;e<this.capacity;e++)void 0!==this.#e[e]&&!this.deleted[e]&&(yield[this.#e[e],this.#t[e]])}*keys(){for(let e=0;e<this.capacity;e++)void 0!==this.#e[e]&&!this.deleted[e]&&(yield this.#e[e])}*values(){for(let e=0;e<this.capacity;e++)void 0!==this.#e[e]&&!this.deleted[e]&&(yield this.#t[e])}*[Symbol.iterator](){yield*this.entries()}hashBigInt(e){if(e>=-2147483648n&&e<=2147483647n)return 0|Number(e);let t=2166136261,r=e<0n?-e:e;for(;r>0n;){t^=Number(0xffffffffn&r),t=Math.imul(t,16777619),r>>=32n}return e<0n&&(t^=2147483648,t=Math.imul(t,16777619)),Math.abs(t)}hash(e){let t=0;switch(typeof e){case"number":if(e!=e)return 0x7ff8000000000000;if(!isFinite(e))return e>0?0x7ff0000000000000:0xfff0000000000000;t=0|e;break;case"string":t=2166136261;for(let r=0;r<e.length;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);break;case"boolean":t=e?1231:1237;break;case"symbol":{const r=e.description||"";t=this.hash(r);break}case"bigint":t=this.hashBigInt(e);break;case"undefined":t=0;break;case"object":if(null===e)t=0;else if(e instanceof Date)t=0|e.getTime();else if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)t=this.hashBuffer(e);else{if(!Array.isArray(e))throw new Error("Raw object not supported.");t=1;for(const r of e)t=Math.imul(t,31)+this.hash(r)}break;case"function":t=this.hash(e.toString())}return Math.abs(t)%this.capacity}hashBuffer(e){let t;if(e instanceof ArrayBuffer)t=new Uint8Array(e);else{if(!ArrayBuffer.isView(e))return 0;t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let r=2166136261;for(let n=0;n<Math.min(t.length,100);n++)r^=t[n],r=Math.imul(r,16777619);return r}equals(e,t){return e===t||"number"==typeof e&&"number"==typeof t&&e!=e&&t!=t||!(!(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)||!(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))&&this.buffersEqual(e,t)}buffersEqual(e,t){const r=this.getBytes(e),n=this.getBytes(t);if(r.length!==n.length)return!1;for(let i=0;i<r.length;i++)if(r[i]!==n[i])return!1;return!0}getBytes(e){return e instanceof ArrayBuffer?new Uint8Array(e):ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(0)}findIndex(e){let t=this.hash(e);for(;void 0!==this.#e[t]||this.deleted[t];){if(void 0!==this.#e[t]&&this.equals(this.#e[t],e))return t;t=(t+1)%this.capacity}return-1}findInsertIndex(e){let t=this.hash(e);for(;void 0!==this.#e[t]&&!this.deleted[t];){if(this.equals(this.#e[t],e))return t;t=(t+1)%this.capacity}return t}resize(){const e=this.#e,t=this.#t;this.capacity*=2,this.#e=new Array(this.capacity),this.#t=new Array(this.capacity),this.deleted=new Array(this.capacity).fill(!1),this._size=0;for(let r=0;r<e.length;r++)void 0!==e[r]&&!this.deleted[r]&&this.set(e[r],t[r])}}wv.MLDSAKeyPair,wv.MLDSASecurityLevel,wv.QuantumBIP32API,wv.QuantumBIP32Factory,wv.QuantumBIP32Interface,wv.QuantumDerivationPath,wv.QuantumSigner,Symbol.toStringTag,wv.MLDSAKeyPair;const SU=wv.MLDSASecurityLevel;wv.QuantumBIP32API;const kU=wv.QuantumBIP32Factory;function AU(e){switch(e){case EU.Mainnet:return In.bitcoin;case EU.Testnet:return In.testnet;case EU.Regtest:return In.regtest}}function IU(e){return e.startsWith("bc1")||e.startsWith("1")||e.startsWith("3")?EU.Mainnet:e.startsWith("tb1")||e.startsWith("m")||e.startsWith("n")||e.startsWith("2")?EU.Testnet:e.startsWith("bcrt1")?EU.Regtest:null}wv.QuantumBIP32Interface,wv.QuantumDerivationPath,wv.QuantumSigner;for(var TU={},xU={byteLength:function(e){var t=NU(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=NU(e),i=n[0],o=n[1],s=new PU(function(e,t,r){return 3*(t+r)/4-r}(0,i,o)),a=0,u=o>0?i-4:i;for(r=0;r<u;r+=4)t=BU[e.charCodeAt(r)]<<18|BU[e.charCodeAt(r+1)]<<12|BU[e.charCodeAt(r+2)]<<6|BU[e.charCodeAt(r+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=255&t;2===o&&(t=BU[e.charCodeAt(r)]<<2|BU[e.charCodeAt(r+1)]>>4,s[a++]=255&t);1===o&&(t=BU[e.charCodeAt(r)]<<10|BU[e.charCodeAt(r+1)]<<4|BU[e.charCodeAt(r+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t);return s},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(CU(e,s,s+o>a?a:s+o));1===n?(t=e[r-1],i.push(OU[t>>2]+OU[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(OU[t>>10]+OU[t>>4&63]+OU[t<<2&63]+"="));return i.join("")}},OU=[],BU=[],PU="undefined"!=typeof Uint8Array?Uint8Array:Array,UU="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",LU=0;LU<64;++LU)OU[LU]=UU[LU],BU[UU.charCodeAt(LU)]=LU;function NU(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function RU(e){return OU[e>>18&63]+OU[e>>12&63]+OU[e>>6&63]+OU[63&e]}function CU(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(RU(n));return i.join("")}BU["-".charCodeAt(0)]=62,BU["_".charCodeAt(0)]=63;var HU={read:function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,f=-7,l=r?i-1:0,h=r?-1:1,p=e[t+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},write:function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<<c)-1,l=f>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?h/u:h*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*y}};!function(e){const t=xU,r=HU,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=c,e.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i;const{Uint8Array:o,ArrayBuffer:s,SharedArrayBuffer:a}=globalThis;function u(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new o(e);return Object.setPrototypeOf(t,c.prototype),t}function c(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return h(e)}return f(e,t,r)}function f(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!c.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|g(e,t);let n=u(r);const i=n.write(e,t);i!==r&&(n=n.slice(0,i));return n}(e,t);if(s.isView(e))return function(e){if(Y(e,o)){const t=new o(e);return d(t.buffer,t.byteOffset,t.byteLength)}return p(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(Y(e,s)||e&&Y(e.buffer,s))return d(e,t,r);if(void 0!==a&&(Y(e,a)||e&&Y(e.buffer,a)))return d(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return c.from(n,t,r);const i=function(e){if(c.isBuffer(e)){const t=0|y(e.length),r=u(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||Z(e.length)?u(0):p(e);if("Buffer"===e.type&&Array.isArray(e.data))return p(e.data)}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return c.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function h(e){return l(e),u(e<0?0:0|y(e))}function p(e){const t=e.length<0?0:0|y(e.length),r=u(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function d(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new o(e):void 0===r?new o(e,t):new o(e,t,r),Object.setPrototypeOf(n,c.prototype),n}function y(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function g(e,t){if(c.isBuffer(e))return e.length;if(s.isView(e)||Y(e,s))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return $(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:$(e).length;t=(""+t).toLowerCase(),i=!0}}function m(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return P(this,t,r);case"utf8":case"utf-8":return T(this,t,r);case"ascii":return O(this,t,r);case"latin1":case"binary":return B(this,t,r);case"base64":return I(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function b(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function w(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Z(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:v(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof o.prototype.indexOf?i?o.prototype.indexOf.call(e,t,r):o.prototype.lastIndexOf.call(e,t,r):v(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function v(e,t,r,n,i){let o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){let n=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(c(e,o+n)!==c(t,n)){r=!1;break}if(r)return o}return-1}function E(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=t.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(Z(n))return s;e[r+s]=n}return s}function _(e,t,r,n){return X($(t,e.length-r),e,r,n)}function S(e,t,r,n){return X(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function k(e,t,r,n){return X(G(t),e,r,n)}function A(e,t,r,n){return X(function(e,t){let r,n,i;const o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function I(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function T(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let o=null,s=t>239?4:t>223?3:t>191?2:1;if(i+s<=r){let r,n,a,u;switch(s){case 1:t<128&&(o=t);break;case 2:r=e[i+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(o=u));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(e){const t=e.length;if(t<=x)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=x));return r}(n)}c.TYPED_ARRAY_SUPPORT=function(){try{const e=new o(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,o.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e_){return!1}}(),c.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),c.poolSize=8192,c.from=function(e,t,r){return f(e,t,r)},Object.setPrototypeOf(c.prototype,o.prototype),Object.setPrototypeOf(c,o),c.alloc=function(e,t,r){return function(e,t,r){return l(e),e<=0?u(e):void 0!==t?"string"==typeof r?u(e).fill(t,r):u(e).fill(t):u(e)}(e,t,r)},c.allocUnsafe=function(e){return h(e)},c.allocUnsafeSlow=function(e){return h(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==c.prototype},c.compare=function(e,t){if(Y(e,o)&&(e=c.from(e,e.offset,e.byteLength)),Y(t,o)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=c.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(Y(t,o))i+t.length>n.length?(c.isBuffer(t)||(t=c.from(t)),t.copy(n,i)):o.prototype.set.call(n,t,i);else{if(!c.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},c.byteLength=g,c.prototype._isBuffer=!0,c.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)b(this,t,t+1);return this},c.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)b(this,t,t+3),b(this,t+1,t+2);return this},c.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)b(this,t,t+7),b(this,t+1,t+6),b(this,t+2,t+5),b(this,t+3,t+4);return this},c.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?T(this,0,e):m.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(c.prototype[n]=c.prototype.inspect),c.prototype.compare=function(e,t,r,n,i){if(Y(e,o)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const u=Math.min(s,a),f=this.slice(n,i),l=e.slice(t,r);for(let o=0;o<u;++o)if(f[o]!==l[o]){s=f[o],a=l[o];break}return s<a?-1:a<s?1:0},c.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},c.prototype.indexOf=function(e,t,r){return w(this,e,t,r,!0)},c.prototype.lastIndexOf=function(e,t,r){return w(this,e,t,r,!1)},c.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return E(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":case"latin1":case"binary":return S(this,e,t,r);case"base64":return k(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const x=4096;function O(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function B(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function P(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=t;o<r;++o)i+=Q[e[o]];return i}function U(e,t,r){const n=e.slice(t,r);let i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function L(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,r,n,i,o){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function R(e,t,r,n,i){F(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function H(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function K(e,t,n,i,o){return t=+t,n>>>=0,o||H(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function z(e,t,n,i,o){return t=+t,n>>>=0,o||H(e,0,n,8),r.write(e,t,n,i,52,8),n+8}c.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,c.prototype),n},c.prototype.readUintLE=c.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return n},c.prototype.readUintBE=c.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},c.prototype.readUint8=c.prototype.readUInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),this[e]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readBigUInt64LE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||q(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),c.prototype.readBigUInt64BE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||q(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)}),c.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);let n=t,i=1,o=this[e+--n];for(;n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},c.prototype.readInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||L(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt16BE=function(e,t){e>>>=0,t||L(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readBigInt64LE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||q(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),c.prototype.readBigInt64BE=J(function(e){V(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||q(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)}),c.prototype.readFloatLE=function(e,t){return e>>>=0,t||L(e,4,this.length),r.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||L(e,4,this.length),r.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||L(e,8,this.length),r.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||L(e,8,this.length),r.read(this,e,!1,52,8)},c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){N(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){N(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},c.prototype.writeUint8=c.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigUInt64LE=J(function(e,t=0){return R(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=J(function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=0,o=1,s=0;for(this[t]=255&e;++i<r&&(o*=256);)e<0&&0===s&&0!==this[t+i-1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},c.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===s&&0!==this[t+i+1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},c.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigInt64LE=J(function(e,t=0){return R(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=J(function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeFloatLE=function(e,t,r){return K(this,e,t,!0,r)},c.prototype.writeFloatBE=function(e,t,r){return K(this,e,t,!1,r)},c.prototype.writeDoubleLE=function(e,t,r){return z(this,e,t,!0,r)},c.prototype.writeDoubleBE=function(e,t,r){return z(this,e,t,!1,r)},c.prototype.copy=function(e,t,r,n){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof o.prototype.copyWithin?this.copyWithin(t,r,n):o.prototype.set.call(e,this.subarray(r,n),t),i},c.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const o=c.isBuffer(e)?e:c.from(e,n),s=o.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=o[i%s]}return this};const M={};function D(e,t,r){M[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function j(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,o){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new M.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,r){V(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||q(t,e.length-(r+1))}(n,i,o)}function V(e,t){if("number"!=typeof e)throw new M.ERR_INVALID_ARG_TYPE(t,"number",e)}function q(e,t,r){if(Math.floor(e)!==e)throw V(e,r),new M.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new M.ERR_BUFFER_OUT_OF_BOUNDS;throw new M.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),D("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=j(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=j(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);const W=/[^+/0-9A-Za-z-_]/g;function $(e,t){let r;t=t||1/0;const n=e.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(W,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function X(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Y(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Z(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return"undefined"==typeof BigInt?ee:e}function ee(){throw new Error("BigInt not supported")}}(TU);const KU=TU.Buffer;function zU(e,t,r){const n="string"==typeof e?KU.from(e,"hex"):e;switch(t){case _P.P2PKH:{const e=nn.p2pkh({pubkey:n,network:r});if(void 0===e.address)throw new Error("Failed to generate P2PKH address");return e.address}case _P.P2WPKH:{const e=nn.p2wpkh({pubkey:n,network:r});if(void 0===e.address)throw new Error("Failed to generate P2WPKH address");return e.address}case _P.P2TR:{const e=33===n.length?n.subarray(1,33):n,t=nn.p2tr({internalPubkey:e,network:r});if(void 0===t.address)throw new Error("Failed to generate P2TR address");return t.address}case _P.P2SH_OR_P2SH_P2WPKH:{const e=nn.p2wpkh({pubkey:n,network:r}),t=nn.p2sh({redeem:e,network:r});if(void 0===t.address)throw new Error("Failed to generate P2SH-P2WPKH address");return t.address}default:throw new Error(`Unsupported address type: ${t}`)}}function MU(e,t,r){const n="string"==typeof e?KU.from(e,"hex"):e;switch(t){case _P.P2PKH:return nn.p2pkh({pubkey:n,network:r});case _P.P2WPKH:return nn.p2wpkh({pubkey:n,network:r});case _P.P2TR:{const e=33===n.length?n.subarray(1,33):n;return nn.p2tr({internalPubkey:e,network:r})}case _P.P2SH_OR_P2SH_P2WPKH:{const e=nn.p2wpkh({pubkey:n,network:r});return nn.p2sh({redeem:e,network:r})}default:throw new Error(`Unsupported address type: ${t}`)}}function DU(e,t){const r="string"==typeof e?KU.from(e,"hex"):e;return Xi.fromOutputScript(r,t)}function jU(e,t){return null!==SP.detectAddressType(e,t)}function FU(e,t){return SP.detectAddressType(e,t)}class VU{static type="HD Key Tree";type=VU.type;mnemonic=null;wallets=new Map;activeIndexes=[];network;securityLevel;passphrase;addressType;_hdPath;constructor(e){if(!e.network)throw new Error("HdKeyring: Network option is required");this.network=e.network,this.securityLevel=e?.securityLevel??SU.LEVEL2,this.passphrase=e?.passphrase??"",this.addressType=e?.addressType??_P.P2TR,this._hdPath=e?.hdPath??"",void 0!==e?.mnemonic&&(this.initFromMnemonic(e.mnemonic),void 0!==e.activeIndexes&&e.activeIndexes.length>0&&this.activateAccounts([...e.activeIndexes]))}get hdPath(){return this._hdPath}static generate(e=GP.MAXIMUM,t="",r=In.bitcoin,n=SU.LEVEL2){const i=QP.generate(e,t,r,n),o=new VU({network:r,securityLevel:n,passphrase:t});return o.mnemonic=i,o}initFromMnemonic(e){if(null!==this.mnemonic)throw new Error("HdKeyring: Mnemonic already initialized");this.mnemonic=new QP(e,this.passphrase,this.network,this.securityLevel)}getMnemonic(){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");return this.mnemonic.phrase}hasMnemonic(){return null!==this.mnemonic}deriveWallet(e){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const t=this.wallets.get(e);if(void 0!==t)return t;let r;if(this.isCustomHdPath()){const t=`${this._hdPath}/${e}`,n=`m/360'/${this.network===In.bitcoin?0:1}'/0'/0/${e}`;r=this.mnemonic.deriveCustomPath(t,n)}else r=this.mnemonic.deriveOPWallet(this.addressType,e);return this.wallets.set(e,r),r}deriveStandardWallet(e){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");return this.mnemonic.derive(e)}addAccounts(e=1){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const t=[];let r=0;for(;t.length<e;){if(!this.activeIndexes.includes(r)){const e=this.deriveWallet(r);this.activeIndexes.push(r),t.push(e.toPublicKeyHex())}r++}return t}activateAccounts(e){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const t=[];for(const r of e)if(this.activeIndexes.includes(r)){const e=this.wallets.get(r);void 0!==e&&t.push(e.toPublicKeyHex())}else{const e=this.deriveWallet(r);this.activeIndexes.push(r),t.push(e.toPublicKeyHex())}return t}getAccounts(){return this.activeIndexes.map(e=>{const t=this.wallets.get(e);if(void 0===t)throw new Error(`HdKeyring: Wallet at index ${e} not found`);return t.toPublicKeyHex()})}getAccountsInfo(){return this.activeIndexes.map(e=>{const t=this.wallets.get(e);if(void 0===t)throw new Error(`HdKeyring: Wallet at index ${e} not found`);const r={p2pkh:t.legacy,p2wpkh:t.p2wpkh,p2tr:t.p2tr,p2shP2wpkh:t.segwitLegacy};return{index:e,publicKey:t.toPublicKeyHex(),quantumPublicKey:t.quantumPublicKeyHex,addresses:r}})}getQuantumPublicKey(e){return this.findWalletByPublicKey(e).quantumPublicKeyHex}getIndexByPublicKey(e){for(const[t,r]of this.wallets.entries())if(r.toPublicKeyHex()===e)return t;return null}getAddressesForPublicKey(e){const t=this.findWalletByPublicKey(e);return{p2pkh:t.legacy,p2wpkh:t.p2wpkh,p2tr:t.p2tr,p2shP2wpkh:t.segwitLegacy}}getAddress(e,t){return zU(KU.from(e,"hex"),t,this.network)}removeAccount(e){const t=this.getIndexByPublicKey(e);if(null===t)throw new Error(`HdKeyring: Account with public key ${e} not found`);const r=this.activeIndexes.indexOf(t);-1!==r&&this.activeIndexes.splice(r,1),this.wallets.delete(t)}exportAccount(e){return this.findWalletByPublicKey(e).toPrivateKeyHex()}signTransaction(e,t){for(const r of t){const t=this.findWalletByPublicKey(r.publicKey),n=e.data.inputs[r.index];if(void 0===n)throw new Error(`HdKeyring: Input at index ${r.index} not found`);const i=t.keypair,o=void 0!==r.sighashTypes?[...r.sighashTypes]:void 0;if(Bs(n)&&!0!==r.disableTweakSigner){const n=t.publicKey.subarray(1,33),s=i.tweak(KU.from(n));e.signInput(r.index,s,o)}else e.signInput(r.index,i,o)}return e}signData(e,t,r="ecdsa"){const n=this.findWalletByPublicKey(e),i=KU.from(t,"hex");return"ecdsa"===r?KU.from(n.keypair.sign(i)).toString("hex"):KU.from(n.keypair.signSchnorr(i)).toString("hex")}getWallet(e){return this.findWalletByPublicKey(e)}serialize(){return{mnemonic:this.mnemonic?.phrase,passphrase:this.passphrase,network:this.network,securityLevel:this.securityLevel,activeIndexes:[...this.activeIndexes],addressType:this.addressType,hdPath:this._hdPath}}getActiveIndexes(){return[...this.activeIndexes]}setAddressType(e){this.addressType=e}getAddressType(){return this.addressType}getSecurityLevel(){return this.securityLevel}getNetwork(){return this.network}getAddressesPage(e,t=5){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const r=e*t,n=r+t,i=[];for(let o=r;o<n;o++){let e;if(this.isCustomHdPath()){const t=`${this._hdPath}/${o}`,r=`m/360'/${this.network===In.bitcoin?0:1}'/0'/0/${o}`;e=this.mnemonic.deriveCustomPath(t,r)}else e=this.mnemonic.deriveOPWallet(this.addressType,o);const t=this.getAddressFromWallet(e);i.push({address:t,index:o})}return i}getChainCode(e){const t=this.findWalletByPublicKey(e);return KU.from(t.chainCode)}getMLDSAKeypair(e){return this.findWalletByPublicKey(e).mldsaKeypair}isCustomHdPath(){const e={[_P.P2PKH]:"m/44'/0'/0'/0",[_P.P2WPKH]:"m/84'/0'/0'/0",[_P.P2TR]:"m/86'/0'/0'/0",[_P.P2SH_OR_P2SH_P2WPKH]:"m/49'/0'/0'/0"}[this.addressType];if(void 0===e)return""!==this._hdPath;const t=e.slice(0,-2);return!this._hdPath.includes(t)&&""!==this._hdPath}findWalletByPublicKey(e){for(const t of this.wallets.values())if(t.toPublicKeyHex()===e)return t;throw new Error(`HdKeyring: Wallet with public key ${e} not found`)}getAddressFromWallet(e){switch(this.addressType){case _P.P2PKH:return e.legacy;case _P.P2WPKH:return e.p2wpkh;case _P.P2TR:return e.p2tr;case _P.P2SH_OR_P2SH_P2WPKH:return e.segwitLegacy;default:return e.p2tr}}}function qU(e,...t){if(!((r=e)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function WU(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $U(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function GU(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function XU(e,t){return e<<32-t|e>>>t}function YU(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),qU(e),e}class ZU{}function QU(e){const t=t=>e().update(YU(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function JU(e,t,r){return e&t^~e&r}function eL(e,t,r){return e&t^e&r^t&r}class tL extends ZU{constructor(e,t,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=GU(this.buffer)}update(e){WU(this),qU(e=YU(e));const{view:t,buffer:r,blockLen:n}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s===n){const t=GU(e);for(;n<=i-o;o+=n)this.process(t,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){WU(this),function(e,t){qU(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,$U(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let f=o;f<n;f++)t[f]=0;!function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,c=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+c,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const s=GU(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)s.setUint32(4*f,c[f],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const rL=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nL=Uint32Array.from([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]),iL=new Uint32Array(64);class oL extends tL{constructor(e=32){super(64,e,8,!1),this.A=0|rL[0],this.B=0|rL[1],this.C=0|rL[2],this.D=0|rL[3],this.E=0|rL[4],this.F=0|rL[5],this.G=0|rL[6],this.H=0|rL[7]}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let f=0;f<16;f++,t+=4)iL[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){const e=iL[f-15],t=iL[f-2],r=XU(e,7)^XU(e,18)^e>>>3,n=XU(t,17)^XU(t,19)^t>>>10;iL[f]=n+iL[f-7]+r+iL[f-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let f=0;f<64;f++){const e=c+(XU(s,6)^XU(s,11)^XU(s,25))+JU(s,a,u)+nL[f]+iL[f]|0,t=(XU(r,2)^XU(r,13)^XU(r,22))+eL(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+t|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){$U(iL)}destroy(){this.set(0,0,0,0,0,0,0,0),$U(this.buffer)}}const sL=QU(()=>new oL),aL="0123456789abcdefABCDEF";function uL(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function cL(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function fL(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function lL(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function hL(e){if(!Array.isArray(e))throw new Error("array expected")}function pL(e,t){if(!cL(!0,t))throw new Error(`${e}: array of strings expected`)}function dL(...e){const t=e=>e,r=(e,t)=>r=>e(t(r));return{encode:e.map(e=>e.encode).reduceRight(r,t),decode:e.map(e=>e.decode).reduce(r,t)}}function yL(e){const t="string"==typeof e?e.split(""):e,r=t.length;pL("alphabet",t);const n=new Map(t.map((e,t)=>[e,t]));return{encode:n=>(hL(n),n.map(n=>{if(!Number.isSafeInteger(n)||n<0||n>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${n}". Allowed: ${e}`);return t[n]})),decode:t=>(hL(t),t.map(t=>{fL("alphabet.decode",t);const r=n.get(t);if(void 0===r)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return r}))}}function gL(e=""){return fL("join",e),{encode:t=>(pL("join.decode",t),t.join(e)),decode:t=>(fL("join.decode",t),t.split(e))}}function mL(e,t,r){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(hL(e),!e.length)return[];let n=0;const i=[],o=Array.from(e,e=>{if(lL(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,a=!0;for(let i=n;i<s;i++){const s=o[i],u=t*e,c=u+s;if(!Number.isSafeInteger(c)||u/t!==e||c-s!==u)throw new Error("convertRadix: carry overflow");const f=c/r;e=c%r;const l=Math.floor(f);if(o[i]=l,!Number.isSafeInteger(l)||l*r+e!==c)throw new Error("convertRadix: carry overflow");a&&(l?a=!1:n=i)}if(i.push(e),a)break}for(let a=0;a<e.length-1&&0===e[a];a++)i.push(0);return i.reverse()}function bL(e){lL(e);return{encode:t=>{if(!uL(t))throw new Error("radix.encode input should be Uint8Array");return mL(Array.from(t),256,e)},decode:t=>(function(e,t){if(!cL(!1,t))throw new Error(`${e}: array of numbers expected`)}("radix.decode",t),Uint8Array.from(mL(t,e,256)))}}function wL(e,t){return lL(e),function(e){if("function"!=typeof e)throw new Error("function expected")}(t),{encode(r){if(!uL(r))throw new Error("checksum.encode: input should be Uint8Array");const n=t(r).slice(0,e),i=new Uint8Array(r.length+e);return i.set(r),i.set(n,r.length),i},decode(r){if(!uL(r))throw new Error("checksum.decode: input should be Uint8Array");const n=r.slice(0,-e),i=r.slice(-e),o=t(n).slice(0,e);for(let t=0;t<e;t++)if(o[t]!==i[t])throw new Error("Invalid checksum");return n}}}aL.split("").map(e=>e.codePointAt(0)),Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=aL.indexOf(r);return n<0?void 0:n<16?n:n-6}),new TextEncoder,new TextDecoder;const vL=(e=>dL(bL(58),yL(e),gL("")))("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),EL=e=>dL(wL(4,t=>e(e(t))),vL);function _L(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function SL(e,t=""){if(!Number.isSafeInteger(e)||e<0){throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}}function kL(e,t,r=""){const n=_L(e),i=e?.length,o=void 0!==t;if(!n||o&&i!==t){throw new Error((r&&`"${r}" `)+"expected Uint8Array"+(o?` of length ${t}`:"")+", got "+(n?`length=${i}`:"type="+typeof e))}return e}function AL(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function IL(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}!function(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let a=0;a<t.length;a++)t[a]=255;for(let a=0;a<e.length;a++){const r=e.charAt(a),n=r.charCodeAt(0);if(255!==t[n])throw new TypeError(r+" is ambiguous");t[n]=a}const r=e.length,n=e.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let o=0,s=0,a=0;for(;e[o]===n;)0;const u=(e.length-o)*i+1>>>0,c=new Uint8Array(u);for(;o<e.length;){const n=e.charCodeAt(o);if(n>255)return;let i=t[n];if(255===i)return;let s=0;for(let e=u-1;(0!==i||s<a)&&-1!==e;s++)r*c[e]>>>0,c[e]=i%256>>>0;if(0!==i)throw new Error("Non-zero carry");0}let f=u-a;for(;f!==u&&0===c[f];)0;const l=new Uint8Array(s+(u-f));let h=s;for(;f!==u;)l[h++]=c[f++];return l}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),EL(sL);function TL(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const xL=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=TL(e[t]);return e};function OL(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];kL(r),t+=r.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const t=e[n];r.set(t,i),i+=t.length}return r}const BL=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])}),PL=function(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))};function UL(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}function LL(e){if("object"!=typeof e||null===e||_L(e))throw new Error("expected opts to be an object")}function NL(e){LL(e),void 0!==e.context&&kL(e.context,void 0,"opts.context")}function RL(e){NL(e),!1!==e.extraEntropy&&void 0!==e.extraEntropy&&kL(e.extraEntropy,void 0,"opts.extraEntropy")}function CL(e,...t){const r=e=>"number"==typeof e?e:e.bytesLen,n=t.reduce((e,t)=>e+r(t),0);return{bytesLen:n,encode:i=>{const o=new Uint8Array(n);for(let n=0,s=0;n<t.length;n++){const a=t[n],u=r(a),c="number"==typeof a?i[n]:a.encode(i[n]);kL(c,u,e),o.set(c,s),"number"!=typeof a&&c.fill(0),s+=u}return o},decode:i=>{kL(i,n,e);const o=[];for(const e of t){const t=r(e),n=i.subarray(0,t);o.push("number"==typeof e?n:e.decode(n)),i=i.subarray(t)}return o}}}function HL(e,t){const r=t*e.bytesLen;return{bytesLen:r,encode:n=>{if(n.length!==t)throw new Error(`vecCoder.encode: wrong length=${n.length}. Expected: ${t}`);const i=new Uint8Array(r);for(let t=0,r=0;t<n.length;t++){const o=e.encode(n[t]);i.set(o,r),o.fill(0),r+=o.length}return i},decode:t=>{kL(t,r);const n=[];for(let r=0;r<t.length;r+=e.bytesLen)n.push(e.decode(t.subarray(r,r+e.bytesLen)));return n}}}function KL(...e){for(const t of e)if(Array.isArray(t))for(const e of t)e.fill(0);else t.fill(0)}function zL(e){return(1<<e)-1}const ML=Uint8Array.of();function DL(e,t=ML){if(kL(e),kL(t),t.length>255)throw new Error("context should be less than 255 bytes");return OL(new Uint8Array([0,t.length]),t,e)}const jL=Uint8Array.from([6,9,96,134,72,1,101,3,4,2]);function FL(e,t,r=ML){if(kL(t),kL(r),r.length>255)throw new Error("context should be less than 255 bytes");const n=e(t);return OL(new Uint8Array([1,r.length]),r,e.oid,n)}const VL=BigInt(2**32-1),qL=BigInt(32);function WL(e,t=!1){return t?{h:Number(e&VL),l:Number(e>>qL&VL)}:{h:0|Number(e>>qL&VL),l:0|Number(e&VL)}}const $L=BigInt(0),GL=BigInt(1),XL=BigInt(2),YL=BigInt(7),ZL=BigInt(256),QL=BigInt(113),JL=[],eN=[],tN=[];for(let _R=0,SR=GL,kR=1,AR=0;_R<24;_R++){[kR,AR]=[AR,(2*kR+3*AR)%5],JL.push(2*(5*AR+kR)),eN.push((_R+1)*(_R+2)/2%64);let e=$L;for(let t=0;t<7;t++)SR=(SR<<GL^(SR>>YL)*QL)%ZL,SR&XL&&(e^=GL<<(GL<<BigInt(t))-GL);tN.push(e)}const rN=function(e,t=!1){const r=e.length;let n=new Uint32Array(r),i=new Uint32Array(r);for(let o=0;o<r;o++){const{h:r,l:s}=WL(e[o],t);[n[o],i[o]]=[r,s]}return[n,i]}(tN,!0),nN=rN[0],iN=rN[1],oN=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),sN=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);class aN{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;enableXOF=!1;rounds;constructor(e,t,r,n=!1,i=24){if(this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=n,this.rounds=i,SL(r,"outputLen"),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}clone(){return this._cloneInto()}keccak(){xL(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let n=0;n<10;n++)r[n]=e[n]^e[n+10]^e[n+20]^e[n+30]^e[n+40];for(let n=0;n<10;n+=2){const t=(n+8)%10,i=(n+2)%10,o=r[i],s=r[i+1],a=oN(o,s,1)^r[t],u=sN(o,s,1)^r[t+1];for(let r=0;r<50;r+=10)e[n+r]^=a,e[n+r+1]^=u}let t=e[2],i=e[3];for(let r=0;r<24;r++){const n=eN[r],o=oN(t,i,n),s=sN(t,i,n),a=JL[r];t=e[a],i=e[a+1],e[a]=o,e[a+1]=s}for(let n=0;n<50;n+=10){for(let t=0;t<10;t++)r[t]=e[n+t];for(let t=0;t<10;t++)e[n+t]^=~r[(t+2)%10]&r[(t+4)%10]}e[0]^=nN[n],e[1]^=iN[n]}IL(r)}(this.state32,this.rounds),xL(this.state32),this.posOut=0,this.pos=0}update(e){AL(this),kL(e);const{blockLen:t,state:r}=this,n=e.length;for(let i=0;i<n;){const o=Math.min(t-this.pos,n-i);for(let t=0;t<o;t++)r[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,128&t&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){AL(this,!1),kL(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,i=e.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);e.set(t.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return SL(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){kL(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,IL(this.state)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:i,enableXOF:o}=this;return e||=new aN(t,r,n,o,i),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=r,e.outputLen=n,e.enableXOF=o,e.destroyed=this.destroyed,e}}const uN=(e,t,r,n={})=>function(e,t={}){const r=(t,r)=>e(r).update(t).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=t=>e(t),Object.assign(r,t),Object.freeze(r)}((n={})=>new aN(t,e,void 0===n.dkLen?r:n.dkLen,!0),n),cN=uN(31,168,16,BL(11)),fN=uN(31,136,32,BL(12));function lN(e){if(!Number.isSafeInteger(e)||e<0||e>4294967295)throw new Error("wrong u32 integer:"+e);return e}function hN(e){return lN(e),!(e&e-1)&&0!==e}function pN(e,t){lN(e);let r=0;for(let n=0;n<t;n++,e>>>=1)r=r<<1|1&e;return r}function dN(e){return lN(e),31-Math.clz32(e)}function yN(e){const t=e.length;if(t<2||!hN(t))throw new Error("n must be a power of 2 and greater than 1. Got "+t);const r=dN(t);for(let n=0;n<t;n++){const t=pN(n,r);if(n<t){const r=e[n];e[n]=e[t],e[t]=r}}return e}const gN=(e,t)=>{const{N:r,roots:n,dit:i,invertButterflies:o=!1,skipStages:s=0,brp:a=!0}=t,u=dN(r);if(!hN(r))throw new Error("FFT: Polynomial size should be power of two");const c=i!==o;return t=>{if(t.length!==r)throw new Error("FFT: wrong Polynomial length");i&&a&&yN(t);for(let a=0,f=1;a<u-s;a++){const l=i?a+1+s:u-a,h=1<<l,p=h>>1,d=r>>l;for(let s=0;s<r;s+=h)for(let a=0,u=f++;a<p;a++){const f=s+a,l=s+a+p,h=n[o?i?r-u:u:a*d],y=t[l],g=t[f];if(c){const r=e.mul(y,h);t[f]=e.add(g,r),t[l]=e.sub(g,r)}else o?(t[f]=e.add(y,g),t[l]=e.mul(e.sub(y,g),h)):(t[f]=e.add(g,y),t[l]=e.mul(e.sub(g,y),h))}}return!i&&a&&yN(t),t}},mN=e=>(t,r)=>{r||(r=e.blockLen);const n=new Uint8Array(t.length+2);n.set(t);const i=t.length,o=new Uint8Array(r);let s=e.create({}),a=0,u=0;return{stats:()=>({calls:a,xofs:u}),get:(t,r)=>(n[i+0]=t,n[i+1]=r,s.destroy(),s=e.create({}).update(n),a++,()=>(u++,s.xofInto(o))),clean:()=>{s.destroy(),KL(o,n)}}},bN=mN(cN),wN=mN(fN);function vN(e){LL(e),void 0!==e.externalMu&&function(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e)}(e.externalMu,"opts.externalMu")}const EN=256,_N=8380417,SN=13,kN=0|Math.floor(95232),AN=0|Math.floor(261888),IN={K:4,L:4,D:SN,GAMMA1:2**17,GAMMA2:kN,TAU:39,ETA:2,OMEGA:80},TN={K:6,L:5,D:SN,GAMMA1:2**19,GAMMA2:AN,TAU:49,ETA:4,OMEGA:55},xN={K:8,L:7,D:SN,GAMMA1:2**19,GAMMA2:AN,TAU:60,ETA:2,OMEGA:75},ON=e=>new Int32Array(e),{mod:BN,smod:PN,NTT:UN,bitsCoder:LN}=(e=>{const{newPoly:t,N:r,Q:n,F:i,ROOT_OF_UNITY:o,brvBits:s}=e,a=(e,t=n)=>{const r=e%t|0;return 0|(r>=0?r:t+r)};const u=function(){const e=t(r);for(let t=0;t<r;t++){const r=pN(t,s),i=BigInt(o)**BigInt(r)%BigInt(n);e[t]=0|Number(i)}return e}(),c={add:(e,t)=>0|a((0|e)+(0|t)),sub:(e,t)=>0|a((0|e)-(0|t)),mul:(e,t)=>0|a((0|e)*(0|t)),inv:e=>{throw new Error("not implemented")}},f={N:r,roots:u,invertButterflies:!0,skipStages:0,brp:!1},l=gN(c,{dit:!1,...f}),h=gN(c,{dit:!0,...f}),p={encode:e=>l(e),decode:e=>{h(e);for(let t=0;t<e.length;t++)e[t]=a(i*e[t]);return e}};return{mod:a,smod:(e,t=n)=>{const r=0|a(e,t);return 0|(r>t>>1?r-t:r)},nttZetas:u,NTT:p,bitsCoder:(e,n)=>{const i=zL(e),o=e*(r/8);return{bytesLen:o,encode:t=>{const r=new Uint8Array(o);for(let o=0,s=0,a=0,u=0;o<t.length;o++)for(s|=(n.encode(t[o])&i)<<a,a+=e;a>=8;a-=8,s>>=8)r[u++]=s&zL(a);return r},decode:o=>{const s=t(r);for(let t=0,r=0,a=0,u=0;t<o.length;t++)for(r|=o[t]<<a,a+=8;a>=e;a-=e,r>>=e)s[u++]=n.decode(r&i);return s}}}}})({N:EN,Q:_N,F:8347681,ROOT_OF_UNITY:1753,newPoly:ON,brvBits:8}),NN=e=>e,RN=(e,t=NN,r=NN)=>LN(e,{encode:e=>t(r(e)),decode:e=>r(t(e))}),CN=(e,t)=>{for(let r=0;r<e.length;r++)e[r]=BN(e[r]+t[r]);return e},HN=(e,t)=>{for(let r=0;r<e.length;r++)e[r]=BN(e[r]-t[r]);return e},KN=e=>{for(let t=0;t<EN;t++)e[t]<<=SN;return e},zN=(e,t)=>{for(let r=0;r<EN;r++)if(Math.abs(PN(e[r]))>=t)return!0;return!1},MN=(e,t)=>{const r=ON(EN);for(let n=0;n<e.length;n++)r[n]=BN(e[n]*t[n]);return r};function DN(e){const t=ON(EN);for(let r=0;r<EN;){const n=e();if(n.length%3)throw new Error("RejNTTPoly: unaligned block");for(let e=0;r<EN&&e<=n.length-3;e+=3){const i=8388607&(n[e+0]|n[e+1]<<8|n[e+2]<<16);i<_N&&(t[r++]=i)}}return t}function jN(e){const{K:t,L:r,GAMMA1:n,GAMMA2:i,TAU:o,ETA:s,OMEGA:a}=e,{CRH_BYTES:u,TR_BYTES:c,C_TILDE_BYTES:f,XOF128:l,XOF256:h,securityLevel:p}=e;if(![2,4].includes(s))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(n))throw new Error("Wrong GAMMA1");if(![kN,AN].includes(i))throw new Error("Wrong GAMMA2");const d=o*s,y=e=>{const t=BN(e),r=0|PN(t,2*i);if(t-r===_N-1)return{r1:0,r0:r-1|0};return{r1:0|Math.floor((t-r)/(2*i)),r0:r}},g=e=>y(e).r1,m=e=>y(e).r0,b=(e,t)=>e<=i||e>_N-i||e===_N-i&&0===t?0:1,w=(e,t)=>{const r=Math.floor((_N-1)/(2*i)),{r1:n,r0:o}=y(t);return 1===e?o>0?0|BN(n+1,r):0|BN(n-1,r):0|n},v=e=>{const t=BN(e),r=0|PN(t,8192);return{r1:0|Math.floor((t-r)/8192),r0:r}},E={bytesLen:a+t,encode:e=>{if(!1===e)throw new Error("hint.encode: hint is false");const r=new Uint8Array(a+t);for(let n=0,i=0;n<t;n++){for(let t=0;t<EN;t++)0!==e[n][t]&&(r[i++]=t);r[a+n]=i}return r},decode:e=>{const r=[];let n=0;for(let i=0;i<t;i++){const t=ON(EN);if(e[a+i]<n||e[a+i]>a)return!1;for(let r=n;r<e[a+i];r++){if(r>n&&e[r]<=e[r-1])return!1;t[e[r]]=1}n=e[a+i],r.push(t)}for(let t=n;t<a;t++)if(0!==e[t])return!1;return r}},_=RN(2===s?3:4,e=>s-e,e=>{if(!(-s<=e&&e<=s))throw new Error(`malformed key s1/s3 ${e} outside of ETA range [${-s}, ${s}]`);return e}),S=RN(13,e=>4096-e),k=RN(10),A=RN(n===1<<17?18:20,e=>PN(n-e)),I=HL(RN(i===kN?6:4),t),T=CL("publicKey",32,HL(k,t)),x=CL("secretKey",32,32,c,HL(_,r),HL(_,t),HL(S,t)),O=CL("signature",f,HL(A,r),E),B=2===s?e=>e<15&&2-e%5:e=>e<9&&4-e;function P(e){const t=ON(EN);for(let r=0;r<EN;){const n=e();for(let e=0;r<EN&&e<n.length;e+=1){const i=B(15&n[e]),o=B(n[e]>>4&15);!1!==i&&(t[r++]=i),r<EN&&!1!==o&&(t[r++]=o)}}return t}const U=e=>{const t=ON(EN),r=fN.create({}).update(e),n=new Uint8Array(fN.blockLen);r.xofInto(n);const i=n.slice(0,8);for(let s=EN-o,a=8,u=0,c=0;s<EN;s++){let e=s+1;for(;e>s;)e=n[a++],a<fN.blockLen||(r.xofInto(n),a=0);t[s]=t[e],t[e]=1-((i[u]>>c++&1)<<1),c>=8&&(u++,c=0)}return t},L=e=>{const t=ON(EN),r=ON(EN);for(let n=0;n<e.length;n++){const{r0:i,r1:o}=v(e[n]);t[n]=i,r[n]=o}return{r0:t,r1:r}},N=(e,t)=>{for(let r=0;r<EN;r++)e[r]=w(t[r],e[r]);return e},R=(e,t)=>{const r=ON(EN);let n=0;for(let i=0;i<EN;i++){const o=b(e[i],t[i]);r[i]=o,n+=o}return{v:r,cnt:n}},C=CL("seed",32,64,32),H={info:{type:"internal-ml-dsa"},lengths:{secretKey:x.bytesLen,publicKey:T.bytesLen,seed:32,signature:O.bytesLen,signRand:32},keygen:e=>{const n=new Uint8Array(34),i=void 0===e;i&&(e=PL(32)),kL(e,32,"seed"),n.set(e),i&&KL(e),n[32]=t,n[33]=r;const[o,s,a]=C.decode(fN(n,{dkLen:C.bytesLen})),u=h(s),f=[];for(let t=0;t<r;t++)f.push(P(u.get(255&t,t>>8&255)));const p=[];for(let c=r;c<r+t;c++)p.push(P(u.get(255&c,c>>8&255)));const d=f.map(e=>UN.encode(e.slice())),y=[],g=[],m=l(o),b=ON(EN);for(let c=0;c<t;c++){KL(b);for(let n=0;n<r;n++){const e=DN(m.get(n,c));CN(b,MN(e,d[n]))}UN.decode(b);const{r0:e,r1:t}=L(CN(b,p[c]));y.push(e),g.push(t)}const w=T.encode([o,g]),v=fN(w,{dkLen:c}),E=x.encode([o,a,v,f,p,y]);return m.clean(),u.clean(),KL(o,s,a,f,p,d,b,y,g,v,n),{publicKey:w,secretKey:E}},getPublicKey:e=>{const[n,i,o,s,a,u]=x.decode(e),c=l(n),f=s.map(e=>UN.encode(e.slice())),h=[],p=ON(EN);for(let l=0;l<t;l++){p.fill(0);for(let t=0;t<r;t++){const e=DN(c.get(t,l));CN(p,MN(e,f[t]))}UN.decode(p),CN(p,a[l]);const{r1:e}=L(p);h.push(e)}return c.clean(),KL(p,f,u,s,a),T.encode([n,h])},sign:(e,o,s={})=>{RL(s),vN(s);let{extraEntropy:c,externalMu:p=!1}=s;const[y,b,w,v,E,_]=x.decode(o),S=[],k=l(y);for(let n=0;n<t;n++){const e=[];for(let t=0;t<r;t++)e.push(DN(k.get(t,n)));S.push(e)}k.clean();for(let t=0;t<r;t++)UN.encode(v[t]);for(let r=0;r<t;r++)UN.encode(E[r]),UN.encode(_[r]);const T=p?e:fN.create({dkLen:u}).update(w).update(e).digest(),B=!1===c?new Uint8Array(32):void 0===c?PL(32):c;kL(B,32,"extraEntropy");const P=fN.create({dkLen:u}).update(b).update(B).update(T).digest();kL(P,u);const L=h(P,A.bytesLen);e:for(let u=0;;){const e=[];for(let t=0;t<r;t++,u++)e.push(A.decode(L.get(255&u,u>>8)()));const o=e.map(e=>UN.encode(e.slice())),s=[];for(let n=0;n<t;n++){const e=ON(EN);for(let t=0;t<r;t++)CN(e,MN(S[n][t],o[t]));UN.decode(e),s.push(e)}const c=s.map(e=>e.map(g)),l=fN.create({dkLen:f}).update(T).update(I.encode(c)).digest(),h=UN.encode(U(l)),p=v.map(e=>MN(e,h));for(let t=0;t<r;t++)if(CN(UN.decode(p[t]),e[t]),zN(p[t],n-d))continue e;let y=0;const b=[];for(let r=0;r<t;r++){const e=UN.decode(MN(E[r],h)),t=HN(s[r],e).map(m);if(zN(t,i-d))continue e;const n=UN.decode(MN(_[r],h));if(zN(n,i))continue e;CN(t,n);const o=R(t,c[r]);b.push(o.v),y+=o.cnt}if(y>a)continue;L.clean();const w=O.encode([l,p,b]);return KL(l,p,b,h,c,s,o,e,P,T,v,E,_,...S),w}throw new Error("Unreachable code path reached, report this error")},verify:(e,i,o,s={})=>{vN(s);const{externalMu:h=!1}=s,[p,y]=T.decode(o),g=fN(o,{dkLen:c});if(e.length!==O.bytesLen)return!1;const[m,b,w]=O.decode(e);if(!1===w)return!1;for(let t=0;t<r;t++)if(zN(b[t],n-d))return!1;const v=h?i:fN.create({dkLen:u}).update(g).update(i).digest(),E=UN.encode(U(m)),_=b.map(e=>e.slice());for(let t=0;t<r;t++)UN.encode(_[t]);const S=[],k=l(p);for(let n=0;n<t;n++){const e=MN(UN.encode(KN(y[n])),E),t=ON(EN);for(let o=0;o<r;o++){const e=DN(k.get(o,n));CN(t,MN(e,_[o]))}const i=UN.decode(HN(t,e));S.push(N(i,w[n]))}k.clean();const A=fN.create({dkLen:f}).update(v).update(I.encode(S)).digest();for(const t of w){const e=t.reduce((e,t)=>e+t,0);if(!(e<=a))return!1}for(const t of b)if(zN(t,n-d))return!1;return UL(m,A)}};return{info:{type:"ml-dsa"},internal:H,securityLevel:p,keygen:H.keygen,lengths:H.lengths,getPublicKey:H.getPublicKey,sign:(e,t,r={})=>{RL(r);const n=DL(e,r.context),i=H.sign(n,t,r);return KL(n),i},verify:(e,t,r,n={})=>(NL(n),H.verify(e,DL(t,n.context),r)),prehash:e=>(function(e,t=0){if(!e.oid||!UL(e.oid.subarray(0,10),jL))throw new Error("hash.oid is invalid: expected NIST hash");const r=8*e.outputLen/2;if(t>r)throw new Error("Pre-hash security strength too low: "+r+", required: "+t)}(e,p),{info:{type:"hashml-dsa"},securityLevel:p,lengths:H.lengths,keygen:H.keygen,getPublicKey:H.getPublicKey,sign:(t,r,n={})=>{RL(n);const i=FL(e,t,n.context),o=H.sign(i,r,n);return KL(i),o},verify:(t,r,n,i={})=>(NL(i),H.verify(t,FL(e,r,i.context),n))})}}const FN=jN({...IN,CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:bN,XOF256:wN,securityLevel:128}),VN=jN({...TN,CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:bN,XOF256:wN,securityLevel:192}),qN=jN({...xN,CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:bN,XOF256:wN,securityLevel:256});var WN,$N;($N=WN||(WN={}))[$N.LEVEL2=44]="LEVEL2",$N[$N.LEVEL3=65]="LEVEL3",$N[$N.LEVEL5=87]="LEVEL5";const GN={[WN.LEVEL2]:{level:WN.LEVEL2,privateKeySize:2560,publicKeySize:1312,signatureSize:2420,algorithm:FN},[WN.LEVEL3]:{level:WN.LEVEL3,privateKeySize:4032,publicKeySize:1952,signatureSize:3309,algorithm:VN},[WN.LEVEL5]:{level:WN.LEVEL5,privateKeySize:4896,publicKeySize:2592,signatureSize:4627,algorithm:qN}};var XN,YN,ZN,QN;WN.LEVEL2,EL(sL),(YN=XN||(XN={})).BIP44="m/44'/0'/0'/0/0",YN.BIP49="m/49'/0'/0'/0/0",YN.BIP84="m/84'/0'/0'/0/0",YN.BIP86="m/86'/0'/0'/0/0",YN.BIP360="m/360'/0'/0'/0/0",(QN=ZN||(ZN={})).STANDARD="m/360'/0'/0'/0/0",QN.CHANGE="m/360'/0'/0'/1/0",QN.ACCOUNT_0_ADDRESS_0="m/360'/0'/0'/0/0",QN.ACCOUNT_0_ADDRESS_1="m/360'/0'/0'/0/1",QN.ACCOUNT_1_ADDRESS_0="m/360'/1'/0'/0/0";class JN{static type="Simple Key Pair";type=JN.type;network;securityLevel;keypair=null;quantumKeypair=null;chainCode=KU.alloc(32);constructor(e){if(!e?.network)throw new Error("SimpleKeyring: Network option is required");this.network=e.network,this.securityLevel=e?.securityLevel??SU.LEVEL2,void 0!==e?.privateKey&&this.importPrivateKey(e.privateKey,e.quantumPrivateKey)}static generate(e=In.bitcoin,t=SU.LEVEL2){const r=new JN({network:e,securityLevel:t,privateKey:""});r.keypair=dP.generateRandomKeyPair(e);const n=KU.from(crypto.getRandomValues(new Uint8Array(64)));return r.quantumKeypair=kU.fromSeed(n,e,t),r.chainCode=KU.from(r.quantumKeypair.chainCode),r}static fromWIF(e,t,r=In.bitcoin,n=SU.LEVEL2){const i=new JN({network:r,securityLevel:n,privateKey:""});return i.keypair=dP.fromWIF(e,r),void 0!==t&&""!==t&&i.importQuantumKey(t),i}static fromPrivateKey(e,t,r=In.bitcoin,n=SU.LEVEL2){const i=new JN({network:r,securityLevel:n,privateKey:""}),o=KU.from(e,"hex");return i.keypair=dP.fromPrivateKey(o,r),void 0!==t&&""!==t&&i.importQuantumKey(t),i}importPrivateKey(e,t){if(""!==e){if(64===e.length){const t=KU.from(e,"hex");this.keypair=dP.fromPrivateKey(t,this.network)}else this.keypair=dP.fromWIF(e,this.network);void 0!==t&&""!==t&&this.importQuantumKey(t)}}importQuantumKey(e){const t=KU.from(e,"hex"),r=function(e,t){const r=GN[e];if(!r)throw new TypeError(`Invalid ML-DSA security level: ${e}. Must be MLDSASecurityLevel.LEVEL2 (44), LEVEL3 (65), or LEVEL5 (87)`);return{...r,network:t}}(this.securityLevel,this.network).privateKeySize,n=r+32,i=t.length===n,o=t.length===r;if(!i&&!o)throw new Error(`Invalid quantum key length: ${t.length} bytes. Expected ${r} bytes (key only) or ${n} bytes (key + chaincode).`);if(i){this.chainCode=t.subarray(-32);const e=t.subarray(0,-32);this.quantumKeypair=kU.fromPrivateKey(e,this.chainCode,this.network,this.securityLevel)}else this.chainCode=KU.from(crypto.getRandomValues(new Uint8Array(32))),this.quantumKeypair=kU.fromPrivateKey(t,this.chainCode,this.network,this.securityLevel)}generateFreshQuantumKey(){const e=KU.from(crypto.getRandomValues(new Uint8Array(64)));this.quantumKeypair=kU.fromSeed(e,this.network,this.securityLevel),this.chainCode=KU.from(this.quantumKeypair.chainCode)}hasKeys(){return null!==this.keypair&&null!==this.quantumKeypair}hasClassicalKey(){return null!==this.keypair}hasQuantumKey(){return null!==this.quantumKeypair}needsQuantumMigration(){return null!==this.keypair&&null===this.quantumKeypair}getPublicKey(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return this.keypair.publicKey.toString("hex")}getQuantumPublicKey(){if(null===this.quantumKeypair)throw new Error("SimpleKeyring: No quantum keypair initialized");return KU.from(this.quantumKeypair.publicKey).toString("hex")}getQuantumPublicKeyOrUndefined(){if(null!==this.quantumKeypair)return KU.from(this.quantumKeypair.publicKey).toString("hex")}getQuantumPublicKeyHash(){if(null===this.quantumKeypair)throw new Error("SimpleKeyring: No quantum keypair initialized");return Xe.sha256(KU.from(this.quantumKeypair.publicKey)).toString("hex")}clearQuantumKey(){this.quantumKeypair=null,this.chainCode=KU.alloc(32)}getAccounts(){return null===this.keypair?[]:[this.getPublicKey()]}getAddresses(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");const e=this.keypair.publicKey;return{p2pkh:zU(e,_P.P2PKH,this.network),p2wpkh:zU(e,_P.P2WPKH,this.network),p2tr:zU(e,_P.P2TR,this.network),p2shP2wpkh:zU(e,_P.P2SH_OR_P2SH_P2WPKH,this.network)}}getAddress(e){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return zU(this.keypair.publicKey,e,this.network)}exportPrivateKey(){if(void 0===this.keypair?.privateKey)throw new Error("SimpleKeyring: No private key available");return KU.from(this.keypair.privateKey).toString("hex")}exportQuantumPrivateKey(){if(void 0===this.quantumKeypair?.privateKey)throw new Error("SimpleKeyring: No quantum private key available");const e=KU.from(this.quantumKeypair.privateKey);return KU.concat([e,this.chainCode]).toString("hex")}exportRawQuantumPrivateKey(){if(void 0===this.quantumKeypair?.privateKey)throw new Error("SimpleKeyring: No quantum private key available");return KU.from(this.quantumKeypair.privateKey).toString("hex")}exportChainCode(){return this.chainCode}exportWIF(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return this.keypair.toWIF()}signTransaction(e,t){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");for(const r of t){const t=e.data.inputs[r.index];if(void 0===t)throw new Error(`SimpleKeyring: Input at index ${r.index} not found`);if(Bs(t)&&!0!==r.disableTweakSigner){const t=this.keypair.tweak(KU.from(this.keypair.publicKey.subarray(1,33)));e.signInput(r.index,t,r.sighashTypes)}else e.signInput(r.index,this.keypair,r.sighashTypes)}return e}signData(e,t="ecdsa"){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");const r=KU.from(e,"hex");return"ecdsa"===t?KU.from(this.keypair.sign(r)).toString("hex"):KU.from(this.keypair.signSchnorr(r)).toString("hex")}verify(e,t,r="ecdsa"){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");const n=KU.from(e,"hex"),i=KU.from(t,"hex");return"ecdsa"===r?this.keypair.verify(n,i):this.keypair.verifySchnorr(n,i)}getKeypair(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return this.keypair}getQuantumKeypair(){if(null===this.quantumKeypair)throw new Error("SimpleKeyring: No quantum keypair initialized");return this.quantumKeypair}getChainCode(){return this.chainCode}getSecurityLevel(){return this.securityLevel}getNetwork(){return this.network}serialize(){let e;try{e=this.exportQuantumPrivateKey()}catch{e=void 0}return{privateKey:this.exportPrivateKey(),quantumPrivateKey:e,network:this.network,securityLevel:this.securityLevel}}clear(){this.keypair=null,this.quantumKeypair=null,this.chainCode=KU.alloc(32)}}const eR="OPNET_WALLET_V1";function tR(e){return Xe.sha256(KU.from(e,"utf8")).subarray(0,4).toString("hex")}function rR(e){return e.bech32===In.bitcoin.bech32?"mainnet":e.bech32===In.testnet.bech32?"testnet":"regtest"}function nR(e,t,r,n,i,o,s){const a={magic:eR,version:1,network:rR(s),classical:{privateKey:e.toString("hex"),publicKey:t.toString("hex")},quantum:{privateKey:KU.from(r).toString("hex"),publicKey:KU.from(n).toString("hex"),securityLevel:o,chainCode:i.toString("hex")}},u=tR(JSON.stringify(a));return{...a,checksum:u}}function iR(e){if(e.magic!==eR)throw new Error("Invalid wallet export format: wrong magic header");if(1!==e.version)throw new Error(`Unsupported wallet export version: ${e.version}`);const t={magic:e.magic,version:e.version,network:e.network,classical:e.classical,quantum:e.quantum},r=tR(JSON.stringify(t));if(e.checksum!==r)throw new Error("Invalid wallet export: checksum mismatch");const n=function(e){switch(e){case"mainnet":default:return In.bitcoin;case"testnet":return In.testnet;case"regtest":return In.regtest}}(e.network),i=KU.from(e.quantum.chainCode,"hex"),o=KU.from(e.classical.privateKey,"hex"),s=dP.fromPrivateKey(o,n),a=KU.from(e.quantum.privateKey,"hex");return{keypair:s,quantumKeypair:kU.fromPrivateKey(a,i,n,e.quantum.securityLevel),network:n,securityLevel:e.quantum.securityLevel,chainCode:i}}function oR(e){const t=JSON.stringify(e);return KU.from(t,"utf8").toString("base64")}function sR(e){try{const t=KU.from(e,"base64").toString("utf8");return JSON.parse(t)}catch{throw new Error("Invalid wallet export: failed to deserialize")}}function aR(e,t){const r=WP.signMLDSAMessage(e,t);return{message:r.message,signature:r.signature,publicKey:r.publicKey,securityLevel:r.securityLevel}}function uR(e,t,r,n,i,o){const s=kU.fromPublicKey(e,t,r,n);return WP.verifyMLDSASignature(s,i,o)}function cR(e,t){const r=WP.signMessage(e,t);return{message:r.message,signature:r.signature,publicKey:e.publicKey}}function fR(e,t,r){return WP.verifySignature(e,t,r)}function lR(e){return"securityLevel"in e&&"chainCode"in e}function hR(e){return"string"==typeof e?KU.from(e,"utf8"):e instanceof Uint8Array?KU.from(e):e}const pR=[_P.P2WPKH,_P.P2TR];function dR(e){const t=Xe.sha256(KU.from("BIP0322-signed-message","utf8")),r="string"==typeof e?KU.from(e,"utf8"):e;return Xe.sha256(KU.concat([t,t,r]))}function yR(e,t,r){const n=Xi.toOutputScript(t,r),i=FU(t,r);if(null===i||!pR.includes(i))throw new Error(`BIP322: Address type not supported for signing. Got: ${String(i)}`);const o=dR(e),s=KU.alloc(32,0),a=KU.concat([KU.from("0020","hex"),o]),u=new pn;u.version=0,u.addInput(s,4294967295,0,a),u.addOutput(n,0);const c=new Ds({network:r});return c.setVersion(0),c.addInput({hash:u.getHash(),index:0,sequence:0,witnessUtxo:{script:n,value:0}}),c.addOutput({script:KU.from("6a","hex"),value:0}),c}function gR(e){const t=e.extractTransaction(),r=t.ins[0]?.witness;if(void 0===r||0===r.length)throw new Error("BIP322: No witness data found in signed transaction");const n=vr.number.encode(r.length);return KU.concat([n,...r.map(e=>function(e){const t=vr.number.encode(e.length);return KU.concat([t,e])}(e))]).toString("base64")}async function mR(e,t,r,n){const i=yR(e,t,r),o=await n(i);return o.finalizeAllInputs(),gR(o)}function bR(e,t,r){try{const n=vr.signature.decode(r);return W.verify(t,e,n.signature)}catch{return!1}}function wR(e,t,r,n){try{const i=Xi.toOutputScript(e,n),o=dR(t),s=KU.alloc(32,0),a=4294967295,u=0,c=KU.concat([KU.from("0020","hex"),o]),f=new pn;f.version=0,f.addInput(s,a,u,c),f.addOutput(i,0);const l=KU.from(r,"base64"),h=vr.decompile(l.subarray(1));if(!Array.isArray(h)||0===h.length)return!1;const p=h[0];if(!KU.isBuffer(p))return!1;const d=KU.concat([KU.from("02","hex"),i.subarray(2)]),y=new Ds({network:n});y.setVersion(0),y.addInput({hash:f.getHash(),index:0,sequence:0,witnessUtxo:{script:i,value:0}}),y.addOutput({script:KU.from("6a","hex"),value:0});const g=y.__CACHE.__TX;return function(e,t,r){try{const n=33===e.length?e.subarray(1,33):e;return W.verifySchnorr(t,n,r)}catch{return!1}}(d,g.hashForWitnessV1(0,[i],[0],pn.SIGHASH_DEFAULT),p)}catch{return!1}}function vR(e,t,r,n){const i=FU(e,n);if(null===i)return!1;switch(i){case _P.P2TR:return wR(e,t,r,n);case _P.P2WPKH:return function(e,t,r,n){try{const i=Xi.toOutputScript(e,n),o=dR(t),s=KU.alloc(32,0),a=4294967295,u=0,c=KU.concat([KU.from("0020","hex"),o]),f=new pn;f.version=0,f.addInput(s,a,u,c),f.addOutput(i,0);const l=KU.from(r,"base64"),h=vr.decompile(l.subarray(1));if(!Array.isArray(h)||h.length<2)return!1;const p=h[0],d=h[1];if(!KU.isBuffer(p)||!KU.isBuffer(d))return!1;const y=new Ds({network:n});return y.setVersion(0),y.addInput({hash:f.getHash(),index:0,sequence:0,witnessUtxo:{script:i,value:0}}),y.addOutput({script:KU.from("6a","hex"),value:0}),y.updateInput(0,{partialSig:[{pubkey:d,signature:p}]}),y.validateSignaturesOfAllInputs(bR)}catch{return!1}}(e,t,r,n);default:return!1}}class ER{keyring;network;addressType;publicKey;address;constructor(e,t,r,n){this.keyring=e,this.network=t,this.addressType=r,this.publicKey=n,this.address=zU(KU.from(n,"hex"),r,t)}static fromWIF(e,t=_P.P2TR,r,n){const i=JN.fromWIF(e,n,r),o=i.getPublicKey();return new ER(i,r,t,o)}static fromPrivateKey(e,t=_P.P2TR,r,n){const i=JN.fromPrivateKey(e,n,r),o=i.getPublicKey();return new ER(i,r,t,o)}static fromMnemonic(e,t=_P.P2TR,r,n,i=0){const o=new VU({mnemonic:e,passphrase:n,network:r,addressType:t,activeIndexes:[i]}),s=o.getAccounts()[0];if(void 0===s)throw new Error("Failed to derive wallet from mnemonic");return new ER(o,r,t,s)}static random(e=_P.P2TR,t=In.bitcoin){const r=JN.generate(t),n=r.getPublicKey();return new ER(r,t,e,n)}getAddress(){return this.address}getPublicKey(){return this.publicKey}getQuantumPublicKey(){return this.keyring instanceof JN?this.keyring.getQuantumPublicKey():this.keyring.getQuantumPublicKey(this.publicKey)}getNetwork(){return this.network}getAddressType(){return this.addressType}signPsbt(e,t){const r=t??{autoFinalized:!0,toSignInputs:[]},n=this.formatInputsToSign(e,r);if(0===n.length)throw new Error("LocalWallet: No inputs to sign");for(const i of n){const t=e.data.inputs[i.index];if(void 0===t)continue;const r=!(t.finalScriptSig??t.finalScriptWitness),n=this.addressType===_P.P2TR,o=void 0===t.tapInternalKey;if(r&&n&&o){const e=KU.from(this.publicKey,"hex"),r=33===e.length?e.subarray(1,33):e,{output:n}=nn.p2tr({internalPubkey:r,network:this.network});t.witnessUtxo?.script.toString("hex")===n?.toString("hex")&&(t.tapInternalKey=r)}}if(this.keyring,this.keyring.signTransaction(e,n),!0===r.autoFinalized)for(const i of n)e.finalizeInput(i.index);return e}async signMessage(e,t){switch(t){case"bip322-simple":return await mR(e,this.address,this.network,e=>Promise.resolve(this.signPsbt(e,{autoFinalized:!1})));case"ecdsa":case"schnorr":{const t=cR(this.getKeypair(),e);return KU.from(t.signature).toString("hex")}case"mldsa":{const t=aR(this.getQuantumKeypair(),e);return KU.from(t.signature).toString("hex")}}}signData(e,t="ecdsa"){return this.keyring instanceof JN?this.keyring.signData(e,t):this.keyring.signData(this.publicKey,e,t)}exportPrivateKey(){return this.keyring instanceof JN?this.keyring.exportPrivateKey():this.keyring.exportAccount(this.publicKey)}exportQuantumPrivateKey(){if(this.keyring instanceof JN)return this.keyring.exportQuantumPrivateKey();const e=this.keyring.getWallet(this.publicKey),t=e.mldsaKeypair.privateKey;if(void 0===t)throw new Error("LocalWallet: No quantum private key available");const r=KU.from(t),n=e.chainCode;return KU.concat([r,n]).toString("hex")}exportRawQuantumPrivateKey(){if(this.keyring instanceof JN)return this.keyring.exportRawQuantumPrivateKey();const e=this.keyring.getWallet(this.publicKey).mldsaKeypair.privateKey;if(void 0===e)throw new Error("LocalWallet: No quantum private key available");return KU.from(e).toString("hex")}exportChainCode(){return this.keyring instanceof JN?this.keyring.exportChainCode():this.keyring.getChainCode(this.publicKey)}exportWIF(){if(this.keyring instanceof JN)return this.keyring.exportWIF();throw new Error("LocalWallet: Cannot export WIF from HD keyring directly")}getKeypair(){return this.keyring instanceof JN?this.keyring.getKeypair():this.keyring.getWallet(this.publicKey).keypair}getQuantumKeypair(){return this.keyring instanceof JN?this.keyring.getQuantumKeypair():this.keyring.getMLDSAKeypair(this.publicKey)}formatInputsToSign(e,t){const r=[];if(void 0!==t.toSignInputs&&t.toSignInputs.length>0)for(const n of t.toSignInputs){const e=n.index;if("address"in n){if(n.address!==this.address)throw new Error(`LocalWallet: Address mismatch at input ${e}`)}else if("publicKey"in n&&n.publicKey!==this.publicKey)throw new Error(`LocalWallet: Public key mismatch at input ${e}`);const t={index:e,publicKey:this.publicKey};void 0!==n.sighashTypes&&(t.sighashTypes=n.sighashTypes),void 0!==n.disableTweakSigner&&(t.disableTweakSigner=n.disableTweakSigner),r.push(t)}else for(let n=0;n<e.data.inputs.length;n++){const t=e.data.inputs[n];if(void 0===t)continue;let i;if(void 0!==t.witnessUtxo)i=t.witnessUtxo.script;else if(void 0!==t.nonWitnessUtxo){const r=e.txInputs[n];if(void 0!==r){const e=pn.fromBuffer(t.nonWitnessUtxo).outs[r.index];i=e?.script}}const o=t.finalScriptSig??t.finalScriptWitness;if(void 0!==i&&void 0===o){if(DU(i,this.network)===this.address){const e={index:n,publicKey:this.publicKey};void 0!==t.sighashType&&(e.sighashTypes=[t.sighashType]),r.push(e)}}}return r}}!function(e){e?e!==Br.eccLib&&(function(e){Lr("function"==typeof e.isXOnlyPoint),Lr(e.isXOnlyPoint(Ur("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Lr(e.isXOnlyPoint(Ur("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Lr(e.isXOnlyPoint(Ur("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Lr(e.isXOnlyPoint(Ur("0000000000000000000000000000000000000000000000000000000000000001"))),Lr(!e.isXOnlyPoint(Ur("0000000000000000000000000000000000000000000000000000000000000000"))),Lr(!e.isXOnlyPoint(Ur("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Lr("function"==typeof e.xOnlyPointAddTweak),Nr.forEach(t=>{const r=e.xOnlyPointAddTweak(Ur(t.pubkey),Ur(t.tweak));null===t.result?Lr(null===r):(Lr(null!==r),Lr(r.parity===t.parity),Lr(oe.from(r.xOnlyPubkey).equals(Ur(t.result))))})}(e),Br.eccLib=e):Br.eccLib=e}($),exports.HdKeyring=VU,exports.LocalWallet=ER,exports.SimpleKeyring=JN,exports.addressToScriptPubKey=function(e,t){return Xi.toOutputScript(e,t)},exports.decodeAddress=function(e){const t=In.bitcoin,r=In.testnet,n=In.regtest,i=[{network:t,networkType:EU.Mainnet},{network:r,networkType:EU.Testnet},{network:n,networkType:EU.Regtest}];for(const{network:o,networkType:s}of i)try{const t=Xi.toOutputScript(e,o),r=FU(e,o);if(null!==r)return{networkType:s,addressType:r,scriptPubKey:t}}catch{}return null},exports.deserializeExport=sR,exports.detectAddressType=FU,exports.detectNetworkFromAddress=IU,exports.exportWallet=nR,exports.exportWalletToString=function(e,t,r,n,i,o,s){return oR(nR(e,t,r,n,i,o,s))},exports.extractBip322Signature=gR,exports.fromLegacyExport=function(e,t){const r=KU.from(e.classicalPrivateKey,"hex"),n=dP.fromPrivateKey(r,t),i={magic:eR,version:1,network:rR(t),classical:{privateKey:e.classicalPrivateKey,publicKey:n.publicKey.toString("hex")},quantum:{privateKey:e.quantumPrivateKey,publicKey:e.quantumPublicKey,securityLevel:e.securityLevel,chainCode:e.chainCode}},o=tR(JSON.stringify(i));return{...i,checksum:o}},exports.generateBip322Psbt=yR,exports.getAddressType=function(e,t){return FU(e,AU(t))},exports.getBech32Prefix=function(e){return AU(e).bech32},exports.importWallet=iR,exports.importWalletFromString=function(e){return iR(sR(e))},exports.isAddressSignInput=function(e){return"address"in e},exports.isP2PKHOrP2SHAddress=function(e,t){return SP.isP2PKHOrP2SH(e,t)},exports.isP2WPKHAddress=function(e,t){return SP.isP2WPKHAddress(e,t)},exports.isPublicKeySignInput=function(e){return"publicKey"in e},exports.isValidAddress=jU,exports.isValidAddressForNetworkType=function(e,t){return jU(e,AU(t))},exports.isValidP2TRAddress=function(e,t){return SP.isValidP2TRAddress(e,t)},exports.isValidPublicKey=function(e,t){const r="string"==typeof e?e:e.toString("hex");return SP.isValidPublicKey(r,t)},exports.publicKeyToAddress=zU,exports.publicKeyToAddressWithNetworkType=function(e,t,r){return zU(e,t,AU(r))},exports.publicKeyToPayment=MU,exports.publicKeyToScriptPubKey=function(e,t,r){const n=MU(e,t,r);if(!n.output)throw new Error("Failed to generate script pubkey");return n.output},exports.scriptPubKeyToAddress=DU,exports.serializeExport=oR,exports.signBip322Message=mR,exports.signBip322MessageWithNetworkType=async function(e,t,r,n){const i=AU(r);return{address:t,message:e,signature:await mR(e,t,i,n),networkType:r}},exports.signMLDSA=aR,exports.signMessage=function(e,t,r){const n=hR(t);switch(r){case"mldsa":{if(!lR(e))throw new Error("ML-DSA signing requires a quantum keypair");const r=aR(e,t);return{message:n,signature:r.signature,publicKey:r.publicKey,signatureType:"mldsa",securityLevel:r.securityLevel}}case"schnorr":{if(lR(e))throw new Error("Schnorr signing requires a classical keypair");const r=cR(e,t);return{message:n,signature:r.signature,publicKey:r.publicKey,signatureType:"schnorr"}}case"ecdsa":{if(lR(e))throw new Error("ECDSA signing requires a classical keypair");const t=WP.sha256(n);return{message:n,signature:e.sign(KU.from(t)),publicKey:e.publicKey,signatureType:"ecdsa"}}}},exports.signSchnorr=cR,exports.signTweakedSchnorr=function(e,t,r=In.bitcoin){const n=WP.tweakAndSignMessage(e,t,r);return{message:n.message,signature:n.signature,publicKey:e.publicKey}},exports.toNetwork=AU,exports.toNetworkType=function(e){return e.bech32===In.bitcoin.bech32?EU.Mainnet:e.bech32===In.testnet.bech32?EU.Testnet:EU.Regtest},exports.validateAddressNetwork=function(e,t){return IU(e)===t},exports.validateExport=function(e){try{if(e.magic!==eR)return!1;if(1!==e.version)return!1;const t={magic:e.magic,version:e.version,network:e.network,classical:e.classical,quantum:e.quantum},r=tR(JSON.stringify(t));return e.checksum===r}catch{return!1}},exports.verifyBip322Message=vR,exports.verifyBip322MessageWithNetworkType=function(e,t,r,n){return vR(e,t,r,AU(n))},exports.verifyMLDSA=uR,exports.verifyMLDSAWithKeypair=function(e,t,r){return WP.verifyMLDSASignature(e,t,r)},exports.verifyMessage=function(e,t,r,n,i,o,s){switch(n){case"mldsa":if(void 0===i||void 0===o||void 0===s)throw new Error("ML-DSA verification requires chainCode, network, and securityLevel");return uR(e,i,o,s,t,r);case"schnorr":return fR(e,t,r);case"ecdsa":{const n=hR(t),i=WP.sha256(n);return W.verify(i,KU.from(e),KU.from(r))}}},exports.verifySchnorr=fR,exports.verifyTweakedSchnorr=function(e,t,r){return WP.tweakAndVerifySignature(e,t,r)};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@btc-vision/transaction"),t=require("@btc-vision/bitcoin"),r=require("@btc-vision/ecpair"),i=require("@btc-vision/bip32");function n(r){switch(r){case e.WalletNetworks.Mainnet:return t.networks.bitcoin;case e.WalletNetworks.Testnet:return t.networks.testnet;case e.WalletNetworks.Regtest:return t.networks.regtest;case e.WalletNetworks.OpnetTestnet:return t.networks.opnetTestnet;default:throw new Error(`Unsupported network type: ${r}`)}}function s(r){return r.bech32===t.networks.bitcoin.bech32?e.WalletNetworks.Mainnet:r.bech32===t.networks.testnet.bech32?e.WalletNetworks.Testnet:r.bech32===t.networks.opnetTestnet.bech32?e.WalletNetworks.OpnetTestnet:e.WalletNetworks.Regtest}function a(r){return r.startsWith(`${t.networks.regtest.bech32}1`)?e.WalletNetworks.Regtest:r.startsWith(`${t.networks.opnetTestnet.bech32}1`)?e.WalletNetworks.OpnetTestnet:r.startsWith(`${t.networks.bitcoin.bech32}1`)?e.WalletNetworks.Mainnet:r.startsWith(`${t.networks.testnet.bech32}1`)?e.WalletNetworks.Testnet:r.startsWith("1")||r.startsWith("3")?e.WalletNetworks.Mainnet:r.startsWith("m")||r.startsWith("n")||r.startsWith("2")?e.WalletNetworks.Testnet:null}function o(i,n,s){const a="string"==typeof i?r.fromHexInternal(i):i;switch(n){case e.AddressTypes.P2PKH:{const e=t.payments.p2pkh({pubkey:r.createPublicKey(a),network:s});if(void 0===e.address)throw new Error("Failed to generate P2PKH address");return e.address}case e.AddressTypes.P2WPKH:{const e=t.payments.p2wpkh({pubkey:r.createPublicKey(a),network:s});if(void 0===e.address)throw new Error("Failed to generate P2WPKH address");return e.address}case e.AddressTypes.P2TR:{const e=33===a.length?a.subarray(1,33):a,i=t.payments.p2tr({internalPubkey:r.createXOnlyPublicKey(e),network:s});if(void 0===i.address)throw new Error("Failed to generate P2TR address");return i.address}case e.AddressTypes.P2SH_OR_P2SH_P2WPKH:{const e=t.payments.p2wpkh({pubkey:r.createPublicKey(a),network:s}),i=t.payments.p2sh({redeem:e,network:s});if(void 0===i.address)throw new Error("Failed to generate P2SH-P2WPKH address");return i.address}default:throw new Error(`Unsupported address type: ${n}`)}}function u(i,n,s){const a="string"==typeof i?r.fromHexInternal(i):i;switch(n){case e.AddressTypes.P2PKH:return t.payments.p2pkh({pubkey:r.createPublicKey(a),network:s});case e.AddressTypes.P2WPKH:return t.payments.p2wpkh({pubkey:r.createPublicKey(a),network:s});case e.AddressTypes.P2TR:{const e=33===a.length?a.subarray(1,33):a;return t.payments.p2tr({internalPubkey:r.createXOnlyPublicKey(e),network:s})}case e.AddressTypes.P2SH_OR_P2SH_P2WPKH:{const e=t.payments.p2wpkh({pubkey:r.createPublicKey(a),network:s});return t.payments.p2sh({redeem:e,network:s})}default:throw new Error(`Unsupported address type: ${n}`)}}function c(e,r){const i="string"==typeof e?t.fromHex(e):e;return t.address.fromOutputScript(i,r)}function y(t,r){return null!==e.AddressVerificator.detectAddressType(t,r)}function l(t,r){return e.AddressVerificator.detectAddressType(t,r)}class p{static type="HD Key Tree";type=p.type;mnemonic=null;wallets=new Map;activeIndexes=[];network;securityLevel;passphrase;addressType;_hdPath;constructor(t){if(!t.network)throw new Error("HdKeyring: Network option is required");this.network=t.network,this.securityLevel=t?.securityLevel??e.MLDSASecurityLevel.LEVEL2,this.passphrase=t?.passphrase??"",this.addressType=t?.addressType??e.AddressTypes.P2TR,this._hdPath=t?.hdPath??"",void 0!==t?.mnemonic&&(this.initFromMnemonic(t.mnemonic),void 0!==t.activeIndexes&&t.activeIndexes.length>0&&this.activateAccounts([...t.activeIndexes]))}get hdPath(){return this._hdPath}static generate(r=e.MnemonicStrength.MAXIMUM,i="",n=t.networks.bitcoin,s=e.MLDSASecurityLevel.LEVEL2){const a=e.Mnemonic.generate(r,i,n,s),o=new p({network:n,securityLevel:s,passphrase:i});return o.mnemonic=a,o}initFromMnemonic(t){if(null!==this.mnemonic)throw new Error("HdKeyring: Mnemonic already initialized");this.mnemonic=new e.Mnemonic(t,this.passphrase,this.network,this.securityLevel)}getMnemonic(){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");return this.mnemonic.phrase}hasMnemonic(){return null!==this.mnemonic}deriveWallet(e){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const r=this.wallets.get(e);if(void 0!==r)return r;let i;if(this.isCustomHdPath()){const r=`${this._hdPath}/${e}`,n=`m/360'/${this.network===t.networks.bitcoin?0:1}'/0'/0/${e}`;i=this.mnemonic.deriveCustomPath(r,n)}else i=this.mnemonic.deriveOPWallet(this.addressType,e);return this.wallets.set(e,i),i}deriveStandardWallet(e){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");return this.mnemonic.derive(e)}addAccounts(e=1){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const t=[];let r=0;for(;t.length<e;){if(!this.activeIndexes.includes(r)){const e=this.deriveWallet(r);this.activeIndexes.push(r),t.push(e.toPublicKeyHex())}r++}return t}activateAccounts(e){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const t=[];for(const r of e)if(this.activeIndexes.includes(r)){const e=this.wallets.get(r);void 0!==e&&t.push(e.toPublicKeyHex())}else{const e=this.deriveWallet(r);this.activeIndexes.push(r),t.push(e.toPublicKeyHex())}return t}getAccounts(){return this.activeIndexes.map(e=>{const t=this.wallets.get(e);if(void 0===t)throw new Error(`HdKeyring: Wallet at index ${e} not found`);return t.toPublicKeyHex()})}getAccountsInfo(){return this.activeIndexes.map(e=>{const t=this.wallets.get(e);if(void 0===t)throw new Error(`HdKeyring: Wallet at index ${e} not found`);const r={p2pkh:t.legacy,p2wpkh:t.p2wpkh,p2tr:t.p2tr,p2shP2wpkh:t.segwitLegacy};return{index:e,publicKey:t.toPublicKeyHex(),quantumPublicKey:t.quantumPublicKeyHex,addresses:r}})}getQuantumPublicKey(e){return this.findWalletByPublicKey(e).quantumPublicKeyHex}getIndexByPublicKey(e){for(const[t,r]of this.wallets.entries())if(r.toPublicKeyHex()===e)return t;return null}getAddressesForPublicKey(e){const t=this.findWalletByPublicKey(e);return{p2pkh:t.legacy,p2wpkh:t.p2wpkh,p2tr:t.p2tr,p2shP2wpkh:t.segwitLegacy}}getAddress(e,t){return o(r.fromHexInternal(e),t,this.network)}removeAccount(e){const t=this.getIndexByPublicKey(e);if(null===t)throw new Error(`HdKeyring: Account with public key ${e} not found`);const r=this.activeIndexes.indexOf(t);-1!==r&&this.activeIndexes.splice(r,1),this.wallets.delete(t)}exportAccount(e){return this.findWalletByPublicKey(e).toPrivateKeyHex()}signTransaction(e,i){for(const n of i){const i=this.findWalletByPublicKey(n.publicKey),s=e.data.inputs[n.index];if(void 0===s)throw new Error(`HdKeyring: Input at index ${n.index} not found`);const a=i.keypair,o=void 0!==n.sighashTypes?[...n.sighashTypes]:void 0;if(t.isTaprootInput(s)&&!0!==n.disableTweakSigner){const t=i.publicKey.subarray(1,33),s=a.tweak(r.createBytes32(t));e.signInput(n.index,s,o)}else e.signInput(n.index,a,o)}return e}signData(e,t,i="ecdsa"){const n=this.findWalletByPublicKey(e),s=r.createMessageHash(r.fromHexInternal(t));if("ecdsa"===i)return r.toHex(n.keypair.sign(s));if(void 0===n.keypair.signSchnorr)throw new Error("HdKeyring: Schnorr signing not supported by this keypair");return r.toHex(n.keypair.signSchnorr(s))}getWallet(e){return this.findWalletByPublicKey(e)}serialize(){return{mnemonic:this.mnemonic?.phrase,passphrase:this.passphrase,network:this.network,securityLevel:this.securityLevel,activeIndexes:[...this.activeIndexes],addressType:this.addressType,hdPath:this._hdPath}}getActiveIndexes(){return[...this.activeIndexes]}setAddressType(e){this.addressType=e}getAddressType(){return this.addressType}getSecurityLevel(){return this.securityLevel}getNetwork(){return this.network}getAddressesPage(e,r=5){if(null===this.mnemonic)throw new Error("HdKeyring: No mnemonic initialized");const i=e*r,n=i+r,s=[];for(let a=i;a<n;a++){let e;if(this.isCustomHdPath()){const r=`${this._hdPath}/${a}`,i=`m/360'/${this.network===t.networks.bitcoin?0:1}'/0'/0/${a}`;e=this.mnemonic.deriveCustomPath(r,i)}else e=this.mnemonic.deriveOPWallet(this.addressType,a);const r=this.getAddressFromWallet(e);s.push({address:r,index:a})}return s}getChainCode(e){const t=this.findWalletByPublicKey(e);return Uint8Array.from(t.chainCode)}getMLDSAKeypair(e){return this.findWalletByPublicKey(e).mldsaKeypair}isCustomHdPath(){const t={[e.AddressTypes.P2PKH]:"m/44'/0'/0'/0",[e.AddressTypes.P2WPKH]:"m/84'/0'/0'/0",[e.AddressTypes.P2TR]:"m/86'/0'/0'/0",[e.AddressTypes.P2SH_OR_P2SH_P2WPKH]:"m/49'/0'/0'/0"}[this.addressType];if(void 0===t)return""!==this._hdPath;const r=t.slice(0,-2);return!this._hdPath.includes(r)&&""!==this._hdPath}findWalletByPublicKey(e){for(const t of this.wallets.values())if(t.toPublicKeyHex()===e)return t;throw new Error(`HdKeyring: Wallet with public key ${e} not found`)}getAddressFromWallet(t){switch(this.addressType){case e.AddressTypes.P2PKH:return t.legacy;case e.AddressTypes.P2WPKH:return t.p2wpkh;case e.AddressTypes.P2TR:return t.p2tr;case e.AddressTypes.P2SH_OR_P2SH_P2WPKH:return t.segwitLegacy;default:return t.p2tr}}}class d{static type="Simple Key Pair";type=d.type;network;securityLevel;keypair=null;quantumKeypair=null;chainCode=new Uint8Array(32);constructor(t){if(!t?.network)throw new Error("SimpleKeyring: Network option is required");this.network=t.network,this.securityLevel=t?.securityLevel??e.MLDSASecurityLevel.LEVEL2,void 0!==t?.privateKey&&this.importPrivateKey(t.privateKey,t.quantumPrivateKey)}static generate(r=t.networks.bitcoin,i=e.MLDSASecurityLevel.LEVEL2){const n=new d({network:r,securityLevel:i,privateKey:""});n.keypair=e.EcKeyPair.generateRandomKeyPair(r);const s=crypto.getRandomValues(new Uint8Array(64));return n.quantumKeypair=e.QuantumBIP32Factory.fromSeed(s,r,i),n.chainCode=Uint8Array.from(n.quantumKeypair.chainCode),n}static fromWIF(r,i,n=t.networks.bitcoin,s=e.MLDSASecurityLevel.LEVEL2){const a=new d({network:n,securityLevel:s,privateKey:""});return a.keypair=e.EcKeyPair.fromWIF(r,n),void 0!==i&&""!==i&&a.importQuantumKey(i),a}static fromPrivateKey(i,n,s=t.networks.bitcoin,a=e.MLDSASecurityLevel.LEVEL2){const o=new d({network:s,securityLevel:a,privateKey:""});return o.keypair=e.EcKeyPair.fromPrivateKey(r.fromHexInternal(i),s),void 0!==n&&""!==n&&o.importQuantumKey(n),o}importPrivateKey(t,i){""!==t&&(64===t.length?this.keypair=e.EcKeyPair.fromPrivateKey(r.fromHexInternal(t),this.network):this.keypair=e.EcKeyPair.fromWIF(t,this.network),void 0!==i&&""!==i&&this.importQuantumKey(i))}importQuantumKey(t){const n=r.fromHexInternal(t),s=i.getMLDSAConfig(this.securityLevel,this.network).privateKeySize,a=s+32,o=n.length===a,u=n.length===s;if(!o&&!u)throw new Error(`Invalid quantum key length: ${n.length} bytes. Expected ${s} bytes (key only) or ${a} bytes (key + chaincode).`);if(o){this.chainCode=n.slice(-32);const t=n.slice(0,-32);this.quantumKeypair=e.QuantumBIP32Factory.fromPrivateKey(t,this.chainCode,this.network,this.securityLevel)}else this.chainCode=crypto.getRandomValues(new Uint8Array(32)),this.quantumKeypair=e.QuantumBIP32Factory.fromPrivateKey(n,this.chainCode,this.network,this.securityLevel)}generateFreshQuantumKey(){const t=crypto.getRandomValues(new Uint8Array(64));this.quantumKeypair=e.QuantumBIP32Factory.fromSeed(t,this.network,this.securityLevel),this.chainCode=Uint8Array.from(this.quantumKeypair.chainCode)}hasKeys(){return null!==this.keypair&&null!==this.quantumKeypair}hasClassicalKey(){return null!==this.keypair}hasQuantumKey(){return null!==this.quantumKeypair}needsQuantumMigration(){return null!==this.keypair&&null===this.quantumKeypair}getPublicKey(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return r.toHex(this.keypair.publicKey)}getQuantumPublicKey(){if(null===this.quantumKeypair)throw new Error("SimpleKeyring: No quantum keypair initialized");return r.toHex(this.quantumKeypair.publicKey)}getQuantumPublicKeyOrUndefined(){if(null!==this.quantumKeypair)return r.toHex(this.quantumKeypair.publicKey)}getQuantumPublicKeyHash(){if(null===this.quantumKeypair)throw new Error("SimpleKeyring: No quantum keypair initialized");const e=t.crypto.sha256(this.quantumKeypair.publicKey);return r.toHex(e)}clearQuantumKey(){this.quantumKeypair=null,this.chainCode=new Uint8Array(32)}getAccounts(){return null===this.keypair?[]:[this.getPublicKey()]}getAddresses(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");const t=this.keypair.publicKey;return{p2pkh:o(t,e.AddressTypes.P2PKH,this.network),p2wpkh:o(t,e.AddressTypes.P2WPKH,this.network),p2tr:o(t,e.AddressTypes.P2TR,this.network),p2shP2wpkh:o(t,e.AddressTypes.P2SH_OR_P2SH_P2WPKH,this.network)}}getAddress(e){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return o(this.keypair.publicKey,e,this.network)}exportPrivateKey(){if(void 0===this.keypair?.privateKey)throw new Error("SimpleKeyring: No private key available");return r.toHex(this.keypair.privateKey)}exportQuantumPrivateKey(){if(void 0===this.quantumKeypair?.privateKey)throw new Error("SimpleKeyring: No quantum private key available");return r.toHex(r.concatBytes(this.quantumKeypair.privateKey,this.chainCode))}exportRawQuantumPrivateKey(){if(void 0===this.quantumKeypair?.privateKey)throw new Error("SimpleKeyring: No quantum private key available");return r.toHex(this.quantumKeypair.privateKey)}exportChainCode(){return this.chainCode}exportWIF(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return this.keypair.toWIF()}signTransaction(e,i){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");for(const n of i){const i=e.data.inputs[n.index];if(void 0===i)throw new Error(`SimpleKeyring: Input at index ${n.index} not found`);if(t.isTaprootInput(i)&&!0!==n.disableTweakSigner){const t=this.keypair.tweak(r.createBytes32(this.keypair.publicKey.subarray(1,33)));e.signInput(n.index,t,n.sighashTypes?[...n.sighashTypes]:void 0)}else e.signInput(n.index,this.keypair,n.sighashTypes?[...n.sighashTypes]:void 0)}return e}signData(e,t="ecdsa"){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");const i=r.createMessageHash(r.fromHexInternal(e));if("ecdsa"===t)return r.toHex(this.keypair.sign(i));if(void 0===this.keypair.signSchnorr)throw new Error("SimpleKeyring: Schnorr signing not supported by this keypair");return r.toHex(this.keypair.signSchnorr(i))}verify(e,t,i="ecdsa"){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");const n=r.createMessageHash(r.fromHexInternal(e));return"ecdsa"===i?this.keypair.verify(n,r.createSignature(r.fromHexInternal(t))):this.keypair.verifySchnorr(n,r.createSchnorrSignature(r.fromHexInternal(t)))}getKeypair(){if(null===this.keypair)throw new Error("SimpleKeyring: No keypair initialized");return this.keypair}getQuantumKeypair(){if(null===this.quantumKeypair)throw new Error("SimpleKeyring: No quantum keypair initialized");return this.quantumKeypair}getChainCode(){return this.chainCode}getSecurityLevel(){return this.securityLevel}getNetwork(){return this.network}serialize(){let e;try{e=this.exportQuantumPrivateKey()}catch{e=void 0}return{privateKey:this.exportPrivateKey(),quantumPrivateKey:e,network:this.network,securityLevel:this.securityLevel}}clear(){this.keypair=null,this.quantumKeypair=null,this.chainCode=new Uint8Array(32)}}const h="OPNET_WALLET_V1",g=new TextEncoder;function w(e){const i=t.crypto.sha256(g.encode(e));return r.toHex(i.subarray(0,4))}function m(e){return s(e)}function f(e,t,i,n,s,a,o){const u={magic:h,version:1,network:m(o),classical:{privateKey:r.toHex(e),publicKey:r.toHex(t)},quantum:{privateKey:r.toHex(i),publicKey:r.toHex(n),securityLevel:a,chainCode:r.toHex(s)}},c=w(JSON.stringify(u));return{...u,checksum:c}}function k(i){if(i.magic!==h)throw new Error("Invalid wallet export format: wrong magic header");if(1!==i.version)throw new Error(`Unsupported wallet export version: ${i.version}`);const s={magic:i.magic,version:i.version,network:i.network,classical:i.classical,quantum:i.quantum},a=w(JSON.stringify(s));if(i.checksum!==a)throw new Error("Invalid wallet export: checksum mismatch");const o=function(r){const i=r;return Object.values(e.WalletNetworks).includes(i)?n(i):t.networks.bitcoin}(i.network),u=r.fromHexInternal(i.quantum.chainCode),c=r.fromHexInternal(i.classical.privateKey),y=e.EcKeyPair.fromPrivateKey(c,o),l=r.fromHexInternal(i.quantum.privateKey);return{keypair:y,quantumKeypair:e.QuantumBIP32Factory.fromPrivateKey(l,u,o,i.quantum.securityLevel),network:o,securityLevel:i.quantum.securityLevel,chainCode:u}}function K(e){const t=JSON.stringify(e);return btoa(t)}function v(e){try{const t=atob(e);return JSON.parse(t)}catch{throw new Error("Invalid wallet export: failed to deserialize")}}let P;function x(){return P??=r.createNobleBackend(),P}function b(t,r){const i=e.MessageSigner.signMLDSAMessage(t,r);return{message:i.message,signature:i.signature,publicKey:i.publicKey,securityLevel:i.securityLevel}}function T(t,r,i,n,s,a){const o=e.QuantumBIP32Factory.fromPublicKey(t,r,i,n);return e.MessageSigner.verifyMLDSASignature(o,s,a)}function S(t,r){const i=e.MessageSigner.signMessage(t,r);return{message:i.message,signature:i.signature,publicKey:t.publicKey}}function H(t,r,i){return e.MessageSigner.verifySignature(t,r,i)}function A(e){return"securityLevel"in e&&"chainCode"in e}const W=new TextEncoder;function I(e){return"string"==typeof e?W.encode(e):e}const E=new TextEncoder,L=t.toSatoshi(0n);function q(e){const t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r}const N=[e.AddressTypes.P2WPKH,e.AddressTypes.P2TR];function M(e){const r=t.crypto.sha256(E.encode("BIP0322-signed-message")),i="string"==typeof e?E.encode(e):e;return t.crypto.sha256(t.concat([r,r,i]))}function C(e,r,i){const n=t.address.toOutputScript(r,i),s=l(r,i);if(null===s||!N.includes(s))throw new Error(`BIP322: Address type not supported for signing. Got: ${String(s)}`);const a=M(e),o=t.alloc(32),u=t.concat([t.fromHex("0020"),a]),c=new t.Transaction;c.version=0,c.addInput(o,4294967295,0,u),c.addOutput(n,L);const y=new t.Psbt({network:i});return y.setVersion(0),y.addInput({hash:c.getHash(),index:0,sequence:0,witnessUtxo:{script:n,value:L}}),y.addOutput({script:t.fromHex("6a"),value:L}),y}function O(e){const r=e.extractTransaction(),i=r.ins[0]?.witness;if(void 0===i||0===i.length)throw new Error("BIP322: No witness data found in signed transaction");const n=t.script.number.encode(i.length);return function(e){let t="";for(const r of e)t+=String.fromCharCode(r);return btoa(t)}(t.concat([n,...i.map(e=>function(e){const r=t.script.number.encode(e.length);return t.concat([r,e])}(e))]))}async function F(e,t,r,i){const n=C(e,t,r),s=await i(n);return s.finalizeAllInputs(),O(s)}const B=(e,i,n)=>{try{const s=t.script.signature.decode(n);return x().verify(r.createMessageHash(i),r.createPublicKey(e),r.createSignature(s.signature))}catch{return!1}};function Q(e,i,n,s){try{const a=t.address.toOutputScript(e,s),o=M(i),u=t.alloc(32),c=4294967295,y=0,l=t.concat([t.fromHex("0020"),o]),p=new t.Transaction;p.version=0,p.addInput(u,c,y,l),p.addOutput(a,L);const d=q(n),h=t.script.decompile(d.subarray(1));if(!Array.isArray(h)||0===h.length)return!1;const g=h[0];if(!(g instanceof Uint8Array))return!1;const w=t.concat([t.fromHex("02"),a.subarray(2)]),m=new t.Psbt({network:s});m.setVersion(0),m.addInput({hash:p.getHash(),index:0,sequence:0,witnessUtxo:{script:a,value:L}}),m.addOutput({script:t.fromHex("6a"),value:L});const f=m.data.globalMap.unsignedTx.tx;return function(e,t,i){try{const n=33===e.length?e.subarray(1,33):e;return x().verifySchnorr(r.createMessageHash(t),r.createXOnlyPublicKey(n),r.createSchnorrSignature(i))}catch{return!1}}(w,f.hashForWitnessV1(0,[a],[L],t.Transaction.SIGHASH_DEFAULT),g)}catch{return!1}}function R(r,i,n,s){const a=l(r,s);if(null===a)return!1;switch(a){case e.AddressTypes.P2TR:return Q(r,i,n,s);case e.AddressTypes.P2WPKH:return function(e,r,i,n){try{const s=t.address.toOutputScript(e,n),a=M(r),o=t.alloc(32),u=4294967295,c=0,y=t.concat([t.fromHex("0020"),a]),l=new t.Transaction;l.version=0,l.addInput(o,u,c,y),l.addOutput(s,L);const p=q(i),d=t.script.decompile(p.subarray(1));if(!Array.isArray(d)||d.length<2)return!1;const h=d[0],g=d[1];if(!(h instanceof Uint8Array&&g instanceof Uint8Array))return!1;const w=new t.Psbt({network:n});return w.setVersion(0),w.addInput({hash:l.getHash(),index:0,sequence:0,witnessUtxo:{script:s,value:L}}),w.addOutput({script:t.fromHex("6a"),value:L}),w.updateInput(0,{partialSig:[{pubkey:g,signature:h}]}),w.validateSignaturesOfAllInputs(B)}catch{return!1}}(r,i,n,s);default:return!1}}class z{keyring;network;addressType;publicKey;address;constructor(e,t,i,n){this.keyring=e,this.network=t,this.addressType=i,this.publicKey=n,this.address=o(r.fromHexInternal(n),i,t)}static fromWIF(t,r=e.AddressTypes.P2TR,i,n){const s=d.fromWIF(t,n,i),a=s.getPublicKey();return new z(s,i,r,a)}static fromPrivateKey(t,r=e.AddressTypes.P2TR,i,n){const s=d.fromPrivateKey(t,n,i),a=s.getPublicKey();return new z(s,i,r,a)}static fromMnemonic(t,r=e.AddressTypes.P2TR,i,n,s=0){const a=new p({mnemonic:t,passphrase:n,network:i,addressType:r,activeIndexes:[s]}),o=a.getAccounts()[0];if(void 0===o)throw new Error("Failed to derive wallet from mnemonic");return new z(a,i,r,o)}static random(r=e.AddressTypes.P2TR,i=t.networks.bitcoin){const n=d.generate(i),s=n.getPublicKey();return new z(n,i,r,s)}getAddress(){return this.address}getPublicKey(){return this.publicKey}getQuantumPublicKey(){return this.keyring instanceof d?this.keyring.getQuantumPublicKey():this.keyring.getQuantumPublicKey(this.publicKey)}getNetwork(){return this.network}getAddressType(){return this.addressType}signPsbt(i,n){const s=n??{autoFinalized:!0,toSignInputs:[]},a=this.formatInputsToSign(i,s);if(0===a.length)throw new Error("LocalWallet: No inputs to sign");for(const o of a){const n=i.data.inputs[o.index];if(void 0===n)continue;const s=!(n.finalScriptSig??n.finalScriptWitness),a=this.addressType===e.AddressTypes.P2TR,u=void 0===n.tapInternalKey;if(s&&a&&u){const e=r.fromHexInternal(this.publicKey),i=33===e.length?e.subarray(1,33):e,s=r.createXOnlyPublicKey(i),{output:a}=t.payments.p2tr({internalPubkey:s,network:this.network});void 0!==a&&void 0!==n.witnessUtxo&&t.equals(n.witnessUtxo.script,a)&&(n.tapInternalKey=s)}}if(this.keyring,this.keyring.signTransaction(i,a),!0===s.autoFinalized)for(const e of a)i.finalizeInput(e.index);return i}async signMessage(e,t){switch(t){case"bip322-simple":return await F(e,this.address,this.network,e=>Promise.resolve(this.signPsbt(e,{autoFinalized:!1})));case"ecdsa":case"schnorr":{const t=S(this.getKeypair(),e);return r.toHex(t.signature)}case"mldsa":{const t=b(this.getQuantumKeypair(),e);return r.toHex(t.signature)}}}signData(e,t="ecdsa"){return this.keyring instanceof d?this.keyring.signData(e,t):this.keyring.signData(this.publicKey,e,t)}exportPrivateKey(){return this.keyring instanceof d?this.keyring.exportPrivateKey():this.keyring.exportAccount(this.publicKey)}exportQuantumPrivateKey(){if(this.keyring instanceof d)return this.keyring.exportQuantumPrivateKey();const e=this.keyring.getWallet(this.publicKey),t=e.mldsaKeypair.privateKey;if(void 0===t)throw new Error("LocalWallet: No quantum private key available");return r.toHex(r.concatBytes(t,e.chainCode))}exportRawQuantumPrivateKey(){if(this.keyring instanceof d)return this.keyring.exportRawQuantumPrivateKey();const e=this.keyring.getWallet(this.publicKey).mldsaKeypair.privateKey;if(void 0===e)throw new Error("LocalWallet: No quantum private key available");return r.toHex(e)}exportChainCode(){return this.keyring instanceof d?this.keyring.exportChainCode():this.keyring.getChainCode(this.publicKey)}exportWIF(){if(this.keyring instanceof d)return this.keyring.exportWIF();throw new Error("LocalWallet: Cannot export WIF from HD keyring directly")}getKeypair(){return this.keyring instanceof d?this.keyring.getKeypair():this.keyring.getWallet(this.publicKey).keypair}getQuantumKeypair(){return this.keyring instanceof d?this.keyring.getQuantumKeypair():this.keyring.getMLDSAKeypair(this.publicKey)}formatInputsToSign(e,r){const i=[];if(void 0!==r.toSignInputs&&r.toSignInputs.length>0)for(const t of r.toSignInputs){const e=t.index;if("address"in t){if(t.address!==this.address)throw new Error(`LocalWallet: Address mismatch at input ${e}`)}else if("publicKey"in t&&t.publicKey!==this.publicKey)throw new Error(`LocalWallet: Public key mismatch at input ${e}`);const r={index:e,publicKey:this.publicKey};void 0!==t.sighashTypes&&(r.sighashTypes=t.sighashTypes),void 0!==t.disableTweakSigner&&(r.disableTweakSigner=t.disableTweakSigner),i.push(r)}else for(let n=0;n<e.data.inputs.length;n++){const r=e.data.inputs[n];if(void 0===r)continue;let s;if(void 0!==r.witnessUtxo)s=r.witnessUtxo.script;else if(void 0!==r.nonWitnessUtxo){const i=e.txInputs[n];if(void 0!==i){const e=t.Transaction.fromBuffer(r.nonWitnessUtxo).outs[i.index];s=e?.script}}const a=r.finalScriptSig??r.finalScriptWitness;if(void 0!==s&&void 0===a){if(c(s,this.network)===this.address){const e={index:n,publicKey:this.publicKey};void 0!==r.sighashType&&(e.sighashTypes=[r.sighashType]),i.push(e)}}}return i}}exports.HdKeyring=p,exports.LocalWallet=z,exports.SimpleKeyring=d,exports.addressToScriptPubKey=function(e,r){return t.address.toOutputScript(e,r)},exports.decodeAddress=function(r){const i=[{network:t.networks.bitcoin,networkType:e.WalletNetworks.Mainnet},{network:t.networks.opnetTestnet,networkType:e.WalletNetworks.OpnetTestnet},{network:t.networks.testnet,networkType:e.WalletNetworks.Testnet},{network:t.networks.regtest,networkType:e.WalletNetworks.Regtest}];for(const{network:e,networkType:n}of i)try{const i=t.address.toOutputScript(r,e),s=l(r,e);if(null!==s)return{networkType:n,addressType:s,scriptPubKey:i}}catch{}return null},exports.deserializeExport=v,exports.detectAddressType=l,exports.detectNetworkFromAddress=a,exports.exportWallet=f,exports.exportWalletToString=function(e,t,r,i,n,s,a){return K(f(e,t,r,i,n,s,a))},exports.extractBip322Signature=O,exports.fromLegacyExport=function(t,i){const n=r.fromHexInternal(t.classicalPrivateKey),s=e.EcKeyPair.fromPrivateKey(n,i),a={magic:h,version:1,network:m(i),classical:{privateKey:t.classicalPrivateKey,publicKey:r.toHex(s.publicKey)},quantum:{privateKey:t.quantumPrivateKey,publicKey:t.quantumPublicKey,securityLevel:t.securityLevel,chainCode:t.chainCode}},o=w(JSON.stringify(a));return{...a,checksum:o}},exports.generateBip322Psbt=C,exports.getAddressType=function(e,t){return l(e,n(t))},exports.getBech32Prefix=function(e){return n(e).bech32},exports.getNobleBackend=x,exports.importWallet=k,exports.importWalletFromString=function(e){return k(v(e))},exports.isAddressSignInput=function(e){return"address"in e},exports.isP2PKHOrP2SHAddress=function(t,r){return e.AddressVerificator.isP2PKHOrP2SH(t,r)},exports.isP2WPKHAddress=function(t,r){return e.AddressVerificator.isP2WPKHAddress(t,r)},exports.isPublicKeySignInput=function(e){return"publicKey"in e},exports.isValidAddress=y,exports.isValidAddressForNetworkType=function(e,t){return y(e,n(t))},exports.isValidP2TRAddress=function(t,r){return e.AddressVerificator.isValidP2TRAddress(t,r)},exports.isValidPublicKey=function(r,i){const n="string"==typeof r?r:t.toHex(r);return e.AddressVerificator.isValidPublicKey(n,i)},exports.publicKeyToAddress=o,exports.publicKeyToAddressWithNetworkType=function(e,t,r){return o(e,t,n(r))},exports.publicKeyToPayment=u,exports.publicKeyToScriptPubKey=function(e,t,r){const i=u(e,t,r);if(!i.output)throw new Error("Failed to generate script pubkey");return i.output},exports.scriptPubKeyToAddress=c,exports.serializeExport=K,exports.signBip322Message=F,exports.signBip322MessageWithNetworkType=async function(e,t,r,i){const s=n(r);return{address:t,message:e,signature:await F(e,t,s,i),networkType:r}},exports.signMLDSA=b,exports.signMessage=function(t,i,n){const s=I(i);switch(n){case"mldsa":{if(!A(t))throw new Error("ML-DSA signing requires a quantum keypair");const e=b(t,i);return{message:s,signature:e.signature,publicKey:e.publicKey,signatureType:"mldsa",securityLevel:e.securityLevel}}case"schnorr":{if(A(t))throw new Error("Schnorr signing requires a classical keypair");const e=S(t,i);return{message:s,signature:e.signature,publicKey:e.publicKey,signatureType:"schnorr"}}case"ecdsa":{if(A(t))throw new Error("ECDSA signing requires a classical keypair");const i=e.MessageSigner.sha256(s);return{message:s,signature:t.sign(r.createMessageHash(i)),publicKey:t.publicKey,signatureType:"ecdsa"}}}},exports.signSchnorr=S,exports.signTweakedSchnorr=function(r,i,n=t.networks.bitcoin){const s=e.MessageSigner.tweakAndSignMessage(r,i,n);return{message:s.message,signature:s.signature,publicKey:r.publicKey}},exports.toNetwork=n,exports.toNetworkType=s,exports.validateAddressNetwork=function(e,t){return a(e)===t},exports.validateExport=function(e){try{if(e.magic!==h)return!1;if(1!==e.version)return!1;const t={magic:e.magic,version:e.version,network:e.network,classical:e.classical,quantum:e.quantum},r=w(JSON.stringify(t));return e.checksum===r}catch{return!1}},exports.verifyBip322Message=R,exports.verifyBip322MessageWithNetworkType=function(e,t,r,i){return R(e,t,r,n(i))},exports.verifyMLDSA=T,exports.verifyMLDSAWithKeypair=function(t,r,i){return e.MessageSigner.verifyMLDSASignature(t,r,i)},exports.verifyMessage=function(t,i,n,s,a,o,u){switch(s){case"mldsa":if(void 0===a||void 0===o||void 0===u)throw new Error("ML-DSA verification requires chainCode, network, and securityLevel");return T(t,a,o,u,i,n);case"schnorr":return H(t,i,n);case"ecdsa":{const s=I(i),a=e.MessageSigner.sha256(s);return x().verify(r.createMessageHash(a),r.createPublicKey(t),r.createSignature(n))}}},exports.verifySchnorr=H,exports.verifyTweakedSchnorr=function(t,r,i){return e.MessageSigner.tweakAndVerifySignature(t,r,i)};
2
2
  //# sourceMappingURL=index.cjs.js.map