@omnity/ree-client-ts-sdk 0.1.1

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.
@@ -0,0 +1,146 @@
1
+ (function(Ie,nt){typeof exports=="object"&&typeof module<"u"?nt(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],nt):(Ie=typeof globalThis<"u"?globalThis:Ie||self,nt(Ie["ree-sdk"]={},Ie.React,Ie.React))})(this,(function(Ie,nt,ye){"use strict";var uy=Ie=>{throw TypeError(Ie)};var fy=(Ie,nt,ye)=>nt.has(Ie)||uy("Cannot "+ye);var Ce=(Ie,nt,ye)=>(fy(Ie,nt,"read from private field"),ye?ye.call(Ie):nt.get(Ie)),Kt=(Ie,nt,ye)=>nt.has(Ie)?uy("Cannot add the same private member more than once"):nt instanceof WeakSet?nt.add(Ie):nt.set(Ie,ye),Ht=(Ie,nt,ye,oi)=>(fy(Ie,nt,"write to private field"),oi?oi.call(Ie,ye):nt.set(Ie,ye),ye);var ly=(Ie,nt,ye,oi)=>({set _(Hc){Ht(Ie,nt,Hc,ye)},get _(){return Ce(Ie,nt,oi)}});var Tt,Ki,Zs,Js,gn,Qs,eo,to,no,ro,io,so,Gi;function oi(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function Hc(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fc={},Rt={},An={},lf;function cn(){return lf||(lf=1,Object.defineProperty(An,"__esModule",{value:!0}),An.testnet=An.regtest=An.bitcoin=void 0,An.bitcoin={messagePrefix:`Bitcoin Signed Message:
2
+ `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},An.regtest={messagePrefix:`Bitcoin Signed Message:
3
+ `,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},An.testnet={messagePrefix:`Bitcoin Signed Message:
4
+ `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}),An}var qc={},Xi={},Mc={},In={},df;function hf(){if(df)return In;df=1,Object.defineProperty(In,"__esModule",{value:!0}),In.encode=In.decode=In.check=void 0;function e(r){if(r.length<8||r.length>72||r[0]!==48||r[1]!==r.length-2||r[2]!==2)return!1;const i=r[3];if(i===0||5+i>=r.length||r[4+i]!==2)return!1;const s=r[5+i];return!(s===0||6+i+s!==r.length||r[4]&128||i>1&&r[4]===0&&!(r[5]&128)||r[i+6]&128||s>1&&r[i+6]===0&&!(r[i+7]&128))}In.check=e;function t(r){if(r.length<8)throw new Error("DER sequence length is too short");if(r.length>72)throw new Error("DER sequence length is too long");if(r[0]!==48)throw new Error("Expected DER sequence");if(r[1]!==r.length-2)throw new Error("DER sequence length is invalid");if(r[2]!==2)throw new Error("Expected DER integer");const i=r[3];if(i===0)throw new Error("R length is zero");if(5+i>=r.length)throw new Error("R length is too long");if(r[4+i]!==2)throw new Error("Expected DER integer (2)");const s=r[5+i];if(s===0)throw new Error("S length is zero");if(6+i+s!==r.length)throw new Error("S length is invalid");if(r[4]&128)throw new Error("R value is negative");if(i>1&&r[4]===0&&!(r[5]&128))throw new Error("R value excessively padded");if(r[i+6]&128)throw new Error("S value is negative");if(s>1&&r[i+6]===0&&!(r[i+7]&128))throw new Error("S value excessively padded");return{r:r.slice(4,4+i),s:r.slice(6+i)}}In.decode=t;function n(r,i){const s=r.length,o=i.length;if(s===0)throw new Error("R length is zero");if(o===0)throw new Error("S length is zero");if(s>33)throw new Error("R length is too long");if(o>33)throw new Error("S length is too long");if(r[0]&128)throw new Error("R value is negative");if(i[0]&128)throw new Error("S value is negative");if(s>1&&r[0]===0&&!(r[1]&128))throw new Error("R value excessively padded");if(o>1&&i[0]===0&&!(i[1]&128))throw new Error("S value excessively padded");const c=Buffer.allocUnsafe(6+s+o);return c[0]=48,c[1]=c.length-2,c[2]=2,c[3]=r.length,r.copy(c,4),c[4+s]=2,c[5+s]=i.length,i.copy(c,6+s),c}return In.encode=n,In}var vr={},pf;function Lc(){if(pf)return vr;pf=1,Object.defineProperty(vr,"__esModule",{value:!0}),vr.REVERSE_OPS=vr.OPS=void 0;const e={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};vr.OPS=e;const t={};vr.REVERSE_OPS=t;for(const n of Object.keys(e)){const r=e[n];t[r]=n}return vr}var On={},yf;function hy(){if(yf)return On;yf=1,Object.defineProperty(On,"__esModule",{value:!0}),On.decode=On.encode=On.encodingLength=void 0;const e=Lc();function t(i){return i<e.OPS.OP_PUSHDATA1?1:i<=255?2:i<=65535?3:5}On.encodingLength=t;function n(i,s,o){const c=t(s);return c===1?i.writeUInt8(s,o):c===2?(i.writeUInt8(e.OPS.OP_PUSHDATA1,o),i.writeUInt8(s,o+1)):c===3?(i.writeUInt8(e.OPS.OP_PUSHDATA2,o),i.writeUInt16LE(s,o+1)):(i.writeUInt8(e.OPS.OP_PUSHDATA4,o),i.writeUInt32LE(s,o+1)),c}On.encode=n;function r(i,s){const o=i.readUInt8(s);let c,a;if(o<e.OPS.OP_PUSHDATA1)c=o,a=1;else if(o===e.OPS.OP_PUSHDATA1){if(s+2>i.length)return null;c=i.readUInt8(s+1),a=2}else if(o===e.OPS.OP_PUSHDATA2){if(s+3>i.length)return null;c=i.readUInt16LE(s+1),a=3}else{if(s+5>i.length)return null;if(o!==e.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");c=i.readUInt32LE(s+1),a=5}return{opcode:o,number:c,size:a}}return On.decode=r,On}var Br={},mf;function py(){if(mf)return Br;mf=1,Object.defineProperty(Br,"__esModule",{value:!0}),Br.encode=Br.decode=void 0;function e(r,i,s){i=i||4,s=s===void 0?!0:s;const o=r.length;if(o===0)return 0;if(o>i)throw new TypeError("Script number overflow");if(s&&(r[o-1]&127)===0&&(o<=1||(r[o-2]&128)===0))throw new Error("Non-minimally encoded script number");if(o===5){const a=r.readUInt32LE(0),u=r.readUInt8(4);return u&128?-((u&-129)*4294967296+a):u*4294967296+a}let c=0;for(let a=0;a<o;++a)c|=r[a]<<8*a;return r[o-1]&128?-(c&~(128<<8*(o-1))):c}Br.decode=e;function t(r){return r>2147483647?5:r>8388607?4:r>32767?3:r>127?2:r>0?1:0}function n(r){let i=Math.abs(r);const s=t(i),o=Buffer.allocUnsafe(s),c=r<0;for(let a=0;a<s;++a)o.writeUInt8(i&255,a),i>>=8;return o[s-1]&128?o.writeUInt8(c?128:0,s-1):c&&(o[s-1]|=128),o}return Br.encode=n,Br}var Ar={},Vc={},Dc={},zi={},gf;function yy(){if(gf)return zi;gf=1,zi.byteLength=c,zi.toByteArray=u,zi.fromByteArray=y;for(var e=[],t=[],n=typeof Uint8Array<"u"?Uint8Array:Array,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,s=r.length;i<s;++i)e[i]=r[i],t[r.charCodeAt(i)]=i;t[45]=62,t[95]=63;function o(p){var m=p.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var g=p.indexOf("=");g===-1&&(g=m);var E=g===m?0:4-g%4;return[g,E]}function c(p){var m=o(p),g=m[0],E=m[1];return(g+E)*3/4-E}function a(p,m,g){return(m+g)*3/4-g}function u(p){var m,g=o(p),E=g[0],x=g[1],_=new n(a(p,E,x)),w=0,T=x>0?E-4:E,R;for(R=0;R<T;R+=4)m=t[p.charCodeAt(R)]<<18|t[p.charCodeAt(R+1)]<<12|t[p.charCodeAt(R+2)]<<6|t[p.charCodeAt(R+3)],_[w++]=m>>16&255,_[w++]=m>>8&255,_[w++]=m&255;return x===2&&(m=t[p.charCodeAt(R)]<<2|t[p.charCodeAt(R+1)]>>4,_[w++]=m&255),x===1&&(m=t[p.charCodeAt(R)]<<10|t[p.charCodeAt(R+1)]<<4|t[p.charCodeAt(R+2)]>>2,_[w++]=m>>8&255,_[w++]=m&255),_}function l(p){return e[p>>18&63]+e[p>>12&63]+e[p>>6&63]+e[p&63]}function h(p,m,g){for(var E,x=[],_=m;_<g;_+=3)E=(p[_]<<16&16711680)+(p[_+1]<<8&65280)+(p[_+2]&255),x.push(l(E));return x.join("")}function y(p){for(var m,g=p.length,E=g%3,x=[],_=16383,w=0,T=g-E;w<T;w+=_)x.push(h(p,w,w+_>T?T:w+_));return E===1?(m=p[g-1],x.push(e[m>>2]+e[m<<4&63]+"==")):E===2&&(m=(p[g-2]<<8)+p[g-1],x.push(e[m>>10]+e[m>>4&63]+e[m<<2&63]+"=")),x.join("")}return zi}var oo={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */var wf;function my(){return wf||(wf=1,oo.read=function(e,t,n,r,i){var s,o,c=i*8-r-1,a=(1<<c)-1,u=a>>1,l=-7,h=n?i-1:0,y=n?-1:1,p=e[t+h];for(h+=y,s=p&(1<<-l)-1,p>>=-l,l+=c;l>0;s=s*256+e[t+h],h+=y,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=r;l>0;o=o*256+e[t+h],h+=y,l-=8);if(s===0)s=1-u;else{if(s===a)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,r),s=s-u}return(p?-1:1)*o*Math.pow(2,s-r)},oo.write=function(e,t,n,r,i,s){var o,c,a,u=s*8-i-1,l=(1<<u)-1,h=l>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:s-1,m=r?1:-1,g=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-o))<1&&(o--,a*=2),o+h>=1?t+=y/a:t+=y*Math.pow(2,1-h),t*a>=2&&(o++,a/=2),o+h>=l?(c=0,o=l):o+h>=1?(c=(t*a-1)*Math.pow(2,i),o=o+h):(c=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[n+p]=c&255,p+=m,c/=256,i-=8);for(o=o<<i|c,u+=i;u>0;e[n+p]=o&255,p+=m,o/=256,u-=8);e[n+p-m]|=g*128}),oo}/*!
5
+ * The buffer module from node.js, for the browser.
6
+ *
7
+ * @author Feross Aboukhadijeh <https://feross.org>
8
+ * @license MIT
9
+ */var bf;function co(){return bf||(bf=1,(function(e){const t=yy(),n=my(),r=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=c,e.SlowBuffer=_,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,c.TYPED_ARRAY_SUPPORT=s(),!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const N=new Uint8Array(1),d={foo:function(){return 42}};return Object.setPrototypeOf(d,Uint8Array.prototype),Object.setPrototypeOf(N,d),N.foo()===42}catch{return!1}}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}});function o(N){if(N>i)throw new RangeError('The value "'+N+'" is invalid for option "size"');const d=new Uint8Array(N);return Object.setPrototypeOf(d,c.prototype),d}function c(N,d,f){if(typeof N=="number"){if(typeof d=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return h(N)}return a(N,d,f)}c.poolSize=8192;function a(N,d,f){if(typeof N=="string")return y(N,d);if(ArrayBuffer.isView(N))return m(N);if(N==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof N);if(Qe(N,ArrayBuffer)||N&&Qe(N.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Qe(N,SharedArrayBuffer)||N&&Qe(N.buffer,SharedArrayBuffer)))return g(N,d,f);if(typeof N=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const b=N.valueOf&&N.valueOf();if(b!=null&&b!==N)return c.from(b,d,f);const A=E(N);if(A)return A;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof N[Symbol.toPrimitive]=="function")return c.from(N[Symbol.toPrimitive]("string"),d,f);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof N)}c.from=function(N,d,f){return a(N,d,f)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array);function u(N){if(typeof N!="number")throw new TypeError('"size" argument must be of type number');if(N<0)throw new RangeError('The value "'+N+'" is invalid for option "size"')}function l(N,d,f){return u(N),N<=0?o(N):d!==void 0?typeof f=="string"?o(N).fill(d,f):o(N).fill(d):o(N)}c.alloc=function(N,d,f){return l(N,d,f)};function h(N){return u(N),o(N<0?0:x(N)|0)}c.allocUnsafe=function(N){return h(N)},c.allocUnsafeSlow=function(N){return h(N)};function y(N,d){if((typeof d!="string"||d==="")&&(d="utf8"),!c.isEncoding(d))throw new TypeError("Unknown encoding: "+d);const f=w(N,d)|0;let b=o(f);const A=b.write(N,d);return A!==f&&(b=b.slice(0,A)),b}function p(N){const d=N.length<0?0:x(N.length)|0,f=o(d);for(let b=0;b<d;b+=1)f[b]=N[b]&255;return f}function m(N){if(Qe(N,Uint8Array)){const d=new Uint8Array(N);return g(d.buffer,d.byteOffset,d.byteLength)}return p(N)}function g(N,d,f){if(d<0||N.byteLength<d)throw new RangeError('"offset" is outside of buffer bounds');if(N.byteLength<d+(f||0))throw new RangeError('"length" is outside of buffer bounds');let b;return d===void 0&&f===void 0?b=new Uint8Array(N):f===void 0?b=new Uint8Array(N,d):b=new Uint8Array(N,d,f),Object.setPrototypeOf(b,c.prototype),b}function E(N){if(c.isBuffer(N)){const d=x(N.length)|0,f=o(d);return f.length===0||N.copy(f,0,0,d),f}if(N.length!==void 0)return typeof N.length!="number"||ke(N.length)?o(0):p(N);if(N.type==="Buffer"&&Array.isArray(N.data))return p(N.data)}function x(N){if(N>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return N|0}function _(N){return+N!=N&&(N=0),c.alloc(+N)}c.isBuffer=function(d){return d!=null&&d._isBuffer===!0&&d!==c.prototype},c.compare=function(d,f){if(Qe(d,Uint8Array)&&(d=c.from(d,d.offset,d.byteLength)),Qe(f,Uint8Array)&&(f=c.from(f,f.offset,f.byteLength)),!c.isBuffer(d)||!c.isBuffer(f))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(d===f)return 0;let b=d.length,A=f.length;for(let H=0,$=Math.min(b,A);H<$;++H)if(d[H]!==f[H]){b=d[H],A=f[H];break}return b<A?-1:A<b?1:0},c.isEncoding=function(d){switch(String(d).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(d,f){if(!Array.isArray(d))throw new TypeError('"list" argument must be an Array of Buffers');if(d.length===0)return c.alloc(0);let b;if(f===void 0)for(f=0,b=0;b<d.length;++b)f+=d[b].length;const A=c.allocUnsafe(f);let H=0;for(b=0;b<d.length;++b){let $=d[b];if(Qe($,Uint8Array))H+$.length>A.length?(c.isBuffer($)||($=c.from($)),$.copy(A,H)):Uint8Array.prototype.set.call(A,$,H);else if(c.isBuffer($))$.copy(A,H);else throw new TypeError('"list" argument must be an Array of Buffers');H+=$.length}return A};function w(N,d){if(c.isBuffer(N))return N.length;if(ArrayBuffer.isView(N)||Qe(N,ArrayBuffer))return N.byteLength;if(typeof N!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof N);const f=N.length,b=arguments.length>2&&arguments[2]===!0;if(!b&&f===0)return 0;let A=!1;for(;;)switch(d){case"ascii":case"latin1":case"binary":return f;case"utf8":case"utf-8":return tt(N).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return f*2;case"hex":return f>>>1;case"base64":return ve(N).length;default:if(A)return b?-1:tt(N).length;d=(""+d).toLowerCase(),A=!0}}c.byteLength=w;function T(N,d,f){let b=!1;if((d===void 0||d<0)&&(d=0),d>this.length||((f===void 0||f>this.length)&&(f=this.length),f<=0)||(f>>>=0,d>>>=0,f<=d))return"";for(N||(N="utf8");;)switch(N){case"hex":return I(this,d,f);case"utf8":case"utf-8":return D(this,d,f);case"ascii":return F(this,d,f);case"latin1":case"binary":return S(this,d,f);case"base64":return U(this,d,f);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,d,f);default:if(b)throw new TypeError("Unknown encoding: "+N);N=(N+"").toLowerCase(),b=!0}}c.prototype._isBuffer=!0;function R(N,d,f){const b=N[d];N[d]=N[f],N[f]=b}c.prototype.swap16=function(){const d=this.length;if(d%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let f=0;f<d;f+=2)R(this,f,f+1);return this},c.prototype.swap32=function(){const d=this.length;if(d%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let f=0;f<d;f+=4)R(this,f,f+3),R(this,f+1,f+2);return this},c.prototype.swap64=function(){const d=this.length;if(d%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let f=0;f<d;f+=8)R(this,f,f+7),R(this,f+1,f+6),R(this,f+2,f+5),R(this,f+3,f+4);return this},c.prototype.toString=function(){const d=this.length;return d===0?"":arguments.length===0?D(this,0,d):T.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(d){if(!c.isBuffer(d))throw new TypeError("Argument must be a Buffer");return this===d?!0:c.compare(this,d)===0},c.prototype.inspect=function(){let d="";const f=e.INSPECT_MAX_BYTES;return d=this.toString("hex",0,f).replace(/(.{2})/g,"$1 ").trim(),this.length>f&&(d+=" ... "),"<Buffer "+d+">"},r&&(c.prototype[r]=c.prototype.inspect),c.prototype.compare=function(d,f,b,A,H){if(Qe(d,Uint8Array)&&(d=c.from(d,d.offset,d.byteLength)),!c.isBuffer(d))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof d);if(f===void 0&&(f=0),b===void 0&&(b=d?d.length:0),A===void 0&&(A=0),H===void 0&&(H=this.length),f<0||b>d.length||A<0||H>this.length)throw new RangeError("out of range index");if(A>=H&&f>=b)return 0;if(A>=H)return-1;if(f>=b)return 1;if(f>>>=0,b>>>=0,A>>>=0,H>>>=0,this===d)return 0;let $=H-A,W=b-f;const ie=Math.min($,W),Q=this.slice(A,H),fe=d.slice(f,b);for(let le=0;le<ie;++le)if(Q[le]!==fe[le]){$=Q[le],W=fe[le];break}return $<W?-1:W<$?1:0};function B(N,d,f,b,A){if(N.length===0)return-1;if(typeof f=="string"?(b=f,f=0):f>2147483647?f=2147483647:f<-2147483648&&(f=-2147483648),f=+f,ke(f)&&(f=A?0:N.length-1),f<0&&(f=N.length+f),f>=N.length){if(A)return-1;f=N.length-1}else if(f<0)if(A)f=0;else return-1;if(typeof d=="string"&&(d=c.from(d,b)),c.isBuffer(d))return d.length===0?-1:P(N,d,f,b,A);if(typeof d=="number")return d=d&255,typeof Uint8Array.prototype.indexOf=="function"?A?Uint8Array.prototype.indexOf.call(N,d,f):Uint8Array.prototype.lastIndexOf.call(N,d,f):P(N,[d],f,b,A);throw new TypeError("val must be string, number or Buffer")}function P(N,d,f,b,A){let H=1,$=N.length,W=d.length;if(b!==void 0&&(b=String(b).toLowerCase(),b==="ucs2"||b==="ucs-2"||b==="utf16le"||b==="utf-16le")){if(N.length<2||d.length<2)return-1;H=2,$/=2,W/=2,f/=2}function ie(fe,le){return H===1?fe[le]:fe.readUInt16BE(le*H)}let Q;if(A){let fe=-1;for(Q=f;Q<$;Q++)if(ie(N,Q)===ie(d,fe===-1?0:Q-fe)){if(fe===-1&&(fe=Q),Q-fe+1===W)return fe*H}else fe!==-1&&(Q-=Q-fe),fe=-1}else for(f+W>$&&(f=$-W),Q=f;Q>=0;Q--){let fe=!0;for(let le=0;le<W;le++)if(ie(N,Q+le)!==ie(d,le)){fe=!1;break}if(fe)return Q}return-1}c.prototype.includes=function(d,f,b){return this.indexOf(d,f,b)!==-1},c.prototype.indexOf=function(d,f,b){return B(this,d,f,b,!0)},c.prototype.lastIndexOf=function(d,f,b){return B(this,d,f,b,!1)};function q(N,d,f,b){f=Number(f)||0;const A=N.length-f;b?(b=Number(b),b>A&&(b=A)):b=A;const H=d.length;b>H/2&&(b=H/2);let $;for($=0;$<b;++$){const W=parseInt(d.substr($*2,2),16);if(ke(W))return $;N[f+$]=W}return $}function v(N,d,f,b){return zt(tt(d,N.length-f),N,f,b)}function C(N,d,f,b){return zt(ut(d),N,f,b)}function L(N,d,f,b){return zt(ve(d),N,f,b)}function K(N,d,f,b){return zt(gt(d,N.length-f),N,f,b)}c.prototype.write=function(d,f,b,A){if(f===void 0)A="utf8",b=this.length,f=0;else if(b===void 0&&typeof f=="string")A=f,b=this.length,f=0;else if(isFinite(f))f=f>>>0,isFinite(b)?(b=b>>>0,A===void 0&&(A="utf8")):(A=b,b=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const H=this.length-f;if((b===void 0||b>H)&&(b=H),d.length>0&&(b<0||f<0)||f>this.length)throw new RangeError("Attempt to write outside buffer bounds");A||(A="utf8");let $=!1;for(;;)switch(A){case"hex":return q(this,d,f,b);case"utf8":case"utf-8":return v(this,d,f,b);case"ascii":case"latin1":case"binary":return C(this,d,f,b);case"base64":return L(this,d,f,b);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return K(this,d,f,b);default:if($)throw new TypeError("Unknown encoding: "+A);A=(""+A).toLowerCase(),$=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function U(N,d,f){return d===0&&f===N.length?t.fromByteArray(N):t.fromByteArray(N.slice(d,f))}function D(N,d,f){f=Math.min(N.length,f);const b=[];let A=d;for(;A<f;){const H=N[A];let $=null,W=H>239?4:H>223?3:H>191?2:1;if(A+W<=f){let ie,Q,fe,le;switch(W){case 1:H<128&&($=H);break;case 2:ie=N[A+1],(ie&192)===128&&(le=(H&31)<<6|ie&63,le>127&&($=le));break;case 3:ie=N[A+1],Q=N[A+2],(ie&192)===128&&(Q&192)===128&&(le=(H&15)<<12|(ie&63)<<6|Q&63,le>2047&&(le<55296||le>57343)&&($=le));break;case 4:ie=N[A+1],Q=N[A+2],fe=N[A+3],(ie&192)===128&&(Q&192)===128&&(fe&192)===128&&(le=(H&15)<<18|(ie&63)<<12|(Q&63)<<6|fe&63,le>65535&&le<1114112&&($=le))}}$===null?($=65533,W=1):$>65535&&($-=65536,b.push($>>>10&1023|55296),$=56320|$&1023),b.push($),A+=W}return j(b)}const k=4096;function j(N){const d=N.length;if(d<=k)return String.fromCharCode.apply(String,N);let f="",b=0;for(;b<d;)f+=String.fromCharCode.apply(String,N.slice(b,b+=k));return f}function F(N,d,f){let b="";f=Math.min(N.length,f);for(let A=d;A<f;++A)b+=String.fromCharCode(N[A]&127);return b}function S(N,d,f){let b="";f=Math.min(N.length,f);for(let A=d;A<f;++A)b+=String.fromCharCode(N[A]);return b}function I(N,d,f){const b=N.length;(!d||d<0)&&(d=0),(!f||f<0||f>b)&&(f=b);let A="";for(let H=d;H<f;++H)A+=oe[N[H]];return A}function M(N,d,f){const b=N.slice(d,f);let A="";for(let H=0;H<b.length-1;H+=2)A+=String.fromCharCode(b[H]+b[H+1]*256);return A}c.prototype.slice=function(d,f){const b=this.length;d=~~d,f=f===void 0?b:~~f,d<0?(d+=b,d<0&&(d=0)):d>b&&(d=b),f<0?(f+=b,f<0&&(f=0)):f>b&&(f=b),f<d&&(f=d);const A=this.subarray(d,f);return Object.setPrototypeOf(A,c.prototype),A};function O(N,d,f){if(N%1!==0||N<0)throw new RangeError("offset is not uint");if(N+d>f)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(d,f,b){d=d>>>0,f=f>>>0,b||O(d,f,this.length);let A=this[d],H=1,$=0;for(;++$<f&&(H*=256);)A+=this[d+$]*H;return A},c.prototype.readUintBE=c.prototype.readUIntBE=function(d,f,b){d=d>>>0,f=f>>>0,b||O(d,f,this.length);let A=this[d+--f],H=1;for(;f>0&&(H*=256);)A+=this[d+--f]*H;return A},c.prototype.readUint8=c.prototype.readUInt8=function(d,f){return d=d>>>0,f||O(d,1,this.length),this[d]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(d,f){return d=d>>>0,f||O(d,2,this.length),this[d]|this[d+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(d,f){return d=d>>>0,f||O(d,2,this.length),this[d]<<8|this[d+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(d,f){return d=d>>>0,f||O(d,4,this.length),(this[d]|this[d+1]<<8|this[d+2]<<16)+this[d+3]*16777216},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(d,f){return d=d>>>0,f||O(d,4,this.length),this[d]*16777216+(this[d+1]<<16|this[d+2]<<8|this[d+3])},c.prototype.readBigUInt64LE=ne(function(d){d=d>>>0,J(d,"offset");const f=this[d],b=this[d+7];(f===void 0||b===void 0)&&de(d,this.length-8);const A=f+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24,H=this[++d]+this[++d]*2**8+this[++d]*2**16+b*2**24;return BigInt(A)+(BigInt(H)<<BigInt(32))}),c.prototype.readBigUInt64BE=ne(function(d){d=d>>>0,J(d,"offset");const f=this[d],b=this[d+7];(f===void 0||b===void 0)&&de(d,this.length-8);const A=f*2**24+this[++d]*2**16+this[++d]*2**8+this[++d],H=this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+b;return(BigInt(A)<<BigInt(32))+BigInt(H)}),c.prototype.readIntLE=function(d,f,b){d=d>>>0,f=f>>>0,b||O(d,f,this.length);let A=this[d],H=1,$=0;for(;++$<f&&(H*=256);)A+=this[d+$]*H;return H*=128,A>=H&&(A-=Math.pow(2,8*f)),A},c.prototype.readIntBE=function(d,f,b){d=d>>>0,f=f>>>0,b||O(d,f,this.length);let A=f,H=1,$=this[d+--A];for(;A>0&&(H*=256);)$+=this[d+--A]*H;return H*=128,$>=H&&($-=Math.pow(2,8*f)),$},c.prototype.readInt8=function(d,f){return d=d>>>0,f||O(d,1,this.length),this[d]&128?(255-this[d]+1)*-1:this[d]},c.prototype.readInt16LE=function(d,f){d=d>>>0,f||O(d,2,this.length);const b=this[d]|this[d+1]<<8;return b&32768?b|4294901760:b},c.prototype.readInt16BE=function(d,f){d=d>>>0,f||O(d,2,this.length);const b=this[d+1]|this[d]<<8;return b&32768?b|4294901760:b},c.prototype.readInt32LE=function(d,f){return d=d>>>0,f||O(d,4,this.length),this[d]|this[d+1]<<8|this[d+2]<<16|this[d+3]<<24},c.prototype.readInt32BE=function(d,f){return d=d>>>0,f||O(d,4,this.length),this[d]<<24|this[d+1]<<16|this[d+2]<<8|this[d+3]},c.prototype.readBigInt64LE=ne(function(d){d=d>>>0,J(d,"offset");const f=this[d],b=this[d+7];(f===void 0||b===void 0)&&de(d,this.length-8);const A=this[d+4]+this[d+5]*2**8+this[d+6]*2**16+(b<<24);return(BigInt(A)<<BigInt(32))+BigInt(f+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24)}),c.prototype.readBigInt64BE=ne(function(d){d=d>>>0,J(d,"offset");const f=this[d],b=this[d+7];(f===void 0||b===void 0)&&de(d,this.length-8);const A=(f<<24)+this[++d]*2**16+this[++d]*2**8+this[++d];return(BigInt(A)<<BigInt(32))+BigInt(this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+b)}),c.prototype.readFloatLE=function(d,f){return d=d>>>0,f||O(d,4,this.length),n.read(this,d,!0,23,4)},c.prototype.readFloatBE=function(d,f){return d=d>>>0,f||O(d,4,this.length),n.read(this,d,!1,23,4)},c.prototype.readDoubleLE=function(d,f){return d=d>>>0,f||O(d,8,this.length),n.read(this,d,!0,52,8)},c.prototype.readDoubleBE=function(d,f){return d=d>>>0,f||O(d,8,this.length),n.read(this,d,!1,52,8)};function V(N,d,f,b,A,H){if(!c.isBuffer(N))throw new TypeError('"buffer" argument must be a Buffer instance');if(d>A||d<H)throw new RangeError('"value" argument is out of bounds');if(f+b>N.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(d,f,b,A){if(d=+d,f=f>>>0,b=b>>>0,!A){const W=Math.pow(2,8*b)-1;V(this,d,f,b,W,0)}let H=1,$=0;for(this[f]=d&255;++$<b&&(H*=256);)this[f+$]=d/H&255;return f+b},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(d,f,b,A){if(d=+d,f=f>>>0,b=b>>>0,!A){const W=Math.pow(2,8*b)-1;V(this,d,f,b,W,0)}let H=b-1,$=1;for(this[f+H]=d&255;--H>=0&&($*=256);)this[f+H]=d/$&255;return f+b},c.prototype.writeUint8=c.prototype.writeUInt8=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,1,255,0),this[f]=d&255,f+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,2,65535,0),this[f]=d&255,this[f+1]=d>>>8,f+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,2,65535,0),this[f]=d>>>8,this[f+1]=d&255,f+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,4,4294967295,0),this[f+3]=d>>>24,this[f+2]=d>>>16,this[f+1]=d>>>8,this[f]=d&255,f+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,4,4294967295,0),this[f]=d>>>24,this[f+1]=d>>>16,this[f+2]=d>>>8,this[f+3]=d&255,f+4};function G(N,d,f,b,A){pe(d,b,A,N,f,7);let H=Number(d&BigInt(4294967295));N[f++]=H,H=H>>8,N[f++]=H,H=H>>8,N[f++]=H,H=H>>8,N[f++]=H;let $=Number(d>>BigInt(32)&BigInt(4294967295));return N[f++]=$,$=$>>8,N[f++]=$,$=$>>8,N[f++]=$,$=$>>8,N[f++]=$,f}function X(N,d,f,b,A){pe(d,b,A,N,f,7);let H=Number(d&BigInt(4294967295));N[f+7]=H,H=H>>8,N[f+6]=H,H=H>>8,N[f+5]=H,H=H>>8,N[f+4]=H;let $=Number(d>>BigInt(32)&BigInt(4294967295));return N[f+3]=$,$=$>>8,N[f+2]=$,$=$>>8,N[f+1]=$,$=$>>8,N[f]=$,f+8}c.prototype.writeBigUInt64LE=ne(function(d,f=0){return G(this,d,f,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=ne(function(d,f=0){return X(this,d,f,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(d,f,b,A){if(d=+d,f=f>>>0,!A){const ie=Math.pow(2,8*b-1);V(this,d,f,b,ie-1,-ie)}let H=0,$=1,W=0;for(this[f]=d&255;++H<b&&($*=256);)d<0&&W===0&&this[f+H-1]!==0&&(W=1),this[f+H]=(d/$>>0)-W&255;return f+b},c.prototype.writeIntBE=function(d,f,b,A){if(d=+d,f=f>>>0,!A){const ie=Math.pow(2,8*b-1);V(this,d,f,b,ie-1,-ie)}let H=b-1,$=1,W=0;for(this[f+H]=d&255;--H>=0&&($*=256);)d<0&&W===0&&this[f+H+1]!==0&&(W=1),this[f+H]=(d/$>>0)-W&255;return f+b},c.prototype.writeInt8=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,1,127,-128),d<0&&(d=255+d+1),this[f]=d&255,f+1},c.prototype.writeInt16LE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,2,32767,-32768),this[f]=d&255,this[f+1]=d>>>8,f+2},c.prototype.writeInt16BE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,2,32767,-32768),this[f]=d>>>8,this[f+1]=d&255,f+2},c.prototype.writeInt32LE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,4,2147483647,-2147483648),this[f]=d&255,this[f+1]=d>>>8,this[f+2]=d>>>16,this[f+3]=d>>>24,f+4},c.prototype.writeInt32BE=function(d,f,b){return d=+d,f=f>>>0,b||V(this,d,f,4,2147483647,-2147483648),d<0&&(d=4294967295+d+1),this[f]=d>>>24,this[f+1]=d>>>16,this[f+2]=d>>>8,this[f+3]=d&255,f+4},c.prototype.writeBigInt64LE=ne(function(d,f=0){return G(this,d,f,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=ne(function(d,f=0){return X(this,d,f,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Y(N,d,f,b,A,H){if(f+b>N.length)throw new RangeError("Index out of range");if(f<0)throw new RangeError("Index out of range")}function ce(N,d,f,b,A){return d=+d,f=f>>>0,A||Y(N,d,f,4),n.write(N,d,f,b,23,4),f+4}c.prototype.writeFloatLE=function(d,f,b){return ce(this,d,f,!0,b)},c.prototype.writeFloatBE=function(d,f,b){return ce(this,d,f,!1,b)};function ue(N,d,f,b,A){return d=+d,f=f>>>0,A||Y(N,d,f,8),n.write(N,d,f,b,52,8),f+8}c.prototype.writeDoubleLE=function(d,f,b){return ue(this,d,f,!0,b)},c.prototype.writeDoubleBE=function(d,f,b){return ue(this,d,f,!1,b)},c.prototype.copy=function(d,f,b,A){if(!c.isBuffer(d))throw new TypeError("argument should be a Buffer");if(b||(b=0),!A&&A!==0&&(A=this.length),f>=d.length&&(f=d.length),f||(f=0),A>0&&A<b&&(A=b),A===b||d.length===0||this.length===0)return 0;if(f<0)throw new RangeError("targetStart out of bounds");if(b<0||b>=this.length)throw new RangeError("Index out of range");if(A<0)throw new RangeError("sourceEnd out of bounds");A>this.length&&(A=this.length),d.length-f<A-b&&(A=d.length-f+b);const H=A-b;return this===d&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(f,b,A):Uint8Array.prototype.set.call(d,this.subarray(b,A),f),H},c.prototype.fill=function(d,f,b,A){if(typeof d=="string"){if(typeof f=="string"?(A=f,f=0,b=this.length):typeof b=="string"&&(A=b,b=this.length),A!==void 0&&typeof A!="string")throw new TypeError("encoding must be a string");if(typeof A=="string"&&!c.isEncoding(A))throw new TypeError("Unknown encoding: "+A);if(d.length===1){const $=d.charCodeAt(0);(A==="utf8"&&$<128||A==="latin1")&&(d=$)}}else typeof d=="number"?d=d&255:typeof d=="boolean"&&(d=Number(d));if(f<0||this.length<f||this.length<b)throw new RangeError("Out of range index");if(b<=f)return this;f=f>>>0,b=b===void 0?this.length:b>>>0,d||(d=0);let H;if(typeof d=="number")for(H=f;H<b;++H)this[H]=d;else{const $=c.isBuffer(d)?d:c.from(d,A),W=$.length;if(W===0)throw new TypeError('The value "'+d+'" is invalid for argument "value"');for(H=0;H<b-f;++H)this[H+f]=$[H%W]}return this};const te={};function Z(N,d,f){te[N]=class extends f{constructor(){super(),Object.defineProperty(this,"message",{value:d.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${N}]`,this.stack,delete this.name}get code(){return N}set code(A){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:A,writable:!0})}toString(){return`${this.name} [${N}]: ${this.message}`}}}Z("ERR_BUFFER_OUT_OF_BOUNDS",function(N){return N?`${N} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Z("ERR_INVALID_ARG_TYPE",function(N,d){return`The "${N}" argument must be of type number. Received type ${typeof d}`},TypeError),Z("ERR_OUT_OF_RANGE",function(N,d,f){let b=`The value of "${N}" is out of range.`,A=f;return Number.isInteger(f)&&Math.abs(f)>2**32?A=ae(String(f)):typeof f=="bigint"&&(A=String(f),(f>BigInt(2)**BigInt(32)||f<-(BigInt(2)**BigInt(32)))&&(A=ae(A)),A+="n"),b+=` It must be ${d}. Received ${A}`,b},RangeError);function ae(N){let d="",f=N.length;const b=N[0]==="-"?1:0;for(;f>=b+4;f-=3)d=`_${N.slice(f-3,f)}${d}`;return`${N.slice(0,f)}${d}`}function ge(N,d,f){J(d,"offset"),(N[d]===void 0||N[d+f]===void 0)&&de(d,N.length-(f+1))}function pe(N,d,f,b,A,H){if(N>f||N<d){const $=typeof d=="bigint"?"n":"";let W;throw d===0||d===BigInt(0)?W=`>= 0${$} and < 2${$} ** ${(H+1)*8}${$}`:W=`>= -(2${$} ** ${(H+1)*8-1}${$}) and < 2 ** ${(H+1)*8-1}${$}`,new te.ERR_OUT_OF_RANGE("value",W,N)}ge(b,A,H)}function J(N,d){if(typeof N!="number")throw new te.ERR_INVALID_ARG_TYPE(d,"number",N)}function de(N,d,f){throw Math.floor(N)!==N?(J(N,f),new te.ERR_OUT_OF_RANGE("offset","an integer",N)):d<0?new te.ERR_BUFFER_OUT_OF_BOUNDS:new te.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${d}`,N)}const xe=/[^+/0-9A-Za-z-_]/g;function Me(N){if(N=N.split("=")[0],N=N.trim().replace(xe,""),N.length<2)return"";for(;N.length%4!==0;)N=N+"=";return N}function tt(N,d){d=d||1/0;let f;const b=N.length;let A=null;const H=[];for(let $=0;$<b;++$){if(f=N.charCodeAt($),f>55295&&f<57344){if(!A){if(f>56319){(d-=3)>-1&&H.push(239,191,189);continue}else if($+1===b){(d-=3)>-1&&H.push(239,191,189);continue}A=f;continue}if(f<56320){(d-=3)>-1&&H.push(239,191,189),A=f;continue}f=(A-55296<<10|f-56320)+65536}else A&&(d-=3)>-1&&H.push(239,191,189);if(A=null,f<128){if((d-=1)<0)break;H.push(f)}else if(f<2048){if((d-=2)<0)break;H.push(f>>6|192,f&63|128)}else if(f<65536){if((d-=3)<0)break;H.push(f>>12|224,f>>6&63|128,f&63|128)}else if(f<1114112){if((d-=4)<0)break;H.push(f>>18|240,f>>12&63|128,f>>6&63|128,f&63|128)}else throw new Error("Invalid code point")}return H}function ut(N){const d=[];for(let f=0;f<N.length;++f)d.push(N.charCodeAt(f)&255);return d}function gt(N,d){let f,b,A;const H=[];for(let $=0;$<N.length&&!((d-=2)<0);++$)f=N.charCodeAt($),b=f>>8,A=f%256,H.push(A),H.push(b);return H}function ve(N){return t.toByteArray(Me(N))}function zt(N,d,f,b){let A;for(A=0;A<b&&!(A+f>=d.length||A>=N.length);++A)d[A+f]=N[A];return A}function Qe(N,d){return N instanceof d||N!=null&&N.constructor!=null&&N.constructor.name!=null&&N.constructor.name===d.name}function ke(N){return N!==N}const oe=(function(){const N="0123456789abcdef",d=new Array(256);for(let f=0;f<16;++f){const b=f*16;for(let A=0;A<16;++A)d[b+A]=N[f]+N[A]}return d})();function ne(N){return typeof BigInt>"u"?re:N}function re(){throw new Error("BigInt not supported")}})(Dc)),Dc}var jc,Ef;function $c(){if(Ef)return jc;Ef=1;var e={Array:function(n){return n!=null&&n.constructor===Array},Boolean:function(n){return typeof n=="boolean"},Function:function(n){return typeof n=="function"},Nil:function(n){return n==null},Number:function(n){return typeof n=="number"},Object:function(n){return typeof n=="object"},String:function(n){return typeof n=="string"},"":function(){return!0}};e.Null=e.Nil;for(var t in e)e[t].toJSON=(function(n){return n}).bind(null,t);return jc=e,jc}var Kc,_f;function Sf(){if(_f)return Kc;_f=1;var e=$c();function t(y){return y.name||y.toString().match(/function (.*?)\s*\(/)[1]}function n(y){return e.Nil(y)?"":t(y.constructor)}function r(y){return e.Function(y)?"":e.String(y)?JSON.stringify(y):y&&e.Object(y)?"":y}function i(y,p){Error.captureStackTrace&&Error.captureStackTrace(y,p)}function s(y){return e.Function(y)?y.toJSON?y.toJSON():t(y):e.Array(y)?"Array":y&&e.Object(y)?"Object":y!==void 0?y:""}function o(y,p,m){var g=r(p);return"Expected "+s(y)+", got"+(m!==""?" "+m:"")+(g!==""?" "+g:"")}function c(y,p,m){m=m||n(p),this.message=o(y,p,m),i(this,c),this.__type=y,this.__value=p,this.__valueTypeName=m}c.prototype=Object.create(Error.prototype),c.prototype.constructor=c;function a(y,p,m,g,E){var x='" of type ';return p==="key"&&(x='" with key type '),o('property "'+s(m)+x+s(y),g,E)}function u(y,p,m,g,E){y?(E=E||n(g),this.message=a(y,m,p,g,E)):this.message='Unexpected property "'+p+'"',i(this,c),this.__label=m,this.__property=p,this.__type=y,this.__value=g,this.__valueTypeName=E}u.prototype=Object.create(Error.prototype),u.prototype.constructor=c;function l(y,p){return new c(y,{},p)}function h(y,p,m){return y instanceof u?(p=p+"."+y.__property,y=new u(y.__type,p,y.__label,y.__value,y.__valueTypeName)):y instanceof c&&(y=new u(y.__type,p,m,y.__value,y.__valueTypeName)),i(y),y}return Kc={TfTypeError:c,TfPropertyTypeError:u,tfCustomError:l,tfSubError:h,tfJSON:s,getValueTypeName:n},Kc}var Gc,xf;function gy(){if(xf)return Gc;xf=1;var e=$c(),t=Sf();function n(B){return Buffer.isBuffer(B)}function r(B){return typeof B=="string"&&/^([0-9a-f]{2})+$/i.test(B)}function i(B,P){var q=B.toJSON();function v(C){if(!B(C))return!1;if(C.length===P)return!0;throw t.tfCustomError(q+"(Length: "+P+")",q+"(Length: "+C.length+")")}return v.toJSON=function(){return q},v}var s=i.bind(null,e.Array),o=i.bind(null,n),c=i.bind(null,r),a=i.bind(null,e.String);function u(B,P,q){q=q||e.Number;function v(C,L){return q(C,L)&&C>B&&C<P}return v.toJSON=function(){return`${q.toJSON()} between [${B}, ${P}]`},v}var l=Math.pow(2,53)-1;function h(B){return typeof B=="number"&&isFinite(B)}function y(B){return B<<24>>24===B}function p(B){return B<<16>>16===B}function m(B){return(B|0)===B}function g(B){return typeof B=="number"&&B>=-l&&B<=l&&Math.floor(B)===B}function E(B){return(B&255)===B}function x(B){return(B&65535)===B}function _(B){return B>>>0===B}function w(B){return typeof B=="number"&&B>=0&&B<=l&&Math.floor(B)===B}var T={ArrayN:s,Buffer:n,BufferN:o,Finite:h,Hex:r,HexN:c,Int8:y,Int16:p,Int32:m,Int53:g,Range:u,StringN:a,UInt8:E,UInt16:x,UInt32:_,UInt53:w};for(var R in T)T[R].toJSON=(function(B){return B}).bind(null,R);return Gc=T,Gc}var Wc,Tf;function wy(){if(Tf)return Wc;Tf=1;var e=Sf(),t=$c(),n=e.tfJSON,r=e.TfTypeError,i=e.TfPropertyTypeError,s=e.tfSubError,o=e.getValueTypeName,c={arrayOf:function(p,m){p=a(p),m=m||{};function g(E,x){return!t.Array(E)||t.Nil(E)||m.minLength!==void 0&&E.length<m.minLength||m.maxLength!==void 0&&E.length>m.maxLength||m.length!==void 0&&E.length!==m.length?!1:E.every(function(_,w){try{return u(p,_,x)}catch(T){throw s(T,w)}})}return g.toJSON=function(){var E="["+n(p)+"]";return m.length!==void 0?E+="{"+m.length+"}":(m.minLength!==void 0||m.maxLength!==void 0)&&(E+="{"+(m.minLength===void 0?0:m.minLength)+","+(m.maxLength===void 0?1/0:m.maxLength)+"}"),E},g},maybe:function y(p){p=a(p);function m(g,E){return t.Nil(g)||p(g,E,y)}return m.toJSON=function(){return"?"+n(p)},m},map:function(p,m){p=a(p),m&&(m=a(m));function g(E,x){if(!t.Object(E)||t.Nil(E))return!1;for(var _ in E){try{m&&u(m,_,x)}catch(T){throw s(T,_,"key")}try{var w=E[_];u(p,w,x)}catch(T){throw s(T,_)}}return!0}return m?g.toJSON=function(){return"{"+n(m)+": "+n(p)+"}"}:g.toJSON=function(){return"{"+n(p)+"}"},g},object:function(p){var m={};for(var g in p)m[g]=a(p[g]);function E(x,_){if(!t.Object(x)||t.Nil(x))return!1;var w;try{for(w in m){var T=m[w],R=x[w];u(T,R,_)}}catch(B){throw s(B,w)}if(_){for(w in x)if(!m[w])throw new i(void 0,w)}return!0}return E.toJSON=function(){return n(m)},E},anyOf:function(){var p=[].slice.call(arguments).map(a);function m(g,E){return p.some(function(x){try{return u(x,g,E)}catch{return!1}})}return m.toJSON=function(){return p.map(n).join("|")},m},allOf:function(){var p=[].slice.call(arguments).map(a);function m(g,E){return p.every(function(x){try{return u(x,g,E)}catch{return!1}})}return m.toJSON=function(){return p.map(n).join(" & ")},m},quacksLike:function(p){function m(g){return p===o(g)}return m.toJSON=function(){return p},m},tuple:function(){var p=[].slice.call(arguments).map(a);function m(g,E){return t.Nil(g)||t.Nil(g.length)||E&&g.length!==p.length?!1:p.every(function(x,_){try{return u(x,g[_],E)}catch(w){throw s(w,_)}})}return m.toJSON=function(){return"("+p.map(n).join(", ")+")"},m},value:function(p){function m(g){return g===p}return m.toJSON=function(){return p},m}};c.oneOf=c.anyOf;function a(y){if(t.String(y))return y[0]==="?"?c.maybe(y.slice(1)):t[y]||c.quacksLike(y);if(y&&t.Object(y)){if(t.Array(y)){if(y.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(y[0])}return c.object(y)}else if(t.Function(y))return y;return c.value(y)}function u(y,p,m,g){if(t.Function(y)){if(y(p,m))return!0;throw new r(g||y,p)}return u(a(y),p,m)}for(var l in t)u[l]=t[l];for(l in c)u[l]=c[l];var h=gy();for(l in h)u[l]=h[l];return u.compile=a,u.TfTypeError=r,u.TfPropertyTypeError=i,Wc=u,Wc}var vf;function vt(){return vf||(vf=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=co();e.typeforce=wy();const n=t.Buffer.alloc(32,0),r=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(l,h){return l.length!==h.length?!1:l.every((y,p)=>y.equals(h[p]))}e.stacksEqual=i;function s(l){if(!t.Buffer.isBuffer(l)||l.length<33)return!1;const h=l[0],y=l.slice(1,33);if(y.compare(n)===0||y.compare(r)>=0)return!1;if((h===2||h===3)&&l.length===33)return!0;const p=l.slice(33);return p.compare(n)===0||p.compare(r)>=0?!1:h===4&&l.length===65}e.isPoint=s;const o=21*1e14;function c(l){return e.typeforce.UInt53(l)&&l<=o}e.Satoshi=c,e.TAPLEAF_VERSION_MASK=254;function a(l){return!l||!("output"in l)||!t.Buffer.isBuffer(l.output)?!1:l.version!==void 0?(l.version&e.TAPLEAF_VERSION_MASK)===l.version:!0}e.isTapleaf=a;function u(l){return(0,e.Array)(l)?l.length!==2?!1:l.every(h=>u(h)):a(l)}e.isTaptree=u,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(Vc)),Vc}var Bf;function by(){if(Bf)return Ar;Bf=1,Object.defineProperty(Ar,"__esModule",{value:!0}),Ar.encode=Ar.decode=void 0;const e=hf(),t=kt(),n=vt(),{typeforce:r}=n,i=Buffer.alloc(1,0);function s(u){let l=0;for(;u[l]===0;)++l;return l===u.length?i:(u=u.slice(l),u[0]&128?Buffer.concat([i,u],1+u.length):u)}function o(u){u[0]===0&&(u=u.slice(1));const l=Buffer.alloc(32,0),h=Math.max(0,32-u.length);return u.copy(l,h),l}function c(u){const l=u.readUInt8(u.length-1);if(!(0,t.isDefinedHashType)(l))throw new Error("Invalid hashType "+l);const h=e.decode(u.slice(0,-1)),y=o(h.r),p=o(h.s);return{signature:Buffer.concat([y,p],64),hashType:l}}Ar.decode=c;function a(u,l){if(r({signature:n.BufferN(64),hashType:n.UInt8},{signature:u,hashType:l}),!(0,t.isDefinedHashType)(l))throw new Error("Invalid hashType "+l);const h=Buffer.allocUnsafe(1);h.writeUInt8(l,0);const y=s(u.slice(0,32)),p=s(u.slice(32,64));return Buffer.concat([e.encode(y,p),h])}return Ar.encode=a,Ar}var Af;function kt(){return Af||(Af=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=hf(),n=Lc();Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return n.OPS}});const r=hy(),i=py(),s=by(),o=vt(),{typeforce:c}=o,a=n.OPS.OP_RESERVED;function u(v){return o.Number(v)&&(v===n.OPS.OP_0||v>=n.OPS.OP_1&&v<=n.OPS.OP_16||v===n.OPS.OP_1NEGATE)}function l(v){return o.Buffer(v)||u(v)}function h(v){return o.Array(v)&&v.every(l)}e.isPushOnly=h;function y(v){return v.length-v.filter(l).length}e.countNonPushOnlyOPs=y;function p(v){if(v.length===0)return n.OPS.OP_0;if(v.length===1){if(v[0]>=1&&v[0]<=16)return a+v[0];if(v[0]===129)return n.OPS.OP_1NEGATE}}function m(v){return Buffer.isBuffer(v)}function g(v){return o.Array(v)}function E(v){return Buffer.isBuffer(v)}function x(v){if(m(v))return v;c(o.Array,v);const C=v.reduce((U,D)=>E(D)?D.length===1&&p(D)!==void 0?U+1:U+r.encodingLength(D.length)+D.length:U+1,0),L=Buffer.allocUnsafe(C);let K=0;if(v.forEach(U=>{if(E(U)){const D=p(U);if(D!==void 0){L.writeUInt8(D,K),K+=1;return}K+=r.encode(L,U.length,K),U.copy(L,K),K+=U.length}else L.writeUInt8(U,K),K+=1}),K!==L.length)throw new Error("Could not decode chunks");return L}e.compile=x;function _(v){if(g(v))return v;c(o.Buffer,v);const C=[];let L=0;for(;L<v.length;){const K=v[L];if(K>n.OPS.OP_0&&K<=n.OPS.OP_PUSHDATA4){const U=r.decode(v,L);if(U===null||(L+=U.size,L+U.number>v.length))return null;const D=v.slice(L,L+U.number);L+=U.number;const k=p(D);k!==void 0?C.push(k):C.push(D)}else C.push(K),L+=1}return C}e.decompile=_;function w(v){if(m(v)&&(v=_(v)),!v)throw new Error("Could not convert invalid chunks to ASM");return v.map(C=>{if(E(C)){const L=p(C);if(L===void 0)return C.toString("hex");C=L}return n.REVERSE_OPS[C]}).join(" ")}e.toASM=w;function T(v){return c(o.String,v),x(v.split(" ").map(C=>n.OPS[C]!==void 0?n.OPS[C]:(c(o.Hex,C),Buffer.from(C,"hex"))))}e.fromASM=T;function R(v){return v=_(v),c(h,v),v.map(C=>E(C)?C:C===n.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(C-a))}e.toStack=R;function B(v){return o.isPoint(v)}e.isCanonicalPubKey=B;function P(v){const C=v&-129;return C>0&&C<4}e.isDefinedHashType=P;function q(v){return!Buffer.isBuffer(v)||!P(v[v.length-1])?!1:t.check(v.slice(0,-1))}e.isCanonicalScriptSignature=q,e.number=i,e.signature=s})(Mc)),Mc}var Ir={},If;function Wn(){if(If)return Ir;If=1,Object.defineProperty(Ir,"__esModule",{value:!0}),Ir.value=Ir.prop=void 0;function e(n,r,i){Object.defineProperty(n,r,{configurable:!0,enumerable:!0,get(){const s=i.call(this);return this[r]=s,s},set(s){Object.defineProperty(this,r,{configurable:!0,enumerable:!0,value:s,writable:!0})}})}Ir.prop=e;function t(n){let r;return()=>(r!==void 0||(r=n()),r)}return Ir.value=t,Ir}var Of;function Ey(){if(Of)return Xi;Of=1,Object.defineProperty(Xi,"__esModule",{value:!0}),Xi.p2data=void 0;const e=cn(),t=kt(),n=vt(),r=Wn(),i=t.OPS;function s(o,c){if(!o.data&&!o.output)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),data:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))},o);const u={name:"embed",network:o.network||e.bitcoin};if(r.prop(u,"output",()=>{if(o.data)return t.compile([i.OP_RETURN].concat(o.data))}),r.prop(u,"data",()=>{if(o.output)return t.decompile(o.output).slice(1)}),c.validate&&o.output){const l=t.decompile(o.output);if(l[0]!==i.OP_RETURN)throw new TypeError("Output is invalid");if(!l.slice(1).every(n.typeforce.Buffer))throw new TypeError("Output is invalid");if(o.data&&!(0,n.stacksEqual)(o.data,u.data))throw new TypeError("Data mismatch")}return Object.assign(u,o)}return Xi.p2data=s,Xi}var Yi={},Nf;function _y(){if(Nf)return Yi;Nf=1,Object.defineProperty(Yi,"__esModule",{value:!0}),Yi.p2ms=void 0;const e=cn(),t=kt(),n=vt(),r=Wn(),i=t.OPS,s=i.OP_RESERVED;function o(c,a){if(!c.input&&!c.output&&!(c.pubkeys&&c.m!==void 0)&&!c.signatures)throw new TypeError("Not enough data");a=Object.assign({validate:!0},a||{});function u(g){return t.isCanonicalScriptSignature(g)||(a.allowIncomplete&&g===i.OP_0)!==void 0}(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),m:n.typeforce.maybe(n.typeforce.Number),n:n.typeforce.maybe(n.typeforce.Number),output:n.typeforce.maybe(n.typeforce.Buffer),pubkeys:n.typeforce.maybe(n.typeforce.arrayOf(n.isPoint)),signatures:n.typeforce.maybe(n.typeforce.arrayOf(u)),input:n.typeforce.maybe(n.typeforce.Buffer)},c);const h={network:c.network||e.bitcoin};let y=[],p=!1;function m(g){p||(p=!0,y=t.decompile(g),h.m=y[0]-s,h.n=y[y.length-2]-s,h.pubkeys=y.slice(1,-2))}if(r.prop(h,"output",()=>{if(c.m&&h.n&&c.pubkeys)return t.compile([].concat(s+c.m,c.pubkeys,s+h.n,i.OP_CHECKMULTISIG))}),r.prop(h,"m",()=>{if(h.output)return m(h.output),h.m}),r.prop(h,"n",()=>{if(h.pubkeys)return h.pubkeys.length}),r.prop(h,"pubkeys",()=>{if(c.output)return m(c.output),h.pubkeys}),r.prop(h,"signatures",()=>{if(c.input)return t.decompile(c.input).slice(1)}),r.prop(h,"input",()=>{if(c.signatures)return t.compile([i.OP_0].concat(c.signatures))}),r.prop(h,"witness",()=>{if(h.input)return[]}),r.prop(h,"name",()=>{if(!(!h.m||!h.n))return`p2ms(${h.m} of ${h.n})`}),a.validate){if(c.output){if(m(c.output),!n.typeforce.Number(y[0]))throw new TypeError("Output is invalid");if(!n.typeforce.Number(y[y.length-2]))throw new TypeError("Output is invalid");if(y[y.length-1]!==i.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(h.m<=0||h.n>16||h.m>h.n||h.n!==y.length-3)throw new TypeError("Output is invalid");if(!h.pubkeys.every(g=>(0,n.isPoint)(g)))throw new TypeError("Output is invalid");if(c.m!==void 0&&c.m!==h.m)throw new TypeError("m mismatch");if(c.n!==void 0&&c.n!==h.n)throw new TypeError("n mismatch");if(c.pubkeys&&!(0,n.stacksEqual)(c.pubkeys,h.pubkeys))throw new TypeError("Pubkeys mismatch")}if(c.pubkeys){if(c.n!==void 0&&c.n!==c.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(h.n=c.pubkeys.length,h.n<h.m)throw new TypeError("Pubkey count cannot be less than m")}if(c.signatures){if(c.signatures.length<h.m)throw new TypeError("Not enough signatures provided");if(c.signatures.length>h.m)throw new TypeError("Too many signatures provided")}if(c.input){if(c.input[0]!==i.OP_0)throw new TypeError("Input is invalid");if(h.signatures.length===0||!h.signatures.every(u))throw new TypeError("Input has invalid signature(s)");if(c.signatures&&!(0,n.stacksEqual)(c.signatures,h.signatures))throw new TypeError("Signature mismatch");if(c.m!==void 0&&c.m!==c.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(h,c)}return Yi.p2ms=o,Yi}var Zi={},Rf;function Sy(){if(Rf)return Zi;Rf=1,Object.defineProperty(Zi,"__esModule",{value:!0}),Zi.p2pk=void 0;const e=cn(),t=kt(),n=vt(),r=Wn(),i=t.OPS;function s(o,c){if(!o.input&&!o.output&&!o.pubkey&&!o.input&&!o.signature)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),pubkey:n.typeforce.maybe(n.isPoint),signature:n.typeforce.maybe(t.isCanonicalScriptSignature),input:n.typeforce.maybe(n.typeforce.Buffer)},o);const a=r.value(()=>t.decompile(o.input)),l={name:"p2pk",network:o.network||e.bitcoin};if(r.prop(l,"output",()=>{if(o.pubkey)return t.compile([o.pubkey,i.OP_CHECKSIG])}),r.prop(l,"pubkey",()=>{if(o.output)return o.output.slice(1,-1)}),r.prop(l,"signature",()=>{if(o.input)return a()[0]}),r.prop(l,"input",()=>{if(o.signature)return t.compile([o.signature])}),r.prop(l,"witness",()=>{if(l.input)return[]}),c.validate){if(o.output){if(o.output[o.output.length-1]!==i.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,n.isPoint)(l.pubkey))throw new TypeError("Output pubkey is invalid");if(o.pubkey&&!o.pubkey.equals(l.pubkey))throw new TypeError("Pubkey mismatch")}if(o.signature&&o.input&&!o.input.equals(l.input))throw new TypeError("Signature mismatch");if(o.input){if(a().length!==1)throw new TypeError("Input is invalid");if(!t.isCanonicalScriptSignature(l.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(l,o)}return Zi.p2pk=s,Zi}var Ji={},Xc={},Or={},Pt={},Bt={},zc={},Qi={},kf;function xy(){return kf||(kf=1,Object.defineProperty(Qi,"__esModule",{value:!0}),Qi.crypto=void 0,Qi.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),Qi}var Pf;function Xn(){return Pf||(Pf=1,(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */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=n,e.anumber=r,e.abytes=i,e.ahash=s,e.aexists=o,e.aoutput=c,e.u8=a,e.u32=u,e.clean=l,e.createView=h,e.rotr=y,e.rotl=p,e.byteSwap=m,e.byteSwap32=g,e.bytesToHex=_,e.hexToBytes=R,e.asyncLoop=P,e.utf8ToBytes=q,e.bytesToUtf8=v,e.toBytes=C,e.kdfInputToBytes=L,e.concatBytes=K,e.checkOpts=U,e.createHasher=k,e.createOptHasher=j,e.createXOFer=F,e.randomBytes=S;const t=xy();function n(I){return I instanceof Uint8Array||ArrayBuffer.isView(I)&&I.constructor.name==="Uint8Array"}function r(I){if(!Number.isSafeInteger(I)||I<0)throw new Error("positive integer expected, got "+I)}function i(I,...M){if(!n(I))throw new Error("Uint8Array expected");if(M.length>0&&!M.includes(I.length))throw new Error("Uint8Array expected of length "+M+", got length="+I.length)}function s(I){if(typeof I!="function"||typeof I.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");r(I.outputLen),r(I.blockLen)}function o(I,M=!0){if(I.destroyed)throw new Error("Hash instance has been destroyed");if(M&&I.finished)throw new Error("Hash#digest() has already been called")}function c(I,M){i(I);const O=M.outputLen;if(I.length<O)throw new Error("digestInto() expects output buffer of length at least "+O)}function a(I){return new Uint8Array(I.buffer,I.byteOffset,I.byteLength)}function u(I){return new Uint32Array(I.buffer,I.byteOffset,Math.floor(I.byteLength/4))}function l(...I){for(let M=0;M<I.length;M++)I[M].fill(0)}function h(I){return new DataView(I.buffer,I.byteOffset,I.byteLength)}function y(I,M){return I<<32-M|I>>>M}function p(I,M){return I<<M|I>>>32-M>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function m(I){return I<<24&4278190080|I<<8&16711680|I>>>8&65280|I>>>24&255}e.swap8IfBE=e.isLE?I=>I:I=>m(I),e.byteSwapIfBE=e.swap8IfBE;function g(I){for(let M=0;M<I.length;M++)I[M]=m(I[M]);return I}e.swap32IfBE=e.isLE?I=>I:g;const E=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",x=Array.from({length:256},(I,M)=>M.toString(16).padStart(2,"0"));function _(I){if(i(I),E)return I.toHex();let M="";for(let O=0;O<I.length;O++)M+=x[I[O]];return M}const w={_0:48,_9:57,A:65,F:70,a:97,f:102};function T(I){if(I>=w._0&&I<=w._9)return I-w._0;if(I>=w.A&&I<=w.F)return I-(w.A-10);if(I>=w.a&&I<=w.f)return I-(w.a-10)}function R(I){if(typeof I!="string")throw new Error("hex string expected, got "+typeof I);if(E)return Uint8Array.fromHex(I);const M=I.length,O=M/2;if(M%2)throw new Error("hex string expected, got unpadded hex of length "+M);const V=new Uint8Array(O);for(let G=0,X=0;G<O;G++,X+=2){const Y=T(I.charCodeAt(X)),ce=T(I.charCodeAt(X+1));if(Y===void 0||ce===void 0){const ue=I[X]+I[X+1];throw new Error('hex string expected, got non-hex character "'+ue+'" at index '+X)}V[G]=Y*16+ce}return V}const B=async()=>{};e.nextTick=B;async function P(I,M,O){let V=Date.now();for(let G=0;G<I;G++){O(G);const X=Date.now()-V;X>=0&&X<M||(await(0,e.nextTick)(),V+=X)}}function q(I){if(typeof I!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(I))}function v(I){return new TextDecoder().decode(I)}function C(I){return typeof I=="string"&&(I=q(I)),i(I),I}function L(I){return typeof I=="string"&&(I=q(I)),i(I),I}function K(...I){let M=0;for(let V=0;V<I.length;V++){const G=I[V];i(G),M+=G.length}const O=new Uint8Array(M);for(let V=0,G=0;V<I.length;V++){const X=I[V];O.set(X,G),G+=X.length}return O}function U(I,M){if(M!==void 0&&{}.toString.call(M)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(I,M)}class D{}e.Hash=D;function k(I){const M=V=>I().update(C(V)).digest(),O=I();return M.outputLen=O.outputLen,M.blockLen=O.blockLen,M.create=()=>I(),M}function j(I){const M=(V,G)=>I(G).update(C(V)).digest(),O=I({});return M.outputLen=O.outputLen,M.blockLen=O.blockLen,M.create=V=>I(V),M}function F(I){const M=(V,G)=>I(G).update(C(V)).digest(),O=I({});return M.outputLen=O.outputLen,M.blockLen=O.blockLen,M.create=V=>I(V),M}e.wrapConstructor=k,e.wrapConstructorWithOpts=j,e.wrapXOFConstructorWithOpts=F;function S(I=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(I));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(I));throw new Error("crypto.getRandomValues must be defined")}})(zc)),zc}var Cf;function Uf(){if(Cf)return Bt;Cf=1,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.SHA512_IV=Bt.SHA384_IV=Bt.SHA224_IV=Bt.SHA256_IV=Bt.HashMD=void 0,Bt.setBigUint64=t,Bt.Chi=n,Bt.Maj=r;const e=Xn();function t(s,o,c,a){if(typeof s.setBigUint64=="function")return s.setBigUint64(o,c,a);const u=BigInt(32),l=BigInt(4294967295),h=Number(c>>u&l),y=Number(c&l),p=a?4:0,m=a?0:4;s.setUint32(o+p,h,a),s.setUint32(o+m,y,a)}function n(s,o,c){return s&o^~s&c}function r(s,o,c){return s&o^s&c^o&c}class i extends e.Hash{constructor(o,c,a,u){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=o,this.outputLen=c,this.padOffset=a,this.isLE=u,this.buffer=new Uint8Array(o),this.view=(0,e.createView)(this.buffer)}update(o){(0,e.aexists)(this),o=(0,e.toBytes)(o),(0,e.abytes)(o);const{view:c,buffer:a,blockLen:u}=this,l=o.length;for(let h=0;h<l;){const y=Math.min(u-this.pos,l-h);if(y===u){const p=(0,e.createView)(o);for(;u<=l-h;h+=u)this.process(p,h);continue}a.set(o.subarray(h,h+y),this.pos),this.pos+=y,h+=y,this.pos===u&&(this.process(c,0),this.pos=0)}return this.length+=o.length,this.roundClean(),this}digestInto(o){(0,e.aexists)(this),(0,e.aoutput)(o,this),this.finished=!0;const{buffer:c,view:a,blockLen:u,isLE:l}=this;let{pos:h}=this;c[h++]=128,(0,e.clean)(this.buffer.subarray(h)),this.padOffset>u-h&&(this.process(a,0),h=0);for(let E=h;E<u;E++)c[E]=0;t(a,u-8,BigInt(this.length*8),l),this.process(a,0);const y=(0,e.createView)(o),p=this.outputLen;if(p%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const m=p/4,g=this.get();if(m>g.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<m;E++)y.setUint32(4*E,g[E],l)}digest(){const{buffer:o,outputLen:c}=this;this.digestInto(o);const a=o.slice(0,c);return this.destroy(),a}_cloneInto(o){o||(o=new this.constructor),o.set(...this.get());const{blockLen:c,buffer:a,length:u,finished:l,destroyed:h,pos:y}=this;return o.destroyed=h,o.finished=l,o.length=u,o.pos=y,u%c&&o.buffer.set(a),o}clone(){return this._cloneInto()}}return Bt.HashMD=i,Bt.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Bt.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Bt.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Bt.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Bt}var Hf;function Ff(){if(Hf)return Pt;Hf=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.ripemd160=Pt.RIPEMD160=Pt.md5=Pt.MD5=Pt.sha1=Pt.SHA1=void 0;const e=Uf(),t=Xn(),n=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),r=new Uint32Array(80);class i extends e.HashMD{constructor(){super(64,20,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0}get(){const{A:v,B:C,C:L,D:K,E:U}=this;return[v,C,L,K,U]}set(v,C,L,K,U){this.A=v|0,this.B=C|0,this.C=L|0,this.D=K|0,this.E=U|0}process(v,C){for(let j=0;j<16;j++,C+=4)r[j]=v.getUint32(C,!1);for(let j=16;j<80;j++)r[j]=(0,t.rotl)(r[j-3]^r[j-8]^r[j-14]^r[j-16],1);let{A:L,B:K,C:U,D,E:k}=this;for(let j=0;j<80;j++){let F,S;j<20?(F=(0,e.Chi)(K,U,D),S=1518500249):j<40?(F=K^U^D,S=1859775393):j<60?(F=(0,e.Maj)(K,U,D),S=2400959708):(F=K^U^D,S=3395469782);const I=(0,t.rotl)(L,5)+F+k+S+r[j]|0;k=D,D=U,U=(0,t.rotl)(K,30),K=L,L=I}L=L+this.A|0,K=K+this.B|0,U=U+this.C|0,D=D+this.D|0,k=k+this.E|0,this.set(L,K,U,D,k)}roundClean(){(0,t.clean)(r)}destroy(){this.set(0,0,0,0,0),(0,t.clean)(this.buffer)}}Pt.SHA1=i,Pt.sha1=(0,t.createHasher)(()=>new i);const s=Math.pow(2,32),o=Array.from({length:64},(q,v)=>Math.floor(s*Math.abs(Math.sin(v+1)))),c=n.slice(0,4),a=new Uint32Array(16);class u extends e.HashMD{constructor(){super(64,16,8,!0),this.A=c[0]|0,this.B=c[1]|0,this.C=c[2]|0,this.D=c[3]|0}get(){const{A:v,B:C,C:L,D:K}=this;return[v,C,L,K]}set(v,C,L,K){this.A=v|0,this.B=C|0,this.C=L|0,this.D=K|0}process(v,C){for(let k=0;k<16;k++,C+=4)a[k]=v.getUint32(C,!0);let{A:L,B:K,C:U,D}=this;for(let k=0;k<64;k++){let j,F,S;k<16?(j=(0,e.Chi)(K,U,D),F=k,S=[7,12,17,22]):k<32?(j=(0,e.Chi)(D,K,U),F=(5*k+1)%16,S=[5,9,14,20]):k<48?(j=K^U^D,F=(3*k+5)%16,S=[4,11,16,23]):(j=U^(K|~D),F=7*k%16,S=[6,10,15,21]),j=j+L+o[k]+a[F],L=D,D=U,U=K,K=K+(0,t.rotl)(j,S[k%4])}L=L+this.A|0,K=K+this.B|0,U=U+this.C|0,D=D+this.D|0,this.set(L,K,U,D)}roundClean(){(0,t.clean)(a)}destroy(){this.set(0,0,0,0),(0,t.clean)(this.buffer)}}Pt.MD5=u,Pt.md5=(0,t.createHasher)(()=>new u);const l=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),h=Uint8Array.from(new Array(16).fill(0).map((q,v)=>v)),y=h.map(q=>(9*q+5)%16),p=(()=>{const C=[[h],[y]];for(let L=0;L<4;L++)for(let K of C)K.push(K[L].map(U=>l[U]));return C})(),m=p[0],g=p[1],E=[[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(q=>Uint8Array.from(q)),x=m.map((q,v)=>q.map(C=>E[v][C])),_=g.map((q,v)=>q.map(C=>E[v][C])),w=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),T=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function R(q,v,C,L){return q===0?v^C^L:q===1?v&C|~v&L:q===2?(v|~C)^L:q===3?v&L|C&~L:v^(C|~L)}const B=new Uint32Array(16);class P 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:v,h1:C,h2:L,h3:K,h4:U}=this;return[v,C,L,K,U]}set(v,C,L,K,U){this.h0=v|0,this.h1=C|0,this.h2=L|0,this.h3=K|0,this.h4=U|0}process(v,C){for(let O=0;O<16;O++,C+=4)B[O]=v.getUint32(C,!0);let L=this.h0|0,K=L,U=this.h1|0,D=U,k=this.h2|0,j=k,F=this.h3|0,S=F,I=this.h4|0,M=I;for(let O=0;O<5;O++){const V=4-O,G=w[O],X=T[O],Y=m[O],ce=g[O],ue=x[O],te=_[O];for(let Z=0;Z<16;Z++){const ae=(0,t.rotl)(L+R(O,U,k,F)+B[Y[Z]]+G,ue[Z])+I|0;L=I,I=F,F=(0,t.rotl)(k,10)|0,k=U,U=ae}for(let Z=0;Z<16;Z++){const ae=(0,t.rotl)(K+R(V,D,j,S)+B[ce[Z]]+X,te[Z])+M|0;K=M,M=S,S=(0,t.rotl)(j,10)|0,j=D,D=ae}}this.set(this.h1+k+S|0,this.h2+F+M|0,this.h3+I+K|0,this.h4+L+D|0,this.h0+U+j|0)}roundClean(){(0,t.clean)(B)}destroy(){this.destroyed=!0,(0,t.clean)(this.buffer),this.set(0,0,0,0,0)}}return Pt.RIPEMD160=P,Pt.ripemd160=(0,t.createHasher)(()=>new P),Pt}var qf;function Ty(){if(qf)return Or;qf=1,Object.defineProperty(Or,"__esModule",{value:!0}),Or.ripemd160=Or.RIPEMD160=void 0;const e=Ff();return Or.RIPEMD160=e.RIPEMD160,Or.ripemd160=e.ripemd160,Or}var Nr={},Mf;function vy(){if(Mf)return Nr;Mf=1,Object.defineProperty(Nr,"__esModule",{value:!0}),Nr.sha1=Nr.SHA1=void 0;const e=Ff();return Nr.SHA1=e.SHA1,Nr.sha1=e.sha1,Nr}var an={},De={},Se={},Lf;function By(){if(Lf)return Se;Lf=1,Object.defineProperty(Se,"__esModule",{value:!0}),Se.toBig=Se.shrSL=Se.shrSH=Se.rotrSL=Se.rotrSH=Se.rotrBL=Se.rotrBH=Se.rotr32L=Se.rotr32H=Se.rotlSL=Se.rotlSH=Se.rotlBL=Se.rotlBH=Se.add5L=Se.add5H=Se.add4L=Se.add4H=Se.add3L=Se.add3H=void 0,Se.add=x,Se.fromBig=n,Se.split=r;const e=BigInt(2**32-1),t=BigInt(32);function n(v,C=!1){return C?{h:Number(v&e),l:Number(v>>t&e)}:{h:Number(v>>t&e)|0,l:Number(v&e)|0}}function r(v,C=!1){const L=v.length;let K=new Uint32Array(L),U=new Uint32Array(L);for(let D=0;D<L;D++){const{h:k,l:j}=n(v[D],C);[K[D],U[D]]=[k,j]}return[K,U]}const i=(v,C)=>BigInt(v>>>0)<<t|BigInt(C>>>0);Se.toBig=i;const s=(v,C,L)=>v>>>L;Se.shrSH=s;const o=(v,C,L)=>v<<32-L|C>>>L;Se.shrSL=o;const c=(v,C,L)=>v>>>L|C<<32-L;Se.rotrSH=c;const a=(v,C,L)=>v<<32-L|C>>>L;Se.rotrSL=a;const u=(v,C,L)=>v<<64-L|C>>>L-32;Se.rotrBH=u;const l=(v,C,L)=>v>>>L-32|C<<64-L;Se.rotrBL=l;const h=(v,C)=>C;Se.rotr32H=h;const y=(v,C)=>v;Se.rotr32L=y;const p=(v,C,L)=>v<<L|C>>>32-L;Se.rotlSH=p;const m=(v,C,L)=>C<<L|v>>>32-L;Se.rotlSL=m;const g=(v,C,L)=>C<<L-32|v>>>64-L;Se.rotlBH=g;const E=(v,C,L)=>v<<L-32|C>>>64-L;Se.rotlBL=E;function x(v,C,L,K){const U=(C>>>0)+(K>>>0);return{h:v+L+(U/2**32|0)|0,l:U|0}}const _=(v,C,L)=>(v>>>0)+(C>>>0)+(L>>>0);Se.add3L=_;const w=(v,C,L,K)=>C+L+K+(v/2**32|0)|0;Se.add3H=w;const T=(v,C,L,K)=>(v>>>0)+(C>>>0)+(L>>>0)+(K>>>0);Se.add4L=T;const R=(v,C,L,K,U)=>C+L+K+U+(v/2**32|0)|0;Se.add4H=R;const B=(v,C,L,K,U)=>(v>>>0)+(C>>>0)+(L>>>0)+(K>>>0)+(U>>>0);Se.add5L=B;const P=(v,C,L,K,U,D)=>C+L+K+U+D+(v/2**32|0)|0;Se.add5H=P;const q={fromBig:n,split:r,toBig:i,shrSH:s,shrSL:o,rotrSH:c,rotrSL:a,rotrBH:u,rotrBL:l,rotr32H:h,rotr32L:y,rotlSH:p,rotlSL:m,rotlBH:g,rotlBL:E,add:x,add3L:_,add3H:w,add4L:T,add4H:R,add5H:P,add5L:B};return Se.default=q,Se}var Vf;function Df(){if(Vf)return De;Vf=1,Object.defineProperty(De,"__esModule",{value:!0}),De.sha512_224=De.sha512_256=De.sha384=De.sha512=De.sha224=De.sha256=De.SHA512_256=De.SHA512_224=De.SHA384=De.SHA512=De.SHA224=De.SHA256=void 0;const e=Uf(),t=By(),n=Xn(),r=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 s extends e.HashMD{constructor(w=32){super(64,w,8,!1),this.A=e.SHA256_IV[0]|0,this.B=e.SHA256_IV[1]|0,this.C=e.SHA256_IV[2]|0,this.D=e.SHA256_IV[3]|0,this.E=e.SHA256_IV[4]|0,this.F=e.SHA256_IV[5]|0,this.G=e.SHA256_IV[6]|0,this.H=e.SHA256_IV[7]|0}get(){const{A:w,B:T,C:R,D:B,E:P,F:q,G:v,H:C}=this;return[w,T,R,B,P,q,v,C]}set(w,T,R,B,P,q,v,C){this.A=w|0,this.B=T|0,this.C=R|0,this.D=B|0,this.E=P|0,this.F=q|0,this.G=v|0,this.H=C|0}process(w,T){for(let U=0;U<16;U++,T+=4)i[U]=w.getUint32(T,!1);for(let U=16;U<64;U++){const D=i[U-15],k=i[U-2],j=(0,n.rotr)(D,7)^(0,n.rotr)(D,18)^D>>>3,F=(0,n.rotr)(k,17)^(0,n.rotr)(k,19)^k>>>10;i[U]=F+i[U-7]+j+i[U-16]|0}let{A:R,B,C:P,D:q,E:v,F:C,G:L,H:K}=this;for(let U=0;U<64;U++){const D=(0,n.rotr)(v,6)^(0,n.rotr)(v,11)^(0,n.rotr)(v,25),k=K+D+(0,e.Chi)(v,C,L)+r[U]+i[U]|0,F=((0,n.rotr)(R,2)^(0,n.rotr)(R,13)^(0,n.rotr)(R,22))+(0,e.Maj)(R,B,P)|0;K=L,L=C,C=v,v=q+k|0,q=P,P=B,B=R,R=k+F|0}R=R+this.A|0,B=B+this.B|0,P=P+this.C|0,q=q+this.D|0,v=v+this.E|0,C=C+this.F|0,L=L+this.G|0,K=K+this.H|0,this.set(R,B,P,q,v,C,L,K)}roundClean(){(0,n.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}De.SHA256=s;class o extends s{constructor(){super(28),this.A=e.SHA224_IV[0]|0,this.B=e.SHA224_IV[1]|0,this.C=e.SHA224_IV[2]|0,this.D=e.SHA224_IV[3]|0,this.E=e.SHA224_IV[4]|0,this.F=e.SHA224_IV[5]|0,this.G=e.SHA224_IV[6]|0,this.H=e.SHA224_IV[7]|0}}De.SHA224=o;const c=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(_=>BigInt(_))),a=c[0],u=c[1],l=new Uint32Array(80),h=new Uint32Array(80);class y extends e.HashMD{constructor(w=64){super(128,w,16,!1),this.Ah=e.SHA512_IV[0]|0,this.Al=e.SHA512_IV[1]|0,this.Bh=e.SHA512_IV[2]|0,this.Bl=e.SHA512_IV[3]|0,this.Ch=e.SHA512_IV[4]|0,this.Cl=e.SHA512_IV[5]|0,this.Dh=e.SHA512_IV[6]|0,this.Dl=e.SHA512_IV[7]|0,this.Eh=e.SHA512_IV[8]|0,this.El=e.SHA512_IV[9]|0,this.Fh=e.SHA512_IV[10]|0,this.Fl=e.SHA512_IV[11]|0,this.Gh=e.SHA512_IV[12]|0,this.Gl=e.SHA512_IV[13]|0,this.Hh=e.SHA512_IV[14]|0,this.Hl=e.SHA512_IV[15]|0}get(){const{Ah:w,Al:T,Bh:R,Bl:B,Ch:P,Cl:q,Dh:v,Dl:C,Eh:L,El:K,Fh:U,Fl:D,Gh:k,Gl:j,Hh:F,Hl:S}=this;return[w,T,R,B,P,q,v,C,L,K,U,D,k,j,F,S]}set(w,T,R,B,P,q,v,C,L,K,U,D,k,j,F,S){this.Ah=w|0,this.Al=T|0,this.Bh=R|0,this.Bl=B|0,this.Ch=P|0,this.Cl=q|0,this.Dh=v|0,this.Dl=C|0,this.Eh=L|0,this.El=K|0,this.Fh=U|0,this.Fl=D|0,this.Gh=k|0,this.Gl=j|0,this.Hh=F|0,this.Hl=S|0}process(w,T){for(let O=0;O<16;O++,T+=4)l[O]=w.getUint32(T),h[O]=w.getUint32(T+=4);for(let O=16;O<80;O++){const V=l[O-15]|0,G=h[O-15]|0,X=t.rotrSH(V,G,1)^t.rotrSH(V,G,8)^t.shrSH(V,G,7),Y=t.rotrSL(V,G,1)^t.rotrSL(V,G,8)^t.shrSL(V,G,7),ce=l[O-2]|0,ue=h[O-2]|0,te=t.rotrSH(ce,ue,19)^t.rotrBH(ce,ue,61)^t.shrSH(ce,ue,6),Z=t.rotrSL(ce,ue,19)^t.rotrBL(ce,ue,61)^t.shrSL(ce,ue,6),ae=t.add4L(Y,Z,h[O-7],h[O-16]),ge=t.add4H(ae,X,te,l[O-7],l[O-16]);l[O]=ge|0,h[O]=ae|0}let{Ah:R,Al:B,Bh:P,Bl:q,Ch:v,Cl:C,Dh:L,Dl:K,Eh:U,El:D,Fh:k,Fl:j,Gh:F,Gl:S,Hh:I,Hl:M}=this;for(let O=0;O<80;O++){const V=t.rotrSH(U,D,14)^t.rotrSH(U,D,18)^t.rotrBH(U,D,41),G=t.rotrSL(U,D,14)^t.rotrSL(U,D,18)^t.rotrBL(U,D,41),X=U&k^~U&F,Y=D&j^~D&S,ce=t.add5L(M,G,Y,u[O],h[O]),ue=t.add5H(ce,I,V,X,a[O],l[O]),te=ce|0,Z=t.rotrSH(R,B,28)^t.rotrBH(R,B,34)^t.rotrBH(R,B,39),ae=t.rotrSL(R,B,28)^t.rotrBL(R,B,34)^t.rotrBL(R,B,39),ge=R&P^R&v^P&v,pe=B&q^B&C^q&C;I=F|0,M=S|0,F=k|0,S=j|0,k=U|0,j=D|0,{h:U,l:D}=t.add(L|0,K|0,ue|0,te|0),L=v|0,K=C|0,v=P|0,C=q|0,P=R|0,q=B|0;const J=t.add3L(te,ae,pe);R=t.add3H(J,ue,Z,ge),B=J|0}({h:R,l:B}=t.add(this.Ah|0,this.Al|0,R|0,B|0)),{h:P,l:q}=t.add(this.Bh|0,this.Bl|0,P|0,q|0),{h:v,l:C}=t.add(this.Ch|0,this.Cl|0,v|0,C|0),{h:L,l:K}=t.add(this.Dh|0,this.Dl|0,L|0,K|0),{h:U,l:D}=t.add(this.Eh|0,this.El|0,U|0,D|0),{h:k,l:j}=t.add(this.Fh|0,this.Fl|0,k|0,j|0),{h:F,l:S}=t.add(this.Gh|0,this.Gl|0,F|0,S|0),{h:I,l:M}=t.add(this.Hh|0,this.Hl|0,I|0,M|0),this.set(R,B,P,q,v,C,L,K,U,D,k,j,F,S,I,M)}roundClean(){(0,n.clean)(l,h)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}De.SHA512=y;class p extends y{constructor(){super(48),this.Ah=e.SHA384_IV[0]|0,this.Al=e.SHA384_IV[1]|0,this.Bh=e.SHA384_IV[2]|0,this.Bl=e.SHA384_IV[3]|0,this.Ch=e.SHA384_IV[4]|0,this.Cl=e.SHA384_IV[5]|0,this.Dh=e.SHA384_IV[6]|0,this.Dl=e.SHA384_IV[7]|0,this.Eh=e.SHA384_IV[8]|0,this.El=e.SHA384_IV[9]|0,this.Fh=e.SHA384_IV[10]|0,this.Fl=e.SHA384_IV[11]|0,this.Gh=e.SHA384_IV[12]|0,this.Gl=e.SHA384_IV[13]|0,this.Hh=e.SHA384_IV[14]|0,this.Hl=e.SHA384_IV[15]|0}}De.SHA384=p;const m=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),g=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class E extends y{constructor(){super(28),this.Ah=m[0]|0,this.Al=m[1]|0,this.Bh=m[2]|0,this.Bl=m[3]|0,this.Ch=m[4]|0,this.Cl=m[5]|0,this.Dh=m[6]|0,this.Dl=m[7]|0,this.Eh=m[8]|0,this.El=m[9]|0,this.Fh=m[10]|0,this.Fl=m[11]|0,this.Gh=m[12]|0,this.Gl=m[13]|0,this.Hh=m[14]|0,this.Hl=m[15]|0}}De.SHA512_224=E;class x extends y{constructor(){super(32),this.Ah=g[0]|0,this.Al=g[1]|0,this.Bh=g[2]|0,this.Bl=g[3]|0,this.Ch=g[4]|0,this.Cl=g[5]|0,this.Dh=g[6]|0,this.Dl=g[7]|0,this.Eh=g[8]|0,this.El=g[9]|0,this.Fh=g[10]|0,this.Fl=g[11]|0,this.Gh=g[12]|0,this.Gl=g[13]|0,this.Hh=g[14]|0,this.Hl=g[15]|0}}return De.SHA512_256=x,De.sha256=(0,n.createHasher)(()=>new s),De.sha224=(0,n.createHasher)(()=>new o),De.sha512=(0,n.createHasher)(()=>new y),De.sha384=(0,n.createHasher)(()=>new p),De.sha512_256=(0,n.createHasher)(()=>new x),De.sha512_224=(0,n.createHasher)(()=>new E),De}var jf;function $f(){if(jf)return an;jf=1,Object.defineProperty(an,"__esModule",{value:!0}),an.sha224=an.SHA224=an.sha256=an.SHA256=void 0;const e=Df();return an.SHA256=e.SHA256,an.sha256=e.sha256,an.SHA224=e.SHA224,an.sha224=e.sha224,an}var Kf;function Nn(){return Kf||(Kf=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=Ty(),n=vy(),r=$f();function i(l){return Buffer.from((0,t.ripemd160)(Uint8Array.from(l)))}e.ripemd160=i;function s(l){return Buffer.from((0,n.sha1)(Uint8Array.from(l)))}e.sha1=s;function o(l){return Buffer.from((0,r.sha256)(Uint8Array.from(l)))}e.sha256=o;function c(l){return Buffer.from((0,t.ripemd160)((0,r.sha256)(Uint8Array.from(l))))}e.hash160=c;function a(l){return Buffer.from((0,r.sha256)((0,r.sha256)(Uint8Array.from(l))))}e.hash256=a,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.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":Buffer.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":Buffer.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:Buffer.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:Buffer.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:Buffer.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:Buffer.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":Buffer.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":Buffer.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 u(l,h){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[l],h]))}e.taggedHash=u})(Xc)),Xc}var Yc,Gf;function Ay(){if(Gf)return Yc;Gf=1;function e(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function h(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,E=0,x=0,_=m.length;x!==_&&m[x]===0;)x++,g++;for(var w=(_-x)*l+1>>>0,T=new Uint8Array(w);x!==_;){for(var R=m[x],B=0,P=w-1;(R!==0||B<E)&&P!==-1;P--,B++)R+=256*T[P]>>>0,T[P]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");E=B,x++}for(var q=w-E;q!==w&&T[q]===0;)q++;for(var v=a.repeat(g);q<w;++q)v+=t.charAt(T[q]);return v}function y(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;for(var g=0,E=0,x=0;m[g]===a;)E++,g++;for(var _=(m.length-g)*u+1>>>0,w=new Uint8Array(_);m[g];){var T=m.charCodeAt(g);if(T>255)return;var R=n[T];if(R===255)return;for(var B=0,P=_-1;(R!==0||B<x)&&P!==-1;P--,B++)R+=c*w[P]>>>0,w[P]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");x=B,g++}for(var q=_-x;q!==_&&w[q]===0;)q++;for(var v=new Uint8Array(E+(_-q)),C=E;q!==_;)v[C++]=w[q++];return v}function p(m){var g=y(m);if(g)return g;throw new Error("Non-base"+c+" character")}return{encode:h,decodeUnsafe:y,decode:p}}return Yc=e,Yc}var Zc,Wf;function Iy(){return Wf||(Wf=1,Zc=Ay()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")),Zc}var Jc,Xf;function Oy(){if(Xf)return Jc;Xf=1;var e=Iy();return Jc=function(t){function n(o){var c=Uint8Array.from(o),a=t(c),u=c.length+4,l=new Uint8Array(u);return l.set(c,0),l.set(a.subarray(0,4),c.length),e.encode(l,u)}function r(o){var c=o.slice(0,-4),a=o.slice(-4),u=t(c);if(!(a[0]^u[0]|a[1]^u[1]|a[2]^u[2]|a[3]^u[3]))return c}function i(o){var c=e.decodeUnsafe(o);if(c)return r(c)}function s(o){var c=e.decode(o),a=r(c);if(!a)throw new Error("Invalid checksum");return a}return{encode:n,decode:s,decodeUnsafe:i}},Jc}var Qc,zf;function ea(){if(zf)return Qc;zf=1;var{sha256:e}=$f(),t=Oy();function n(r){return e(e(r))}return Qc=t(n),Qc}var Yf;function Ny(){if(Yf)return Ji;Yf=1,Object.defineProperty(Ji,"__esModule",{value:!0}),Ji.p2pkh=void 0;const e=Nn(),t=cn(),n=kt(),r=vt(),i=Wn(),s=ea(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.pubkey&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(25)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),input:r.typeforce.maybe(r.typeforce.Buffer)},a);const l=i.value(()=>{const m=Buffer.from(s.decode(a.address)),g=m.readUInt8(0),E=m.slice(1);return{version:g,hash:E}}),h=i.value(()=>n.decompile(a.input)),y=a.network||t.bitcoin,p={name:"p2pkh",network:y};if(i.prop(p,"address",()=>{if(!p.hash)return;const m=Buffer.allocUnsafe(21);return m.writeUInt8(y.pubKeyHash,0),p.hash.copy(m,1),s.encode(m)}),i.prop(p,"hash",()=>{if(a.output)return a.output.slice(3,23);if(a.address)return l().hash;if(a.pubkey||p.pubkey)return e.hash160(a.pubkey||p.pubkey)}),i.prop(p,"output",()=>{if(p.hash)return n.compile([o.OP_DUP,o.OP_HASH160,p.hash,o.OP_EQUALVERIFY,o.OP_CHECKSIG])}),i.prop(p,"pubkey",()=>{if(a.input)return h()[1]}),i.prop(p,"signature",()=>{if(a.input)return h()[0]}),i.prop(p,"input",()=>{if(a.pubkey&&a.signature)return n.compile([a.signature,a.pubkey])}),i.prop(p,"witness",()=>{if(p.input)return[]}),u.validate){let m=Buffer.from([]);if(a.address){if(l().version!==y.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(l().hash.length!==20)throw new TypeError("Invalid address");m=l().hash}if(a.hash){if(m.length>0&&!m.equals(a.hash))throw new TypeError("Hash mismatch");m=a.hash}if(a.output){if(a.output.length!==25||a.output[0]!==o.OP_DUP||a.output[1]!==o.OP_HASH160||a.output[2]!==20||a.output[23]!==o.OP_EQUALVERIFY||a.output[24]!==o.OP_CHECKSIG)throw new TypeError("Output is invalid");const g=a.output.slice(3,23);if(m.length>0&&!m.equals(g))throw new TypeError("Hash mismatch");m=g}if(a.pubkey){const g=e.hash160(a.pubkey);if(m.length>0&&!m.equals(g))throw new TypeError("Hash mismatch");m=g}if(a.input){const g=h();if(g.length!==2)throw new TypeError("Input is invalid");if(!n.isCanonicalScriptSignature(g[0]))throw new TypeError("Input has invalid signature");if(!(0,r.isPoint)(g[1]))throw new TypeError("Input has invalid pubkey");if(a.signature&&!a.signature.equals(g[0]))throw new TypeError("Signature mismatch");if(a.pubkey&&!a.pubkey.equals(g[1]))throw new TypeError("Pubkey mismatch");const E=e.hash160(g[1]);if(m.length>0&&!m.equals(E))throw new TypeError("Hash mismatch")}}return Object.assign(p,a)}return Ji.p2pkh=c,Ji}var es={},Zf;function Ry(){if(Zf)return es;Zf=1,Object.defineProperty(es,"__esModule",{value:!0}),es.p2sh=void 0;const e=Nn(),t=cn(),n=kt(),r=vt(),i=Wn(),s=ea(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.redeem&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(23)),redeem:r.typeforce.maybe({network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},a);let l=a.network;l||(l=a.redeem&&a.redeem.network||t.bitcoin);const h={network:l},y=i.value(()=>{const g=Buffer.from(s.decode(a.address)),E=g.readUInt8(0),x=g.slice(1);return{version:E,hash:x}}),p=i.value(()=>n.decompile(a.input)),m=i.value(()=>{const g=p(),E=g[g.length-1];return{network:l,output:E===o.OP_FALSE?Buffer.from([]):E,input:n.compile(g.slice(0,-1)),witness:a.witness||[]}});if(i.prop(h,"address",()=>{if(!h.hash)return;const g=Buffer.allocUnsafe(21);return g.writeUInt8(h.network.scriptHash,0),h.hash.copy(g,1),s.encode(g)}),i.prop(h,"hash",()=>{if(a.output)return a.output.slice(2,22);if(a.address)return y().hash;if(h.redeem&&h.redeem.output)return e.hash160(h.redeem.output)}),i.prop(h,"output",()=>{if(h.hash)return n.compile([o.OP_HASH160,h.hash,o.OP_EQUAL])}),i.prop(h,"redeem",()=>{if(a.input)return m()}),i.prop(h,"input",()=>{if(!(!a.redeem||!a.redeem.input||!a.redeem.output))return n.compile([].concat(n.decompile(a.redeem.input),a.redeem.output))}),i.prop(h,"witness",()=>{if(h.redeem&&h.redeem.witness)return h.redeem.witness;if(h.input)return[]}),i.prop(h,"name",()=>{const g=["p2sh"];return h.redeem!==void 0&&h.redeem.name!==void 0&&g.push(h.redeem.name),g.join("-")}),u.validate){let g=Buffer.from([]);if(a.address){if(y().version!==l.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(y().hash.length!==20)throw new TypeError("Invalid address");g=y().hash}if(a.hash){if(g.length>0&&!g.equals(a.hash))throw new TypeError("Hash mismatch");g=a.hash}if(a.output){if(a.output.length!==23||a.output[0]!==o.OP_HASH160||a.output[1]!==20||a.output[22]!==o.OP_EQUAL)throw new TypeError("Output is invalid");const x=a.output.slice(2,22);if(g.length>0&&!g.equals(x))throw new TypeError("Hash mismatch");g=x}const E=x=>{if(x.output){const _=n.decompile(x.output);if(!_||_.length<1)throw new TypeError("Redeem.output too short");if(x.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(n.countNonPushOnlyOPs(_)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const w=e.hash160(x.output);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");g=w}if(x.input){const _=x.input.length>0,w=x.witness&&x.witness.length>0;if(!_&&!w)throw new TypeError("Empty input");if(_&&w)throw new TypeError("Input and witness provided");if(_){const T=n.decompile(x.input);if(!n.isPushOnly(T))throw new TypeError("Non push-only scriptSig")}}};if(a.input){const x=p();if(!x||x.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(m().output))throw new TypeError("Input is invalid");E(m())}if(a.redeem){if(a.redeem.network&&a.redeem.network!==l)throw new TypeError("Network mismatch");if(a.input){const x=m();if(a.redeem.output&&!a.redeem.output.equals(x.output))throw new TypeError("Redeem.output mismatch");if(a.redeem.input&&!a.redeem.input.equals(x.input))throw new TypeError("Redeem.input mismatch")}E(a.redeem)}if(a.witness&&a.redeem&&a.redeem.witness&&!(0,r.stacksEqual)(a.redeem.witness,a.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(h,a)}return es.p2sh=c,es}var ts={},Rr={},Jf;function ao(){if(Jf)return Rr;Jf=1,Object.defineProperty(Rr,"__esModule",{value:!0}),Rr.bech32m=Rr.bech32=void 0;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",t={};for(let u=0;u<e.length;u++){const l=e.charAt(u);t[l]=u}function n(u){const l=u>>25;return(u&33554431)<<5^-(l>>0&1)&996825010^-(l>>1&1)&642813549^-(l>>2&1)&513874426^-(l>>3&1)&1027748829^-(l>>4&1)&705979059}function r(u){let l=1;for(let h=0;h<u.length;++h){const y=u.charCodeAt(h);if(y<33||y>126)return"Invalid prefix ("+u+")";l=n(l)^y>>5}l=n(l);for(let h=0;h<u.length;++h){const y=u.charCodeAt(h);l=n(l)^y&31}return l}function i(u,l,h,y){let p=0,m=0;const g=(1<<h)-1,E=[];for(let x=0;x<u.length;++x)for(p=p<<l|u[x],m+=l;m>=h;)m-=h,E.push(p>>m&g);if(y)m>0&&E.push(p<<h-m&g);else{if(m>=l)return"Excess padding";if(p<<h-m&g)return"Non-zero padding"}return E}function s(u){return i(u,8,5,!0)}function o(u){const l=i(u,5,8,!1);if(Array.isArray(l))return l}function c(u){const l=i(u,5,8,!1);if(Array.isArray(l))return l;throw new Error(l)}function a(u){let l;u==="bech32"?l=1:l=734539939;function h(g,E,x){if(x=x||90,g.length+7+E.length>x)throw new TypeError("Exceeds length limit");g=g.toLowerCase();let _=r(g);if(typeof _=="string")throw new Error(_);let w=g+"1";for(let T=0;T<E.length;++T){const R=E[T];if(R>>5!==0)throw new Error("Non 5-bit word");_=n(_)^R,w+=e.charAt(R)}for(let T=0;T<6;++T)_=n(_);_^=l;for(let T=0;T<6;++T){const R=_>>(5-T)*5&31;w+=e.charAt(R)}return w}function y(g,E){if(E=E||90,g.length<8)return g+" too short";if(g.length>E)return"Exceeds length limit";const x=g.toLowerCase(),_=g.toUpperCase();if(g!==x&&g!==_)return"Mixed-case string "+g;g=x;const w=g.lastIndexOf("1");if(w===-1)return"No separator character for "+g;if(w===0)return"Missing prefix for "+g;const T=g.slice(0,w),R=g.slice(w+1);if(R.length<6)return"Data too short";let B=r(T);if(typeof B=="string")return B;const P=[];for(let q=0;q<R.length;++q){const v=R.charAt(q),C=t[v];if(C===void 0)return"Unknown character "+v;B=n(B)^C,!(q+6>=R.length)&&P.push(C)}return B!==l?"Invalid checksum for "+g:{prefix:T,words:P}}function p(g,E){const x=y(g,E);if(typeof x=="object")return x}function m(g,E){const x=y(g,E);if(typeof x=="object")return x;throw new Error(x)}return{decodeUnsafe:p,decode:m,encode:h,toWords:s,fromWordsUnsafe:o,fromWords:c}}return Rr.bech32=a("bech32"),Rr.bech32m=a("bech32m"),Rr}var Qf;function ky(){if(Qf)return ts;Qf=1,Object.defineProperty(ts,"__esModule",{value:!0}),ts.p2wpkh=void 0;const e=Nn(),t=cn(),n=kt(),r=vt(),i=Wn(),s=ao(),o=n.OPS,c=Buffer.alloc(0);function a(u,l){if(!u.address&&!u.hash&&!u.output&&!u.pubkey&&!u.witness)throw new TypeError("Not enough data");l=Object.assign({validate:!0},l||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(22)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},u);const h=i.value(()=>{const m=s.bech32.decode(u.address),g=m.words.shift(),E=s.bech32.fromWords(m.words);return{version:g,prefix:m.prefix,data:Buffer.from(E)}}),y=u.network||t.bitcoin,p={name:"p2wpkh",network:y};if(i.prop(p,"address",()=>{if(!p.hash)return;const m=s.bech32.toWords(p.hash);return m.unshift(0),s.bech32.encode(y.bech32,m)}),i.prop(p,"hash",()=>{if(u.output)return u.output.slice(2,22);if(u.address)return h().data;if(u.pubkey||p.pubkey)return e.hash160(u.pubkey||p.pubkey)}),i.prop(p,"output",()=>{if(p.hash)return n.compile([o.OP_0,p.hash])}),i.prop(p,"pubkey",()=>{if(u.pubkey)return u.pubkey;if(u.witness)return u.witness[1]}),i.prop(p,"signature",()=>{if(u.witness)return u.witness[0]}),i.prop(p,"input",()=>{if(p.witness)return c}),i.prop(p,"witness",()=>{if(u.pubkey&&u.signature)return[u.signature,u.pubkey]}),l.validate){let m=Buffer.from([]);if(u.address){if(y&&y.bech32!==h().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(h().version!==0)throw new TypeError("Invalid address version");if(h().data.length!==20)throw new TypeError("Invalid address data");m=h().data}if(u.hash){if(m.length>0&&!m.equals(u.hash))throw new TypeError("Hash mismatch");m=u.hash}if(u.output){if(u.output.length!==22||u.output[0]!==o.OP_0||u.output[1]!==20)throw new TypeError("Output is invalid");if(m.length>0&&!m.equals(u.output.slice(2)))throw new TypeError("Hash mismatch");m=u.output.slice(2)}if(u.pubkey){const g=e.hash160(u.pubkey);if(m.length>0&&!m.equals(g))throw new TypeError("Hash mismatch");if(m=g,!(0,r.isPoint)(u.pubkey)||u.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(u.witness){if(u.witness.length!==2)throw new TypeError("Witness is invalid");if(!n.isCanonicalScriptSignature(u.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,r.isPoint)(u.witness[1])||u.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(u.signature&&!u.signature.equals(u.witness[0]))throw new TypeError("Signature mismatch");if(u.pubkey&&!u.pubkey.equals(u.witness[1]))throw new TypeError("Pubkey mismatch");const g=e.hash160(u.witness[1]);if(m.length>0&&!m.equals(g))throw new TypeError("Hash mismatch")}}return Object.assign(p,u)}return ts.p2wpkh=a,ts}var ns={},el;function Py(){if(el)return ns;el=1,Object.defineProperty(ns,"__esModule",{value:!0}),ns.p2wsh=void 0;const e=Nn(),t=cn(),n=kt(),r=vt(),i=Wn(),s=ao(),o=n.OPS,c=Buffer.alloc(0);function a(l){return!!(Buffer.isBuffer(l)&&l.length===65&&l[0]===4&&(0,r.isPoint)(l))}function u(l,h){if(!l.address&&!l.hash&&!l.output&&!l.redeem&&!l.witness)throw new TypeError("Not enough data");h=Object.assign({validate:!0},h||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),output:r.typeforce.maybe(r.typeforce.BufferN(34)),redeem:r.typeforce.maybe({input:r.typeforce.maybe(r.typeforce.Buffer),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.BufferN(0)),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},l);const y=i.value(()=>{const E=s.bech32.decode(l.address),x=E.words.shift(),_=s.bech32.fromWords(E.words);return{version:x,prefix:E.prefix,data:Buffer.from(_)}}),p=i.value(()=>n.decompile(l.redeem.input));let m=l.network;m||(m=l.redeem&&l.redeem.network||t.bitcoin);const g={network:m};if(i.prop(g,"address",()=>{if(!g.hash)return;const E=s.bech32.toWords(g.hash);return E.unshift(0),s.bech32.encode(m.bech32,E)}),i.prop(g,"hash",()=>{if(l.output)return l.output.slice(2);if(l.address)return y().data;if(g.redeem&&g.redeem.output)return e.sha256(g.redeem.output)}),i.prop(g,"output",()=>{if(g.hash)return n.compile([o.OP_0,g.hash])}),i.prop(g,"redeem",()=>{if(l.witness)return{output:l.witness[l.witness.length-1],input:c,witness:l.witness.slice(0,-1)}}),i.prop(g,"input",()=>{if(g.witness)return c}),i.prop(g,"witness",()=>{if(l.redeem&&l.redeem.input&&l.redeem.input.length>0&&l.redeem.output&&l.redeem.output.length>0){const E=n.toStack(p());return g.redeem=Object.assign({witness:E},l.redeem),g.redeem.input=c,[].concat(E,l.redeem.output)}if(l.redeem&&l.redeem.output&&l.redeem.witness)return[].concat(l.redeem.witness,l.redeem.output)}),i.prop(g,"name",()=>{const E=["p2wsh"];return g.redeem!==void 0&&g.redeem.name!==void 0&&E.push(g.redeem.name),E.join("-")}),h.validate){let E=Buffer.from([]);if(l.address){if(y().prefix!==m.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(y().version!==0)throw new TypeError("Invalid address version");if(y().data.length!==32)throw new TypeError("Invalid address data");E=y().data}if(l.hash){if(E.length>0&&!E.equals(l.hash))throw new TypeError("Hash mismatch");E=l.hash}if(l.output){if(l.output.length!==34||l.output[0]!==o.OP_0||l.output[1]!==32)throw new TypeError("Output is invalid");const x=l.output.slice(2);if(E.length>0&&!E.equals(x))throw new TypeError("Hash mismatch");E=x}if(l.redeem){if(l.redeem.network&&l.redeem.network!==m)throw new TypeError("Network mismatch");if(l.redeem.input&&l.redeem.input.length>0&&l.redeem.witness&&l.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(l.redeem.output){const x=n.decompile(l.redeem.output);if(!x||x.length<1)throw new TypeError("Redeem.output is invalid");if(l.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(n.countNonPushOnlyOPs(x)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const _=e.sha256(l.redeem.output);if(E.length>0&&!E.equals(_))throw new TypeError("Hash mismatch");E=_}if(l.redeem.input&&!n.isPushOnly(p()))throw new TypeError("Non push-only scriptSig");if(l.witness&&l.redeem.witness&&!(0,r.stacksEqual)(l.witness,l.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(l.redeem.input&&p().some(a)||l.redeem.output&&(n.decompile(l.redeem.output)||[]).some(a))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(l.witness&&l.witness.length>0){const x=l.witness[l.witness.length-1];if(l.redeem&&l.redeem.output&&!l.redeem.output.equals(x))throw new TypeError("Witness and redeem.output mismatch");if(l.witness.some(a)||(n.decompile(x)||[]).some(a))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(g,l)}return ns.p2wsh=u,ns}var rs={},kr={},tl;function ta(){if(tl)return kr;tl=1,Object.defineProperty(kr,"__esModule",{value:!0}),kr.getEccLib=kr.initEccLib=void 0;const e={};function t(c,a){c?c!==e.eccLib&&(a?.DANGER_DO_NOT_VERIFY_ECCLIB||i(c),e.eccLib=c):e.eccLib=c}kr.initEccLib=t;function n(){if(!e.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return e.eccLib}kr.getEccLib=n;const r=c=>Buffer.from(c,"hex");function i(c){s(typeof c.isXOnlyPoint=="function"),s(c.isXOnlyPoint(r("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),s(c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),s(c.isXOnlyPoint(r("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),s(c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000001"))),s(!c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000000"))),s(!c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),s(typeof c.xOnlyPointAddTweak=="function"),o.forEach(a=>{const u=c.xOnlyPointAddTweak(r(a.pubkey),r(a.tweak));a.result===null?s(u===null):(s(u!==null),s(u.parity===a.parity),s(Buffer.from(u.xOnlyPubkey).equals(r(a.result))))})}function s(c){if(!c)throw new Error("ecc library invalid")}const o=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];return kr}var na={},wt={},uo={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var nl;function Cy(){return nl||(nl=1,(function(e,t){var n=co(),r=n.Buffer;function i(o,c){for(var a in o)c[a]=o[a]}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(i(n,t),t.Buffer=s);function s(o,c,a){return r(o,c,a)}s.prototype=Object.create(r.prototype),i(r,s),s.from=function(o,c,a){if(typeof o=="number")throw new TypeError("Argument must not be a number");return r(o,c,a)},s.alloc=function(o,c,a){if(typeof o!="number")throw new TypeError("Argument must be a number");var u=r(o);return c!==void 0?typeof a=="string"?u.fill(c,a):u.fill(c):u.fill(0),u},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n.SlowBuffer(o)}})(uo,uo.exports)),uo.exports}var ra,rl;function Uy(){if(rl)return ra;rl=1;var e=Cy().Buffer,t=9007199254740991;function n(o){if(o<0||o>t||o%1!==0)throw new RangeError("value out of range")}function r(o,c,a){if(n(o),c||(c=e.allocUnsafe(s(o))),!e.isBuffer(c))throw new TypeError("buffer must be a Buffer instance");return a||(a=0),o<253?(c.writeUInt8(o,a),r.bytes=1):o<=65535?(c.writeUInt8(253,a),c.writeUInt16LE(o,a+1),r.bytes=3):o<=4294967295?(c.writeUInt8(254,a),c.writeUInt32LE(o,a+1),r.bytes=5):(c.writeUInt8(255,a),c.writeUInt32LE(o>>>0,a+1),c.writeUInt32LE(o/4294967296|0,a+5),r.bytes=9),c}function i(o,c){if(!e.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");c||(c=0);var a=o.readUInt8(c);if(a<253)return i.bytes=1,a;if(a===253)return i.bytes=3,o.readUInt16LE(c+1);if(a===254)return i.bytes=5,o.readUInt32LE(c+1);i.bytes=9;var u=o.readUInt32LE(c+1),l=o.readUInt32LE(c+5),h=l*4294967296+u;return n(h),h}function s(o){return n(o),o<253?1:o<=65535?3:o<=4294967295?5:9}return ra={encode:r,decode:i,encodingLength:s},ra}var il;function fo(){if(il)return wt;il=1,Object.defineProperty(wt,"__esModule",{value:!0}),wt.BufferReader=wt.BufferWriter=wt.cloneBuffer=wt.reverseBuffer=wt.writeUInt64LE=wt.readUInt64LE=wt.varuint=void 0;const e=vt(),{typeforce:t}=e,n=Uy();wt.varuint=n;function r(l,h){if(typeof l!="number")throw new Error("cannot write a non-number as a number");if(l<0)throw new Error("specified a negative value for writing an unsigned value");if(l>h)throw new Error("RangeError: value out of range");if(Math.floor(l)!==l)throw new Error("value has a fractional component")}function i(l,h){const y=l.readUInt32LE(h);let p=l.readUInt32LE(h+4);return p*=4294967296,r(p+y,9007199254740991),p+y}wt.readUInt64LE=i;function s(l,h,y){return r(h,9007199254740991),l.writeInt32LE(h&-1,y),l.writeUInt32LE(Math.floor(h/4294967296),y+4),y+8}wt.writeUInt64LE=s;function o(l){if(l.length<1)return l;let h=l.length-1,y=0;for(let p=0;p<l.length/2;p++)y=l[p],l[p]=l[h],l[h]=y,h--;return l}wt.reverseBuffer=o;function c(l){const h=Buffer.allocUnsafe(l.length);return l.copy(h),h}wt.cloneBuffer=c;class a{static withCapacity(h){return new a(Buffer.alloc(h))}constructor(h,y=0){this.buffer=h,this.offset=y,t(e.tuple(e.Buffer,e.UInt32),[h,y])}writeUInt8(h){this.offset=this.buffer.writeUInt8(h,this.offset)}writeInt32(h){this.offset=this.buffer.writeInt32LE(h,this.offset)}writeUInt32(h){this.offset=this.buffer.writeUInt32LE(h,this.offset)}writeUInt64(h){this.offset=s(this.buffer,h,this.offset)}writeVarInt(h){n.encode(h,this.buffer,this.offset),this.offset+=n.encode.bytes}writeSlice(h){if(this.buffer.length<this.offset+h.length)throw new Error("Cannot write slice out of bounds");this.offset+=h.copy(this.buffer,this.offset)}writeVarSlice(h){this.writeVarInt(h.length),this.writeSlice(h)}writeVector(h){this.writeVarInt(h.length),h.forEach(y=>this.writeVarSlice(y))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}wt.BufferWriter=a;class u{constructor(h,y=0){this.buffer=h,this.offset=y,t(e.tuple(e.Buffer,e.UInt32),[h,y])}readUInt8(){const h=this.buffer.readUInt8(this.offset);return this.offset++,h}readInt32(){const h=this.buffer.readInt32LE(this.offset);return this.offset+=4,h}readUInt32(){const h=this.buffer.readUInt32LE(this.offset);return this.offset+=4,h}readUInt64(){const h=i(this.buffer,this.offset);return this.offset+=8,h}readVarInt(){const h=n.decode(this.buffer,this.offset);return this.offset+=n.decode.bytes,h}readSlice(h){if(this.buffer.length<this.offset+h)throw new Error("Cannot read slice out of bounds");const y=this.buffer.slice(this.offset,this.offset+h);return this.offset+=h,y}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const h=this.readVarInt(),y=[];for(let p=0;p<h;p++)y.push(this.readVarSlice());return y}}return wt.BufferReader=u,wt}var sl;function ia(){return sl||(sl=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=co(),n=ta(),r=Nn(),i=fo(),s=vt();e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=g=>"left"in g&&"right"in g;function c(g,E){if(g.length<33)throw new TypeError(`The control-block length is too small. Got ${g.length}, expected min 33.`);const x=(g.length-33)/32;let _=E;for(let w=0;w<x;w++){const T=g.slice(33+32*w,65+32*w);_.compare(T)<0?_=p(_,T):_=p(T,_)}return _}e.rootHashFromPath=c;function a(g){if((0,s.isTapleaf)(g))return{hash:l(g)};const E=[a(g[0]),a(g[1])];E.sort((w,T)=>w.hash.compare(T.hash));const[x,_]=E;return{hash:p(x.hash,_.hash),left:x,right:_}}e.toHashTree=a;function u(g,E){if(o(g)){const x=u(g.left,E);if(x!==void 0)return[...x,g.right.hash];const _=u(g.right,E);if(_!==void 0)return[..._,g.left.hash]}else if(g.hash.equals(E))return[]}e.findScriptPath=u;function l(g){const E=g.version||e.LEAF_VERSION_TAPSCRIPT;return r.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([E]),m(g.output)]))}e.tapleafHash=l;function h(g,E){return r.taggedHash("TapTweak",t.Buffer.concat(E?[g,E]:[g]))}e.tapTweakHash=h;function y(g,E){if(!t.Buffer.isBuffer(g)||g.length!==32||E&&E.length!==32)return null;const x=h(g,E),_=(0,n.getEccLib)().xOnlyPointAddTweak(g,x);return!_||_.xOnlyPubkey===null?null:{parity:_.parity,x:t.Buffer.from(_.xOnlyPubkey)}}e.tweakKey=y;function p(g,E){return r.taggedHash("TapBranch",t.Buffer.concat([g,E]))}function m(g){const E=i.varuint.encodingLength(g.length),x=t.Buffer.allocUnsafe(E);return i.varuint.encode(g.length,x),t.Buffer.concat([x,g])}})(na)),na}var ol;function Hy(){if(ol)return rs;ol=1,Object.defineProperty(rs,"__esModule",{value:!0}),rs.p2tr=void 0;const e=co(),t=cn(),n=kt(),r=vt(),i=ta(),s=ia(),o=Wn(),c=ao(),a=sa(),u=n.OPS,l=1,h=80;function y(p,m){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");m=Object.assign({validate:!0},m||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(34)),internalPubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),pubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),signature:r.typeforce.maybe(r.typeforce.anyOf(r.typeforce.BufferN(64),r.typeforce.BufferN(65))),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer)),scriptTree:r.typeforce.maybe(r.isTaptree),redeem:r.typeforce.maybe({output:r.typeforce.maybe(r.typeforce.Buffer),redeemVersion:r.typeforce.maybe(r.typeforce.Number),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),redeemVersion:r.typeforce.maybe(r.typeforce.Number)},p);const g=o.value(()=>(0,a.fromBech32)(p.address)),E=o.value(()=>{if(!(!p.witness||!p.witness.length))return p.witness.length>=2&&p.witness[p.witness.length-1][0]===h?p.witness.slice(0,-1):p.witness.slice()}),x=o.value(()=>{if(p.scriptTree)return(0,s.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),_=p.network||t.bitcoin,w={name:"p2tr",network:_};if(o.prop(w,"address",()=>{if(!w.pubkey)return;const T=c.bech32m.toWords(w.pubkey);return T.unshift(l),c.bech32m.encode(_.bech32,T)}),o.prop(w,"hash",()=>{const T=x();if(T)return T.hash;const R=E();if(R&&R.length>1){const B=R[R.length-1],P=B[0]&r.TAPLEAF_VERSION_MASK,q=R[R.length-2],v=(0,s.tapleafHash)({output:q,version:P});return(0,s.rootHashFromPath)(B,v)}return null}),o.prop(w,"output",()=>{if(w.pubkey)return n.compile([u.OP_1,w.pubkey])}),o.prop(w,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(w,"redeem",()=>{const T=E();if(!(!T||T.length<2))return{output:T[T.length-2],witness:T.slice(0,-2),redeemVersion:T[T.length-1][0]&r.TAPLEAF_VERSION_MASK}}),o.prop(w,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return g().data;if(w.internalPubkey){const T=(0,s.tweakKey)(w.internalPubkey,w.hash);if(T)return T.x}}),o.prop(w,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const T=E();if(T&&T.length>1)return T[T.length-1].slice(1,33)}),o.prop(w,"signature",()=>{if(p.signature)return p.signature;const T=E();if(!(!T||T.length!==1))return T[0]}),o.prop(w,"witness",()=>{if(p.witness)return p.witness;const T=x();if(T&&p.redeem&&p.redeem.output&&p.internalPubkey){const R=(0,s.tapleafHash)({output:p.redeem.output,version:w.redeemVersion}),B=(0,s.findScriptPath)(T,R);if(!B)return;const P=(0,s.tweakKey)(p.internalPubkey,T.hash);if(!P)return;const q=e.Buffer.concat([e.Buffer.from([w.redeemVersion|P.parity]),p.internalPubkey].concat(B));return[p.redeem.output,q]}if(p.signature)return[p.signature]}),m.validate){let T=e.Buffer.from([]);if(p.address){if(_&&_.bech32!==g().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(g().version!==l)throw new TypeError("Invalid address version");if(g().data.length!==32)throw new TypeError("Invalid address data");T=g().data}if(p.pubkey){if(T.length>0&&!T.equals(p.pubkey))throw new TypeError("Pubkey mismatch");T=p.pubkey}if(p.output){if(p.output.length!==34||p.output[0]!==u.OP_1||p.output[1]!==32)throw new TypeError("Output is invalid");if(T.length>0&&!T.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");T=p.output.slice(2)}if(p.internalPubkey){const P=(0,s.tweakKey)(p.internalPubkey,w.hash);if(T.length>0&&!T.equals(P.x))throw new TypeError("Pubkey mismatch");T=P.x}if(T&&T.length&&!(0,i.getEccLib)().isXOnlyPoint(T))throw new TypeError("Invalid pubkey for p2tr");const R=x();if(p.hash&&R&&!p.hash.equals(R.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&R){const P=(0,s.tapleafHash)({output:p.redeem.output,version:w.redeemVersion});if(!(0,s.findScriptPath)(R,P))throw new TypeError("Redeem script not in tree")}const B=E();if(p.redeem&&w.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==w.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(p.redeem.output){if(n.decompile(p.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(w.redeem.output&&!p.redeem.output.equals(w.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&w.redeem.witness&&!(0,r.stacksEqual)(p.redeem.witness,w.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(B&&B.length)if(B.length===1){if(p.signature&&!p.signature.equals(B[0]))throw new TypeError("Signature mismatch")}else{const P=B[B.length-1];if(P.length<33)throw new TypeError(`The control-block length is too small. Got ${P.length}, expected min 33.`);if((P.length-33)%32!==0)throw new TypeError(`The control-block length of ${P.length} is incorrect!`);const q=(P.length-33)/32;if(q>128)throw new TypeError(`The script path is too long. Got ${q}, expected max 128.`);const v=P.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(v))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid internalPubkey for p2tr witness");const C=P[0]&r.TAPLEAF_VERSION_MASK,L=B[B.length-2],K=(0,s.tapleafHash)({output:L,version:C}),U=(0,s.rootHashFromPath)(P,K),D=(0,s.tweakKey)(v,U);if(!D)throw new TypeError("Invalid outputKey for p2tr witness");if(T.length&&!T.equals(D.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(D.parity!==(P[0]&1))throw new Error("Incorrect parity")}}return Object.assign(w,p)}return rs.p2tr=y,rs}var cl;function is(){return cl||(cl=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=Ey();Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const n=_y();Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return n.p2ms}});const r=Sy();Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return r.p2pk}});const i=Ny();Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=Ry();Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=ky();Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const c=Py();Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return c.p2wsh}});const a=Hy();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return a.p2tr}})})(qc)),qc}var al;function sa(){if(al)return Rt;al=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.toOutputScript=Rt.fromOutputScript=Rt.toBech32=Rt.toBase58Check=Rt.fromBech32=Rt.fromBase58Check=void 0;const e=cn(),t=is(),n=kt(),r=vt(),i=ao(),s=ea(),o=40,c=2,a=16,u=2,l=80,h="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function y(w,T){const R=w.slice(2);if(R.length<c||R.length>o)throw new TypeError("Invalid program length for segwit address");const B=w[0]-l;if(B<u||B>a)throw new TypeError("Invalid version for segwit address");if(w[1]!==R.length)throw new TypeError("Invalid script for segwit address");return console.warn(h),E(R,B,T.bech32)}function p(w){const T=Buffer.from(s.decode(w));if(T.length<21)throw new TypeError(w+" is too short");if(T.length>21)throw new TypeError(w+" is too long");const R=T.readUInt8(0),B=T.slice(1);return{version:R,hash:B}}Rt.fromBase58Check=p;function m(w){let T,R;try{T=i.bech32.decode(w)}catch{}if(T){if(R=T.words[0],R!==0)throw new TypeError(w+" uses wrong encoding")}else if(T=i.bech32m.decode(w),R=T.words[0],R===0)throw new TypeError(w+" uses wrong encoding");const B=i.bech32.fromWords(T.words.slice(1));return{version:R,prefix:T.prefix,data:Buffer.from(B)}}Rt.fromBech32=m;function g(w,T){(0,r.typeforce)((0,r.tuple)(r.Hash160bit,r.UInt8),arguments);const R=Buffer.allocUnsafe(21);return R.writeUInt8(T,0),w.copy(R,1),s.encode(R)}Rt.toBase58Check=g;function E(w,T,R){const B=i.bech32.toWords(w);return B.unshift(T),T===0?i.bech32.encode(R,B):i.bech32m.encode(R,B)}Rt.toBech32=E;function x(w,T){T=T||e.bitcoin;try{return t.p2pkh({output:w,network:T}).address}catch{}try{return t.p2sh({output:w,network:T}).address}catch{}try{return t.p2wpkh({output:w,network:T}).address}catch{}try{return t.p2wsh({output:w,network:T}).address}catch{}try{return t.p2tr({output:w,network:T}).address}catch{}try{return y(w,T)}catch{}throw new Error(n.toASM(w)+" has no matching Address")}Rt.fromOutputScript=x;function _(w,T){T=T||e.bitcoin;let R,B;try{R=p(w)}catch{}if(R){if(R.version===T.pubKeyHash)return t.p2pkh({hash:R.hash}).output;if(R.version===T.scriptHash)return t.p2sh({hash:R.hash}).output}else{try{B=m(w)}catch{}if(B){if(B.prefix!==T.bech32)throw new Error(w+" has an invalid prefix");if(B.version===0){if(B.data.length===20)return t.p2wpkh({hash:B.data}).output;if(B.data.length===32)return t.p2wsh({hash:B.data}).output}else if(B.version===1){if(B.data.length===32)return t.p2tr({pubkey:B.data}).output}else if(B.version>=u&&B.version<=a&&B.data.length>=c&&B.data.length<=o)return console.warn(h),n.compile([B.version+l,B.data])}}throw new Error(w+" has no matching Script")}return Rt.toOutputScript=_,Rt}var ss={},os={},ul;function Fy(){if(ul)return os;ul=1,Object.defineProperty(os,"__esModule",{value:!0}),os.fastMerkleRoot=void 0;function e(t,n){if(!Array.isArray(t))throw TypeError("Expected values Array");if(typeof n!="function")throw TypeError("Expected digest Function");let r=t.length;const i=t.concat();for(;r>1;){let s=0;for(let o=0;o<r;o+=2,++s){const c=i[o],a=o+1===r?c:i[o+1],u=Buffer.concat([c,a]);i[s]=n(u)}r=s}return i[0]}return os.fastMerkleRoot=e,os}var cs={},fl;function as(){if(fl)return cs;fl=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.Transaction=void 0;const e=fo(),t=Nn(),n=kt(),r=kt(),i=vt(),{typeforce:s}=i;function o(E){const x=E.length;return e.varuint.encodingLength(x)+x}function c(E){const x=E.length;return e.varuint.encodingLength(x)+E.reduce((_,w)=>_+o(w),0)}const a=Buffer.allocUnsafe(0),u=[],l=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),h=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),y=Buffer.from("ffffffffffffffff","hex"),p={script:a,valueBuffer:y};function m(E){return E.value!==void 0}class g{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(x,_){const w=new e.BufferReader(x),T=new g;T.version=w.readInt32();const R=w.readUInt8(),B=w.readUInt8();let P=!1;R===g.ADVANCED_TRANSACTION_MARKER&&B===g.ADVANCED_TRANSACTION_FLAG?P=!0:w.offset-=2;const q=w.readVarInt();for(let C=0;C<q;++C)T.ins.push({hash:w.readSlice(32),index:w.readUInt32(),script:w.readVarSlice(),sequence:w.readUInt32(),witness:u});const v=w.readVarInt();for(let C=0;C<v;++C)T.outs.push({value:w.readUInt64(),script:w.readVarSlice()});if(P){for(let C=0;C<q;++C)T.ins[C].witness=w.readVector();if(!T.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(T.locktime=w.readUInt32(),_)return T;if(w.offset!==x.length)throw new Error("Transaction has unexpected data");return T}static fromHex(x){return g.fromBuffer(Buffer.from(x,"hex"),!1)}static isCoinbaseHash(x){s(i.Hash256bit,x);for(let _=0;_<32;++_)if(x[_]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&g.isCoinbaseHash(this.ins[0].hash)}addInput(x,_,w,T){return s(i.tuple(i.Hash256bit,i.UInt32,i.maybe(i.UInt32),i.maybe(i.Buffer)),arguments),i.Null(w)&&(w=g.DEFAULT_SEQUENCE),this.ins.push({hash:x,index:_,script:T||a,sequence:w,witness:u})-1}addOutput(x,_){return s(i.tuple(i.Buffer,i.Satoshi),arguments),this.outs.push({script:x,value:_})-1}hasWitnesses(){return this.ins.some(x=>x.witness.length!==0)}stripWitnesses(){this.ins.forEach(x=>{x.witness=u})}weight(){const x=this.byteLength(!1),_=this.byteLength(!0);return x*3+_}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(x=!0){const _=x&&this.hasWitnesses();return(_?10:8)+e.varuint.encodingLength(this.ins.length)+e.varuint.encodingLength(this.outs.length)+this.ins.reduce((w,T)=>w+40+o(T.script),0)+this.outs.reduce((w,T)=>w+8+o(T.script),0)+(_?this.ins.reduce((w,T)=>w+c(T.witness),0):0)}clone(){const x=new g;return x.version=this.version,x.locktime=this.locktime,x.ins=this.ins.map(_=>({hash:_.hash,index:_.index,script:_.script,sequence:_.sequence,witness:_.witness})),x.outs=this.outs.map(_=>({script:_.script,value:_.value})),x}hashForSignature(x,_,w){if(s(i.tuple(i.UInt32,i.Buffer,i.Number),arguments),x>=this.ins.length)return h;const T=n.compile(n.decompile(_).filter(P=>P!==r.OPS.OP_CODESEPARATOR)),R=this.clone();if((w&31)===g.SIGHASH_NONE)R.outs=[],R.ins.forEach((P,q)=>{q!==x&&(P.sequence=0)});else if((w&31)===g.SIGHASH_SINGLE){if(x>=this.outs.length)return h;R.outs.length=x+1;for(let P=0;P<x;P++)R.outs[P]=p;R.ins.forEach((P,q)=>{q!==x&&(P.sequence=0)})}w&g.SIGHASH_ANYONECANPAY?(R.ins=[R.ins[x]],R.ins[0].script=T):(R.ins.forEach(P=>{P.script=a}),R.ins[x].script=T);const B=Buffer.allocUnsafe(R.byteLength(!1)+4);return B.writeInt32LE(w,B.length-4),R.__toBuffer(B,0,!1),t.hash256(B)}hashForWitnessV1(x,_,w,T,R,B){if(s(i.tuple(i.UInt32,s.arrayOf(i.Buffer),s.arrayOf(i.Satoshi),i.UInt32),arguments),w.length!==this.ins.length||_.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const P=T===g.SIGHASH_DEFAULT?g.SIGHASH_ALL:T&g.SIGHASH_OUTPUT_MASK,v=(T&g.SIGHASH_INPUT_MASK)===g.SIGHASH_ANYONECANPAY,C=P===g.SIGHASH_NONE,L=P===g.SIGHASH_SINGLE;let K=a,U=a,D=a,k=a,j=a;if(!v){let M=e.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(O=>{M.writeSlice(O.hash),M.writeUInt32(O.index)}),K=t.sha256(M.end()),M=e.BufferWriter.withCapacity(8*this.ins.length),w.forEach(O=>M.writeUInt64(O)),U=t.sha256(M.end()),M=e.BufferWriter.withCapacity(_.map(o).reduce((O,V)=>O+V)),_.forEach(O=>M.writeVarSlice(O)),D=t.sha256(M.end()),M=e.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(O=>M.writeUInt32(O.sequence)),k=t.sha256(M.end())}if(C||L){if(L&&x<this.outs.length){const M=this.outs[x],O=e.BufferWriter.withCapacity(8+o(M.script));O.writeUInt64(M.value),O.writeVarSlice(M.script),j=t.sha256(O.end())}}else{const M=this.outs.map(V=>8+o(V.script)).reduce((V,G)=>V+G),O=e.BufferWriter.withCapacity(M);this.outs.forEach(V=>{O.writeUInt64(V.value),O.writeVarSlice(V.script)}),j=t.sha256(O.end())}const F=(R?2:0)+(B?1:0),S=174-(v?49:0)-(C?32:0)+(B?32:0)+(R?37:0),I=e.BufferWriter.withCapacity(S);if(I.writeUInt8(T),I.writeInt32(this.version),I.writeUInt32(this.locktime),I.writeSlice(K),I.writeSlice(U),I.writeSlice(D),I.writeSlice(k),C||L||I.writeSlice(j),I.writeUInt8(F),v){const M=this.ins[x];I.writeSlice(M.hash),I.writeUInt32(M.index),I.writeUInt64(w[x]),I.writeVarSlice(_[x]),I.writeUInt32(M.sequence)}else I.writeUInt32(x);if(B){const M=e.BufferWriter.withCapacity(o(B));M.writeVarSlice(B),I.writeSlice(t.sha256(M.end()))}return L&&I.writeSlice(j),R&&(I.writeSlice(R),I.writeUInt8(0),I.writeUInt32(4294967295)),t.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),I.end()]))}hashForWitnessV0(x,_,w,T){s(i.tuple(i.UInt32,i.Buffer,i.Satoshi,i.UInt32),arguments);let R=Buffer.from([]),B,P=l,q=l,v=l;if(T&g.SIGHASH_ANYONECANPAY||(R=Buffer.allocUnsafe(36*this.ins.length),B=new e.BufferWriter(R,0),this.ins.forEach(L=>{B.writeSlice(L.hash),B.writeUInt32(L.index)}),q=t.hash256(R)),!(T&g.SIGHASH_ANYONECANPAY)&&(T&31)!==g.SIGHASH_SINGLE&&(T&31)!==g.SIGHASH_NONE&&(R=Buffer.allocUnsafe(4*this.ins.length),B=new e.BufferWriter(R,0),this.ins.forEach(L=>{B.writeUInt32(L.sequence)}),v=t.hash256(R)),(T&31)!==g.SIGHASH_SINGLE&&(T&31)!==g.SIGHASH_NONE){const L=this.outs.reduce((K,U)=>K+8+o(U.script),0);R=Buffer.allocUnsafe(L),B=new e.BufferWriter(R,0),this.outs.forEach(K=>{B.writeUInt64(K.value),B.writeVarSlice(K.script)}),P=t.hash256(R)}else if((T&31)===g.SIGHASH_SINGLE&&x<this.outs.length){const L=this.outs[x];R=Buffer.allocUnsafe(8+o(L.script)),B=new e.BufferWriter(R,0),B.writeUInt64(L.value),B.writeVarSlice(L.script),P=t.hash256(R)}R=Buffer.allocUnsafe(156+o(_)),B=new e.BufferWriter(R,0);const C=this.ins[x];return B.writeInt32(this.version),B.writeSlice(q),B.writeSlice(v),B.writeSlice(C.hash),B.writeUInt32(C.index),B.writeVarSlice(_),B.writeUInt64(w),B.writeUInt32(C.sequence),B.writeSlice(P),B.writeUInt32(this.locktime),B.writeUInt32(T),t.hash256(R)}getHash(x){return x&&this.isCoinbase()?Buffer.alloc(32,0):t.hash256(this.__toBuffer(void 0,void 0,x))}getId(){return(0,e.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(x,_){return this.__toBuffer(x,_,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(x,_){s(i.tuple(i.Number,i.Buffer),arguments),this.ins[x].script=_}setWitness(x,_){s(i.tuple(i.Number,[i.Buffer]),arguments),this.ins[x].witness=_}__toBuffer(x,_,w=!1){x||(x=Buffer.allocUnsafe(this.byteLength(w)));const T=new e.BufferWriter(x,_||0);T.writeInt32(this.version);const R=w&&this.hasWitnesses();return R&&(T.writeUInt8(g.ADVANCED_TRANSACTION_MARKER),T.writeUInt8(g.ADVANCED_TRANSACTION_FLAG)),T.writeVarInt(this.ins.length),this.ins.forEach(B=>{T.writeSlice(B.hash),T.writeUInt32(B.index),T.writeVarSlice(B.script),T.writeUInt32(B.sequence)}),T.writeVarInt(this.outs.length),this.outs.forEach(B=>{m(B)?T.writeUInt64(B.value):T.writeSlice(B.valueBuffer),T.writeVarSlice(B.script)}),R&&this.ins.forEach(B=>{T.writeVector(B.witness)}),T.writeUInt32(this.locktime),_!==void 0?x.slice(_,T.offset):x}}return cs.Transaction=g,g.DEFAULT_SEQUENCE=4294967295,g.SIGHASH_DEFAULT=0,g.SIGHASH_ALL=1,g.SIGHASH_NONE=2,g.SIGHASH_SINGLE=3,g.SIGHASH_ANYONECANPAY=128,g.SIGHASH_OUTPUT_MASK=3,g.SIGHASH_INPUT_MASK=128,g.ADVANCED_TRANSACTION_MARKER=0,g.ADVANCED_TRANSACTION_FLAG=1,cs}var ll;function qy(){if(ll)return ss;ll=1,Object.defineProperty(ss,"__esModule",{value:!0}),ss.Block=void 0;const e=fo(),t=Nn(),n=Fy(),r=as(),i=vt(),{typeforce:s}=i,o=new TypeError("Cannot compute merkle root for zero transactions"),c=new TypeError("Cannot compute witness commit for non-segwit block");class a{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(y){if(y.length<80)throw new Error("Buffer too small (< 80 bytes)");const p=new e.BufferReader(y),m=new a;if(m.version=p.readInt32(),m.prevHash=p.readSlice(32),m.merkleRoot=p.readSlice(32),m.timestamp=p.readUInt32(),m.bits=p.readUInt32(),m.nonce=p.readUInt32(),y.length===80)return m;const g=()=>{const _=r.Transaction.fromBuffer(p.buffer.slice(p.offset),!0);return p.offset+=_.byteLength(),_},E=p.readVarInt();m.transactions=[];for(let _=0;_<E;++_){const w=g();m.transactions.push(w)}const x=m.getWitnessCommit();return x&&(m.witnessCommit=x),m}static fromHex(y){return a.fromBuffer(Buffer.from(y,"hex"))}static calculateTarget(y){const p=((y&4278190080)>>24)-3,m=y&8388607,g=Buffer.alloc(32,0);return g.writeUIntBE(m,29-p,3),g}static calculateMerkleRoot(y,p){if(s([{getHash:i.Function}],y),y.length===0)throw o;if(p&&!u(y))throw c;const m=y.map(E=>E.getHash(p)),g=(0,n.fastMerkleRoot)(m,t.hash256);return p?t.hash256(Buffer.concat([g,y[0].ins[0].witness[0]])):g}getWitnessCommit(){if(!u(this.transactions))return null;const y=this.transactions[0].outs.filter(m=>m.script.slice(0,6).equals(Buffer.from("6a24aa21a9ed","hex"))).map(m=>m.script.slice(6,38));if(y.length===0)return null;const p=y[y.length-1];return p instanceof Buffer&&p.length===32?p:null}hasWitnessCommit(){return this.witnessCommit instanceof Buffer&&this.witnessCommit.length===32||this.getWitnessCommit()!==null}hasWitness(){return l(this.transactions)}weight(){const y=this.byteLength(!1,!1),p=this.byteLength(!1,!0);return y*3+p}byteLength(y,p=!0){return y||!this.transactions?80:80+e.varuint.encodingLength(this.transactions.length)+this.transactions.reduce((m,g)=>m+g.byteLength(p),0)}getHash(){return t.hash256(this.toBuffer(!0))}getId(){return(0,e.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const y=new Date(0);return y.setUTCSeconds(this.timestamp),y}toBuffer(y){const p=Buffer.allocUnsafe(this.byteLength(y)),m=new e.BufferWriter(p);return m.writeInt32(this.version),m.writeSlice(this.prevHash),m.writeSlice(this.merkleRoot),m.writeUInt32(this.timestamp),m.writeUInt32(this.bits),m.writeUInt32(this.nonce),y||!this.transactions||(e.varuint.encode(this.transactions.length,p,m.offset),m.offset+=e.varuint.encode.bytes,this.transactions.forEach(g=>{const E=g.byteLength();g.toBuffer(p,m.offset),m.offset+=E})),p}toHex(y){return this.toBuffer(y).toString("hex")}checkTxRoots(){const y=this.hasWitnessCommit();return!y&&this.hasWitness()?!1:this.__checkMerkleRoot()&&(y?this.__checkWitnessCommit():!0)}checkProofOfWork(){const y=(0,e.reverseBuffer)(this.getHash()),p=a.calculateTarget(this.bits);return y.compare(p)<=0}__checkMerkleRoot(){if(!this.transactions)throw o;const y=a.calculateMerkleRoot(this.transactions);return this.merkleRoot.compare(y)===0}__checkWitnessCommit(){if(!this.transactions)throw o;if(!this.hasWitnessCommit())throw c;const y=a.calculateMerkleRoot(this.transactions,!0);return this.witnessCommit.compare(y)===0}}ss.Block=a;function u(h){return h instanceof Array&&h[0]&&h[0].ins&&h[0].ins instanceof Array&&h[0].ins[0]&&h[0].ins[0].witness&&h[0].ins[0].witness instanceof Array&&h[0].ins[0].witness.length>0}function l(h){return h instanceof Array&&h.some(y=>typeof y=="object"&&y.ins instanceof Array&&y.ins.some(p=>typeof p=="object"&&p.witness instanceof Array&&p.witness.length>0))}return ss}var us={},lo={},ho={},oa={},ci={},ai={},ca={},dl;function bt(){return dl||(dl=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),(function(t){t[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(e.GlobalTypes||(e.GlobalTypes={})),e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(function(t){t[t.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",t[t.WITNESS_UTXO=1]="WITNESS_UTXO",t[t.PARTIAL_SIG=2]="PARTIAL_SIG",t[t.SIGHASH_TYPE=3]="SIGHASH_TYPE",t[t.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=6]="BIP32_DERIVATION",t[t.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",t[t.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",t[t.POR_COMMITMENT=9]="POR_COMMITMENT",t[t.TAP_KEY_SIG=19]="TAP_KEY_SIG",t[t.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",t[t.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",t[t.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",t[t.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(function(t){t[t.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=2]="BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",t[t.TAP_TREE=6]="TAP_TREE",t[t.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]})(ca)),ca}var zn={},hl;function My(){if(hl)return zn;hl=1,Object.defineProperty(zn,"__esModule",{value:!0});const e=bt(),t=o=>[...Array(o).keys()];function n(o){if(o.key[0]!==e.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+o.key.toString("hex"));if(o.key.length!==79||![2,3].includes(o.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+o.key.toString("hex"));if(o.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const c=o.key.slice(1),a={masterFingerprint:o.value.slice(0,4),extendedPubkey:c,path:"m"};for(const u of t(o.value.length/4-1)){const l=o.value.readUInt32LE(u*4+4),h=!!(l&2147483648),y=l&2147483647;a.path+="/"+y.toString(10)+(h?"'":"")}return a}zn.decode=n;function r(o){const c=Buffer.from([e.GlobalTypes.GLOBAL_XPUB]),a=Buffer.concat([c,o.extendedPubkey]),u=o.path.split("/"),l=Buffer.allocUnsafe(u.length*4);o.masterFingerprint.copy(l,0);let h=4;return u.slice(1).forEach(y=>{const p=y.slice(-1)==="'";let m=2147483647&parseInt(p?y.slice(0,-1):y,10);p&&(m+=2147483648),l.writeUInt32LE(m,h),h+=4}),{key:a,value:l}}zn.encode=r,zn.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";function i(o){const c=o.extendedPubkey,a=o.masterFingerprint,u=o.path;return Buffer.isBuffer(c)&&c.length===78&&[2,3].indexOf(c[45])>-1&&Buffer.isBuffer(a)&&a.length===4&&typeof u=="string"&&!!u.match(/^m(\/\d+'?)*$/)}zn.check=i;function s(o,c,a){const u=c.extendedPubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(l=>l.extendedPubkey.equals(c.extendedPubkey)).length===0)}return zn.canAddToArray=s,zn}var po={},pl;function Ly(){if(pl)return po;pl=1,Object.defineProperty(po,"__esModule",{value:!0});const e=bt();function t(n){return{key:Buffer.from([e.GlobalTypes.UNSIGNED_TX]),value:n.toBuffer()}}return po.encode=t,po}var Yn={},yl;function Vy(){if(yl)return Yn;yl=1,Object.defineProperty(Yn,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+s.key.toString("hex"));return s.value}Yn.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTSIG]),value:s}}Yn.encode=n,Yn.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Yn.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptSig===void 0}return Yn.canAdd=i,Yn}var Zn={},ml;function Dy(){if(ml)return Zn;ml=1,Object.defineProperty(Zn,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+s.key.toString("hex"));return s.value}Zn.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTWITNESS]),value:s}}Zn.encode=n,Zn.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Zn.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptWitness===void 0}return Zn.canAdd=i,Zn}var Jn={},gl;function jy(){if(gl)return Jn;gl=1,Object.defineProperty(Jn,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+s.key.toString("hex"));return s.value}Jn.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.NON_WITNESS_UTXO]),value:s}}Jn.encode=n,Jn.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Jn.check=r;function i(s,o){return!!s&&!!o&&s.nonWitnessUtxo===void 0}return Jn.canAdd=i,Jn}var Qn={},wl;function $y(){if(wl)return Qn;wl=1,Object.defineProperty(Qn,"__esModule",{value:!0});const e=bt();function t(o){if(o.key[0]!==e.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+o.key.toString("hex"));if(!(o.key.length===34||o.key.length===66)||![2,3,4].includes(o.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+o.key.toString("hex"));return{pubkey:o.key.slice(1),signature:o.value}}Qn.decode=t;function n(o){const c=Buffer.from([e.InputTypes.PARTIAL_SIG]);return{key:Buffer.concat([c,o.pubkey]),value:o.signature}}Qn.encode=n,Qn.expected="{ pubkey: Buffer; signature: Buffer; }";function r(o){return Buffer.isBuffer(o.pubkey)&&Buffer.isBuffer(o.signature)&&[33,65].includes(o.pubkey.length)&&[2,3,4].includes(o.pubkey[0])&&i(o.signature)}Qn.check=r;function i(o){if(!Buffer.isBuffer(o)||o.length<9||o[0]!==48||o.length!==o[1]+3||o[2]!==2)return!1;const c=o[3];if(c>33||c<1||o[3+c+1]!==2)return!1;const a=o[3+c+2];return!(a>33||a<1||o.length!==3+c+2+a+2)}function s(o,c,a){const u=c.pubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(l=>l.pubkey.equals(c.pubkey)).length===0)}return Qn.canAddToArray=s,Qn}var er={},bl;function Ky(){if(bl)return er;bl=1,Object.defineProperty(er,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+s.key.toString("hex"));return s.value.toString("utf8")}er.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.POR_COMMITMENT]),value:Buffer.from(s,"utf8")}}er.encode=n,er.expected="string";function r(s){return typeof s=="string"}er.check=r;function i(s,o){return!!s&&!!o&&s.porCommitment===void 0}return er.canAdd=i,er}var tr={},El;function Gy(){if(El)return tr;El=1,Object.defineProperty(tr,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+s.key.toString("hex"));return s.value.readUInt32LE(0)}tr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.SIGHASH_TYPE]),c=Buffer.allocUnsafe(4);return c.writeUInt32LE(s,0),{key:o,value:c}}tr.encode=n,tr.expected="number";function r(s){return typeof s=="number"}tr.check=r;function i(s,o){return!!s&&!!o&&s.sighashType===void 0}return tr.canAdd=i,tr}var nr={},_l;function Wy(){if(_l)return nr;_l=1,Object.defineProperty(nr,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.TAP_KEY_SIG||s.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return s.value}nr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_KEY_SIG]),value:s}}nr.encode=n,nr.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&(s.length===64||s.length===65)}nr.check=r;function i(s,o){return!!s&&!!o&&s.tapKeySig===void 0}return nr.canAdd=i,nr}var rr={},Sl;function Xy(){if(Sl)return rr;Sl=1,Object.defineProperty(rr,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+s.key.toString("hex"));if((s.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+s.key.toString("hex"));const o=s.value[s.value.length-1];if((s.key[1]&254)!==o)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+s.key.toString("hex"));const c=s.value.slice(0,-1);return{controlBlock:s.key.slice(1),script:c,leafVersion:o}}rr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_LEAF_SCRIPT]),c=Buffer.from([s.leafVersion]);return{key:Buffer.concat([o,s.controlBlock]),value:Buffer.concat([s.script,c])}}rr.encode=n,rr.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";function r(s){return Buffer.isBuffer(s.controlBlock)&&(s.controlBlock.length-1)%32===0&&(s.controlBlock[0]&254)===s.leafVersion&&Buffer.isBuffer(s.script)}rr.check=r;function i(s,o,c){const a=o.controlBlock.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.controlBlock.equals(o.controlBlock)).length===0)}return rr.canAddToArray=i,rr}var ir={},xl;function zy(){if(xl)return ir;xl=1,Object.defineProperty(ir,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.TAP_MERKLE_ROOT||s.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return s.value}ir.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_MERKLE_ROOT]),value:s}}ir.encode=n,ir.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&s.length===32}ir.check=r;function i(s,o){return!!s&&!!o&&s.tapMerkleRoot===void 0}return ir.canAdd=i,ir}var sr={},Tl;function Yy(){if(Tl)return sr;Tl=1,Object.defineProperty(sr,"__esModule",{value:!0});const e=bt();function t(s){if(s.key[0]!==e.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+s.key.toString("hex"));if(s.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+s.key.toString("hex"));if(s.value.length!==64&&s.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+s.key.toString("hex"));const o=s.key.slice(1,33),c=s.key.slice(33);return{pubkey:o,leafHash:c,signature:s.value}}sr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_SCRIPT_SIG]);return{key:Buffer.concat([o,s.pubkey,s.leafHash]),value:s.signature}}sr.encode=n,sr.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";function r(s){return Buffer.isBuffer(s.pubkey)&&Buffer.isBuffer(s.leafHash)&&Buffer.isBuffer(s.signature)&&s.pubkey.length===32&&s.leafHash.length===32&&(s.signature.length===64||s.signature.length===65)}sr.check=r;function i(s,o,c){const a=o.pubkey.toString("hex")+o.leafHash.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.pubkey.equals(o.pubkey)&&u.leafHash.equals(o.leafHash)).length===0)}return sr.canAddToArray=i,sr}var or={},Rn={},ui={},vl;function Pr(){if(vl)return ui;vl=1,Object.defineProperty(ui,"__esModule",{value:!0});const e=9007199254740991;function t(s){if(s<0||s>e||s%1!==0)throw new RangeError("value out of range")}function n(s,o,c){if(t(s),o||(o=Buffer.allocUnsafe(i(s))),!Buffer.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");return c||(c=0),s<253?(o.writeUInt8(s,c),Object.assign(n,{bytes:1})):s<=65535?(o.writeUInt8(253,c),o.writeUInt16LE(s,c+1),Object.assign(n,{bytes:3})):s<=4294967295?(o.writeUInt8(254,c),o.writeUInt32LE(s,c+1),Object.assign(n,{bytes:5})):(o.writeUInt8(255,c),o.writeUInt32LE(s>>>0,c+1),o.writeUInt32LE(s/4294967296|0,c+5),Object.assign(n,{bytes:9})),o}ui.encode=n;function r(s,o){if(!Buffer.isBuffer(s))throw new TypeError("buffer must be a Buffer instance");o||(o=0);const c=s.readUInt8(o);if(c<253)return Object.assign(r,{bytes:1}),c;if(c===253)return Object.assign(r,{bytes:3}),s.readUInt16LE(o+1);if(c===254)return Object.assign(r,{bytes:5}),s.readUInt32LE(o+1);{Object.assign(r,{bytes:9});const a=s.readUInt32LE(o+1),l=s.readUInt32LE(o+5)*4294967296+a;return t(l),l}}ui.decode=r;function i(s){return t(s),s<253?1:s<=65535?3:s<=4294967295?5:9}return ui.encodingLength=i,ui}var Bl;function aa(){if(Bl)return Rn;Bl=1,Object.defineProperty(Rn,"__esModule",{value:!0});const e=Pr();Rn.range=c=>[...Array(c).keys()];function t(c){if(c.length<1)return c;let a=c.length-1,u=0;for(let l=0;l<c.length/2;l++)u=c[l],c[l]=c[a],c[a]=u,a--;return c}Rn.reverseBuffer=t;function n(c){const a=c.map(r);return a.push(Buffer.from([0])),Buffer.concat(a)}Rn.keyValsToBuffer=n;function r(c){const a=c.key.length,u=c.value.length,l=e.encodingLength(a),h=e.encodingLength(u),y=Buffer.allocUnsafe(l+a+h+u);return e.encode(a,y,0),c.key.copy(y,l),e.encode(u,y,l+a),c.value.copy(y,l+a+h),y}Rn.keyValToBuffer=r;function i(c,a){if(typeof c!="number")throw new Error("cannot write a non-number as a number");if(c<0)throw new Error("specified a negative value for writing an unsigned value");if(c>a)throw new Error("RangeError: value out of range");if(Math.floor(c)!==c)throw new Error("value has a fractional component")}function s(c,a){const u=c.readUInt32LE(a);let l=c.readUInt32LE(a+4);return l*=4294967296,i(l+u,9007199254740991),l+u}Rn.readUInt64LE=s;function o(c,a,u){return i(a,9007199254740991),c.writeInt32LE(a&-1,u),c.writeUInt32LE(Math.floor(a/4294967296),u+4),u+8}return Rn.writeUInt64LE=o,Rn}var Al;function Zy(){if(Al)return or;Al=1,Object.defineProperty(or,"__esModule",{value:!0});const e=bt(),t=aa(),n=Pr();function r(c){if(c.key[0]!==e.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+c.key.toString("hex"));const a=t.readUInt64LE(c.value,0);let u=8;const l=n.decode(c.value,u);u+=n.encodingLength(l);const h=c.value.slice(u);if(h.length!==l)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:h,value:a}}or.decode=r;function i(c){const{script:a,value:u}=c,l=n.encodingLength(a.length),h=Buffer.allocUnsafe(8+l+a.length);return t.writeUInt64LE(h,u,0),n.encode(a.length,h,8),a.copy(h,8+l),{key:Buffer.from([e.InputTypes.WITNESS_UTXO]),value:h}}or.encode=i,or.expected="{ script: Buffer; value: number; }";function s(c){return Buffer.isBuffer(c.script)&&typeof c.value=="number"}or.check=s;function o(c,a){return!!c&&!!a&&c.witnessUtxo===void 0}return or.canAdd=o,or}var cr={},Il;function Jy(){if(Il)return cr;Il=1,Object.defineProperty(cr,"__esModule",{value:!0});const e=bt(),t=Pr();function n(o){if(o.key[0]!==e.OutputTypes.TAP_TREE||o.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+o.key.toString("hex"));let c=0;const a=[];for(;c<o.value.length;){const u=o.value[c++],l=o.value[c++],h=t.decode(o.value,c);c+=t.encodingLength(h),a.push({depth:u,leafVersion:l,script:o.value.slice(c,c+h)}),c+=h}return{leaves:a}}cr.decode=n;function r(o){const c=Buffer.from([e.OutputTypes.TAP_TREE]),a=[].concat(...o.leaves.map(u=>[Buffer.of(u.depth,u.leafVersion),t.encode(u.script.length),u.script]));return{key:c,value:Buffer.concat(a)}}cr.encode=r,cr.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";function i(o){return Array.isArray(o.leaves)&&o.leaves.every(c=>c.depth>=0&&c.depth<=128&&(c.leafVersion&254)===c.leafVersion&&Buffer.isBuffer(c.script))}cr.check=i;function s(o,c){return!!o&&!!c&&o.tapTree===void 0}return cr.canAdd=s,cr}var yo={},Ol;function Nl(){if(Ol)return yo;Ol=1,Object.defineProperty(yo,"__esModule",{value:!0});const e=r=>[...Array(r).keys()],t=r=>r.length===33&&[2,3].includes(r[0])||r.length===65&&r[0]===4;function n(r,i=t){function s(l){if(l.key[0]!==r)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+l.key.toString("hex"));const h=l.key.slice(1);if(!i(h))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+l.key.toString("hex"));if(l.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const y={masterFingerprint:l.value.slice(0,4),pubkey:h,path:"m"};for(const p of e(l.value.length/4-1)){const m=l.value.readUInt32LE(p*4+4),g=!!(m&2147483648),E=m&2147483647;y.path+="/"+E.toString(10)+(g?"'":"")}return y}function o(l){const h=Buffer.from([r]),y=Buffer.concat([h,l.pubkey]),p=l.path.split("/"),m=Buffer.allocUnsafe(p.length*4);l.masterFingerprint.copy(m,0);let g=4;return p.slice(1).forEach(E=>{const x=E.slice(-1)==="'";let _=2147483647&parseInt(x?E.slice(0,-1):E,10);x&&(_+=2147483648),m.writeUInt32LE(_,g),g+=4}),{key:y,value:m}}const c="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";function a(l){return Buffer.isBuffer(l.pubkey)&&Buffer.isBuffer(l.masterFingerprint)&&typeof l.path=="string"&&i(l.pubkey)&&l.masterFingerprint.length===4}function u(l,h,y){const p=h.pubkey.toString("hex");return y.has(p)?!1:(y.add(p),l.filter(m=>m.pubkey.equals(h.pubkey)).length===0)}return{decode:s,encode:o,check:a,expected:c,canAddToArray:u}}return yo.makeConverter=n,yo}var mo={},Rl;function Qy(){if(Rl)return mo;Rl=1,Object.defineProperty(mo,"__esModule",{value:!0});function e(t){return n;function n(r){let i;if(t.includes(r.key[0])&&(i=r.key.slice(1),!(i.length===33||i.length===65)||![2,3,4].includes(i[0])))throw new Error("Format Error: invalid pubkey in key 0x"+r.key.toString("hex"));return i}}return mo.makeChecker=e,mo}var go={},kl;function em(){if(kl)return go;kl=1,Object.defineProperty(go,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.redeemScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return go.makeConverter=e,go}var wo={},Pl;function tm(){if(Pl)return wo;Pl=1,Object.defineProperty(wo,"__esModule",{value:!0});const e=Pr(),t=Nl(),n=i=>i.length===32;function r(i){const s=t.makeConverter(i,n);function o(l){const h=e.decode(l.value),y=e.encodingLength(h),p=s.decode({key:l.key,value:l.value.slice(y+h*32)}),m=new Array(h);for(let g=0,E=y;g<h;g++,E+=32)m[g]=l.value.slice(E,E+32);return Object.assign({},p,{leafHashes:m})}function c(l){const h=s.encode(l),y=e.encodingLength(l.leafHashes.length),p=Buffer.allocUnsafe(y);e.encode(l.leafHashes.length,p);const m=Buffer.concat([p,...l.leafHashes,h.value]);return Object.assign({},h,{value:m})}const a="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";function u(l){return Array.isArray(l.leafHashes)&&l.leafHashes.every(h=>Buffer.isBuffer(h)&&h.length===32)&&s.check(l)}return{decode:o,encode:c,check:u,expected:a,canAddToArray:s.canAddToArray}}return wo.makeConverter=r,wo}var bo={},Cl;function nm(){if(Cl)return bo;Cl=1,Object.defineProperty(bo,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t||c.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+c.key.toString("hex"));if(c.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)&&c.length===32}function o(c,a){return!!c&&!!a&&c.tapInternalKey===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return bo.makeConverter=e,bo}var Eo={},Ul;function rm(){if(Ul)return Eo;Ul=1,Object.defineProperty(Eo,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.witnessScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Eo.makeConverter=e,Eo}var Hl;function ua(){if(Hl)return ai;Hl=1,Object.defineProperty(ai,"__esModule",{value:!0});const e=bt(),t=My(),n=Ly(),r=Vy(),i=Dy(),s=jy(),o=$y(),c=Ky(),a=Gy(),u=Wy(),l=Xy(),h=zy(),y=Yy(),p=Zy(),m=Jy(),g=Nl(),E=Qy(),x=em(),_=tm(),w=nm(),T=rm(),R={unsignedTx:n,globalXpub:t,checkPubkey:E.makeChecker([])};ai.globals=R;const B={nonWitnessUtxo:s,partialSig:o,sighashType:a,finalScriptSig:r,finalScriptWitness:i,porCommitment:c,witnessUtxo:p,bip32Derivation:g.makeConverter(e.InputTypes.BIP32_DERIVATION),redeemScript:x.makeConverter(e.InputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.InputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.InputTypes.PARTIAL_SIG,e.InputTypes.BIP32_DERIVATION]),tapKeySig:u,tapScriptSig:y,tapLeafScript:l,tapBip32Derivation:_.makeConverter(e.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:w.makeConverter(e.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:h};ai.inputs=B;const P={bip32Derivation:g.makeConverter(e.OutputTypes.BIP32_DERIVATION),redeemScript:x.makeConverter(e.OutputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.OutputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:_.makeConverter(e.OutputTypes.TAP_BIP32_DERIVATION),tapTree:m,tapInternalKey:w.makeConverter(e.OutputTypes.TAP_INTERNAL_KEY)};return ai.outputs=P,ai}var Fl;function im(){if(Fl)return ci;Fl=1,Object.defineProperty(ci,"__esModule",{value:!0});const e=ua(),t=aa(),n=Pr(),r=bt();function i(c,a){let u=0;function l(){const P=n.decode(c,u);u+=n.encodingLength(P);const q=c.slice(u,u+P);return u+=P,q}function h(){const P=c.readUInt32BE(u);return u+=4,P}function y(){const P=c.readUInt8(u);return u+=1,P}function p(){const P=l(),q=l();return{key:P,value:q}}function m(){if(u>=c.length)throw new Error("Format Error: Unexpected End of PSBT");const P=c.readUInt8(u)===0;return P&&u++,P}if(h()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(y()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const g=[],E={};for(;!m();){const P=p(),q=P.key.toString("hex");if(E[q])throw new Error("Format Error: Keys must be unique for global keymap: key "+q);E[q]=1,g.push(P)}const x=g.filter(P=>P.key[0]===r.GlobalTypes.UNSIGNED_TX);if(x.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const _=a(x[0].value),{inputCount:w,outputCount:T}=_.getInputOutputCounts(),R=[],B=[];for(const P of t.range(w)){const q={},v=[];for(;!m();){const C=p(),L=C.key.toString("hex");if(q[L])throw new Error("Format Error: Keys must be unique for each input: input index "+P+" key "+L);q[L]=1,v.push(C)}R.push(v)}for(const P of t.range(T)){const q={},v=[];for(;!m();){const C=p(),L=C.key.toString("hex");if(q[L])throw new Error("Format Error: Keys must be unique for each output: output index "+P+" key "+L);q[L]=1,v.push(C)}B.push(v)}return o(_,{globalMapKeyVals:g,inputKeyVals:R,outputKeyVals:B})}ci.psbtFromBuffer=i;function s(c,a,u){if(!a.equals(Buffer.from([u])))throw new Error(`Format Error: Invalid ${c} key: ${a.toString("hex")}`)}ci.checkKeyBuffer=s;function o(c,{globalMapKeyVals:a,inputKeyVals:u,outputKeyVals:l}){const h={unsignedTx:c};let y=0;for(const x of a)switch(x.key[0]){case r.GlobalTypes.UNSIGNED_TX:if(s("global",x.key,r.GlobalTypes.UNSIGNED_TX),y>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");y++;break;case r.GlobalTypes.GLOBAL_XPUB:h.globalXpub===void 0&&(h.globalXpub=[]),h.globalXpub.push(e.globals.globalXpub.decode(x));break;default:h.unknownKeyVals||(h.unknownKeyVals=[]),h.unknownKeyVals.push(x)}const p=u.length,m=l.length,g=[],E=[];for(const x of t.range(p)){const _={};for(const w of u[x])switch(e.inputs.checkPubkey(w),w.key[0]){case r.InputTypes.NON_WITNESS_UTXO:if(s("input",w.key,r.InputTypes.NON_WITNESS_UTXO),_.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");_.nonWitnessUtxo=e.inputs.nonWitnessUtxo.decode(w);break;case r.InputTypes.WITNESS_UTXO:if(s("input",w.key,r.InputTypes.WITNESS_UTXO),_.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");_.witnessUtxo=e.inputs.witnessUtxo.decode(w);break;case r.InputTypes.PARTIAL_SIG:_.partialSig===void 0&&(_.partialSig=[]),_.partialSig.push(e.inputs.partialSig.decode(w));break;case r.InputTypes.SIGHASH_TYPE:if(s("input",w.key,r.InputTypes.SIGHASH_TYPE),_.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");_.sighashType=e.inputs.sighashType.decode(w);break;case r.InputTypes.REDEEM_SCRIPT:if(s("input",w.key,r.InputTypes.REDEEM_SCRIPT),_.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");_.redeemScript=e.inputs.redeemScript.decode(w);break;case r.InputTypes.WITNESS_SCRIPT:if(s("input",w.key,r.InputTypes.WITNESS_SCRIPT),_.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");_.witnessScript=e.inputs.witnessScript.decode(w);break;case r.InputTypes.BIP32_DERIVATION:_.bip32Derivation===void 0&&(_.bip32Derivation=[]),_.bip32Derivation.push(e.inputs.bip32Derivation.decode(w));break;case r.InputTypes.FINAL_SCRIPTSIG:s("input",w.key,r.InputTypes.FINAL_SCRIPTSIG),_.finalScriptSig=e.inputs.finalScriptSig.decode(w);break;case r.InputTypes.FINAL_SCRIPTWITNESS:s("input",w.key,r.InputTypes.FINAL_SCRIPTWITNESS),_.finalScriptWitness=e.inputs.finalScriptWitness.decode(w);break;case r.InputTypes.POR_COMMITMENT:s("input",w.key,r.InputTypes.POR_COMMITMENT),_.porCommitment=e.inputs.porCommitment.decode(w);break;case r.InputTypes.TAP_KEY_SIG:s("input",w.key,r.InputTypes.TAP_KEY_SIG),_.tapKeySig=e.inputs.tapKeySig.decode(w);break;case r.InputTypes.TAP_SCRIPT_SIG:_.tapScriptSig===void 0&&(_.tapScriptSig=[]),_.tapScriptSig.push(e.inputs.tapScriptSig.decode(w));break;case r.InputTypes.TAP_LEAF_SCRIPT:_.tapLeafScript===void 0&&(_.tapLeafScript=[]),_.tapLeafScript.push(e.inputs.tapLeafScript.decode(w));break;case r.InputTypes.TAP_BIP32_DERIVATION:_.tapBip32Derivation===void 0&&(_.tapBip32Derivation=[]),_.tapBip32Derivation.push(e.inputs.tapBip32Derivation.decode(w));break;case r.InputTypes.TAP_INTERNAL_KEY:s("input",w.key,r.InputTypes.TAP_INTERNAL_KEY),_.tapInternalKey=e.inputs.tapInternalKey.decode(w);break;case r.InputTypes.TAP_MERKLE_ROOT:s("input",w.key,r.InputTypes.TAP_MERKLE_ROOT),_.tapMerkleRoot=e.inputs.tapMerkleRoot.decode(w);break;default:_.unknownKeyVals||(_.unknownKeyVals=[]),_.unknownKeyVals.push(w)}g.push(_)}for(const x of t.range(m)){const _={};for(const w of l[x])switch(e.outputs.checkPubkey(w),w.key[0]){case r.OutputTypes.REDEEM_SCRIPT:if(s("output",w.key,r.OutputTypes.REDEEM_SCRIPT),_.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");_.redeemScript=e.outputs.redeemScript.decode(w);break;case r.OutputTypes.WITNESS_SCRIPT:if(s("output",w.key,r.OutputTypes.WITNESS_SCRIPT),_.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");_.witnessScript=e.outputs.witnessScript.decode(w);break;case r.OutputTypes.BIP32_DERIVATION:_.bip32Derivation===void 0&&(_.bip32Derivation=[]),_.bip32Derivation.push(e.outputs.bip32Derivation.decode(w));break;case r.OutputTypes.TAP_INTERNAL_KEY:s("output",w.key,r.OutputTypes.TAP_INTERNAL_KEY),_.tapInternalKey=e.outputs.tapInternalKey.decode(w);break;case r.OutputTypes.TAP_TREE:s("output",w.key,r.OutputTypes.TAP_TREE),_.tapTree=e.outputs.tapTree.decode(w);break;case r.OutputTypes.TAP_BIP32_DERIVATION:_.tapBip32Derivation===void 0&&(_.tapBip32Derivation=[]),_.tapBip32Derivation.push(e.outputs.tapBip32Derivation.decode(w));break;default:_.unknownKeyVals||(_.unknownKeyVals=[]),_.unknownKeyVals.push(w)}E.push(_)}return{globalMap:h,inputs:g,outputs:E}}return ci.psbtFromKeyVals=o,ci}var fs={},ql;function sm(){if(ql)return fs;ql=1,Object.defineProperty(fs,"__esModule",{value:!0});const e=ua(),t=aa();function n({globalMap:o,inputs:c,outputs:a}){const{globalKeyVals:u,inputKeyVals:l,outputKeyVals:h}=s({globalMap:o,inputs:c,outputs:a}),y=t.keyValsToBuffer(u),p=x=>x.length===0?[Buffer.from([0])]:x.map(t.keyValsToBuffer),m=p(l),g=p(h),E=Buffer.allocUnsafe(5);return E.writeUIntBE(482972169471,0,5),Buffer.concat([E,y].concat(m,g))}fs.psbtToBuffer=n;const r=(o,c)=>o.key.compare(c.key);function i(o,c){const a=new Set,u=Object.entries(o).reduce((h,[y,p])=>{if(y==="unknownKeyVals")return h;const m=c[y];if(m===void 0)return h;const g=(Array.isArray(p)?p:[p]).map(m.encode);return g.map(x=>x.key.toString("hex")).forEach(x=>{if(a.has(x))throw new Error("Serialize Error: Duplicate key: "+x);a.add(x)}),h.concat(g)},[]),l=o.unknownKeyVals?o.unknownKeyVals.filter(h=>!a.has(h.key.toString("hex"))):[];return u.concat(l).sort(r)}function s({globalMap:o,inputs:c,outputs:a}){return{globalKeyVals:i(o,e.globals),inputKeyVals:c.map(u=>i(u,e.inputs)),outputKeyVals:a.map(u=>i(u,e.outputs))}}return fs.psbtToKeyVals=s,fs}var Ml;function Ll(){return Ml||(Ml=1,(function(e){function t(n){for(var r in n)e.hasOwnProperty(r)||(e[r]=n[r])}Object.defineProperty(e,"__esModule",{value:!0}),t(im()),t(sm())})(oa)),oa}var Vl;function om(){if(Vl)return ho;Vl=1,Object.defineProperty(ho,"__esModule",{value:!0});const e=Ll();function t(s){const o=s[0],c=e.psbtToKeyVals(o),a=s.slice(1);if(a.length===0)throw new Error("Combine: Nothing to combine");const u=r(o);if(u===void 0)throw new Error("Combine: Self missing transaction");const l=i(c.globalKeyVals),h=c.inputKeyVals.map(i),y=c.outputKeyVals.map(i);for(const p of a){const m=r(p);if(m===void 0||!m.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const g=e.psbtToKeyVals(p);i(g.globalKeyVals).forEach(n(l,c.globalKeyVals,g.globalKeyVals)),g.inputKeyVals.map(i).forEach((w,T)=>w.forEach(n(h[T],c.inputKeyVals[T],g.inputKeyVals[T]))),g.outputKeyVals.map(i).forEach((w,T)=>w.forEach(n(y[T],c.outputKeyVals[T],g.outputKeyVals[T])))}return e.psbtFromKeyVals(u,{globalMapKeyVals:c.globalKeyVals,inputKeyVals:c.inputKeyVals,outputKeyVals:c.outputKeyVals})}ho.combine=t;function n(s,o,c){return a=>{if(s.has(a))return;const u=c.filter(l=>l.key.toString("hex")===a)[0];o.push(u),s.add(a)}}function r(s){return s.globalMap.unsignedTx}function i(s){const o=new Set;return s.forEach(c=>{const a=c.key.toString("hex");if(o.has(a))throw new Error("Combine: KeyValue Map keys should be unique");o.add(a)}),o}return ho}var fa={},Dl;function jl(){return Dl||(Dl=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=ua();function n(p,m){const g=p[m];if(g===void 0)throw new Error(`No input #${m}`);return g}e.checkForInput=n;function r(p,m){const g=p[m];if(g===void 0)throw new Error(`No output #${m}`);return g}e.checkForOutput=r;function i(p,m,g){if(p.key[0]<g)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(m&&m.filter(E=>E.key.equals(p.key)).length!==0)throw new Error(`Duplicate Key: ${p.key.toString("hex")}`)}e.checkHasKey=i;function s(p){let m=0;return Object.keys(p).forEach(g=>{Number(isNaN(Number(g)))&&m++}),m}e.getEnumLength=s;function o(p,m){let g=!1;if(m.nonWitnessUtxo||m.witnessUtxo){const E=!!m.redeemScript,x=!!m.witnessScript,_=!E||!!m.finalScriptSig,w=!x||!!m.finalScriptWitness,T=!!m.finalScriptSig||!!m.finalScriptWitness;g=_&&w&&T}if(g===!1)throw new Error(`Input #${p} has too much or too little data to clean`)}e.inputCheckUncleanFinalized=o;function c(p,m,g,E){throw new Error(`Data for ${p} key ${m} is incorrect: Expected ${g} and got ${JSON.stringify(E)}`)}function a(p){return(m,g)=>{for(const E of Object.keys(m)){const x=m[E],{canAdd:_,canAddToArray:w,check:T,expected:R}=t[p+"s"][E]||{},B=!!w;if(T)if(B){if(!Array.isArray(x)||g[E]&&!Array.isArray(g[E]))throw new Error(`Key type ${E} must be an array`);x.every(T)||c(p,E,R,x);const P=g[E]||[],q=new Set;if(!x.every(v=>w(P,v,q)))throw new Error("Can not add duplicate data to array");g[E]=P.concat(x)}else{if(T(x)||c(p,E,R,x),!_(g,x))throw new Error(`Can not add duplicate data to ${p}`);g[E]=x}}}}e.updateGlobal=a("global"),e.updateInput=a("input"),e.updateOutput=a("output");function u(p,m){const g=p.length-1,E=n(p,g);e.updateInput(m,E)}e.addInputAttributes=u;function l(p,m){const g=p.length-1,E=r(p,g);e.updateOutput(m,E)}e.addOutputAttributes=l;function h(p,m){if(!Buffer.isBuffer(m)||m.length<4)throw new Error("Set Version: Invalid Transaction");return m.writeUInt32LE(p,0),m}e.defaultVersionSetter=h;function y(p,m){if(!Buffer.isBuffer(m)||m.length<4)throw new Error("Set Locktime: Invalid Transaction");return m.writeUInt32LE(p,m.length-4),m}e.defaultLocktimeSetter=y})(fa)),fa}var $l;function cm(){if($l)return lo;$l=1,Object.defineProperty(lo,"__esModule",{value:!0});const e=om(),t=Ll(),n=bt(),r=jl();class i{constructor(o){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:o}}static fromBase64(o,c){const a=Buffer.from(o,"base64");return this.fromBuffer(a,c)}static fromHex(o,c){const a=Buffer.from(o,"hex");return this.fromBuffer(a,c)}static fromBuffer(o,c){const a=t.psbtFromBuffer(o,c),u=new this(a.globalMap.unsignedTx);return Object.assign(u,a),u}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return t.psbtToBuffer(this)}updateGlobal(o){return r.updateGlobal(o,this.globalMap),this}updateInput(o,c){const a=r.checkForInput(this.inputs,o);return r.updateInput(c,a),this}updateOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.updateOutput(c,a),this}addUnknownKeyValToGlobal(o){return r.checkHasKey(o,this.globalMap.unknownKeyVals,r.getEnumLength(n.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(o),this}addUnknownKeyValToInput(o,c){const a=r.checkForInput(this.inputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.InputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addUnknownKeyValToOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.OutputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addInput(o){this.globalMap.unsignedTx.addInput(o),this.inputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.inputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToInput(a,u)),r.addInputAttributes(this.inputs,o),this}addOutput(o){this.globalMap.unsignedTx.addOutput(o),this.outputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.outputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToOutput(a,u)),r.addOutputAttributes(this.outputs,o),this}clearFinalizedInput(o){const c=r.checkForInput(this.inputs,o);r.inputCheckUncleanFinalized(o,c);for(const a of Object.keys(c))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(a)||delete c[a];return this}combine(...o){const c=e.combine([this].concat(o));return Object.assign(this,c),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}return lo.Psbt=i,lo}var Ge={},je={},Kl;function la(){if(Kl)return je;Kl=1,Object.defineProperty(je,"__esModule",{value:!0}),je.signatureBlocksAction=je.checkInputForSig=je.pubkeyInScript=je.pubkeyPositionInScript=je.witnessStackToScriptWitness=je.isP2TR=je.isP2SHScript=je.isP2WSHScript=je.isP2WPKH=je.isP2PKH=je.isP2PK=je.isP2MS=void 0;const e=Pr(),t=kt(),n=as(),r=Nn(),i=is();function s(p){return m=>{try{return p({output:m}),!0}catch{return!1}}}je.isP2MS=s(i.p2ms),je.isP2PK=s(i.p2pk),je.isP2PKH=s(i.p2pkh),je.isP2WPKH=s(i.p2wpkh),je.isP2WSHScript=s(i.p2wsh),je.isP2SHScript=s(i.p2sh),je.isP2TR=s(i.p2tr);function o(p){let m=Buffer.allocUnsafe(0);function g(w){m=Buffer.concat([m,Buffer.from(w)])}function E(w){const T=m.length,R=e.encodingLength(w);m=Buffer.concat([m,Buffer.allocUnsafe(R)]),e.encode(w,m,T)}function x(w){E(w.length),g(w)}function _(w){E(w.length),w.forEach(x)}return _(p),m}je.witnessStackToScriptWitness=o;function c(p,m){const g=(0,r.hash160)(p),E=p.slice(1,33),x=t.decompile(m);if(x===null)throw new Error("Unknown script error");return x.findIndex(_=>typeof _=="number"?!1:_.equals(p)||_.equals(g)||_.equals(E))}je.pubkeyPositionInScript=c;function a(p,m){return c(p,m)!==-1}je.pubkeyInScript=a;function u(p,m){return h(p).some(E=>l(E,t.signature.decode,m))}je.checkInputForSig=u;function l(p,m,g){const{hashType:E}=m(p),x=[];switch(E&n.Transaction.SIGHASH_ANYONECANPAY&&x.push("addInput"),E&31){case n.Transaction.SIGHASH_ALL:break;case n.Transaction.SIGHASH_SINGLE:case n.Transaction.SIGHASH_NONE:x.push("addOutput"),x.push("setInputSequence");break}return x.indexOf(g)===-1}je.signatureBlocksAction=l;function h(p){let m=[];if((p.partialSig||[]).length===0){if(!p.finalScriptSig&&!p.finalScriptWitness)return[];m=y(p)}else m=p.partialSig;return m.map(g=>g.signature)}function y(p){const m=p.finalScriptSig?t.decompile(p.finalScriptSig)||[]:[],g=p.finalScriptWitness?t.decompile(p.finalScriptWitness)||[]:[];return m.concat(g).filter(E=>Buffer.isBuffer(E)&&t.isCanonicalScriptSignature(E)).map(E=>({signature:E}))}return je}var Gl;function am(){if(Gl)return Ge;Gl=1,Object.defineProperty(Ge,"__esModule",{value:!0}),Ge.checkTaprootInputForSigs=Ge.tapTreeFromList=Ge.tapTreeToList=Ge.tweakInternalPubKey=Ge.checkTaprootOutputFields=Ge.checkTaprootInputFields=Ge.isTaprootOutput=Ge.isTaprootInput=Ge.serializeTaprootSignature=Ge.tapScriptFinalizer=Ge.toXOnly=void 0;const e=vt(),t=as(),n=la(),r=ia(),i=is(),s=la(),o=S=>S.length===32?S:S.slice(1,33);Ge.toXOnly=o;function c(S,I,M){const O=k(I,S,M);try{const G=U(I,O).concat(O.script).concat(O.controlBlock);return{finalScriptWitness:(0,n.witnessStackToScriptWitness)(G)}}catch(V){throw new Error(`Can not finalize taproot input #${S}: ${V}`)}}Ge.tapScriptFinalizer=c;function a(S,I){const M=I?Buffer.from([I]):Buffer.from([]);return Buffer.concat([S,M])}Ge.serializeTaprootSignature=a;function u(S){return S&&!!(S.tapInternalKey||S.tapMerkleRoot||S.tapLeafScript&&S.tapLeafScript.length||S.tapBip32Derivation&&S.tapBip32Derivation.length||S.witnessUtxo&&(0,n.isP2TR)(S.witnessUtxo.script))}Ge.isTaprootInput=u;function l(S,I){return S&&!!(S.tapInternalKey||S.tapTree||S.tapBip32Derivation&&S.tapBip32Derivation.length||I&&(0,n.isP2TR)(I))}Ge.isTaprootOutput=l;function h(S,I,M){v(S,I,M),L(S,I,M)}Ge.checkTaprootInputFields=h;function y(S,I,M){C(S,I,M),p(S,I)}Ge.checkTaprootOutputFields=y;function p(S,I){if(!I.tapTree&&!I.tapInternalKey)return;const M=I.tapInternalKey||S.tapInternalKey,O=I.tapTree||S.tapTree;if(M){const{script:V}=S,G=m(M,O);if(V&&!V.equals(G))throw new Error("Error adding output. Script or address missmatch.")}}function m(S,I){const M=I&&x(I.leaves),{output:O}=(0,i.p2tr)({internalPubkey:S,scriptTree:M});return O}function g(S,I){const M=I.tapInternalKey,O=M&&(0,r.tweakKey)(M,I.tapMerkleRoot);if(!O)throw new Error(`Cannot tweak tap internal key for input #${S}. Public key: ${M&&M.toString("hex")}`);return O.x}Ge.tweakInternalPubKey=g;function E(S){if(!(0,e.isTaptree)(S))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return B(S)}Ge.tapTreeToList=E;function x(S=[]){return S.length===1&&S[0].depth===0?{output:S[0].script,version:S[0].leafVersion}:P(S)}Ge.tapTreeFromList=x;function _(S,I){return T(S).some(O=>(0,s.signatureBlocksAction)(O,w,I))}Ge.checkTaprootInputForSigs=_;function w(S){return{signature:S.slice(0,64),hashType:S.slice(64)[0]||t.Transaction.SIGHASH_DEFAULT}}function T(S){const I=[];if(S.tapKeySig&&I.push(S.tapKeySig),S.tapScriptSig&&I.push(...S.tapScriptSig.map(M=>M.signature)),!I.length){const M=R(S.finalScriptWitness);M&&I.push(M)}return I}function R(S){if(!S)return;const I=S.slice(2);if(I.length===64||I.length===65)return I}function B(S,I=[],M=0){if(M>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return S?(0,e.isTapleaf)(S)?(I.push({depth:M,leafVersion:S.version||r.LEAF_VERSION_TAPSCRIPT,script:S.output}),I):(S[0]&&B(S[0],I,M+1),S[1]&&B(S[1],I,M+1),I):[]}function P(S){let I;for(const M of S)if(I=q(M,I),!I)throw new Error("No room left to insert tapleaf in tree");return I}function q(S,I,M=0){if(M>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(S.depth===M)return I?void 0:{output:S.script,version:S.leafVersion};if((0,e.isTapleaf)(I))return;const O=q(S,I&&I[0],M+1);if(O)return[O,I&&I[1]];const V=q(S,I&&I[1],M+1);if(V)return[I&&I[0],V]}function v(S,I,M){const O=u(S)&&F(I),V=F(S)&&u(I),G=S===I&&u(I)&&F(I);if(O||V||G)throw new Error(`Invalid arguments for Psbt.${M}. Cannot use both taproot and non-taproot fields.`)}function C(S,I,M){const O=l(S)&&F(I),V=F(S)&&l(I),G=S===I&&l(I)&&F(I);if(O||V||G)throw new Error(`Invalid arguments for Psbt.${M}. Cannot use both taproot and non-taproot fields.`)}function L(S,I,M){if(I.tapMerkleRoot){const O=(I.tapLeafScript||[]).every(G=>K(G,I.tapMerkleRoot)),V=(S.tapLeafScript||[]).every(G=>K(G,I.tapMerkleRoot));if(!O||!V)throw new Error(`Invalid arguments for Psbt.${M}. Tapleaf not part of taptree.`)}else if(S.tapMerkleRoot&&!(I.tapLeafScript||[]).every(V=>K(V,S.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${M}. Tapleaf not part of taptree.`)}function K(S,I){if(!I)return!0;const M=(0,r.tapleafHash)({output:S.script,version:S.leafVersion});return(0,r.rootHashFromPath)(S.controlBlock,M).equals(I)}function U(S,I){const M=(0,r.tapleafHash)({output:I.script,version:I.leafVersion});return(S.tapScriptSig||[]).filter(O=>O.leafHash.equals(M)).map(O=>D(I.script,O)).sort((O,V)=>V.positionInScript-O.positionInScript).map(O=>O.signature)}function D(S,I){return Object.assign({positionInScript:(0,n.pubkeyPositionInScript)(I.pubkey,S)},I)}function k(S,I,M){if(!S.tapScriptSig||!S.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${I}. No tapleaf script signature provided.`);const O=(S.tapLeafScript||[]).sort((V,G)=>V.controlBlock.length-G.controlBlock.length).find(V=>j(V,S.tapScriptSig,M));if(!O)throw new Error(`Can not finalize taproot input #${I}. Signature for tapleaf script not found.`);return O}function j(S,I,M){const O=(0,r.tapleafHash)({output:S.script,version:S.leafVersion});return(!M||M.equals(O))&&I.find(G=>G.leafHash.equals(O))!==void 0}function F(S){return S&&!!(S.redeemScript||S.witnessScript||S.bip32Derivation&&S.bip32Derivation.length)}return Ge}var Wl;function um(){if(Wl)return us;Wl=1,Object.defineProperty(us,"__esModule",{value:!0}),us.Psbt=void 0;const e=cm(),t=Pr(),n=jl(),r=sa(),i=fo(),s=cn(),o=is(),c=ia(),a=kt(),u=as(),l=am(),h=la(),y={network:s.bitcoin,maximumFeeRate:5e3};class p{static fromBase64(f,b={}){const A=Buffer.from(f,"base64");return this.fromBuffer(A,b)}static fromHex(f,b={}){const A=Buffer.from(f,"hex");return this.fromBuffer(A,b)}static fromBuffer(f,b={}){const A=e.Psbt.fromBuffer(f,m),H=new p(b,A);return L(H.__CACHE.__TX,H.__CACHE),H}constructor(f={},b=new e.Psbt(new g)){this.data=b,this.opts=Object.assign({},y,f),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const A=(H,$,W,ie)=>Object.defineProperty(H,$,{enumerable:W,writable:ie});A(this,"__CACHE",!1,!0),A(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(f){this.setVersion(f)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(f){this.setLocktime(f)}get txInputs(){return this.__CACHE.__TX.ins.map(f=>({hash:(0,i.cloneBuffer)(f.hash),index:f.index,sequence:f.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(f=>{let b;try{b=(0,r.fromOutputScript)(f.script,this.opts.network)}catch{}return{script:(0,i.cloneBuffer)(f.script),value:f.value,address:b}})}combine(...f){return this.data.combine(...f.map(b=>b.data)),this}clone(){const f=p.fromBuffer(this.data.toBuffer());return f.opts=JSON.parse(JSON.stringify(this.opts)),f}setMaximumFeeRate(f){R(f),this.opts.maximumFeeRate=f}setVersion(f){R(f),P(this.data.inputs,"setVersion");const b=this.__CACHE;return b.__TX.version=f,b.__EXTRACTED_TX=void 0,this}setLocktime(f){R(f),P(this.data.inputs,"setLocktime");const b=this.__CACHE;return b.__TX.locktime=f,b.__EXTRACTED_TX=void 0,this}setInputSequence(f,b){R(b),P(this.data.inputs,"setInputSequence");const A=this.__CACHE;if(A.__TX.ins.length<=f)throw new Error("Input index too high");return A.__TX.ins[f].sequence=b,A.__EXTRACTED_TX=void 0,this}addInputs(f){return f.forEach(b=>this.addInput(b)),this}addInput(f){if(arguments.length>1||!f||f.hash===void 0||f.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");(0,l.checkTaprootInputFields)(f,f,"addInput"),P(this.data.inputs,"addInput"),f.witnessScript&&ne(f.witnessScript);const b=this.__CACHE;this.data.addInput(f);const A=b.__TX.ins[b.__TX.ins.length-1];K(b,A);const H=this.data.inputs.length-1,$=this.data.inputs[H];return $.nonWitnessUtxo&&pe(this.__CACHE,$,H),b.__FEE=void 0,b.__FEE_RATE=void 0,b.__EXTRACTED_TX=void 0,this}addOutputs(f){return f.forEach(b=>this.addOutput(b)),this}addOutput(f){if(arguments.length>1||!f||f.value===void 0||f.address===void 0&&f.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");P(this.data.inputs,"addOutput");const{address:b}=f;if(typeof b=="string"){const{network:H}=this.opts,$=(0,r.toOutputScript)(b,H);f=Object.assign({},f,{script:$})}(0,l.checkTaprootOutputFields)(f,f,"addOutput");const A=this.__CACHE;return this.data.addOutput(f),A.__FEE=void 0,A.__FEE_RATE=void 0,A.__EXTRACTED_TX=void 0,this}extractTransaction(f){if(!this.data.inputs.every(w))throw new Error("Not finalized");const b=this.__CACHE;if(f||B(this,b,this.opts),b.__EXTRACTED_TX)return b.__EXTRACTED_TX;const A=b.__TX.clone();return J(this.data.inputs,A,b,!0),A}getFeeRate(){return j("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return j("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,n.checkForInput)(this.data.inputs,0),N(this.data.inputs.length).forEach(f=>this.finalizeInput(f)),this}finalizeInput(f,b){const A=(0,n.checkForInput)(this.data.inputs,f);return(0,l.isTaprootInput)(A)?this._finalizeTaprootInput(f,A,void 0,b):this._finalizeInput(f,A,b)}finalizeTaprootInput(f,b,A=l.tapScriptFinalizer){const H=(0,n.checkForInput)(this.data.inputs,f);if((0,l.isTaprootInput)(H))return this._finalizeTaprootInput(f,H,b,A);throw new Error(`Cannot finalize input #${f}. Not Taproot.`)}_finalizeInput(f,b,A=F){const{script:H,isP2SH:$,isP2WSH:W,isSegwit:ie}=ue(f,b,this.__CACHE);if(!H)throw new Error(`No script found for input #${f}`);q(b);const{finalScriptSig:Q,finalScriptWitness:fe}=A(f,b,H,ie,$,W);if(Q&&this.data.updateInput(f,{finalScriptSig:Q}),fe&&this.data.updateInput(f,{finalScriptWitness:fe}),!Q&&!fe)throw new Error(`Unknown error finalizing input #${f}`);return this.data.clearFinalizedInput(f),this}_finalizeTaprootInput(f,b,A,H=l.tapScriptFinalizer){if(!b.witnessUtxo)throw new Error(`Cannot finalize input #${f}. Missing withness utxo.`);if(b.tapKeySig){const $=o.p2tr({output:b.witnessUtxo.script,signature:b.tapKeySig}),W=(0,h.witnessStackToScriptWitness)($.witness);this.data.updateInput(f,{finalScriptWitness:W})}else{const{finalScriptWitness:$}=H(f,b,A);this.data.updateInput(f,{finalScriptWitness:$})}return this.data.clearFinalizedInput(f),this}getInputType(f){const b=(0,n.checkForInput)(this.data.inputs,f),A=xe(f,b,this.__CACHE),H=oe(A,f,"input",b.redeemScript||gt(b.finalScriptSig),b.witnessScript||ve(b.finalScriptWitness)),$=H.type==="raw"?"":H.type+"-",W=re(H.meaningfulScript);return $+W}inputHasPubkey(f,b){const A=(0,n.checkForInput)(this.data.inputs,f);return tt(b,A,f,this.__CACHE)}inputHasHDKey(f,b){const A=(0,n.checkForInput)(this.data.inputs,f),H=T(b);return!!A.bip32Derivation&&A.bip32Derivation.some(H)}outputHasPubkey(f,b){const A=(0,n.checkForOutput)(this.data.outputs,f);return ut(b,A,f,this.__CACHE)}outputHasHDKey(f,b){const A=(0,n.checkForOutput)(this.data.outputs,f),H=T(b);return!!A.bip32Derivation&&A.bip32Derivation.some(H)}validateSignaturesOfAllInputs(f){return(0,n.checkForInput)(this.data.inputs,0),N(this.data.inputs.length).map(A=>this.validateSignaturesOfInput(A,f)).reduce((A,H)=>H===!0&&A,!0)}validateSignaturesOfInput(f,b,A){const H=this.data.inputs[f];return(0,l.isTaprootInput)(H)?this.validateSignaturesOfTaprootInput(f,b,A):this._validateSignaturesOfInput(f,b,A)}_validateSignaturesOfInput(f,b,A){const H=this.data.inputs[f],$=(H||{}).partialSig;if(!H||!$||$.length<1)throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");const W=A?$.filter(Ae=>Ae.pubkey.equals(A)):$;if(W.length<1)throw new Error("No signatures for this pubkey");const ie=[];let Q,fe,le;for(const Ae of W){const Ne=a.signature.decode(Ae.signature),{hash:Ye,script:Ve}=le!==Ne.hashType?M(f,Object.assign({},H,{sighashType:Ne.hashType}),this.__CACHE,!0):{hash:Q,script:fe};le=Ne.hashType,Q=Ye,fe=Ve,v(Ae.pubkey,Ve,"verify"),ie.push(b(Ae.pubkey,Ye,Ne.signature))}return ie.every(Ae=>Ae===!0)}validateSignaturesOfTaprootInput(f,b,A){const H=this.data.inputs[f],$=(H||{}).tapKeySig,W=(H||{}).tapScriptSig;if(!H&&!$&&!(W&&!W.length))throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");A=A&&(0,l.toXOnly)(A);const ie=A?X(f,H,this.data.inputs,A,this.__CACHE):O(f,H,this.data.inputs,this.__CACHE);if(!ie.length)throw new Error("No signatures for this pubkey");const Q=ie.find(le=>!le.leafHash);let fe=0;if($&&Q){if(!b(Q.pubkey,Q.hash,G($)))return!1;fe++}if(W)for(const le of W){const Ae=ie.find(Ne=>le.pubkey.equals(Ne.pubkey));if(Ae){if(!b(le.pubkey,Ae.hash,G(le.signature)))return!1;fe++}}return fe>0}signAllInputsHD(f,b=[u.Transaction.SIGHASH_ALL]){if(!f||!f.publicKey||!f.fingerprint)throw new Error("Need HDSigner to sign input");const A=[];for(const H of N(this.data.inputs.length))try{this.signInputHD(H,f,b),A.push(!0)}catch{A.push(!1)}if(A.every(H=>H===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(f,b=[u.Transaction.SIGHASH_ALL]){return new Promise((A,H)=>{if(!f||!f.publicKey||!f.fingerprint)return H(new Error("Need HDSigner to sign input"));const $=[],W=[];for(const ie of N(this.data.inputs.length))W.push(this.signInputHDAsync(ie,f,b).then(()=>{$.push(!0)},()=>{$.push(!1)}));return Promise.all(W).then(()=>{if($.every(ie=>ie===!1))return H(new Error("No inputs were signed"));A()})})}signInputHD(f,b,A=[u.Transaction.SIGHASH_ALL]){if(!b||!b.publicKey||!b.fingerprint)throw new Error("Need HDSigner to sign input");return te(f,this.data.inputs,b).forEach($=>this.signInput(f,$,A)),this}signInputHDAsync(f,b,A=[u.Transaction.SIGHASH_ALL]){return new Promise((H,$)=>{if(!b||!b.publicKey||!b.fingerprint)return $(new Error("Need HDSigner to sign input"));const ie=te(f,this.data.inputs,b).map(Q=>this.signInputAsync(f,Q,A));return Promise.all(ie).then(()=>{H()}).catch($)})}signAllInputs(f,b){if(!f||!f.publicKey)throw new Error("Need Signer to sign input");const A=[];for(const H of N(this.data.inputs.length))try{this.signInput(H,f,b),A.push(!0)}catch{A.push(!1)}if(A.every(H=>H===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(f,b){return new Promise((A,H)=>{if(!f||!f.publicKey)return H(new Error("Need Signer to sign input"));const $=[],W=[];for(const[ie]of this.data.inputs.entries())W.push(this.signInputAsync(ie,f,b).then(()=>{$.push(!0)},()=>{$.push(!1)}));return Promise.all(W).then(()=>{if($.every(ie=>ie===!1))return H(new Error("No inputs were signed"));A()})})}signInput(f,b,A){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const H=(0,n.checkForInput)(this.data.inputs,f);return(0,l.isTaprootInput)(H)?this._signTaprootInput(f,H,b,void 0,A):this._signInput(f,b,A)}signTaprootInput(f,b,A,H){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const $=(0,n.checkForInput)(this.data.inputs,f);if((0,l.isTaprootInput)($))return this._signTaprootInput(f,$,b,A,H);throw new Error(`Input #${f} is not of type Taproot.`)}_signInput(f,b,A=[u.Transaction.SIGHASH_ALL]){const{hash:H,sighashType:$}=I(this.data.inputs,f,b.publicKey,this.__CACHE,A),W=[{pubkey:b.publicKey,signature:a.signature.encode(b.sign(H),$)}];return this.data.updateInput(f,{partialSig:W}),this}_signTaprootInput(f,b,A,H,$=[u.Transaction.SIGHASH_DEFAULT]){const W=this.checkTaprootHashesForSig(f,b,A,H,$),ie=W.filter(fe=>!fe.leafHash).map(fe=>(0,l.serializeTaprootSignature)(A.signSchnorr(fe.hash),b.sighashType))[0],Q=W.filter(fe=>!!fe.leafHash).map(fe=>({pubkey:(0,l.toXOnly)(A.publicKey),signature:(0,l.serializeTaprootSignature)(A.signSchnorr(fe.hash),b.sighashType),leafHash:fe.leafHash}));return ie&&this.data.updateInput(f,{tapKeySig:ie}),Q.length&&this.data.updateInput(f,{tapScriptSig:Q}),this}signInputAsync(f,b,A){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const H=(0,n.checkForInput)(this.data.inputs,f);return(0,l.isTaprootInput)(H)?this._signTaprootInputAsync(f,H,b,void 0,A):this._signInputAsync(f,b,A)})}signTaprootInputAsync(f,b,A,H){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const $=(0,n.checkForInput)(this.data.inputs,f);if((0,l.isTaprootInput)($))return this._signTaprootInputAsync(f,$,b,A,H);throw new Error(`Input #${f} is not of type Taproot.`)})}_signInputAsync(f,b,A=[u.Transaction.SIGHASH_ALL]){const{hash:H,sighashType:$}=I(this.data.inputs,f,b.publicKey,this.__CACHE,A);return Promise.resolve(b.sign(H)).then(W=>{const ie=[{pubkey:b.publicKey,signature:a.signature.encode(W,$)}];this.data.updateInput(f,{partialSig:ie})})}async _signTaprootInputAsync(f,b,A,H,$=[u.Transaction.SIGHASH_DEFAULT]){const W=this.checkTaprootHashesForSig(f,b,A,H,$),ie=[],Q=W.filter(le=>!le.leafHash)[0];if(Q){const le=Promise.resolve(A.signSchnorr(Q.hash)).then(Ae=>({tapKeySig:(0,l.serializeTaprootSignature)(Ae,b.sighashType)}));ie.push(le)}const fe=W.filter(le=>!!le.leafHash);if(fe.length){const le=fe.map(Ae=>Promise.resolve(A.signSchnorr(Ae.hash)).then(Ne=>({tapScriptSig:[{pubkey:(0,l.toXOnly)(A.publicKey),signature:(0,l.serializeTaprootSignature)(Ne,b.sighashType),leafHash:Ae.leafHash}]})));ie.push(...le)}return Promise.all(ie).then(le=>{le.forEach(Ae=>this.data.updateInput(f,Ae))})}checkTaprootHashesForSig(f,b,A,H,$){if(typeof A.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${f}.`);const W=X(f,b,this.data.inputs,A.publicKey,this.__CACHE,H,$);if(!W||!W.length)throw new Error(`Can not sign for input #${f} with the key ${A.publicKey.toString("hex")}`);return W}toBuffer(){return x(this.__CACHE),this.data.toBuffer()}toHex(){return x(this.__CACHE),this.data.toHex()}toBase64(){return x(this.__CACHE),this.data.toBase64()}updateGlobal(f){return this.data.updateGlobal(f),this}updateInput(f,b){return b.witnessScript&&ne(b.witnessScript),(0,l.checkTaprootInputFields)(this.data.inputs[f],b,"updateInput"),this.data.updateInput(f,b),b.nonWitnessUtxo&&pe(this.__CACHE,this.data.inputs[f],f),this}updateOutput(f,b){const A=this.data.outputs[f];return(0,l.checkTaprootOutputFields)(A,b,"updateOutput"),this.data.updateOutput(f,b),this}addUnknownKeyValToGlobal(f){return this.data.addUnknownKeyValToGlobal(f),this}addUnknownKeyValToInput(f,b){return this.data.addUnknownKeyValToInput(f,b),this}addUnknownKeyValToOutput(f,b){return this.data.addUnknownKeyValToOutput(f,b),this}clearFinalizedInput(f){return this.data.clearFinalizedInput(f),this}}us.Psbt=p;const m=d=>new g(d);class g{constructor(f=Buffer.from([2,0,0,0,0,0,0,0,0,0])){this.tx=u.Transaction.fromBuffer(f),C(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(f){if(f.hash===void 0||f.index===void 0||!Buffer.isBuffer(f.hash)&&typeof f.hash!="string"||typeof f.index!="number")throw new Error("Error adding input.");const b=typeof f.hash=="string"?(0,i.reverseBuffer)(Buffer.from(f.hash,"hex")):f.hash;this.tx.addInput(b,f.index,f.sequence)}addOutput(f){if(f.script===void 0||f.value===void 0||!Buffer.isBuffer(f.script)||typeof f.value!="number")throw new Error("Error adding output.");this.tx.addOutput(f.script,f.value)}toBuffer(){return this.tx.toBuffer()}}function E(d,f,b){switch(b){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return _(1,d.partialSig);case"multisig":const A=o.p2ms({output:f});return _(A.m,d.partialSig,A.pubkeys);default:return!1}}function x(d){if(d.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function _(d,f,b){if(!f)return!1;let A;if(b?A=b.map(H=>{const $=zt(H);return f.find(W=>W.pubkey.equals($))}).filter(H=>!!H):A=f,A.length>d)throw new Error("Too many signatures");return A.length===d}function w(d){return!!d.finalScriptSig||!!d.finalScriptWitness}function T(d){return f=>!(!f.masterFingerprint.equals(d.fingerprint)||!d.derivePath(f.path).publicKey.equals(f.pubkey))}function R(d){if(typeof d!="number"||d!==Math.floor(d)||d>4294967295||d<0)throw new Error("Invalid 32 bit integer")}function B(d,f,b){const A=f.__FEE_RATE||d.getFeeRate(),H=f.__EXTRACTED_TX.virtualSize(),$=A*H;if(A>=b.maximumFeeRate)throw new Error(`Warning: You are paying around ${($/1e8).toFixed(8)} in fees, which is ${A} satoshi per byte for a transaction with a VSize of ${H} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function P(d,f){d.forEach(b=>{if((0,l.isTaprootInput)(b)?(0,l.checkTaprootInputForSigs)(b,f):(0,h.checkInputForSig)(b,f))throw new Error("Can not modify transaction, signatures exist.")})}function q(d){if(!d.sighashType||!d.partialSig)return;const{partialSig:f,sighashType:b}=d;f.forEach(A=>{const{hashType:H}=a.signature.decode(A.signature);if(b!==H)throw new Error("Signature sighash does not match input sighash type")})}function v(d,f,b){if(!(0,h.pubkeyInScript)(d,f))throw new Error(`Can not ${b} for this input with the key ${d.toString("hex")}`)}function C(d){if(!d.ins.every(b=>b.script&&b.script.length===0&&b.witness&&b.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function L(d,f){d.ins.forEach(b=>{K(f,b)})}function K(d,f){const b=(0,i.reverseBuffer)(Buffer.from(f.hash)).toString("hex")+":"+f.index;if(d.__TX_IN_CACHE[b])throw new Error("Duplicate input detected.");d.__TX_IN_CACHE[b]=1}function U(d,f){return(b,A,H,$)=>{const W=d({redeem:{output:H}}).output;if(!A.equals(W))throw new Error(`${f} for ${$} #${b} doesn't match the scriptPubKey in the prevout`)}}const D=U(o.p2sh,"Redeem script"),k=U(o.p2wsh,"Witness script");function j(d,f,b,A){if(!b.every(w))throw new Error(`PSBT must be finalized to calculate ${f}`);if(d==="__FEE_RATE"&&A.__FEE_RATE)return A.__FEE_RATE;if(d==="__FEE"&&A.__FEE)return A.__FEE;let H,$=!0;if(A.__EXTRACTED_TX?(H=A.__EXTRACTED_TX,$=!1):H=A.__TX.clone(),J(b,H,A,$),d==="__FEE_RATE")return A.__FEE_RATE;if(d==="__FEE")return A.__FEE}function F(d,f,b,A,H,$){const W=re(b);if(!E(f,b,W))throw new Error(`Can not finalize input #${d}`);return S(b,W,f.partialSig,A,H,$)}function S(d,f,b,A,H,$){let W,ie;const Q=ce(d,f,b),fe=$?o.p2wsh({redeem:Q}):null,le=H?o.p2sh({redeem:fe||Q}):null;return A?(fe?ie=(0,h.witnessStackToScriptWitness)(fe.witness):ie=(0,h.witnessStackToScriptWitness)(Q.witness),le&&(W=le.input)):le?W=le.input:W=Q.input,{finalScriptSig:W,finalScriptWitness:ie}}function I(d,f,b,A,H){const $=(0,n.checkForInput)(d,f),{hash:W,sighashType:ie,script:Q}=M(f,$,A,!1,H);return v(b,Q,"sign"),{hash:W,sighashType:ie}}function M(d,f,b,A,H){const $=b.__TX,W=f.sighashType||u.Transaction.SIGHASH_ALL;Y(W,H);let ie,Q;if(f.nonWitnessUtxo){const Ae=de(b,f,d),Ne=$.ins[d].hash,Ye=Ae.getHash();if(!Ne.equals(Ye))throw new Error(`Non-witness UTXO hash for input #${d} doesn't match the hash specified in the prevout`);const Ve=$.ins[d].index;Q=Ae.outs[Ve]}else if(f.witnessUtxo)Q=f.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:fe,type:le}=oe(Q.script,d,"input",f.redeemScript,f.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(le)>=0)ie=$.hashForWitnessV0(d,fe,Q.value,W);else if((0,h.isP2WPKH)(fe)){const Ae=o.p2pkh({hash:fe.slice(2)}).output;ie=$.hashForWitnessV0(d,Ae,Q.value,W)}else{if(f.nonWitnessUtxo===void 0&&b.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${d} has witnessUtxo but non-segwit script: ${fe.toString("hex")}`);!A&&b.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
10
+ *********************
11
+ PROCEED WITH CAUTION!
12
+ *********************`),ie=$.hashForSignature(d,fe,W)}return{script:fe,sighashType:W,hash:ie}}function O(d,f,b,A){const H=[];if(f.tapInternalKey){const W=V(d,f,A);W&&H.push(W)}if(f.tapScriptSig){const W=f.tapScriptSig.map(ie=>ie.pubkey);H.push(...W)}return H.map(W=>X(d,f,b,W,A)).flat()}function V(d,f,b){const{script:A}=Me(d,f,b);return(0,h.isP2TR)(A)?A.subarray(2,34):null}function G(d){return d.length===64?d:d.subarray(0,64)}function X(d,f,b,A,H,$,W){const ie=H.__TX,Q=f.sighashType||u.Transaction.SIGHASH_DEFAULT;Y(Q,W);const fe=b.map((Ve,Bn)=>Me(Bn,Ve,H)),le=fe.map(Ve=>Ve.script),Ae=fe.map(Ve=>Ve.value),Ne=[];if(f.tapInternalKey&&!$){const Ve=V(d,f,H)||Buffer.from([]);if((0,l.toXOnly)(A).equals(Ve)){const Bn=ie.hashForWitnessV1(d,le,Ae,Q);Ne.push({pubkey:A,hash:Bn})}}const Ye=(f.tapLeafScript||[]).filter(Ve=>(0,h.pubkeyInScript)(A,Ve.script)).map(Ve=>{const Bn=(0,c.tapleafHash)({output:Ve.script,version:Ve.leafVersion});return Object.assign({hash:Bn},Ve)}).filter(Ve=>!$||$.equals(Ve.hash)).map(Ve=>{const Bn=ie.hashForWitnessV1(d,le,Ae,Q,Ve.hash);return{pubkey:A,hash:Bn,leafHash:Ve.hash}});return Ne.concat(Ye)}function Y(d,f){if(f&&f.indexOf(d)<0){const b=ge(d);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${b}`)}}function ce(d,f,b){let A;switch(f){case"multisig":const H=Z(d,b);A=o.p2ms({output:d,signatures:H});break;case"pubkey":A=o.p2pk({output:d,signature:b[0].signature});break;case"pubkeyhash":A=o.p2pkh({output:d,pubkey:b[0].pubkey,signature:b[0].signature});break;case"witnesspubkeyhash":A=o.p2wpkh({output:d,pubkey:b[0].pubkey,signature:b[0].signature});break}return A}function ue(d,f,b){const A=b.__TX,H={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(H.isP2SH=!!f.redeemScript,H.isP2WSH=!!f.witnessScript,f.witnessScript)H.script=f.witnessScript;else if(f.redeemScript)H.script=f.redeemScript;else if(f.nonWitnessUtxo){const $=de(b,f,d),W=A.ins[d].index;H.script=$.outs[W].script}else f.witnessUtxo&&(H.script=f.witnessUtxo.script);return(f.witnessScript||(0,h.isP2WPKH)(H.script))&&(H.isSegwit=!0),H}function te(d,f,b){const A=(0,n.checkForInput)(f,d);if(!A.bip32Derivation||A.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const H=A.bip32Derivation.map(W=>{if(W.masterFingerprint.equals(b.fingerprint))return W}).filter(W=>!!W);if(H.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return H.map(W=>{const ie=b.derivePath(W.path);if(!W.pubkey.equals(ie.publicKey))throw new Error("pubkey did not match bip32Derivation");return ie})}function Z(d,f){return o.p2ms({output:d}).pubkeys.map(A=>(f.filter(H=>H.pubkey.equals(A))[0]||{}).signature).filter(A=>!!A)}function ae(d){let f=0;function b(W){return f+=W,d.slice(f-W,f)}function A(){const W=t.decode(d,f);return f+=t.decode.bytes,W}function H(){return b(A())}function $(){const W=A(),ie=[];for(let Q=0;Q<W;Q++)ie.push(H());return ie}return $()}function ge(d){let f=d&u.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(d&31){case u.Transaction.SIGHASH_ALL:f+="SIGHASH_ALL";break;case u.Transaction.SIGHASH_SINGLE:f+="SIGHASH_SINGLE";break;case u.Transaction.SIGHASH_NONE:f+="SIGHASH_NONE";break}return f}function pe(d,f,b){d.__NON_WITNESS_UTXO_BUF_CACHE[b]=f.nonWitnessUtxo;const A=u.Transaction.fromBuffer(f.nonWitnessUtxo);d.__NON_WITNESS_UTXO_TX_CACHE[b]=A;const H=d,$=b;delete f.nonWitnessUtxo,Object.defineProperty(f,"nonWitnessUtxo",{enumerable:!0,get(){const W=H.__NON_WITNESS_UTXO_BUF_CACHE[$],ie=H.__NON_WITNESS_UTXO_TX_CACHE[$];if(W!==void 0)return W;{const Q=ie.toBuffer();return H.__NON_WITNESS_UTXO_BUF_CACHE[$]=Q,Q}},set(W){H.__NON_WITNESS_UTXO_BUF_CACHE[$]=W}})}function J(d,f,b,A){let H=0;d.forEach((Q,fe)=>{if(A&&Q.finalScriptSig&&(f.ins[fe].script=Q.finalScriptSig),A&&Q.finalScriptWitness&&(f.ins[fe].witness=ae(Q.finalScriptWitness)),Q.witnessUtxo)H+=Q.witnessUtxo.value;else if(Q.nonWitnessUtxo){const le=de(b,Q,fe),Ae=f.ins[fe].index,Ne=le.outs[Ae];H+=Ne.value}});const $=f.outs.reduce((Q,fe)=>Q+fe.value,0),W=H-$;if(W<0)throw new Error("Outputs are spending more than Inputs");const ie=f.virtualSize();b.__FEE=W,b.__EXTRACTED_TX=f,b.__FEE_RATE=Math.floor(W/ie)}function de(d,f,b){const A=d.__NON_WITNESS_UTXO_TX_CACHE;return A[b]||pe(d,f,b),A[b]}function xe(d,f,b){const{script:A}=Me(d,f,b);return A}function Me(d,f,b){if(f.witnessUtxo!==void 0)return{script:f.witnessUtxo.script,value:f.witnessUtxo.value};if(f.nonWitnessUtxo!==void 0){const H=de(b,f,d).outs[b.__TX.ins[d].index];return{script:H.script,value:H.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function tt(d,f,b,A){const H=xe(b,f,A),{meaningfulScript:$}=oe(H,b,"input",f.redeemScript,f.witnessScript);return(0,h.pubkeyInScript)(d,$)}function ut(d,f,b,A){const H=A.__TX.outs[b].script,{meaningfulScript:$}=oe(H,b,"output",f.redeemScript,f.witnessScript);return(0,h.pubkeyInScript)(d,$)}function gt(d){if(!d)return;const f=a.decompile(d);if(!f)return;const b=f[f.length-1];if(!(!Buffer.isBuffer(b)||Qe(b)||ke(b)||!a.decompile(b)))return b}function ve(d){if(!d)return;const f=ae(d),b=f[f.length-1];if(!(Qe(b)||!a.decompile(b)))return b}function zt(d){if(d.length===65){const f=d[64]&1,b=d.slice(0,33);return b[0]=2|f,b}return d.slice()}function Qe(d){return d.length===33&&a.isCanonicalPubKey(d)}function ke(d){return a.isCanonicalScriptSignature(d)}function oe(d,f,b,A,H){const $=(0,h.isP2SHScript)(d),W=$&&A&&(0,h.isP2WSHScript)(A),ie=(0,h.isP2WSHScript)(d);if($&&A===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((ie||W)&&H===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let Q;return W?(Q=H,D(f,d,A,b),k(f,A,H,b),ne(Q)):ie?(Q=H,k(f,d,H,b),ne(Q)):$?(Q=A,D(f,d,A,b)):Q=d,{meaningfulScript:Q,type:W?"p2sh-p2wsh":$?"p2sh":ie?"p2wsh":"raw"}}function ne(d){if((0,h.isP2WPKH)(d)||(0,h.isP2SHScript)(d))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function re(d){return(0,h.isP2WPKH)(d)?"witnesspubkeyhash":(0,h.isP2PKH)(d)?"pubkeyhash":(0,h.isP2MS)(d)?"multisig":(0,h.isP2PK)(d)?"pubkey":"nonstandard"}function N(d){return[...Array(d).keys()]}return us}var Xl;function zl(){return Xl||(Xl=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=sa();e.address=t;const n=Nn();e.crypto=n;const r=cn();e.networks=r;const i=is();e.payments=i;const s=kt();e.script=s;var o=qy();Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return o.Block}});var c=um();Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return c.Psbt}});var a=Lc();Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return a.OPS}});var u=as();Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}});var l=ta();Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return l.initEccLib}})})(Fc)),Fc}var wn=zl(),Ze={},da={},ls={},ha={},pa={},Yl;function fm(){return Yl||(Yl=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=Xn();class n extends t.Hash{constructor(s,o){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(s);const c=(0,t.toBytes)(o);if(this.iHash=s.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const a=this.blockLen,u=new Uint8Array(a);u.set(c.length>a?s.create().update(c).digest():c);for(let l=0;l<u.length;l++)u[l]^=54;this.iHash.update(u),this.oHash=s.create();for(let l=0;l<u.length;l++)u[l]^=106;this.oHash.update(u),(0,t.clean)(u)}update(s){return(0,t.aexists)(this),this.iHash.update(s),this}digestInto(s){(0,t.aexists)(this),(0,t.abytes)(s,this.outputLen),this.finished=!0,this.iHash.digestInto(s),this.oHash.update(s),this.oHash.digestInto(s),this.destroy()}digest(){const s=new Uint8Array(this.oHash.outputLen);return this.digestInto(s),s}_cloneInto(s){s||(s=Object.create(Object.getPrototypeOf(this),{}));const{oHash:o,iHash:c,finished:a,destroyed:u,blockLen:l,outputLen:h}=this;return s=s,s.finished=a,s.destroyed=u,s.blockLen=l,s.outputLen=h,s.oHash=o._cloneInto(s.oHash),s.iHash=c._cloneInto(s.iHash),s}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=n;const r=(i,s,o)=>new n(i,s).update(o).digest();e.hmac=r,e.hmac.create=(i,s)=>new n(i,s)})(pa)),pa}var ya={},Zl;function fi(){return Zl||(Zl=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=s,e._abool2=o,e._abytes2=c,e.numberToHexUnpadded=a,e.hexToNumber=u,e.bytesToNumberBE=l,e.bytesToNumberLE=h,e.numberToBytesBE=y,e.numberToBytesLE=p,e.numberToVarBytesBE=m,e.ensureBytes=g,e.equalBytes=E,e.copyBytes=x,e.asciiToBytes=_,e.inRange=T,e.aInRange=R,e.bitLen=B,e.bitGet=P,e.bitSet=q,e.createHmacDrbg=C,e.validateObject=K,e.isHash=U,e._validateObject=D,e.memoized=j;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Xn();var n=Xn();Object.defineProperty(e,"abytes",{enumerable:!0,get:function(){return n.abytes}}),Object.defineProperty(e,"anumber",{enumerable:!0,get:function(){return n.anumber}}),Object.defineProperty(e,"bytesToHex",{enumerable:!0,get:function(){return n.bytesToHex}}),Object.defineProperty(e,"bytesToUtf8",{enumerable:!0,get:function(){return n.bytesToUtf8}}),Object.defineProperty(e,"concatBytes",{enumerable:!0,get:function(){return n.concatBytes}}),Object.defineProperty(e,"hexToBytes",{enumerable:!0,get:function(){return n.hexToBytes}}),Object.defineProperty(e,"isBytes",{enumerable:!0,get:function(){return n.isBytes}}),Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return n.randomBytes}}),Object.defineProperty(e,"utf8ToBytes",{enumerable:!0,get:function(){return n.utf8ToBytes}});const r=BigInt(0),i=BigInt(1);function s(F,S){if(typeof S!="boolean")throw new Error(F+" boolean expected, got "+S)}function o(F,S=""){if(typeof F!="boolean"){const I=S&&`"${S}"`;throw new Error(I+"expected boolean, got type="+typeof F)}return F}function c(F,S,I=""){const M=(0,t.isBytes)(F),O=F?.length,V=S!==void 0;if(!M||V&&O!==S){const G=I&&`"${I}" `,X=V?` of length ${S}`:"",Y=M?`length=${O}`:`type=${typeof F}`;throw new Error(G+"expected Uint8Array"+X+", got "+Y)}return F}function a(F){const S=F.toString(16);return S.length&1?"0"+S:S}function u(F){if(typeof F!="string")throw new Error("hex string expected, got "+typeof F);return F===""?r:BigInt("0x"+F)}function l(F){return u((0,t.bytesToHex)(F))}function h(F){return(0,t.abytes)(F),u((0,t.bytesToHex)(Uint8Array.from(F).reverse()))}function y(F,S){return(0,t.hexToBytes)(F.toString(16).padStart(S*2,"0"))}function p(F,S){return y(F,S).reverse()}function m(F){return(0,t.hexToBytes)(a(F))}function g(F,S,I){let M;if(typeof S=="string")try{M=(0,t.hexToBytes)(S)}catch(V){throw new Error(F+" must be hex string or Uint8Array, cause: "+V)}else if((0,t.isBytes)(S))M=Uint8Array.from(S);else throw new Error(F+" must be hex string or Uint8Array");const O=M.length;if(typeof I=="number"&&O!==I)throw new Error(F+" of length "+I+" expected, got "+O);return M}function E(F,S){if(F.length!==S.length)return!1;let I=0;for(let M=0;M<F.length;M++)I|=F[M]^S[M];return I===0}function x(F){return Uint8Array.from(F)}function _(F){return Uint8Array.from(F,(S,I)=>{const M=S.charCodeAt(0);if(S.length!==1||M>127)throw new Error(`string contains non-ASCII character "${F[I]}" with code ${M} at position ${I}`);return M})}const w=F=>typeof F=="bigint"&&r<=F;function T(F,S,I){return w(F)&&w(S)&&w(I)&&S<=F&&F<I}function R(F,S,I,M){if(!T(S,I,M))throw new Error("expected valid "+F+": "+I+" <= n < "+M+", got "+S)}function B(F){let S;for(S=0;F>r;F>>=i,S+=1);return S}function P(F,S){return F>>BigInt(S)&i}function q(F,S,I){return F|(I?i:r)<<BigInt(S)}const v=F=>(i<<BigInt(F))-i;e.bitMask=v;function C(F,S,I){if(typeof F!="number"||F<2)throw new Error("hashLen must be a number");if(typeof S!="number"||S<2)throw new Error("qByteLen must be a number");if(typeof I!="function")throw new Error("hmacFn must be a function");const M=ae=>new Uint8Array(ae),O=ae=>Uint8Array.of(ae);let V=M(F),G=M(F),X=0;const Y=()=>{V.fill(1),G.fill(0),X=0},ce=(...ae)=>I(G,V,...ae),ue=(ae=M(0))=>{G=ce(O(0),ae),V=ce(),ae.length!==0&&(G=ce(O(1),ae),V=ce())},te=()=>{if(X++>=1e3)throw new Error("drbg: tried 1000 values");let ae=0;const ge=[];for(;ae<S;){V=ce();const pe=V.slice();ge.push(pe),ae+=V.length}return(0,t.concatBytes)(...ge)};return(ae,ge)=>{Y(),ue(ae);let pe;for(;!(pe=ge(te()));)ue();return Y(),pe}}const L={bigint:F=>typeof F=="bigint",function:F=>typeof F=="function",boolean:F=>typeof F=="boolean",string:F=>typeof F=="string",stringOrUint8Array:F=>typeof F=="string"||(0,t.isBytes)(F),isSafeInteger:F=>Number.isSafeInteger(F),array:F=>Array.isArray(F),field:(F,S)=>S.Fp.isValid(F),hash:F=>typeof F=="function"&&Number.isSafeInteger(F.outputLen)};function K(F,S,I={}){const M=(O,V,G)=>{const X=L[V];if(typeof X!="function")throw new Error("invalid validator function");const Y=F[O];if(!(G&&Y===void 0)&&!X(Y,F))throw new Error("param "+String(O)+" is invalid. Expected "+V+", got "+Y)};for(const[O,V]of Object.entries(S))M(O,V,!1);for(const[O,V]of Object.entries(I))M(O,V,!0);return F}function U(F){return typeof F=="function"&&Number.isSafeInteger(F.outputLen)}function D(F,S,I={}){if(!F||typeof F!="object")throw new Error("expected valid options object");function M(O,V,G){const X=F[O];if(G&&X===void 0)return;const Y=typeof X;if(Y!==V||X===null)throw new Error(`param "${O}" is invalid: expected ${V}, got ${Y}`)}Object.entries(S).forEach(([O,V])=>M(O,V,!1)),Object.entries(I).forEach(([O,V])=>M(O,V,!0))}const k=()=>{throw new Error("not implemented")};e.notImplemented=k;function j(F){const S=new WeakMap;return(I,...M)=>{const O=S.get(I);if(O!==void 0)return O;const V=F(I,...M);return S.set(I,V),V}}})(ya)),ya}var Yt={},We={},Jl;function ds(){if(Jl)return We;Jl=1,Object.defineProperty(We,"__esModule",{value:!0}),We.isNegativeLE=void 0,We.mod=h,We.pow=y,We.pow2=p,We.invert=m,We.tonelliShanks=w,We.FpSqrt=T,We.validateField=P,We.FpPow=q,We.FpInvertBatch=v,We.FpDiv=C,We.FpLegendre=L,We.FpIsSquare=K,We.nLength=U,We.Field=D,We.FpSqrtOdd=k,We.FpSqrtEven=j,We.hashToPrivateScalar=F,We.getFieldBytesLength=S,We.getMinHashLength=I,We.mapHashToField=M;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=fi(),t=BigInt(0),n=BigInt(1),r=BigInt(2),i=BigInt(3),s=BigInt(4),o=BigInt(5),c=BigInt(7),a=BigInt(8),u=BigInt(9),l=BigInt(16);function h(O,V){const G=O%V;return G>=t?G:V+G}function y(O,V,G){return q(D(G),O,V)}function p(O,V,G){let X=O;for(;V-- >t;)X*=X,X%=G;return X}function m(O,V){if(O===t)throw new Error("invert: expected non-zero number");if(V<=t)throw new Error("invert: expected positive modulus, got "+V);let G=h(O,V),X=V,Y=t,ce=n;for(;G!==t;){const te=X/G,Z=X%G,ae=Y-ce*te;X=G,G=Z,Y=ce,ce=ae}if(X!==n)throw new Error("invert: does not exist");return h(Y,V)}function g(O,V,G){if(!O.eql(O.sqr(V),G))throw new Error("Cannot find square root")}function E(O,V){const G=(O.ORDER+n)/s,X=O.pow(V,G);return g(O,X,V),X}function x(O,V){const G=(O.ORDER-o)/a,X=O.mul(V,r),Y=O.pow(X,G),ce=O.mul(V,Y),ue=O.mul(O.mul(ce,r),Y),te=O.mul(ce,O.sub(ue,O.ONE));return g(O,te,V),te}function _(O){const V=D(O),G=w(O),X=G(V,V.neg(V.ONE)),Y=G(V,X),ce=G(V,V.neg(X)),ue=(O+c)/l;return(te,Z)=>{let ae=te.pow(Z,ue),ge=te.mul(ae,X);const pe=te.mul(ae,Y),J=te.mul(ae,ce),de=te.eql(te.sqr(ge),Z),xe=te.eql(te.sqr(pe),Z);ae=te.cmov(ae,ge,de),ge=te.cmov(J,pe,xe);const Me=te.eql(te.sqr(ge),Z),tt=te.cmov(ae,ge,Me);return g(te,tt,Z),tt}}function w(O){if(O<i)throw new Error("sqrt is not defined for small field");let V=O-n,G=0;for(;V%r===t;)V/=r,G++;let X=r;const Y=D(O);for(;L(Y,X)===1;)if(X++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(G===1)return E;let ce=Y.pow(X,V);const ue=(V+n)/r;return function(Z,ae){if(Z.is0(ae))return ae;if(L(Z,ae)!==1)throw new Error("Cannot find square root");let ge=G,pe=Z.mul(Z.ONE,ce),J=Z.pow(ae,V),de=Z.pow(ae,ue);for(;!Z.eql(J,Z.ONE);){if(Z.is0(J))return Z.ZERO;let xe=1,Me=Z.sqr(J);for(;!Z.eql(Me,Z.ONE);)if(xe++,Me=Z.sqr(Me),xe===ge)throw new Error("Cannot find square root");const tt=n<<BigInt(ge-xe-1),ut=Z.pow(pe,tt);ge=xe,pe=Z.sqr(ut),J=Z.mul(J,pe),de=Z.mul(de,ut)}return de}}function T(O){return O%s===i?E:O%a===o?x:O%l===u?_(O):w(O)}const R=(O,V)=>(h(O,V)&n)===n;We.isNegativeLE=R;const B=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function P(O){const V={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=B.reduce((X,Y)=>(X[Y]="function",X),V);return(0,e._validateObject)(O,G),O}function q(O,V,G){if(G<t)throw new Error("invalid exponent, negatives unsupported");if(G===t)return O.ONE;if(G===n)return V;let X=O.ONE,Y=V;for(;G>t;)G&n&&(X=O.mul(X,Y)),Y=O.sqr(Y),G>>=n;return X}function v(O,V,G=!1){const X=new Array(V.length).fill(G?O.ZERO:void 0),Y=V.reduce((ue,te,Z)=>O.is0(te)?ue:(X[Z]=ue,O.mul(ue,te)),O.ONE),ce=O.inv(Y);return V.reduceRight((ue,te,Z)=>O.is0(te)?ue:(X[Z]=O.mul(ue,X[Z]),O.mul(ue,te)),ce),X}function C(O,V,G){return O.mul(V,typeof G=="bigint"?m(G,O.ORDER):O.inv(G))}function L(O,V){const G=(O.ORDER-n)/r,X=O.pow(V,G),Y=O.eql(X,O.ONE),ce=O.eql(X,O.ZERO),ue=O.eql(X,O.neg(O.ONE));if(!Y&&!ce&&!ue)throw new Error("invalid Legendre symbol result");return Y?1:ce?0:-1}function K(O,V){return L(O,V)===1}function U(O,V){V!==void 0&&(0,e.anumber)(V);const G=V!==void 0?V:O.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function D(O,V,G=!1,X={}){if(O<=t)throw new Error("invalid field: expected ORDER > 0, got "+O);let Y,ce,ue=!1,te;if(typeof V=="object"&&V!=null){if(X.sqrt||G)throw new Error("cannot specify opts in two arguments");const J=V;J.BITS&&(Y=J.BITS),J.sqrt&&(ce=J.sqrt),typeof J.isLE=="boolean"&&(G=J.isLE),typeof J.modFromBytes=="boolean"&&(ue=J.modFromBytes),te=J.allowedLengths}else typeof V=="number"&&(Y=V),X.sqrt&&(ce=X.sqrt);const{nBitLength:Z,nByteLength:ae}=U(O,Y);if(ae>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let ge;const pe=Object.freeze({ORDER:O,isLE:G,BITS:Z,BYTES:ae,MASK:(0,e.bitMask)(Z),ZERO:t,ONE:n,allowedLengths:te,create:J=>h(J,O),isValid:J=>{if(typeof J!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof J);return t<=J&&J<O},is0:J=>J===t,isValidNot0:J=>!pe.is0(J)&&pe.isValid(J),isOdd:J=>(J&n)===n,neg:J=>h(-J,O),eql:(J,de)=>J===de,sqr:J=>h(J*J,O),add:(J,de)=>h(J+de,O),sub:(J,de)=>h(J-de,O),mul:(J,de)=>h(J*de,O),pow:(J,de)=>q(pe,J,de),div:(J,de)=>h(J*m(de,O),O),sqrN:J=>J*J,addN:(J,de)=>J+de,subN:(J,de)=>J-de,mulN:(J,de)=>J*de,inv:J=>m(J,O),sqrt:ce||(J=>(ge||(ge=T(O)),ge(pe,J))),toBytes:J=>G?(0,e.numberToBytesLE)(J,ae):(0,e.numberToBytesBE)(J,ae),fromBytes:(J,de=!0)=>{if(te){if(!te.includes(J.length)||J.length>ae)throw new Error("Field.fromBytes: expected "+te+" bytes, got "+J.length);const Me=new Uint8Array(ae);Me.set(J,G?0:Me.length-J.length),J=Me}if(J.length!==ae)throw new Error("Field.fromBytes: expected "+ae+" bytes, got "+J.length);let xe=G?(0,e.bytesToNumberLE)(J):(0,e.bytesToNumberBE)(J);if(ue&&(xe=h(xe,O)),!de&&!pe.isValid(xe))throw new Error("invalid field element: outside of range 0..ORDER");return xe},invertBatch:J=>v(pe,J),cmov:(J,de,xe)=>xe?de:J});return Object.freeze(pe)}function k(O,V){if(!O.isOdd)throw new Error("Field doesn't have isOdd");const G=O.sqrt(V);return O.isOdd(G)?G:O.neg(G)}function j(O,V){if(!O.isOdd)throw new Error("Field doesn't have isOdd");const G=O.sqrt(V);return O.isOdd(G)?O.neg(G):G}function F(O,V,G=!1){O=(0,e.ensureBytes)("privateHash",O);const X=O.length,Y=U(V).nByteLength+8;if(Y<24||X<Y||X>1024)throw new Error("hashToPrivateScalar: expected "+Y+"-1024 bytes of input, got "+X);const ce=G?(0,e.bytesToNumberLE)(O):(0,e.bytesToNumberBE)(O);return h(ce,V-n)+n}function S(O){if(typeof O!="bigint")throw new Error("field order must be bigint");const V=O.toString(2).length;return Math.ceil(V/8)}function I(O){const V=S(O);return V+Math.ceil(V/2)}function M(O,V,G=!1){const X=O.length,Y=S(V),ce=I(V);if(X<16||X<ce||X>1024)throw new Error("expected "+ce+"-1024 bytes of input, got "+X);const ue=G?(0,e.bytesToNumberLE)(O):(0,e.bytesToNumberBE)(O),te=h(ue,V-n)+n;return G?(0,e.numberToBytesLE)(te,Y):(0,e.numberToBytesBE)(te,Y)}return We}var Ql;function lm(){if(Ql)return Yt;Ql=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.wNAF=void 0,Yt.negateCt=i,Yt.normalizeZ=s,Yt.mulEndoUnsafe=E,Yt.pippenger=x,Yt.precomputeMSMUnsafe=_,Yt.validateBasic=w,Yt._createCurveFields=R;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=fi(),t=ds(),n=BigInt(0),r=BigInt(1);function i(B,P){const q=P.negate();return B?q:P}function s(B,P){const q=(0,t.FpInvertBatch)(B.Fp,P.map(v=>v.Z));return P.map((v,C)=>B.fromAffine(v.toAffine(q[C])))}function o(B,P){if(!Number.isSafeInteger(B)||B<=0||B>P)throw new Error("invalid window size, expected [1.."+P+"], got W="+B)}function c(B,P){o(B,P);const q=Math.ceil(P/B)+1,v=2**(B-1),C=2**B,L=(0,e.bitMask)(B),K=BigInt(B);return{windows:q,windowSize:v,mask:L,maxNumber:C,shiftBy:K}}function a(B,P,q){const{windowSize:v,mask:C,maxNumber:L,shiftBy:K}=q;let U=Number(B&C),D=B>>K;U>v&&(U-=L,D+=r);const k=P*v,j=k+Math.abs(U)-1,F=U===0,S=U<0,I=P%2!==0;return{nextN:D,offset:j,isZero:F,isNeg:S,isNegF:I,offsetF:k}}function u(B,P){if(!Array.isArray(B))throw new Error("array expected");B.forEach((q,v)=>{if(!(q instanceof P))throw new Error("invalid point at index "+v)})}function l(B,P){if(!Array.isArray(B))throw new Error("array of scalars expected");B.forEach((q,v)=>{if(!P.isValid(q))throw new Error("invalid scalar at index "+v)})}const h=new WeakMap,y=new WeakMap;function p(B){return y.get(B)||1}function m(B){if(B!==n)throw new Error("invalid wNAF")}class g{constructor(P,q){this.BASE=P.BASE,this.ZERO=P.ZERO,this.Fn=P.Fn,this.bits=q}_unsafeLadder(P,q,v=this.ZERO){let C=P;for(;q>n;)q&r&&(v=v.add(C)),C=C.double(),q>>=r;return v}precomputeWindow(P,q){const{windows:v,windowSize:C}=c(q,this.bits),L=[];let K=P,U=K;for(let D=0;D<v;D++){U=K,L.push(U);for(let k=1;k<C;k++)U=U.add(K),L.push(U);K=U.double()}return L}wNAF(P,q,v){if(!this.Fn.isValid(v))throw new Error("invalid scalar");let C=this.ZERO,L=this.BASE;const K=c(P,this.bits);for(let U=0;U<K.windows;U++){const{nextN:D,offset:k,isZero:j,isNeg:F,isNegF:S,offsetF:I}=a(v,U,K);v=D,j?L=L.add(i(S,q[I])):C=C.add(i(F,q[k]))}return m(v),{p:C,f:L}}wNAFUnsafe(P,q,v,C=this.ZERO){const L=c(P,this.bits);for(let K=0;K<L.windows&&v!==n;K++){const{nextN:U,offset:D,isZero:k,isNeg:j}=a(v,K,L);if(v=U,!k){const F=q[D];C=C.add(j?F.negate():F)}}return m(v),C}getPrecomputes(P,q,v){let C=h.get(q);return C||(C=this.precomputeWindow(q,P),P!==1&&(typeof v=="function"&&(C=v(C)),h.set(q,C))),C}cached(P,q,v){const C=p(P);return this.wNAF(C,this.getPrecomputes(C,P,v),q)}unsafe(P,q,v,C){const L=p(P);return L===1?this._unsafeLadder(P,q,C):this.wNAFUnsafe(L,this.getPrecomputes(L,P,v),q,C)}createCache(P,q){o(q,this.bits),y.set(P,q),h.delete(P)}hasCache(P){return p(P)!==1}}Yt.wNAF=g;function E(B,P,q,v){let C=P,L=B.ZERO,K=B.ZERO;for(;q>n||v>n;)q&r&&(L=L.add(C)),v&r&&(K=K.add(C)),C=C.double(),q>>=r,v>>=r;return{p1:L,p2:K}}function x(B,P,q,v){u(q,B),l(v,P);const C=q.length,L=v.length;if(C!==L)throw new Error("arrays of points and scalars must have equal length");const K=B.ZERO,U=(0,e.bitLen)(BigInt(C));let D=1;U>12?D=U-3:U>4?D=U-2:U>0&&(D=2);const k=(0,e.bitMask)(D),j=new Array(Number(k)+1).fill(K),F=Math.floor((P.BITS-1)/D)*D;let S=K;for(let I=F;I>=0;I-=D){j.fill(K);for(let O=0;O<L;O++){const V=v[O],G=Number(V>>BigInt(I)&k);j[G]=j[G].add(q[O])}let M=K;for(let O=j.length-1,V=K;O>0;O--)V=V.add(j[O]),M=M.add(V);if(S=S.add(M),I!==0)for(let O=0;O<D;O++)S=S.double()}return S}function _(B,P,q,v){o(v,P.BITS),u(q,B);const C=B.ZERO,L=2**v-1,K=Math.ceil(P.BITS/v),U=(0,e.bitMask)(v),D=q.map(k=>{const j=[];for(let F=0,S=k;F<L;F++)j.push(S),S=S.add(k);return j});return k=>{if(l(k,P),k.length>q.length)throw new Error("array of scalars must be smaller than array of points");let j=C;for(let F=0;F<K;F++){if(j!==C)for(let I=0;I<v;I++)j=j.double();const S=BigInt(K*v-(F+1)*v);for(let I=0;I<k.length;I++){const M=k[I],O=Number(M>>S&U);O&&(j=j.add(D[I][O-1]))}}return j}}function w(B){return(0,t.validateField)(B.Fp),(0,e.validateObject)(B,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(B.n,B.nBitLength),...B,p:B.Fp.ORDER})}function T(B,P,q){if(P){if(P.ORDER!==B)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(P),P}else return(0,t.Field)(B,{isLE:q})}function R(B,P,q={},v){if(v===void 0&&(v=B==="edwards"),!P||typeof P!="object")throw new Error(`expected valid ${B} CURVE object`);for(const D of["p","n","h"]){const k=P[D];if(!(typeof k=="bigint"&&k>n))throw new Error(`CURVE.${D} must be positive bigint`)}const C=T(P.p,q.Fp,v),L=T(P.n,q.Fn,v),U=["Gx","Gy","a",B==="weierstrass"?"b":"d"];for(const D of U)if(!C.isValid(P[D]))throw new Error(`CURVE.${D} must be valid field element of CURVE.Fp`);return P=Object.freeze(Object.assign({},P)),{CURVE:P,Fp:C,Fn:L}}return Yt}var ed;function td(){return ed||(ed=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=c,e._normFnElement=E,e.weierstrassN=x,e.SWUFpSqrtRatio=w,e.mapToCurveSimpleSWU=T,e.ecdh=B,e.ecdsa=P,e.weierstrassPoints=q,e._legacyHelperEquat=L,e.weierstrass=D;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=fm(),n=Xn(),r=fi(),i=lm(),s=ds(),o=(k,j)=>(k+(k>=0?j:-j)/p)/j;function c(k,j,F){const[[S,I],[M,O]]=j,V=o(O*k,F),G=o(-I*k,F);let X=k-V*S-G*M,Y=-V*I-G*O;const ce=X<h,ue=Y<h;ce&&(X=-X),ue&&(Y=-Y);const te=(0,r.bitMask)(Math.ceil((0,r.bitLen)(F)/2))+y;if(X<h||X>=te||Y<h||Y>=te)throw new Error("splitScalar (endomorphism): failed, k="+k);return{k1neg:ce,k1:X,k2neg:ue,k2:Y}}function a(k){if(!["compact","recovered","der"].includes(k))throw new Error('Signature format must be "compact", "recovered", or "der"');return k}function u(k,j){const F={};for(let S of Object.keys(j))F[S]=k[S]===void 0?j[S]:k[S];return(0,r._abool2)(F.lowS,"lowS"),(0,r._abool2)(F.prehash,"prehash"),F.format!==void 0&&a(F.format),F}class l extends Error{constructor(j=""){super(j)}}e.DERErr=l,e.DER={Err:l,_tlv:{encode:(k,j)=>{const{Err:F}=e.DER;if(k<0||k>256)throw new F("tlv.encode: wrong tag");if(j.length&1)throw new F("tlv.encode: unpadded data");const S=j.length/2,I=(0,r.numberToHexUnpadded)(S);if(I.length/2&128)throw new F("tlv.encode: long form length too big");const M=S>127?(0,r.numberToHexUnpadded)(I.length/2|128):"";return(0,r.numberToHexUnpadded)(k)+M+I+j},decode(k,j){const{Err:F}=e.DER;let S=0;if(k<0||k>256)throw new F("tlv.encode: wrong tag");if(j.length<2||j[S++]!==k)throw new F("tlv.decode: wrong tlv");const I=j[S++],M=!!(I&128);let O=0;if(!M)O=I;else{const G=I&127;if(!G)throw new F("tlv.decode(long): indefinite length not supported");if(G>4)throw new F("tlv.decode(long): byte length is too big");const X=j.subarray(S,S+G);if(X.length!==G)throw new F("tlv.decode: length bytes not complete");if(X[0]===0)throw new F("tlv.decode(long): zero leftmost byte");for(const Y of X)O=O<<8|Y;if(S+=G,O<128)throw new F("tlv.decode(long): not minimal encoding")}const V=j.subarray(S,S+O);if(V.length!==O)throw new F("tlv.decode: wrong value length");return{v:V,l:j.subarray(S+O)}}},_int:{encode(k){const{Err:j}=e.DER;if(k<h)throw new j("integer: negative integers are not allowed");let F=(0,r.numberToHexUnpadded)(k);if(Number.parseInt(F[0],16)&8&&(F="00"+F),F.length&1)throw new j("unexpected DER parsing assertion: unpadded hex");return F},decode(k){const{Err:j}=e.DER;if(k[0]&128)throw new j("invalid signature integer: negative");if(k[0]===0&&!(k[1]&128))throw new j("invalid signature integer: unnecessary leading zero");return(0,r.bytesToNumberBE)(k)}},toSig(k){const{Err:j,_int:F,_tlv:S}=e.DER,I=(0,r.ensureBytes)("signature",k),{v:M,l:O}=S.decode(48,I);if(O.length)throw new j("invalid signature: left bytes after parsing");const{v:V,l:G}=S.decode(2,M),{v:X,l:Y}=S.decode(2,G);if(Y.length)throw new j("invalid signature: left bytes after parsing");return{r:F.decode(V),s:F.decode(X)}},hexFromSig(k){const{_tlv:j,_int:F}=e.DER,S=j.encode(2,F.encode(k.r)),I=j.encode(2,F.encode(k.s)),M=S+I;return j.encode(48,M)}};const h=BigInt(0),y=BigInt(1),p=BigInt(2),m=BigInt(3),g=BigInt(4);function E(k,j){const{BYTES:F}=k;let S;if(typeof j=="bigint")S=j;else{let I=(0,r.ensureBytes)("private key",j);try{S=k.fromBytes(I)}catch{throw new Error(`invalid private key: expected ui8a of size ${F}, got ${typeof j}`)}}if(!k.isValidNot0(S))throw new Error("invalid private key: out of range [1..N-1]");return S}function x(k,j={}){const F=(0,i._createCurveFields)("weierstrass",k,j),{Fp:S,Fn:I}=F;let M=F.CURVE;const{h:O,n:V}=M;(0,r._validateObject)(j,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:G}=j;if(G&&(!S.is0(M.a)||typeof G.beta!="bigint"||!Array.isArray(G.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const X=R(S,I);function Y(){if(!S.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function ce(ke,oe,ne){const{x:re,y:N}=oe.toAffine(),d=S.toBytes(re);if((0,r._abool2)(ne,"isCompressed"),ne){Y();const f=!S.isOdd(N);return(0,r.concatBytes)(_(f),d)}else return(0,r.concatBytes)(Uint8Array.of(4),d,S.toBytes(N))}function ue(ke){(0,r._abytes2)(ke,void 0,"Point");const{publicKey:oe,publicKeyUncompressed:ne}=X,re=ke.length,N=ke[0],d=ke.subarray(1);if(re===oe&&(N===2||N===3)){const f=S.fromBytes(d);if(!S.isValid(f))throw new Error("bad point: is not on curve, wrong x");const b=ae(f);let A;try{A=S.sqrt(b)}catch(W){const ie=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+ie)}Y();const H=S.isOdd(A);return(N&1)===1!==H&&(A=S.neg(A)),{x:f,y:A}}else if(re===ne&&N===4){const f=S.BYTES,b=S.fromBytes(d.subarray(0,f)),A=S.fromBytes(d.subarray(f,f*2));if(!ge(b,A))throw new Error("bad point: is not on curve");return{x:b,y:A}}else throw new Error(`bad point: got length ${re}, expected compressed=${oe} or uncompressed=${ne}`)}const te=j.toBytes||ce,Z=j.fromBytes||ue;function ae(ke){const oe=S.sqr(ke),ne=S.mul(oe,ke);return S.add(S.add(ne,S.mul(ke,M.a)),M.b)}function ge(ke,oe){const ne=S.sqr(oe),re=ae(ke);return S.eql(ne,re)}if(!ge(M.Gx,M.Gy))throw new Error("bad curve params: generator point");const pe=S.mul(S.pow(M.a,m),g),J=S.mul(S.sqr(M.b),BigInt(27));if(S.is0(S.add(pe,J)))throw new Error("bad curve params: a or b");function de(ke,oe,ne=!1){if(!S.isValid(oe)||ne&&S.is0(oe))throw new Error(`bad point coordinate ${ke}`);return oe}function xe(ke){if(!(ke instanceof ve))throw new Error("ProjectivePoint expected")}function Me(ke){if(!G||!G.basises)throw new Error("no endo");return c(ke,G.basises,I.ORDER)}const tt=(0,r.memoized)((ke,oe)=>{const{X:ne,Y:re,Z:N}=ke;if(S.eql(N,S.ONE))return{x:ne,y:re};const d=ke.is0();oe==null&&(oe=d?S.ONE:S.inv(N));const f=S.mul(ne,oe),b=S.mul(re,oe),A=S.mul(N,oe);if(d)return{x:S.ZERO,y:S.ZERO};if(!S.eql(A,S.ONE))throw new Error("invZ was invalid");return{x:f,y:b}}),ut=(0,r.memoized)(ke=>{if(ke.is0()){if(j.allowInfinityPoint&&!S.is0(ke.Y))return;throw new Error("bad point: ZERO")}const{x:oe,y:ne}=ke.toAffine();if(!S.isValid(oe)||!S.isValid(ne))throw new Error("bad point: x or y not field elements");if(!ge(oe,ne))throw new Error("bad point: equation left != right");if(!ke.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function gt(ke,oe,ne,re,N){return ne=new ve(S.mul(ne.X,ke),ne.Y,ne.Z),oe=(0,i.negateCt)(re,oe),ne=(0,i.negateCt)(N,ne),oe.add(ne)}class ve{constructor(oe,ne,re){this.X=de("x",oe),this.Y=de("y",ne,!0),this.Z=de("z",re),Object.freeze(this)}static CURVE(){return M}static fromAffine(oe){const{x:ne,y:re}=oe||{};if(!oe||!S.isValid(ne)||!S.isValid(re))throw new Error("invalid affine point");if(oe instanceof ve)throw new Error("projective point not allowed");return S.is0(ne)&&S.is0(re)?ve.ZERO:new ve(ne,re,S.ONE)}static fromBytes(oe){const ne=ve.fromAffine(Z((0,r._abytes2)(oe,void 0,"point")));return ne.assertValidity(),ne}static fromHex(oe){return ve.fromBytes((0,r.ensureBytes)("pointHex",oe))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(oe=8,ne=!0){return Qe.createCache(this,oe),ne||this.multiply(m),this}assertValidity(){ut(this)}hasEvenY(){const{y:oe}=this.toAffine();if(!S.isOdd)throw new Error("Field doesn't support isOdd");return!S.isOdd(oe)}equals(oe){xe(oe);const{X:ne,Y:re,Z:N}=this,{X:d,Y:f,Z:b}=oe,A=S.eql(S.mul(ne,b),S.mul(d,N)),H=S.eql(S.mul(re,b),S.mul(f,N));return A&&H}negate(){return new ve(this.X,S.neg(this.Y),this.Z)}double(){const{a:oe,b:ne}=M,re=S.mul(ne,m),{X:N,Y:d,Z:f}=this;let b=S.ZERO,A=S.ZERO,H=S.ZERO,$=S.mul(N,N),W=S.mul(d,d),ie=S.mul(f,f),Q=S.mul(N,d);return Q=S.add(Q,Q),H=S.mul(N,f),H=S.add(H,H),b=S.mul(oe,H),A=S.mul(re,ie),A=S.add(b,A),b=S.sub(W,A),A=S.add(W,A),A=S.mul(b,A),b=S.mul(Q,b),H=S.mul(re,H),ie=S.mul(oe,ie),Q=S.sub($,ie),Q=S.mul(oe,Q),Q=S.add(Q,H),H=S.add($,$),$=S.add(H,$),$=S.add($,ie),$=S.mul($,Q),A=S.add(A,$),ie=S.mul(d,f),ie=S.add(ie,ie),$=S.mul(ie,Q),b=S.sub(b,$),H=S.mul(ie,W),H=S.add(H,H),H=S.add(H,H),new ve(b,A,H)}add(oe){xe(oe);const{X:ne,Y:re,Z:N}=this,{X:d,Y:f,Z:b}=oe;let A=S.ZERO,H=S.ZERO,$=S.ZERO;const W=M.a,ie=S.mul(M.b,m);let Q=S.mul(ne,d),fe=S.mul(re,f),le=S.mul(N,b),Ae=S.add(ne,re),Ne=S.add(d,f);Ae=S.mul(Ae,Ne),Ne=S.add(Q,fe),Ae=S.sub(Ae,Ne),Ne=S.add(ne,N);let Ye=S.add(d,b);return Ne=S.mul(Ne,Ye),Ye=S.add(Q,le),Ne=S.sub(Ne,Ye),Ye=S.add(re,N),A=S.add(f,b),Ye=S.mul(Ye,A),A=S.add(fe,le),Ye=S.sub(Ye,A),$=S.mul(W,Ne),A=S.mul(ie,le),$=S.add(A,$),A=S.sub(fe,$),$=S.add(fe,$),H=S.mul(A,$),fe=S.add(Q,Q),fe=S.add(fe,Q),le=S.mul(W,le),Ne=S.mul(ie,Ne),fe=S.add(fe,le),le=S.sub(Q,le),le=S.mul(W,le),Ne=S.add(Ne,le),Q=S.mul(fe,Ne),H=S.add(H,Q),Q=S.mul(Ye,Ne),A=S.mul(Ae,A),A=S.sub(A,Q),Q=S.mul(Ae,fe),$=S.mul(Ye,$),$=S.add($,Q),new ve(A,H,$)}subtract(oe){return this.add(oe.negate())}is0(){return this.equals(ve.ZERO)}multiply(oe){const{endo:ne}=j;if(!I.isValidNot0(oe))throw new Error("invalid scalar: out of range");let re,N;const d=f=>Qe.cached(this,f,b=>(0,i.normalizeZ)(ve,b));if(ne){const{k1neg:f,k1:b,k2neg:A,k2:H}=Me(oe),{p:$,f:W}=d(b),{p:ie,f:Q}=d(H);N=W.add(Q),re=gt(ne.beta,$,ie,f,A)}else{const{p:f,f:b}=d(oe);re=f,N=b}return(0,i.normalizeZ)(ve,[re,N])[0]}multiplyUnsafe(oe){const{endo:ne}=j,re=this;if(!I.isValid(oe))throw new Error("invalid scalar: out of range");if(oe===h||re.is0())return ve.ZERO;if(oe===y)return re;if(Qe.hasCache(this))return this.multiply(oe);if(ne){const{k1neg:N,k1:d,k2neg:f,k2:b}=Me(oe),{p1:A,p2:H}=(0,i.mulEndoUnsafe)(ve,re,d,b);return gt(ne.beta,A,H,N,f)}else return Qe.unsafe(re,oe)}multiplyAndAddUnsafe(oe,ne,re){const N=this.multiplyUnsafe(ne).add(oe.multiplyUnsafe(re));return N.is0()?void 0:N}toAffine(oe){return tt(this,oe)}isTorsionFree(){const{isTorsionFree:oe}=j;return O===y?!0:oe?oe(ve,this):Qe.unsafe(this,V).is0()}clearCofactor(){const{clearCofactor:oe}=j;return O===y?this:oe?oe(ve,this):this.multiplyUnsafe(O)}isSmallOrder(){return this.multiplyUnsafe(O).is0()}toBytes(oe=!0){return(0,r._abool2)(oe,"isCompressed"),this.assertValidity(),te(ve,this,oe)}toHex(oe=!0){return(0,r.bytesToHex)(this.toBytes(oe))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(oe=!0){return this.toBytes(oe)}_setWindowSize(oe){this.precompute(oe)}static normalizeZ(oe){return(0,i.normalizeZ)(ve,oe)}static msm(oe,ne){return(0,i.pippenger)(ve,I,oe,ne)}static fromPrivateKey(oe){return ve.BASE.multiply(E(I,oe))}}ve.BASE=new ve(M.Gx,M.Gy,S.ONE),ve.ZERO=new ve(S.ZERO,S.ONE,S.ZERO),ve.Fp=S,ve.Fn=I;const zt=I.BITS,Qe=new i.wNAF(ve,j.endo?Math.ceil(zt/2):zt);return ve.BASE.precompute(8),ve}function _(k){return Uint8Array.of(k?2:3)}function w(k,j){const F=k.ORDER;let S=h;for(let Z=F-y;Z%p===h;Z/=p)S+=y;const I=S,M=p<<I-y-y,O=M*p,V=(F-y)/O,G=(V-y)/p,X=O-y,Y=M,ce=k.pow(j,V),ue=k.pow(j,(V+y)/p);let te=(Z,ae)=>{let ge=ce,pe=k.pow(ae,X),J=k.sqr(pe);J=k.mul(J,ae);let de=k.mul(Z,J);de=k.pow(de,G),de=k.mul(de,pe),pe=k.mul(de,ae),J=k.mul(de,Z);let xe=k.mul(J,pe);de=k.pow(xe,Y);let Me=k.eql(de,k.ONE);pe=k.mul(J,ue),de=k.mul(xe,ge),J=k.cmov(pe,J,Me),xe=k.cmov(de,xe,Me);for(let tt=I;tt>y;tt--){let ut=tt-p;ut=p<<ut-y;let gt=k.pow(xe,ut);const ve=k.eql(gt,k.ONE);pe=k.mul(J,ge),ge=k.mul(ge,ge),gt=k.mul(xe,ge),J=k.cmov(pe,J,ve),xe=k.cmov(gt,xe,ve)}return{isValid:Me,value:J}};if(k.ORDER%g===m){const Z=(k.ORDER-m)/g,ae=k.sqrt(k.neg(j));te=(ge,pe)=>{let J=k.sqr(pe);const de=k.mul(ge,pe);J=k.mul(J,de);let xe=k.pow(J,Z);xe=k.mul(xe,de);const Me=k.mul(xe,ae),tt=k.mul(k.sqr(xe),pe),ut=k.eql(tt,ge);let gt=k.cmov(Me,xe,ut);return{isValid:ut,value:gt}}}return te}function T(k,j){(0,s.validateField)(k);const{A:F,B:S,Z:I}=j;if(!k.isValid(F)||!k.isValid(S)||!k.isValid(I))throw new Error("mapToCurveSimpleSWU: invalid opts");const M=w(k,I);if(!k.isOdd)throw new Error("Field does not have .isOdd()");return O=>{let V,G,X,Y,ce,ue,te,Z;V=k.sqr(O),V=k.mul(V,I),G=k.sqr(V),G=k.add(G,V),X=k.add(G,k.ONE),X=k.mul(X,S),Y=k.cmov(I,k.neg(G),!k.eql(G,k.ZERO)),Y=k.mul(Y,F),G=k.sqr(X),ue=k.sqr(Y),ce=k.mul(ue,F),G=k.add(G,ce),G=k.mul(G,X),ue=k.mul(ue,Y),ce=k.mul(ue,S),G=k.add(G,ce),te=k.mul(V,X);const{isValid:ae,value:ge}=M(G,ue);Z=k.mul(V,O),Z=k.mul(Z,ge),te=k.cmov(te,X,ae),Z=k.cmov(Z,ge,ae);const pe=k.isOdd(O)===k.isOdd(Z);Z=k.cmov(k.neg(Z),Z,pe);const J=(0,s.FpInvertBatch)(k,[Y],!0)[0];return te=k.mul(te,J),{x:te,y:Z}}}function R(k,j){return{secretKey:j.BYTES,publicKey:1+k.BYTES,publicKeyUncompressed:1+2*k.BYTES,publicKeyHasPrefix:!0,signature:2*j.BYTES}}function B(k,j={}){const{Fn:F}=k,S=j.randomBytes||r.randomBytes,I=Object.assign(R(k.Fp,F),{seed:(0,s.getMinHashLength)(F.ORDER)});function M(te){try{return!!E(F,te)}catch{return!1}}function O(te,Z){const{publicKey:ae,publicKeyUncompressed:ge}=I;try{const pe=te.length;return Z===!0&&pe!==ae||Z===!1&&pe!==ge?!1:!!k.fromBytes(te)}catch{return!1}}function V(te=S(I.seed)){return(0,s.mapHashToField)((0,r._abytes2)(te,I.seed,"seed"),F.ORDER)}function G(te,Z=!0){return k.BASE.multiply(E(F,te)).toBytes(Z)}function X(te){const Z=V(te);return{secretKey:Z,publicKey:G(Z)}}function Y(te){if(typeof te=="bigint")return!1;if(te instanceof k)return!0;const{secretKey:Z,publicKey:ae,publicKeyUncompressed:ge}=I;if(F.allowedLengths||Z===ae)return;const pe=(0,r.ensureBytes)("key",te).length;return pe===ae||pe===ge}function ce(te,Z,ae=!0){if(Y(te)===!0)throw new Error("first arg must be private key");if(Y(Z)===!1)throw new Error("second arg must be public key");const ge=E(F,te);return k.fromHex(Z).multiply(ge).toBytes(ae)}return Object.freeze({getPublicKey:G,getSharedSecret:ce,keygen:X,Point:k,utils:{isValidSecretKey:M,isValidPublicKey:O,randomSecretKey:V,isValidPrivateKey:M,randomPrivateKey:V,normPrivateKeyToScalar:te=>E(F,te),precompute(te=8,Z=k.BASE){return Z.precompute(te,!1)}},lengths:I})}function P(k,j,F={}){(0,n.ahash)(j),(0,r._validateObject)(F,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const S=F.randomBytes||r.randomBytes,I=F.hmac||((ne,...re)=>(0,t.hmac)(j,ne,(0,r.concatBytes)(...re))),{Fp:M,Fn:O}=k,{ORDER:V,BITS:G}=O,{keygen:X,getPublicKey:Y,getSharedSecret:ce,utils:ue,lengths:te}=B(k,F),Z={prehash:!1,lowS:typeof F.lowS=="boolean"?F.lowS:!1,format:void 0,extraEntropy:!1},ae="compact";function ge(ne){const re=V>>y;return ne>re}function pe(ne,re){if(!O.isValidNot0(re))throw new Error(`invalid signature ${ne}: out of range 1..Point.Fn.ORDER`);return re}function J(ne,re){a(re);const N=te.signature,d=re==="compact"?N:re==="recovered"?N+1:void 0;return(0,r._abytes2)(ne,d,`${re} signature`)}class de{constructor(re,N,d){this.r=pe("r",re),this.s=pe("s",N),d!=null&&(this.recovery=d),Object.freeze(this)}static fromBytes(re,N=ae){J(re,N);let d;if(N==="der"){const{r:H,s:$}=e.DER.toSig((0,r._abytes2)(re));return new de(H,$)}N==="recovered"&&(d=re[0],N="compact",re=re.subarray(1));const f=O.BYTES,b=re.subarray(0,f),A=re.subarray(f,f*2);return new de(O.fromBytes(b),O.fromBytes(A),d)}static fromHex(re,N){return this.fromBytes((0,r.hexToBytes)(re),N)}addRecoveryBit(re){return new de(this.r,this.s,re)}recoverPublicKey(re){const N=M.ORDER,{r:d,s:f,recovery:b}=this;if(b==null||![0,1,2,3].includes(b))throw new Error("recovery id invalid");if(V*p<N&&b>1)throw new Error("recovery id is ambiguous for h>1 curve");const H=b===2||b===3?d+V:d;if(!M.isValid(H))throw new Error("recovery id 2 or 3 invalid");const $=M.toBytes(H),W=k.fromBytes((0,r.concatBytes)(_((b&1)===0),$)),ie=O.inv(H),Q=Me((0,r.ensureBytes)("msgHash",re)),fe=O.create(-Q*ie),le=O.create(f*ie),Ae=k.BASE.multiplyUnsafe(fe).add(W.multiplyUnsafe(le));if(Ae.is0())throw new Error("point at infinify");return Ae.assertValidity(),Ae}hasHighS(){return ge(this.s)}toBytes(re=ae){if(a(re),re==="der")return(0,r.hexToBytes)(e.DER.hexFromSig(this));const N=O.toBytes(this.r),d=O.toBytes(this.s);if(re==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,r.concatBytes)(Uint8Array.of(this.recovery),N,d)}return(0,r.concatBytes)(N,d)}toHex(re){return(0,r.bytesToHex)(this.toBytes(re))}assertValidity(){}static fromCompact(re){return de.fromBytes((0,r.ensureBytes)("sig",re),"compact")}static fromDER(re){return de.fromBytes((0,r.ensureBytes)("sig",re),"der")}normalizeS(){return this.hasHighS()?new de(this.r,O.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,r.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,r.bytesToHex)(this.toBytes("compact"))}}const xe=F.bits2int||function(re){if(re.length>8192)throw new Error("input is too large");const N=(0,r.bytesToNumberBE)(re),d=re.length*8-G;return d>0?N>>BigInt(d):N},Me=F.bits2int_modN||function(re){return O.create(xe(re))},tt=(0,r.bitMask)(G);function ut(ne){return(0,r.aInRange)("num < 2^"+G,ne,h,tt),O.toBytes(ne)}function gt(ne,re){return(0,r._abytes2)(ne,void 0,"message"),re?(0,r._abytes2)(j(ne),void 0,"prehashed message"):ne}function ve(ne,re,N){if(["recovered","canonical"].some(fe=>fe in N))throw new Error("sign() legacy options not supported");const{lowS:d,prehash:f,extraEntropy:b}=u(N,Z);ne=gt(ne,f);const A=Me(ne),H=E(O,re),$=[ut(H),ut(A)];if(b!=null&&b!==!1){const fe=b===!0?S(te.secretKey):b;$.push((0,r.ensureBytes)("extraEntropy",fe))}const W=(0,r.concatBytes)(...$),ie=A;function Q(fe){const le=xe(fe);if(!O.isValidNot0(le))return;const Ae=O.inv(le),Ne=k.BASE.multiply(le).toAffine(),Ye=O.create(Ne.x);if(Ye===h)return;const Ve=O.create(Ae*O.create(ie+Ye*H));if(Ve===h)return;let Bn=(Ne.x===Ye?0:2)|Number(Ne.y&y),ay=Ve;return d&&ge(Ve)&&(ay=O.neg(Ve),Bn^=1),new de(Ye,ay,Bn)}return{seed:W,k2sig:Q}}function zt(ne,re,N={}){ne=(0,r.ensureBytes)("message",ne);const{seed:d,k2sig:f}=ve(ne,re,N);return(0,r.createHmacDrbg)(j.outputLen,O.BYTES,I)(d,f)}function Qe(ne){let re;const N=typeof ne=="string"||(0,r.isBytes)(ne),d=!N&&ne!==null&&typeof ne=="object"&&typeof ne.r=="bigint"&&typeof ne.s=="bigint";if(!N&&!d)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(d)re=new de(ne.r,ne.s);else if(N){try{re=de.fromBytes((0,r.ensureBytes)("sig",ne),"der")}catch(f){if(!(f instanceof e.DER.Err))throw f}if(!re)try{re=de.fromBytes((0,r.ensureBytes)("sig",ne),"compact")}catch{return!1}}return re||!1}function ke(ne,re,N,d={}){const{lowS:f,prehash:b,format:A}=u(d,Z);if(N=(0,r.ensureBytes)("publicKey",N),re=gt((0,r.ensureBytes)("message",re),b),"strict"in d)throw new Error("options.strict was renamed to lowS");const H=A===void 0?Qe(ne):de.fromBytes((0,r.ensureBytes)("sig",ne),A);if(H===!1)return!1;try{const $=k.fromBytes(N);if(f&&H.hasHighS())return!1;const{r:W,s:ie}=H,Q=Me(re),fe=O.inv(ie),le=O.create(Q*fe),Ae=O.create(W*fe),Ne=k.BASE.multiplyUnsafe(le).add($.multiplyUnsafe(Ae));return Ne.is0()?!1:O.create(Ne.x)===W}catch{return!1}}function oe(ne,re,N={}){const{prehash:d}=u(N,Z);return re=gt(re,d),de.fromBytes(ne,"recovered").recoverPublicKey(re).toBytes()}return Object.freeze({keygen:X,getPublicKey:Y,getSharedSecret:ce,utils:ue,lengths:te,Point:k,sign:zt,verify:ke,recoverPublicKey:oe,Signature:de,hash:j})}function q(k){const{CURVE:j,curveOpts:F}=v(k),S=x(j,F);return K(k,S)}function v(k){const j={a:k.a,b:k.b,p:k.Fp.ORDER,n:k.n,h:k.h,Gx:k.Gx,Gy:k.Gy},F=k.Fp;let S=k.allowedPrivateKeyLengths?Array.from(new Set(k.allowedPrivateKeyLengths.map(O=>Math.ceil(O/2)))):void 0;const I=(0,s.Field)(j.n,{BITS:k.nBitLength,allowedLengths:S,modFromBytes:k.wrapPrivateKey}),M={Fp:F,Fn:I,allowInfinityPoint:k.allowInfinityPoint,endo:k.endo,isTorsionFree:k.isTorsionFree,clearCofactor:k.clearCofactor,fromBytes:k.fromBytes,toBytes:k.toBytes};return{CURVE:j,curveOpts:M}}function C(k){const{CURVE:j,curveOpts:F}=v(k),S={hmac:k.hmac,randomBytes:k.randomBytes,lowS:k.lowS,bits2int:k.bits2int,bits2int_modN:k.bits2int_modN};return{CURVE:j,curveOpts:F,hash:k.hash,ecdsaOpts:S}}function L(k,j,F){function S(I){const M=k.sqr(I),O=k.mul(M,I);return k.add(k.add(O,k.mul(I,j)),F)}return S}function K(k,j){const{Fp:F,Fn:S}=j;function I(O){return(0,r.inRange)(O,y,S.ORDER)}const M=L(F,k.a,k.b);return Object.assign({},{CURVE:k,Point:j,ProjectivePoint:j,normPrivateKeyToScalar:O=>E(S,O),weierstrassEquation:M,isWithinCurveOrder:I})}function U(k,j){const F=j.Point;return Object.assign({},j,{ProjectivePoint:F,CURVE:Object.assign({},k,(0,s.nLength)(F.Fn.ORDER,F.Fn.BITS))})}function D(k){const{CURVE:j,curveOpts:F,hash:S,ecdsaOpts:I}=C(k),M=x(j,F),O=P(M,S,I);return U(k,O)}})(ha)),ha}var nd;function dm(){if(nd)return ls;nd=1,Object.defineProperty(ls,"__esModule",{value:!0}),ls.getHash=t,ls.createCurve=n;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=td();function t(r){return{hash:r}}function n(r,i){const s=o=>(0,e.weierstrass)({...r,hash:o});return{...s(i),create:s}}return ls}var ma={},rd;function hm(){return rd||(rd=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=a,e.expand_message_xof=u,e.hash_to_field=l,e.isogenyMap=h,e.createHasher=y;const t=fi(),n=ds(),r=t.bytesToNumberBE;function i(p,m){if(o(p),o(m),p<0||p>=1<<8*m)throw new Error("invalid I2OSP input: "+p);const g=Array.from({length:m}).fill(0);for(let E=m-1;E>=0;E--)g[E]=p&255,p>>>=8;return new Uint8Array(g)}function s(p,m){const g=new Uint8Array(p.length);for(let E=0;E<p.length;E++)g[E]=p[E]^m[E];return g}function o(p){if(!Number.isSafeInteger(p))throw new Error("number expected")}function c(p){if(!(0,t.isBytes)(p)&&typeof p!="string")throw new Error("DST must be Uint8Array or string");return typeof p=="string"?(0,t.utf8ToBytes)(p):p}function a(p,m,g,E){(0,t.abytes)(p),o(g),m=c(m),m.length>255&&(m=E((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),m)));const{outputLen:x,blockLen:_}=E,w=Math.ceil(g/x);if(g>65535||w>255)throw new Error("expand_message_xmd: invalid lenInBytes");const T=(0,t.concatBytes)(m,i(m.length,1)),R=i(0,_),B=i(g,2),P=new Array(w),q=E((0,t.concatBytes)(R,p,B,i(0,1),T));P[0]=E((0,t.concatBytes)(q,i(1,1),T));for(let C=1;C<=w;C++){const L=[s(q,P[C-1]),i(C+1,1),T];P[C]=E((0,t.concatBytes)(...L))}return(0,t.concatBytes)(...P).slice(0,g)}function u(p,m,g,E,x){if((0,t.abytes)(p),o(g),m=c(m),m.length>255){const _=Math.ceil(2*E/8);m=x.create({dkLen:_}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(m).digest()}if(g>65535||m.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return x.create({dkLen:g}).update(p).update(i(g,2)).update(m).update(i(m.length,1)).digest()}function l(p,m,g){(0,t._validateObject)(g,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:E,k:x,m:_,hash:w,expand:T,DST:R}=g;if(!(0,t.isHash)(g.hash))throw new Error("expected valid hash");(0,t.abytes)(p),o(m);const B=E.toString(2).length,P=Math.ceil((B+x)/8),q=m*_*P;let v;if(T==="xmd")v=a(p,R,q,w);else if(T==="xof")v=u(p,R,q,x,w);else if(T==="_internal_pass")v=p;else throw new Error('expand must be "xmd" or "xof"');const C=new Array(m);for(let L=0;L<m;L++){const K=new Array(_);for(let U=0;U<_;U++){const D=P*(U+L*_),k=v.subarray(D,D+P);K[U]=(0,n.mod)(r(k),E)}C[L]=K}return C}function h(p,m){const g=m.map(E=>Array.from(E).reverse());return(E,x)=>{const[_,w,T,R]=g.map(q=>q.reduce((v,C)=>p.add(p.mul(v,E),C))),[B,P]=(0,n.FpInvertBatch)(p,[w,R],!0);return E=p.mul(_,B),x=p.mul(x,p.mul(T,P)),{x:E,y:x}}}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-");function y(p,m,g){if(typeof m!="function")throw new Error("mapToCurve() must be defined");function E(_){return p.fromAffine(m(_))}function x(_){const w=_.clearCofactor();return w.equals(p.ZERO)?p.ZERO:(w.assertValidity(),w)}return{defaults:g,hashToCurve(_,w){const T=Object.assign({},g,w),R=l(_,2,T),B=E(R[0]),P=E(R[1]);return x(B.add(P))},encodeToCurve(_,w){const T=g.encodeDST?{DST:g.encodeDST}:{},R=Object.assign({},g,T,w),B=l(_,1,R),P=E(B[0]);return x(P)},mapToCurve(_){if(!Array.isArray(_))throw new Error("expected array of bigints");for(const w of _)if(typeof w!="bigint")throw new Error("expected array of bigints");return x(E(_))},hashToScalar(_,w){const T=p.Fn.ORDER,R=Object.assign({},g,{p:T,m:1,DST:e._DST_scalar},w);return l(_,1,R)[0][0]}}}})(ma)),ma}var id;function pm(){return id||(id=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.encodeToCurve=e.hashToCurve=e.secp256k1_hasher=e.schnorr=e.secp256k1=void 0;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Df(),n=Xn(),r=dm(),i=hm(),s=ds(),o=td(),c=fi(),a={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},u={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},l=BigInt(0),h=BigInt(1),y=BigInt(2);function p(U){const D=a.p,k=BigInt(3),j=BigInt(6),F=BigInt(11),S=BigInt(22),I=BigInt(23),M=BigInt(44),O=BigInt(88),V=U*U*U%D,G=V*V*U%D,X=(0,s.pow2)(G,k,D)*G%D,Y=(0,s.pow2)(X,k,D)*G%D,ce=(0,s.pow2)(Y,y,D)*V%D,ue=(0,s.pow2)(ce,F,D)*ce%D,te=(0,s.pow2)(ue,S,D)*ue%D,Z=(0,s.pow2)(te,M,D)*te%D,ae=(0,s.pow2)(Z,O,D)*Z%D,ge=(0,s.pow2)(ae,M,D)*te%D,pe=(0,s.pow2)(ge,k,D)*G%D,J=(0,s.pow2)(pe,I,D)*ue%D,de=(0,s.pow2)(J,j,D)*V%D,xe=(0,s.pow2)(de,y,D);if(!m.eql(m.sqr(xe),U))throw new Error("Cannot find square root");return xe}const m=(0,s.Field)(a.p,{sqrt:p});e.secp256k1=(0,r.createCurve)({...a,Fp:m,lowS:!0,endo:u},t.sha256);const g={};function E(U,...D){let k=g[U];if(k===void 0){const j=(0,t.sha256)((0,c.utf8ToBytes)(U));k=(0,c.concatBytes)(j,j),g[U]=k}return(0,t.sha256)((0,c.concatBytes)(k,...D))}const x=U=>U.toBytes(!0).slice(1),_=e.secp256k1.Point,w=U=>U%y===l;function T(U){const{Fn:D,BASE:k}=_,j=(0,o._normFnElement)(D,U),F=k.multiply(j);return{scalar:w(F.y)?j:D.neg(j),bytes:x(F)}}function R(U){const D=m;if(!D.isValidNot0(U))throw new Error("invalid x: Fail if x ≥ p");const k=D.create(U*U),j=D.create(k*U+BigInt(7));let F=D.sqrt(j);w(F)||(F=D.neg(F));const S=_.fromAffine({x:U,y:F});return S.assertValidity(),S}const B=c.bytesToNumberBE;function P(...U){return _.Fn.create(B(E("BIP0340/challenge",...U)))}function q(U){return T(U).bytes}function v(U,D,k=(0,n.randomBytes)(32)){const{Fn:j}=_,F=(0,c.ensureBytes)("message",U),{bytes:S,scalar:I}=T(D),M=(0,c.ensureBytes)("auxRand",k,32),O=j.toBytes(I^B(E("BIP0340/aux",M))),V=E("BIP0340/nonce",O,S,F),{bytes:G,scalar:X}=T(V),Y=P(G,S,F),ce=new Uint8Array(64);if(ce.set(G,0),ce.set(j.toBytes(j.create(X+Y*I)),32),!C(ce,F,S))throw new Error("sign: Invalid signature produced");return ce}function C(U,D,k){const{Fn:j,BASE:F}=_,S=(0,c.ensureBytes)("signature",U,64),I=(0,c.ensureBytes)("message",D),M=(0,c.ensureBytes)("publicKey",k,32);try{const O=R(B(M)),V=B(S.subarray(0,32));if(!(0,c.inRange)(V,h,a.p))return!1;const G=B(S.subarray(32,64));if(!(0,c.inRange)(G,h,a.n))return!1;const X=P(j.toBytes(V),x(O),I),Y=F.multiplyUnsafe(G).add(O.multiplyUnsafe(j.neg(X))),{x:ce,y:ue}=Y.toAffine();return!(Y.is0()||!w(ue)||ce!==V)}catch{return!1}}e.schnorr=(()=>{const k=(F=(0,n.randomBytes)(48))=>(0,s.mapHashToField)(F,a.n);e.secp256k1.utils.randomSecretKey;function j(F){const S=k(F);return{secretKey:S,publicKey:q(S)}}return{keygen:j,getPublicKey:q,sign:v,verify:C,Point:_,utils:{randomSecretKey:k,randomPrivateKey:k,taggedHash:E,lift_x:R,pointToBytes:x,numberToBytesBE:c.numberToBytesBE,bytesToNumberBE:c.bytesToNumberBE,mod:s.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const L=(0,i.isogenyMap)(m,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(U=>U.map(D=>BigInt(D)))),K=(0,o.mapToCurveSimpleSWU)(m,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:m.create(BigInt("-11"))});e.secp256k1_hasher=(0,i.createHasher)(e.secp256k1.Point,U=>{const{x:D,y:k}=K(m.create(U[0]));return L(D,k)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:m.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve})(da)),da}var Cr={},sd;function ym(){return sd||(sd=1,(function(e){var t=Cr&&Cr.__createBinding||(Object.create?(function(r,i,s,o){o===void 0&&(o=s);var c=Object.getOwnPropertyDescriptor(i,s);(!c||("get"in c?!i.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return i[s]}}),Object.defineProperty(r,o,c)}):(function(r,i,s,o){o===void 0&&(o=s),r[o]=i[s]})),n=Cr&&Cr.__exportStar||function(r,i){for(var s in r)s!=="default"&&!Object.prototype.hasOwnProperty.call(i,s)&&t(i,r,s)};Object.defineProperty(e,"__esModule",{value:!0}),n(fi(),e)})(Cr)),Cr}var od;function mm(){if(od)return Ze;od=1;var e=pm(),t=ds(),n=ym();function r(d){var f=Object.create(null);return d&&Object.keys(d).forEach(function(b){if(b!=="default"){var A=Object.getOwnPropertyDescriptor(d,b);Object.defineProperty(f,b,A.get?A:{enumerable:!0,get:function(){return d[b]}})}}),f.default=d,Object.freeze(f)}var i=r(t),s=r(n);const o=e.secp256k1.ProjectivePoint,c="Expected Private",a="Expected Point",u="Expected Tweak",l="Expected Hash",h="Expected Signature",y="Expected Extra Data (32 bytes)",p="Expected Scalar",m="Bad Recovery Id",g=32,E=32,x=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]),_=32,w=new Uint8Array(32),T=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]),R=BigInt(1);function B(d){return d instanceof Uint8Array}function P(d,f){for(let b=0;b<32;++b)if(d[b]!==f[b])return d[b]<f[b]?-1:1;return 0}function q(d){return P(d,w)===0}function v(d){return!(!(d instanceof Uint8Array)||d.length!==E||P(d,x)>=0)}function C(d){return d instanceof Uint8Array&&d.length===64&&P(d.subarray(0,32),x)<0&&P(d.subarray(32,64),x)<0}function L(d){return B(d)&&d.length===64&&P(d.subarray(0,32),T)<0}function K(d){return!(q(d.subarray(0,32))||q(d.subarray(32,64)))}function U(d){return d instanceof Uint8Array&&d.length===g}function D(d){return d===void 0||d instanceof Uint8Array&&d.length===_}function k(d){let f;if(typeof d=="bigint")f=d;else if(typeof d=="number"&&Number.isSafeInteger(d)&&d>=0)f=BigInt(d);else if(typeof d=="string"){if(d.length!==64)throw new Error("Expected 32 bytes of private scalar");f=s.hexToNumber(d)}else if(d instanceof Uint8Array){if(d.length!==32)throw new Error("Expected 32 bytes of private scalar");f=s.bytesToNumberBE(d)}else throw new TypeError("Expected valid private scalar");if(f<0)throw new Error("Expected private scalar >= 0");return f}function j(d){return e.secp256k1.utils.normPrivateKeyToScalar(d)}function F(d,f){const b=j(d),A=k(f),H=s.numberToBytesBE(i.mod(b+A,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(H)?H:null}function S(d,f){const b=j(d),A=k(f),H=s.numberToBytesBE(i.mod(b-A,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(H)?H:null}function I(d){const f=j(d),b=s.numberToBytesBE(e.secp256k1.CURVE.n-f,32);return e.secp256k1.utils.isValidPrivateKey(b)?b:null}function M(d,f,b){const A=Y(d),H=k(f),$=o.BASE.multiplyAndAddUnsafe(A,H,R);if(!$)throw new Error("Tweaked point at infinity");return $.toRawBytes(b)}function O(d,f,b){const A=Y(d),H=typeof f=="string"?f:s.bytesToHex(f),$=s.hexToNumber(H);return A.multiply($).toRawBytes(b)}function V(d,f){return d===void 0?f!==void 0?te(f):!0:!!d}function G(d){try{return d()}catch{return null}}function X(d){return e.schnorr.utils.lift_x(s.bytesToNumberBE(d))}function Y(d){return d.length===32?X(d):o.fromHex(d)}function ce(d,f){if(d.length===32!==f)return!1;try{return f?!!X(d):!!o.fromHex(d)}catch{return!1}}function ue(d){return ce(d,!1)}function te(d){return ce(d,!1)&&d.length===33}function Z(d){return e.secp256k1.utils.isValidPrivateKey(d)}function ae(d){return ce(d,!0)}function ge(d,f){if(!ae(d))throw new Error(a);if(!v(f))throw new Error(u);return G(()=>{const b=M(d,f,!0);return{parity:b[0]%2===1?1:0,xOnlyPubkey:b.slice(1)}})}function pe(d){if(!ue(d))throw new Error(a);return d.slice(1,33)}function J(d,f){if(!Z(d))throw new Error(c);return G(()=>e.secp256k1.getPublicKey(d,V(f)))}function de(d){if(!Z(d))throw new Error(c);return pe(J(d))}function xe(d,f){if(!ue(d))throw new Error(a);return Y(d).toRawBytes(V(f,d))}function Me(d,f,b){if(!ue(d))throw new Error(a);if(!v(f))throw new Error(u);return G(()=>O(d,f,V(b,d)))}function tt(d,f,b){if(!ue(d)||!ue(f))throw new Error(a);return G(()=>{const A=Y(d),H=Y(f);return A.equals(H.negate())?null:A.add(H).toRawBytes(V(b,d))})}function ut(d,f,b){if(!ue(d))throw new Error(a);if(!v(f))throw new Error(u);return G(()=>M(d,f,V(b,d)))}function gt(d,f){if(!Z(d))throw new Error(c);if(!v(f))throw new Error(u);return G(()=>F(d,f))}function ve(d,f){if(!Z(d))throw new Error(c);if(!v(f))throw new Error(u);return G(()=>S(d,f))}function zt(d){if(!Z(d))throw new Error(c);return I(d)}function Qe(d,f,b){if(!Z(f))throw new Error(c);if(!U(d))throw new Error(p);if(!D(b))throw new Error(y);return e.secp256k1.sign(d,f,{extraEntropy:b}).toCompactRawBytes()}function ke(d,f,b){if(!Z(f))throw new Error(c);if(!U(d))throw new Error(p);if(!D(b))throw new Error(y);const A=e.secp256k1.sign(d,f,{extraEntropy:b});return{signature:A.toCompactRawBytes(),recoveryId:A.recovery}}function oe(d,f,b){if(!Z(f))throw new Error(c);if(!U(d))throw new Error(p);if(!D(b))throw new Error(y);return e.schnorr.sign(d,f,b)}function ne(d,f,b,A){if(!U(d))throw new Error(l);if(!C(f)||!K(f))throw new Error(h);if(b&2&&!L(f))throw new Error(m);if(!ae(f.subarray(0,32)))throw new Error(h);const $=e.secp256k1.Signature.fromCompact(f).addRecoveryBit(b).recoverPublicKey(d);if(!$)throw new Error(h);return $.toRawBytes(V(A))}function re(d,f,b,A){if(!ue(f))throw new Error(a);if(!C(b))throw new Error(h);if(!U(d))throw new Error(p);return e.secp256k1.verify(b,d,f,{lowS:A})}function N(d,f,b){if(!ae(f))throw new Error(a);if(!C(b))throw new Error(h);if(!U(d))throw new Error(p);return e.schnorr.verify(b,d,f)}return Ze.isPoint=ue,Ze.isPointCompressed=te,Ze.isPrivate=Z,Ze.isXOnlyPoint=ae,Ze.pointAdd=tt,Ze.pointAddScalar=ut,Ze.pointCompress=xe,Ze.pointFromScalar=J,Ze.pointMultiply=Me,Ze.privateAdd=gt,Ze.privateNegate=zt,Ze.privateSub=ve,Ze.recover=ne,Ze.sign=Qe,Ze.signRecoverable=ke,Ze.signSchnorr=oe,Ze.verify=re,Ze.verifySchnorr=N,Ze.xOnlyPointAddTweak=ge,Ze.xOnlyPointFromPoint=pe,Ze.xOnlyPointFromScalar=de,Ze}var cd=mm();const gm=oi({__proto__:null,default:Hc(cd)},[cd]);wn.initEccLib(gm);const hs={Mainnet:"mainnet",Testnet:"testnet"},_o="abcdefghijklmnopqrstuvwxyz234567",li=Object.create(null);for(let e=0;e<_o.length;e++)li[_o[e]]=e;li[0]=li.o,li[1]=li.i;function wm(e){let t=0,n=0,r="";function i(s){return t<0?n|=s>>-t:n=s<<t&248,t>3?(t-=8,1):(t<4&&(r+=_o[n>>3],t+=5),0)}for(let s=0;s<e.length;)s+=i(e[s]);return r+(t<0?_o[n>>3]:"")}function bm(e){let t=0,n=0;const r=new Uint8Array(e.length*4/3|0);let i=0;function s(o){let c=li[o.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(o)}`);c<<=3,n|=c>>>t,t+=5,t>=8&&(r[i++]=n,t-=8,t>0?n=c<<5-t&255:n=0)}for(const o of e)s(o);return r.slice(0,i)}const Em=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function _m(e){let t=-1;for(let n=0;n<e.length;n++){const i=(e[n]^t)&255;t=Em[i]^t>>>8}return(t^-1)>>>0}const di=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ps(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Sm(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Zt(e,...t){if(!ps(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 ad(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 xm(e,t){Zt(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ys(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ga(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function bn(e,t){return e<<32-t|e>>>t}const ud=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Tm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ze(e){if(Zt(e),ud)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Tm[e[n]];return t}const kn={_0:48,_9:57,A:65,F:70,a:97,f:102};function fd(e){if(e>=kn._0&&e<=kn._9)return e-kn._0;if(e>=kn.A&&e<=kn.F)return e-(kn.A-10);if(e>=kn.a&&e<=kn.f)return e-(kn.a-10)}function ms(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ud)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=fd(e.charCodeAt(s)),c=fd(e.charCodeAt(s+1));if(o===void 0||c===void 0){const a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}r[i]=o*16+c}return r}function rt(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ld(e){return typeof e=="string"&&(e=rt(e)),Zt(e),e}function qe(...e){let t=0;for(let r=0;r<e.length;r++){const i=e[r];Zt(i),t+=i.length}const n=new Uint8Array(t);for(let r=0,i=0;r<e.length;r++){const s=e[r];n.set(s,i),i+=s.length}return n}class vm{}function wa(e){const t=r=>e().update(ld(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function dd(e=32){if(di&&typeof di.getRandomValues=="function")return di.getRandomValues(new Uint8Array(e));if(di&&typeof di.randomBytes=="function")return Uint8Array.from(di.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Bm(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,u=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+u,c,r)}function Am(e,t,n){return e&t^~e&n}function Im(e,t,n){return e&t^e&n^t&n}class hd extends vm{constructor(t,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(t),this.view=ga(this.buffer)}update(t){ad(this),t=ld(t),Zt(t);const{view:n,buffer:r,blockLen:i}=this,s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=ga(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ad(this),xm(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,ys(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;Bm(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=ga(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)c.setUint32(4*h,l[h],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.destroyed=o,t.finished=s,t.length=i,t.pos=c,i%n&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const ar=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ur=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),At=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),So=BigInt(2**32-1),pd=BigInt(32);function Om(e,t=!1){return t?{h:Number(e&So),l:Number(e>>pd&So)}:{h:Number(e>>pd&So)|0,l:Number(e&So)|0}}function Nm(e,t=!1){const n=e.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:c}=Om(e[s],t);[r[s],i[s]]=[o,c]}return[r,i]}const yd=(e,t,n)=>e>>>n,md=(e,t,n)=>e<<32-n|t>>>n,hi=(e,t,n)=>e>>>n|t<<32-n,pi=(e,t,n)=>e<<32-n|t>>>n,xo=(e,t,n)=>e<<64-n|t>>>n-32,To=(e,t,n)=>e>>>n-32|t<<64-n;function Pn(e,t,n,r){const i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}const Rm=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),km=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Pm=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Cm=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,Um=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),Hm=(e,t,n,r,i,s)=>t+n+r+i+s+(e/2**32|0)|0,Fm=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]),fr=new Uint32Array(64);class gd extends hd{constructor(t=32){super(64,t,8,!1),this.A=ar[0]|0,this.B=ar[1]|0,this.C=ar[2]|0,this.D=ar[3]|0,this.E=ar[4]|0,this.F=ar[5]|0,this.G=ar[6]|0,this.H=ar[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let h=0;h<16;h++,n+=4)fr[h]=t.getUint32(n,!1);for(let h=16;h<64;h++){const y=fr[h-15],p=fr[h-2],m=bn(y,7)^bn(y,18)^y>>>3,g=bn(p,17)^bn(p,19)^p>>>10;fr[h]=g+fr[h-7]+m+fr[h-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:u,H:l}=this;for(let h=0;h<64;h++){const y=bn(c,6)^bn(c,11)^bn(c,25),p=l+y+Am(c,a,u)+Fm[h]+fr[h]|0,g=(bn(r,2)^bn(r,13)^bn(r,22))+Im(r,i,s)|0;l=u,u=a,a=c,c=o+p|0,o=s,s=i,i=r,r=p+g|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,i,s,o,c,a,u,l)}roundClean(){ys(fr)}destroy(){this.set(0,0,0,0,0,0,0,0),ys(this.buffer)}}class qm extends gd{constructor(){super(28),this.A=ur[0]|0,this.B=ur[1]|0,this.C=ur[2]|0,this.D=ur[3]|0,this.E=ur[4]|0,this.F=ur[5]|0,this.G=ur[6]|0,this.H=ur[7]|0}}const wd=Nm(["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))),Mm=wd[0],Lm=wd[1],lr=new Uint32Array(80),dr=new Uint32Array(80);class Vm extends hd{constructor(t=64){super(128,t,16,!1),this.Ah=At[0]|0,this.Al=At[1]|0,this.Bh=At[2]|0,this.Bl=At[3]|0,this.Ch=At[4]|0,this.Cl=At[5]|0,this.Dh=At[6]|0,this.Dl=At[7]|0,this.Eh=At[8]|0,this.El=At[9]|0,this.Fh=At[10]|0,this.Fl=At[11]|0,this.Gh=At[12]|0,this.Gl=At[13]|0,this.Hh=At[14]|0,this.Hl=At[15]|0}get(){const{Ah:t,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:c,Dl:a,Eh:u,El:l,Fh:h,Fl:y,Gh:p,Gl:m,Hh:g,Hl:E}=this;return[t,n,r,i,s,o,c,a,u,l,h,y,p,m,g,E]}set(t,n,r,i,s,o,c,a,u,l,h,y,p,m,g,E){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=h|0,this.Fl=y|0,this.Gh=p|0,this.Gl=m|0,this.Hh=g|0,this.Hl=E|0}process(t,n){for(let w=0;w<16;w++,n+=4)lr[w]=t.getUint32(n),dr[w]=t.getUint32(n+=4);for(let w=16;w<80;w++){const T=lr[w-15]|0,R=dr[w-15]|0,B=hi(T,R,1)^hi(T,R,8)^yd(T,R,7),P=pi(T,R,1)^pi(T,R,8)^md(T,R,7),q=lr[w-2]|0,v=dr[w-2]|0,C=hi(q,v,19)^xo(q,v,61)^yd(q,v,6),L=pi(q,v,19)^To(q,v,61)^md(q,v,6),K=Pm(P,L,dr[w-7],dr[w-16]),U=Cm(K,B,C,lr[w-7],lr[w-16]);lr[w]=U|0,dr[w]=K|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:u,Dl:l,Eh:h,El:y,Fh:p,Fl:m,Gh:g,Gl:E,Hh:x,Hl:_}=this;for(let w=0;w<80;w++){const T=hi(h,y,14)^hi(h,y,18)^xo(h,y,41),R=pi(h,y,14)^pi(h,y,18)^To(h,y,41),B=h&p^~h&g,P=y&m^~y&E,q=Um(_,R,P,Lm[w],dr[w]),v=Hm(q,x,T,B,Mm[w],lr[w]),C=q|0,L=hi(r,i,28)^xo(r,i,34)^xo(r,i,39),K=pi(r,i,28)^To(r,i,34)^To(r,i,39),U=r&s^r&c^s&c,D=i&o^i&a^o&a;x=g|0,_=E|0,g=p|0,E=m|0,p=h|0,m=y|0,{h,l:y}=Pn(u|0,l|0,v|0,C|0),u=c|0,l=a|0,c=s|0,a=o|0,s=r|0,o=i|0;const k=Rm(C,K,D);r=km(k,v,L,U),i=k|0}({h:r,l:i}=Pn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Pn(this.Bh|0,this.Bl|0,s|0,o|0),{h:c,l:a}=Pn(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Pn(this.Dh|0,this.Dl|0,u|0,l|0),{h,l:y}=Pn(this.Eh|0,this.El|0,h|0,y|0),{h:p,l:m}=Pn(this.Fh|0,this.Fl|0,p|0,m|0),{h:g,l:E}=Pn(this.Gh|0,this.Gl|0,g|0,E|0),{h:x,l:_}=Pn(this.Hh|0,this.Hl|0,x|0,_|0),this.set(r,i,s,o,c,a,u,l,h,y,p,m,g,E,x,_)}roundClean(){ys(lr,dr)}destroy(){ys(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Jt=wa(()=>new gd),Dm=wa(()=>new qm),jm=wa(()=>new Vm),vo="__principal__",$m=2,bd=4,Km="aaaaa-aa";let Le=class Wi{static anonymous(){return new this(new Uint8Array([bd]))}static managementCanister(){return this.fromText(Km)}static selfAuthenticating(t){const n=Dm(t);return new this(new Uint8Array([...n,$m]))}static from(t){if(typeof t=="string")return Wi.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new Wi(t);if(Wi.isPrincipal(t))return new Wi(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(ms(t))}static fromText(t){let n=t;if(t.includes(vo)){const o=JSON.parse(t);vo in o&&(n=o[vo])}const r=n.toLowerCase().replace(/-/g,"");let i=bm(r);i=i.slice(4,i.length);const s=new this(i);if(s.toText()!==n)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${n}" may not be a valid Principal ID).`);return s}static fromUint8Array(t){return new this(t)}static isPrincipal(t){return t instanceof Wi||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===bd}toUint8Array(){return this._arr}toHex(){return ze(this._arr).toUpperCase()}toText(){const t=new ArrayBuffer(4);new DataView(t).setUint32(0,_m(this._arr));const r=new Uint8Array(t),i=new Uint8Array([...r,...this._arr]),o=wm(i).match(/.{1,5}/g);if(!o)throw new Error;return o.join("-")}toString(){return this.toText()}toJSON(){return{[vo]:this.toText()}}compareTo(t){for(let n=0;n<Math.min(this._arr.length,t._arr.length);n++){if(this._arr[n]<t._arr[n])return"lt";if(this._arr[n]>t._arr[n])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){const n=this.compareTo(t);return n=="lt"||n=="eq"}gtEq(t){const n=this.compareTo(t);return n=="gt"||n=="eq"}};function He(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.byteLength,0));let n=0;for(const r of e)t.set(r,n),n+=r.byteLength;return t}class yi{save(){return this._view}restore(t){if(!(t instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=t}constructor(t,n=t?.byteLength||0){if(t&&!(t instanceof Uint8Array))try{t=Ed(t)}catch{throw new Error("Buffer must be a Uint8Array")}if(n<0||!Number.isInteger(n))throw new Error("Length must be a non-negative integer");if(t&&n>t.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=t||new Uint8Array(0),this._view=new Uint8Array(this._buffer.buffer,0,n)}get buffer(){return this._view.slice()}get byteLength(){return this._view.byteLength}read(t){const n=this._view.subarray(0,t);return this._view=this._view.subarray(t),n.slice()}readUint8(){if(this._view.byteLength===0)return;const t=this._view[0];return this._view=this._view.subarray(1),t}write(t){if(!(t instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");const n=this._view.byteLength;this._view.byteOffset+this._view.byteLength+t.byteLength>=this._buffer.byteLength?this.alloc(t.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+t.byteLength),this._view.set(t,n)}get end(){return this._view.byteLength===0}alloc(t){if(t<=0||!Number.isInteger(t))throw new Error("Amount must be a positive integer");const n=new Uint8Array((this._buffer.byteLength+t)*1.2|0),r=new Uint8Array(n.buffer,0,this._view.byteLength+t);r.set(this._view),this._buffer=n,this._view=r}}function Ed(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?Ed(e.buffer):new Uint8Array(e)}function Gm(e,t){if(e.byteLength!==t.byteLength)return e.byteLength-t.byteLength;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]-t[n];return 0}function Wm(e){if(!(e instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Xm(e){const n=new TextEncoder().encode(e);let r=0;for(const i of n)r=(r*223+i)%2**32;return r}function Ft(e){if(/^_\d+_$/.test(e)||/^_0x[0-9a-fA-F]+_$/.test(e)){const t=+e.slice(1,-1);if(Number.isSafeInteger(t)&&t>=0&&t<2**32)return t}return Xm(e)}function _d(e){const t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}function ba(e){const t=BigInt(e);if(e<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<t}function Sd(){throw new Error("unexpected end of buffer")}function Ur(e,t){return e.byteLength<t&&Sd(),e.read(t)}function Hr(e){const t=e.readUint8();return t===void 0&&Sd(),t}function et(e){if(typeof e=="number"&&(e=BigInt(e)),e<BigInt(0))throw new Error("Cannot leb encode negative values.");const t=(e===BigInt(0)?0:_d(e))+1,n=new yi(new Uint8Array(t),0);for(;;){const r=Number(e&BigInt(127));if(e/=BigInt(128),e===BigInt(0)){n.write(new Uint8Array([r]));break}else n.write(new Uint8Array([r|128]))}return n.buffer}function pt(e){let t=BigInt(1),n=BigInt(0),r;do r=Hr(e),n+=BigInt(r&127).valueOf()*t,t*=BigInt(128);while(r>=128);return n}function ft(e){typeof e=="number"&&(e=BigInt(e));const t=e<BigInt(0);t&&(e=-e-BigInt(1));const n=(e===BigInt(0)?0:_d(e))+1,r=new yi(new Uint8Array(n),0);for(;;){const s=i(e);if(e/=BigInt(128),t&&e===BigInt(0)&&(s&64)!==0||!t&&e===BigInt(0)&&(s&64)===0){r.write(new Uint8Array([s]));break}else r.write(new Uint8Array([s|128]))}function i(s){const o=s%BigInt(128);return Number(t?BigInt(128)-o-BigInt(1):o)}return r.buffer}function hr(e){const t=new Uint8Array(e.buffer);let n=0;for(;n<t.byteLength;n++)if(t[n]<128){if((t[n]&64)===0)return pt(e);break}const r=new Uint8Array(Ur(e,n+1));let i=BigInt(0);for(let s=r.byteLength-1;s>=0;s--)i=i*BigInt(128)+BigInt(128-(r[s]&127)-1);return-i-BigInt(1)}function zm(e,t){if(BigInt(e)<BigInt(0))throw new Error("Cannot write negative values.");return xd(e,t)}function xd(e,t){e=BigInt(e);const n=new yi(new Uint8Array(Math.min(1,t)),0);let r=0,i=BigInt(256),s=BigInt(0),o=Number(e%i);for(n.write(new Uint8Array([o]));++r<t;)e<0&&s===BigInt(0)&&o!==0&&(s=BigInt(1)),o=Number((e/i-s)%BigInt(256)),n.write(new Uint8Array([o])),i*=BigInt(256);return n.buffer}function Td(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let n=BigInt(Hr(e)),r=BigInt(1),i=0;for(;++i<t;){r*=BigInt(256);const s=BigInt(Hr(e));n=n+r*s}return n}function Ym(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let n=Td(e,t);const r=BigInt(2)**(BigInt(8)*BigInt(t-1)+BigInt(7));return n>=r&&(n-=r*BigInt(2)),n}var Fe;(function(e){e[e.Null=-1]="Null",e[e.Bool=-2]="Bool",e[e.Nat=-3]="Nat",e[e.Int=-4]="Int",e[e.Float32=-13]="Float32",e[e.Float64=-14]="Float64",e[e.Text=-15]="Text",e[e.Reserved=-16]="Reserved",e[e.Empty=-17]="Empty",e[e.Opt=-18]="Opt",e[e.Vector=-19]="Vector",e[e.Record=-20]="Record",e[e.Variant=-21]="Variant",e[e.Func=-22]="Func",e[e.Service=-23]="Service",e[e.Principal=-24]="Principal"})(Fe||(Fe={}));const Bo="DIDL",vd=400;function gs(e,t,n){return e.map((r,i)=>n(r,t[i]))}class Zm{constructor(){this._typs=[],this._idx=new Map}has(t){return this._idx.has(t.name)}add(t,n){const r=this._typs.length;this._idx.set(t.name,r),this._typs.push(n)}merge(t,n){const r=this._idx.get(t.name),i=this._idx.get(n);if(r===void 0)throw new Error("Missing type index for "+t);if(i===void 0)throw new Error("Missing type index for "+n);this._typs[r]=this._typs[i],this._typs.splice(i,1),this._idx.delete(n)}encode(){const t=et(this._typs.length),n=He(...this._typs);return He(t,n)}indexOf(t){if(!this._idx.has(t))throw new Error("Missing type index for "+t);return ft(this._idx.get(t)||0)}}class Jm{visitType(t,n){throw new Error("Not implemented")}visitPrimitive(t,n){return this.visitType(t,n)}visitEmpty(t,n){return this.visitPrimitive(t,n)}visitBool(t,n){return this.visitPrimitive(t,n)}visitNull(t,n){return this.visitPrimitive(t,n)}visitReserved(t,n){return this.visitPrimitive(t,n)}visitText(t,n){return this.visitPrimitive(t,n)}visitNumber(t,n){return this.visitPrimitive(t,n)}visitInt(t,n){return this.visitNumber(t,n)}visitNat(t,n){return this.visitNumber(t,n)}visitFloat(t,n){return this.visitPrimitive(t,n)}visitFixedInt(t,n){return this.visitNumber(t,n)}visitFixedNat(t,n){return this.visitNumber(t,n)}visitPrincipal(t,n){return this.visitPrimitive(t,n)}visitConstruct(t,n){return this.visitType(t,n)}visitVec(t,n,r){return this.visitConstruct(t,r)}visitOpt(t,n,r){return this.visitConstruct(t,r)}visitRecord(t,n,r){return this.visitConstruct(t,r)}visitTuple(t,n,r){const i=n.map((s,o)=>[`_${o}_`,s]);return this.visitRecord(t,i,r)}visitVariant(t,n,r){return this.visitConstruct(t,r)}visitRec(t,n,r){return this.visitConstruct(n,r)}visitFunc(t,n){return this.visitConstruct(t,n)}visitService(t,n){return this.visitConstruct(t,n)}}var Te;(function(e){e.EmptyClass="__IDL_EmptyClass__",e.UnknownClass="__IDL_UnknownClass__",e.BoolClass="__IDL_BoolClass__",e.NullClass="__IDL_NullClass__",e.ReservedClass="__IDL_ReservedClass__",e.TextClass="__IDL_TextClass__",e.IntClass="__IDL_IntClass__",e.NatClass="__IDL_NatClass__",e.FloatClass="__IDL_FloatClass__",e.FixedIntClass="__IDL_FixedIntClass__",e.FixedNatClass="__IDL_FixedNatClass__",e.VecClass="__IDL_VecClass__",e.OptClass="__IDL_OptClass__",e.RecordClass="__IDL_RecordClass__",e.TupleClass="__IDL_TupleClass__",e.VariantClass="__IDL_VariantClass__",e.RecClass="__IDL_RecClass__",e.PrincipalClass="__IDL_PrincipalClass__",e.FuncClass="__IDL_FuncClass__",e.ServiceClass="__IDL_ServiceClass__"})(Te||(Te={}));class Ao{display(){return this.name}valueToString(t){return it(t)}buildTypeTable(t){t.has(this)||this._buildTypeTableImpl(t)}}class Qt extends Ao{checkType(t){if(this.name!==t.name)throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);return t}_buildTypeTableImpl(t){}}class pr extends Ao{checkType(t){if(t instanceof en){const n=t.getType();if(typeof n>"u")throw new Error("type mismatch with uninitialized type");return n}throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`)}encodeType(t){return t.indexOf(this.name)}}class Ea extends Qt{get typeName(){return Te.EmptyClass}static[Symbol.hasInstance](t){return t.typeName===Te.EmptyClass}accept(t,n){return t.visitEmpty(this,n)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return ft(Fe.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}}class Bd extends Ao{get typeName(){return Te.UnknownClass}static[Symbol.hasInstance](t){return t.typeName===Te.UnknownClass}checkType(t){throw new Error("Method not implemented for unknown.")}accept(t,n){throw t.visitType(this,n)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(t,n){let r=n.decodeValue(t,n);Object(r)!==r&&(r=Object(r));let i;return n instanceof en?i=()=>n.getType():i=()=>n,Object.defineProperty(r,"type",{value:i,writable:!0,enumerable:!1,configurable:!0}),r}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}}class Ad extends Qt{get typeName(){return Te.BoolClass}static[Symbol.hasInstance](t){return t.typeName===Te.BoolClass}accept(t,n){return t.visitBool(this,n)}covariant(t){if(typeof t=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){return new Uint8Array([t?1:0])}encodeType(){return ft(Fe.Bool)}decodeValue(t,n){switch(this.checkType(n),Hr(t)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}}class ws extends Qt{get typeName(){return Te.NullClass}static[Symbol.hasInstance](t){return t.typeName===Te.NullClass}accept(t,n){return t.visitNull(this,n)}covariant(t){if(t===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return ft(Fe.Null)}decodeValue(t,n){return this.checkType(n),null}get name(){return"null"}}class yr extends Qt{get typeName(){return Te.ReservedClass}static[Symbol.hasInstance](t){return t.typeName===Te.ReservedClass}accept(t,n){return t.visitReserved(this,n)}covariant(t){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return ft(Fe.Reserved)}decodeValue(t,n){return n.name!==this.name&&n.decodeValue(t,n),null}get name(){return"reserved"}}class Id extends Qt{get typeName(){return Te.TextClass}static[Symbol.hasInstance](t){return t.typeName===Te.TextClass}accept(t,n){return t.visitText(this,n)}covariant(t){if(typeof t=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=new TextEncoder().encode(t),r=et(n.byteLength);return He(r,n)}encodeType(){return ft(Fe.Text)}decodeValue(t,n){this.checkType(n);const r=pt(t),i=Ur(t,Number(r));return new TextDecoder("utf8",{fatal:!0}).decode(i)}get name(){return"text"}valueToString(t){return'"'+t+'"'}}class _a extends Qt{get typeName(){return Te.IntClass}static[Symbol.hasInstance](t){return t.typeName===Te.IntClass}accept(t,n){return t.visitInt(this,n)}covariant(t){if(typeof t=="bigint"||Number.isInteger(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){return ft(t)}encodeType(){return ft(Fe.Int)}decodeValue(t,n){return this.checkType(n),hr(t)}get name(){return"int"}valueToString(t){return t.toString()}}class Sa extends Qt{get typeName(){return Te.NatClass}static[Symbol.hasInstance](t){return t.typeName===Te.NatClass}accept(t,n){return t.visitNat(this,n)}covariant(t){if(typeof t=="bigint"&&t>=BigInt(0)||Number.isInteger(t)&&t>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){return et(t)}encodeType(){return ft(Fe.Nat)}decodeValue(t,n){return this.checkType(n),pt(t)}get name(){return"nat"}valueToString(t){return t.toString()}}class xa extends Qt{get typeName(){return Te.FloatClass}static[Symbol.hasInstance](t){return t.typeName===Te.FloatClass}constructor(t){if(super(),this._bits=t,t!==32&&t!==64)throw new Error("not a valid float type")}accept(t,n){return t.visitFloat(this,n)}covariant(t){if(typeof t=="number"||t instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=new ArrayBuffer(this._bits/8),r=new DataView(n);return this._bits===32?r.setFloat32(0,t,!0):r.setFloat64(0,t,!0),new Uint8Array(n)}encodeType(){const t=this._bits===32?Fe.Float32:Fe.Float64;return ft(t)}decodeValue(t,n){this.checkType(n);const r=Ur(t,this._bits/8),i=Wm(r);return this._bits===32?i.getFloat32(0,!0):i.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(t){return t.toString()}}class Fr extends Qt{get typeName(){return Te.FixedIntClass}static[Symbol.hasInstance](t){return t.typeName===Te.FixedIntClass}constructor(t){super(),this._bits=t}accept(t,n){return t.visitFixedInt(this,n)}covariant(t){const n=ba(this._bits-1)*BigInt(-1),r=ba(this._bits-1)-BigInt(1);let i=!1;if(typeof t=="bigint")i=t>=n&&t<=r;else if(Number.isInteger(t)){const s=BigInt(t);i=s>=n&&s<=r}else i=!1;if(i)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){return xd(t,this._bits/8)}encodeType(){const t=Math.log2(this._bits)-3;return ft(-9-t)}decodeValue(t,n){this.checkType(n);const r=Ym(t,this._bits/8);return this._bits<=32?Number(r):r}get name(){return`int${this._bits}`}valueToString(t){return t.toString()}}class mr extends Qt{get typeName(){return Te.FixedNatClass}static[Symbol.hasInstance](t){return t.typeName===Te.FixedNatClass}constructor(t){super(),this._bits=t}accept(t,n){return t.visitFixedNat(this,n)}covariant(t){const n=ba(this._bits);let r=!1;if(typeof t=="bigint"&&t>=BigInt(0)?r=t<n:Number.isInteger(t)&&t>=0?r=BigInt(t)<n:r=!1,r)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){return zm(t,this._bits/8)}encodeType(){const t=Math.log2(this._bits)-3;return ft(-5-t)}decodeValue(t,n){this.checkType(n);const r=Td(t,this._bits/8);return this._bits<=32?Number(r):r}get name(){return`nat${this._bits}`}valueToString(t){return t.toString()}}class mi extends pr{get typeName(){return Te.VecClass}static[Symbol.hasInstance](t){return t.typeName===Te.VecClass}constructor(t){super(),this._type=t,this._blobOptimization=!1,t instanceof mr&&t._bits===8&&(this._blobOptimization=!0)}accept(t,n){return t.visitVec(this,this._type,n)}covariant(t){const n=this._type instanceof mr?this._type._bits:this._type instanceof Fr?this._type._bits:0;if(ArrayBuffer.isView(t)&&n==t.BYTES_PER_ELEMENT*8||Array.isArray(t)&&t.every((r,i)=>{try{return this._type.covariant(r)}catch(s){throw new Error(`Invalid ${this.display()} argument:
13
+
14
+ index ${i} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=et(t.length);if(this._blobOptimization)return He(n,new Uint8Array(t));if(ArrayBuffer.isView(t))if(t instanceof Int16Array||t instanceof Uint16Array){const i=new DataView(new ArrayBuffer(t.length*2));for(let s=0;s<t.length;s++)t instanceof Int16Array?i.setInt16(s*2,t[s],!0):i.setUint16(s*2,t[s],!0);return He(n,new Uint8Array(i.buffer))}else if(t instanceof Int32Array||t instanceof Uint32Array){const i=new DataView(new ArrayBuffer(t.length*4));for(let s=0;s<t.length;s++)t instanceof Int32Array?i.setInt32(s*4,t[s],!0):i.setUint32(s*4,t[s],!0);return He(n,new Uint8Array(i.buffer))}else if(t instanceof BigInt64Array||t instanceof BigUint64Array){const i=new DataView(new ArrayBuffer(t.length*8));for(let s=0;s<t.length;s++)t instanceof BigInt64Array?i.setBigInt64(s*8,t[s],!0):i.setBigUint64(s*8,t[s],!0);return He(n,new Uint8Array(i.buffer))}else return He(n,new Uint8Array(t.buffer,t.byteOffset,t.byteLength));const r=new yi(new Uint8Array(n.byteLength+t.length),0);r.write(n);for(const i of t){const s=this._type.encodeValue(i);r.write(new Uint8Array(s))}return r.buffer}_buildTypeTableImpl(t){this._type.buildTypeTable(t);const n=ft(Fe.Vector),r=this._type.encodeType(t);t.add(this,He(n,r))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof mi))throw new Error("Not a vector type");const i=Number(pt(t));if(this._type instanceof mr){if(this._type._bits==8)return new Uint8Array(t.read(i));if(this._type._bits==16){const o=t.read(i*2);return new Uint16Array(o.buffer,o.byteOffset,i)}if(this._type._bits==32){const o=t.read(i*4);return new Uint32Array(o.buffer,o.byteOffset,i)}if(this._type._bits==64)return new BigUint64Array(t.read(i*8).buffer)}if(this._type instanceof Fr){if(this._type._bits==8)return new Int8Array(t.read(i));if(this._type._bits==16){const o=t.read(i*2),c=new DataView(o.buffer,o.byteOffset,o.byteLength),a=new Int16Array(i);for(let u=0;u<i;u++)a[u]=c.getInt16(u*2,!0);return a}if(this._type._bits==32){const o=t.read(i*4),c=new DataView(o.buffer,o.byteOffset,o.byteLength),a=new Int32Array(i);for(let u=0;u<i;u++)a[u]=c.getInt32(u*4,!0);return a}if(this._type._bits==64){const o=t.read(i*8),c=new DataView(o.buffer,o.byteOffset,o.byteLength),a=new BigInt64Array(i);for(let u=0;u<i;u++)a[u]=c.getBigInt64(u*8,!0);return a}}const s=[];for(let o=0;o<i;o++)s.push(this._type.decodeValue(t,r._type));return s}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(t){return"vec {"+t.map(r=>this._type.valueToString(r)).join("; ")+"}"}}class Cn extends pr{get typeName(){return Te.OptClass}static[Symbol.hasInstance](t){return t.typeName===Te.OptClass}constructor(t){super(),this._type=t}accept(t,n){return t.visitOpt(this,this._type,n)}covariant(t){try{if(Array.isArray(t)&&(t.length===0||t.length===1&&this._type.covariant(t[0])))return!0}catch(n){throw new Error(`Invalid ${this.display()} argument: ${it(t)}
15
+
16
+ -> ${n.message}`)}throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){return t.length===0?new Uint8Array([0]):He(new Uint8Array([1]),this._type.encodeValue(t[0]))}_buildTypeTableImpl(t){this._type.buildTypeTable(t);const n=ft(Fe.Opt),r=this._type.encodeType(t);t.add(this,He(n,r))}decodeValue(t,n){if(n instanceof ws)return[];if(n instanceof yr)return[];let r=n;if(n instanceof en){const i=n.getType();if(typeof i>"u")throw new Error("type mismatch with uninitialized type");r=i}if(r instanceof Cn)switch(Hr(t)){case 0:return[];case 1:{const i=t.save();try{return[this._type.decodeValue(t,r._type)]}catch{return t.restore(i),r._type.decodeValue(t,r._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof ws||this._type instanceof Cn||this._type instanceof yr)return r.decodeValue(t,r),[];{const i=t.save();try{return[this._type.decodeValue(t,n)]}catch{return t.restore(i),r.decodeValue(t,n),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(t){return t.length===0?"null":`opt ${this._type.valueToString(t[0])}`}}class qr extends pr{get typeName(){return Te.RecordClass}static[Symbol.hasInstance](t){return t.typeName===Te.RecordClass||t.typeName===Te.TupleClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((n,r)=>Ft(n[0])-Ft(r[0]))}accept(t,n){return t.visitRecord(this,this._fields,n)}tryAsTuple(){const t=[];for(let n=0;n<this._fields.length;n++){const[r,i]=this._fields[n];if(r!==`_${n}_`)return null;t.push(i)}return t}covariant(t){if(typeof t=="object"&&this._fields.every(([n,r])=>{if(!t.hasOwnProperty(n))throw new Error(`Record is missing key "${n}".`);try{return r.covariant(t[n])}catch(i){throw new Error(`Invalid ${this.display()} argument:
17
+
18
+ field ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=this._fields.map(([i])=>t[i]),r=gs(this._fields,n,([,i],s)=>i.encodeValue(s));return He(...r)}_buildTypeTableImpl(t){this._fields.forEach(([s,o])=>o.buildTypeTable(t));const n=ft(Fe.Record),r=et(this._fields.length),i=this._fields.map(([s,o])=>He(et(Ft(s)),o.encodeType(t)));t.add(this,He(n,r,He(...i)))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof qr))throw new Error("Not a record type");const i={};let s=0,o=0;for(;o<r._fields.length;){const[c,a]=r._fields[o];if(s>=this._fields.length){a.decodeValue(t,a),o++;continue}const[u,l]=this._fields[s],h=Ft(this._fields[s][0]),y=Ft(c);if(h===y)i[u]=l.decodeValue(t,a),s++,o++;else if(y>h)if(l instanceof Cn||l instanceof yr)i[u]=[],s++;else throw new Error("Cannot find required field "+u);else a.decodeValue(t,a),o++}for(const[c,a]of this._fields.slice(s))if(a instanceof Cn||a instanceof yr)i[c]=[];else throw new Error("Cannot find required field "+c);return i}get fieldsAsObject(){const t={};for(const[n,r]of this._fields)t[Ft(n)]=r;return t}get name(){return`record {${this._fields.map(([n,r])=>n+":"+r.name).join("; ")}}`}display(){return`record {${this._fields.map(([n,r])=>n+":"+r.display()).join("; ")}}`}valueToString(t){const n=this._fields.map(([i])=>t[i]);return`record {${gs(this._fields,n,([i,s],o)=>i+"="+s.valueToString(o)).join("; ")}}`}}class Io extends qr{get typeName(){return Te.TupleClass}static[Symbol.hasInstance](t){return t.typeName===Te.TupleClass}constructor(t){const n={};t.forEach((r,i)=>n["_"+i+"_"]=r),super(n),this._components=t}accept(t,n){return t.visitTuple(this,this._components,n)}covariant(t){if(Array.isArray(t)&&t.length>=this._fields.length&&this._components.every((n,r)=>{try{return n.covariant(t[r])}catch(i){throw new Error(`Invalid ${this.display()} argument:
19
+
20
+ index ${r} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=gs(this._components,t,(r,i)=>r.encodeValue(i));return He(...n)}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof Io))throw new Error("not a tuple type");if(r._components.length<this._components.length)throw new Error("tuple mismatch");const i=[];for(const[s,o]of r._components.entries())s>=this._components.length?o.decodeValue(t,o):i.push(this._components[s].decodeValue(t,o));return i}display(){return`record {${this._components.map(n=>n.display()).join("; ")}}`}valueToString(t){return`record {${gs(this._components,t,(r,i)=>r.valueToString(i)).join("; ")}}`}}class gi extends pr{get typeName(){return Te.VariantClass}static[Symbol.hasInstance](t){return t.typeName===Te.VariantClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((n,r)=>Ft(n[0])-Ft(r[0]))}accept(t,n){return t.visitVariant(this,this._fields,n)}covariant(t){if(typeof t=="object"&&Object.entries(t).length===1&&this._fields.every(([n,r])=>{try{return!t.hasOwnProperty(n)||r.covariant(t[n])}catch(i){throw new Error(`Invalid ${this.display()} argument:
21
+
22
+ variant ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){for(let n=0;n<this._fields.length;n++){const[r,i]=this._fields[n];if(t.hasOwnProperty(r)){const s=et(n),o=i.encodeValue(t[r]);return He(s,o)}}throw Error("Variant has no data: "+t)}_buildTypeTableImpl(t){this._fields.forEach(([,s])=>{s.buildTypeTable(t)});const n=ft(Fe.Variant),r=et(this._fields.length),i=this._fields.map(([s,o])=>He(et(Ft(s)),o.encodeType(t)));t.add(this,He(n,r,...i))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof gi))throw new Error("Not a variant type");const i=Number(pt(t));if(i>=r._fields.length)throw Error("Invalid variant index: "+i);const[s,o]=r._fields[i];for(const[c,a]of this._fields)if(Ft(s)===Ft(c)){const u=a.decodeValue(t,o);return{[c]:u}}throw new Error("Cannot find field hash "+s)}get name(){return`variant {${this._fields.map(([n,r])=>n+":"+r.name).join("; ")}}`}display(){return`variant {${this._fields.map(([n,r])=>n+(r.name==="null"?"":`:${r.display()}`)).join("; ")}}`}valueToString(t){for(const[n,r]of this._fields)if(t.hasOwnProperty(n)){const i=r.valueToString(t[n]);return i==="null"?`variant {${n}}`:`variant {${n}=${i}}`}throw new Error("Variant has no data: "+t)}get alternativesAsObject(){const t={};for(const[n,r]of this._fields)t[Ft(n)]=r;return t}}const Cc=class Cc extends pr{constructor(){super(...arguments),this._id=Cc._counter++}get typeName(){return Te.RecClass}static[Symbol.hasInstance](t){return t.typeName===Te.RecClass}accept(t,n){if(!this._type)throw Error("Recursive type uninitialized.");return t.visitRec(this,this._type,n)}fill(t){this._type=t}getType(){return this._type}covariant(t){if(this._type&&this._type.covariant(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(t)}_buildTypeTableImpl(t){if(!this._type)throw Error("Recursive type uninitialized.");t.add(this,new Uint8Array([])),this._type.buildTypeTable(t),t.merge(this,this._type.name)}decodeValue(t,n){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(t,n)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`μ${this.name}.${this._type.name}`}valueToString(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(t)}};Cc._counter=0;let en=Cc;function Ta(e){if(Hr(e)!==1)throw new Error("Cannot decode principal");const n=Number(pt(e));return Le.fromUint8Array(new Uint8Array(Ur(e,n)))}class Od extends Qt{get typeName(){return Te.PrincipalClass}static[Symbol.hasInstance](t){return t.typeName===Te.PrincipalClass}accept(t,n){return t.visitPrincipal(this,n)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=t.toUint8Array(),r=et(n.byteLength);return He(new Uint8Array([1]),r,n)}encodeType(){return ft(Fe.Principal)}decodeValue(t,n){return this.checkType(n),Ta(t)}get name(){return"principal"}valueToString(t){return`${this.name} "${t.toText()}"`}}class bs extends pr{get typeName(){return Te.FuncClass}static[Symbol.hasInstance](t){return t.typeName===Te.FuncClass}static argsToString(t,n){if(t.length!==n.length)throw new Error("arity mismatch");return"("+t.map((r,i)=>r.valueToString(n[i])).join(", ")+")"}constructor(t,n,r=[]){super(),this.argTypes=t,this.retTypes=n,this.annotations=r}accept(t,n){return t.visitFunc(this,n)}covariant(t){if(Array.isArray(t)&&t.length===2&&t[0]&&t[0]._isPrincipal&&typeof t[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue([t,n]){const r=t.toUint8Array(),i=et(r.byteLength),s=He(new Uint8Array([1]),i,r),o=new TextEncoder().encode(n),c=et(o.byteLength);return He(new Uint8Array([1]),s,c,o)}_buildTypeTableImpl(t){this.argTypes.forEach(u=>u.buildTypeTable(t)),this.retTypes.forEach(u=>u.buildTypeTable(t));const n=ft(Fe.Func),r=et(this.argTypes.length),i=He(...this.argTypes.map(u=>u.encodeType(t))),s=et(this.retTypes.length),o=He(...this.retTypes.map(u=>u.encodeType(t))),c=et(this.annotations.length),a=He(...this.annotations.map(u=>this.encodeAnnotation(u)));t.add(this,He(n,r,i,s,o,c,a))}decodeValue(t,n){const r=n instanceof en?n.getType()??n:n;if(!Ia(r,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${r.display()}`);if(Hr(t)!==1)throw new Error("Cannot decode function reference");const s=Ta(t),o=Number(pt(t)),c=Ur(t,o),u=new TextDecoder("utf8",{fatal:!0}).decode(c);return[s,u]}get name(){const t=this.argTypes.map(i=>i.name).join(", "),n=this.retTypes.map(i=>i.name).join(", "),r=" "+this.annotations.join(" ");return`(${t}) -> (${n})${r}`}valueToString([t,n]){return`func "${t.toText()}".${n}`}display(){const t=this.argTypes.map(i=>i.display()).join(", "),n=this.retTypes.map(i=>i.display()).join(", "),r=" "+this.annotations.join(" ");return`(${t}) → (${n})${r}`}encodeAnnotation(t){if(t==="query")return new Uint8Array([1]);if(t==="oneway")return new Uint8Array([2]);if(t==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}}class Oo extends pr{get typeName(){return Te.ServiceClass}static[Symbol.hasInstance](t){return t.typeName===Te.ServiceClass}constructor(t){super(),this._fields=Object.entries(t).sort((n,r)=>n[0]<r[0]?-1:n[0]>r[0]?1:0)}accept(t,n){return t.visitService(this,n)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${it(t)}`)}encodeValue(t){const n=t.toUint8Array(),r=et(n.length);return He(new Uint8Array([1]),r,n)}_buildTypeTableImpl(t){this._fields.forEach(([s,o])=>o.buildTypeTable(t));const n=ft(Fe.Service),r=et(this._fields.length),i=this._fields.map(([s,o])=>{const c=new TextEncoder().encode(s),a=et(c.length);return He(a,c,o.encodeType(t))});t.add(this,He(n,r,...i))}decodeValue(t,n){const r=n instanceof en?n.getType()??n:n;if(!Ia(r,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${r.display()}`);return Ta(t)}get name(){return`service {${this._fields.map(([n,r])=>n+":"+r.name).join("; ")}}`}valueToString(t){return`service "${t.toText()}"`}fieldsAsObject(){const t={};for(const[n,r]of this._fields)t[n]=r;return t}}function it(e){const t=JSON.stringify(e,(n,r)=>typeof r=="bigint"?`BigInt(${r})`:r);return t&&t.length>vd?t.substring(0,vd-3)+"...":t}function va(e,t){if(t.length<e.length)throw Error("Wrong number of message arguments");const n=new Zm;e.forEach(a=>a.buildTypeTable(n));const r=new TextEncoder().encode(Bo),i=n.encode(),s=et(t.length),o=He(...e.map(a=>a.encodeType(n))),c=He(...gs(e,t,(a,u)=>{try{a.covariant(u)}catch(l){throw new Error(l.message+`
23
+
24
+ `)}return a.encodeValue(u)}));return He(r,i,s,o,c)}function Nd(e,t){const n=new yi(t);if(t.byteLength<Bo.length)throw new Error("Message length smaller than magic number");const r=Ur(n,Bo.length),i=new TextDecoder().decode(r);if(i!==Bo)throw new Error("Wrong magic number: "+JSON.stringify(i));function s(y){const p=[],m=Number(pt(y));for(let x=0;x<m;x++){const _=Number(hr(y));switch(_){case Fe.Opt:case Fe.Vector:{const w=Number(hr(y));p.push([_,w]);break}case Fe.Record:case Fe.Variant:{const w=[];let T=Number(pt(y)),R;for(;T--;){const B=Number(pt(y));if(B>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof R=="number"&&R>=B)throw new Error("field id collision or not sorted");R=B;const P=Number(hr(y));w.push([B,P])}p.push([_,w]);break}case Fe.Func:{const w=[];let T=Number(pt(y));for(;T--;)w.push(Number(hr(y)));const R=[];let B=Number(pt(y));for(;B--;)R.push(Number(hr(y)));const P=[];let q=Number(pt(y));for(;q--;)switch(Number(pt(y))){case 1:{P.push("query");break}case 2:{P.push("oneway");break}case 3:{P.push("composite_query");break}default:throw new Error("unknown annotation")}p.push([_,[w,R,P]]);break}case Fe.Service:{let w=Number(pt(y));const T=[];for(;w--;){const R=Number(pt(y)),B=new TextDecoder().decode(Ur(y,R)),P=hr(y);T.push([B,P])}p.push([_,T]);break}default:throw new Error("Illegal op_code: "+_)}}const g=[],E=Number(pt(y));for(let x=0;x<E;x++)g.push(Number(hr(y)));return[p,g]}const[o,c]=s(n);if(c.length<e.length)throw new Error("Wrong number of return values");const a=o.map(y=>eh());function u(y){if(y<-24)throw new Error("future value not supported");if(y<0)switch(y){case-1:return Cd;case-2:return Pd;case-3:return Fd;case-4:return Hd;case-5:return $d;case-6:return Kd;case-7:return Gd;case-8:return Wd;case-9:return Ld;case-10:return Vd;case-11:return Dd;case-12:return jd;case-13:return qd;case-14:return Md;case-15:return Ud;case-16:return kd;case-17:return Rd;case-24:return Xd;default:throw new Error("Illegal op_code: "+y)}if(y>=o.length)throw new Error("type index out of range");return a[y]}function l(y){switch(y[0]){case Fe.Vector:{const p=u(y[1]);return Yd(p)}case Fe.Opt:{const p=u(y[1]);return Zd(p)}case Fe.Record:{const p={};for(const[E,x]of y[1]){const _=`_${E}_`;p[_]=u(x)}const m=Jd(p),g=m.tryAsTuple();return Array.isArray(g)?zd(...g):m}case Fe.Variant:{const p={};for(const[m,g]of y[1]){const E=`_${m}_`;p[E]=u(g)}return Qd(p)}case Fe.Func:{const[p,m,g]=y[1];return th(p.map(E=>u(E)),m.map(E=>u(E)),g)}case Fe.Service:{const p={},m=y[1];for(const[g,E]of m){let x=u(E);if(x instanceof en&&(x=x.getType()),!(x instanceof bs))throw new Error("Illegal service definition: services can only contain functions");p[g]=x}return nh(p)}default:throw new Error("Illegal op_code: "+y[0])}}o.forEach((y,p)=>{if(y[0]===Fe.Func){const m=l(y);a[p].fill(m)}}),o.forEach((y,p)=>{if(y[0]!==Fe.Func){const m=l(y);a[p].fill(m)}}),Ba();const h=c.map(y=>u(y));try{const y=e.map((p,m)=>p.decodeValue(n,h[m]));for(let p=e.length;p<h.length;p++)h[p].decodeValue(n,h[p]);if(n.byteLength>0)throw new Error("decode: Left-over bytes");return y}finally{Ba()}}const Rd=new Ea,kd=new yr,Qm=new Bd,Pd=new Ad,Cd=new ws,Ud=new Id,Hd=new _a,Fd=new Sa,qd=new xa(32),Md=new xa(64),Ld=new Fr(8),Vd=new Fr(16),Dd=new Fr(32),jd=new Fr(64),$d=new mr(8),Kd=new mr(16),Gd=new mr(32),Wd=new mr(64),Xd=new Od;function zd(...e){return new Io(e)}function Yd(e){return new mi(e)}function Zd(e){return new Cn(e)}function Jd(e){return new qr(e)}function Qd(e){return new gi(e)}function eh(){return new en}function th(e,t,n=[]){return new bs(e,t,n)}function nh(e){return new Oo(e)}class No{constructor(t=new Map){this.rels=t}copy(){const t=new Map;for(const[n,r]of this.rels.entries()){const i=new Map(r);t.set(n,i)}return new No(t)}known(t,n){return this.rels.get(t.name)?.get(n.name)}addNegative(t,n){this.addNames(t.name,n.name,!1)}add(t,n){this.addNames(t.name,n.name,!0)}display(){let t="";for(const[n,r]of this.rels)for(const[i,s]of r)t+=`${n} ${s?":<":"!<:"} ${i}
25
+ `;return t}addNames(t,n,r){const i=this.rels.get(t);if(i==null){const s=new Map;s.set(n,r),this.rels.set(t,s)}else i.set(n,r)}}let Ro=new No;function Ba(){Ro=new No}function eg(e,t){const n=new Set(e.annotations),r=new Set(t.annotations);if(n.size!==r.size)return!1;for(const i of n)if(!r.has(i))return!1;return!0}function Aa(e){return e instanceof Cn||e instanceof ws||e instanceof yr}function Ia(e,t){const n=Ro.copy(),r=Un(n,e,t);return r?Ro.add(e,t):Ro.addNegative(e,t),r}function Un(e,t,n){if(t.name===n.name)return!0;const r=e.known(t,n);if(r!==void 0)return r;if(e.add(t,n),n instanceof yr||t instanceof Ea||t instanceof Sa&&n instanceof _a)return!0;if(t instanceof mi&&n instanceof mi)return Un(e,t._type,n._type);if(n instanceof Cn)return!0;if(t instanceof qr&&n instanceof qr){const i=t.fieldsAsObject;for(const[s,o]of n._fields){const c=i[Ft(s)];if(c){if(!Un(e,c,o))return!1}else if(!Aa(o))return!1}return!0}if(t instanceof bs&&n instanceof bs){if(!eg(t,n))return!1;for(let i=0;i<t.argTypes.length;i++){const s=t.argTypes[i];if(i<n.argTypes.length){if(!Un(e,n.argTypes[i],s))return!1}else if(!Aa(s))return!1}for(let i=0;i<n.retTypes.length;i++){const s=n.retTypes[i];if(i<t.retTypes.length){if(!Un(e,t.retTypes[i],s))return!1}else if(!Aa(s))return!1}return!0}if(t instanceof gi&&n instanceof gi){const i=n.alternativesAsObject;for(const[s,o]of t._fields){const c=i[Ft(s)];if(!c||!Un(e,o,c))return!1}return!0}if(t instanceof Oo&&n instanceof Oo){const i=t.fieldsAsObject();for(const[s,o]of n._fields){const c=i[s];if(!c||!Un(e,c,o))return!1}return!0}return t instanceof en?Un(e,t.getType(),n):n instanceof en?Un(e,t,n.getType()):!1}const tg=Object.freeze(Object.defineProperty({__proto__:null,Bool:Pd,BoolClass:Ad,ConstructType:pr,Empty:Rd,EmptyClass:Ea,FixedIntClass:Fr,FixedNatClass:mr,Float32:qd,Float64:Md,FloatClass:xa,Func:th,FuncClass:bs,Int:Hd,Int16:Vd,Int32:Dd,Int64:jd,Int8:Ld,IntClass:_a,Nat:Fd,Nat16:Kd,Nat32:Gd,Nat64:Wd,Nat8:$d,NatClass:Sa,Null:Cd,NullClass:ws,Opt:Zd,OptClass:Cn,PrimitiveType:Qt,Principal:Xd,PrincipalClass:Od,Rec:eh,RecClass:en,Record:Jd,RecordClass:qr,Reserved:kd,ReservedClass:yr,Service:nh,ServiceClass:Oo,Text:Ud,TextClass:Id,Tuple:zd,TupleClass:Io,Type:Ao,Unknown:Qm,UnknownClass:Bd,Variant:Qd,VariantClass:gi,Vec:Yd,VecClass:mi,Visitor:Jm,decode:Nd,encode:va,resetSubtypeCache:Ba,subtype:Ia},Symbol.toStringTag,{value:"Module"}));function rh(e,t){return function(){return e.apply(t,arguments)}}const{toString:ng}=Object.prototype,{getPrototypeOf:Oa}=Object,{iterator:ko,toStringTag:ih}=Symbol,Po=(e=>t=>{const n=ng.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),un=e=>(e=e.toLowerCase(),t=>Po(t)===e),Co=e=>t=>typeof t===e,{isArray:wi}=Array,Es=Co("undefined");function _s(e){return e!==null&&!Es(e)&&e.constructor!==null&&!Es(e.constructor)&&qt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const sh=un("ArrayBuffer");function rg(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&sh(e.buffer),t}const ig=Co("string"),qt=Co("function"),oh=Co("number"),Ss=e=>e!==null&&typeof e=="object",sg=e=>e===!0||e===!1,Uo=e=>{if(Po(e)!=="object")return!1;const t=Oa(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ih in e)&&!(ko in e)},og=e=>{if(!Ss(e)||_s(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},cg=un("Date"),ag=un("File"),ug=un("Blob"),fg=un("FileList"),lg=e=>Ss(e)&&qt(e.pipe),dg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||qt(e.append)&&((t=Po(e))==="formdata"||t==="object"&&qt(e.toString)&&e.toString()==="[object FormData]"))},hg=un("URLSearchParams"),[pg,yg,mg,gg]=["ReadableStream","Request","Response","Headers"].map(un),wg=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function xs(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,i;if(typeof e!="object"&&(e=[e]),wi(e))for(r=0,i=e.length;r<i;r++)t.call(null,e[r],r,e);else{if(_s(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),o=s.length;let c;for(r=0;r<o;r++)c=s[r],t.call(null,e[c],c,e)}}function ch(e,t){if(_s(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,i;for(;r-- >0;)if(i=n[r],t===i.toLowerCase())return i;return null}const Mr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ah=e=>!Es(e)&&e!==Mr;function Na(){const{caseless:e}=ah(this)&&this||{},t={},n=(r,i)=>{const s=e&&ch(t,i)||i;Uo(t[s])&&Uo(r)?t[s]=Na(t[s],r):Uo(r)?t[s]=Na({},r):wi(r)?t[s]=r.slice():t[s]=r};for(let r=0,i=arguments.length;r<i;r++)arguments[r]&&xs(arguments[r],n);return t}const bg=(e,t,n,{allOwnKeys:r}={})=>(xs(t,(i,s)=>{n&&qt(i)?e[s]=rh(i,n):e[s]=i},{allOwnKeys:r}),e),Eg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),_g=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Sg=(e,t,n,r)=>{let i,s,o;const c={};if(t=t||{},e==null)return t;do{for(i=Object.getOwnPropertyNames(e),s=i.length;s-- >0;)o=i[s],(!r||r(o,e,t))&&!c[o]&&(t[o]=e[o],c[o]=!0);e=n!==!1&&Oa(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},xg=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Tg=e=>{if(!e)return null;if(wi(e))return e;let t=e.length;if(!oh(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},vg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Oa(Uint8Array)),Bg=(e,t)=>{const r=(e&&e[ko]).call(e);let i;for(;(i=r.next())&&!i.done;){const s=i.value;t.call(e,s[0],s[1])}},Ag=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Ig=un("HTMLFormElement"),Og=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,i){return r.toUpperCase()+i}),uh=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Ng=un("RegExp"),fh=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};xs(n,(i,s)=>{let o;(o=t(i,s,e))!==!1&&(r[s]=o||i)}),Object.defineProperties(e,r)},Rg=e=>{fh(e,(t,n)=>{if(qt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(qt(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},kg=(e,t)=>{const n={},r=i=>{i.forEach(s=>{n[s]=!0})};return wi(e)?r(e):r(String(e).split(t)),n},Pg=()=>{},Cg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Ug(e){return!!(e&&qt(e.append)&&e[ih]==="FormData"&&e[ko])}const Hg=e=>{const t=new Array(10),n=(r,i)=>{if(Ss(r)){if(t.indexOf(r)>=0)return;if(_s(r))return r;if(!("toJSON"in r)){t[i]=r;const s=wi(r)?[]:{};return xs(r,(o,c)=>{const a=n(o,i+1);!Es(a)&&(s[c]=a)}),t[i]=void 0,s}}return r};return n(e,0)},Fg=un("AsyncFunction"),qg=e=>e&&(Ss(e)||qt(e))&&qt(e.then)&&qt(e.catch),lh=((e,t)=>e?setImmediate:t?((n,r)=>(Mr.addEventListener("message",({source:i,data:s})=>{i===Mr&&s===n&&r.length&&r.shift()()},!1),i=>{r.push(i),Mr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",qt(Mr.postMessage)),Mg=typeof queueMicrotask<"u"?queueMicrotask.bind(Mr):typeof process<"u"&&process.nextTick||lh,z={isArray:wi,isArrayBuffer:sh,isBuffer:_s,isFormData:dg,isArrayBufferView:rg,isString:ig,isNumber:oh,isBoolean:sg,isObject:Ss,isPlainObject:Uo,isEmptyObject:og,isReadableStream:pg,isRequest:yg,isResponse:mg,isHeaders:gg,isUndefined:Es,isDate:cg,isFile:ag,isBlob:ug,isRegExp:Ng,isFunction:qt,isStream:lg,isURLSearchParams:hg,isTypedArray:vg,isFileList:fg,forEach:xs,merge:Na,extend:bg,trim:wg,stripBOM:Eg,inherits:_g,toFlatObject:Sg,kindOf:Po,kindOfTest:un,endsWith:xg,toArray:Tg,forEachEntry:Bg,matchAll:Ag,isHTMLForm:Ig,hasOwnProperty:uh,hasOwnProp:uh,reduceDescriptors:fh,freezeMethods:Rg,toObjectSet:kg,toCamelCase:Og,noop:Pg,toFiniteNumber:Cg,findKey:ch,global:Mr,isContextDefined:ah,isSpecCompliantForm:Ug,toJSONObject:Hg,isAsyncFn:Fg,isThenable:qg,setImmediate:lh,asap:Mg,isIterable:e=>e!=null&&qt(e[ko])};function Be(e,t,n,r,i){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),i&&(this.response=i,this.status=i.status?i.status:null)}z.inherits(Be,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:z.toJSONObject(this.config),code:this.code,status:this.status}}});const dh=Be.prototype,hh={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{hh[e]={value:e}}),Object.defineProperties(Be,hh),Object.defineProperty(dh,"isAxiosError",{value:!0}),Be.from=(e,t,n,r,i,s)=>{const o=Object.create(dh);return z.toFlatObject(e,o,function(a){return a!==Error.prototype},c=>c!=="isAxiosError"),Be.call(o,e.message,t,n,r,i),o.cause=e,o.name=e.name,s&&Object.assign(o,s),o};const Lg=null;function Ra(e){return z.isPlainObject(e)||z.isArray(e)}function ph(e){return z.endsWith(e,"[]")?e.slice(0,-2):e}function yh(e,t,n){return e?e.concat(t).map(function(i,s){return i=ph(i),!n&&s?"["+i+"]":i}).join(n?".":""):t}function Vg(e){return z.isArray(e)&&!e.some(Ra)}const Dg=z.toFlatObject(z,{},null,function(t){return/^is[A-Z]/.test(t)});function Ho(e,t,n){if(!z.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=z.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,E){return!z.isUndefined(E[g])});const r=n.metaTokens,i=n.visitor||l,s=n.dots,o=n.indexes,a=(n.Blob||typeof Blob<"u"&&Blob)&&z.isSpecCompliantForm(t);if(!z.isFunction(i))throw new TypeError("visitor must be a function");function u(m){if(m===null)return"";if(z.isDate(m))return m.toISOString();if(z.isBoolean(m))return m.toString();if(!a&&z.isBlob(m))throw new Be("Blob is not supported. Use a Buffer instead.");return z.isArrayBuffer(m)||z.isTypedArray(m)?a&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function l(m,g,E){let x=m;if(m&&!E&&typeof m=="object"){if(z.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(z.isArray(m)&&Vg(m)||(z.isFileList(m)||z.endsWith(g,"[]"))&&(x=z.toArray(m)))return g=ph(g),x.forEach(function(w,T){!(z.isUndefined(w)||w===null)&&t.append(o===!0?yh([g],T,s):o===null?g:g+"[]",u(w))}),!1}return Ra(m)?!0:(t.append(yh(E,g,s),u(m)),!1)}const h=[],y=Object.assign(Dg,{defaultVisitor:l,convertValue:u,isVisitable:Ra});function p(m,g){if(!z.isUndefined(m)){if(h.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));h.push(m),z.forEach(m,function(x,_){(!(z.isUndefined(x)||x===null)&&i.call(t,x,z.isString(_)?_.trim():_,g,y))===!0&&p(x,g?g.concat(_):[_])}),h.pop()}}if(!z.isObject(e))throw new TypeError("data must be an object");return p(e),t}function mh(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ka(e,t){this._pairs=[],e&&Ho(e,this,t)}const gh=ka.prototype;gh.append=function(t,n){this._pairs.push([t,n])},gh.toString=function(t){const n=t?function(r){return t.call(this,r,mh)}:mh;return this._pairs.map(function(i){return n(i[0])+"="+n(i[1])},"").join("&")};function jg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function wh(e,t,n){if(!t)return e;const r=n&&n.encode||jg;z.isFunction(n)&&(n={serialize:n});const i=n&&n.serialize;let s;if(i?s=i(t,n):s=z.isURLSearchParams(t)?t.toString():new ka(t,n).toString(r),s){const o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class bh{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){z.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Eh={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},$g={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ka,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Pa=typeof window<"u"&&typeof document<"u",Ca=typeof navigator=="object"&&navigator||void 0,Kg=Pa&&(!Ca||["ReactNative","NativeScript","NS"].indexOf(Ca.product)<0),Gg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Wg=Pa&&window.location.href||"http://localhost",It={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Pa,hasStandardBrowserEnv:Kg,hasStandardBrowserWebWorkerEnv:Gg,navigator:Ca,origin:Wg},Symbol.toStringTag,{value:"Module"})),...$g};function Xg(e,t){return Ho(e,new It.classes.URLSearchParams,{visitor:function(n,r,i,s){return It.isNode&&z.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function zg(e){return z.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Yg(e){const t={},n=Object.keys(e);let r;const i=n.length;let s;for(r=0;r<i;r++)s=n[r],t[s]=e[s];return t}function _h(e){function t(n,r,i,s){let o=n[s++];if(o==="__proto__")return!0;const c=Number.isFinite(+o),a=s>=n.length;return o=!o&&z.isArray(i)?i.length:o,a?(z.hasOwnProp(i,o)?i[o]=[i[o],r]:i[o]=r,!c):((!i[o]||!z.isObject(i[o]))&&(i[o]=[]),t(n,r,i[o],s)&&z.isArray(i[o])&&(i[o]=Yg(i[o])),!c)}if(z.isFormData(e)&&z.isFunction(e.entries)){const n={};return z.forEachEntry(e,(r,i)=>{t(zg(r),i,n,0)}),n}return null}function Zg(e,t,n){if(z.isString(e))try{return(t||JSON.parse)(e),z.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Ts={transitional:Eh,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",i=r.indexOf("application/json")>-1,s=z.isObject(t);if(s&&z.isHTMLForm(t)&&(t=new FormData(t)),z.isFormData(t))return i?JSON.stringify(_h(t)):t;if(z.isArrayBuffer(t)||z.isBuffer(t)||z.isStream(t)||z.isFile(t)||z.isBlob(t)||z.isReadableStream(t))return t;if(z.isArrayBufferView(t))return t.buffer;if(z.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Xg(t,this.formSerializer).toString();if((c=z.isFileList(t))||r.indexOf("multipart/form-data")>-1){const a=this.env&&this.env.FormData;return Ho(c?{"files[]":t}:t,a&&new a,this.formSerializer)}}return s||i?(n.setContentType("application/json",!1),Zg(t)):t}],transformResponse:[function(t){const n=this.transitional||Ts.transitional,r=n&&n.forcedJSONParsing,i=this.responseType==="json";if(z.isResponse(t)||z.isReadableStream(t))return t;if(t&&z.isString(t)&&(r&&!this.responseType||i)){const o=!(n&&n.silentJSONParsing)&&i;try{return JSON.parse(t)}catch(c){if(o)throw c.name==="SyntaxError"?Be.from(c,Be.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:It.classes.FormData,Blob:It.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};z.forEach(["delete","get","head","post","put","patch"],e=>{Ts.headers[e]={}});const Jg=z.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Qg=e=>{const t={};let n,r,i;return e&&e.split(`
26
+ `).forEach(function(o){i=o.indexOf(":"),n=o.substring(0,i).trim().toLowerCase(),r=o.substring(i+1).trim(),!(!n||t[n]&&Jg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Sh=Symbol("internals");function vs(e){return e&&String(e).trim().toLowerCase()}function Fo(e){return e===!1||e==null?e:z.isArray(e)?e.map(Fo):String(e)}function e1(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const t1=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Ua(e,t,n,r,i){if(z.isFunction(r))return r.call(this,t,n);if(i&&(t=n),!!z.isString(t)){if(z.isString(r))return t.indexOf(r)!==-1;if(z.isRegExp(r))return r.test(t)}}function n1(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function r1(e,t){const n=z.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(i,s,o){return this[r].call(this,t,i,s,o)},configurable:!0})})}let Mt=class{constructor(t){t&&this.set(t)}set(t,n,r){const i=this;function s(c,a,u){const l=vs(a);if(!l)throw new Error("header name must be a non-empty string");const h=z.findKey(i,l);(!h||i[h]===void 0||u===!0||u===void 0&&i[h]!==!1)&&(i[h||a]=Fo(c))}const o=(c,a)=>z.forEach(c,(u,l)=>s(u,l,a));if(z.isPlainObject(t)||t instanceof this.constructor)o(t,n);else if(z.isString(t)&&(t=t.trim())&&!t1(t))o(Qg(t),n);else if(z.isObject(t)&&z.isIterable(t)){let c={},a,u;for(const l of t){if(!z.isArray(l))throw TypeError("Object iterator must return a key-value pair");c[u=l[0]]=(a=c[u])?z.isArray(a)?[...a,l[1]]:[a,l[1]]:l[1]}o(c,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=vs(t),t){const r=z.findKey(this,t);if(r){const i=this[r];if(!n)return i;if(n===!0)return e1(i);if(z.isFunction(n))return n.call(this,i,r);if(z.isRegExp(n))return n.exec(i);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=vs(t),t){const r=z.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Ua(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let i=!1;function s(o){if(o=vs(o),o){const c=z.findKey(r,o);c&&(!n||Ua(r,r[c],c,n))&&(delete r[c],i=!0)}}return z.isArray(t)?t.forEach(s):s(t),i}clear(t){const n=Object.keys(this);let r=n.length,i=!1;for(;r--;){const s=n[r];(!t||Ua(this,this[s],s,t,!0))&&(delete this[s],i=!0)}return i}normalize(t){const n=this,r={};return z.forEach(this,(i,s)=>{const o=z.findKey(r,s);if(o){n[o]=Fo(i),delete n[s];return}const c=t?n1(s):String(s).trim();c!==s&&delete n[s],n[c]=Fo(i),r[c]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return z.forEach(this,(r,i)=>{r!=null&&r!==!1&&(n[i]=t&&z.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
27
+ `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(i=>r.set(i)),r}static accessor(t){const r=(this[Sh]=this[Sh]={accessors:{}}).accessors,i=this.prototype;function s(o){const c=vs(o);r[c]||(r1(i,o),r[c]=!0)}return z.isArray(t)?t.forEach(s):s(t),this}};Mt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),z.reduceDescriptors(Mt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),z.freezeMethods(Mt);function Ha(e,t){const n=this||Ts,r=t||n,i=Mt.from(r.headers);let s=r.data;return z.forEach(e,function(c){s=c.call(n,s,i.normalize(),t?t.status:void 0)}),i.normalize(),s}function xh(e){return!!(e&&e.__CANCEL__)}function bi(e,t,n){Be.call(this,e??"canceled",Be.ERR_CANCELED,t,n),this.name="CanceledError"}z.inherits(bi,Be,{__CANCEL__:!0});function Th(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Be("Request failed with status code "+n.status,[Be.ERR_BAD_REQUEST,Be.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function i1(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function s1(e,t){e=e||10;const n=new Array(e),r=new Array(e);let i=0,s=0,o;return t=t!==void 0?t:1e3,function(a){const u=Date.now(),l=r[s];o||(o=u),n[i]=a,r[i]=u;let h=s,y=0;for(;h!==i;)y+=n[h++],h=h%e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const p=l&&u-l;return p?Math.round(y*1e3/p):void 0}}function o1(e,t){let n=0,r=1e3/t,i,s;const o=(u,l=Date.now())=>{n=l,i=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const l=Date.now(),h=l-n;h>=r?o(u,l):(i=u,s||(s=setTimeout(()=>{s=null,o(i)},r-h)))},()=>i&&o(i)]}const qo=(e,t,n=3)=>{let r=0;const i=s1(50,250);return o1(s=>{const o=s.loaded,c=s.lengthComputable?s.total:void 0,a=o-r,u=i(a),l=o<=c;r=o;const h={loaded:o,total:c,progress:c?o/c:void 0,bytes:a,rate:u||void 0,estimated:u&&c&&l?(c-o)/u:void 0,event:s,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(h)},n)},vh=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Bh=e=>(...t)=>z.asap(()=>e(...t)),c1=It.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,It.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(It.origin),It.navigator&&/(msie|trident)/i.test(It.navigator.userAgent)):()=>!0,a1=It.hasStandardBrowserEnv?{write(e,t,n,r,i,s){const o=[e+"="+encodeURIComponent(t)];z.isNumber(n)&&o.push("expires="+new Date(n).toGMTString()),z.isString(r)&&o.push("path="+r),z.isString(i)&&o.push("domain="+i),s===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function u1(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function f1(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Ah(e,t,n){let r=!u1(t);return e&&(r||n==!1)?f1(e,t):t}const Ih=e=>e instanceof Mt?{...e}:e;function Lr(e,t){t=t||{};const n={};function r(u,l,h,y){return z.isPlainObject(u)&&z.isPlainObject(l)?z.merge.call({caseless:y},u,l):z.isPlainObject(l)?z.merge({},l):z.isArray(l)?l.slice():l}function i(u,l,h,y){if(z.isUndefined(l)){if(!z.isUndefined(u))return r(void 0,u,h,y)}else return r(u,l,h,y)}function s(u,l){if(!z.isUndefined(l))return r(void 0,l)}function o(u,l){if(z.isUndefined(l)){if(!z.isUndefined(u))return r(void 0,u)}else return r(void 0,l)}function c(u,l,h){if(h in t)return r(u,l);if(h in e)return r(void 0,u)}const a={url:s,method:s,data:s,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:c,headers:(u,l,h)=>i(Ih(u),Ih(l),h,!0)};return z.forEach(Object.keys({...e,...t}),function(l){const h=a[l]||i,y=h(e[l],t[l],l);z.isUndefined(y)&&h!==c||(n[l]=y)}),n}const Oh=e=>{const t=Lr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:i,xsrfCookieName:s,headers:o,auth:c}=t;t.headers=o=Mt.from(o),t.url=wh(Ah(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&o.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let a;if(z.isFormData(n)){if(It.hasStandardBrowserEnv||It.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((a=o.getContentType())!==!1){const[u,...l]=a?a.split(";").map(h=>h.trim()).filter(Boolean):[];o.setContentType([u||"multipart/form-data",...l].join("; "))}}if(It.hasStandardBrowserEnv&&(r&&z.isFunction(r)&&(r=r(t)),r||r!==!1&&c1(t.url))){const u=i&&s&&a1.read(s);u&&o.set(i,u)}return t},l1=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const i=Oh(e);let s=i.data;const o=Mt.from(i.headers).normalize();let{responseType:c,onUploadProgress:a,onDownloadProgress:u}=i,l,h,y,p,m;function g(){p&&p(),m&&m(),i.cancelToken&&i.cancelToken.unsubscribe(l),i.signal&&i.signal.removeEventListener("abort",l)}let E=new XMLHttpRequest;E.open(i.method.toUpperCase(),i.url,!0),E.timeout=i.timeout;function x(){if(!E)return;const w=Mt.from("getAllResponseHeaders"in E&&E.getAllResponseHeaders()),R={data:!c||c==="text"||c==="json"?E.responseText:E.response,status:E.status,statusText:E.statusText,headers:w,config:e,request:E};Th(function(P){n(P),g()},function(P){r(P),g()},R),E=null}"onloadend"in E?E.onloadend=x:E.onreadystatechange=function(){!E||E.readyState!==4||E.status===0&&!(E.responseURL&&E.responseURL.indexOf("file:")===0)||setTimeout(x)},E.onabort=function(){E&&(r(new Be("Request aborted",Be.ECONNABORTED,e,E)),E=null)},E.onerror=function(){r(new Be("Network Error",Be.ERR_NETWORK,e,E)),E=null},E.ontimeout=function(){let T=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const R=i.transitional||Eh;i.timeoutErrorMessage&&(T=i.timeoutErrorMessage),r(new Be(T,R.clarifyTimeoutError?Be.ETIMEDOUT:Be.ECONNABORTED,e,E)),E=null},s===void 0&&o.setContentType(null),"setRequestHeader"in E&&z.forEach(o.toJSON(),function(T,R){E.setRequestHeader(R,T)}),z.isUndefined(i.withCredentials)||(E.withCredentials=!!i.withCredentials),c&&c!=="json"&&(E.responseType=i.responseType),u&&([y,m]=qo(u,!0),E.addEventListener("progress",y)),a&&E.upload&&([h,p]=qo(a),E.upload.addEventListener("progress",h),E.upload.addEventListener("loadend",p)),(i.cancelToken||i.signal)&&(l=w=>{E&&(r(!w||w.type?new bi(null,e,E):w),E.abort(),E=null)},i.cancelToken&&i.cancelToken.subscribe(l),i.signal&&(i.signal.aborted?l():i.signal.addEventListener("abort",l)));const _=i1(i.url);if(_&&It.protocols.indexOf(_)===-1){r(new Be("Unsupported protocol "+_+":",Be.ERR_BAD_REQUEST,e));return}E.send(s||null)})},d1=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,i;const s=function(u){if(!i){i=!0,c();const l=u instanceof Error?u:this.reason;r.abort(l instanceof Be?l:new bi(l instanceof Error?l.message:l))}};let o=t&&setTimeout(()=>{o=null,s(new Be(`timeout ${t} of ms exceeded`,Be.ETIMEDOUT))},t);const c=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:a}=r;return a.unsubscribe=()=>z.asap(c),a}},h1=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,i;for(;r<n;)i=r+t,yield e.slice(r,i),r=i},p1=async function*(e,t){for await(const n of y1(e))yield*h1(n,t)},y1=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Nh=(e,t,n,r)=>{const i=p1(e,t);let s=0,o,c=a=>{o||(o=!0,r&&r(a))};return new ReadableStream({async pull(a){try{const{done:u,value:l}=await i.next();if(u){c(),a.close();return}let h=l.byteLength;if(n){let y=s+=h;n(y)}a.enqueue(new Uint8Array(l))}catch(u){throw c(u),u}},cancel(a){return c(a),i.return()}},{highWaterMark:2})},Mo=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Rh=Mo&&typeof ReadableStream=="function",m1=Mo&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),kh=(e,...t)=>{try{return!!e(...t)}catch{return!1}},g1=Rh&&kh(()=>{let e=!1;const t=new Request(It.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Ph=64*1024,Fa=Rh&&kh(()=>z.isReadableStream(new Response("").body)),Lo={stream:Fa&&(e=>e.body)};Mo&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!Lo[t]&&(Lo[t]=z.isFunction(e[t])?n=>n[t]():(n,r)=>{throw new Be(`Response type '${t}' is not supported`,Be.ERR_NOT_SUPPORT,r)})})})(new Response);const w1=async e=>{if(e==null)return 0;if(z.isBlob(e))return e.size;if(z.isSpecCompliantForm(e))return(await new Request(It.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(z.isArrayBufferView(e)||z.isArrayBuffer(e))return e.byteLength;if(z.isURLSearchParams(e)&&(e=e+""),z.isString(e))return(await m1(e)).byteLength},b1=async(e,t)=>{const n=z.toFiniteNumber(e.getContentLength());return n??w1(t)},qa={http:Lg,xhr:l1,fetch:Mo&&(async e=>{let{url:t,method:n,data:r,signal:i,cancelToken:s,timeout:o,onDownloadProgress:c,onUploadProgress:a,responseType:u,headers:l,withCredentials:h="same-origin",fetchOptions:y}=Oh(e);u=u?(u+"").toLowerCase():"text";let p=d1([i,s&&s.toAbortSignal()],o),m;const g=p&&p.unsubscribe&&(()=>{p.unsubscribe()});let E;try{if(a&&g1&&n!=="get"&&n!=="head"&&(E=await b1(l,r))!==0){let R=new Request(t,{method:"POST",body:r,duplex:"half"}),B;if(z.isFormData(r)&&(B=R.headers.get("content-type"))&&l.setContentType(B),R.body){const[P,q]=vh(E,qo(Bh(a)));r=Nh(R.body,Ph,P,q)}}z.isString(h)||(h=h?"include":"omit");const x="credentials"in Request.prototype;m=new Request(t,{...y,signal:p,method:n.toUpperCase(),headers:l.normalize().toJSON(),body:r,duplex:"half",credentials:x?h:void 0});let _=await fetch(m,y);const w=Fa&&(u==="stream"||u==="response");if(Fa&&(c||w&&g)){const R={};["status","statusText","headers"].forEach(v=>{R[v]=_[v]});const B=z.toFiniteNumber(_.headers.get("content-length")),[P,q]=c&&vh(B,qo(Bh(c),!0))||[];_=new Response(Nh(_.body,Ph,P,()=>{q&&q(),g&&g()}),R)}u=u||"text";let T=await Lo[z.findKey(Lo,u)||"text"](_,e);return!w&&g&&g(),await new Promise((R,B)=>{Th(R,B,{data:T,headers:Mt.from(_.headers),status:_.status,statusText:_.statusText,config:e,request:m})})}catch(x){throw g&&g(),x&&x.name==="TypeError"&&/Load failed|fetch/i.test(x.message)?Object.assign(new Be("Network Error",Be.ERR_NETWORK,e,m),{cause:x.cause||x}):Be.from(x,x&&x.code,e,m)}})};z.forEach(qa,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ch=e=>`- ${e}`,E1=e=>z.isFunction(e)||e===null||e===!1,Uh={getAdapter:e=>{e=z.isArray(e)?e:[e];const{length:t}=e;let n,r;const i={};for(let s=0;s<t;s++){n=e[s];let o;if(r=n,!E1(n)&&(r=qa[(o=String(n)).toLowerCase()],r===void 0))throw new Be(`Unknown adapter '${o}'`);if(r)break;i[o||"#"+s]=r}if(!r){const s=Object.entries(i).map(([c,a])=>`adapter ${c} `+(a===!1?"is not supported by the environment":"is not available in the build"));let o=t?s.length>1?`since :
28
+ `+s.map(Ch).join(`
29
+ `):" "+Ch(s[0]):"as no adapter specified";throw new Be("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return r},adapters:qa};function Ma(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new bi(null,e)}function Hh(e){return Ma(e),e.headers=Mt.from(e.headers),e.data=Ha.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Uh.getAdapter(e.adapter||Ts.adapter)(e).then(function(r){return Ma(e),r.data=Ha.call(e,e.transformResponse,r),r.headers=Mt.from(r.headers),r},function(r){return xh(r)||(Ma(e),r&&r.response&&(r.response.data=Ha.call(e,e.transformResponse,r.response),r.response.headers=Mt.from(r.response.headers))),Promise.reject(r)})}const Fh="1.11.0",Vo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Vo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const qh={};Vo.transitional=function(t,n,r){function i(s,o){return"[Axios v"+Fh+"] Transitional option '"+s+"'"+o+(r?". "+r:"")}return(s,o,c)=>{if(t===!1)throw new Be(i(o," has been removed"+(n?" in "+n:"")),Be.ERR_DEPRECATED);return n&&!qh[o]&&(qh[o]=!0,console.warn(i(o," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,o,c):!0}},Vo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function _1(e,t,n){if(typeof e!="object")throw new Be("options must be an object",Be.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let i=r.length;for(;i-- >0;){const s=r[i],o=t[s];if(o){const c=e[s],a=c===void 0||o(c,s,e);if(a!==!0)throw new Be("option "+s+" must be "+a,Be.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Be("Unknown option "+s,Be.ERR_BAD_OPTION)}}const Do={assertOptions:_1,validators:Vo},En=Do.validators;let Vr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new bh,response:new bh}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const s=i.stack?i.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
30
+ `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Lr(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&Do.assertOptions(r,{silentJSONParsing:En.transitional(En.boolean),forcedJSONParsing:En.transitional(En.boolean),clarifyTimeoutError:En.transitional(En.boolean)},!1),i!=null&&(z.isFunction(i)?n.paramsSerializer={serialize:i}:Do.assertOptions(i,{encode:En.function,serialize:En.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Do.assertOptions(n,{baseUrl:En.spelling("baseURL"),withXsrfToken:En.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&z.merge(s.common,s[n.method]);s&&z.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Mt.concat(o,s);const c=[];let a=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(a=a&&g.synchronous,c.unshift(g.fulfilled,g.rejected))});const u=[];this.interceptors.response.forEach(function(g){u.push(g.fulfilled,g.rejected)});let l,h=0,y;if(!a){const m=[Hh.bind(this),void 0];for(m.unshift(...c),m.push(...u),y=m.length,l=Promise.resolve(n);h<y;)l=l.then(m[h++],m[h++]);return l}y=c.length;let p=n;for(h=0;h<y;){const m=c[h++],g=c[h++];try{p=m(p)}catch(E){g.call(this,E);break}}try{l=Hh.call(this,p)}catch(m){return Promise.reject(m)}for(h=0,y=u.length;h<y;)l=l.then(u[h++],u[h++]);return l}getUri(t){t=Lr(this.defaults,t);const n=Ah(t.baseURL,t.url,t.allowAbsoluteUrls);return wh(n,t.params,t.paramsSerializer)}};z.forEach(["delete","get","head","options"],function(t){Vr.prototype[t]=function(n,r){return this.request(Lr(r||{},{method:t,url:n,data:(r||{}).data}))}}),z.forEach(["post","put","patch"],function(t){function n(r){return function(s,o,c){return this.request(Lr(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Vr.prototype[t]=n(),Vr.prototype[t+"Form"]=n(!0)});let S1=class dy{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(c=>{r.subscribe(c),s=c}).then(i);return o.cancel=function(){r.unsubscribe(s)},o},t(function(s,o,c){r.reason||(r.reason=new bi(s,o,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new dy(function(i){t=i}),cancel:t}}};function x1(e){return function(n){return e.apply(null,n)}}function T1(e){return z.isObject(e)&&e.isAxiosError===!0}const La={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(La).forEach(([e,t])=>{La[t]=e});function Mh(e){const t=new Vr(e),n=rh(Vr.prototype.request,t);return z.extend(n,Vr.prototype,t,{allOwnKeys:!0}),z.extend(n,t,null,{allOwnKeys:!0}),n.create=function(i){return Mh(Lr(e,i))},n}const st=Mh(Ts);st.Axios=Vr,st.CanceledError=bi,st.CancelToken=S1,st.isCancel=xh,st.VERSION=Fh,st.toFormData=Ho,st.AxiosError=Be,st.Cancel=st.CanceledError,st.all=function(t){return Promise.all(t)},st.spread=x1,st.isAxiosError=T1,st.mergeConfig=Lr,st.AxiosHeaders=Mt,st.formToJSON=e=>_h(z.isHTMLForm(e)?new FormData(e):e),st.getAdapter=Uh.getAdapter,st.HttpStatusCode=La,st.default=st;const{Axios:R_,AxiosError:k_,CanceledError:P_,isCancel:C_,CancelToken:U_,VERSION:H_,all:F_,Cancel:q_,isAxiosError:M_,spread:L_,toFormData:V_,AxiosHeaders:D_,HttpStatusCode:j_,formToJSON:$_,getAdapter:K_,mergeConfig:G_}=st;class v1{axios;constructor(t){this.axios=st.create({baseURL:t.baseUrl,headers:{Accept:"application/json","Content-Type":"application/json","api-key":`${t.apiKey}`}})}async utxosByAddress(t,n){return await this.axios.get(`/addresses/${t}/utxos?filter_dust=true&filter_dust_threshold=547&exclude_metaprotocols=true&order=asc&count=100${n?`&cursor=${n}`:""}`).then(i=>i.data)}async inscriptionsByAddress(t,n){return await this.axios.get(`/addresses/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(i=>i.data)}async inscriptionIdsByCollectionSymbol(t,n){return await this.axios.get(`/assets/collections/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(i=>i.data)}async runeUtxosByAddress(t,n,r){return await this.axios.get(`/addresses/${t}/runes/utxos?order_by=height&order=asc&count=100&rune=${n}${r?`&cursor=${r}`:""}`).then(s=>s.data)}}var Lh;(function(e){e[e.SysFatal=1]="SysFatal",e[e.SysTransient=2]="SysTransient",e[e.DestinationInvalid=3]="DestinationInvalid",e[e.CanisterReject=4]="CanisterReject",e[e.CanisterError=5]="CanisterError"})(Lh||(Lh={}));var Ei;(function(e){e.Replied="replied",e.Rejected="rejected"})(Ei||(Ei={}));function B1(e){return e!=null&&"reject_code"in e}function A1(e){return e!=null&&"certificate"in e}var Hn;(function(e){e.Trust="Trust",e.Protocol="Protocol",e.Reject="Reject",e.Transport="Transport",e.External="External",e.Limit="Limit",e.Input="Input",e.Unknown="Unknown"})(Hn||(Hn={}));class Re{constructor(t=!1){this.isCertified=t}toString(){let t=this.toErrorMessage();return this.requestContext&&(t+=`
31
+ Request context:
32
+ Request ID (hex): ${this.requestContext.requestId?ze(this.requestContext.requestId):"undefined"}
33
+ Sender pubkey (hex): ${ze(this.requestContext.senderPubKey)}
34
+ Sender signature (hex): ${ze(this.requestContext.senderSignature)}
35
+ Ingress expiry: ${this.requestContext.ingressExpiry.toString()}`),this.callContext&&(t+=`
36
+ Call context:
37
+ Canister ID: ${this.callContext.canisterId.toText()}
38
+ Method name: ${this.callContext.methodName}
39
+ HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),t}}class Fn extends Error{get code(){return this.cause.code}set code(t){this.cause.code=t}get kind(){return this.cause.kind}set kind(t){this.cause.kind=t}get isCertified(){return this.code.isCertified}constructor(t,n){super(t.toString()),this.name="AgentError",this.cause={code:t,kind:n},Object.setPrototypeOf(this,Fn.prototype)}hasCode(t){return this.code instanceof t}toString(){return`${this.name} (${this.kind}): ${this.message}`}}class Dr extends Fn{static fromCode(t){return new this(t)}}class tn extends Dr{constructor(t){super(t,Hn.Trust),this.name="TrustError",Object.setPrototypeOf(this,tn.prototype)}}class ot extends Dr{constructor(t){super(t,Hn.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,ot.prototype)}}class _i extends Dr{constructor(t){super(t,Hn.Reject),this.name="RejectError",Object.setPrototypeOf(this,_i.prototype)}}class jo extends Dr{constructor(t){super(t,Hn.Transport),this.name="TransportError",Object.setPrototypeOf(this,jo.prototype)}}class Lt extends Dr{constructor(t){super(t,Hn.External),this.name="ExternalError",Object.setPrototypeOf(this,Lt.prototype)}}class Xe extends Dr{constructor(t){super(t,Hn.Input),this.name="InputError",Object.setPrototypeOf(this,Xe.prototype)}}class Vt extends Dr{constructor(t){super(t,Hn.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,Vt.prototype)}}class Si extends Re{constructor(t,n){super(),this.reason=t,this.error=n,this.name="CertificateVerificationErrorCode",Object.setPrototypeOf(this,Si.prototype)}toErrorMessage(){let t=this.reason;return this.error&&(t+=`: ${Ns(this.error)}`),`Certificate verification error: "${t}"`}}class Bs extends Re{constructor(t,n,r,i,s){super(),this.maxAgeInMinutes=t,this.certificateTime=n,this.currentTime=r,this.timeDiffMsecs=i,this.ageType=s,this.name="CertificateTimeErrorCode",Object.setPrototypeOf(this,Bs.prototype)}toErrorMessage(){return`Certificate is signed more than ${this.maxAgeInMinutes} minutes in the ${this.ageType}. Certificate time: ${this.certificateTime.toISOString()} Current time: ${this.currentTime.toISOString()} Clock drift: ${this.timeDiffMsecs}ms`}}class Va extends Re{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,Va.prototype)}toErrorMessage(){return"Certificate has too many delegations"}}class $o extends Re{constructor(t,n){super(),this.canisterId=t,this.subnetId=n,this.name="CertificateNotAuthorizedErrorCode",Object.setPrototypeOf(this,$o.prototype)}toErrorMessage(){return`The certificate contains a delegation that does not include the canister ${this.canisterId.toText()} in the canister_ranges field. Subnet ID: ${this.subnetId.toText()}`}}class xi extends Re{constructor(t,n){super(),this.message=t,this.lookupStatus=n,this.name="LookupErrorCode",Object.setPrototypeOf(this,xi.prototype)}toErrorMessage(){return`${this.message}. Lookup status: ${this.lookupStatus}`}}class Ko extends Re{constructor(t){super(),this.message=t,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,Ko.prototype)}toErrorMessage(){return this.message}}class Da extends Re{constructor(t){super(),this.message=t,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,Da.prototype)}toErrorMessage(){return this.message}}class Go extends Re{constructor(t,n){super(),this.expectedLength=t,this.actualLength=n,this.name="DerKeyLengthMismatchErrorCode",Object.setPrototypeOf(this,Go.prototype)}toErrorMessage(){return`BLS DER-encoded public key must be ${this.expectedLength} bytes long, but is ${this.actualLength} bytes long`}}class ja extends Re{constructor(t,n){super(),this.expectedPrefix=t,this.actualPrefix=n,this.name="DerPrefixMismatchErrorCode",Object.setPrototypeOf(this,ja.prototype)}toErrorMessage(){return`BLS DER-encoded public key is invalid. Expected the following prefix: ${ze(this.expectedPrefix)}, but got ${ze(this.actualPrefix)}`}}class $a extends Re{constructor(t,n){super(),this.expectedLength=t,this.actualLength=n,this.name="DerDecodeLengthMismatchErrorCode",Object.setPrototypeOf(this,$a.prototype)}toErrorMessage(){return`DER payload mismatch: Expected length ${this.expectedLength}, actual length: ${this.actualLength}`}}class qn extends Re{constructor(t){super(),this.error=t,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,qn.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}}class Wo extends Re{constructor(t){super(),this.error=t,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,Wo.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}}class Ka extends Re{constructor(t,n){super(),this.error=t,this.input=n,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,Ka.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${Ns(this.error)}, input: ${ze(this.input)}`}}class Ga extends Re{constructor(t,n){super(),this.error=t,this.value=n,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,Ga.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${Ns(this.error)}, input: ${this.value}`}}class As extends Re{constructor(t,n,r){super(),this.message=t,this.requestId=n,this.status=r,this.name="TimeoutWaitingForResponseErrorCode",Object.setPrototypeOf(this,As.prototype)}toErrorMessage(){let t=`${this.message}
40
+ `;return this.requestId&&(t+=` Request ID: ${ze(this.requestId)}
41
+ `),this.status&&(t+=` Request status: ${this.status}
42
+ `),t}}class Wa extends Re{constructor(t,n,r){super(),this.maxIngressExpiryInMinutes=t,this.requestId=n,this.retryTimes=r,this.name="CertificateOutdatedErrorCode",Object.setPrototypeOf(this,Wa.prototype)}toErrorMessage(){let t=`Certificate is stale (over ${this.maxIngressExpiryInMinutes} minutes). Is the computer's clock synchronized?
43
+ Request ID: ${ze(this.requestId)}
44
+ `;return this.retryTimes!==void 0&&(t+=` Retried ${this.retryTimes} times.`),t}}class Xo extends Re{constructor(t,n,r,i){super(!0),this.requestId=t,this.rejectCode=n,this.rejectMessage=r,this.rejectErrorCode=i,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,Xo.prototype)}toErrorMessage(){return`The replica returned a rejection error:
45
+ Request ID: ${ze(this.requestId)}
46
+ Reject code: ${this.rejectCode}
47
+ Reject text: ${this.rejectMessage}
48
+ Error code: ${this.rejectErrorCode}
49
+ `}}class Xa extends Re{constructor(t,n,r,i,s){super(),this.requestId=t,this.rejectCode=n,this.rejectMessage=r,this.rejectErrorCode=i,this.signatures=s,this.name="UncertifiedRejectErrorCode",Object.setPrototypeOf(this,Xa.prototype)}toErrorMessage(){return`The replica returned a rejection error:
50
+ Request ID: ${ze(this.requestId)}
51
+ Reject code: ${this.rejectCode}
52
+ Reject text: ${this.rejectMessage}
53
+ Error code: ${this.rejectErrorCode}
54
+ `}}class za extends Re{constructor(t,n,r,i){super(),this.requestId=t,this.rejectCode=n,this.rejectMessage=r,this.rejectErrorCode=i,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,za.prototype)}toErrorMessage(){return`The replica returned a rejection error:
55
+ Request ID: ${ze(this.requestId)}
56
+ Reject code: ${this.rejectCode}
57
+ Reject text: ${this.rejectMessage}
58
+ Error code: ${this.rejectErrorCode}
59
+ `}}class Ya extends Re{constructor(t){super(),this.requestId=t,this.name="RequestStatusDoneNoReplyErrorCode",Object.setPrototypeOf(this,Ya.prototype)}toErrorMessage(){return`Call was marked as done but we never saw the reply:
60
+ Request ID: ${ze(this.requestId)}
61
+ `}}class Ti extends Re{constructor(t){super(),this.shouldFetchRootKey=t,this.name="MissingRootKeyErrorCode",Object.setPrototypeOf(this,Ti.prototype)}toErrorMessage(){return this.shouldFetchRootKey===void 0?"Agent is missing root key":`Agent is missing root key and the shouldFetchRootKey value is set to ${this.shouldFetchRootKey}. The root key should only be unknown if you are in local development. Otherwise you should avoid fetching and use the default IC Root Key or the known root key of your environment.`}}class Za extends Re{constructor(t){super(),this.value=t,this.name="HashValueErrorCode",Object.setPrototypeOf(this,Za.prototype)}toErrorMessage(){return`Attempt to hash a value of unsupported type: ${this.value}`}}class Is extends Re{constructor(t){super(),this.error=t,this.name="HttpDefaultFetchErrorCode",Object.setPrototypeOf(this,Is.prototype)}toErrorMessage(){return this.error}}class jr extends Re{constructor(){super(),this.name="IdentityInvalidErrorCode",Object.setPrototypeOf(this,jr.prototype)}toErrorMessage(){return"This identity has expired due this application's security policy. Please refresh your authentication."}}class vi extends Re{constructor(t,n){super(),this.message=t,this.providedIngressExpiryInMinutes=n,this.name="IngressExpiryInvalidErrorCode",Object.setPrototypeOf(this,vi.prototype)}toErrorMessage(){return`${this.message}. Provided ingress expiry time is ${this.providedIngressExpiryInMinutes} minutes.`}}class Ja extends Re{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,Ja.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}}class Qa extends Re{constructor(t){super(),this.error=t,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,Qa.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}}class eu extends Re{constructor(){super(),this.name="MissingSignatureErrorCode",Object.setPrototypeOf(this,eu.prototype)}toErrorMessage(){return"Query response did not contain any node signatures"}}class tu extends Re{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,tu.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}}class nu extends Re{constructor(t){super(),this.nodeId=t,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,nu.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}}class fn extends Re{constructor(t){super(),this.error=t,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,fn.prototype)}toErrorMessage(){return`Unexpected error: ${Ns(this.error)}`}}class Os extends Re{constructor(t){super(),this.error=t,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,Os.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}}class zo extends Re{constructor(t,n,r,i){super(),this.status=t,this.statusText=n,this.headers=r,this.bodyText=i,this.name="HttpErrorCode",Object.setPrototypeOf(this,zo.prototype)}toErrorMessage(){let t=`HTTP request failed:
62
+ Status: ${this.status} (${this.statusText})
63
+ Headers: ${JSON.stringify(this.headers)}
64
+ `;return this.bodyText&&(t+=` Body: ${this.bodyText}
65
+ `),t}}class Yo extends Re{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,Yo.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}}class Zo extends Re{constructor(t){super(),this.error=t,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,Zo.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${Ns(this.error)}`}}class Jo extends Re{constructor(t){super(),this.receivedCanisterId=t,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,Jo.prototype)}toErrorMessage(){return`Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`}}class ru extends Re{constructor(t){super(),this.request=t,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,ru.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}}class Qo extends Re{constructor(t){super(),this.error=t,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,Qo.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}}function Ns(e){if(e instanceof Error)return e.stack??e.message;try{return JSON.stringify(e)}catch{return String(e)}}const Bi=new Error("unreachable");function ec(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?ec(e.buffer):new Uint8Array(e)}function tc(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function iu(e){if(typeof e=="string")return Vh(e);if(typeof e=="number")return Jt(et(e));if(e instanceof Uint8Array||ArrayBuffer.isView(e))return Jt(ec(e));if(Array.isArray(e)){const t=e.map(iu);return Jt(qe(...t))}else{if(e&&typeof e=="object"&&e._isPrincipal)return Jt(e.toUint8Array());if(typeof e=="object"&&e!==null&&typeof e.toHash=="function")return iu(e.toHash());if(typeof e=="object")return nc(e);if(typeof e=="bigint")return Jt(et(e))}throw Xe.fromCode(new Za(e))}const Vh=e=>{const t=new TextEncoder().encode(e);return Jt(t)};function su(e){return nc(e)}function nc(e){const r=Object.entries(e).filter(([,o])=>o!==void 0).map(([o,c])=>{const a=Vh(o),u=iu(c);return[a,u]}).sort(([o],[c])=>Gm(o,c)),i=qe(...r.map(o=>qe(...o)));return Jt(i)}new TextEncoder().encode(`
66
+ ic-request`);const I1=new TextEncoder().encode("\vic-response");new TextEncoder().encode("ic-request-auth-delegation");class Dh{getPrincipal(){return Le.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}}class $r extends Error{constructor(t){super(t),this.name="DecodingError"}}const jh=55799,$h=Symbol("CBOR_STOP_CODE");var ln=(e=>(e[e.False=20]="False",e[e.True=21]="True",e[e.Null=22]="Null",e[e.Undefined=23]="Undefined",e[e.Break=31]="Break",e))(ln||{}),lt=(e=>(e[e.UnsignedInteger=0]="UnsignedInteger",e[e.NegativeInteger=1]="NegativeInteger",e[e.ByteString=2]="ByteString",e[e.TextString=3]="TextString",e[e.Array=4]="Array",e[e.Map=5]="Map",e[e.Tag=6]="Tag",e[e.Simple=7]="Simple",e))(lt||{});const O1=23,N1=255,R1=65535,k1=4294967295,P1=BigInt("0xffffffffffffffff");var dn=(e=>(e[e.Value=23]="Value",e[e.OneByte=24]="OneByte",e[e.TwoBytes=25]="TwoBytes",e[e.FourBytes=26]="FourBytes",e[e.EightBytes=27]="EightBytes",e[e.Indefinite=31]="Indefinite",e))(dn||{});const Ai=!1;function C1(e){return e==null}function Kh(e,t){const n=new Uint8Array(t);return n.set(e),n}const U1=new TextDecoder;function H1(e){return(e&224)>>5}function F1(e){return e&31}let Rs=new Uint8Array,ks,hn=0;function q1(e,t){Rs=e,hn=0;const n=Kr();return t?.(n)??n}function Kr(e){const[t,n]=rc();switch(t){case lt.UnsignedInteger:return Ii(n);case lt.NegativeInteger:return D1(n);case lt.ByteString:return Gh(n);case lt.TextString:return ou(n);case lt.Array:return M1(n);case lt.Map:return V1(n);case lt.Tag:return j1(n);case lt.Simple:return L1(n)}throw new $r(`Unsupported major type: ${t}`)}function rc(){const e=Rs.at(hn);if(C1(e))throw new $r("Provided CBOR data is empty");const t=H1(e),n=F1(e);return hn++,[t,n]}function M1(e,t){const n=Ii(e);if(n===1/0){const i=[];let s=Kr();for(;s!==$h;)i.push(s),s=Kr();return i}const r=new Array(n);for(let i=0;i<n;i++){const s=Kr();r[i]=s}return r}function L1(e){switch(e){case ln.False:return!1;case ln.True:return!0;case ln.Null:return null;case ln.Undefined:return;case ln.Break:return $h}throw new $r(`Unrecognized simple type: ${e.toString(2)}`)}function V1(e,t){const n=Ii(e),r={};if(n===1/0){let[i,s]=rc();for(;i!==lt.Simple&&s!==ln.Break;){const o=ou(s),c=Kr();r[o]=c,[i,s]=rc()}return r}for(let i=0;i<n;i++){const[s,o]=rc();if(s!==lt.TextString)throw new $r("Map keys must be text strings");const c=ou(o),a=Kr();r[c]=a}return r}function Ii(e){if(e<=dn.Value)return e;switch(ks=new DataView(Rs.buffer,Rs.byteOffset+hn),e){case dn.OneByte:return hn++,ks.getUint8(0);case dn.TwoBytes:return hn+=2,ks.getUint16(0,Ai);case dn.FourBytes:return hn+=4,ks.getUint32(0,Ai);case dn.EightBytes:return hn+=8,ks.getBigUint64(0,Ai);case dn.Indefinite:return 1/0;default:throw new $r(`Unsupported integer info: ${e.toString(2)}`)}}function D1(e){const t=Ii(e);return typeof t=="number"?-1-t:-1n-t}function Gh(e){const t=Ii(e);if(t>Number.MAX_SAFE_INTEGER)throw new $r("Byte length is too large");const n=Number(t);return hn+=n,Rs.slice(hn-n,hn)}function ou(e){const t=Gh(e);return U1.decode(t)}function j1(e,t){const n=Ii(e);if(n===jh)return Kr();throw new $r(`Unsupported tag: ${n}.`)}class cu extends Error{constructor(t){super(t),this.name="SerializationError"}}const $1=2*1024,K1=100,G1=new TextEncoder;function Ps(e){return e<<5}let Gt=new Uint8Array($1),pn=new DataView(Gt.buffer),dt=0,au=[];function W1(e,t){dt=0;const n=t?.(e)??e;return tw(jh,n,t),Gt.slice(0,dt)}function uu(e,t){if(dt>Gt.length-K1&&(Gt=Kh(Gt,Gt.length*2),pn=new DataView(Gt.buffer)),e===!1||e===!0||e===null||e===void 0){Y1(e);return}if(typeof e=="number"||typeof e=="bigint"){ew(e);return}if(typeof e=="string"){zh(e);return}if(e instanceof Uint8Array){Yh(e);return}if(e instanceof ArrayBuffer){Yh(new Uint8Array(e));return}if(Array.isArray(e)){X1(e,t);return}if(typeof e=="object"){z1(e,t);return}throw new cu(`Unsupported type: ${typeof e}`)}function X1(e,t){Oi(lt.Array,e.length),e.forEach((n,r)=>{uu(t?.(n,r.toString())??n,t)})}function z1(e,t){au=Object.entries(e),Oi(lt.Map,au.length),au.forEach(([n,r])=>{zh(n),uu(t?.(r,n)??r,t)})}function Oi(e,t){if(t<=O1){pn.setUint8(dt++,Ps(e)|Number(t));return}if(t<=N1){pn.setUint8(dt++,Ps(e)|dn.OneByte),pn.setUint8(dt,Number(t)),dt+=1;return}if(t<=R1){pn.setUint8(dt++,Ps(e)|dn.TwoBytes),pn.setUint16(dt,Number(t),Ai),dt+=2;return}if(t<=k1){pn.setUint8(dt++,Ps(e)|dn.FourBytes),pn.setUint32(dt,Number(t),Ai),dt+=4;return}if(t<=P1){pn.setUint8(dt++,Ps(e)|dn.EightBytes),pn.setBigUint64(dt,BigInt(t),Ai),dt+=8;return}throw new cu(`Value too large to encode: ${t}`)}function Y1(e){Oi(lt.Simple,Z1(e))}function Z1(e){if(e===!1)return ln.False;if(e===!0)return ln.True;if(e===null)return ln.Null;if(e===void 0)return ln.Undefined;throw new cu(`Unrecognized simple value: ${e.toString()}`)}function Wh(e,t){Oi(e,t.length),dt>Gt.length-t.length&&(Gt=Kh(Gt,Gt.length+t.length),pn=new DataView(Gt.buffer)),Gt.set(t,dt),dt+=t.length}function Xh(e,t){Oi(e,t)}function J1(e){Xh(lt.UnsignedInteger,e)}function Q1(e){Xh(lt.NegativeInteger,typeof e=="bigint"?-1n-e:-1-e)}function ew(e){e>=0?J1(e):Q1(e)}function zh(e){Wh(lt.TextString,G1.encode(e))}function Yh(e){Wh(lt.ByteString,e)}function tw(e,t,n){Oi(lt.Tag,e),uu(t,n)}function nw(e){return typeof e=="object"&&e!==null&&"toCborValue"in e}function fu(e){try{return W1(e,t=>Le.isPrincipal(t)?t.toUint8Array():Ni.isExpiry(t)?t.toBigInt():nw(t)?t.toCborValue():t)}catch(t){throw Xe.fromCode(new Ga(t,e))}}function _n(e){try{return q1(e)}catch(t){throw Xe.fromCode(new Ka(t,e))}}const ic=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){const e=new Uint32Array(1);return window.crypto.getRandomValues(e),e[0]}if(typeof crypto<"u"&&crypto.getRandomValues){const e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Gr;(function(e){e.Query="read",e.ReadState="read_state",e.Call="call"})(Gr||(Gr={}));var lu;(function(e){e.Call="call"})(lu||(lu={}));var Cs;(function(e){e.Query="query",e.ReadState="read_state"})(Cs||(Cs={}));function du(){const e=new ArrayBuffer(16),t=new DataView(e),n=ic(),r=ic(),i=ic(),s=ic();return t.setUint32(0,n),t.setUint32(4,r),t.setUint32(8,i),t.setUint32(12,s),Object.assign(new Uint8Array(e),{__nonce__:void 0})}const sc="__expiry__",hu=BigInt(1e3),rw=BigInt(1e6),Zh=BigInt(60),iw=BigInt(90)*hu;function Jh(e){return e/hu}function sw(e){return Jh(e)/Zh}class Ni{constructor(t){this.__expiry__=t,this._isExpiry=!0}static fromDeltaInMilliseconds(t,n=0){const r=BigInt(t),i=BigInt(Date.now())+r+BigInt(n);let s;return r<iw?s=Jh(i):s=sw(i)*Zh,new Ni(s*hu*rw)}toBigInt(){return this.__expiry__}toHash(){return et(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[sc]:this.toString()}}static fromJSON(t){const n=JSON.parse(t);if(n[sc])try{const r=BigInt(n[sc]);return new Ni(r)}catch(r){throw new Xe(new Qo(`Not a valid BigInt: ${r}`))}throw new Xe(new Qo(`The input does not contain the key ${sc}`))}static isExpiry(t){return t instanceof Ni||typeof t=="object"&&t!==null&&"_isExpiry"in t&&t._isExpiry===!0&&"__expiry__"in t&&typeof t.__expiry__=="bigint"}}function Qh(e=du){return async t=>{const n=t.request.headers;t.request.headers=n,t.endpoint===Gr.Call&&(t.body.nonce=e())}}function pu(e){const t=[];return e.forEach((n,r)=>{t.push([r,n])}),t}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const yu=BigInt(0),oc=BigInt(1);function Us(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function Ri(e,t,n=""){const r=ps(e),i=e?.length,s=t!==void 0;if(!r||s&&i!==t){const o=n&&`"${n}" `,c=s?` of length ${t}`:"",a=r?`length=${i}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+c+", got "+a)}return e}function e0(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?yu:BigInt("0x"+e)}function Sn(e){return e0(ze(e))}function Hs(e){return Zt(e),e0(ze(Uint8Array.from(e).reverse()))}function Et(e,t){return ms(e.toString(16).padStart(t*2,"0"))}function t0(e,t){return Et(e,t).reverse()}function Dt(e,t,n){let r;if(typeof t=="string")try{r=ms(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(ps(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(e+" of length "+n+" expected, got "+i);return r}function n0(e){return Uint8Array.from(e)}const mu=e=>typeof e=="bigint"&&yu<=e;function r0(e,t,n){return mu(e)&&mu(t)&&mu(n)&&t<=e&&e<n}function i0(e,t,n,r){if(!r0(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function Fs(e){let t;for(t=0;e>yu;e>>=oc,t+=1);return t}function ow(e,t){return e>>BigInt(t)&oc}const Wr=e=>(oc<<BigInt(e))-oc;function cw(e){return typeof e=="function"&&Number.isSafeInteger(e.outputLen)}function qs(e,t,n={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function r(i,s,o){const c=e[i];if(o&&c===void 0)return;const a=typeof c;if(a!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}const s0=()=>{throw new Error("not implemented")};function Ms(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(i!==void 0)return i;const s=e(n,...r);return t.set(n,s),s}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const jt=BigInt(0),_t=BigInt(1),Xr=BigInt(2),o0=BigInt(3),c0=BigInt(4),a0=BigInt(5),aw=BigInt(7),u0=BigInt(8),uw=BigInt(9),f0=BigInt(16);function ct(e,t){const n=e%t;return n>=jt?n:t+n}function xn(e,t,n){let r=e;for(;t-- >jt;)r*=r,r%=n;return r}function l0(e,t){if(e===jt)throw new Error("invert: expected non-zero number");if(t<=jt)throw new Error("invert: expected positive modulus, got "+t);let n=ct(e,t),r=t,i=jt,s=_t;for(;n!==jt;){const c=r/n,a=r%n,u=i-s*c;r=n,n=a,i=s,s=u}if(r!==_t)throw new Error("invert: does not exist");return ct(i,t)}function gu(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function d0(e,t){const n=(e.ORDER+_t)/c0,r=e.pow(t,n);return gu(e,r,t),r}function fw(e,t){const n=(e.ORDER-a0)/u0,r=e.mul(t,Xr),i=e.pow(r,n),s=e.mul(t,i),o=e.mul(e.mul(s,Xr),i),c=e.mul(s,e.sub(o,e.ONE));return gu(e,c,t),c}function lw(e){const t=gr(e),n=h0(e),r=n(t,t.neg(t.ONE)),i=n(t,r),s=n(t,t.neg(r)),o=(e+aw)/f0;return(c,a)=>{let u=c.pow(a,o),l=c.mul(u,r);const h=c.mul(u,i),y=c.mul(u,s),p=c.eql(c.sqr(l),a),m=c.eql(c.sqr(h),a);u=c.cmov(u,l,p),l=c.cmov(y,h,m);const g=c.eql(c.sqr(l),a),E=c.cmov(u,l,g);return gu(c,E,a),E}}function h0(e){if(e<o0)throw new Error("sqrt is not defined for small field");let t=e-_t,n=0;for(;t%Xr===jt;)t/=Xr,n++;let r=Xr;const i=gr(e);for(;ac(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return d0;let s=i.pow(r,t);const o=(t+_t)/Xr;return function(a,u){if(a.is0(u))return u;if(ac(a,u)!==1)throw new Error("Cannot find square root");let l=n,h=a.mul(a.ONE,s),y=a.pow(u,t),p=a.pow(u,o);for(;!a.eql(y,a.ONE);){if(a.is0(y))return a.ZERO;let m=1,g=a.sqr(y);for(;!a.eql(g,a.ONE);)if(m++,g=a.sqr(g),m===l)throw new Error("Cannot find square root");const E=_t<<BigInt(l-m-1),x=a.pow(h,E);l=m,h=a.sqr(x),y=a.mul(y,h),p=a.mul(p,x)}return p}}function dw(e){return e%c0===o0?d0:e%u0===a0?fw:e%f0===uw?lw(e):h0(e)}const hw=(e,t)=>(ct(e,t)&_t)===_t,pw=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function p0(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=pw.reduce((r,i)=>(r[i]="function",r),t);return qs(e,n),e}function cc(e,t,n){if(n<jt)throw new Error("invalid exponent, negatives unsupported");if(n===jt)return e.ONE;if(n===_t)return t;let r=e.ONE,i=t;for(;n>jt;)n&_t&&(r=e.mul(r,i)),i=e.sqr(i),n>>=_t;return r}function zr(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((o,c,a)=>e.is0(c)?o:(r[a]=o,e.mul(o,c)),e.ONE),s=e.inv(i);return t.reduceRight((o,c,a)=>e.is0(c)?o:(r[a]=e.mul(o,r[a]),e.mul(o,c)),s),r}function ac(e,t){const n=(e.ORDER-_t)/Xr,r=e.pow(t,n),i=e.eql(r,e.ONE),s=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function yw(e,t){t!==void 0&&Sm(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function gr(e,t,n=!1,r={}){if(e<=jt)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,s,o=!1,c;if(typeof t=="object"&&t!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const y=t;y.BITS&&(i=y.BITS),y.sqrt&&(s=y.sqrt),typeof y.isLE=="boolean"&&(n=y.isLE),typeof y.modFromBytes=="boolean"&&(o=y.modFromBytes),c=y.allowedLengths}else typeof t=="number"&&(i=t),r.sqrt&&(s=r.sqrt);const{nBitLength:a,nByteLength:u}=yw(e,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const h=Object.freeze({ORDER:e,isLE:n,BITS:a,BYTES:u,MASK:Wr(a),ZERO:jt,ONE:_t,allowedLengths:c,create:y=>ct(y,e),isValid:y=>{if(typeof y!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof y);return jt<=y&&y<e},is0:y=>y===jt,isValidNot0:y=>!h.is0(y)&&h.isValid(y),isOdd:y=>(y&_t)===_t,neg:y=>ct(-y,e),eql:(y,p)=>y===p,sqr:y=>ct(y*y,e),add:(y,p)=>ct(y+p,e),sub:(y,p)=>ct(y-p,e),mul:(y,p)=>ct(y*p,e),pow:(y,p)=>cc(h,y,p),div:(y,p)=>ct(y*l0(p,e),e),sqrN:y=>y*y,addN:(y,p)=>y+p,subN:(y,p)=>y-p,mulN:(y,p)=>y*p,inv:y=>l0(y,e),sqrt:s||(y=>(l||(l=dw(e)),l(h,y))),toBytes:y=>n?t0(y,u):Et(y,u),fromBytes:(y,p=!0)=>{if(c){if(!c.includes(y.length)||y.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+y.length);const g=new Uint8Array(u);g.set(y,n?0:g.length-y.length),y=g}if(y.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+y.length);let m=n?Hs(y):Sn(y);if(o&&(m=ct(m,e)),!p&&!h.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:y=>zr(h,y),cmov:(y,p,m)=>m?p:y});return Object.freeze(h)}function y0(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function m0(e){const t=y0(e);return t+Math.ceil(t/2)}function mw(e,t,n=!1){const r=e.length,i=y0(t),s=m0(t);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Hs(e):Sn(e),c=ct(o,t-_t)+_t;return n?t0(c,i):Et(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ki=BigInt(0),Yr=BigInt(1);function uc(e,t){const n=t.negate();return e?n:t}function Mn(e,t){const n=zr(e.Fp,t.map(r=>r.Z));return t.map((r,i)=>e.fromAffine(r.toAffine(n[i])))}function g0(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function wu(e,t){g0(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e,s=Wr(e),o=BigInt(e);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function w0(e,t,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let c=Number(e&i),a=e>>o;c>r&&(c-=s,a+=Yr);const u=t*r,l=u+Math.abs(c)-1,h=c===0,y=c<0,p=t%2!==0;return{nextN:a,offset:l,isZero:h,isNeg:y,isNegF:p,offsetF:u}}function gw(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((n,r)=>{if(!(n instanceof t))throw new Error("invalid point at index "+r)})}function ww(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,r)=>{if(!t.isValid(n))throw new Error("invalid scalar at index "+r)})}const bu=new WeakMap,b0=new WeakMap;function Eu(e){return b0.get(e)||1}function E0(e){if(e!==ki)throw new Error("invalid wNAF")}class _0{constructor(t,n){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=n}_unsafeLadder(t,n,r=this.ZERO){let i=t;for(;n>ki;)n&Yr&&(r=r.add(i)),i=i.double(),n>>=Yr;return r}precomputeWindow(t,n){const{windows:r,windowSize:i}=wu(n,this.bits),s=[];let o=t,c=o;for(let a=0;a<r;a++){c=o,s.push(c);for(let u=1;u<i;u++)c=c.add(o),s.push(c);o=c.double()}return s}wNAF(t,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=wu(t,this.bits);for(let c=0;c<o.windows;c++){const{nextN:a,offset:u,isZero:l,isNeg:h,isNegF:y,offsetF:p}=w0(r,c,o);r=a,l?s=s.add(uc(y,n[p])):i=i.add(uc(h,n[u]))}return E0(r),{p:i,f:s}}wNAFUnsafe(t,n,r,i=this.ZERO){const s=wu(t,this.bits);for(let o=0;o<s.windows&&r!==ki;o++){const{nextN:c,offset:a,isZero:u,isNeg:l}=w0(r,o,s);if(r=c,!u){const h=n[a];i=i.add(l?h.negate():h)}}return E0(r),i}getPrecomputes(t,n,r){let i=bu.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof r=="function"&&(i=r(i)),bu.set(n,i))),i}cached(t,n,r){const i=Eu(t);return this.wNAF(i,this.getPrecomputes(i,t,r),n)}unsafe(t,n,r,i){const s=Eu(t);return s===1?this._unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,r),n,i)}createCache(t,n){g0(n,this.bits),b0.set(t,n),bu.delete(t)}hasCache(t){return Eu(t)!==1}}function bw(e,t,n,r){let i=t,s=e.ZERO,o=e.ZERO;for(;n>ki||r>ki;)n&Yr&&(s=s.add(i)),r&Yr&&(o=o.add(i)),i=i.double(),n>>=Yr,r>>=Yr;return{p1:s,p2:o}}function S0(e,t,n,r){gw(n,e),ww(r,t);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=e.ZERO,c=Fs(BigInt(i));let a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);const u=Wr(a),l=new Array(Number(u)+1).fill(o),h=Math.floor((t.BITS-1)/a)*a;let y=o;for(let p=h;p>=0;p-=a){l.fill(o);for(let g=0;g<s;g++){const E=r[g],x=Number(E>>BigInt(p)&u);l[x]=l[x].add(n[g])}let m=o;for(let g=l.length-1,E=o;g>0;g--)E=E.add(l[g]),m=m.add(E);if(y=y.add(m),p!==0)for(let g=0;g<a;g++)y=y.double()}return y}function x0(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return p0(t),t}else return gr(e,{isLE:n})}function T0(e,t,n={},r){if(r===void 0&&(r=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const u=t[a];if(!(typeof u=="bigint"&&u>ki))throw new Error(`CURVE.${a} must be positive bigint`)}const i=x0(t.p,n.Fp,r),s=x0(t.n,n.Fn,r),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(const a of c)if(!i.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:s}}const Ew=Sn;function wr(e,t){if(Ls(e),Ls(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function _w(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r];return n}function Ls(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function v0(e){if(!ps(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or string");return typeof e=="string"?rt(e):e}function Sw(e,t,n,r){Zt(e),Ls(n),t=v0(t),t.length>255&&(t=r(qe(rt("H2C-OVERSIZE-DST-"),t)));const{outputLen:i,blockLen:s}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const c=qe(t,wr(t.length,1)),a=wr(0,s),u=wr(n,2),l=new Array(o),h=r(qe(a,e,u,wr(0,1),c));l[0]=r(qe(h,wr(1,1),c));for(let p=1;p<=o;p++){const m=[_w(h,l[p-1]),wr(p+1,1),c];l[p]=r(qe(...m))}return qe(...l).slice(0,n)}function xw(e,t,n,r,i){if(Zt(e),Ls(n),t=v0(t),t.length>255){const s=Math.ceil(2*r/8);t=i.create({dkLen:s}).update(rt("H2C-OVERSIZE-DST-")).update(t).digest()}if(n>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:n}).update(e).update(wr(n,2)).update(t).update(wr(t.length,1)).digest()}function _u(e,t,n){qs(n,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:r,k:i,m:s,hash:o,expand:c,DST:a}=n;if(!cw(n.hash))throw new Error("expected valid hash");Zt(e),Ls(t);const u=r.toString(2).length,l=Math.ceil((u+i)/8),h=t*s*l;let y;if(c==="xmd")y=Sw(e,a,h,o);else if(c==="xof")y=xw(e,a,h,i,o);else if(c==="_internal_pass")y=e;else throw new Error('expand must be "xmd" or "xof"');const p=new Array(t);for(let m=0;m<t;m++){const g=new Array(s);for(let E=0;E<s;E++){const x=l*(E+m*s),_=y.subarray(x,x+l);g[E]=ct(Ew(_),r)}p[m]=g}return p}function B0(e,t){const n=t.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,c,a]=n.map(h=>h.reduce((y,p)=>e.add(e.mul(y,r),p))),[u,l]=zr(e,[o,a],!0);return r=e.mul(s,u),i=e.mul(i,e.mul(c,l)),{x:r,y:i}}}const Tw=rt("HashToScalar-");function A0(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");function r(s){return e.fromAffine(t(s))}function i(s){const o=s.clearCofactor();return o.equals(e.ZERO)?e.ZERO:(o.assertValidity(),o)}return{defaults:n,hashToCurve(s,o){const c=Object.assign({},n,o),a=_u(s,2,c),u=r(a[0]),l=r(a[1]);return i(u.add(l))},encodeToCurve(s,o){const c=n.encodeDST?{DST:n.encodeDST}:{},a=Object.assign({},n,c,o),u=_u(s,1,a),l=r(u[0]);return i(l)},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(const o of s)if(typeof o!="bigint")throw new Error("expected array of bigints");return i(r(s))},hashToScalar(s,o){const c=e.Fn.ORDER,a=Object.assign({},n,{p:c,m:1,DST:Tw},o);return _u(s,1,a)[0][0]}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const I0=(e,t)=>(e+(e>=0?t:-t)/Ln)/t;function vw(e,t,n){const[[r,i],[s,o]]=t,c=I0(o*e,n),a=I0(-i*e,n);let u=e-c*r-a*s,l=-c*i-a*o;const h=u<Zr,y=l<Zr;h&&(u=-u),y&&(l=-l);const p=Wr(Math.ceil(Fs(n)/2))+Ct;if(u<Zr||u>=p||l<Zr||l>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:u,k2neg:y,k2:l}}const Zr=BigInt(0),Ct=BigInt(1),Ln=BigInt(2),Pi=BigInt(3),Su=BigInt(4);function fc(e,t){const{BYTES:n}=e;let r;if(typeof t=="bigint")r=t;else{let i=Dt("private key",t);try{r=e.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Bw(e,t={}){const n=T0("weierstrass",e,t),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:c}=s;qs(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:a}=t;if(a&&(!r.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Ow(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(K,U,D){const{x:k,y:j}=U.toAffine(),F=r.toBytes(k);if(Us(D,"isCompressed"),D){l();const S=!r.isOdd(j);return qe(Aw(S),F)}else return qe(Uint8Array.of(4),F,r.toBytes(j))}function y(K){Ri(K,void 0,"Point");const{publicKey:U,publicKeyUncompressed:D}=u,k=K.length,j=K[0],F=K.subarray(1);if(k===U&&(j===2||j===3)){const S=r.fromBytes(F);if(!r.isValid(S))throw new Error("bad point: is not on curve, wrong x");const I=g(S);let M;try{M=r.sqrt(I)}catch(G){const X=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}l();const O=r.isOdd(M);return(j&1)===1!==O&&(M=r.neg(M)),{x:S,y:M}}else if(k===D&&j===4){const S=r.BYTES,I=r.fromBytes(F.subarray(0,S)),M=r.fromBytes(F.subarray(S,S*2));if(!E(I,M))throw new Error("bad point: is not on curve");return{x:I,y:M}}else throw new Error(`bad point: got length ${k}, expected compressed=${U} or uncompressed=${D}`)}const p=t.toBytes||h,m=t.fromBytes||y;function g(K){const U=r.sqr(K),D=r.mul(U,K);return r.add(r.add(D,r.mul(K,s.a)),s.b)}function E(K,U){const D=r.sqr(U),k=g(K);return r.eql(D,k)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const x=r.mul(r.pow(s.a,Pi),Su),_=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(x,_)))throw new Error("bad curve params: a or b");function w(K,U,D=!1){if(!r.isValid(U)||D&&r.is0(U))throw new Error(`bad point coordinate ${K}`);return U}function T(K){if(!(K instanceof v))throw new Error("ProjectivePoint expected")}function R(K){if(!a||!a.basises)throw new Error("no endo");return vw(K,a.basises,i.ORDER)}const B=Ms((K,U)=>{const{X:D,Y:k,Z:j}=K;if(r.eql(j,r.ONE))return{x:D,y:k};const F=K.is0();U==null&&(U=F?r.ONE:r.inv(j));const S=r.mul(D,U),I=r.mul(k,U),M=r.mul(j,U);if(F)return{x:r.ZERO,y:r.ZERO};if(!r.eql(M,r.ONE))throw new Error("invZ was invalid");return{x:S,y:I}}),P=Ms(K=>{if(K.is0()){if(t.allowInfinityPoint&&!r.is0(K.Y))return;throw new Error("bad point: ZERO")}const{x:U,y:D}=K.toAffine();if(!r.isValid(U)||!r.isValid(D))throw new Error("bad point: x or y not field elements");if(!E(U,D))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function q(K,U,D,k,j){return D=new v(r.mul(D.X,K),D.Y,D.Z),U=uc(k,U),D=uc(j,D),U.add(D)}class v{constructor(U,D,k){this.X=w("x",U),this.Y=w("y",D,!0),this.Z=w("z",k),Object.freeze(this)}static CURVE(){return s}static fromAffine(U){const{x:D,y:k}=U||{};if(!U||!r.isValid(D)||!r.isValid(k))throw new Error("invalid affine point");if(U instanceof v)throw new Error("projective point not allowed");return r.is0(D)&&r.is0(k)?v.ZERO:new v(D,k,r.ONE)}static fromBytes(U){const D=v.fromAffine(m(Ri(U,void 0,"point")));return D.assertValidity(),D}static fromHex(U){return v.fromBytes(Dt("pointHex",U))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(U=8,D=!0){return L.createCache(this,U),D||this.multiply(Pi),this}assertValidity(){P(this)}hasEvenY(){const{y:U}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(U)}equals(U){T(U);const{X:D,Y:k,Z:j}=this,{X:F,Y:S,Z:I}=U,M=r.eql(r.mul(D,I),r.mul(F,j)),O=r.eql(r.mul(k,I),r.mul(S,j));return M&&O}negate(){return new v(this.X,r.neg(this.Y),this.Z)}double(){const{a:U,b:D}=s,k=r.mul(D,Pi),{X:j,Y:F,Z:S}=this;let I=r.ZERO,M=r.ZERO,O=r.ZERO,V=r.mul(j,j),G=r.mul(F,F),X=r.mul(S,S),Y=r.mul(j,F);return Y=r.add(Y,Y),O=r.mul(j,S),O=r.add(O,O),I=r.mul(U,O),M=r.mul(k,X),M=r.add(I,M),I=r.sub(G,M),M=r.add(G,M),M=r.mul(I,M),I=r.mul(Y,I),O=r.mul(k,O),X=r.mul(U,X),Y=r.sub(V,X),Y=r.mul(U,Y),Y=r.add(Y,O),O=r.add(V,V),V=r.add(O,V),V=r.add(V,X),V=r.mul(V,Y),M=r.add(M,V),X=r.mul(F,S),X=r.add(X,X),V=r.mul(X,Y),I=r.sub(I,V),O=r.mul(X,G),O=r.add(O,O),O=r.add(O,O),new v(I,M,O)}add(U){T(U);const{X:D,Y:k,Z:j}=this,{X:F,Y:S,Z:I}=U;let M=r.ZERO,O=r.ZERO,V=r.ZERO;const G=s.a,X=r.mul(s.b,Pi);let Y=r.mul(D,F),ce=r.mul(k,S),ue=r.mul(j,I),te=r.add(D,k),Z=r.add(F,S);te=r.mul(te,Z),Z=r.add(Y,ce),te=r.sub(te,Z),Z=r.add(D,j);let ae=r.add(F,I);return Z=r.mul(Z,ae),ae=r.add(Y,ue),Z=r.sub(Z,ae),ae=r.add(k,j),M=r.add(S,I),ae=r.mul(ae,M),M=r.add(ce,ue),ae=r.sub(ae,M),V=r.mul(G,Z),M=r.mul(X,ue),V=r.add(M,V),M=r.sub(ce,V),V=r.add(ce,V),O=r.mul(M,V),ce=r.add(Y,Y),ce=r.add(ce,Y),ue=r.mul(G,ue),Z=r.mul(X,Z),ce=r.add(ce,ue),ue=r.sub(Y,ue),ue=r.mul(G,ue),Z=r.add(Z,ue),Y=r.mul(ce,Z),O=r.add(O,Y),Y=r.mul(ae,Z),M=r.mul(te,M),M=r.sub(M,Y),Y=r.mul(te,ce),V=r.mul(ae,V),V=r.add(V,Y),new v(M,O,V)}subtract(U){return this.add(U.negate())}is0(){return this.equals(v.ZERO)}multiply(U){const{endo:D}=t;if(!i.isValidNot0(U))throw new Error("invalid scalar: out of range");let k,j;const F=S=>L.cached(this,S,I=>Mn(v,I));if(D){const{k1neg:S,k1:I,k2neg:M,k2:O}=R(U),{p:V,f:G}=F(I),{p:X,f:Y}=F(O);j=G.add(Y),k=q(D.beta,V,X,S,M)}else{const{p:S,f:I}=F(U);k=S,j=I}return Mn(v,[k,j])[0]}multiplyUnsafe(U){const{endo:D}=t,k=this;if(!i.isValid(U))throw new Error("invalid scalar: out of range");if(U===Zr||k.is0())return v.ZERO;if(U===Ct)return k;if(L.hasCache(this))return this.multiply(U);if(D){const{k1neg:j,k1:F,k2neg:S,k2:I}=R(U),{p1:M,p2:O}=bw(v,k,F,I);return q(D.beta,M,O,j,S)}else return L.unsafe(k,U)}multiplyAndAddUnsafe(U,D,k){const j=this.multiplyUnsafe(D).add(U.multiplyUnsafe(k));return j.is0()?void 0:j}toAffine(U){return B(this,U)}isTorsionFree(){const{isTorsionFree:U}=t;return o===Ct?!0:U?U(v,this):L.unsafe(this,c).is0()}clearCofactor(){const{clearCofactor:U}=t;return o===Ct?this:U?U(v,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(U=!0){return Us(U,"isCompressed"),this.assertValidity(),p(v,this,U)}toHex(U=!0){return ze(this.toBytes(U))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(U=!0){return this.toBytes(U)}_setWindowSize(U){this.precompute(U)}static normalizeZ(U){return Mn(v,U)}static msm(U,D){return S0(v,i,U,D)}static fromPrivateKey(U){return v.BASE.multiply(fc(i,U))}}v.BASE=new v(s.Gx,s.Gy,r.ONE),v.ZERO=new v(r.ZERO,r.ONE,r.ZERO),v.Fp=r,v.Fn=i;const C=i.BITS,L=new _0(v,t.endo?Math.ceil(C/2):C);return v.BASE.precompute(8),v}function Aw(e){return Uint8Array.of(e?2:3)}function Iw(e,t){const n=e.ORDER;let r=Zr;for(let m=n-Ct;m%Ln===Zr;m/=Ln)r+=Ct;const i=r,s=Ln<<i-Ct-Ct,o=s*Ln,c=(n-Ct)/o,a=(c-Ct)/Ln,u=o-Ct,l=s,h=e.pow(t,c),y=e.pow(t,(c+Ct)/Ln);let p=(m,g)=>{let E=h,x=e.pow(g,u),_=e.sqr(x);_=e.mul(_,g);let w=e.mul(m,_);w=e.pow(w,a),w=e.mul(w,x),x=e.mul(w,g),_=e.mul(w,m);let T=e.mul(_,x);w=e.pow(T,l);let R=e.eql(w,e.ONE);x=e.mul(_,y),w=e.mul(T,E),_=e.cmov(x,_,R),T=e.cmov(w,T,R);for(let B=i;B>Ct;B--){let P=B-Ln;P=Ln<<P-Ct;let q=e.pow(T,P);const v=e.eql(q,e.ONE);x=e.mul(_,E),E=e.mul(E,E),q=e.mul(T,E),_=e.cmov(x,_,v),T=e.cmov(q,T,v)}return{isValid:R,value:_}};if(e.ORDER%Su===Pi){const m=(e.ORDER-Pi)/Su,g=e.sqrt(e.neg(t));p=(E,x)=>{let _=e.sqr(x);const w=e.mul(E,x);_=e.mul(_,w);let T=e.pow(_,m);T=e.mul(T,w);const R=e.mul(T,g),B=e.mul(e.sqr(T),x),P=e.eql(B,E);let q=e.cmov(R,T,P);return{isValid:P,value:q}}}return p}function O0(e,t){p0(e);const{A:n,B:r,Z:i}=t;if(!e.isValid(n)||!e.isValid(r)||!e.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");const s=Iw(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return o=>{let c,a,u,l,h,y,p,m;c=e.sqr(o),c=e.mul(c,i),a=e.sqr(c),a=e.add(a,c),u=e.add(a,e.ONE),u=e.mul(u,r),l=e.cmov(i,e.neg(a),!e.eql(a,e.ZERO)),l=e.mul(l,n),a=e.sqr(u),y=e.sqr(l),h=e.mul(y,n),a=e.add(a,h),a=e.mul(a,u),y=e.mul(y,l),h=e.mul(y,r),a=e.add(a,h),p=e.mul(c,u);const{isValid:g,value:E}=s(a,y);m=e.mul(c,o),m=e.mul(m,E),p=e.cmov(p,u,g),m=e.cmov(m,E,g);const x=e.isOdd(o)===e.isOdd(m);m=e.cmov(e.neg(m),m,x);const _=zr(e,[l],!0)[0];return p=e.mul(p,_),{x:p,y:m}}}function Ow(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function N0(e){const{CURVE:t,curveOpts:n}=Nw(e),r=Bw(t,n);return kw(e,r)}function Nw(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},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=gr(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Rw(e,t,n){function r(i){const s=e.sqr(i),o=e.mul(s,i);return e.add(e.add(o,e.mul(i,t)),n)}return r}function kw(e,t){const{Fp:n,Fn:r}=t;function i(o){return r0(o,Ct,r.ORDER)}const s=Rw(n,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:o=>fc(r,o),weierstrassEquation:s,isWithinCurveOrder:i})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pw=BigInt(0),lc=BigInt(1),R0=BigInt(2),Ci=BigInt(3);function Cw(e){const t=[];for(;e>lc;e>>=lc)(e&lc)===Pw?t.unshift(0):(e&Ci)===Ci?(t.unshift(-1),e+=lc):t.unshift(1);return t}function xu(e){if(!Array.isArray(e)||e.length===0)throw new Error("expected non-empty array")}function Uw(e,t,n,r){const{Fp2:i,Fp12:s}=e,{twistType:o,ateLoopSize:c,xNegative:a,postPrecompute:u}=r;let l;if(o==="multiplicative")l=(w,T,R,B,P,q)=>s.mul014(B,w,i.mul(T,P),i.mul(R,q));else if(o==="divisive")l=(w,T,R,B,P,q)=>s.mul034(B,i.mul(R,q),i.mul(T,P),w);else throw new Error("bls: unknown twist type");const h=i.div(i.ONE,i.mul(i.ONE,R0));function y(w,T,R,B){const P=i.sqr(R),q=i.sqr(B),v=i.mulByB(i.mul(q,Ci)),C=i.mul(v,Ci),L=i.sub(i.sub(i.sqr(i.add(R,B)),q),P),K=i.sub(v,P),U=i.mul(i.sqr(T),Ci),D=i.neg(L);return w.push([K,U,D]),T=i.mul(i.mul(i.mul(i.sub(P,C),T),R),h),R=i.sub(i.sqr(i.mul(i.add(P,C),h)),i.mul(i.sqr(v),Ci)),B=i.mul(P,L),{Rx:T,Ry:R,Rz:B}}function p(w,T,R,B,P,q){const v=i.sub(R,i.mul(q,B)),C=i.sub(T,i.mul(P,B)),L=i.sub(i.mul(v,P),i.mul(C,q)),K=i.neg(v),U=C;w.push([L,K,U]);const D=i.sqr(C),k=i.mul(D,C),j=i.mul(D,T),F=i.add(i.sub(k,i.mul(j,R0)),i.mul(i.sqr(v),B));return T=i.mul(C,F),R=i.sub(i.mul(i.sub(j,F),v),i.mul(k,R)),B=i.mul(B,k),{Rx:T,Ry:R,Rz:B}}const m=Cw(c),g=Ms(w=>{const T=w,{x:R,y:B}=T.toAffine(),P=R,q=B,v=i.neg(B);let C=P,L=q,K=i.ONE;const U=[];for(const D of m){const k=[];({Rx:C,Ry:L,Rz:K}=y(k,C,L,K)),D&&({Rx:C,Ry:L,Rz:K}=p(k,C,L,K,P,D===-1?v:q)),U.push(k)}if(u){const D=U[U.length-1];u(C,L,K,P,q,p.bind(null,D))}return U});function E(w,T=!1){let R=s.ONE;if(w.length){const B=w[0][0].length;for(let P=0;P<B;P++){R=s.sqr(R);for(const[q,v,C]of w)for(const[L,K,U]of q[P])R=l(L,K,U,R,v,C)}}return a&&(R=s.conjugate(R)),T?s.finalExponentiate(R):R}function x(w,T=!0){const R=[];Mn(t,w.map(({g1:B})=>B)),Mn(n,w.map(({g2:B})=>B));for(const{g1:B,g2:P}of w){if(B.is0()||P.is0())throw new Error("pairing is not available for ZERO point");B.assertValidity(),P.assertValidity();const q=B.toAffine();R.push([g(P),q.x,q.y])}return E(R,T)}function _(w,T,R=!0){return x([{g1:w,g2:T}],R)}return{Fp12:s,millerLoopBatch:E,pairing:_,pairingBatch:x,calcPairingPrecomputes:g}}function k0(e,t,n,r,i){const{Fp12:s,pairingBatch:o}=e;function c(h){return h instanceof t.Point?h:t.Point.fromHex(h)}function a(h){return h instanceof n.Point?h:n.Point.fromHex(h)}function u(h){if(!(h instanceof n.Point))throw new Error(`expected valid message hashed to ${i?"G1":"G2"} curve`);return h}const l=i?(h,y)=>({g1:y,g2:h}):(h,y)=>({g1:h,g2:y});return{getPublicKey(h){const y=fc(t.Point.Fn,h);return t.Point.BASE.multiply(y)},sign(h,y,p){if(p!=null)throw new Error("sign() expects 2 arguments");const m=fc(t.Point.Fn,y);return u(h).assertValidity(),h.multiply(m)},verify(h,y,p,m){if(m!=null)throw new Error("verify() expects 3 arguments");h=a(h),p=c(p);const g=p.negate(),E=t.Point.BASE,x=u(y),_=h,w=o([l(g,x),l(E,_)]);return s.eql(w,s.ONE)},verifyBatch(h,y,p){if(xu(y),p.length!==y.length)throw new Error("amount of public keys and messages should be equal");const m=a(h),g=y,E=p.map(c),x=new Map;for(let T=0;T<E.length;T++){const R=E[T],B=g[T];let P=x.get(B);P===void 0&&(P=[],x.set(B,P)),P.push(R)}const _=[],w=t.Point.BASE;try{for(const[T,R]of x){const B=R.reduce((P,q)=>P.add(q));_.push(l(B,T))}return _.push(l(w.negate(),m)),s.eql(o(_),s.ONE)}catch{return!1}},aggregatePublicKeys(h){xu(h),h=h.map(p=>c(p));const y=h.reduce((p,m)=>p.add(m),t.Point.ZERO);return y.assertValidity(),y},aggregateSignatures(h){xu(h),h=h.map(p=>a(p));const y=h.reduce((p,m)=>p.add(m),n.Point.ZERO);return y.assertValidity(),y},hash(h,y){Zt(h);const p=y?{DST:y}:void 0;return n.hashToCurve(h,p)},Signature:r}}function Hw(e){const{Fp:t,Fr:n,Fp2:r,Fp6:i,Fp12:s}=e.fields,o=N0(e.G1),c=Object.assign(o,A0(o.Point,e.G1.mapToCurve,{...e.htfDefaults,...e.G1.htfDefaults})),a=N0(e.G2),u=Object.assign(a,A0(a.Point,e.G2.mapToCurve,{...e.htfDefaults,...e.G2.htfDefaults})),l=Uw(e.fields,c.Point,u.Point,{...e.params,postPrecompute:e.postPrecompute}),{millerLoopBatch:h,pairing:y,pairingBatch:p,calcPairingPrecomputes:m}=l,g=k0(l,c,u,e.G2.Signature,!1),E=k0(l,u,c,e.G1.ShortSignature,!0),x=e.randomBytes||dd,_=()=>{const S=m0(n.ORDER);return mw(x(S),n.ORDER)},w={randomSecretKey:_,randomPrivateKey:_,calcPairingPrecomputes:m},{ShortSignature:T}=e.G1,{Signature:R}=e.G2;function B(S,I){return S instanceof c.Point?S:E.hash(Dt("point",S),I?.DST)}function P(S,I){return S instanceof u.Point?S:g.hash(Dt("point",S),I?.DST)}function q(S){return g.getPublicKey(S).toBytes(!0)}function v(S){return E.getPublicKey(S).toBytes(!0)}function C(S,I,M){const O=P(S,M),V=g.sign(O,I);return S instanceof u.Point?V:R.toBytes(V)}function L(S,I,M){const O=B(S,M),V=E.sign(O,I);return S instanceof c.Point?V:T.toBytes(V)}function K(S,I,M,O){const V=P(I,O);return g.verify(S,V,M)}function U(S,I,M,O){const V=B(I,O);return E.verify(S,V,M)}function D(S){const I=g.aggregatePublicKeys(S);return S[0]instanceof c.Point?I:I.toBytes(!0)}function k(S){const I=g.aggregateSignatures(S);return S[0]instanceof u.Point?I:R.toBytes(I)}function j(S){const I=E.aggregateSignatures(S);return S[0]instanceof c.Point?I:T.toBytes(I)}function F(S,I,M,O){const V=I.map(G=>P(G,O));return g.verifyBatch(S,V,M)}return c.Point.BASE.precompute(4),{longSignatures:g,shortSignatures:E,millerLoopBatch:h,pairing:y,pairingBatch:p,verifyBatch:F,fields:{Fr:n,Fp:t,Fp2:r,Fp6:i,Fp12:s},params:{ateLoopSize:e.params.ateLoopSize,twistType:e.params.twistType,r:e.params.r,G1b:e.G1.b,G2b:e.G2.b},utils:w,getPublicKey:q,getPublicKeyForShortSignatures:v,sign:C,signShortSignature:L,verify:K,verifyShortSignature:U,aggregatePublicKeys:D,aggregateSignatures:k,aggregateShortSignatures:j,G1:c,G2:u,Signature:R,ShortSignature:T}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const P0=BigInt(0),Vn=BigInt(1),Ut=BigInt(2),C0=BigInt(3);function Tu(e,t,n,r,i=1,s){const o=BigInt(s===void 0?r:s),c=n**BigInt(r),a=[];for(let u=0;u<i;u++){const l=BigInt(u+1),h=[];for(let y=0,p=Vn;y<r;y++){const m=(l*p-l)/o%c;h.push(e.pow(t,m)),p*=n}a.push(h)}return a}function Fw(e,t,n){const r=t.pow(n,(e.ORDER-Vn)/C0),i=t.pow(n,(e.ORDER-Vn)/Ut);function s(y,p){const m=t.mul(t.frobeniusMap(y,1),r),g=t.mul(t.frobeniusMap(p,1),i);return[m,g]}const o=t.pow(n,(e.ORDER**Ut-Vn)/C0),c=t.pow(n,(e.ORDER**Ut-Vn)/Ut);if(!t.eql(c,t.neg(t.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function a(y,p){return[t.mul(y,o),t.neg(p)]}const u=y=>(p,m)=>{const g=m.toAffine(),E=y(g.x,g.y);return p.fromAffine({x:E[0],y:E[1]})},l=u(s),h=u(a);return{psi:s,psi2:a,G2psi:l,G2psi2:h,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:c}}const U0=(e,t)=>{if(t.length!==2)throw new Error("invalid tuple");const n=t.map(r=>e.create(r));return{c0:n[0],c1:n[1]}};class qw{constructor(t,n={}){this.MASK=Vn;const r=t.ORDER,i=r*r;this.Fp=t,this.ORDER=i,this.BITS=Fs(i),this.BYTES=Math.ceil(Fs(i)/8),this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.Fp_NONRESIDUE=t.create(n.NONRESIDUE||BigInt(-1)),this.Fp_div2=t.div(t.ONE,Ut),this.NONRESIDUE=U0(t,n.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=Tu(t,this.Fp_NONRESIDUE,t.ORDER,2)[0],this.mulByB=n.Fp2mulByB,Object.seal(this)}fromBigTuple(t){return U0(this.Fp,t)}create(t){return t}isValid({c0:t,c1:n}){function r(i,s){return typeof i=="bigint"&&P0<=i&&i<s}return r(t,this.ORDER)&&r(n,this.ORDER)}is0({c0:t,c1:n}){return this.Fp.is0(t)&&this.Fp.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}eql({c0:t,c1:n},{c0:r,c1:i}){return this.Fp.eql(t,r)&&this.Fp.eql(n,i)}neg({c0:t,c1:n}){return{c0:this.Fp.neg(t),c1:this.Fp.neg(n)}}pow(t,n){return cc(this,t,n)}invertBatch(t){return zr(this,t)}add(t,n){const{c0:r,c1:i}=t,{c0:s,c1:o}=n;return{c0:this.Fp.add(r,s),c1:this.Fp.add(i,o)}}sub({c0:t,c1:n},{c0:r,c1:i}){return{c0:this.Fp.sub(t,r),c1:this.Fp.sub(n,i)}}mul({c0:t,c1:n},r){const{Fp:i}=this;if(typeof r=="bigint")return{c0:i.mul(t,r),c1:i.mul(n,r)};const{c0:s,c1:o}=r;let c=i.mul(t,s),a=i.mul(n,o);const u=i.sub(c,a),l=i.sub(i.mul(i.add(t,n),i.add(s,o)),i.add(c,a));return{c0:u,c1:l}}sqr({c0:t,c1:n}){const{Fp:r}=this,i=r.add(t,n),s=r.sub(t,n),o=r.add(t,t);return{c0:r.mul(i,s),c1:r.mul(o,n)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}div(t,n){const{Fp:r}=this;return this.mul(t,typeof n=="bigint"?r.inv(r.create(n)):this.inv(n))}inv({c0:t,c1:n}){const{Fp:r}=this,i=r.inv(r.create(t*t+n*n));return{c0:r.mul(i,r.create(t)),c1:r.mul(i,r.create(-n))}}sqrt(t){const{Fp:n}=this,r=this,{c0:i,c1:s}=t;if(n.is0(s))return ac(n,i)===1?r.create({c0:n.sqrt(i),c1:n.ZERO}):r.create({c0:n.ZERO,c1:n.sqrt(n.div(i,this.Fp_NONRESIDUE))});const o=n.sqrt(n.sub(n.sqr(i),n.mul(n.sqr(s),this.Fp_NONRESIDUE)));let c=n.mul(n.add(o,i),this.Fp_div2);ac(n,c)===-1&&(c=n.sub(c,o));const u=n.sqrt(c),l=r.create({c0:u,c1:n.div(n.mul(s,this.Fp_div2),u)});if(!r.eql(r.sqr(l),t))throw new Error("Cannot find square root");const h=l,y=r.neg(h),{re:p,im:m}=r.reim(h),{re:g,im:E}=r.reim(y);return m>E||m===E&&p>g?h:y}isOdd(t){const{re:n,im:r}=this.reim(t),i=n%Ut,s=n===P0,o=r%Ut;return BigInt(i||s&&o)==Vn}fromBytes(t){const{Fp:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:n.fromBytes(t.subarray(0,n.BYTES)),c1:n.fromBytes(t.subarray(n.BYTES))}}toBytes({c0:t,c1:n}){return qe(this.Fp.toBytes(t),this.Fp.toBytes(n))}cmov({c0:t,c1:n},{c0:r,c1:i},s){return{c0:this.Fp.cmov(t,r,s),c1:this.Fp.cmov(n,i,s)}}reim({c0:t,c1:n}){return{re:t,im:n}}Fp4Square(t,n){const r=this,i=r.sqr(t),s=r.sqr(n);return{first:r.add(r.mulByNonresidue(s),i),second:r.sub(r.sub(r.sqr(r.add(t,n)),i),s)}}mulByNonresidue({c0:t,c1:n}){return this.mul({c0:t,c1:n},this.NONRESIDUE)}frobeniusMap({c0:t,c1:n},r){return{c0:t,c1:this.Fp.mul(n,this.FROBENIUS_COEFFICIENTS[r%2])}}}class Mw{constructor(t){this.MASK=Vn,this.Fp2=t,this.ORDER=t.ORDER,this.BITS=3*t.BITS,this.BYTES=3*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO,c2:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO,c2:t.ZERO};const{Fp:n}=t,r=Tu(t,t.NONRESIDUE,n.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=r[0],this.FROBENIUS_COEFFICIENTS_2=r[1],Object.seal(this)}add({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return{c0:c.add(t,i),c1:c.add(n,s),c2:c.add(r,o)}}sub({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return{c0:c.sub(t,i),c1:c.sub(n,s),c2:c.sub(r,o)}}mul({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;if(typeof i=="bigint")return{c0:s.mul(t,i),c1:s.mul(n,i),c2:s.mul(r,i)};const{c0:o,c1:c,c2:a}=i,u=s.mul(t,o),l=s.mul(n,c),h=s.mul(r,a);return{c0:s.add(u,s.mulByNonresidue(s.sub(s.mul(s.add(n,r),s.add(c,a)),s.add(l,h)))),c1:s.add(s.sub(s.mul(s.add(t,n),s.add(o,c)),s.add(u,l)),s.mulByNonresidue(h)),c2:s.sub(s.add(l,s.mul(s.add(t,r),s.add(o,a))),s.add(u,h))}}sqr({c0:t,c1:n,c2:r}){const{Fp2:i}=this;let s=i.sqr(t),o=i.mul(i.mul(t,n),Ut),c=i.mul(i.mul(n,r),Ut),a=i.sqr(r);return{c0:i.add(i.mulByNonresidue(c),s),c1:i.add(i.mulByNonresidue(a),o),c2:i.sub(i.sub(i.add(i.add(o,i.sqr(i.add(i.sub(t,n),r))),c),s),a)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}create(t){return t}isValid({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return i.isValid(t)&&i.isValid(n)&&i.isValid(r)}is0({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return i.is0(t)&&i.is0(n)&&i.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return{c0:i.neg(t),c1:i.neg(n),c2:i.neg(r)}}eql({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return c.eql(t,i)&&c.eql(n,s)&&c.eql(r,o)}sqrt(t){return s0()}div(t,n){const{Fp2:r}=this,{Fp:i}=r;return this.mul(t,typeof n=="bigint"?i.inv(i.create(n)):this.inv(n))}pow(t,n){return cc(this,t,n)}invertBatch(t){return zr(this,t)}inv({c0:t,c1:n,c2:r}){const{Fp2:i}=this;let s=i.sub(i.sqr(t),i.mulByNonresidue(i.mul(r,n))),o=i.sub(i.mulByNonresidue(i.sqr(r)),i.mul(t,n)),c=i.sub(i.sqr(n),i.mul(t,r)),a=i.inv(i.add(i.mulByNonresidue(i.add(i.mul(r,o),i.mul(n,c))),i.mul(t,s)));return{c0:i.mul(a,s),c1:i.mul(a,o),c2:i.mul(a,c)}}fromBytes(t){const{Fp2:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);const r=n.BYTES;return{c0:n.fromBytes(t.subarray(0,r)),c1:n.fromBytes(t.subarray(r,r*2)),c2:n.fromBytes(t.subarray(2*r))}}toBytes({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return qe(i.toBytes(t),i.toBytes(n),i.toBytes(r))}cmov({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o},c){const{Fp2:a}=this;return{c0:a.cmov(t,i,c),c1:a.cmov(n,s,c),c2:a.cmov(r,o,c)}}fromBigSix(t){const{Fp2:n}=this;if(!Array.isArray(t)||t.length!==6)throw new Error("invalid Fp6 usage");return{c0:n.fromBigTuple(t.slice(0,2)),c1:n.fromBigTuple(t.slice(2,4)),c2:n.fromBigTuple(t.slice(4,6))}}frobeniusMap({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.frobeniusMap(t,i),c1:s.mul(s.frobeniusMap(n,i),this.FROBENIUS_COEFFICIENTS_1[i%6]),c2:s.mul(s.frobeniusMap(r,i),this.FROBENIUS_COEFFICIENTS_2[i%6])}}mulByFp2({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.mul(t,i),c1:s.mul(n,i),c2:s.mul(r,i)}}mulByNonresidue({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return{c0:i.mulByNonresidue(r),c1:t,c2:n}}mul1({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.mulByNonresidue(s.mul(r,i)),c1:s.mul(t,i),c2:s.mul(n,i)}}mul01({c0:t,c1:n,c2:r},i,s){const{Fp2:o}=this;let c=o.mul(t,i),a=o.mul(n,s);return{c0:o.add(o.mulByNonresidue(o.sub(o.mul(o.add(n,r),s),a)),c),c1:o.sub(o.sub(o.mul(o.add(i,s),o.add(t,n)),c),a),c2:o.add(o.sub(o.mul(o.add(t,r),i),c),a)}}}class Lw{constructor(t,n){this.MASK=Vn;const{Fp2:r}=t,{Fp:i}=r;this.Fp6=t,this.ORDER=r.ORDER,this.BITS=2*t.BITS,this.BYTES=2*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.FROBENIUS_COEFFICIENTS=Tu(r,r.NONRESIDUE,i.ORDER,12,1,6)[0],this.X_LEN=n.X_LEN,this.finalExponentiate=n.Fp12finalExponentiate}create(t){return t}isValid({c0:t,c1:n}){const{Fp6:r}=this;return r.isValid(t)&&r.isValid(n)}is0({c0:t,c1:n}){const{Fp6:r}=this;return r.is0(t)&&r.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:n}){const{Fp6:r}=this;return{c0:r.neg(t),c1:r.neg(n)}}eql({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return s.eql(t,r)&&s.eql(n,i)}sqrt(t){s0()}inv({c0:t,c1:n}){const{Fp6:r}=this;let i=r.inv(r.sub(r.sqr(t),r.mulByNonresidue(r.sqr(n))));return{c0:r.mul(t,i),c1:r.neg(r.mul(n,i))}}div(t,n){const{Fp6:r}=this,{Fp2:i}=r,{Fp:s}=i;return this.mul(t,typeof n=="bigint"?s.inv(s.create(n)):this.inv(n))}pow(t,n){return cc(this,t,n)}invertBatch(t){return zr(this,t)}add({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return{c0:s.add(t,r),c1:s.add(n,i)}}sub({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return{c0:s.sub(t,r),c1:s.sub(n,i)}}mul({c0:t,c1:n},r){const{Fp6:i}=this;if(typeof r=="bigint")return{c0:i.mul(t,r),c1:i.mul(n,r)};let{c0:s,c1:o}=r,c=i.mul(t,s),a=i.mul(n,o);return{c0:i.add(c,i.mulByNonresidue(a)),c1:i.sub(i.mul(i.add(t,n),i.add(s,o)),i.add(c,a))}}sqr({c0:t,c1:n}){const{Fp6:r}=this;let i=r.mul(t,n);return{c0:r.sub(r.sub(r.mul(r.add(r.mulByNonresidue(n),t),r.add(t,n)),i),r.mulByNonresidue(i)),c1:r.add(i,i)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}fromBytes(t){const{Fp6:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:n.fromBytes(t.subarray(0,n.BYTES)),c1:n.fromBytes(t.subarray(n.BYTES))}}toBytes({c0:t,c1:n}){const{Fp6:r}=this;return qe(r.toBytes(t),r.toBytes(n))}cmov({c0:t,c1:n},{c0:r,c1:i},s){const{Fp6:o}=this;return{c0:o.cmov(t,r,s),c1:o.cmov(n,i,s)}}fromBigTwelve(t){const{Fp6:n}=this;return{c0:n.fromBigSix(t.slice(0,6)),c1:n.fromBigSix(t.slice(6,12))}}frobeniusMap(t,n){const{Fp6:r}=this,{Fp2:i}=r,{c0:s,c1:o,c2:c}=r.frobeniusMap(t.c1,n),a=this.FROBENIUS_COEFFICIENTS[n%12];return{c0:r.frobeniusMap(t.c0,n),c1:r.create({c0:i.mul(s,a),c1:i.mul(o,a),c2:i.mul(c,a)})}}mulByFp2({c0:t,c1:n},r){const{Fp6:i}=this;return{c0:i.mulByFp2(t,r),c1:i.mulByFp2(n,r)}}conjugate({c0:t,c1:n}){return{c0:t,c1:this.Fp6.neg(n)}}mul014({c0:t,c1:n},r,i,s){const{Fp6:o}=this,{Fp2:c}=o;let a=o.mul01(t,r,i),u=o.mul1(n,s);return{c0:o.add(o.mulByNonresidue(u),a),c1:o.sub(o.sub(o.mul01(o.add(n,t),r,c.add(i,s)),a),u)}}mul034({c0:t,c1:n},r,i,s){const{Fp6:o}=this,{Fp2:c}=o,a=o.create({c0:c.mul(t.c0,r),c1:c.mul(t.c1,r),c2:c.mul(t.c2,r)}),u=o.mul01(n,i,s),l=o.mul01(o.add(t,n),c.add(r,i),s);return{c0:o.add(o.mulByNonresidue(u),a),c1:o.sub(l,o.add(a,u))}}_cyclotomicSquare({c0:t,c1:n}){const{Fp6:r}=this,{Fp2:i}=r,{c0:s,c1:o,c2:c}=t,{c0:a,c1:u,c2:l}=n,{first:h,second:y}=i.Fp4Square(s,u),{first:p,second:m}=i.Fp4Square(a,c),{first:g,second:E}=i.Fp4Square(o,l),x=i.mulByNonresidue(E);return{c0:r.create({c0:i.add(i.mul(i.sub(h,s),Ut),h),c1:i.add(i.mul(i.sub(p,o),Ut),p),c2:i.add(i.mul(i.sub(g,c),Ut),g)}),c1:r.create({c0:i.add(i.mul(i.add(x,a),Ut),x),c1:i.add(i.mul(i.add(y,u),Ut),y),c2:i.add(i.mul(i.add(m,l),Ut),m)})}}_cyclotomicExp(t,n){let r=this.ONE;for(let i=this.X_LEN-1;i>=0;i--)r=this._cyclotomicSquare(r),ow(n,i)&&(r=this.mul(r,t));return r}}function Vw(e){const t=gr(e.ORDER),n=new qw(t,e),r=new Mw(n),i=new Lw(r,e);return{Fp:t,Fp2:n,Fp6:r,Fp12:i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ot=BigInt(0),dc=BigInt(1),nn=BigInt(2),hc=BigInt(3),Vs=BigInt(4),br=BigInt("0xd201000000010000"),Dw=Fs(br),Jr={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Ot,b:Vs,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},jw=gr(Jr.n,{modFromBytes:!0,isLE:!0}),{Fp:we,Fp2:Oe,Fp6:$w,Fp12:Ue}=Vw({ORDER:Jr.p,X_LEN:Dw,FP2_NONRESIDUE:[dc,dc],Fp2mulByB:({c0:e,c1:t})=>{const n=we.mul(e,Vs),r=we.mul(t,Vs);return{c0:we.sub(n,r),c1:we.add(n,r)}},Fp12finalExponentiate:e=>{const t=br,n=Ue.div(Ue.frobeniusMap(e,6),e),r=Ue.mul(Ue.frobeniusMap(n,2),n),i=Ue.conjugate(Ue._cyclotomicExp(r,t)),s=Ue.mul(Ue.conjugate(Ue._cyclotomicSquare(r)),i),o=Ue.conjugate(Ue._cyclotomicExp(s,t)),c=Ue.conjugate(Ue._cyclotomicExp(o,t)),a=Ue.mul(Ue.conjugate(Ue._cyclotomicExp(c,t)),Ue._cyclotomicSquare(i)),u=Ue.conjugate(Ue._cyclotomicExp(a,t)),l=Ue.frobeniusMap(Ue.mul(i,c),2),h=Ue.frobeniusMap(Ue.mul(o,r),3),y=Ue.frobeniusMap(Ue.mul(a,Ue.conjugate(r)),1),p=Ue.mul(Ue.mul(u,Ue.conjugate(s)),r);return Ue.mul(Ue.mul(Ue.mul(l,h),y),p)}}),{G2psi:H0,G2psi2:Kw}=Fw(we,Oe,Oe.div(Oe.ONE,Oe.NONRESIDUE)),vu=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:we.ORDER,m:2,k:128,expand:"xmd",hash:Jt}),Bu={p:Oe.ORDER,n:Jr.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:Oe.ZERO,b:Oe.fromBigTuple([Vs,Vs]),Gx:Oe.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:Oe.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},pc=Ds(we.toBytes(Ot),{infinity:!0,compressed:!0});function yc(e){e=e.slice();const t=e[0]&224,n=!!(t>>7&1),r=!!(t>>6&1),i=!!(t>>5&1);return e[0]&=31,{compressed:n,infinity:r,sort:i,value:e}}function Ds(e,t){if(e[0]&224)throw new Error("setMask: non-empty mask");return t.compressed&&(e[0]|=128),t.infinity&&(e[0]|=64),t.sort&&(e[0]|=32),e}function Gw(e,t,n){const{BYTES:r,ORDER:i}=we,s=t.is0(),{x:o,y:c}=t.toAffine();if(n){if(s)return pc.slice();const a=!!(c*nn/i);return Ds(Et(o,r),{compressed:!0,sort:a})}else return s?qe(Uint8Array.of(64),new Uint8Array(2*r-1)):qe(Et(o,r),Et(c,r))}function Au(e){e.assertValidity();const{BYTES:t,ORDER:n}=we,{x:r,y:i}=e.toAffine();if(e.is0())return pc.slice();const s=!!(i*nn/n);return Ds(Et(r,t),{compressed:!0,sort:s})}function Ww(e){const{compressed:t,infinity:n,sort:r,value:i}=yc(e),{BYTES:s,ORDER:o}=we;if(i.length===48&&t){const c=Sn(i),a=we.create(c&Wr(we.BITS));if(n){if(a!==Ot)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:Ot,y:Ot}}const u=we.add(we.pow(a,hc),we.create(Jr.b));let l=we.sqrt(u);if(!l)throw new Error("invalid G1 point: compressed point");return l*nn/o!==BigInt(r)&&(l=we.neg(l)),{x:we.create(a),y:we.create(l)}}else if(i.length===96&&!t){const c=Sn(i.subarray(0,s)),a=Sn(i.subarray(s));if(n){if(c!==Ot||a!==Ot)throw new Error("G1: non-empty point at infinity");return mc.G1.Point.ZERO.toAffine()}return{x:we.create(c),y:we.create(a)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function F0(e){const{infinity:t,sort:n,value:r}=yc(Dt("signatureHex",e,48)),i=we.ORDER,s=mc.G1.Point,o=Sn(r);if(t)return s.ZERO;const c=we.create(o&Wr(we.BITS)),a=we.add(we.pow(c,hc),we.create(Jr.b));let u=we.sqrt(a);if(!u)throw new Error("invalid G1 point: compressed");const l=BigInt(n);u*nn/i!==l&&(u=we.neg(u));const h=s.fromAffine({x:c,y:u});return h.assertValidity(),h}function Xw(e,t,n){const{BYTES:r,ORDER:i}=we,s=t.is0(),{x:o,y:c}=t.toAffine();if(n){if(s)return qe(pc,Et(Ot,r));const a=!!(c.c1===Ot?c.c0*nn/i:c.c1*nn/i);return qe(Ds(Et(o.c1,r),{compressed:!0,sort:a}),Et(o.c0,r))}else{if(s)return qe(Uint8Array.of(64),new Uint8Array(4*r-1));const{re:a,im:u}=Oe.reim(o),{re:l,im:h}=Oe.reim(c);return qe(Et(u,r),Et(a,r),Et(h,r),Et(l,r))}}function Iu(e){e.assertValidity();const{BYTES:t}=we;if(e.is0())return qe(pc,Et(Ot,t));const{x:n,y:r}=e.toAffine(),{re:i,im:s}=Oe.reim(n),{re:o,im:c}=Oe.reim(r),u=!!((c>Ot?c*nn:o*nn)/we.ORDER&dc),l=i;return qe(Ds(Et(s,t),{sort:u,compressed:!0}),Et(l,t))}function zw(e){const{BYTES:t,ORDER:n}=we,{compressed:r,infinity:i,sort:s,value:o}=yc(e);if(!r&&!i&&s||!r&&i&&s||s&&i&&r)throw new Error("invalid encoding flag: "+(e[0]&224));const c=(a,u,l)=>Sn(a.slice(u,l));if(o.length===96&&r){if(i){if(o.reduce((m,g)=>m!==0?g+1:g,0)>0)throw new Error("invalid G2 point: compressed");return{x:Oe.ZERO,y:Oe.ZERO}}const a=c(o,0,t),u=c(o,t,2*t),l=Oe.create({c0:we.create(u),c1:we.create(a)}),h=Oe.add(Oe.pow(l,hc),Bu.b);let y=Oe.sqrt(h);const p=y.c1===Ot?y.c0*nn/n:y.c1*nn/n?dc:Ot;return y=s&&p>0?y:Oe.neg(y),{x:l,y}}else if(o.length===192&&!r){if(i){if(o.reduce((y,p)=>y!==0?p+1:p,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:Oe.ZERO,y:Oe.ZERO}}const a=c(o,0*t,1*t),u=c(o,1*t,2*t),l=c(o,2*t,3*t),h=c(o,3*t,4*t);return{x:Oe.fromBigTuple([u,a]),y:Oe.fromBigTuple([h,l])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function q0(e){const{ORDER:t}=we,{infinity:n,sort:r,value:i}=yc(Dt("signatureHex",e)),s=mc.G2.Point,o=i.length/2;if(o!==48&&o!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");const c=Sn(i.slice(0,o)),a=Sn(i.slice(o));if(n)return s.ZERO;const u=we.create(c&Wr(we.BITS)),l=we.create(a),h=Oe.create({c0:l,c1:u}),y=Oe.add(Oe.pow(h,hc),Bu.b);let p=Oe.sqrt(y);if(!p)throw new Error("Failed to find a square root");const{re:m,im:g}=Oe.reim(p),E=BigInt(r),x=g>Ot&&g*nn/t!==E,_=g===Ot&&m*nn/t!==E;(x||_)&&(p=Oe.neg(p));const w=s.fromAffine({x:h,y:p});return w.assertValidity(),w}const mc=Hw({fields:{Fp:we,Fp2:Oe,Fp6:$w,Fp12:Ue,Fr:jw},G1:{...Jr,Fp:we,htfDefaults:{...vu,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(e,t)=>{const n=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),r=new e(we.mul(t.X,n),t.Y,t.Z);return t.multiplyUnsafe(br).negate().multiplyUnsafe(br).equals(r)},clearCofactor:(e,t)=>t.multiplyUnsafe(br).add(t),mapToCurve:eb,fromBytes:Ww,toBytes:Gw,ShortSignature:{fromBytes(e){return Zt(e),F0(e)},fromHex(e){return F0(e)},toBytes(e){return Au(e)},toRawBytes(e){return Au(e)},toHex(e){return ze(Au(e))}}},G2:{...Bu,Fp:Oe,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...vu},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:tb,isTorsionFree:(e,t)=>t.multiplyUnsafe(br).negate().equals(H0(e,t)),clearCofactor:(e,t)=>{const n=br;let r=t.multiplyUnsafe(n).negate(),i=H0(e,t),s=t.double();return s=Kw(e,s),s=s.subtract(i),i=r.add(i),i=i.multiplyUnsafe(n).negate(),s=s.add(i),s=s.subtract(r),s.subtract(t)},fromBytes:zw,toBytes:Xw,Signature:{fromBytes(e){return Zt(e),q0(e)},fromHex(e){return q0(e)},toBytes(e){return Iu(e)},toRawBytes(e){return Iu(e)},toHex(e){return ze(Iu(e))}}},params:{ateLoopSize:br,r:Jr.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:vu}),Yw=B0(Oe,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(e=>e.map(t=>Oe.fromBigTuple(t.map(BigInt))))),Zw=B0(we,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),Jw=O0(we,{A:we.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:we.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:we.create(BigInt(11))}),Qw=O0(Oe,{A:Oe.create({c0:we.create(Ot),c1:we.create(BigInt(240))}),B:Oe.create({c0:we.create(BigInt(1012)),c1:we.create(BigInt(1012))}),Z:Oe.create({c0:we.create(BigInt(-2)),c1:we.create(BigInt(-1))})});function eb(e){const{x:t,y:n}=Jw(we.create(e[0]));return Zw(t,n)}function tb(e){const{x:t,y:n}=Qw(Oe.fromBigTuple(e));return Yw(t,n)}function nb(e,t,n){const r=typeof e=="string"?e:ze(e),i=typeof t=="string"?t:ze(t),s=typeof n=="string"?n:ze(n);return mc.verifyShortSignature(i,s,r)}const rb=BigInt(1e6),M0=e=>pt(new yi(e)),Ou=e=>{const n=M0(e)/rb;return new Date(Number(n))},L0=60*1e3,ib=24*60,sb=5,ob=5,cb=30*ib;var St;(function(e){e[e.Empty=0]="Empty",e[e.Fork=1]="Fork",e[e.Labeled=2]="Labeled",e[e.Leaf=3]="Leaf",e[e.Pruned=4]="Pruned"})(St||(St={}));function ab(e,t){for(let n=0;n<e.length;n++)if(e[n]>t[n])return!0;return!1}class Qr{#t=!1;#e=void 0;static async create(t){const n=Qr.createUnverified(t);return await n.verify(),n}static createUnverified(t){return new Qr(t.certificate,t.rootKey,t.canisterId,t.blsVerify??nb,t.maxAgeInMinutes,t.disableTimeVerification,t.agent)}constructor(t,n,r,i,s=sb,o=!1,c){this._rootKey=n,this._canisterId=r,this._blsVerify=i,this._maxAgeInMinutes=s,this.#t=o,this.cert=_n(t),c&&"getTimeDiffMsecs"in c&&"hasSyncedTime"in c&&"syncTime"in c&&(this.#e=c)}lookup_path(t){return Ks(t,this.cert.tree)}lookup_subtree(t){return Nu(t,this.cert.tree)}async verify(){const t=await gc(this.cert.tree),n=await this._checkDelegationAndGetKey(this.cert.delegation),r=this.cert.signature,i=fb(n),s=qe($s("ic-state-root"),t),o=Wt(this.lookup_path(["time"]));if(!o)throw ot.fromCode(new Si("Certificate does not contain a time"));if(!this.#t){const c=this.#e?.getTimeDiffMsecs()??0,a=this._maxAgeInMinutes*L0,u=new Date,l=u.getTime()+c,h=l-a,y=l+ob*L0,p=Ou(o),m=p.getTime()<h,g=p.getTime()>y;if((m||g)&&this.#e&&!this.#e.hasSyncedTime())return await this.#e.syncTime(this._canisterId),await this.verify();if(m)throw tn.fromCode(new Bs(this._maxAgeInMinutes,p,u,c,"past"));if(g)throw this.#e?.hasSyncedTime()?Vt.fromCode(new fn("System time has been synced with the IC network, but certificate is still too far in the future.")):tn.fromCode(new Bs(5,p,u,c,"future"))}try{if(!await this._blsVerify(i,r,s))throw tn.fromCode(new Si("Invalid signature"))}catch(c){throw tn.fromCode(new Si("Signature verification failed",c))}}async _checkDelegationAndGetKey(t){if(!t)return this._rootKey;const n=Qr.createUnverified({certificate:t.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#t,maxAgeInMinutes:cb,agent:this.#e});if(n.cert.delegation)throw ot.fromCode(new Va);await n.verify();const r=t.subnet_id,i=Le.fromUint8Array(r);if(!D0({canisterId:this._canisterId,subnetId:i,tree:n.cert.tree}))throw tn.fromCode(new $o(this._canisterId,i));const o=Wt(n.lookup_path(["subnet",r,"public_key"]));if(!o)throw tn.fromCode(new Da(`Could not find subnet key for subnet ID ${i.toText()}`));return o}}const js=ms("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),ub=96;function fb(e){const t=js.byteLength+ub;if(e.byteLength!==t)throw ot.fromCode(new Go(t,e.byteLength));const n=e.slice(0,js.byteLength);if(!tc(n,js))throw ot.fromCode(new ja(js,n));return e.slice(js.byteLength)}function Wt(e){if(e.status===rn.Found&&e.value instanceof Uint8Array)return e.value}async function gc(e){switch(e[0]){case St.Empty:return Jt($s("ic-hashtree-empty"));case St.Pruned:return e[1];case St.Leaf:return Jt(qe($s("ic-hashtree-leaf"),e[1]));case St.Labeled:return Jt(qe($s("ic-hashtree-labeled"),e[1],await gc(e[2])));case St.Fork:return Jt(qe($s("ic-hashtree-fork"),await gc(e[1]),await gc(e[2])));default:throw Bi}}function $s(e){const t=new Uint8Array([e.length]),n=new TextEncoder().encode(e);return qe(t,n)}function V0(e){return typeof e[0]=="string"?rt(e[0]):e[0]}var rn;(function(e){e.Unknown="Unknown",e.Absent="Absent",e.Found="Found",e.Error="Error"})(rn||(rn={}));var Ui;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found"})(Ui||(Ui={}));var Je;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found",e.Less="Less",e.Greater="Greater"})(Je||(Je={}));function Ks(e,t){if(e.length===0)switch(t[0]){case St.Empty:return{status:rn.Absent};case St.Leaf:{if(!t[1])throw Vt.fromCode(new Os("Invalid tree structure for leaf"));if(t[1]instanceof Uint8Array)return{status:rn.Found,value:t[1].slice(t[1].byteOffset,t[1].byteLength+t[1].byteOffset)};throw Bi}case St.Pruned:return{status:rn.Unknown};case St.Labeled:case St.Fork:return{status:rn.Error};default:throw Bi}const n=V0(e),r=Gs(n,t);switch(r.status){case Je.Found:return Ks(e.slice(1),r.value);case Je.Absent:case Je.Greater:case Je.Less:return{status:rn.Absent};case Je.Unknown:return{status:rn.Unknown};default:throw Bi}}function Nu(e,t){if(e.length===0)return{status:Ui.Found,value:t};const n=V0(e),r=Gs(n,t);switch(r.status){case Je.Found:return Nu(e.slice(1),r.value);case Je.Unknown:return{status:Ui.Unknown};case Je.Absent:case Je.Greater:case Je.Less:return{status:Ui.Absent};default:throw Bi}}function Ru(e){switch(e[0]){case St.Empty:return[];case St.Fork:return Ru(e[1]).concat(Ru(e[2]));default:return[e]}}function Gs(e,t){switch(t[0]){case St.Labeled:return ab(e,t[1])?{status:Je.Greater}:tc(e,t[1])?{status:Je.Found,value:t[2]}:{status:Je.Less};case St.Fork:{const n=Gs(e,t[1]);switch(n.status){case Je.Greater:{const r=Gs(e,t[2]);return r.status===Je.Less?{status:Je.Absent}:r}case Je.Unknown:{const r=Gs(e,t[2]);return r.status===Je.Less?{status:Je.Unknown}:r}default:return n}}case St.Pruned:return{status:Je.Unknown};default:return{status:Je.Absent}}}function D0(e){const{canisterId:t,subnetId:n,tree:r}=e,i=Ks(["subnet",n.toUint8Array(),"canister_ranges"],r);if(i.status!==rn.Found)throw ot.fromCode(new xi(`Could not find canister ranges for subnet ${n.toText()}`,i.status));if(!(i.value instanceof Uint8Array))throw ot.fromCode(new Ko(`Could not find canister ranges for subnet ${n.toText()}`));return _n(i.value).map(a=>[Le.fromUint8Array(a[0]),Le.fromUint8Array(a[1])]).some(a=>a[0].ltEq(t)&&a[1].gtEq(t))}const j0=async e=>{const{agent:t,paths:n,disableCertificateTimeVerification:r=!1}=e,i=Le.from(e.canisterId),s=[...new Set(n)],o=new Map,c=s.map((a,u)=>{const l=db(a,i);return(async()=>{try{if(t.rootKey===null)throw Lt.fromCode(new Ti);const h=t.rootKey,y=await t.readState(i,{paths:[l]}),p=await Qr.create({certificate:y.certificate,rootKey:h,canisterId:i,disableTimeVerification:r,agent:t}),m=(x,_)=>{if(_==="subnet"){const w=lb(y.certificate,i,h);return{path:_,data:w}}else return{path:_,data:Wt(x.lookup_path(l))}},{path:g,data:E}=m(p,s[u]);if(!E)console.warn(`Expected to find result for path ${g}, but instead found nothing.`),typeof g=="string"?o.set(g,null):o.set(g.key,null);else switch(g){case"time":{o.set(g,Ou(E));break}case"controllers":{o.set(g,hb(E));break}case"module_hash":{o.set(g,ze(E));break}case"subnet":{o.set(g,E);break}case"candid":{o.set(g,new TextDecoder().decode(E));break}default:if(typeof g!="string"&&"key"in g&&"path"in g)switch(g.decodeStrategy){case"raw":o.set(g.key,E);break;case"leb128":{o.set(g.key,M0(E));break}case"cbor":{o.set(g.key,_n(E));break}case"hex":{o.set(g.key,ze(E));break}case"utf-8":o.set(g.key,new TextDecoder().decode(E))}}}catch(h){if(h instanceof Fn&&(h.hasCode(Si)||h.hasCode(Bs)))throw h;typeof a!="string"&&"key"in a&&"path"in a?o.set(a.key,null):o.set(a,null),console.group(),console.warn(`Expected to find result for path ${a}, but instead found nothing.`),console.warn(h),console.groupEnd()}})()});return await Promise.all(c),o},lb=(e,t,n)=>{if(!t._isPrincipal)throw Xe.fromCode(new fn("Invalid canisterId"));const r=_n(e),i=r.tree;let s=r.delegation,o;if(s&&s.subnet_id?o=Le.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof n<"u"?(o=Le.selfAuthenticating(new Uint8Array(n)),s={subnet_id:o.toUint8Array(),certificate:new Uint8Array(0)}):(o=Le.selfAuthenticating(Le.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:o.toUint8Array(),certificate:new Uint8Array(0)}),!D0({canisterId:t,subnetId:o,tree:i}))throw tn.fromCode(new $o(t,o));const a=Nu(["subnet",s.subnet_id,"node"],i);if(a.status!==Ui.Found)throw ot.fromCode(new xi("Node not found",a.status));if(a.value instanceof Uint8Array)throw Vt.fromCode(new Os("Invalid node tree"));const u=Ru(a.value),l=new Map;return u.forEach(h=>{const y=Le.from(h[1]).toText(),p=Ks(["public_key"],h[2]);if(p.status!==rn.Found)throw ot.fromCode(new xi("Public key not found",p.status));const m=p.value;if(m.byteLength!==44)throw ot.fromCode(new Go(44,m.byteLength));l.set(y,m)}),{subnetId:Le.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:l}},db=(e,t)=>{const n=t.toUint8Array();switch(e){case"time":return[rt("time")];case"controllers":return[rt("canister"),n,rt("controllers")];case"module_hash":return[rt("canister"),n,rt("module_hash")];case"subnet":return[rt("subnet")];case"candid":return[rt("canister"),n,rt("metadata"),rt("candid:service")];default:if("key"in e&&"path"in e)if(typeof e.path=="string"||e.path instanceof Uint8Array){const r=e.path,i=typeof r=="string"?rt(r):r;return[rt("canister"),n,rt("metadata"),i]}else return e.path}throw Vt.fromCode(new fn(`Error while encoding your path for canister status. Please ensure that your path ${e} was formatted correctly.`))},hb=e=>_n(e).map(n=>Le.fromUint8Array(n));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Er=BigInt(0),yt=BigInt(1),ku=BigInt(2),pb=BigInt(8);function yb(e,t,n,r){const i=e.sqr(n),s=e.sqr(r),o=e.add(e.mul(t.a,i),s),c=e.add(e.ONE,e.mul(t.d,e.mul(i,s)));return e.eql(o,c)}function mb(e,t={}){const n=T0("edwards",e,t,t.FpFnLE),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o}=s;qs(t,{},{uvRatio:"function"});const c=ku<<BigInt(i.BYTES*8)-yt,a=E=>r.create(E),u=t.uvRatio||((E,x)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,x))}}catch{return{isValid:!1,value:Er}}});if(!yb(r,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(E,x,_=!1){const w=_?yt:Er;return i0("coordinate "+E,x,w,c),x}function h(E){if(!(E instanceof m))throw new Error("ExtendedPoint expected")}const y=Ms((E,x)=>{const{X:_,Y:w,Z:T}=E,R=E.is0();x==null&&(x=R?pb:r.inv(T));const B=a(_*x),P=a(w*x),q=r.mul(T,x);if(R)return{x:Er,y:yt};if(q!==yt)throw new Error("invZ was invalid");return{x:B,y:P}}),p=Ms(E=>{const{a:x,d:_}=s;if(E.is0())throw new Error("bad point: ZERO");const{X:w,Y:T,Z:R,T:B}=E,P=a(w*w),q=a(T*T),v=a(R*R),C=a(v*v),L=a(P*x),K=a(v*a(L+q)),U=a(C+a(_*a(P*q)));if(K!==U)throw new Error("bad point: equation left != right (1)");const D=a(w*T),k=a(R*B);if(D!==k)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(x,_,w,T){this.X=l("x",x),this.Y=l("y",_),this.Z=l("z",w,!0),this.T=l("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof m)throw new Error("extended point not allowed");const{x:_,y:w}=x||{};return l("x",_),l("y",w),new m(_,w,yt,a(_*w))}static fromBytes(x,_=!1){const w=r.BYTES,{a:T,d:R}=s;x=n0(Ri(x,w,"point")),Us(_,"zip215");const B=n0(x),P=x[w-1];B[w-1]=P&-129;const q=Hs(B),v=_?c:r.ORDER;i0("point.y",q,Er,v);const C=a(q*q),L=a(C-yt),K=a(R*C-T);let{isValid:U,value:D}=u(L,K);if(!U)throw new Error("bad point: invalid y coordinate");const k=(D&yt)===yt,j=(P&128)!==0;if(!_&&D===Er&&j)throw new Error("bad point: x=0 and x_0=1");return j!==k&&(D=a(-D)),m.fromAffine({x:D,y:q})}static fromHex(x,_=!1){return m.fromBytes(Dt("point",x),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,_=!0){return g.createCache(this,x),_||this.multiply(ku),this}assertValidity(){p(this)}equals(x){h(x);const{X:_,Y:w,Z:T}=this,{X:R,Y:B,Z:P}=x,q=a(_*P),v=a(R*T),C=a(w*P),L=a(B*T);return q===v&&C===L}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.X),this.Y,this.Z,a(-this.T))}double(){const{a:x}=s,{X:_,Y:w,Z:T}=this,R=a(_*_),B=a(w*w),P=a(ku*a(T*T)),q=a(x*R),v=_+w,C=a(a(v*v)-R-B),L=q+B,K=L-P,U=q-B,D=a(C*K),k=a(L*U),j=a(C*U),F=a(K*L);return new m(D,k,F,j)}add(x){h(x);const{a:_,d:w}=s,{X:T,Y:R,Z:B,T:P}=this,{X:q,Y:v,Z:C,T:L}=x,K=a(T*q),U=a(R*v),D=a(P*w*L),k=a(B*C),j=a((T+R)*(q+v)-K-U),F=k-D,S=k+D,I=a(U-_*K),M=a(j*F),O=a(S*I),V=a(j*I),G=a(F*S);return new m(M,O,G,V)}subtract(x){return this.add(x.negate())}multiply(x){if(!i.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:_,f:w}=g.cached(this,x,T=>Mn(m,T));return Mn(m,[_,w])[0]}multiplyUnsafe(x,_=m.ZERO){if(!i.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===Er?m.ZERO:this.is0()||x===yt?this:g.unsafe(this,x,w=>Mn(m,w),_)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.unsafe(this,s.n).is0()}toAffine(x){return y(this,x)}clearCofactor(){return o===yt?this:this.multiplyUnsafe(o)}toBytes(){const{x,y:_}=this.toAffine(),w=r.toBytes(_);return w[w.length-1]|=x&yt?128:0,w}toHex(){return ze(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return Mn(m,x)}static msm(x,_){return S0(m,i,x,_)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}m.BASE=new m(s.Gx,s.Gy,yt,a(s.Gx*s.Gy)),m.ZERO=new m(Er,yt,yt,Er),m.Fp=r,m.Fn=i;const g=new _0(m,i.BITS);return m.BASE.precompute(8),m}function gb(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');qs(n,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=n,{BASE:i,Fp:s,Fn:o}=e,c=n.randomBytes||dd,a=n.adjustScalarBytes||(v=>v),u=n.domain||((v,C,L)=>{if(Us(L,"phflag"),C.length||L)throw new Error("Contexts/pre-hash are not supported");return v});function l(v){return o.create(Hs(v))}function h(v){const C=w.secretKey;v=Dt("private key",v,C);const L=Dt("hashed private key",t(v),2*C),K=a(L.slice(0,C)),U=L.slice(C,2*C),D=l(K);return{head:K,prefix:U,scalar:D}}function y(v){const{head:C,prefix:L,scalar:K}=h(v),U=i.multiply(K),D=U.toBytes();return{head:C,prefix:L,scalar:K,point:U,pointBytes:D}}function p(v){return y(v).pointBytes}function m(v=Uint8Array.of(),...C){const L=qe(...C);return l(t(u(L,Dt("context",v),!!r)))}function g(v,C,L={}){v=Dt("message",v),r&&(v=r(v));const{prefix:K,scalar:U,pointBytes:D}=y(C),k=m(L.context,K,v),j=i.multiply(k).toBytes(),F=m(L.context,j,D,v),S=o.create(k+F*U);if(!o.isValid(S))throw new Error("sign failed: invalid s");const I=qe(j,o.toBytes(S));return Ri(I,w.signature,"result")}const E={zip215:!0};function x(v,C,L,K=E){const{context:U,zip215:D}=K,k=w.signature;v=Dt("signature",v,k),C=Dt("message",C),L=Dt("publicKey",L,w.publicKey),D!==void 0&&Us(D,"zip215"),r&&(C=r(C));const j=k/2,F=v.subarray(0,j),S=Hs(v.subarray(j,k));let I,M,O;try{I=e.fromBytes(L,D),M=e.fromBytes(F,D),O=i.multiplyUnsafe(S)}catch{return!1}if(!D&&I.isSmallOrder())return!1;const V=m(U,M.toBytes(),I.toBytes(),C);return M.add(I.multiplyUnsafe(V)).subtract(O).clearCofactor().is0()}const _=s.BYTES,w={secretKey:_,publicKey:_,signature:2*_,seed:_};function T(v=c(w.seed)){return Ri(v,w.seed,"seed")}function R(v){const C=q.randomSecretKey(v);return{secretKey:C,publicKey:p(C)}}function B(v){return ps(v)&&v.length===o.BYTES}function P(v,C){try{return!!e.fromBytes(v,C)}catch{return!1}}const q={getExtendedPublicKey:y,randomSecretKey:T,isValidSecretKey:B,isValidPublicKey:P,toMontgomery(v){const{y:C}=e.fromBytes(v),L=w.publicKey,K=L===32;if(!K&&L!==57)throw new Error("only defined for 25519 and 448");const U=K?s.div(yt+C,yt-C):s.div(C-yt,C+yt);return s.toBytes(U)},toMontgomeryPriv(v){const C=w.secretKey;Ri(v,C);const L=t(v.subarray(0,C));return a(L).subarray(0,C)},randomPrivateKey:T,precompute(v=8,C=e.BASE){return C.precompute(v,!1)}};return Object.freeze({keygen:R,getPublicKey:p,sign:g,verify:x,utils:q,Point:e,lengths:w})}function wb(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=gr(t.n,e.nBitLength,!0),i={Fp:n,Fn:r,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:i,hash:e.hash,eddsaOpts:s}}function bb(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function Eb(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:i}=wb(e),s=mb(t,n),o=gb(s,r,i);return bb(e,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _b=BigInt(1),$0=BigInt(2);BigInt(3);const Sb=BigInt(5),xb=BigInt(8),Pu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),K0={p:Pu,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xb,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Tb(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=Pu,c=e*e%s*e%s,a=xn(c,$0,s)*c%s,u=xn(a,_b,s)*e%s,l=xn(u,Sb,s)*u%s,h=xn(l,t,s)*l%s,y=xn(h,n,s)*h%s,p=xn(y,r,s)*y%s,m=xn(p,i,s)*p%s,g=xn(m,i,s)*p%s,E=xn(g,t,s)*l%s;return{pow_p_5_8:xn(E,$0,s)*e%s,b2:c}}function vb(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const G0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bb(e,t){const n=Pu,r=ct(t*t*t,n),i=ct(r*r*t,n),s=Tb(e*i).pow_p_5_8;let o=ct(e*r*s,n);const c=ct(t*o*o,n),a=o,u=ct(o*G0,n),l=c===e,h=c===ct(-e,n),y=c===ct(-e*G0,n);return l&&(o=a),(h||y)&&(o=u),hw(o,n)&&(o=ct(-o,n)),{isValid:l||h,value:o}}const Ab=gr(K0.p,{isLE:!0}),Ib={...K0,Fp:Ab,hash:jm,adjustScalarBytes:vb,uvRatio:Bb},Ob=Eb(Ib);var W0,X0;class Nb{constructor(t={}){Kt(this,Tt);Kt(this,Ki);this[W0]=this.entries.bind(this),this[X0]="ExpirableMap";const{source:n=[],expirationTime:r=600*1e3}=t,i=Date.now();Ht(this,Tt,new Map([...n].map(([s,o])=>[s,{value:o,timestamp:i}]))),Ht(this,Ki,r)}prune(){const t=Date.now();for(const[n,r]of Ce(this,Tt).entries())t-r.timestamp>Ce(this,Ki)&&Ce(this,Tt).delete(n);return this}set(t,n){this.prune();const r={value:n,timestamp:Date.now()};return Ce(this,Tt).set(t,r),this}get(t){const n=Ce(this,Tt).get(t);if(n!==void 0){if(Date.now()-n.timestamp>Ce(this,Ki)){Ce(this,Tt).delete(t);return}return n.value}}clear(){Ce(this,Tt).clear()}entries(){const t=Ce(this,Tt).entries();return function*(){for(const[r,i]of t)yield[r,i.value]}()}values(){const t=Ce(this,Tt).values();return function*(){for(const r of t)yield r.value}()}keys(){return Ce(this,Tt).keys()}forEach(t,n){for(const[r,i]of Ce(this,Tt).entries())t.call(n,i.value,r,this)}has(t){return Ce(this,Tt).has(t)}delete(t){return Ce(this,Tt).delete(t)}get size(){return Ce(this,Tt).size}}Tt=new WeakMap,Ki=new WeakMap,W0=Symbol.iterator,X0=Symbol.toStringTag;const z0=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw Xe.fromCode(new Wo("Length too long (> 4 bytes)"))},Y0=(e,t,n)=>{if(n<=127)return e[t]=n,1;if(n<=255)return e[t]=129,e[t+1]=n,2;if(n<=65535)return e[t]=130,e[t+1]=n>>8,e[t+2]=n,3;if(n<=16777215)return e[t]=131,e[t+1]=n>>16,e[t+2]=n>>8,e[t+3]=n,4;throw Xe.fromCode(new Wo("Length too long (> 4 bytes)"))},Cu=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw Xe.fromCode(new qn("Invalid length 0"));if(e[t]===129)return 2;if(e[t]===130)return 3;if(e[t]===131)return 4;throw Xe.fromCode(new qn("Length too long (> 4 bytes)"))},Rb=(e,t)=>{const n=Cu(e,t);if(n===1)return e[t];if(n===2)return e[t+1];if(n===3)return(e[t+1]<<8)+e[t+2];if(n===4)return(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];throw Xe.fromCode(new qn("Length too long (> 4 bytes)"))};Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]);const Z0=Uint8Array.from([48,5,6,3,43,101,112]);Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),Uint8Array.from([48,29,6,13,43,6,1,4,1,130,220,124,5,3,1,2,1,6,12,43,6,1,4,1,130,220,124,5,3,2,1]);function kb(e,t){const n=2+z0(e.byteLength+1),r=t.byteLength+n+e.byteLength;let i=0;const s=new Uint8Array(1+z0(r)+r);return s[i++]=48,i+=Y0(s,i,r),s.set(t,i),i+=t.byteLength,s[i++]=3,i+=Y0(s,i,e.byteLength+1),s[i++]=0,s.set(new Uint8Array(e),i),s}const Pb=(e,t)=>{let n=0;const r=(c,a)=>{if(i[n++]!==c)throw Xe.fromCode(new qn(`Expected ${a} at offset ${n}`))},i=new Uint8Array(e);if(r(48,"sequence"),n+=Cu(i,n),!tc(i.slice(n,n+t.byteLength),t))throw Xe.fromCode(new qn("Not the expected OID."));n+=t.byteLength,r(3,"bit string");const s=Rb(i,n)-1;n+=Cu(i,n),r(0,"0 padding");const o=i.slice(n);if(s!==o.length)throw Xe.fromCode(new $a(s,o.length));return o},si=class si{constructor(t){Kt(this,Zs);Kt(this,Js);if(t.byteLength!==si.RAW_KEY_LENGTH)throw Xe.fromCode(new qn("An Ed25519 public key must be exactly 32 bytes long"));Ht(this,Zs,t),Ht(this,Js,si.derEncode(t))}static from(t){return this.fromDer(t.toDer())}static fromRaw(t){return new si(t)}static fromDer(t){return new si(this.derDecode(t))}static derEncode(t){return kb(t,Z0)}static derDecode(t){const n=Pb(t,Z0);if(n.length!==this.RAW_KEY_LENGTH)throw Xe.fromCode(new qn("An Ed25519 public key must be exactly 32 bytes long"));return n}get rawKey(){return Ce(this,Zs)}get derKey(){return Ce(this,Js)}toDer(){return this.derKey}toRaw(){return this.rawKey}};Zs=new WeakMap,Js=new WeakMap,si.RAW_KEY_LENGTH=32;let Uu=si;class Cb{constructor(){this.observers=[]}subscribe(t){this.observers.push(t)}unsubscribe(t){this.observers=this.observers.filter(n=>n!==t)}notify(t,...n){this.observers.forEach(r=>r(t,...n))}}class Ub extends Cb{constructor(){super()}print(t,...n){this.notify({message:t,level:"info"},...n)}warn(t,...n){this.notify({message:t,level:"warn"},...n)}error(t,n,...r){this.notify({message:t,level:"error",error:n},...r)}}const J0=.5,Q0=1.5,ep=500,tp=6e4,np=9e5,rp=10,Uc=class Uc{constructor(t=Uc.default){Kt(this,gn);Kt(this,Qs);Kt(this,eo);Kt(this,to);Kt(this,no);Kt(this,ro);Kt(this,io);Kt(this,so);Kt(this,Gi,0);const{initialInterval:n=ep,randomizationFactor:r=J0,multiplier:i=Q0,maxInterval:s=tp,maxElapsedTime:o=np,maxIterations:c=rp,date:a=Date}=t;Ht(this,gn,n),Ht(this,Qs,r),Ht(this,eo,i),Ht(this,to,s),Ht(this,so,a),Ht(this,no,a.now()),Ht(this,ro,o),Ht(this,io,c)}get ellapsedTimeInMsec(){return Ce(this,so).now()-Ce(this,no)}get currentInterval(){return Ce(this,gn)}get count(){return Ce(this,Gi)}get randomValueFromInterval(){const t=Ce(this,Qs)*Ce(this,gn),n=Ce(this,gn)-t,r=Ce(this,gn)+t;return Math.random()*(r-n)+n}incrementCurrentInterval(){return Ht(this,gn,Math.min(Ce(this,gn)*Ce(this,eo),Ce(this,to))),ly(this,Gi)._++,Ce(this,gn)}next(){return this.ellapsedTimeInMsec>=Ce(this,ro)||Ce(this,Gi)>=Ce(this,io)?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};gn=new WeakMap,Qs=new WeakMap,eo=new WeakMap,to=new WeakMap,no=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,Gi=new WeakMap,Uc.default={initialInterval:ep,randomizationFactor:J0,multiplier:Q0,maxInterval:tp,maxElapsedTime:np,maxIterations:rp,date:Date};let Hu=Uc;var Dn;(function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"})(Dn||(Dn={}));const Fu=60*1e3,Hb=1e6,Fb=0,qb="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",Mb="ic0.app",Lb=".ic0.app",Vb="icp0.io",Db=".icp0.io",jb="icp-api.io",$b=".icp-api.io",qu=200,Kb=202,Gb=404;function Wb(){let e;if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw Lt.fromCode(new Is("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof global<"u")if(global.fetch)e=global.fetch.bind(global);else throw Lt.fromCode(new Is("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(e=self.fetch.bind(self));if(e)return e;throw Lt.fromCode(new Is("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function Xb(e){let t;if(e!==void 0)!e.match(/^[a-z]+:/)&&typeof window<"u"?t=new URL(window.location.protocol+"//"+e):t=new URL(e);else{const n=["ic0.app","icp0.io","127.0.0.1","localhost"],r=[".github.dev",".gitpod.io"],i=typeof window<"u"?window.location:void 0,s=i?.hostname;let o;s&&typeof s=="string"&&(r.some(c=>s.endsWith(c))?o=s:o=n.find(c=>s.endsWith(c))),i&&o?t=new URL(`${i.protocol}//${o}${i.port?":"+i.port:""}`):t=new URL("https://icp-api.io")}return t.toString()}class jn{#t;#e;#i;#m;#a;#w;#n;#s;#g;#b;#r;#c;#u;#o;get#x(){return this.#o*Fu}#f;#l;#d;#h;constructor(t={}){this.#t=null,this.#e=!1,this.#i=Fb,this.#m=!1,this.#a=null,this.#w=!1,this._isAgent=!0,this.config={},this.log=new Ub,this.#f=[],this.#l=[],this.#d=new Nb({expirationTime:5*Fu}),this.#h=!0,this.#_=(i,s)=>{if(this.#h===!1)return i;const{status:o,signatures:c=[],requestId:a}=i;for(const u of c){const{timestamp:l,identity:h}=u,y=Le.fromUint8Array(h).toText();let p;if(o===Ei.Replied){const{reply:_}=i;p=nc({status:o,reply:_,timestamp:BigInt(l),request_id:a})}else if(o===Ei.Rejected){const{reject_code:_,reject_message:w,error_code:T}=i;p=nc({status:o,reject_code:_,reject_message:w,error_code:T,timestamp:BigInt(l),request_id:a})}else throw Vt.fromCode(new fn(`Unknown status: ${o}`));const m=qe(I1,p),g=s.nodeKeys.get(y);if(!g)throw ot.fromCode(new tu);const E=Uu.fromDer(g).rawKey;if(Ob.verify(u.signature,m,E))return i;throw tn.fromCode(new nu(y))}return i},this.config=t,this.#s=t.fetch||Wb()||fetch.bind(global),this.#g=t.fetchOptions,this.#b=t.callOptions,this.#e=t.shouldFetchRootKey??!1,this.#w=t.shouldSyncTime??!1,t.rootKey?this.rootKey=t.rootKey:this.#e?this.rootKey=null:this.rootKey=ms(qb);const n=Xb(t.host);this.host=new URL(n),t.verifyQuerySignatures!==void 0&&(this.#h=t.verifyQuerySignatures),this.#c=t.retryTimes??3;const r=()=>new Hu({maxIterations:this.#c});if(this.#u=t.backoffStrategy||r,this.host.hostname.endsWith(Lb)?this.host.hostname=Mb:this.host.hostname.endsWith(Db)?this.host.hostname=Vb:this.host.hostname.endsWith($b)&&(this.host.hostname=jb),t.credentials){const{name:i,password:s}=t.credentials;this.#r=`${i}${s?":"+s:""}`}if(this.#n=Promise.resolve(t.identity||new Dh),t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes>5)throw Xe.fromCode(new vi("The maximum ingress expiry time is 5 minutes.",t.ingressExpiryInMinutes));if(t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes<=0)throw Xe.fromCode(new vi("Ingress expiry time must be greater than 0.",t.ingressExpiryInMinutes));this.#o=t.ingressExpiryInMinutes||5,this.addTransform("update",Qh(du)),t.useQueryNonces&&this.addTransform("query",Qh(du)),t.logToConsole&&this.log.subscribe(i=>{i.level==="error"?console.error(i.message):i.level==="warn"?console.warn(i.message):console.log(i.message)})}static createSync(t={}){return new this({...t})}static async create(t={}){const n=jn.createSync(t);return await n.#y(),n}static async from(t){try{return"config"in t?await jn.create(t.config):await jn.create({fetch:t._fetch,fetchOptions:t._fetchOptions,callOptions:t._callOptions,host:t._host.toString(),identity:t._identity??void 0})}catch{throw Xe.fromCode(new Ja)}}isLocal(){const t=this.host.hostname;return t==="127.0.0.1"||t.endsWith("127.0.0.1")}addTransform(t,n,r=n.priority||0){if(t==="update"){const i=this.#l.findIndex(s=>(s.priority||0)<r);this.#l.splice(i>=0?i:this.#l.length,0,Object.assign(n,{priority:r}))}else if(t==="query"){const i=this.#f.findIndex(s=>(s.priority||0)<r);this.#f.splice(i>=0?i:this.#f.length,0,Object.assign(n,{priority:r}))}}async getPrincipal(){if(!this.#n)throw Lt.fromCode(new jr);return(await this.#n).getPrincipal()}async call(t,n,r){const i=n.callSync??!0,s=await(r??this.#n);if(!s)throw Lt.fromCode(new jr);const o=Le.from(t),c=n.effectiveCanisterId?Le.from(n.effectiveCanisterId):o;await this.#y(c);const a=s.getPrincipal(),u=Mu(this.#o,this.#i),l={request_type:lu.Call,canister_id:o,method_name:n.methodName,arg:n.arg,sender:a,ingress_expiry:u};let h=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Gr.Call,body:l}),y;n?.nonce?y=p(n.nonce):h.body.nonce?y=p(h.body.nonce):y=void 0,l.nonce=y;function p(x){return Object.assign(x,{__nonce__:void 0})}h=await s.transformRequest(h);const m=fu(h.body),g=this.#u(),E=su(l);try{const w=i?()=>(this.log.print(`fetching "/api/v3/canister/${c.toText()}/call" with request:`,h),this.#s(""+new URL(`/api/v3/canister/${c.toText()}/call`,this.host),{...this.#b,...h.request,body:m})):()=>(this.log.print(`fetching "/api/v2/canister/${c.toText()}/call" with request:`,h),this.#s(""+new URL(`/api/v2/canister/${c.toText()}/call`,this.host),{...this.#b,...h.request,body:m})),{responseBodyBytes:T,...R}=await this.#p({requestFn:w,backoff:g,tries:0}),B=T.byteLength>0?_n(T):null;return{requestId:E,response:{...R,body:B},requestDetails:l}}catch(x){let _;if(x instanceof Fn){if(x.hasCode(Yo))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(t,{...n,callSync:!1},r);if(x.hasCode(vi)&&!this.#m)return await this.syncTime(o),this.call(o,n,r);x.code.requestContext={requestId:E,senderPubKey:h.body.sender_pubkey,senderSignature:h.body.sender_sig,ingressExpiry:h.body.content.ingress_expiry},_=x}else _=Vt.fromCode(new fn(x));throw this.log.error(`Error while making call: ${_.message}`,_),_}}async#E(t){const{ecid:n,transformedRequest:r,body:i,requestId:s,backoff:o,tries:c}=t,a=c===0?0:o.next();if(this.log.print(`fetching "/api/v2/canister/${n.toString()}/query" with tries:`,{tries:c,backoff:o,delay:a}),a===null)throw Vt.fromCode(new As(`Backoff strategy exhausted after ${c} attempts.`,s));a>0&&await new Promise(p=>setTimeout(p,a));let u;try{this.log.print(`fetching "/api/v2/canister/${n.toString()}/query" with request:`,r);const p=await this.#s(""+new URL(`/api/v2/canister/${n.toString()}/query`,this.host),{...this.#g,...r.request,body:i});if(p.status===qu)u={..._n(ec(await p.arrayBuffer())),httpDetails:{ok:p.ok,status:p.status,statusText:p.statusText,headers:pu(p.headers)},requestId:s};else throw ot.fromCode(new zo(p.status,p.statusText,pu(p.headers),await p.text()))}catch(p){if(c<this.#c)return this.log.warn(`Caught exception while attempting to make query:
67
+ ${p}
68
+ Retrying query.`),await this.#E({...t,tries:c+1});throw p instanceof Fn?p:jo.fromCode(new Zo(p))}if(!this.#h)return u;const l=u.signatures?.[0]?.timestamp;if(!l)throw ot.fromCode(new Qa("Timestamp not found in query response. This suggests a malformed or malicious response."));const h=Number(BigInt(l)/BigInt(Hb));if(Date.now()+this.#i-h>this.#x){if(c<this.#c)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:s,signatureTimestampMs:h}),await this.#E({...t,tries:c+1});throw tn.fromCode(new Wa(this.#o,s,c))}return u}async#p(t){const{requestFn:n,backoff:r,tries:i}=t,s=i===0?0:r.next();if(s===null)throw ot.fromCode(new As(`Retry strategy exhausted after ${i} attempts.`));s>0&&await new Promise(l=>setTimeout(l,s));let o,c=new Uint8Array;try{o=await n(),o.status===qu&&(c=ec(await o.clone().arrayBuffer()))}catch(l){if(i<this.#c)return this.log.warn(`Caught exception while attempting to make request:
69
+ ${l}
70
+ Retrying request.`),await this.#p({requestFn:n,backoff:r,tries:i+1});throw jo.fromCode(new Zo(l))}const a=pu(o.headers);if(o.status===qu||o.status===Kb)return{ok:o.ok,status:o.status,statusText:o.statusText,responseBodyBytes:c,headers:a};const u=await o.text();if(o.status===Gb&&o.url.includes("api/v3"))throw ot.fromCode(new Yo);if(u.startsWith("Invalid request expiry: "))throw Xe.fromCode(new vi(u,this.#o));if(i<this.#c)return await this.#p({requestFn:n,backoff:r,tries:i+1});throw ot.fromCode(new zo(o.status,o.statusText,a,u))}async query(t,n,r){const i=this.#u(),s=n.effectiveCanisterId?Le.from(n.effectiveCanisterId):Le.from(t);await this.#y(s),this.log.print(`ecid ${s.toString()}`),this.log.print(`canisterId ${t.toString()}`);let o;const c=await(r??this.#n);if(!c)throw Lt.fromCode(new jr);const a=Le.from(t),u=c.getPrincipal(),l=Mu(this.#o,this.#i),h={request_type:Cs.Query,canister_id:a,method_name:n.methodName,arg:n.arg,sender:u,ingress_expiry:l},y=su(h);o=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Gr.Query,body:h}),o=await c.transformRequest(o);const p=fu(o.body),m={canister:a.toText(),ecid:s,transformedRequest:o,body:p,requestId:y,backoff:i,tries:0},g=async()=>{const x=await this.#E(m);return{requestDetails:h,...x}},E=async()=>{const x=this.#d.get(s.toString());if(x)return x;await this.fetchSubnetKeys(s.toString());const _=this.#d.get(s.toString());if(!_)throw tn.fromCode(new eu);return _};try{if(!this.#h)return await g();const[x,_]=await Promise.all([g(),E()]);try{return this.#_(x,_)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#d.delete(s.toString());const w=await E();return this.#_(x,w)}}catch(x){let _;throw x instanceof Fn?(x.code.requestContext={requestId:y,senderPubKey:o.body.sender_pubkey,senderSignature:o.body.sender_sig,ingressExpiry:o.body.content.ingress_expiry},_=x):_=Vt.fromCode(new fn(x)),this.log.error(`Error while making query: ${_.message}`,_),_}}#_;async createReadStateRequest(t,n){await this.#y();const r=await(n??this.#n);if(!r)throw Lt.fromCode(new jr);const i=r.getPrincipal(),s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Gr.ReadState,body:{request_type:Cs.ReadState,paths:t.paths,sender:i,ingress_expiry:Mu(this.#o,this.#i)}});return r.transformRequest(s)}async readState(t,n,r,i){await this.#S();const s=Le.from(t);function o(l){for(const h of l.paths){const[y,p]=h,m=new TextEncoder().encode("request_status");if(tc(y,m))return p}}let c,a;if(i)c=i,a=su(c);else{a=o(n);const l=await this.#n;if(!l)throw Lt.fromCode(new jr);c=await this.createReadStateRequest(n,l)}this.log.print(`fetching "/api/v2/canister/${s}/read_state" with request:`,c);const u=this.#u();try{const{responseBodyBytes:l}=await this.#p({requestFn:()=>this.#s(""+new URL(`/api/v2/canister/${s.toString()}/read_state`,this.host),{...this.#g,...c.request,body:fu(c.body)}),backoff:u,tries:0}),h=_n(l);return this.log.print("Read state response:",h),h}catch(l){let h;throw l instanceof Fn?(l.code.requestContext={requestId:a,senderPubKey:c.body.sender_pubkey,senderSignature:c.body.sender_sig,ingressExpiry:c.body.content.ingress_expiry},h=l):h=Vt.fromCode(new fn(l)),this.log.error(`Error while making read state: ${h.message}`,h),h}}parseTimeFromResponse(t){let n;if(t.certificate){const r=_n(t.certificate);if(r&&"tree"in r)n=r.tree;else throw ot.fromCode(new Os("Could not decode time from response"));const i=Ks(["time"],n);if(i.status!==rn.Found)throw ot.fromCode(new xi("Time was not found in the response or was not in its expected format.",i.status));if(!(i.value instanceof Uint8Array)&&!ArrayBuffer.isView(i))throw ot.fromCode(new Ko("Time was not in its expected format."));const s=Ou(i.value);return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",s.getTime()),s.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(t){this.#a=this.#a??(async()=>{await this.#S();const n=Date.now();try{t||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");const r=t??Le.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),i=jn.createSync({identity:new Dh,host:this.host.toString(),fetch:this.#s,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),o=(await Promise.all(Array(3).fill(null).map(async()=>{const a=(await j0({canisterId:r,agent:i,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(a instanceof Date)return a.getTime()},[]))).reduce((c,a)=>typeof a=="number"&&a>c?a:c,0);o>0&&(this.#i=o-n,this.#m=!0,this.log.notify({message:`Syncing time: offset of ${this.#i}`,level:"info"}))}catch(r){const i=r instanceof Fn?r:Vt.fromCode(new fn(r));throw this.log.error("Caught exception while attempting to sync time",i),i}})(),await this.#a.finally(()=>{this.#a=null})}async status(){const t=this.#r?{Authorization:"Basic "+btoa(this.#r)}:{};this.log.print('fetching "/api/v2/status"');const n=this.#u(),{responseBodyBytes:r}=await this.#p({backoff:n,requestFn:()=>this.#s(""+new URL("/api/v2/status",this.host),{headers:t,...this.#g}),tries:0});return _n(r)}async fetchRootKey(){return this.#t=this.#t??(async()=>{const t=await this.status();return this.rootKey=t.root_key,this.rootKey})(),await this.#t.finally(()=>{this.#t=null})}async#y(t){await Promise.all([this.#S(),this.#T(t)])}async#S(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#e)await this.fetchRootKey();else throw Lt.fromCode(new Ti(this.#e))}async#T(t){this.#w&&!this.hasSyncedTime()&&await this.syncTime(t)}invalidateIdentity(){this.#n=null}replaceIdentity(t){this.#n=Promise.resolve(t)}async fetchSubnetKeys(t){const n=Le.from(t);await this.#y(n);const i=(await j0({canisterId:n,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return this.#d.set(n.toText(),i),i}_transform(t){let n=Promise.resolve(t);if(t.endpoint===Gr.Call)for(const r of this.#l)n=n.then(i=>r(i).then(s=>s||i));else for(const r of this.#f)n=n.then(i=>r(i).then(s=>s||i));return n}getTimeDiffMsecs(){return this.#i}hasSyncedTime(){return this.#m}}function Mu(e,t){const n=e*Fu;return Ni.fromDeltaInMilliseconds(n,t)}const zb=300*1e3;function ip(){return e2(Zb(Yb(),1e3),Qb(1e3,1.2),Jb(zb))}function Yb(){let e=!0;return async()=>e?(e=!1,!0):!1}function Zb(e,t){return async(n,r,i)=>{if(await e(n,r,i))return new Promise(s=>setTimeout(s,t))}}function Jb(e){const t=Date.now()+e;return async(n,r,i)=>{if(Date.now()>t)throw ot.fromCode(new As(`Request timed out after ${e} msec`,r,i))}}function Qb(e,t){let n=e;return()=>new Promise(r=>setTimeout(()=>{n*=t,r()},n))}function e2(...e){return async(t,n,r)=>{for(const i of e)await i(t,n,r)}}const t2={strategy:ip(),preSignReadStateRequest:!1};function sp(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Lu(e,t){return e!==null&&typeof e=="object"&&sp(e,t)}function n2(e,t){return sp(e,t)&&typeof e[t]=="function"}function op(e){return Lu(e,"body")&&Lu(e.body,"content")&&e.body.content.request_type===Cs.ReadState&&Lu(e.body.content,"ingress_expiry")&&typeof e.body.content.ingress_expiry=="object"&&e.body.content.ingress_expiry!==null&&n2(e.body.content.ingress_expiry,"toHash")}async function cp(e,t,n,r={}){const i=[rt("request_status"),n];let s,o;if(r.preSignReadStateRequest??!1?(o=await r2({paths:[i],agent:e,pollingOptions:r}),s=await e.readState(t,{paths:[i]},void 0,o)):s=await e.readState(t,{paths:[i]}),e.rootKey==null)throw Lt.fromCode(new Ti);const a=await Qr.create({certificate:s.certificate,rootKey:e.rootKey,canisterId:t,blsVerify:r.blsVerify,agent:e}),u=Wt(a.lookup_path([...i,rt("status")]));let l;switch(typeof u>"u"?l=Dn.Unknown:l=new TextDecoder().decode(u),l){case Dn.Replied:return{reply:Wt(a.lookup_path([...i,"reply"])),certificate:a};case Dn.Received:case Dn.Unknown:case Dn.Processing:return await(r.strategy??ip())(t,n,l),cp(e,t,n,{...r,request:o});case Dn.Rejected:{const h=new Uint8Array(Wt(a.lookup_path([...i,"reject_code"])))[0],y=new TextDecoder().decode(Wt(a.lookup_path([...i,"reject_message"]))),p=Wt(a.lookup_path([...i,"error_code"])),m=p?new TextDecoder().decode(p):void 0;throw _i.fromCode(new Xo(n,h,y,m))}case Dn.Done:throw Vt.fromCode(new Ya(n))}throw Bi}async function r2(e){const{paths:t,agent:n,pollingOptions:r}=e;if(r.request&&op(r.request))return r.request;const i=await n.createReadStateRequest?.({paths:t},void 0);if(!op(i))throw Xe.fromCode(new ru(i));return i}const sn=Symbol.for("ic-agent-metadata");class wc{static agentOf(t){return t[sn].config.agent}static interfaceOf(t){return t[sn].service}static canisterIdOf(t){return Le.from(t[sn].config.canisterId)}static createActorClass(t,n){const r=t({IDL:tg});class i extends wc{constructor(o){if(!o.canisterId)throw Xe.fromCode(new Jo(o.canisterId));const c=typeof o.canisterId=="string"?Le.fromText(o.canisterId):o.canisterId;super({config:{...ap,...o,canisterId:c},service:r});for(const[a,u]of r._fields)n?.httpDetails&&u.annotations.push(Vu),n?.certificate&&u.annotations.push(up),this[a]=i2(this,a,u,o.blsVerify)}}return i}static createActor(t,n){if(!n.canisterId)throw Xe.fromCode(new Jo(n.canisterId));return new(this.createActorClass(t))(n)}static createActorWithHttpDetails(t,n){return new(this.createActorClass(t,{httpDetails:!0}))(n)}static createActorWithExtendedDetails(t,n,r={httpDetails:!0,certificate:!0}){return new(this.createActorClass(t,r))(n)}constructor(t){this[sn]=Object.freeze(t)}}function Hi(e,t){const n=Nd(e,t);switch(n.length){case 0:return;case 1:return n[0];default:return n}}const ap={pollingOptions:t2},Vu="http-details",up="certificate";function i2(e,t,n,r){let i;n.annotations.includes("query")||n.annotations.includes("composite_query")?i=async(o,...c)=>{o={...o,...e[sn].config.queryTransform?.(t,c,{...e[sn].config,...o})};const a=o.agent||e[sn].config.agent||new jn,u=Le.from(o.canisterId||e[sn].config.canisterId),l=va(n.argTypes,c),h=await a.query(u,{methodName:t,arg:l,effectiveCanisterId:o.effectiveCanisterId}),y={...h.httpDetails,requestDetails:h.requestDetails};switch(h.status){case Ei.Rejected:{const p=new Xa(h.requestId,h.reject_code,h.reject_message,h.error_code,h.signatures);throw p.callContext={canisterId:u,methodName:t,httpDetails:y},_i.fromCode(p)}case Ei.Replied:return n.annotations.includes(Vu)?{httpDetails:y,result:Hi(n.retTypes,h.reply.arg)}:Hi(n.retTypes,h.reply.arg)}}:i=async(o,...c)=>{o={...o,...e[sn].config.callTransform?.(t,c,{...e[sn].config,...o})};const a=o.agent||e[sn].config.agent||jn.createSync(),{canisterId:u,effectiveCanisterId:l,pollingOptions:h}={...ap,...e[sn].config,...o},y=Le.from(u),p=l!==void 0?Le.from(l):y,m=va(n.argTypes,c),{requestId:g,response:E,requestDetails:x}=await a.call(y,{methodName:t,arg:m,effectiveCanisterId:p,nonce:o.nonce});let _,w;if(A1(E.body)){if(a.rootKey==null)throw Lt.fromCode(new Ti);const P=E.body.certificate;w=await Qr.create({certificate:P,rootKey:a.rootKey,canisterId:Le.from(u),blsVerify:r,agent:a});const q=[rt("request_status"),g];switch(new TextDecoder().decode(Wt(w.lookup_path([...q,"status"])))){case"replied":_=Wt(w.lookup_path([...q,"reply"]));break;case"rejected":{const C=new Uint8Array(Wt(w.lookup_path([...q,"reject_code"])))[0],L=new TextDecoder().decode(Wt(w.lookup_path([...q,"reject_message"]))),K=Wt(w.lookup_path([...q,"error_code"])),U=K?new TextDecoder().decode(K):void 0,D=new Xo(g,C,L,U);throw D.callContext={canisterId:y,methodName:t,httpDetails:E},_i.fromCode(D)}}}else if(B1(E.body)){const{reject_code:P,reject_message:q,error_code:v}=E.body,C=new za(g,P,q,v);throw C.callContext={canisterId:y,methodName:t,httpDetails:E},_i.fromCode(C)}if(E.status===202){const P={...h,blsVerify:r},q=await cp(a,p,g,P);w=q.certificate,_=q.reply}const T=n.annotations.includes(Vu),R=n.annotations.includes(up),B={...E,requestDetails:x};if(_!==void 0)return T&&R?{httpDetails:B,certificate:w,result:Hi(n.retTypes,_)}:R?{certificate:w,result:Hi(n.retTypes,_)}:T?{httpDetails:B,result:Hi(n.retTypes,_)}:Hi(n.retTypes,_);{const P=new fn(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${n.retTypes.map(q=>q.display()).join(",")}].`);throw P.callContext={canisterId:y,methodName:t,httpDetails:B},Vt.fromCode(P)}};const s=(...o)=>i({},...o);return s.withOptions=o=>(...c)=>i(o,...c),s}var ei={},$e={},ti={},fp;function s2(){if(fp)return ti;fp=1,Object.defineProperty(ti,"__esModule",{value:!0}),ti.base26Decode=ti.base26Encode=void 0;function e(n){let r=0n;for(let i=0;i<n.length;i++){const s=BigInt(n.charCodeAt(i)-65),o=BigInt(n.length)-1n-BigInt(i);if(o==0n)r+=s;else{const c=26n**o;r+=c*(s+1n)}}return r}ti.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let r=[];for(;n>0;){const i=(n-1n)%26n;r.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(i))),n=(n-1n)/26n}return r.reverse().join("")}return ti.base26Decode=t,ti}var ni={},lp;function dp(){if(lp)return ni;lp=1,Object.defineProperty(ni,"__esModule",{value:!0}),ni.none=ni.some=void 0;class e{constructor(){}isSome(){return!1}map(s){return new e}value(){return null}}class t{constructor(s){this._value=s}isSome(){return!0}map(s){return new t(s(this.value()))}value(){return this._value}}function n(i){return new t(i)}ni.some=n;function r(){return new e}return ni.none=r,ni}var ri={},hp;function o2(){if(hp)return ri;hp=1,Object.defineProperty(ri,"__esModule",{value:!0}),ri.decodeLEB128=ri.encodeLEB128=void 0;function e(n){const r=[];let i=!0;for(;i;){let s=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?i=!1:s|=128,r.push(s)}return r}ri.encodeLEB128=e;function t(n){let r=BigInt(0);for(let i=0;i<n.length;i++){const s=BigInt(n[i]);if(i>18)throw new Error("Overlong");let o=s&BigInt(127);if(i==18&&(o&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(r|=o<<BigInt(7)*BigInt(i),(s&BigInt(128))==BigInt(0))return{n:r,len:i+1}}throw new Error("Unterminated")}return ri.decodeLEB128=t,ri}var Du={},pp;function c2(){return pp||(pp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=s=>s.length%2===1?"0"+s:s;e.zero2=t;const n=s=>{let o="";for(let c=0;c<s.length;c++)o+=(0,e.zero2)(s[c].toString(16));return o};e.toHex=n;function r(s,o){const c=[];let a=0;for(;a<s.length;){const u=s.slice(a,a+o);c.push(u),a+=o}return c}e.chunks=r;function i(s){const o=[],c=s.length;if(c<76){const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=255){o.push(Buffer.from("4c","hex"));const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=65535){o.push(Buffer.from("4d","hex"));const a=Buffer.alloc(2);a.writeUint16LE(c),o.push(a)}else{o.push(Buffer.from("4e","hex"));const a=Buffer.alloc(4);a.writeUint32LE(c),o.push(a)}return o.push(s),Buffer.concat(o)}e.toPushData=i})(Du)),Du}var $n={},yp;function mp(){if(yp)return $n;yp=1,Object.defineProperty($n,"__esModule",{value:!0}),$n.removeSpacers=$n.getSpacersVal=$n.applySpacers=void 0;function e(r,i){let s="";for(let o=0;o<r.length;o++)s+=r.charAt(o),i>0&&((i&1)===1&&(s+="•"),i>>=1);return s}$n.applySpacers=e;function t(r){let i=0,s=0;for(let o=0;o<r.length;o++)r.charAt(o)==="•"&&(i+=1<<o-1-s,s++);return i}$n.getSpacersVal=t;function n(r){return r.replace(/[•]+/g,"")}return $n.removeSpacers=n,$n}var gp;function a2(){if(gp)return $e;gp=1,Object.defineProperty($e,"__esModule",{value:!0}),$e.EtchInscription=$e.Message=$e.Runestone=$e.Etching=$e.Rune=$e.Terms=$e.Range=$e.Flaw=$e.Tag=$e.Flag=$e.Edict=$e.RuneId=void 0;const e=zl(),t=s2(),n=dp(),r=o2(),i=c2(),s=mp();class o{constructor(w,T){this.block=w,this.idx=T}next(w,T){if(w>BigInt(Number.MAX_SAFE_INTEGER)||T>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let R=BigInt(this.block)+w;if(R>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let B=w===0n?BigInt(this.idx)+T:T;return B>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new o(Number(R),Number(B)))}}$e.RuneId=o;class c{constructor(w,T,R){this.id=w,this.amount=T,this.output=R}static from_integers(w,T,R,B){return B>4294967295n||B<0n||Number(B)>w.outs.length?(0,n.none)():(0,n.some)(new c(T,R,Number(B)))}}$e.Edict=c;var a;(function(_){_[_.Etching=0]="Etching",_[_.Terms=1]="Terms",_[_.Turbo=2]="Turbo",_[_.Cenotaph=127]="Cenotaph"})(a||($e.Flag=a={}));var u;(function(_){_[_.Body=0]="Body",_[_.Flags=2]="Flags",_[_.Rune=4]="Rune",_[_.Premine=6]="Premine",_[_.Cap=8]="Cap",_[_.Amount=10]="Amount",_[_.HeightStart=12]="HeightStart",_[_.HeightEnd=14]="HeightEnd",_[_.OffsetStart=16]="OffsetStart",_[_.OffsetEnd=18]="OffsetEnd",_[_.Mint=20]="Mint",_[_.Pointer=22]="Pointer",_[_.Cenotaph=126]="Cenotaph",_[_.Divisibility=1]="Divisibility",_[_.Spacers=3]="Spacers",_[_.Symbol=5]="Symbol",_[_.Nop=127]="Nop"})(u||($e.Tag=u={}));var l;(function(_){_[_.EdictOutput=0]="EdictOutput",_[_.EdictRuneId=1]="EdictRuneId",_[_.InvalidScript=2]="InvalidScript",_[_.Opcode=3]="Opcode",_[_.SupplyOverflow=4]="SupplyOverflow",_[_.TrailingIntegers=5]="TrailingIntegers",_[_.TruncatedField=6]="TruncatedField",_[_.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",_[_.UnrecognizedFlag=8]="UnrecognizedFlag",_[_.Varint=9]="Varint"})(l||($e.Flaw=l={}));class h{constructor(w,T){this.start=w,this.end=T}}$e.Range=h;class y{constructor(w,T,R,B){this.amount=w,this.cap=T,this.height=R,this.offset=B}}$e.Terms=y;class p{constructor(w){this.value=w}get name(){return p.toName(this.value)}static toName(w){return(0,t.base26Decode)(w)}static fromName(w){return new p((0,t.base26Encode)((0,s.removeSpacers)(w)))}toString(){return this.name}}$e.Rune=p;class m{constructor(w,T,R,B,P,q,v){this.divisibility=w,this.premine=T,this.rune=R,this.spacers=B,this.symbol=P,this.terms=q,this.turbo=v}}$e.Etching=m,m.MAX_DIVISIBILITY=38,m.MAX_SPACERS=134217727;class g{constructor(w=[],T,R,B){this.edicts=w,this.etching=T,this.mint=R,this.pointer=B}static create(w,T="etch"){if(T==="etch"){w=w;const R=p.fromName(w.name),B=new y(w.amount,w.cap,new h(w.startHeight?(0,n.some)(w.startHeight):(0,n.none)(),w.endHeight?(0,n.some)(w.endHeight):(0,n.none)()),new h(w.startOffset?(0,n.some)(w.startOffset):(0,n.none)(),w.endOffset?(0,n.some)(w.endOffset):(0,n.none)())),P=w.divisibility?(0,n.some)(w.divisibility):(0,n.none)(),q=w.premine?(0,n.some)(w.premine):(0,n.none)(),v=w.name.indexOf("•")>-1?(0,n.some)((0,s.getSpacersVal)(w.name)):(0,n.none)(),C=w.symbol?(0,n.some)(w.symbol):(0,n.none)(),L=typeof w.pointer=="number"?(0,n.some)(w.pointer):(0,n.none)(),K=new m(P,q,(0,n.some)(R),v,C,(0,n.some)(B),!0);return new g([],(0,n.some)(K),(0,n.none)(),L)}else if(T==="mint"){w=w;const R=typeof w.pointer=="number"?(0,n.some)(w.pointer):(0,n.none)();return new g([],(0,n.none)(),(0,n.some)(new o(w.block,w.txIdx)),R)}else throw new Error(`not ${T} support now`)}static decipher(w){const T=e.Transaction.fromHex(w),R=g.payload(T);if(R.isSome()){const B=g.integers(R.value()),P=E.from_integers(T,B.value()),q=P.getEtching(),v=P.getMint(),C=P.getPointer();return(0,n.some)(new g(P.edicts,q,v,C))}return(0,n.none)()}encipher(){const T=this.toMessage().toBuffer(),R=Buffer.from("6a5d","hex");let B;if(T.length<76)B=Buffer.alloc(1),B.writeUint8(T.length);else if(T.length<256)B=Buffer.alloc(2),B.writeUint8(76),B.writeUint8(T.length);else if(T.length<65536)B=Buffer.alloc(3),B.writeUint8(77),B.writeUint16LE(T.length);else if(T.length<4294967296)B=Buffer.alloc(5),B.writeUint8(78),B.writeUint32LE(T.length);else throw new Error("runestone too big!");return Buffer.concat([R,B,T])}static payload(w){for(const T of w.outs){const R=e.script.decompile(T.script);if(R[0]===e.script.OPS.OP_RETURN&&R[1]===g.MAGIC_NUMBER){for(let B=2;B<R.length;B++){const P=R[B];return P instanceof Uint8Array?(0,n.some)(Array.from(P)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(w){let T=[],R=0;for(;R<w.length;){let{n:B,len:P}=(0,r.decodeLEB128)(w.slice(R));T.push(B),R+=P}return(0,n.some)(T)}toMessage(){let w=new Map;const T=this.etching.value();if(T){let P=1;if(T.terms.isSome()){let D=1<<a.Terms;P|=D}if(T.turbo){let D=1<<a.Turbo;P|=D}w.set(u.Flags,[BigInt(P)]);const q=T.rune.value();q!==null&&w.set(u.Rune,[BigInt(q.value)]);const v=T.divisibility.value();v!==null&&w.set(u.Divisibility,[BigInt(v)]);const C=T.spacers.value();C!==null&&w.set(u.Spacers,[BigInt(C)]);const L=T.symbol.value();L!==null&&w.set(u.Symbol,[BigInt(L.charCodeAt(0))]);const K=T.premine.value();K!==null&&w.set(u.Premine,[BigInt(K)]);const U=T.terms.value();if(U!==null){w.set(u.Amount,[BigInt(U.amount)]),w.set(u.Cap,[BigInt(U.cap)]);const D=U.height.start.value();D&&w.set(u.HeightStart,[BigInt(D)]);const k=U.height.end.value();k&&w.set(u.HeightEnd,[BigInt(k)]);const j=U.offset.start.value();j&&w.set(u.OffsetStart,[BigInt(j)]);const F=U.offset.end.value();F&&w.set(u.OffsetEnd,[BigInt(F)])}}const R=this.mint.value();R!==null&&w.set(u.Mint,[BigInt(R.block),BigInt(R.idx)]);const B=this.pointer.value();return B!==null&&w.set(u.Pointer,[BigInt(B)]),new E(w,this.edicts,0)}}$e.Runestone=g,g.MAGIC_NUMBER=93;class E{constructor(w=new Map,T=[],R=0){this.fields=w,this.edicts=T,this.flaws=R}static from_integers(w,T){let R=new Map,B=[],P=0,q=!1;for(let v=0;v<T.length;){let C=T[v];if(Number(C)===u.Body){q=!0,v+=1;continue}if(q){let L=new o(0,0);for(const K of(0,i.chunks)(T.slice(v),4)){if(K.length!=4){P|=l.TrailingIntegers;break}let U=L.next(K[0],K[1]);if(!U.isSome()){P|=l.EdictRuneId;break}const D=c.from_integers(w,U.value(),K[2],K[3]);if(!D.isSome()){P|=l.EdictOutput;break}L=U.value(),B.push(D.value())}v+=4}else{let L=T[v+1];const K=R.get(Number(C))||[];K.push(L),R.set(Number(C),K),v+=2}}return new E(R,B,P)}addFieldVal(w,T){const R=this.fields.get(Number(w))||[];R.push(T),this.fields.set(Number(w),R)}addEdict(w){this.edicts.push(w)}toBuffer(){const w=[];for(const[T,R]of this.fields)for(const B of R){const P=Buffer.alloc(1);P.writeUInt8(T),w.push(P),w.push(Buffer.from((0,r.encodeLEB128)(B)))}if(this.edicts.length>0){w.push(Buffer.from("00","hex")),this.edicts.sort((B,P)=>B.id.block==P.id.block?B.id.idx-P.id.idx:B.id.block-P.id.block);let T=0n,R=0n;for(let B=0;B<this.edicts.length;B++){const P=this.edicts[B];if(B==0)T=BigInt(P.id.block),R=BigInt(P.id.idx),w.push(Buffer.from((0,r.encodeLEB128)(T))),w.push(Buffer.from((0,r.encodeLEB128)(R)));else{const q=BigInt(P.id.block),v=BigInt(P.id.idx);if(q==T){const C=v-R;R=v,w.push(Buffer.from((0,r.encodeLEB128)(0n))),w.push(Buffer.from((0,r.encodeLEB128)(C)))}else{const C=q-T;T=q,R=v,w.push(Buffer.from((0,r.encodeLEB128)(C))),w.push(Buffer.from((0,r.encodeLEB128)(v)))}}w.push(Buffer.from((0,r.encodeLEB128)(BigInt(P.amount)))),w.push(Buffer.from((0,r.encodeLEB128)(BigInt(P.output))))}}return Buffer.concat(w)}getFlags(){return Number(this.fields.get(u.Flags))}hasFlags(w){const T=this.getFlags(),R=1<<w;return(T&R)!=0}getMint(){if(!this.fields.has(u.Mint))return(0,n.none)();const[w,T]=this.fields.get(u.Mint);return(0,n.some)(new o(Number(w),Number(T)))}getEtching(){if(!this.hasFlags(a.Etching))return(0,n.none)();const w=this.getDivisibility(),T=this.getPremine(),R=this.getRune(),B=this.getSpacers(),P=this.getSymbol(),q=this.getTerms(),v=this.hasFlags(a.Turbo);return(0,n.some)(new m(w,T,R,B,P,q,v))}getDivisibility(){if(!this.fields.has(u.Divisibility))return(0,n.none)();const[w]=this.fields.get(u.Divisibility);if(w>m.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(w))}getPremine(){if(!this.fields.has(u.Premine))return(0,n.none)();const[w]=this.fields.get(u.Premine);return(0,n.some)(Number(w))}getRune(){if(!this.fields.has(u.Rune))return(0,n.none)();const[w]=this.fields.get(u.Rune);return(0,n.some)(new p(w))}getSpacers(){if(!this.fields.has(u.Spacers))return(0,n.none)();const[w]=this.fields.get(u.Spacers);if(w>m.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(w))}getHeightStart(){if(!this.fields.has(u.HeightStart))return(0,n.none)();const[w]=this.fields.get(u.HeightStart);return(0,n.some)(Number(w))}getHeightEnd(){if(!this.fields.has(u.HeightEnd))return(0,n.none)();const[w]=this.fields.get(u.HeightEnd);return(0,n.some)(Number(w))}getOffsetStart(){if(!this.fields.has(u.OffsetStart))return(0,n.none)();const[w]=this.fields.get(u.OffsetStart);return(0,n.some)(Number(w))}getOffsetEnd(){if(!this.fields.has(u.OffsetEnd))return(0,n.none)();const[w]=this.fields.get(u.OffsetEnd);return(0,n.some)(Number(w))}getCap(){if(!this.fields.has(u.Cap))return(0,n.none)();const[w]=this.fields.get(u.Cap);return(0,n.some)(Number(w))}getAmount(){if(!this.fields.has(u.Amount))return(0,n.none)();const[w]=this.fields.get(u.Amount);return(0,n.some)(Number(w))}getSymbol(){if(!this.fields.has(u.Symbol))return(0,n.none)();const[w]=this.fields.get(u.Symbol);return(0,n.some)(String.fromCharCode(Number(w)))}getTerms(){if(!this.hasFlags(a.Terms))return(0,n.none)();const w=this.getCap();if(!w.isSome())throw new Error("no cap field");const T=this.getAmount();if(!T.isSome())throw new Error("no amount field");const R=this.getHeightStart(),B=this.getHeightEnd(),P=this.getOffsetStart(),q=this.getOffsetEnd(),v=new h(R,B),C=new h(P,q);return(0,n.some)(new y(T.value(),w.value(),v,C))}getPointer(){if(!this.fields.has(u.Pointer))return(0,n.none)();const[w]=this.fields.get(u.Pointer);return(0,n.some)(Number(w))}}$e.Message=E;class x{constructor(w=new Map,T=Buffer.alloc(0)){this.fields=w,this.data=T}setContent(w,T){this.fields.set(1,Buffer.from(w,"utf8")),this.data=T}setRune(w){let R=(0,t.base26Encode)((0,s.removeSpacers)(w)).toString(16);R.length%2===1&&(R="0"+R),this.setField(x.Tag.RUNE,Buffer.from(R,"hex").reverse())}setField(w,T){this.fields.set(w,T)}static decipher(w,T){const P=e.Transaction.fromHex(w).ins[T].witness[1],q=e.script.decompile(P),v=new Map,C=[];let L=!1;for(let K=5;K<q.length-1;){const U=q[K];if(U===0){L=!0,K++;continue}else if(L)C.push(U),K++;else{const D=U-80,k=q[K+1];if(typeof k=="number"){const j=Buffer.alloc(1);j.writeUint8(k),v.set(D,j)}else v.set(D,k);K+=2}}return new x(v,Buffer.concat(C))}encipher(){const w=[];if(this.data&&this.data.length>0){w.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((R,B)=>R[0]-B[0]).forEach(([R,B])=>{const P=Buffer.alloc(1);P.writeUInt8(R),w.push(Buffer.from("01","hex")),w.push(P),B.length!=1||B[0]!=0?w.push((0,i.toPushData)(B)):w.push(B)}),w.push(Buffer.from("00","hex"));const T=(0,i.chunks)(Array.from(this.data),520);for(const R of T)w.push((0,i.toPushData)(Buffer.from(R)))}else{w.push(Buffer.from("0063","hex"));const T=this.fields.get(x.Tag.RUNE);if(!T)throw new Error("No rune found!");w.push((0,i.toPushData)(T))}return w.push(Buffer.from("68","hex")),Buffer.concat(w)}}return $e.EtchInscription=x,x.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},$e}var wp;function u2(){return wp||(wp=1,(function(e){var t=ei&&ei.__createBinding||(Object.create?(function(s,o,c,a){a===void 0&&(a=c);var u=Object.getOwnPropertyDescriptor(o,c);(!u||("get"in u?!o.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return o[c]}}),Object.defineProperty(s,a,u)}):(function(s,o,c,a){a===void 0&&(a=c),s[a]=o[c]})),n=ei&&ei.__exportStar||function(s,o){for(var c in s)c!=="default"&&!Object.prototype.hasOwnProperty.call(o,c)&&t(o,s,c)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(a2(),e);var r=dp();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return r.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return r.some}});var i=mp();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return i.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return i.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return i.removeSpacers}})})(ei)),ei}var Xt=u2();function f2(e){if(e.length%2!==0)throw new Error("Hex string must have even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}function ju(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function $u(e){return e===hs.Mainnet?wn.networks.bitcoin:wn.networks.testnet}const on={P2PKH:{P2PKH:null},P2SH_P2WPKH:{P2SH_P2WPKH:null},P2WPKH:{P2WPKH:null},P2WSH:{P2WSH:null},P2SH:{P2SH:null},P2TR:{P2TR:null},UNKNOWN:{UNKNOWN:null}};function Ku(e,t=hs.Testnet){const n=$u(t);return wn.address.toOutputScript(e,n)}function Ws(e){const t=wn.networks.bitcoin,n=wn.networks.testnet,r=wn.networks.regtest;let i,s,o=on.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return s=wn.address.fromBech32(e),s.version===0?s.data.length===20?o=on.P2WPKH:o=on.P2WSH:o=on.P2TR,o}catch{return on.UNKNOWN}else try{return i=wn.address.fromBase58Check(e),i.version===t.pubKeyHash||i.version===n.pubKeyHash||i.version===r.pubKeyHash?o=on.P2PKH:(i.version===t.scriptHash||(i.version,n.scriptHash),o=on.P2SH_P2WPKH),o}catch{return on.UNKNOWN}}const l2=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:ju,getAddressType:Ws,getScriptByAddress:Ku,hexToBytes:f2,toBitcoinNetwork:$u},Symbol.toStringTag,{value:"Module"})),d2="kqs64-paaaa-aaaar-qamza-cai",h2="hvyp5-5yaaa-aaaao-qjxha-cai",Fi=BigInt(547),bc="0:0",p2="https://runescan-hasura-mainnet.omnity.network/v1/graphql",y2="https://runescan-hasura-testnet.omnity.network/v1/graphql";class bp{psbt;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);orchestrator;intentionSet=null;constructor(t,n){this.config=t,this.psbt=new wn.Psbt({network:$u(t.network)}),this.orchestrator=n}addInput(t){const{address:n}=t;this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:Number(t.satoshis),script:Buffer.from(t.scriptPk,"hex")}}),this.inputAddressTypes.push(Ws(n)),(n===this.config.address||n===this.config.paymentAddress)&&t.runes.length!==0&&(this.userInputUtxoDusts+=BigInt(t.satoshis))}addOutput(t,n){this.psbt.addOutput({address:t,value:Number(n)}),this.outputAddressTypes.push(Ws(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:0}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,r){const i=[];if(r==BigInt(0))return i;for(const s of t)if(s.runes.length){const o=s.runes.find(c=>c.id==n);if(o&&BigInt(o.amount)==r){i.push(s);break}}if(i.length==0){let s=BigInt(0);for(const o of t)if(o.runes.forEach(c=>{c.id==n&&(s=s+BigInt(c.amount))}),i.push(o),s>=r)break}return i}selectBtcUtxos(t,n){const r=[];if(n==BigInt(0))return r;let i=BigInt(0);for(const s of t)s.runes.length||i<n&&(i+=BigInt(s.satoshis),r.push(s));return r}caclulateRuneChangeAmount(t,n,r){let i=BigInt(0),s=!1;const o={};n.forEach(u=>{u.runes&&u.runes.forEach(l=>{o[l.id]=!0,l.id===t&&(i=i+BigInt(l.amount))})}),Object.keys(o).length>1&&(s=!0);const c=i-r;return{needChange:s||c>0,changeRuneAmount:c}}addRuneOutputs(t,n,r,i){const[s,o]=t.split(":"),c=new Xt.RuneId(Number(s),Number(o));if(r===BigInt(0)&&n.length!==0){const p=n.reduce((g,E)=>g+BigInt(E.runes.find(x=>x.id===t)?.amount??"0"),BigInt(0)),m=new Xt.Runestone([new Xt.Edict(c,p,1)],Xt.none(),Xt.none(),Xt.none());return this.addScriptOutput(m.encipher()),this.addOutput(n[0].address,Fi),{needChange:!1}}const{needChange:a,changeRuneAmount:u}=this.caclulateRuneChangeAmount(t,n,r),l=n[0].address,h=a?[new Xt.Edict(c,r,1),new Xt.Edict(c,u,2)]:[new Xt.Edict(c,r,1)],y=new Xt.Runestone(h,Xt.none(),Xt.none(),Xt.none());return this.addScriptOutput(y.encipher()),this.addOutput(i,Fi),a&&this.addOutput(l,Fi),{needChange:a}}async addBtcAndFees(t,n,r,i=BigInt(0)){this.outputAddressTypes.push(Ws(r));let s=BigInt(0),o=BigInt(0),c=[],a=BigInt(0),u=BigInt(0);const l=[...this.inputAddressTypes];do if(s=o,o=(await this.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes,pool_address:[this.config.poolAddress],output_types:this.outputAddressTypes})).Ok+BigInt(1),a=n+o+i-this.userInputUtxoDusts,o>s&&a>0){const m=this.selectBtcUtxos(t,a);if(m.length===0)throw new Error("INSUFFICIENT_BTC_UTXOs");this.inputAddressTypes=l.concat([...m.map(()=>Ws(r))]);const g=m.reduce((E,x)=>E+BigInt(x.satoshis),BigInt(0));g-a>0&&g-a>Fi||this.outputAddressTypes.pop(),c=m}while(o>s&&a>0);let h=BigInt(0);c.forEach(p=>{this.addInput(p),h+=BigInt(p.satoshis)});const y=h-a;if(y<0)throw new Error("Insufficient UTXO(s)");return y>Fi?this.psbt.addOutput({address:r,value:Number(y)}):y>BigInt(0)&&(u=y),{discardedSats:u,currentFee:o}}async build(t,n,r){const{runeId:i,sendRuneAmount:s,receiveRuneAmount:o,sendBtcAmount:c,receiveBtcAmount:a,btcUtxos:u,runeUtxos:l,poolUtxos:h,address:y,paymentAddress:p,poolAddress:m}=this.config;if(!i||!l?.length){h.forEach(U=>{this.addInput(U)});const q=h.reduce((U,D)=>U+BigInt(D.satoshis),BigInt(0));this.addOutput(m,q+c);const{discardedSats:v,currentFee:C}=await this.addBtcAndFees(u,c,p),L=[{from:p,coin:{id:bc,value:c}}],K=[];return a>BigInt(0)&&K.push({to:y,coin:{id:bc,value:o}}),this.intentionSet={tx_fee_in_sats:v+C,initiator_address:p,intentions:[{action:t,exchange_id:this.config.exchangeId,input_coins:L,pool_utxo_spent:[],pool_utxo_received:[],output_coins:K,pool_address:m,action_params:r??"",nonce:n}]},this.psbt}const g=this.selectRuneUtxos(l,i,s),E=s>BigInt(0)&&g.length>0;E&&g.forEach(q=>{this.addInput(q)});let x=BigInt(0),_=BigInt(0);h.forEach(q=>{const v=q.runes.find(C=>C.id===i);x+=BigInt(v?.amount??"0"),_+=BigInt(q.satoshis),this.addInput(q)});const{needChange:w}=this.addRuneOutputs(i,E?g:h,E?s:o,E?m:y);this.addOutput(m,_+c);const{discardedSats:T,currentFee:R}=await this.addBtcAndFees(u,c,p,E&&w?Fi:BigInt(0)),B=[],P=[];return c>BigInt(0)&&B.push({from:p,coin:{id:bc,value:c}}),s>BigInt(0)&&B.push({from:y,coin:{id:i,value:s}}),a>BigInt(0)&&P.push({to:p,coin:{id:bc,value:a}}),o>BigInt(0)&&P.push({to:y,coin:{id:i,value:o}}),this.intentionSet={tx_fee_in_sats:T+R,initiator_address:p,intentions:[{action:t,exchange_id:this.config.exchangeId,input_coins:B,pool_utxo_spent:[],pool_utxo_received:[],output_coins:P,pool_address:m,action_params:r??"",nonce:n}]},this.psbt}async send(t){if(!this.intentionSet)throw new Error("Intention set not available");return this.orchestrator.invoke({intention_set:this.intentionSet,initiator_utxo_proof:[],psbt_hex:t}).then(n=>{if(n?.Ok)return n.Ok;{const r=n?.Err??{},i=Object.keys(r)[0],s=r[i];throw new Error(s?i==="ErrorOccurredDuringExecution"?`${i}: ${s.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(n)}`:`Invoke Error: ${JSON.stringify(n)}`)}})}}class qi extends Error{response;request;constructor(t,n){const r=`${qi.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(r),Object.setPrototypeOf(this,qi.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,qi)}static extractMessage(t){return t.errors?.[0]?.message??`GraphQL Error (Code: ${String(t.status)})`}}const Ep=e=>e.toUpperCase(),Gu=e=>typeof e=="function"?e():e,_p=(e,t)=>e.map((n,r)=>[n,t[r]]),Mi=e=>{let t={};return e instanceof Headers?t=m2(e):Array.isArray(e)?e.forEach(([n,r])=>{n&&r!==void 0&&(t[n]=r)}):e&&(t=e),t},m2=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},g2=e=>{try{const t=e();return w2(t)?t.catch(n=>Sp(n)):t}catch(t){return Sp(t)}},Sp=e=>e instanceof Error?e:new Error(String(e)),w2=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function"&&"catch"in e&&typeof e.catch=="function"&&"finally"in e&&typeof e.finally=="function",Wu=e=>{throw new Error(`Unhandled case: ${String(e)}`)},Ec=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b2=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},E2=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0};function _c(e,t){if(!!!e)throw new Error(t)}function _2(e){return typeof e=="object"&&e!==null}function S2(e,t){if(!!!e)throw new Error("Unexpected invariant triggered.")}const x2=/\r\n|[\n\r]/g;function Xu(e,t){let n=0,r=1;for(const i of e.body.matchAll(x2)){if(typeof i.index=="number"||S2(!1),i.index>=t)break;n=i.index+i[0].length,r+=1}return{line:r,column:t+1-n}}function T2(e){return xp(e.source,Xu(e.source,e.start))}function xp(e,t){const n=e.locationOffset.column-1,r="".padStart(n)+e.body,i=t.line-1,s=e.locationOffset.line-1,o=t.line+s,c=t.line===1?n:0,a=t.column+c,u=`${e.name}:${o}:${a}
71
+ `,l=r.split(/\r\n|[\n\r]/g),h=l[i];if(h.length>120){const y=Math.floor(a/80),p=a%80,m=[];for(let g=0;g<h.length;g+=80)m.push(h.slice(g,g+80));return u+Tp([[`${o} |`,m[0]],...m.slice(1,y+1).map(g=>["|",g]),["|","^".padStart(p)],["|",m[y+1]]])}return u+Tp([[`${o-1} |`,l[i-1]],[`${o} |`,h],["|","^".padStart(a)],[`${o+1} |`,l[i+1]]])}function Tp(e){const t=e.filter(([r,i])=>i!==void 0),n=Math.max(...t.map(([r])=>r.length));return t.map(([r,i])=>r.padStart(n)+(i?" "+i:"")).join(`
72
+ `)}function v2(e){const t=e[0];return t==null||"kind"in t||"length"in t?{nodes:t,source:e[1],positions:e[2],path:e[3],originalError:e[4],extensions:e[5]}:t}class zu extends Error{constructor(t,...n){var r,i,s;const{nodes:o,source:c,positions:a,path:u,originalError:l,extensions:h}=v2(n);super(t),this.name="GraphQLError",this.path=u??void 0,this.originalError=l??void 0,this.nodes=vp(Array.isArray(o)?o:o?[o]:void 0);const y=vp((r=this.nodes)===null||r===void 0?void 0:r.map(m=>m.loc).filter(m=>m!=null));this.source=c??(y==null||(i=y[0])===null||i===void 0?void 0:i.source),this.positions=a??y?.map(m=>m.start),this.locations=a&&c?a.map(m=>Xu(c,m)):y?.map(m=>Xu(m.source,m.start));const p=_2(l?.extensions)?l?.extensions:void 0;this.extensions=(s=h??p)!==null&&s!==void 0?s:Object.create(null),Object.defineProperties(this,{message:{writable:!0,enumerable:!0},name:{enumerable:!1},nodes:{enumerable:!1},source:{enumerable:!1},positions:{enumerable:!1},originalError:{enumerable:!1}}),l!=null&&l.stack?Object.defineProperty(this,"stack",{value:l.stack,writable:!0,configurable:!0}):Error.captureStackTrace?Error.captureStackTrace(this,zu):Object.defineProperty(this,"stack",{value:Error().stack,writable:!0,configurable:!0})}get[Symbol.toStringTag](){return"GraphQLError"}toString(){let t=this.message;if(this.nodes)for(const n of this.nodes)n.loc&&(t+=`
73
+
74
+ `+T2(n.loc));else if(this.source&&this.locations)for(const n of this.locations)t+=`
75
+
76
+ `+xp(this.source,n);return t}toJSON(){const t={message:this.message};return this.locations!=null&&(t.locations=this.locations),this.path!=null&&(t.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(t.extensions=this.extensions),t}}function vp(e){return e===void 0||e.length===0?void 0:e}function mt(e,t,n){return new zu(`Syntax Error: ${n}`,{source:e,positions:[t]})}class B2{constructor(t,n,r){this.start=t.start,this.end=n.end,this.startToken=t,this.endToken=n,this.source=r}get[Symbol.toStringTag](){return"Location"}toJSON(){return{start:this.start,end:this.end}}}class Bp{constructor(t,n,r,i,s,o){this.kind=t,this.start=n,this.end=r,this.line=i,this.column=s,this.value=o,this.prev=null,this.next=null}get[Symbol.toStringTag](){return"Token"}toJSON(){return{kind:this.kind,value:this.value,line:this.line,column:this.column}}}const Ap={Name:[],Document:["definitions"],OperationDefinition:["name","variableDefinitions","directives","selectionSet"],VariableDefinition:["variable","type","defaultValue","directives"],Variable:["name"],SelectionSet:["selections"],Field:["alias","name","arguments","directives","selectionSet"],Argument:["name","value"],FragmentSpread:["name","directives"],InlineFragment:["typeCondition","directives","selectionSet"],FragmentDefinition:["name","variableDefinitions","typeCondition","directives","selectionSet"],IntValue:[],FloatValue:[],StringValue:[],BooleanValue:[],NullValue:[],EnumValue:[],ListValue:["values"],ObjectValue:["fields"],ObjectField:["name","value"],Directive:["name","arguments"],NamedType:["name"],ListType:["type"],NonNullType:["type"],SchemaDefinition:["description","directives","operationTypes"],OperationTypeDefinition:["type"],ScalarTypeDefinition:["description","name","directives"],ObjectTypeDefinition:["description","name","interfaces","directives","fields"],FieldDefinition:["description","name","arguments","type","directives"],InputValueDefinition:["description","name","type","defaultValue","directives"],InterfaceTypeDefinition:["description","name","interfaces","directives","fields"],UnionTypeDefinition:["description","name","directives","types"],EnumTypeDefinition:["description","name","directives","values"],EnumValueDefinition:["description","name","directives"],InputObjectTypeDefinition:["description","name","directives","fields"],DirectiveDefinition:["description","name","arguments","locations"],SchemaExtension:["directives","operationTypes"],ScalarTypeExtension:["name","directives"],ObjectTypeExtension:["name","interfaces","directives","fields"],InterfaceTypeExtension:["name","interfaces","directives","fields"],UnionTypeExtension:["name","directives","types"],EnumTypeExtension:["name","directives","values"],InputObjectTypeExtension:["name","directives","fields"]},A2=new Set(Object.keys(Ap));function Ip(e){const t=e?.kind;return typeof t=="string"&&A2.has(t)}var Li;(function(e){e.QUERY="query",e.MUTATION="mutation",e.SUBSCRIPTION="subscription"})(Li||(Li={}));var Yu;(function(e){e.QUERY="QUERY",e.MUTATION="MUTATION",e.SUBSCRIPTION="SUBSCRIPTION",e.FIELD="FIELD",e.FRAGMENT_DEFINITION="FRAGMENT_DEFINITION",e.FRAGMENT_SPREAD="FRAGMENT_SPREAD",e.INLINE_FRAGMENT="INLINE_FRAGMENT",e.VARIABLE_DEFINITION="VARIABLE_DEFINITION",e.SCHEMA="SCHEMA",e.SCALAR="SCALAR",e.OBJECT="OBJECT",e.FIELD_DEFINITION="FIELD_DEFINITION",e.ARGUMENT_DEFINITION="ARGUMENT_DEFINITION",e.INTERFACE="INTERFACE",e.UNION="UNION",e.ENUM="ENUM",e.ENUM_VALUE="ENUM_VALUE",e.INPUT_OBJECT="INPUT_OBJECT",e.INPUT_FIELD_DEFINITION="INPUT_FIELD_DEFINITION"})(Yu||(Yu={}));var Ee;(function(e){e.NAME="Name",e.DOCUMENT="Document",e.OPERATION_DEFINITION="OperationDefinition",e.VARIABLE_DEFINITION="VariableDefinition",e.SELECTION_SET="SelectionSet",e.FIELD="Field",e.ARGUMENT="Argument",e.FRAGMENT_SPREAD="FragmentSpread",e.INLINE_FRAGMENT="InlineFragment",e.FRAGMENT_DEFINITION="FragmentDefinition",e.VARIABLE="Variable",e.INT="IntValue",e.FLOAT="FloatValue",e.STRING="StringValue",e.BOOLEAN="BooleanValue",e.NULL="NullValue",e.ENUM="EnumValue",e.LIST="ListValue",e.OBJECT="ObjectValue",e.OBJECT_FIELD="ObjectField",e.DIRECTIVE="Directive",e.NAMED_TYPE="NamedType",e.LIST_TYPE="ListType",e.NON_NULL_TYPE="NonNullType",e.SCHEMA_DEFINITION="SchemaDefinition",e.OPERATION_TYPE_DEFINITION="OperationTypeDefinition",e.SCALAR_TYPE_DEFINITION="ScalarTypeDefinition",e.OBJECT_TYPE_DEFINITION="ObjectTypeDefinition",e.FIELD_DEFINITION="FieldDefinition",e.INPUT_VALUE_DEFINITION="InputValueDefinition",e.INTERFACE_TYPE_DEFINITION="InterfaceTypeDefinition",e.UNION_TYPE_DEFINITION="UnionTypeDefinition",e.ENUM_TYPE_DEFINITION="EnumTypeDefinition",e.ENUM_VALUE_DEFINITION="EnumValueDefinition",e.INPUT_OBJECT_TYPE_DEFINITION="InputObjectTypeDefinition",e.DIRECTIVE_DEFINITION="DirectiveDefinition",e.SCHEMA_EXTENSION="SchemaExtension",e.SCALAR_TYPE_EXTENSION="ScalarTypeExtension",e.OBJECT_TYPE_EXTENSION="ObjectTypeExtension",e.INTERFACE_TYPE_EXTENSION="InterfaceTypeExtension",e.UNION_TYPE_EXTENSION="UnionTypeExtension",e.ENUM_TYPE_EXTENSION="EnumTypeExtension",e.INPUT_OBJECT_TYPE_EXTENSION="InputObjectTypeExtension"})(Ee||(Ee={}));function Zu(e){return e===9||e===32}function Xs(e){return e>=48&&e<=57}function Op(e){return e>=97&&e<=122||e>=65&&e<=90}function Np(e){return Op(e)||e===95}function I2(e){return Op(e)||Xs(e)||e===95}function O2(e){var t;let n=Number.MAX_SAFE_INTEGER,r=null,i=-1;for(let o=0;o<e.length;++o){var s;const c=e[o],a=N2(c);a!==c.length&&(r=(s=r)!==null&&s!==void 0?s:o,i=o,o!==0&&a<n&&(n=a))}return e.map((o,c)=>c===0?o:o.slice(n)).slice((t=r)!==null&&t!==void 0?t:0,i+1)}function N2(e){let t=0;for(;t<e.length&&Zu(e.charCodeAt(t));)++t;return t}function R2(e,t){const n=e.replace(/"""/g,'\\"""'),r=n.split(/\r\n|[\n\r]/g),i=r.length===1,s=r.length>1&&r.slice(1).every(p=>p.length===0||Zu(p.charCodeAt(0))),o=n.endsWith('\\"""'),c=e.endsWith('"')&&!o,a=e.endsWith("\\"),u=c||a,l=!i||e.length>70||u||s||o;let h="";const y=i&&Zu(e.charCodeAt(0));return(l&&!y||s)&&(h+=`
77
+ `),h+=n,(l||u)&&(h+=`
78
+ `),'"""'+h+'"""'}var ee;(function(e){e.SOF="<SOF>",e.EOF="<EOF>",e.BANG="!",e.DOLLAR="$",e.AMP="&",e.PAREN_L="(",e.PAREN_R=")",e.SPREAD="...",e.COLON=":",e.EQUALS="=",e.AT="@",e.BRACKET_L="[",e.BRACKET_R="]",e.BRACE_L="{",e.PIPE="|",e.BRACE_R="}",e.NAME="Name",e.INT="Int",e.FLOAT="Float",e.STRING="String",e.BLOCK_STRING="BlockString",e.COMMENT="Comment"})(ee||(ee={}));class k2{constructor(t){const n=new Bp(ee.SOF,0,0,0,0);this.source=t,this.lastToken=n,this.token=n,this.line=1,this.lineStart=0}get[Symbol.toStringTag](){return"Lexer"}advance(){return this.lastToken=this.token,this.token=this.lookahead()}lookahead(){let t=this.token;if(t.kind!==ee.EOF)do if(t.next)t=t.next;else{const n=C2(this,t.end);t.next=n,n.prev=t,t=n}while(t.kind===ee.COMMENT);return t}}function P2(e){return e===ee.BANG||e===ee.DOLLAR||e===ee.AMP||e===ee.PAREN_L||e===ee.PAREN_R||e===ee.SPREAD||e===ee.COLON||e===ee.EQUALS||e===ee.AT||e===ee.BRACKET_L||e===ee.BRACKET_R||e===ee.BRACE_L||e===ee.PIPE||e===ee.BRACE_R}function Vi(e){return e>=0&&e<=55295||e>=57344&&e<=1114111}function Sc(e,t){return Rp(e.charCodeAt(t))&&kp(e.charCodeAt(t+1))}function Rp(e){return e>=55296&&e<=56319}function kp(e){return e>=56320&&e<=57343}function ii(e,t){const n=e.source.body.codePointAt(t);if(n===void 0)return ee.EOF;if(n>=32&&n<=126){const r=String.fromCodePoint(n);return r==='"'?`'"'`:`"${r}"`}return"U+"+n.toString(16).toUpperCase().padStart(4,"0")}function at(e,t,n,r,i){const s=e.line,o=1+n-e.lineStart;return new Bp(t,n,r,s,o,i)}function C2(e,t){const n=e.source.body,r=n.length;let i=t;for(;i<r;){const s=n.charCodeAt(i);switch(s){case 65279:case 9:case 32:case 44:++i;continue;case 10:++i,++e.line,e.lineStart=i;continue;case 13:n.charCodeAt(i+1)===10?i+=2:++i,++e.line,e.lineStart=i;continue;case 35:return U2(e,i);case 33:return at(e,ee.BANG,i,i+1);case 36:return at(e,ee.DOLLAR,i,i+1);case 38:return at(e,ee.AMP,i,i+1);case 40:return at(e,ee.PAREN_L,i,i+1);case 41:return at(e,ee.PAREN_R,i,i+1);case 46:if(n.charCodeAt(i+1)===46&&n.charCodeAt(i+2)===46)return at(e,ee.SPREAD,i,i+3);break;case 58:return at(e,ee.COLON,i,i+1);case 61:return at(e,ee.EQUALS,i,i+1);case 64:return at(e,ee.AT,i,i+1);case 91:return at(e,ee.BRACKET_L,i,i+1);case 93:return at(e,ee.BRACKET_R,i,i+1);case 123:return at(e,ee.BRACE_L,i,i+1);case 124:return at(e,ee.PIPE,i,i+1);case 125:return at(e,ee.BRACE_R,i,i+1);case 34:return n.charCodeAt(i+1)===34&&n.charCodeAt(i+2)===34?V2(e,i):F2(e,i)}if(Xs(s)||s===45)return H2(e,i,s);if(Np(s))return D2(e,i);throw mt(e.source,i,s===39?`Unexpected single quote character ('), did you mean to use a double quote (")?`:Vi(s)||Sc(n,i)?`Unexpected character: ${ii(e,i)}.`:`Invalid character: ${ii(e,i)}.`)}return at(e,ee.EOF,r,r)}function U2(e,t){const n=e.source.body,r=n.length;let i=t+1;for(;i<r;){const s=n.charCodeAt(i);if(s===10||s===13)break;if(Vi(s))++i;else if(Sc(n,i))i+=2;else break}return at(e,ee.COMMENT,t,i,n.slice(t+1,i))}function H2(e,t,n){const r=e.source.body;let i=t,s=n,o=!1;if(s===45&&(s=r.charCodeAt(++i)),s===48){if(s=r.charCodeAt(++i),Xs(s))throw mt(e.source,i,`Invalid number, unexpected digit after 0: ${ii(e,i)}.`)}else i=Ju(e,i,s),s=r.charCodeAt(i);if(s===46&&(o=!0,s=r.charCodeAt(++i),i=Ju(e,i,s),s=r.charCodeAt(i)),(s===69||s===101)&&(o=!0,s=r.charCodeAt(++i),(s===43||s===45)&&(s=r.charCodeAt(++i)),i=Ju(e,i,s),s=r.charCodeAt(i)),s===46||Np(s))throw mt(e.source,i,`Invalid number, expected digit but got: ${ii(e,i)}.`);return at(e,o?ee.FLOAT:ee.INT,t,i,r.slice(t,i))}function Ju(e,t,n){if(!Xs(n))throw mt(e.source,t,`Invalid number, expected digit but got: ${ii(e,t)}.`);const r=e.source.body;let i=t+1;for(;Xs(r.charCodeAt(i));)++i;return i}function F2(e,t){const n=e.source.body,r=n.length;let i=t+1,s=i,o="";for(;i<r;){const c=n.charCodeAt(i);if(c===34)return o+=n.slice(s,i),at(e,ee.STRING,t,i+1,o);if(c===92){o+=n.slice(s,i);const a=n.charCodeAt(i+1)===117?n.charCodeAt(i+2)===123?q2(e,i):M2(e,i):L2(e,i);o+=a.value,i+=a.size,s=i;continue}if(c===10||c===13)break;if(Vi(c))++i;else if(Sc(n,i))i+=2;else throw mt(e.source,i,`Invalid character within String: ${ii(e,i)}.`)}throw mt(e.source,i,"Unterminated string.")}function q2(e,t){const n=e.source.body;let r=0,i=3;for(;i<12;){const s=n.charCodeAt(t+i++);if(s===125){if(i<5||!Vi(r))break;return{value:String.fromCodePoint(r),size:i}}if(r=r<<4|zs(s),r<0)break}throw mt(e.source,t,`Invalid Unicode escape sequence: "${n.slice(t,t+i)}".`)}function M2(e,t){const n=e.source.body,r=Pp(n,t+2);if(Vi(r))return{value:String.fromCodePoint(r),size:6};if(Rp(r)&&n.charCodeAt(t+6)===92&&n.charCodeAt(t+7)===117){const i=Pp(n,t+8);if(kp(i))return{value:String.fromCodePoint(r,i),size:12}}throw mt(e.source,t,`Invalid Unicode escape sequence: "${n.slice(t,t+6)}".`)}function Pp(e,t){return zs(e.charCodeAt(t))<<12|zs(e.charCodeAt(t+1))<<8|zs(e.charCodeAt(t+2))<<4|zs(e.charCodeAt(t+3))}function zs(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:-1}function L2(e,t){const n=e.source.body;switch(n.charCodeAt(t+1)){case 34:return{value:'"',size:2};case 92:return{value:"\\",size:2};case 47:return{value:"/",size:2};case 98:return{value:"\b",size:2};case 102:return{value:"\f",size:2};case 110:return{value:`
79
+ `,size:2};case 114:return{value:"\r",size:2};case 116:return{value:" ",size:2}}throw mt(e.source,t,`Invalid character escape sequence: "${n.slice(t,t+2)}".`)}function V2(e,t){const n=e.source.body,r=n.length;let i=e.lineStart,s=t+3,o=s,c="";const a=[];for(;s<r;){const u=n.charCodeAt(s);if(u===34&&n.charCodeAt(s+1)===34&&n.charCodeAt(s+2)===34){c+=n.slice(o,s),a.push(c);const l=at(e,ee.BLOCK_STRING,t,s+3,O2(a).join(`
80
+ `));return e.line+=a.length-1,e.lineStart=i,l}if(u===92&&n.charCodeAt(s+1)===34&&n.charCodeAt(s+2)===34&&n.charCodeAt(s+3)===34){c+=n.slice(o,s),o=s+1,s+=4;continue}if(u===10||u===13){c+=n.slice(o,s),a.push(c),u===13&&n.charCodeAt(s+1)===10?s+=2:++s,c="",o=s,i=s;continue}if(Vi(u))++s;else if(Sc(n,s))s+=2;else throw mt(e.source,s,`Invalid character within String: ${ii(e,s)}.`)}throw mt(e.source,s,"Unterminated string.")}function D2(e,t){const n=e.source.body,r=n.length;let i=t+1;for(;i<r;){const s=n.charCodeAt(i);if(I2(s))++i;else break}return at(e,ee.NAME,t,i,n.slice(t,i))}const j2=10,Cp=2;function Qu(e){return xc(e,[])}function xc(e,t){switch(typeof e){case"string":return JSON.stringify(e);case"function":return e.name?`[function ${e.name}]`:"[function]";case"object":return $2(e,t);default:return String(e)}}function $2(e,t){if(e===null)return"null";if(t.includes(e))return"[Circular]";const n=[...t,e];if(K2(e)){const r=e.toJSON();if(r!==e)return typeof r=="string"?r:xc(r,n)}else if(Array.isArray(e))return W2(e,n);return G2(e,n)}function K2(e){return typeof e.toJSON=="function"}function G2(e,t){const n=Object.entries(e);return n.length===0?"{}":t.length>Cp?"["+X2(e)+"]":"{ "+n.map(([i,s])=>i+": "+xc(s,t)).join(", ")+" }"}function W2(e,t){if(e.length===0)return"[]";if(t.length>Cp)return"[Array]";const n=Math.min(j2,e.length),r=e.length-n,i=[];for(let s=0;s<n;++s)i.push(xc(e[s],t));return r===1?i.push("... 1 more item"):r>1&&i.push(`... ${r} more items`),"["+i.join(", ")+"]"}function X2(e){const t=Object.prototype.toString.call(e).replace(/^\[object /,"").replace(/]$/,"");if(t==="Object"&&typeof e.constructor=="function"){const n=e.constructor.name;if(typeof n=="string"&&n!=="")return n}return t}const z2=globalThis.process&&process.env.NODE_ENV==="production"?function(t,n){return t instanceof n}:function(t,n){if(t instanceof n)return!0;if(typeof t=="object"&&t!==null){var r;const i=n.prototype[Symbol.toStringTag],s=Symbol.toStringTag in t?t[Symbol.toStringTag]:(r=t.constructor)===null||r===void 0?void 0:r.name;if(i===s){const o=Qu(t);throw new Error(`Cannot use ${i} "${o}" from another module or realm.
81
+
82
+ Ensure that there is only one instance of "graphql" in the node_modules
83
+ directory. If different versions of "graphql" are the dependencies of other
84
+ relied on modules, use "resolutions" to ensure only one version is installed.
85
+
86
+ https://yarnpkg.com/en/docs/selective-version-resolutions
87
+
88
+ Duplicate "graphql" modules cannot be used at the same time since different
89
+ versions may have different capabilities and behavior. The data from one
90
+ version used in the function from another could produce confusing and
91
+ spurious results.`)}}return!1};class Up{constructor(t,n="GraphQL request",r={line:1,column:1}){typeof t=="string"||_c(!1,`Body must be a string. Received: ${Qu(t)}.`),this.body=t,this.name=n,this.locationOffset=r,this.locationOffset.line>0||_c(!1,"line in locationOffset is 1-indexed and must be positive."),this.locationOffset.column>0||_c(!1,"column in locationOffset is 1-indexed and must be positive.")}get[Symbol.toStringTag](){return"Source"}}function Y2(e){return z2(e,Up)}function Z2(e,t){const n=new J2(e,t),r=n.parseDocument();return Object.defineProperty(r,"tokenCount",{enumerable:!1,value:n.tokenCount}),r}class J2{constructor(t,n={}){const r=Y2(t)?t:new Up(t);this._lexer=new k2(r),this._options=n,this._tokenCounter=0}get tokenCount(){return this._tokenCounter}parseName(){const t=this.expectToken(ee.NAME);return this.node(t,{kind:Ee.NAME,value:t.value})}parseDocument(){return this.node(this._lexer.token,{kind:Ee.DOCUMENT,definitions:this.many(ee.SOF,this.parseDefinition,ee.EOF)})}parseDefinition(){if(this.peek(ee.BRACE_L))return this.parseOperationDefinition();const t=this.peekDescription(),n=t?this._lexer.lookahead():this._lexer.token;if(n.kind===ee.NAME){switch(n.value){case"schema":return this.parseSchemaDefinition();case"scalar":return this.parseScalarTypeDefinition();case"type":return this.parseObjectTypeDefinition();case"interface":return this.parseInterfaceTypeDefinition();case"union":return this.parseUnionTypeDefinition();case"enum":return this.parseEnumTypeDefinition();case"input":return this.parseInputObjectTypeDefinition();case"directive":return this.parseDirectiveDefinition()}if(t)throw mt(this._lexer.source,this._lexer.token.start,"Unexpected description, descriptions are supported only on type definitions.");switch(n.value){case"query":case"mutation":case"subscription":return this.parseOperationDefinition();case"fragment":return this.parseFragmentDefinition();case"extend":return this.parseTypeSystemExtension()}}throw this.unexpected(n)}parseOperationDefinition(){const t=this._lexer.token;if(this.peek(ee.BRACE_L))return this.node(t,{kind:Ee.OPERATION_DEFINITION,operation:Li.QUERY,name:void 0,variableDefinitions:[],directives:[],selectionSet:this.parseSelectionSet()});const n=this.parseOperationType();let r;return this.peek(ee.NAME)&&(r=this.parseName()),this.node(t,{kind:Ee.OPERATION_DEFINITION,operation:n,name:r,variableDefinitions:this.parseVariableDefinitions(),directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()})}parseOperationType(){const t=this.expectToken(ee.NAME);switch(t.value){case"query":return Li.QUERY;case"mutation":return Li.MUTATION;case"subscription":return Li.SUBSCRIPTION}throw this.unexpected(t)}parseVariableDefinitions(){return this.optionalMany(ee.PAREN_L,this.parseVariableDefinition,ee.PAREN_R)}parseVariableDefinition(){return this.node(this._lexer.token,{kind:Ee.VARIABLE_DEFINITION,variable:this.parseVariable(),type:(this.expectToken(ee.COLON),this.parseTypeReference()),defaultValue:this.expectOptionalToken(ee.EQUALS)?this.parseConstValueLiteral():void 0,directives:this.parseConstDirectives()})}parseVariable(){const t=this._lexer.token;return this.expectToken(ee.DOLLAR),this.node(t,{kind:Ee.VARIABLE,name:this.parseName()})}parseSelectionSet(){return this.node(this._lexer.token,{kind:Ee.SELECTION_SET,selections:this.many(ee.BRACE_L,this.parseSelection,ee.BRACE_R)})}parseSelection(){return this.peek(ee.SPREAD)?this.parseFragment():this.parseField()}parseField(){const t=this._lexer.token,n=this.parseName();let r,i;return this.expectOptionalToken(ee.COLON)?(r=n,i=this.parseName()):i=n,this.node(t,{kind:Ee.FIELD,alias:r,name:i,arguments:this.parseArguments(!1),directives:this.parseDirectives(!1),selectionSet:this.peek(ee.BRACE_L)?this.parseSelectionSet():void 0})}parseArguments(t){const n=t?this.parseConstArgument:this.parseArgument;return this.optionalMany(ee.PAREN_L,n,ee.PAREN_R)}parseArgument(t=!1){const n=this._lexer.token,r=this.parseName();return this.expectToken(ee.COLON),this.node(n,{kind:Ee.ARGUMENT,name:r,value:this.parseValueLiteral(t)})}parseConstArgument(){return this.parseArgument(!0)}parseFragment(){const t=this._lexer.token;this.expectToken(ee.SPREAD);const n=this.expectOptionalKeyword("on");return!n&&this.peek(ee.NAME)?this.node(t,{kind:Ee.FRAGMENT_SPREAD,name:this.parseFragmentName(),directives:this.parseDirectives(!1)}):this.node(t,{kind:Ee.INLINE_FRAGMENT,typeCondition:n?this.parseNamedType():void 0,directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()})}parseFragmentDefinition(){const t=this._lexer.token;return this.expectKeyword("fragment"),this._options.allowLegacyFragmentVariables===!0?this.node(t,{kind:Ee.FRAGMENT_DEFINITION,name:this.parseFragmentName(),variableDefinitions:this.parseVariableDefinitions(),typeCondition:(this.expectKeyword("on"),this.parseNamedType()),directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()}):this.node(t,{kind:Ee.FRAGMENT_DEFINITION,name:this.parseFragmentName(),typeCondition:(this.expectKeyword("on"),this.parseNamedType()),directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()})}parseFragmentName(){if(this._lexer.token.value==="on")throw this.unexpected();return this.parseName()}parseValueLiteral(t){const n=this._lexer.token;switch(n.kind){case ee.BRACKET_L:return this.parseList(t);case ee.BRACE_L:return this.parseObject(t);case ee.INT:return this.advanceLexer(),this.node(n,{kind:Ee.INT,value:n.value});case ee.FLOAT:return this.advanceLexer(),this.node(n,{kind:Ee.FLOAT,value:n.value});case ee.STRING:case ee.BLOCK_STRING:return this.parseStringLiteral();case ee.NAME:switch(this.advanceLexer(),n.value){case"true":return this.node(n,{kind:Ee.BOOLEAN,value:!0});case"false":return this.node(n,{kind:Ee.BOOLEAN,value:!1});case"null":return this.node(n,{kind:Ee.NULL});default:return this.node(n,{kind:Ee.ENUM,value:n.value})}case ee.DOLLAR:if(t)if(this.expectToken(ee.DOLLAR),this._lexer.token.kind===ee.NAME){const r=this._lexer.token.value;throw mt(this._lexer.source,n.start,`Unexpected variable "$${r}" in constant value.`)}else throw this.unexpected(n);return this.parseVariable();default:throw this.unexpected()}}parseConstValueLiteral(){return this.parseValueLiteral(!0)}parseStringLiteral(){const t=this._lexer.token;return this.advanceLexer(),this.node(t,{kind:Ee.STRING,value:t.value,block:t.kind===ee.BLOCK_STRING})}parseList(t){const n=()=>this.parseValueLiteral(t);return this.node(this._lexer.token,{kind:Ee.LIST,values:this.any(ee.BRACKET_L,n,ee.BRACKET_R)})}parseObject(t){const n=()=>this.parseObjectField(t);return this.node(this._lexer.token,{kind:Ee.OBJECT,fields:this.any(ee.BRACE_L,n,ee.BRACE_R)})}parseObjectField(t){const n=this._lexer.token,r=this.parseName();return this.expectToken(ee.COLON),this.node(n,{kind:Ee.OBJECT_FIELD,name:r,value:this.parseValueLiteral(t)})}parseDirectives(t){const n=[];for(;this.peek(ee.AT);)n.push(this.parseDirective(t));return n}parseConstDirectives(){return this.parseDirectives(!0)}parseDirective(t){const n=this._lexer.token;return this.expectToken(ee.AT),this.node(n,{kind:Ee.DIRECTIVE,name:this.parseName(),arguments:this.parseArguments(t)})}parseTypeReference(){const t=this._lexer.token;let n;if(this.expectOptionalToken(ee.BRACKET_L)){const r=this.parseTypeReference();this.expectToken(ee.BRACKET_R),n=this.node(t,{kind:Ee.LIST_TYPE,type:r})}else n=this.parseNamedType();return this.expectOptionalToken(ee.BANG)?this.node(t,{kind:Ee.NON_NULL_TYPE,type:n}):n}parseNamedType(){return this.node(this._lexer.token,{kind:Ee.NAMED_TYPE,name:this.parseName()})}peekDescription(){return this.peek(ee.STRING)||this.peek(ee.BLOCK_STRING)}parseDescription(){if(this.peekDescription())return this.parseStringLiteral()}parseSchemaDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("schema");const r=this.parseConstDirectives(),i=this.many(ee.BRACE_L,this.parseOperationTypeDefinition,ee.BRACE_R);return this.node(t,{kind:Ee.SCHEMA_DEFINITION,description:n,directives:r,operationTypes:i})}parseOperationTypeDefinition(){const t=this._lexer.token,n=this.parseOperationType();this.expectToken(ee.COLON);const r=this.parseNamedType();return this.node(t,{kind:Ee.OPERATION_TYPE_DEFINITION,operation:n,type:r})}parseScalarTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("scalar");const r=this.parseName(),i=this.parseConstDirectives();return this.node(t,{kind:Ee.SCALAR_TYPE_DEFINITION,description:n,name:r,directives:i})}parseObjectTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("type");const r=this.parseName(),i=this.parseImplementsInterfaces(),s=this.parseConstDirectives(),o=this.parseFieldsDefinition();return this.node(t,{kind:Ee.OBJECT_TYPE_DEFINITION,description:n,name:r,interfaces:i,directives:s,fields:o})}parseImplementsInterfaces(){return this.expectOptionalKeyword("implements")?this.delimitedMany(ee.AMP,this.parseNamedType):[]}parseFieldsDefinition(){return this.optionalMany(ee.BRACE_L,this.parseFieldDefinition,ee.BRACE_R)}parseFieldDefinition(){const t=this._lexer.token,n=this.parseDescription(),r=this.parseName(),i=this.parseArgumentDefs();this.expectToken(ee.COLON);const s=this.parseTypeReference(),o=this.parseConstDirectives();return this.node(t,{kind:Ee.FIELD_DEFINITION,description:n,name:r,arguments:i,type:s,directives:o})}parseArgumentDefs(){return this.optionalMany(ee.PAREN_L,this.parseInputValueDef,ee.PAREN_R)}parseInputValueDef(){const t=this._lexer.token,n=this.parseDescription(),r=this.parseName();this.expectToken(ee.COLON);const i=this.parseTypeReference();let s;this.expectOptionalToken(ee.EQUALS)&&(s=this.parseConstValueLiteral());const o=this.parseConstDirectives();return this.node(t,{kind:Ee.INPUT_VALUE_DEFINITION,description:n,name:r,type:i,defaultValue:s,directives:o})}parseInterfaceTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("interface");const r=this.parseName(),i=this.parseImplementsInterfaces(),s=this.parseConstDirectives(),o=this.parseFieldsDefinition();return this.node(t,{kind:Ee.INTERFACE_TYPE_DEFINITION,description:n,name:r,interfaces:i,directives:s,fields:o})}parseUnionTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("union");const r=this.parseName(),i=this.parseConstDirectives(),s=this.parseUnionMemberTypes();return this.node(t,{kind:Ee.UNION_TYPE_DEFINITION,description:n,name:r,directives:i,types:s})}parseUnionMemberTypes(){return this.expectOptionalToken(ee.EQUALS)?this.delimitedMany(ee.PIPE,this.parseNamedType):[]}parseEnumTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("enum");const r=this.parseName(),i=this.parseConstDirectives(),s=this.parseEnumValuesDefinition();return this.node(t,{kind:Ee.ENUM_TYPE_DEFINITION,description:n,name:r,directives:i,values:s})}parseEnumValuesDefinition(){return this.optionalMany(ee.BRACE_L,this.parseEnumValueDefinition,ee.BRACE_R)}parseEnumValueDefinition(){const t=this._lexer.token,n=this.parseDescription(),r=this.parseEnumValueName(),i=this.parseConstDirectives();return this.node(t,{kind:Ee.ENUM_VALUE_DEFINITION,description:n,name:r,directives:i})}parseEnumValueName(){if(this._lexer.token.value==="true"||this._lexer.token.value==="false"||this._lexer.token.value==="null")throw mt(this._lexer.source,this._lexer.token.start,`${Tc(this._lexer.token)} is reserved and cannot be used for an enum value.`);return this.parseName()}parseInputObjectTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("input");const r=this.parseName(),i=this.parseConstDirectives(),s=this.parseInputFieldsDefinition();return this.node(t,{kind:Ee.INPUT_OBJECT_TYPE_DEFINITION,description:n,name:r,directives:i,fields:s})}parseInputFieldsDefinition(){return this.optionalMany(ee.BRACE_L,this.parseInputValueDef,ee.BRACE_R)}parseTypeSystemExtension(){const t=this._lexer.lookahead();if(t.kind===ee.NAME)switch(t.value){case"schema":return this.parseSchemaExtension();case"scalar":return this.parseScalarTypeExtension();case"type":return this.parseObjectTypeExtension();case"interface":return this.parseInterfaceTypeExtension();case"union":return this.parseUnionTypeExtension();case"enum":return this.parseEnumTypeExtension();case"input":return this.parseInputObjectTypeExtension()}throw this.unexpected(t)}parseSchemaExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("schema");const n=this.parseConstDirectives(),r=this.optionalMany(ee.BRACE_L,this.parseOperationTypeDefinition,ee.BRACE_R);if(n.length===0&&r.length===0)throw this.unexpected();return this.node(t,{kind:Ee.SCHEMA_EXTENSION,directives:n,operationTypes:r})}parseScalarTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("scalar");const n=this.parseName(),r=this.parseConstDirectives();if(r.length===0)throw this.unexpected();return this.node(t,{kind:Ee.SCALAR_TYPE_EXTENSION,name:n,directives:r})}parseObjectTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("type");const n=this.parseName(),r=this.parseImplementsInterfaces(),i=this.parseConstDirectives(),s=this.parseFieldsDefinition();if(r.length===0&&i.length===0&&s.length===0)throw this.unexpected();return this.node(t,{kind:Ee.OBJECT_TYPE_EXTENSION,name:n,interfaces:r,directives:i,fields:s})}parseInterfaceTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("interface");const n=this.parseName(),r=this.parseImplementsInterfaces(),i=this.parseConstDirectives(),s=this.parseFieldsDefinition();if(r.length===0&&i.length===0&&s.length===0)throw this.unexpected();return this.node(t,{kind:Ee.INTERFACE_TYPE_EXTENSION,name:n,interfaces:r,directives:i,fields:s})}parseUnionTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("union");const n=this.parseName(),r=this.parseConstDirectives(),i=this.parseUnionMemberTypes();if(r.length===0&&i.length===0)throw this.unexpected();return this.node(t,{kind:Ee.UNION_TYPE_EXTENSION,name:n,directives:r,types:i})}parseEnumTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("enum");const n=this.parseName(),r=this.parseConstDirectives(),i=this.parseEnumValuesDefinition();if(r.length===0&&i.length===0)throw this.unexpected();return this.node(t,{kind:Ee.ENUM_TYPE_EXTENSION,name:n,directives:r,values:i})}parseInputObjectTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("input");const n=this.parseName(),r=this.parseConstDirectives(),i=this.parseInputFieldsDefinition();if(r.length===0&&i.length===0)throw this.unexpected();return this.node(t,{kind:Ee.INPUT_OBJECT_TYPE_EXTENSION,name:n,directives:r,fields:i})}parseDirectiveDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("directive"),this.expectToken(ee.AT);const r=this.parseName(),i=this.parseArgumentDefs(),s=this.expectOptionalKeyword("repeatable");this.expectKeyword("on");const o=this.parseDirectiveLocations();return this.node(t,{kind:Ee.DIRECTIVE_DEFINITION,description:n,name:r,arguments:i,repeatable:s,locations:o})}parseDirectiveLocations(){return this.delimitedMany(ee.PIPE,this.parseDirectiveLocation)}parseDirectiveLocation(){const t=this._lexer.token,n=this.parseName();if(Object.prototype.hasOwnProperty.call(Yu,n.value))return n;throw this.unexpected(t)}node(t,n){return this._options.noLocation!==!0&&(n.loc=new B2(t,this._lexer.lastToken,this._lexer.source)),n}peek(t){return this._lexer.token.kind===t}expectToken(t){const n=this._lexer.token;if(n.kind===t)return this.advanceLexer(),n;throw mt(this._lexer.source,n.start,`Expected ${Hp(t)}, found ${Tc(n)}.`)}expectOptionalToken(t){return this._lexer.token.kind===t?(this.advanceLexer(),!0):!1}expectKeyword(t){const n=this._lexer.token;if(n.kind===ee.NAME&&n.value===t)this.advanceLexer();else throw mt(this._lexer.source,n.start,`Expected "${t}", found ${Tc(n)}.`)}expectOptionalKeyword(t){const n=this._lexer.token;return n.kind===ee.NAME&&n.value===t?(this.advanceLexer(),!0):!1}unexpected(t){const n=t??this._lexer.token;return mt(this._lexer.source,n.start,`Unexpected ${Tc(n)}.`)}any(t,n,r){this.expectToken(t);const i=[];for(;!this.expectOptionalToken(r);)i.push(n.call(this));return i}optionalMany(t,n,r){if(this.expectOptionalToken(t)){const i=[];do i.push(n.call(this));while(!this.expectOptionalToken(r));return i}return[]}many(t,n,r){this.expectToken(t);const i=[];do i.push(n.call(this));while(!this.expectOptionalToken(r));return i}delimitedMany(t,n){this.expectOptionalToken(t);const r=[];do r.push(n.call(this));while(this.expectOptionalToken(t));return r}advanceLexer(){const{maxTokens:t}=this._options,n=this._lexer.advance();if(n.kind!==ee.EOF&&(++this._tokenCounter,t!==void 0&&this._tokenCounter>t))throw mt(this._lexer.source,n.start,`Document contains more that ${t} tokens. Parsing aborted.`)}}function Tc(e){const t=e.value;return Hp(e.kind)+(t!=null?` "${t}"`:"")}function Hp(e){return P2(e)?`"${e}"`:e}function Q2(e){return`"${e.replace(eE,tE)}"`}const eE=/[\x00-\x1f\x22\x5c\x7f-\x9f]/g;function tE(e){return nE[e.charCodeAt(0)]}const nE=["\\u0000","\\u0001","\\u0002","\\u0003","\\u0004","\\u0005","\\u0006","\\u0007","\\b","\\t","\\n","\\u000B","\\f","\\r","\\u000E","\\u000F","\\u0010","\\u0011","\\u0012","\\u0013","\\u0014","\\u0015","\\u0016","\\u0017","\\u0018","\\u0019","\\u001A","\\u001B","\\u001C","\\u001D","\\u001E","\\u001F","","",'\\"',"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","\\\\","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","\\u007F","\\u0080","\\u0081","\\u0082","\\u0083","\\u0084","\\u0085","\\u0086","\\u0087","\\u0088","\\u0089","\\u008A","\\u008B","\\u008C","\\u008D","\\u008E","\\u008F","\\u0090","\\u0091","\\u0092","\\u0093","\\u0094","\\u0095","\\u0096","\\u0097","\\u0098","\\u0099","\\u009A","\\u009B","\\u009C","\\u009D","\\u009E","\\u009F"],rE=Object.freeze({});function iE(e,t,n=Ap){const r=new Map;for(const x of Object.values(Ee))r.set(x,sE(t,x));let i,s=Array.isArray(e),o=[e],c=-1,a=[],u=e,l,h;const y=[],p=[];do{c++;const x=c===o.length,_=x&&a.length!==0;if(x){if(l=p.length===0?void 0:y[y.length-1],u=h,h=p.pop(),_)if(s){u=u.slice();let T=0;for(const[R,B]of a){const P=R-T;B===null?(u.splice(P,1),T++):u[P]=B}}else{u={...u};for(const[T,R]of a)u[T]=R}c=i.index,o=i.keys,a=i.edits,s=i.inArray,i=i.prev}else if(h){if(l=s?c:o[c],u=h[l],u==null)continue;y.push(l)}let w;if(!Array.isArray(u)){var m,g;Ip(u)||_c(!1,`Invalid AST Node: ${Qu(u)}.`);const T=x?(m=r.get(u.kind))===null||m===void 0?void 0:m.leave:(g=r.get(u.kind))===null||g===void 0?void 0:g.enter;if(w=T?.call(t,u,l,h,y,p),w===rE)break;if(w===!1){if(!x){y.pop();continue}}else if(w!==void 0&&(a.push([l,w]),!x))if(Ip(w))u=w;else{y.pop();continue}}if(w===void 0&&_&&a.push([l,u]),x)y.pop();else{var E;i={inArray:s,index:c,keys:o,edits:a,prev:i},s=Array.isArray(u),o=s?u:(E=n[u.kind])!==null&&E!==void 0?E:[],c=-1,a=[],h&&p.push(h),h=u}}while(i!==void 0);return a.length!==0?a[a.length-1][1]:e}function sE(e,t){const n=e[t];return typeof n=="object"?n:typeof n=="function"?{enter:n,leave:void 0}:{enter:e.enter,leave:e.leave}}function oE(e){return iE(e,aE)}const cE=80,aE={Name:{leave:e=>e.value},Variable:{leave:e=>"$"+e.name},Document:{leave:e=>he(e.definitions,`
92
+
93
+ `)},OperationDefinition:{leave(e){const t=Pe("(",he(e.variableDefinitions,", "),")"),n=he([e.operation,he([e.name,t]),he(e.directives," ")]," ");return(n==="query"?"":n+" ")+e.selectionSet}},VariableDefinition:{leave:({variable:e,type:t,defaultValue:n,directives:r})=>e+": "+t+Pe(" = ",n)+Pe(" ",he(r," "))},SelectionSet:{leave:({selections:e})=>yn(e)},Field:{leave({alias:e,name:t,arguments:n,directives:r,selectionSet:i}){const s=Pe("",e,": ")+t;let o=s+Pe("(",he(n,", "),")");return o.length>cE&&(o=s+Pe(`(
94
+ `,vc(he(n,`
95
+ `)),`
96
+ )`)),he([o,he(r," "),i]," ")}},Argument:{leave:({name:e,value:t})=>e+": "+t},FragmentSpread:{leave:({name:e,directives:t})=>"..."+e+Pe(" ",he(t," "))},InlineFragment:{leave:({typeCondition:e,directives:t,selectionSet:n})=>he(["...",Pe("on ",e),he(t," "),n]," ")},FragmentDefinition:{leave:({name:e,typeCondition:t,variableDefinitions:n,directives:r,selectionSet:i})=>`fragment ${e}${Pe("(",he(n,", "),")")} on ${t} ${Pe("",he(r," ")," ")}`+i},IntValue:{leave:({value:e})=>e},FloatValue:{leave:({value:e})=>e},StringValue:{leave:({value:e,block:t})=>t?R2(e):Q2(e)},BooleanValue:{leave:({value:e})=>e?"true":"false"},NullValue:{leave:()=>"null"},EnumValue:{leave:({value:e})=>e},ListValue:{leave:({values:e})=>"["+he(e,", ")+"]"},ObjectValue:{leave:({fields:e})=>"{"+he(e,", ")+"}"},ObjectField:{leave:({name:e,value:t})=>e+": "+t},Directive:{leave:({name:e,arguments:t})=>"@"+e+Pe("(",he(t,", "),")")},NamedType:{leave:({name:e})=>e},ListType:{leave:({type:e})=>"["+e+"]"},NonNullType:{leave:({type:e})=>e+"!"},SchemaDefinition:{leave:({description:e,directives:t,operationTypes:n})=>Pe("",e,`
97
+ `)+he(["schema",he(t," "),yn(n)]," ")},OperationTypeDefinition:{leave:({operation:e,type:t})=>e+": "+t},ScalarTypeDefinition:{leave:({description:e,name:t,directives:n})=>Pe("",e,`
98
+ `)+he(["scalar",t,he(n," ")]," ")},ObjectTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:r,fields:i})=>Pe("",e,`
99
+ `)+he(["type",t,Pe("implements ",he(n," & ")),he(r," "),yn(i)]," ")},FieldDefinition:{leave:({description:e,name:t,arguments:n,type:r,directives:i})=>Pe("",e,`
100
+ `)+t+(Fp(n)?Pe(`(
101
+ `,vc(he(n,`
102
+ `)),`
103
+ )`):Pe("(",he(n,", "),")"))+": "+r+Pe(" ",he(i," "))},InputValueDefinition:{leave:({description:e,name:t,type:n,defaultValue:r,directives:i})=>Pe("",e,`
104
+ `)+he([t+": "+n,Pe("= ",r),he(i," ")]," ")},InterfaceTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:r,fields:i})=>Pe("",e,`
105
+ `)+he(["interface",t,Pe("implements ",he(n," & ")),he(r," "),yn(i)]," ")},UnionTypeDefinition:{leave:({description:e,name:t,directives:n,types:r})=>Pe("",e,`
106
+ `)+he(["union",t,he(n," "),Pe("= ",he(r," | "))]," ")},EnumTypeDefinition:{leave:({description:e,name:t,directives:n,values:r})=>Pe("",e,`
107
+ `)+he(["enum",t,he(n," "),yn(r)]," ")},EnumValueDefinition:{leave:({description:e,name:t,directives:n})=>Pe("",e,`
108
+ `)+he([t,he(n," ")]," ")},InputObjectTypeDefinition:{leave:({description:e,name:t,directives:n,fields:r})=>Pe("",e,`
109
+ `)+he(["input",t,he(n," "),yn(r)]," ")},DirectiveDefinition:{leave:({description:e,name:t,arguments:n,repeatable:r,locations:i})=>Pe("",e,`
110
+ `)+"directive @"+t+(Fp(n)?Pe(`(
111
+ `,vc(he(n,`
112
+ `)),`
113
+ )`):Pe("(",he(n,", "),")"))+(r?" repeatable":"")+" on "+he(i," | ")},SchemaExtension:{leave:({directives:e,operationTypes:t})=>he(["extend schema",he(e," "),yn(t)]," ")},ScalarTypeExtension:{leave:({name:e,directives:t})=>he(["extend scalar",e,he(t," ")]," ")},ObjectTypeExtension:{leave:({name:e,interfaces:t,directives:n,fields:r})=>he(["extend type",e,Pe("implements ",he(t," & ")),he(n," "),yn(r)]," ")},InterfaceTypeExtension:{leave:({name:e,interfaces:t,directives:n,fields:r})=>he(["extend interface",e,Pe("implements ",he(t," & ")),he(n," "),yn(r)]," ")},UnionTypeExtension:{leave:({name:e,directives:t,types:n})=>he(["extend union",e,he(t," "),Pe("= ",he(n," | "))]," ")},EnumTypeExtension:{leave:({name:e,directives:t,values:n})=>he(["extend enum",e,he(t," "),yn(n)]," ")},InputObjectTypeExtension:{leave:({name:e,directives:t,fields:n})=>he(["extend input",e,he(t," "),yn(n)]," ")}};function he(e,t=""){var n;return(n=e?.filter(r=>r).join(t))!==null&&n!==void 0?n:""}function yn(e){return Pe(`{
114
+ `,vc(he(e,`
115
+ `)),`
116
+ }`)}function Pe(e,t,n=""){return t!=null&&t!==""?e+t+n:""}function vc(e){return Pe(" ",e.replace(/\n/g,`
117
+ `))}function Fp(e){var t;return(t=e?.some(n=>n.includes(`
118
+ `)))!==null&&t!==void 0?t:!1}const qp="Accept",ef="Content-Type",tf="application/json",Mp="application/graphql-response+json",Lp=e=>e.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),uE=e=>{const t=e.toLowerCase();return t.includes(Mp)||t.includes(tf)},Vp=e=>{try{if(Array.isArray(e))return{_tag:"Batch",executionResults:e.map(Dp)};if(Ec(e))return{_tag:"Single",executionResult:Dp(e)};throw new Error(`Invalid execution result: result is not object or array.
119
+ Got:
120
+ ${String(e)}`)}catch(t){return t}},Dp=e=>{if(typeof e!="object"||e===null)throw new Error("Invalid execution result: result is not object");let t,n,r;if("errors"in e){if(!Ec(e.errors)&&!Array.isArray(e.errors))throw new Error("Invalid execution result: errors is not plain object OR array");t=e.errors}if("data"in e){if(!Ec(e.data)&&e.data!==null)throw new Error("Invalid execution result: data is not plain object");n=e.data}if("extensions"in e){if(!Ec(e.extensions))throw new Error("Invalid execution result: extensions is not plain object");r=e.extensions}return{data:n,errors:t,extensions:r}},fE=e=>e._tag==="Batch"?e.executionResults.some(jp):jp(e.executionResult),jp=e=>Array.isArray(e.errors)?e.errors.length>0:!!e.errors,$p=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===Ee.OPERATION_DEFINITION,lE=e=>{let t;const n=e.definitions.filter($p);return n.length===1&&(t=n[0].name?.value),t},dE=e=>{let t=!1;const n=e.definitions.filter($p);return n.length===1&&(t=n[0].operation==="mutation"),t},nf=(e,t)=>{const n=typeof e=="string"?e:oE(e);let r=!1,i;if(t)return{expression:n,isMutation:r,operationName:i};const s=g2(()=>typeof e=="string"?Z2(e):e);return s instanceof Error?{expression:n,isMutation:r,operationName:i}:(i=lE(s),r=dE(s),{expression:n,operationName:i,isMutation:r})},rf=JSON,sf=async e=>{const t={...e,method:e.request._tag==="Single"?e.request.document.isMutation?"POST":Ep(e.method??"post"):e.request.hasMutations?"POST":Ep(e.method??"post"),fetchOptions:{...e.fetchOptions,errorPolicy:e.fetchOptions.errorPolicy??"none"}},r=await pE(t.method)(t);if(!r.ok)return new qi({status:r.status,headers:r.headers},{query:e.request._tag==="Single"?e.request.document.expression:e.request.query,variables:e.request.variables});const i=await hE(r,e.fetchOptions.jsonSerializer??rf);if(i instanceof Error)throw i;const s={status:r.status,headers:r.headers};if(fE(i)&&t.fetchOptions.errorPolicy==="none"){const o=i._tag==="Batch"?{...i.executionResults,...s}:{...i.executionResult,...s};return new qi(o,{query:e.request._tag==="Single"?e.request.document.expression:e.request.query,variables:e.request.variables})}switch(i._tag){case"Single":return{...s,...Kp(t)(i.executionResult)};case"Batch":return{...s,data:i.executionResults.map(Kp(t))};default:Wu(i)}},Kp=e=>t=>({extensions:t.extensions,data:t.data,errors:e.fetchOptions.errorPolicy==="all"?t.errors:void 0}),hE=async(e,t)=>{const n=e.headers.get(ef),r=await e.text();return n&&uE(n)?Vp(t.parse(r)):Vp(r)},pE=e=>async t=>{const n=new Headers(t.headers);let r=null,i;n.has(qp)||n.set(qp,[Mp,tf].join(", ")),e==="POST"?(i=(t.fetchOptions.jsonSerializer??rf).stringify(yE(t)),typeof i=="string"&&!n.has(ef)&&n.set(ef,tf)):r=mE(t);const s={method:e,headers:n,body:i,...t.fetchOptions};let o=new URL(t.url),c=s;if(t.middleware){const u=await Promise.resolve(t.middleware({...s,url:t.url,operationName:t.request._tag==="Single"?t.request.document.operationName:void 0,variables:t.request.variables})),{url:l,...h}=u;o=new URL(l),c=h}return r&&r.forEach((u,l)=>{o.searchParams.append(l,u)}),await(t.fetch??fetch)(o,c)},yE=e=>{switch(e.request._tag){case"Single":return{query:e.request.document.expression,variables:e.request.variables,operationName:e.request.document.operationName};case"Batch":return _p(e.request.query,e.request.variables??[]).map(([t,n])=>({query:t,variables:n}));default:throw Wu(e.request)}},mE=e=>{const t=e.fetchOptions.jsonSerializer??rf,n=new URLSearchParams;switch(e.request._tag){case"Single":return n.append("query",Lp(e.request.document.expression)),e.request.variables&&n.append("variables",t.stringify(e.request.variables)),e.request.document.operationName&&n.append("operationName",e.request.document.operationName),n;case"Batch":{const r=e.request.variables?.map(o=>t.stringify(o))??[],i=e.request.query.map(Lp),s=_p(i,r).map(([o,c])=>({query:o,variables:c}));return n.append("query",t.stringify(s)),n}default:throw Wu(e.request)}};class gE{url;requestConfig;constructor(t,n={}){this.url=t,this.requestConfig=n}rawRequest=async(...t)=>{const[n,r,i]=t,s=E2(n,r,i),{headers:o,fetch:c=globalThis.fetch,method:a="POST",requestMiddleware:u,responseMiddleware:l,excludeOperationName:h,...y}=this.requestConfig,{url:p}=this;s.signal!==void 0&&(y.signal=s.signal);const m=nf(s.query,h),g=await sf({url:p,request:{_tag:"Single",document:m,variables:s.variables},headers:{...Mi(Gu(o)),...Mi(s.requestHeaders)},fetch:c,method:a,fetchOptions:y,middleware:u});if(l&&await l(g,{operationName:m.operationName,variables:r,url:this.url}),g instanceof Error)throw g;return g};async request(t,...n){const[r,i]=n,s=wE(t,r,i),{headers:o,fetch:c=globalThis.fetch,method:a="POST",requestMiddleware:u,responseMiddleware:l,excludeOperationName:h,...y}=this.requestConfig,{url:p}=this;s.signal!==void 0&&(y.signal=s.signal);const m=nf(s.document,h),g=await sf({url:p,request:{_tag:"Single",document:m,variables:s.variables},headers:{...Mi(Gu(o)),...Mi(s.requestHeaders)},fetch:c,method:a,fetchOptions:y,middleware:u});if(l&&await l(g,{operationName:m.operationName,variables:s.variables,url:this.url}),g instanceof Error)throw g;return g.data}async batchRequests(t,n){const r=b2(t,n),{headers:i,excludeOperationName:s,...o}=this.requestConfig;r.signal!==void 0&&(o.signal=r.signal);const c=r.documents.map(({document:y})=>nf(y,s)),a=c.map(({expression:y})=>y),u=c.some(({isMutation:y})=>y),l=r.documents.map(({variables:y})=>y),h=await sf({url:this.url,request:{_tag:"Batch",operationName:void 0,query:a,hasMutations:u,variables:l},headers:{...Mi(Gu(i)),...Mi(r.requestHeaders)},fetch:this.requestConfig.fetch??globalThis.fetch,method:this.requestConfig.method||"POST",fetchOptions:o,middleware:this.requestConfig.requestMiddleware});if(this.requestConfig.responseMiddleware&&await this.requestConfig.responseMiddleware(h,{operationName:void 0,variables:l,url:this.url}),h instanceof Error)throw h;return h.data}setHeaders(t){return this.requestConfig.headers=t,this}setHeader(t,n){const{headers:r}=this.requestConfig;return r?r[t]=n:this.requestConfig.headers={[t]:n},this}setEndpoint(t){return this.url=t,this}}const wE=(e,t,n)=>e.document?e:{document:e,variables:t,requestHeaders:n,signal:void 0},bE=(e,...t)=>e.reduce((n,r,i)=>`${n}${r}${i in t?String(t[i]):""}`,"");/*!
121
+ * decimal.js v10.6.0
122
+ * An arbitrary-precision Decimal type for JavaScript.
123
+ * https://github.com/MikeMcl/decimal.js
124
+ * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
125
+ * MIT Licence
126
+ */var Di=9e15,_r=1e9,of="0123456789abcdef",Bc="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ac="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",cf={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Di,maxE:Di,crypto:!1},Gp,Kn,_e=!0,Ic="[DecimalError] ",Sr=Ic+"Invalid argument: ",Wp=Ic+"Precision limit exceeded",Xp=Ic+"crypto unavailable",zp="[object Decimal]",Nt=Math.floor,ht=Math.pow,EE=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,_E=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,SE=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Yp=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,mn=1e7,be=7,xE=9007199254740991,TE=Bc.length-1,af=Ac.length-1,se={toStringTag:zp};se.absoluteValue=se.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),me(e)},se.ceil=function(){return me(new this.constructor(this),this.e+1,2)},se.clampedTo=se.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(Sr+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},se.comparedTo=se.cmp=function(e){var t,n,r,i,s=this,o=s.d,c=(e=new s.constructor(e)).d,a=s.s,u=e.s;if(!o||!c)return!a||!u?NaN:a!==u?a:o===c?0:!o^a<0?1:-1;if(!o[0]||!c[0])return o[0]?a:c[0]?-u:0;if(a!==u)return a;if(s.e!==e.e)return s.e>e.e^a<0?1:-1;for(r=o.length,i=c.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==c[t])return o[t]>c[t]^a<0?1:-1;return r===i?0:r>i^a<0?1:-1},se.cosine=se.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+be,r.rounding=1,n=vE(r,ny(r,n)),r.precision=e,r.rounding=t,me(Kn==2||Kn==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},se.cubeRoot=se.cbrt=function(){var e,t,n,r,i,s,o,c,a,u,l=this,h=l.constructor;if(!l.isFinite()||l.isZero())return new h(l);for(_e=!1,s=l.s*ht(l.s*l,1/3),!s||Math.abs(s)==1/0?(n=xt(l.d),e=l.e,(s=(e-n.length+1)%3)&&(n+=s==1||s==-2?"0":"00"),s=ht(n,1/3),e=Nt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?n="5e"+e:(n=s.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new h(n),r.s=l.s):r=new h(s.toString()),o=(e=h.precision)+3;;)if(c=r,a=c.times(c).times(c),u=a.plus(l),r=Ke(u.plus(l).times(c),u.plus(a),o+2,1),xt(c.d).slice(0,o)===(n=xt(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n=="9999"||!i&&n=="4999"){if(!i&&(me(c,e+1,0),c.times(c).times(c).eq(l))){r=c;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(me(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return _e=!0,me(r,e,h.rounding,t)},se.decimalPlaces=se.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Nt(this.e/be))*be,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},se.dividedBy=se.div=function(e){return Ke(this,new this.constructor(e))},se.dividedToIntegerBy=se.divToInt=function(e){var t=this,n=t.constructor;return me(Ke(t,new n(e),0,1,1),n.precision,n.rounding)},se.equals=se.eq=function(e){return this.cmp(e)===0},se.floor=function(){return me(new this.constructor(this),this.e+1,3)},se.greaterThan=se.gt=function(e){return this.cmp(e)>0},se.greaterThanOrEqualTo=se.gte=function(e){var t=this.cmp(e);return t==1||t===0},se.hyperbolicCosine=se.cosh=function(){var e,t,n,r,i,s=this,o=s.constructor,c=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return c;n=o.precision,r=o.rounding,o.precision=n+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(e=Math.ceil(i/3),t=(1/Pc(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=ji(o,1,s.times(t),new o(1),!0);for(var a,u=e,l=new o(8);u--;)a=s.times(s),s=c.minus(a.times(l.minus(a.times(l))));return me(s,o.precision=n,o.rounding=r,!0)},se.hyperbolicSine=se.sinh=function(){var e,t,n,r,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(t=s.precision,n=s.rounding,s.precision=t+Math.max(i.e,i.sd())+4,s.rounding=1,r=i.d.length,r<3)i=ji(s,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Pc(5,e)),i=ji(s,2,i,i,!0);for(var o,c=new s(5),a=new s(16),u=new s(20);e--;)o=i.times(i),i=i.times(c.plus(o.times(a.times(o).plus(u))))}return s.precision=t,s.rounding=n,me(i,t,n,!0)},se.hyperbolicTangent=se.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,Ke(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},se.inverseCosine=se.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n!==-1?n===0?e.isNeg()?vn(t,r,i):new t(0):new t(NaN):e.isZero()?vn(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2))},se.inverseHyperbolicCosine=se.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,_e=!1,n=n.times(n).minus(1).sqrt().plus(n),_e=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},se.inverseHyperbolicSine=se.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,_e=!1,n=n.times(n).plus(1).sqrt().plus(n),_e=!0,r.precision=e,r.rounding=t,n.ln())},se.inverseHyperbolicTangent=se.atanh=function(){var e,t,n,r,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=s.precision,t=s.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?me(new s(i),e,t,!0):(s.precision=n=r-i.e,i=Ke(i.plus(1),new s(1).minus(i),n+e,1),s.precision=e+4,s.rounding=1,i=i.ln(),s.precision=e,s.rounding=t,i.times(.5))):new s(NaN)},se.inverseSine=se.asin=function(){var e,t,n,r,i=this,s=i.constructor;return i.isZero()?new s(i):(t=i.abs().cmp(1),n=s.precision,r=s.rounding,t!==-1?t===0?(e=vn(s,n+4,r).times(.5),e.s=i.s,e):new s(NaN):(s.precision=n+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=n,s.rounding=r,i.times(2)))},se.inverseTangent=se.atan=function(){var e,t,n,r,i,s,o,c,a,u=this,l=u.constructor,h=l.precision,y=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&h+4<=af)return o=vn(l,h+4,y).times(.25),o.s=u.s,o}else{if(!u.s)return new l(NaN);if(h+4<=af)return o=vn(l,h+4,y).times(.5),o.s=u.s,o}for(l.precision=c=h+10,l.rounding=1,n=Math.min(28,c/be+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(_e=!1,t=Math.ceil(c/be),r=1,a=u.times(u),o=new l(u),i=u;e!==-1;)if(i=i.times(a),s=o.minus(i.div(r+=2)),i=i.times(a),o=s.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===s.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),_e=!0,me(o,l.precision=h,l.rounding=y,!0)},se.isFinite=function(){return!!this.d},se.isInteger=se.isInt=function(){return!!this.d&&Nt(this.e/be)>this.d.length-2},se.isNaN=function(){return!this.s},se.isNegative=se.isNeg=function(){return this.s<0},se.isPositive=se.isPos=function(){return this.s>0},se.isZero=function(){return!!this.d&&this.d[0]===0},se.lessThan=se.lt=function(e){return this.cmp(e)<0},se.lessThanOrEqualTo=se.lte=function(e){return this.cmp(e)<1},se.logarithm=se.log=function(e){var t,n,r,i,s,o,c,a,u=this,l=u.constructor,h=l.precision,y=l.rounding,p=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)s=!0;else{for(i=n[0];i%10===0;)i/=10;s=i!==1}if(_e=!1,c=h+p,o=Tr(u,c),r=t?Rc(l,c+10):Tr(e,c),a=Ke(o,r,c,1),Ys(a.d,i=h,y))do if(c+=10,o=Tr(u,c),r=t?Rc(l,c+10):Tr(e,c),a=Ke(o,r,c,1),!s){+xt(a.d).slice(i+1,i+15)+1==1e14&&(a=me(a,h+1,0));break}while(Ys(a.d,i+=10,y));return _e=!0,me(a,h,y)},se.minus=se.sub=function(e){var t,n,r,i,s,o,c,a,u,l,h,y,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(u=p.d,y=e.d,c=m.precision,a=m.rounding,!u[0]||!y[0]){if(y[0])e.s=-e.s;else if(u[0])e=new m(p);else return new m(a===3?-0:0);return _e?me(e,c,a):e}if(n=Nt(e.e/be),l=Nt(p.e/be),u=u.slice(),s=l-n,s){for(h=s<0,h?(t=u,s=-s,o=y.length):(t=y,n=l,o=u.length),r=Math.max(Math.ceil(c/be),o)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=u.length,o=y.length,h=r<o,h&&(o=r),r=0;r<o;r++)if(u[r]!=y[r]){h=u[r]<y[r];break}s=0}for(h&&(t=u,u=y,y=t,e.s=-e.s),o=u.length,r=y.length-o;r>0;--r)u[o++]=0;for(r=y.length;r>s;){if(u[--r]<y[r]){for(i=r;i&&u[--i]===0;)u[i]=mn-1;--u[i],u[r]+=mn}u[r]-=y[r]}for(;u[--o]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=Nc(u,n),_e?me(e,c,a):e):new m(a===3?-0:0)},se.modulo=se.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?me(new r(n),r.precision,r.rounding):(_e=!1,r.modulo==9?(t=Ke(n,e.abs(),0,3,1),t.s*=e.s):t=Ke(n,e,0,r.modulo,1),t=t.times(e),_e=!0,n.minus(t))},se.naturalExponential=se.exp=function(){return uf(this)},se.naturalLogarithm=se.ln=function(){return Tr(this)},se.negated=se.neg=function(){var e=new this.constructor(this);return e.s=-e.s,me(e)},se.plus=se.add=function(e){var t,n,r,i,s,o,c,a,u,l,h=this,y=h.constructor;if(e=new y(e),!h.d||!e.d)return!h.s||!e.s?e=new y(NaN):h.d||(e=new y(e.d||h.s===e.s?h:NaN)),e;if(h.s!=e.s)return e.s=-e.s,h.minus(e);if(u=h.d,l=e.d,c=y.precision,a=y.rounding,!u[0]||!l[0])return l[0]||(e=new y(h)),_e?me(e,c,a):e;if(s=Nt(h.e/be),r=Nt(e.e/be),u=u.slice(),i=s-r,i){for(i<0?(n=u,i=-i,o=l.length):(n=l,r=s,o=u.length),s=Math.ceil(c/be),o=s>o?s+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=u.length,i=l.length,o-i<0&&(i=o,n=l,l=u,u=n),t=0;i;)t=(u[--i]=u[i]+l[i]+t)/mn|0,u[i]%=mn;for(t&&(u.unshift(t),++r),o=u.length;u[--o]==0;)u.pop();return e.d=u,e.e=Nc(u,r),_e?me(e,c,a):e},se.precision=se.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Sr+e);return n.d?(t=Zp(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},se.round=function(){var e=this,t=e.constructor;return me(new t(e),e.e+1,t.rounding)},se.sine=se.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+be,r.rounding=1,n=AE(r,ny(r,n)),r.precision=e,r.rounding=t,me(Kn>2?n.neg():n,e,t,!0)):new r(NaN)},se.squareRoot=se.sqrt=function(){var e,t,n,r,i,s,o=this,c=o.d,a=o.e,u=o.s,l=o.constructor;if(u!==1||!c||!c[0])return new l(!u||u<0&&(!c||c[0])?NaN:c?o:1/0);for(_e=!1,u=Math.sqrt(+o),u==0||u==1/0?(t=xt(c),(t.length+a)%2==0&&(t+="0"),u=Math.sqrt(t),a=Nt((a+1)/2)-(a<0||a%2),u==1/0?t="5e"+a:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+a),r=new l(t)):r=new l(u.toString()),n=(a=l.precision)+3;;)if(s=r,r=s.plus(Ke(o,s,n+2,1)).times(.5),xt(s.d).slice(0,n)===(t=xt(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!i&&t=="4999"){if(!i&&(me(s,a+1,0),s.times(s).eq(o))){r=s;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(me(r,a+1,1),e=!r.times(r).eq(o));break}return _e=!0,me(r,a,l.rounding,e)},se.tangent=se.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=Ke(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,me(Kn==2||Kn==4?n.neg():n,e,t,!0)):new r(NaN)},se.times=se.mul=function(e){var t,n,r,i,s,o,c,a,u,l=this,h=l.constructor,y=l.d,p=(e=new h(e)).d;if(e.s*=l.s,!y||!y[0]||!p||!p[0])return new h(!e.s||y&&!y[0]&&!p||p&&!p[0]&&!y?NaN:!y||!p?e.s/0:e.s*0);for(n=Nt(l.e/be)+Nt(e.e/be),a=y.length,u=p.length,a<u&&(s=y,y=p,p=s,o=a,a=u,u=o),s=[],o=a+u,r=o;r--;)s.push(0);for(r=u;--r>=0;){for(t=0,i=a+r;i>r;)c=s[i]+p[r]*y[i-r-1]+t,s[i--]=c%mn|0,t=c/mn|0;s[i]=(s[i]+t)%mn|0}for(;!s[--o];)s.pop();return t?++n:s.shift(),e.d=s,e.e=Nc(s,n),_e?me(e,h.precision,h.rounding):e},se.toBinary=function(e,t){return ff(this,2,e,t)},se.toDecimalPlaces=se.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:($t(e,0,_r),t===void 0?t=r.rounding:$t(t,0,8),me(n,e+n.e+1,t))},se.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Tn(r,!0):($t(e,0,_r),t===void 0?t=i.rounding:$t(t,0,8),r=me(new i(r),e+1,t),n=Tn(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n},se.toFixed=function(e,t){var n,r,i=this,s=i.constructor;return e===void 0?n=Tn(i):($t(e,0,_r),t===void 0?t=s.rounding:$t(t,0,8),r=me(new s(i),e+i.e+1,t),n=Tn(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n},se.toFraction=function(e){var t,n,r,i,s,o,c,a,u,l,h,y,p=this,m=p.d,g=p.constructor;if(!m)return new g(p);if(u=n=new g(1),r=a=new g(0),t=new g(r),s=t.e=Zp(m)-p.e-1,o=s%be,t.d[0]=ht(10,o<0?be+o:o),e==null)e=s>0?t:u;else{if(c=new g(e),!c.isInt()||c.lt(u))throw Error(Sr+c);e=c.gt(t)?s>0?t:u:c}for(_e=!1,c=new g(xt(m)),l=g.precision,g.precision=s=m.length*be*2;h=Ke(c,t,0,1,1),i=n.plus(h.times(r)),i.cmp(e)!=1;)n=r,r=i,i=u,u=a.plus(h.times(i)),a=i,i=t,t=c.minus(h.times(i)),c=i;return i=Ke(e.minus(n),r,0,1,1),a=a.plus(i.times(u)),n=n.plus(i.times(r)),a.s=u.s=p.s,y=Ke(u,r,s,1).minus(p).abs().cmp(Ke(a,n,s,1).minus(p).abs())<1?[u,r]:[a,n],g.precision=l,_e=!0,y},se.toHexadecimal=se.toHex=function(e,t){return ff(this,16,e,t)},se.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:$t(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(_e=!1,n=Ke(n,e,0,t,1).times(e),_e=!0,me(n)):(e.s=n.s,n=e),n},se.toNumber=function(){return+this},se.toOctal=function(e,t){return ff(this,8,e,t)},se.toPower=se.pow=function(e){var t,n,r,i,s,o,c=this,a=c.constructor,u=+(e=new a(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new a(ht(+c,u));if(c=new a(c),c.eq(1))return c;if(r=a.precision,s=a.rounding,e.eq(1))return me(c,r,s);if(t=Nt(e.e/be),t>=e.d.length-1&&(n=u<0?-u:u)<=xE)return i=Jp(a,c,n,r),e.s<0?new a(1).div(i):me(i,r,s);if(o=c.s,o<0){if(t<e.d.length-1)return new a(NaN);if((e.d[t]&1)==0&&(o=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=o,c}return n=ht(+c,u),t=n==0||!isFinite(n)?Nt(u*(Math.log("0."+xt(c.d))/Math.LN10+c.e+1)):new a(n+"").e,t>a.maxE+1||t<a.minE-1?new a(t>0?o/0:0):(_e=!1,a.rounding=c.s=1,n=Math.min(12,(t+"").length),i=uf(e.times(Tr(c,r+n)),r),i.d&&(i=me(i,r+5,1),Ys(i.d,r,s)&&(t=r+10,i=me(uf(e.times(Tr(c,t+n)),t),t+5,1),+xt(i.d).slice(r+1,r+15)+1==1e14&&(i=me(i,r+1,0)))),i.s=o,_e=!0,a.rounding=s,me(i,r,s))},se.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Tn(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):($t(e,1,_r),t===void 0?t=i.rounding:$t(t,0,8),r=me(new i(r),e,t),n=Tn(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n},se.toSignificantDigits=se.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):($t(e,1,_r),t===void 0?t=r.rounding:$t(t,0,8)),me(new r(n),e,t)},se.toString=function(){var e=this,t=e.constructor,n=Tn(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n},se.truncated=se.trunc=function(){return me(new this.constructor(this),this.e+1,1)},se.valueOf=se.toJSON=function(){var e=this,t=e.constructor,n=Tn(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function xt(e){var t,n,r,i=e.length-1,s="",o=e[0];if(i>0){for(s+=o,t=1;t<i;t++)r=e[t]+"",n=be-r.length,n&&(s+=xr(n)),s+=r;o=e[t],r=o+"",n=be-r.length,n&&(s+=xr(n))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function $t(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Sr+e)}function Ys(e,t,n,r){var i,s,o,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=be,i=0):(i=Math.ceil((t+1)/be),t%=be),s=ht(10,be-t),c=e[i]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),o=n<4&&c==99999||n>3&&c==49999||c==5e4||c==0):o=(n<4&&c+1==s||n>3&&c+1==s/2)&&(e[i+1]/s/100|0)==ht(10,t-2)-1||(c==s/2||c==0)&&(e[i+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),o=(r||n<4)&&c==9999||!r&&n>3&&c==4999):o=((r||n<4)&&c+1==s||!r&&n>3&&c+1==s/2)&&(e[i+1]/s/1e3|0)==ht(10,t-3)-1,o}function Oc(e,t,n){for(var r,i=[0],s,o=0,c=e.length;o<c;){for(s=i.length;s--;)i[s]*=t;for(i[0]+=of.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function vE(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Pc(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),e.precision+=n,t=ji(e,1,t.times(i),new e(1));for(var s=n;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var Ke=(function(){function e(r,i,s){var o,c=0,a=r.length;for(r=r.slice();a--;)o=r[a]*i+c,r[a]=o%s|0,c=o/s|0;return c&&r.unshift(c),r}function t(r,i,s,o){var c,a;if(s!=o)a=s>o?1:-1;else for(c=a=0;c<s;c++)if(r[c]!=i[c]){a=r[c]>i[c]?1:-1;break}return a}function n(r,i,s,o){for(var c=0;s--;)r[s]-=c,c=r[s]<i[s]?1:0,r[s]=c*o+r[s]-i[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,s,o,c,a){var u,l,h,y,p,m,g,E,x,_,w,T,R,B,P,q,v,C,L,K,U=r.constructor,D=r.s==i.s?1:-1,k=r.d,j=i.d;if(!k||!k[0]||!j||!j[0])return new U(!r.s||!i.s||(k?j&&k[0]==j[0]:!j)?NaN:k&&k[0]==0||!j?D*0:D/0);for(a?(p=1,l=r.e-i.e):(a=mn,p=be,l=Nt(r.e/p)-Nt(i.e/p)),L=j.length,v=k.length,x=new U(D),_=x.d=[],h=0;j[h]==(k[h]||0);h++);if(j[h]>(k[h]||0)&&l--,s==null?(B=s=U.precision,o=U.rounding):c?B=s+(r.e-i.e)+1:B=s,B<0)_.push(1),m=!0;else{if(B=B/p+2|0,h=0,L==1){for(y=0,j=j[0],B++;(h<v||y)&&B--;h++)P=y*a+(k[h]||0),_[h]=P/j|0,y=P%j|0;m=y||h<v}else{for(y=a/(j[0]+1)|0,y>1&&(j=e(j,y,a),k=e(k,y,a),L=j.length,v=k.length),q=L,w=k.slice(0,L),T=w.length;T<L;)w[T++]=0;K=j.slice(),K.unshift(0),C=j[0],j[1]>=a/2&&++C;do y=0,u=t(j,w,L,T),u<0?(R=w[0],L!=T&&(R=R*a+(w[1]||0)),y=R/C|0,y>1?(y>=a&&(y=a-1),g=e(j,y,a),E=g.length,T=w.length,u=t(g,w,E,T),u==1&&(y--,n(g,L<E?K:j,E,a))):(y==0&&(u=y=1),g=j.slice()),E=g.length,E<T&&g.unshift(0),n(w,g,T,a),u==-1&&(T=w.length,u=t(j,w,L,T),u<1&&(y++,n(w,L<T?K:j,T,a))),T=w.length):u===0&&(y++,w=[0]),_[h++]=y,u&&w[0]?w[T++]=k[q]||0:(w=[k[q]],T=1);while((q++<v||w[0]!==void 0)&&B--);m=w[0]!==void 0}_[0]||_.shift()}if(p==1)x.e=l,Gp=m;else{for(h=1,y=_[0];y>=10;y/=10)h++;x.e=h+l*p-1,me(x,c?s+x.e+1:s,o,m)}return x}})();function me(e,t,n,r){var i,s,o,c,a,u,l,h,y,p=e.constructor;e:if(t!=null){if(h=e.d,!h)return e;for(i=1,c=h[0];c>=10;c/=10)i++;if(s=t-i,s<0)s+=be,o=t,l=h[y=0],a=l/ht(10,i-o-1)%10|0;else if(y=Math.ceil((s+1)/be),c=h.length,y>=c)if(r){for(;c++<=y;)h.push(0);l=a=0,i=1,s%=be,o=s-be+1}else break e;else{for(l=c=h[y],i=1;c>=10;c/=10)i++;s%=be,o=s-be+i,a=o<0?0:l/ht(10,i-o-1)%10|0}if(r=r||t<0||h[y+1]!==void 0||(o<0?l:l%ht(10,i-o-1)),u=n<4?(a||r)&&(n==0||n==(e.s<0?3:2)):a>5||a==5&&(n==4||r||n==6&&(s>0?o>0?l/ht(10,i-o):0:h[y-1])%10&1||n==(e.s<0?8:7)),t<1||!h[0])return h.length=0,u?(t-=e.e+1,h[0]=ht(10,(be-t%be)%be),e.e=-t||0):h[0]=e.e=0,e;if(s==0?(h.length=y,c=1,y--):(h.length=y+1,c=ht(10,be-s),h[y]=o>0?(l/ht(10,i-o)%ht(10,o)|0)*c:0),u)for(;;)if(y==0){for(s=1,o=h[0];o>=10;o/=10)s++;for(o=h[0]+=c,c=1;o>=10;o/=10)c++;s!=c&&(e.e++,h[0]==mn&&(h[0]=1));break}else{if(h[y]+=c,h[y]!=mn)break;h[y--]=0,c=1}for(s=h.length;h[--s]===0;)h.pop()}return _e&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function Tn(e,t,n){if(!e.isFinite())return ty(e);var r,i=e.e,s=xt(e.d),o=s.length;return t?(n&&(r=n-o)>0?s=s.charAt(0)+"."+s.slice(1)+xr(r):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):i<0?(s="0."+xr(-i-1)+s,n&&(r=n-o)>0&&(s+=xr(r))):i>=o?(s+=xr(i+1-o),n&&(r=n-i-1)>0&&(s=s+"."+xr(r))):((r=i+1)<o&&(s=s.slice(0,r)+"."+s.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(s+="."),s+=xr(r))),s}function Nc(e,t){var n=e[0];for(t*=be;n>=10;n/=10)t++;return t}function Rc(e,t,n){if(t>TE)throw _e=!0,n&&(e.precision=n),Error(Wp);return me(new e(Bc),t,1,!0)}function vn(e,t,n){if(t>af)throw Error(Wp);return me(new e(Ac),t,n,!0)}function Zp(e){var t=e.length-1,n=t*be+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function xr(e){for(var t="";e--;)t+="0";return t}function Jp(e,t,n,r){var i,s=new e(1),o=Math.ceil(r/be+4);for(_e=!1;;){if(n%2&&(s=s.times(t),ry(s.d,o)&&(i=!0)),n=Nt(n/2),n===0){n=s.d.length-1,i&&s.d[n]===0&&++s.d[n];break}t=t.times(t),ry(t.d,o)}return _e=!0,s}function Qp(e){return e.d[e.d.length-1]&1}function ey(e,t,n){for(var r,i,s=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){s=i;break}r=s.cmp(i),(r===n||r===0&&s.s===n)&&(s=i)}return s}function uf(e,t){var n,r,i,s,o,c,a,u=0,l=0,h=0,y=e.constructor,p=y.rounding,m=y.precision;if(!e.d||!e.d[0]||e.e>17)return new y(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(_e=!1,a=m):a=t,c=new y(.03125);e.e>-2;)e=e.times(c),h+=5;for(r=Math.log(ht(2,h))/Math.LN10*2+5|0,a+=r,n=s=o=new y(1),y.precision=a;;){if(s=me(s.times(e),a,1),n=n.times(++l),c=o.plus(Ke(s,n,a,1)),xt(c.d).slice(0,a)===xt(o.d).slice(0,a)){for(i=h;i--;)o=me(o.times(o),a,1);if(t==null)if(u<3&&Ys(o.d,a-r,p,u))y.precision=a+=10,n=s=c=new y(1),l=0,u++;else return me(o,y.precision=m,p,_e=!0);else return y.precision=m,o}o=c}}function Tr(e,t){var n,r,i,s,o,c,a,u,l,h,y,p=1,m=10,g=e,E=g.d,x=g.constructor,_=x.rounding,w=x.precision;if(g.s<0||!E||!E[0]||!g.e&&E[0]==1&&E.length==1)return new x(E&&!E[0]?-1/0:g.s!=1?NaN:E?0:g);if(t==null?(_e=!1,l=w):l=t,x.precision=l+=m,n=xt(E),r=n.charAt(0),Math.abs(s=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(e),n=xt(g.d),r=n.charAt(0),p++;s=g.e,r>1?(g=new x("0."+n),s++):g=new x(r+"."+n.slice(1))}else return u=Rc(x,l+2,w).times(s+""),g=Tr(new x(r+"."+n.slice(1)),l-m).plus(u),x.precision=w,t==null?me(g,w,_,_e=!0):g;for(h=g,a=o=g=Ke(g.minus(1),g.plus(1),l,1),y=me(g.times(g),l,1),i=3;;){if(o=me(o.times(y),l,1),u=a.plus(Ke(o,new x(i),l,1)),xt(u.d).slice(0,l)===xt(a.d).slice(0,l))if(a=a.times(2),s!==0&&(a=a.plus(Rc(x,l+2,w).times(s+""))),a=Ke(a,new x(p),l,1),t==null)if(Ys(a.d,l-m,_,c))x.precision=l+=m,u=o=g=Ke(h.minus(1),h.plus(1),l,1),y=me(g.times(g),l,1),i=c=1;else return me(a,x.precision=w,_,_e=!0);else return x.precision=w,a;a=u,i+=2}}function ty(e){return String(e.s*e.s/0)}function kc(e,t){var n,r,i;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%be,n<0&&(r+=be),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=be;r<i;)e.d.push(+t.slice(r,r+=be));t=t.slice(r),r=be-t.length}else r-=i;for(;r--;)t+="0";e.d.push(+t),_e&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function BE(e,t){var n,r,i,s,o,c,a,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Yp.test(t))return kc(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(_E.test(t))n=16,t=t.toLowerCase();else if(EE.test(t))n=2;else if(SE.test(t))n=8;else throw Error(Sr+t);for(s=t.search(/p/i),s>0?(a=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),o=s>=0,r=e.constructor,o&&(t=t.replace(".",""),c=t.length,s=c-s,i=Jp(r,new r(n),s,s*2)),u=Oc(t,n,mn),l=u.length-1,s=l;u[s]===0;--s)u.pop();return s<0?new r(e.s*0):(e.e=Nc(u,l),e.d=u,_e=!1,o&&(e=Ke(e,i,c*4)),a&&(e=e.times(Math.abs(a)<54?ht(2,a):$i.pow(2,a))),_e=!0,e)}function AE(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ji(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Pc(5,n)),t=ji(e,2,t,t);for(var i,s=new e(5),o=new e(16),c=new e(20);n--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(c))));return t}function ji(e,t,n,r,i){var s,o,c,a,u=e.precision,l=Math.ceil(u/be);for(_e=!1,a=n.times(n),c=new e(r);;){if(o=Ke(c.times(a),new e(t++*t++),u,1),c=i?r.plus(o):r.minus(o),r=Ke(o.times(a),new e(t++*t++),u,1),o=c.plus(r),o.d[l]!==void 0){for(s=l;o.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=o,o=s}return _e=!0,o.d.length=l+1,o}function Pc(e,t){for(var n=e;--t;)n*=e;return n}function ny(e,t){var n,r=t.s<0,i=vn(e,e.precision,1),s=i.times(.5);if(t=t.abs(),t.lte(s))return Kn=r?4:1,t;if(n=t.divToInt(i),n.isZero())Kn=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(s))return Kn=Qp(n)?r?2:3:r?4:1,t;Kn=Qp(n)?r?1:4:r?3:2}return t.minus(i).abs()}function ff(e,t,n,r){var i,s,o,c,a,u,l,h,y,p=e.constructor,m=n!==void 0;if(m?($t(n,1,_r),r===void 0?r=p.rounding:$t(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())l=ty(e);else{for(l=Tn(e),o=l.indexOf("."),m?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(l=l.replace(".",""),y=new p(1),y.e=l.length-o,y.d=Oc(Tn(y),10,i),y.e=y.d.length),h=Oc(l,10,i),s=a=h.length;h[--a]==0;)h.pop();if(!h[0])l=m?"0p+0":"0";else{if(o<0?s--:(e=new p(e),e.d=h,e.e=s,e=Ke(e,y,n,r,0,i),h=e.d,s=e.e,u=Gp),o=h[n],c=i/2,u=u||h[n+1]!==void 0,u=r<4?(o!==void 0||u)&&(r===0||r===(e.s<0?3:2)):o>c||o===c&&(r===4||u||r===6&&h[n-1]&1||r===(e.s<0?8:7)),h.length=n,u)for(;++h[--n]>i-1;)h[n]=0,n||(++s,h.unshift(1));for(a=h.length;!h[a-1];--a);for(o=0,l="";o<a;o++)l+=of.charAt(h[o]);if(m){if(a>1)if(t==16||t==8){for(o=t==16?4:3,--a;a%o;a++)l+="0";for(h=Oc(l,i,t),a=h.length;!h[a-1];--a);for(o=1,l="1.";o<a;o++)l+=of.charAt(h[o])}else l=l.charAt(0)+"."+l.slice(1);l=l+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)l="0"+l;l="0."+l}else if(++s>a)for(s-=a;s--;)l+="0";else s<a&&(l=l.slice(0,s)+"."+l.slice(s))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function ry(e,t){if(e.length>t)return e.length=t,!0}function IE(e){return new this(e).abs()}function OE(e){return new this(e).acos()}function NE(e){return new this(e).acosh()}function RE(e,t){return new this(e).plus(t)}function kE(e){return new this(e).asin()}function PE(e){return new this(e).asinh()}function CE(e){return new this(e).atan()}function UE(e){return new this(e).atanh()}function HE(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,s=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=vn(this,s,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?vn(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=vn(this,s,1).times(.5),n.s=e.s):t.s<0?(this.precision=s,this.rounding=1,n=this.atan(Ke(e,t,s,1)),t=vn(this,s,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Ke(e,t,s,1)),n}function FE(e){return new this(e).cbrt()}function qE(e){return me(e=new this(e),e.e+1,2)}function ME(e,t,n){return new this(e).clamp(t,n)}function LE(e){if(!e||typeof e!="object")throw Error(Ic+"Object expected");var t,n,r,i=e.defaults===!0,s=["precision",1,_r,"rounding",0,8,"toExpNeg",-Di,0,"toExpPos",0,Di,"maxE",0,Di,"minE",-Di,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(n=s[t],i&&(this[n]=cf[n]),(r=e[n])!==void 0)if(Nt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[n]=r;else throw Error(Sr+n+": "+r);if(n="crypto",i&&(this[n]=cf[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Xp);else this[n]=!1;else throw Error(Sr+n+": "+r);return this}function VE(e){return new this(e).cos()}function DE(e){return new this(e).cosh()}function iy(e){var t,n,r;function i(s){var o,c,a,u=this;if(!(u instanceof i))return new i(s);if(u.constructor=i,sy(s)){u.s=s.s,_e?!s.d||s.e>i.maxE?(u.e=NaN,u.d=null):s.e<i.minE?(u.e=0,u.d=[0]):(u.e=s.e,u.d=s.d.slice()):(u.e=s.e,u.d=s.d?s.d.slice():s.d);return}if(a=typeof s,a==="number"){if(s===0){u.s=1/s<0?-1:1,u.e=0,u.d=[0];return}if(s<0?(s=-s,u.s=-1):u.s=1,s===~~s&&s<1e7){for(o=0,c=s;c>=10;c/=10)o++;_e?o>i.maxE?(u.e=NaN,u.d=null):o<i.minE?(u.e=0,u.d=[0]):(u.e=o,u.d=[s]):(u.e=o,u.d=[s]);return}if(s*0!==0){s||(u.s=NaN),u.e=NaN,u.d=null;return}return kc(u,s.toString())}if(a==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),u.s=-1):(c===43&&(s=s.slice(1)),u.s=1),Yp.test(s)?kc(u,s):BE(u,s);if(a==="bigint")return s<0?(s=-s,u.s=-1):u.s=1,kc(u,s.toString());throw Error(Sr+s)}if(i.prototype=se,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=LE,i.clone=iy,i.isDecimal=sy,i.abs=IE,i.acos=OE,i.acosh=NE,i.add=RE,i.asin=kE,i.asinh=PE,i.atan=CE,i.atanh=UE,i.atan2=HE,i.cbrt=FE,i.ceil=qE,i.clamp=ME,i.cos=VE,i.cosh=DE,i.div=jE,i.exp=$E,i.floor=KE,i.hypot=GE,i.ln=WE,i.log=XE,i.log10=YE,i.log2=zE,i.max=ZE,i.min=JE,i.mod=QE,i.mul=e_,i.pow=t_,i.random=n_,i.round=r_,i.sign=i_,i.sin=s_,i.sinh=o_,i.sqrt=c_,i.sub=a_,i.sum=u_,i.tan=f_,i.tanh=l_,i.trunc=d_,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}function jE(e,t){return new this(e).div(t)}function $E(e){return new this(e).exp()}function KE(e){return me(e=new this(e),e.e+1,3)}function GE(){var e,t,n=new this(0);for(_e=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return _e=!0,new this(1/0);n=t}return _e=!0,n.sqrt()}function sy(e){return e instanceof $i||e&&e.toStringTag===zp||!1}function WE(e){return new this(e).ln()}function XE(e,t){return new this(e).log(t)}function zE(e){return new this(e).log(2)}function YE(e){return new this(e).log(10)}function ZE(){return ey(this,arguments,-1)}function JE(){return ey(this,arguments,1)}function QE(e,t){return new this(e).mod(t)}function e_(e,t){return new this(e).mul(t)}function t_(e,t){return new this(e).pow(t)}function n_(e){var t,n,r,i,s=0,o=new this(1),c=[];if(e===void 0?e=this.precision:$t(e,1,_r),r=Math.ceil(e/be),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)i=t[s],i>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)i=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(i%1e7),s+=4);s=r/4}else throw Error(Xp);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=be,r&&e&&(i=ht(10,be-e),c[s]=(r/i|0)*i);c[s]===0;s--)c.pop();if(s<0)n=0,c=[0];else{for(n=-1;c[0]===0;n-=be)c.shift();for(r=1,i=c[0];i>=10;i/=10)r++;r<be&&(n-=be-r)}return o.e=n,o.d=c,o}function r_(e){return me(e=new this(e),e.e+1,this.rounding)}function i_(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function s_(e){return new this(e).sin()}function o_(e){return new this(e).sinh()}function c_(e){return new this(e).sqrt()}function a_(e,t){return new this(e).sub(t)}function u_(){var e=0,t=arguments,n=new this(t[e]);for(_e=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return _e=!0,me(n,this.precision,this.rounding)}function f_(e){return new this(e).tan()}function l_(e){return new this(e).tanh()}function d_(e){return me(e=new this(e),e.e+1,1)}se[Symbol.for("nodejs.util.inspect.custom")]=se.toString,se[Symbol.toStringTag]="Decimal";var $i=se.constructor=iy(cf);Bc=new $i(Bc),Ac=new $i(Ac);const h_=({IDL:e})=>{const t=e.Variant({Ok:e.Null,Err:e.Text}),n=e.Variant({P2WPKH:e.Null,OpReturn:e.Nat64,P2SH:e.Null,P2TR:e.Null}),r=e.Record({input_types:e.Vec(n),pool_address:e.Vec(e.Text),output_types:e.Vec(n)}),i=e.Variant({Ok:e.Nat64,Err:e.Text}),s=e.Record({user_id:e.Principal}),o=e.Record({canister_version:e.Opt(e.Nat64),canister_id:e.Principal}),c=e.Variant({from_user:s,from_canister:o}),a=e.Record({controllers:e.Vec(e.Principal)}),u=e.Variant({reinstall:e.Null,upgrade:e.Null,install:e.Null}),l=e.Record({mode:u,module_hash:e.Vec(e.Nat8)}),h=e.Record({canister_version:e.Nat64,taken_at_timestamp:e.Nat64,snapshot_id:e.Vec(e.Nat8)}),y=e.Variant({creation:a,code_deployment:l,load_snapshot:h,controllers_change:a,code_uninstall:e.Null}),p=e.Record({timestamp_nanos:e.Nat64,canister_version:e.Nat64,origin:c,details:y}),m=e.Record({controllers:e.Vec(e.Principal),module_hash:e.Opt(e.Vec(e.Nat8)),recent_changes:e.Vec(p),total_num_changes:e.Nat64}),g=e.Variant({Ok:m,Err:e.Text}),E=e.Record({exchange_id:e.Text,pool_address:e.Text,pool_key:e.Text}),x=e.Variant({All:e.Null,ByTxid:e.Text,ByAddress:e.Text,BySecondsPassed:e.Nat64}),_=e.Variant({Ok:e.Text,Err:e.Text}),w=e.Record({result:_,exchange_id:e.Text,maybe_return_time:e.Opt(e.Text),calling_method:e.Text,calling_args:e.Text,pool_address:e.Text,calling_time:e.Text}),T=e.Record({rollback_results:e.Vec(e.Text),invoke_args:e.Text,invoke_time:e.Text,finalized_time:e.Opt(e.Text),confirmed_time:e.Opt(e.Text),execution_steps:e.Vec(w),processing_result:_,broadcasted_time:e.Opt(e.Text)}),R=e.Record({block_hash:e.Text,block_height:e.Nat32}),B=e.Record({processing_results:e.Vec(e.Text),block_basic:R,txids:e.Vec(e.Text),block_time:e.Text,received_time:e.Text}),P=e.Variant({Active:e.Null,Halted:e.Record({reason:e.Text})}),q=e.Record({status:P,exchange_id:e.Text,canister_id:e.Principal,client_canisters:e.Vec(e.Principal)}),v=e.Record({rollback_results:e.Vec(e.Text),txid:e.Text,received_time:e.Text,reason:e.Text}),C=e.Variant({mainnet:e.Null,regtest:e.Null,testnet:e.Null}),L=e.Record({exchange_registry_principal:e.Principal,max_input_count_of_psbt:e.Nat32,min_tx_confirmations:e.Nat32,mempool_connector_principal:e.Principal,max_unconfirmed_tx_count_in_pool:e.Nat32,min_btc_amount_for_utxo:e.Nat64,rune_indexer_principal:e.Principal,max_intentions_per_invoke:e.Nat32,max_received_blocks_count:e.Nat32,bitcoin_network:C}),K=e.Record({low:e.Nat64,high:e.Nat64,update_time:e.Text,medium:e.Nat64}),U=e.Variant({Enabled:e.Null,Disabled:e.Null,AllowEmpty:e.Null}),D=e.Record({last_block:e.Opt(R),pending_tx_count:e.Nat64,mempool_tx_fee_rate:K,invoke_paused:e.Bool,utxo_proof_verification_status:U}),k=e.Variant({Confirmed:e.Nat32,Rejected:e.Text,Pending:e.Null}),j=e.Record({status:e.Opt(k),invoke_log:T,included_block:e.Opt(R),sent_tx_hex:e.Text}),F=e.Record({id:e.Text,value:e.Nat}),S=e.Record({maybe_rune:e.Opt(F),value:e.Nat64,script_pubkey_hex:e.Text,outpoint:e.Text}),I=e.Record({coin:F,from:e.Text}),M=e.Record({to:e.Text,coin:F}),O=e.Record({coins:e.Vec(F),sats:e.Nat64,txid:e.Text,vout:e.Nat32}),V=e.Record({input_coins:e.Vec(I),output_coins:e.Vec(M),action:e.Text,exchange_id:e.Text,pool_utxo_spent:e.Vec(e.Text),action_params:e.Text,nonce:e.Nat64,pool_address:e.Text,pool_utxo_received:e.Vec(O)}),G=e.Record({tx_fee_in_sats:e.Nat64,initiator_address:e.Text,intentions:e.Vec(V)}),X=e.Record({intention_set:G,initiator_utxo_proof:e.Vec(e.Nat8),psbt_hex:e.Text}),Y=e.Record({block_hash:e.Text,block_timestamp:e.Nat64,tx_ids:e.Vec(e.Text),block_height:e.Nat32}),ce=e.Variant({Ok:e.Vec(e.Text),Err:e.Text}),ue=e.Record({exchange_canister:e.Principal,exchange_id:e.Text,client_canisters:e.Vec(e.Principal)}),te=e.Record({txid:e.Text,timestamp:e.Nat64,block:R}),Z=e.Record({low:e.Nat64,high:e.Nat64,medium:e.Nat64});return e.Service({clear_failed_invoke_logs:e.Func([e.Opt(e.Nat64),e.Vec(e.Text)],[t],[]),estimate_min_tx_fee:e.Func([r],[i],["query"]),get_canister_info:e.Func([e.Nat64],[g],[]),get_exchange_pools:e.Func([],[e.Vec(E)],["query"]),get_failed_invoke_logs:e.Func([x],[e.Vec(e.Tuple(e.Text,T))],["query"]),get_last_sent_txs:e.Func([e.Opt(e.Nat32)],[e.Vec(e.Tuple(e.Text,e.Text,e.Opt(e.Nat32)))],["query"]),get_received_blocks:e.Func([e.Opt(e.Bool)],[e.Vec(B)],["query"]),get_registered_exchanges:e.Func([],[e.Vec(q)],["query"]),get_rejected_txs:e.Func([e.Opt(e.Nat32)],[e.Vec(v)],["query"]),get_settings:e.Func([],[L],["query"]),get_status:e.Func([],[D],["query"]),get_tx_for_outpoint:e.Func([e.Text],[e.Opt(j)],["query"]),get_tx_queue_of_pool:e.Func([e.Text],[e.Vec(e.Tuple(e.Text,e.Opt(e.Nat32)))],["query"]),get_tx_sent:e.Func([e.Text],[e.Opt(j)],["query"]),get_used_outpoints:e.Func([e.Opt(e.Text)],[e.Vec(e.Tuple(e.Text,e.Text))],["query"]),get_zero_confirmed_tx_count_of_pool:e.Func([e.Text],[e.Nat32],["query"]),get_zero_confirmed_txs:e.Func([e.Opt(e.Text)],[e.Vec(e.Text)],["query"]),get_zero_confirmed_utxos_of_address:e.Func([e.Text],[e.Vec(S)],["query"]),invoke:e.Func([X],[_],[]),new_block_detected:e.Func([Y],[t],[]),notify_exchange_for_blocks_from_height:e.Func([e.Text,e.Nat32],[ce],[]),register_exchange:e.Func([ue],[t],[]),save_included_block_for_tx:e.Func([te],[t],[]),set_max_input_count_of_psbt:e.Func([e.Nat32],[t],[]),set_max_intentions_per_invoke:e.Func([e.Nat32],[t],[]),set_max_received_blocks_count:e.Func([e.Nat32],[t],[]),set_max_unconfirmed_tx_count_in_pool:e.Func([e.Nat32],[t],[]),set_min_btc_amount_for_utxo:e.Func([e.Nat64],[t],[]),set_min_tx_confirmations:e.Func([e.Nat32],[t],[]),set_tx_fee_per_vbyte:e.Func([Z],[t],[]),update_bitcoin_subnet_certificate:e.Func([e.Vec(e.Nat8)],[],[]),version:e.Func([],[e.Text],["query"])})};class oy{maestro;config;exchange;orchestrator;constructor(t){this.config=t;const n=t.network===hs.Testnet,r=n?"https://xbt-testnet.gomaestro-api.org/v0":"https://xbt-mainnet.gomaestro-api.org/v0";this.maestro=new v1({baseUrl:r,apiKey:t.maestroApiKey});const i="https://icp0.io";this.exchange=wc.createActor(t.exchangeIdlFactory,{agent:jn.createSync({host:i,retryTimes:50,verifyQuerySignatures:!1}),canisterId:t.exchangeCanisterId}),this.orchestrator=wc.createActor(h_,{agent:jn.createSync({host:i,retryTimes:50,verifyQuerySignatures:!1}),canisterId:n?h2:d2})}async filterSpentUtxos(t,n){const r=await this.orchestrator.get_used_outpoints([t]);return n.filter(({txid:i,vout:s})=>r.findIndex(([o])=>`${i}:${s}`===o)<0)}async getBtcUtxos(t){let n=null;const r=[];do{const s=await this.maestro.utxosByAddress(t,n);r.push(...s.data),n=s.next_cursor}while(n!==null);const i=r.map(({txid:s,vout:o,runes:c,satoshis:a,script_pubkey:u,address:l})=>({txid:s,vout:o,address:l,runes:c.map(({rune_id:h,amount:y})=>({id:h,amount:y})),satoshis:a,scriptPk:u}));return this.filterSpentUtxos(t,i)}async getRuneUtxos(t,n){let r=null;const i=[];do{const o=await this.maestro.runeUtxosByAddress(t,n,r);i.push(...o.data),r=o.next_cursor}while(r!==null);const s=i.map(({txid:o,vout:c,runes:a,satoshis:u})=>{const l=Ku(t,this.config.network);return{txid:o,vout:c,address:t,runes:a.map(({rune_id:h,amount:y})=>({id:h,amount:y})),satoshis:u,scriptPk:ju(l)}});return this.filterSpentUtxos(t,s)}async searchRunes(t){const n=this.config.network===hs.Testnet?y2:p2,r=bE`
127
+ query GetRunes($keyword: String!, $regex: String!) {
128
+ runes(
129
+ where: {
130
+ _or: [
131
+ { rune_id: { _eq: $keyword } }
132
+ { spaced_rune: { _iregex: $regex } }
133
+ ]
134
+ }
135
+ limit: 100
136
+ ) {
137
+ rune_id
138
+ spaced_rune
139
+ symbol
140
+ id
141
+ number
142
+ etching
143
+ divisibility
144
+ }
145
+ }
146
+ `,i=new gE(n),s=t.split("").filter(c=>!(c==="•"||c===" ")).join("•?"),{runes:o}=await i.request(r,{keyword:t,regex:`(?i)${s}`});return o.map(({rune_id:c,spaced_rune:a,symbol:u,divisibility:l,etching:h})=>({runeId:c,spacedRune:a,symbol:u,divisibility:l,etching:h}))}async getRuneInfo(t){return(await this.searchRunes(t))[0]}async getBtcBalance(t){const r=(await this.getBtcUtxos(t)).reduce((i,s)=>i+BigInt(s.satoshis),BigInt(0));return new $i(r.toString()).div(1e8).toNumber()}async getRuneBalance(t,n){const[r,i]=await Promise.all([this.getRuneUtxos(t,n),this.getRuneInfo(n)]);if(!r||!i)return;let s=BigInt(0);for(const o of r)s+=BigInt(o.runes.find(c=>c.id===n)?.amount??0);return s>BigInt(0)?new $i(s.toString()).div(Math.pow(i.divisibility,10)).toNumber():0}async getPoolList(){try{return await this.exchange.get_pool_list()??[]}catch(t){throw console.error("get pool list failed:",t),t}}async getPoolInfo(t){try{const n=await this.exchange.get_pool_info({pool_address:t});if(n.length===0)throw new Error("Pool not found");return n[0]}catch(n){throw console.error("get pool data failed:",n),n}}async createTransaction({address:t,paymentAddress:n,runeId:r,poolAddress:i,sendBtcAmount:s,sendRuneAmount:o,receiveBtcAmount:c,receiveRuneAmount:a}){const[u,l,h]=await Promise.all([this.getBtcUtxos(n),r?this.getRuneUtxos(t,r):Promise.resolve([]),this.getPoolInfo(i)]),y=h.utxos.map(({txid:p,vout:m,coins:g,sats:E})=>{const x=Ku(i,this.config.network);return{txid:p,vout:m,address:i,runes:g.map(({id:_,value:w})=>({id:_,amount:w.toString()})),satoshis:E.toString(),scriptPk:ju(x)}});return new bp({network:this.config.network,exchangeId:this.config.exchangeId,address:t,paymentAddress:n,poolAddress:i,runeId:r,sendBtcAmount:s,sendRuneAmount:o,receiveBtcAmount:c,receiveRuneAmount:a,btcUtxos:u,runeUtxos:l,poolUtxos:y},this.orchestrator)}}const cy=ye.createContext(null);function p_({children:e,config:t}){if(!t)throw new Error("ReeProvider: config is required");if(!t.network)throw new Error("ReeProvider: config.network is required");if(!t.maestroApiKey)throw new Error("ReeProvider: config.maestroApiKey is required");if(!t.exchangeIdlFactory)throw new Error("ReeProvider: config.exchangeIdlFactory is required");if(!t.exchangeCanisterId)throw new Error("ReeProvider: config.exchangeCanisterId is required");const[n,r]=ye.useState({address:"",paymentAddress:"",publicKey:"",paymentPublicKey:""}),i=ye.useCallback(a=>{r(u=>({...u,...a}))},[]),s=ye.useMemo(()=>new oy(t),[t]),o=ye.useCallback(async a=>{if(!s)throw new Error("Client not available");if(!n.address||!n.paymentAddress)throw new Error("Wallet not connected");return s.createTransaction({...a,address:n.address,paymentAddress:n.paymentAddress})},[s,n]),c=ye.useMemo(()=>({client:s,...n,exchange:s.exchange,updateWallet:i,createTransaction:o}),[s,n,i,o]);return nt.jsx(cy.Provider,{value:c,children:e})}function Gn(){const e=ye.useContext(cy);if(!e)throw new Error("useRee must be used within ReeProvider");return e}function y_(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:r,paymentAddress:i}=Gn(),[s,o]=ye.useState(null),[c,a]=ye.useState(!1),[u,l]=ye.useState(null),h=ye.useCallback(async()=>{if(!i){o(null),l("Payment address not set");return}a(!0),l(null);try{const y=await r.getBtcBalance(i);o(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch BTC balance"),o(null)}finally{a(!1)}},[r,i]);return ye.useEffect(()=>{n&&h()},[i,h,n]),ye.useEffect(()=>{if(t>0){const y=setInterval(h,t);return()=>clearInterval(y)}},[t,i,h]),{balance:s,loading:c,error:u,refetch:h}}function m_(e,t={}){const{refreshInterval:n=0,autoRefresh:r=!0}=t,{client:i,address:s}=Gn(),[o,c]=ye.useState(null),[a,u]=ye.useState(!1),[l,h]=ye.useState(null),y=ye.useCallback(async()=>{if(!s){c(null),h("Address not set");return}if(!e){c(null),h("Rune ID is required");return}u(!0),h(null);try{const p=await i.getRuneBalance(s,e);c(p??null)}catch(p){h(p instanceof Error?p.message:"Failed to fetch rune balance"),c(null)}finally{u(!1)}},[i,s,e]);return ye.useEffect(()=>{r&&e&&y()},[s,e,y,r]),ye.useEffect(()=>{if(n>0&&e){const p=setInterval(y,n);return()=>clearInterval(p)}},[n,s,e,y]),{balance:o,loading:a,error:l,refetch:y}}function g_(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:r,paymentAddress:i}=Gn(),[s,o]=ye.useState([]),[c,a]=ye.useState(!1),[u,l]=ye.useState(null),h=ye.useCallback(async()=>{if(!i){o([]),l("Payment address not set");return}a(!0),l(null);try{const y=await r.getBtcUtxos(i);o(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch BTC UTXOs"),o([])}finally{a(!1)}},[r,i]);return ye.useEffect(()=>{n&&i&&h()},[i,h,n]),ye.useEffect(()=>{if(t>0&&i){const y=setInterval(h,t);return()=>clearInterval(y)}},[t,i,h]),{utxos:s,loading:c,error:u,refetch:h}}function w_(e,t={}){const{refreshInterval:n=0,autoRefresh:r=!0}=t,{client:i,address:s}=Gn(),[o,c]=ye.useState([]),[a,u]=ye.useState(!1),[l,h]=ye.useState(null),y=ye.useCallback(async()=>{if(!s){c([]),h("Address not set");return}if(!e){c([]),h("Rune ID is required");return}u(!0),h(null);try{const p=await i.getRuneUtxos(s,e);c(p)}catch(p){h(p instanceof Error?p.message:"Failed to fetch rune UTXOs"),c([])}finally{u(!1)}},[i,s,e]);return ye.useEffect(()=>{r&&s&&e&&y()},[s,e,y,r]),ye.useEffect(()=>{if(n>0&&s&&e){const p=setInterval(y,n);return()=>clearInterval(p)}},[n,s,e,y]),{utxos:o,loading:a,error:l,refetch:y}}function b_(){const{client:e}=Gn();return ye.useCallback(async n=>{const r=n;if(!r)throw new Error("Search keyword is required");return await e.searchRunes(r)},[e])}function E_(e){const{client:t}=Gn(),[n,r]=ye.useState(null),[i,s]=ye.useState(!1),[o,c]=ye.useState(null),a=ye.useCallback(async()=>{if(!e){r(null),c("Rune ID is required");return}s(!0),c(null);try{const u=await t.getRuneInfo(e);r(u||null)}catch(u){c(u instanceof Error?u.message:"Failed to fetch rune info"),r(null)}finally{s(!1)}},[t,e]);return{runeInfo:n,loading:i,error:o,refetch:a}}function __(){const{client:e}=Gn(),[t,n]=ye.useState([]),[r,i]=ye.useState(!1),[s,o]=ye.useState(null),c=ye.useCallback(async()=>{i(!0),o(null);try{const a=await e.getPoolList();n(a)}catch(a){o(a instanceof Error?a.message:"Failed to fetch pool list"),n([])}finally{i(!1)}},[e]);return ye.useEffect(()=>{c()},[c]),{pools:t,loading:r,error:s,refetch:c}}function S_(e){const{client:t}=Gn(),[n,r]=ye.useState(null),[i,s]=ye.useState(!1),[o,c]=ye.useState(null),a=ye.useCallback(async()=>{if(!e){r(null),c("Pool address is required");return}s(!0),c(null);try{const u=await t.getPoolInfo(e);r(u)}catch(u){c(u instanceof Error?u.message:"Failed to fetch pool info"),r(null)}finally{s(!1)}},[t,e]);return ye.useEffect(()=>{a()},[e]),{poolInfo:n,loading:i,error:o,refetch:a}}Ie.Network=hs,Ie.ReeClient=oy,Ie.ReeProvider=p_,Ie.Transaction=bp,Ie.useBtcBalance=y_,Ie.useBtcUtxos=g_,Ie.usePoolInfo=S_,Ie.usePoolList=__,Ie.useRee=Gn,Ie.useRuneBalance=m_,Ie.useRuneInfo=E_,Ie.useRuneUtxos=w_,Ie.useSearchRunes=b_,Ie.utils=l2,Object.defineProperty(Ie,Symbol.toStringTag,{value:"Module"})}));