@omnity/ree-client-ts-sdk 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/ree-sdk.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/ree-sdk.umd.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
(function(Ae,
|
|
1
|
+
(function(Ae,ut){typeof exports=="object"&&typeof module<"u"?ut(exports,require("bitcoinjs-lib"),require("@dfinity/candid"),require("axios"),require("@dfinity/agent"),require("graphql"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","bitcoinjs-lib","@dfinity/candid","axios","@dfinity/agent","graphql","react/jsx-runtime","react"],ut):(Ae=typeof globalThis<"u"?globalThis:Ae||self,ut(Ae["ree-sdk"]={},Ae.bitcoin,null,Ae.axios,Ae.agent,Ae.GraphQL,Ae.React,Ae.React))})(this,(function(Ae,ut,wo,pr,Bt,Ct,gr,ge){"use strict";const mr=e=>e&&e.__esModule?e:{default:e};function wr(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}function yr(e,t){for(var n=0;n<t.length;n++){const i=t[n];if(typeof i!="string"&&!Array.isArray(i)){for(const c in i)if(c!=="default"&&!(c in e)){const o=Object.getOwnPropertyDescriptor(i,c);o&&Object.defineProperty(e,c,o.get?o:{enumerable:!0,get:()=>i[c]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}const Ge=wr(ut),br=mr(pr);function cn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var It={},pt={},un;function Er(){if(un)return pt;un=1,pt.byteLength=u,pt.toByteArray=l,pt.fromByteArray=B;for(var e=[],t=[],n=typeof Uint8Array<"u"?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=0,o=i.length;c<o;++c)e[c]=i[c],t[i.charCodeAt(c)]=c;t[45]=62,t[95]=63;function a(v){var T=v.length;if(T%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var N=v.indexOf("=");N===-1&&(N=T);var K=N===T?0:4-N%4;return[N,K]}function u(v){var T=a(v),N=T[0],K=T[1];return(N+K)*3/4-K}function h(v,T,N){return(T+N)*3/4-N}function l(v){var T,N=a(v),K=N[0],J=N[1],F=new n(h(v,K,J)),b=0,P=J>0?K-4:K,I;for(I=0;I<P;I+=4)T=t[v.charCodeAt(I)]<<18|t[v.charCodeAt(I+1)]<<12|t[v.charCodeAt(I+2)]<<6|t[v.charCodeAt(I+3)],F[b++]=T>>16&255,F[b++]=T>>8&255,F[b++]=T&255;return J===2&&(T=t[v.charCodeAt(I)]<<2|t[v.charCodeAt(I+1)]>>4,F[b++]=T&255),J===1&&(T=t[v.charCodeAt(I)]<<10|t[v.charCodeAt(I+1)]<<4|t[v.charCodeAt(I+2)]>>2,F[b++]=T>>8&255,F[b++]=T&255),F}function m(v){return e[v>>18&63]+e[v>>12&63]+e[v>>6&63]+e[v&63]}function y(v,T,N){for(var K,J=[],F=T;F<N;F+=3)K=(v[F]<<16&16711680)+(v[F+1]<<8&65280)+(v[F+2]&255),J.push(m(K));return J.join("")}function B(v){for(var T,N=v.length,K=N%3,J=[],F=16383,b=0,P=N-K;b<P;b+=F)J.push(y(v,b,b+F>P?P:b+F));return K===1?(T=v[N-1],J.push(e[T>>2]+e[T<<4&63]+"==")):K===2&&(T=(v[N-2]<<8)+v[N-1],J.push(e[T>>10]+e[T>>4&63]+e[T<<2&63]+"=")),J.join("")}return pt}var _t={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */var an;function Br(){return an||(an=1,_t.read=function(e,t,n,i,c){var o,a,u=c*8-i-1,h=(1<<u)-1,l=h>>1,m=-7,y=n?c-1:0,B=n?-1:1,v=e[t+y];for(y+=B,o=v&(1<<-m)-1,v>>=-m,m+=u;m>0;o=o*256+e[t+y],y+=B,m-=8);for(a=o&(1<<-m)-1,o>>=-m,m+=i;m>0;a=a*256+e[t+y],y+=B,m-=8);if(o===0)o=1-l;else{if(o===h)return a?NaN:(v?-1:1)*(1/0);a=a+Math.pow(2,i),o=o-l}return(v?-1:1)*a*Math.pow(2,o-i)},_t.write=function(e,t,n,i,c,o){var a,u,h,l=o*8-c-1,m=(1<<l)-1,y=m>>1,B=c===23?Math.pow(2,-24)-Math.pow(2,-77):0,v=i?0:o-1,T=i?1:-1,N=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,a=m):(a=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-a))<1&&(a--,h*=2),a+y>=1?t+=B/h:t+=B*Math.pow(2,1-y),t*h>=2&&(a++,h/=2),a+y>=m?(u=0,a=m):a+y>=1?(u=(t*h-1)*Math.pow(2,c),a=a+y):(u=t*Math.pow(2,y-1)*Math.pow(2,c),a=0));c>=8;e[n+v]=u&255,v+=T,u/=256,c-=8);for(a=a<<c|u,l+=c;l>0;e[n+v]=a&255,v+=T,a/=256,l-=8);e[n+v-T]|=N*128}),_t}/*!
|
|
2
2
|
* The buffer module from node.js, for the browser.
|
|
3
3
|
*
|
|
4
4
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
5
|
* @license MIT
|
|
6
|
-
*/var fn;function Er(){return fn||(fn=1,(function(e){const t=yr(),n=br(),i=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=F,e.INSPECT_MAX_BYTES=50;const c=2147483647;e.kMaxLength=c,u.TYPED_ARRAY_SUPPORT=o(),!u.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 o(){try{const f=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(f,r),f.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function a(f){if(f>c)throw new RangeError('The value "'+f+'" is invalid for option "size"');const r=new Uint8Array(f);return Object.setPrototypeOf(r,u.prototype),r}function u(f,r,s){if(typeof f=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return y(f)}return h(f,r,s)}u.poolSize=8192;function h(f,r,s){if(typeof f=="string")return B(f,r);if(ArrayBuffer.isView(f))return T(f);if(f==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f);if(He(f,ArrayBuffer)||f&&He(f.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(He(f,SharedArrayBuffer)||f&&He(f.buffer,SharedArrayBuffer)))return N(f,r,s);if(typeof f=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const d=f.valueOf&&f.valueOf();if(d!=null&&d!==f)return u.from(d,r,s);const E=K(f);if(E)return E;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof f[Symbol.toPrimitive]=="function")return u.from(f[Symbol.toPrimitive]("string"),r,s);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f)}u.from=function(f,r,s){return h(f,r,s)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array);function l(f){if(typeof f!="number")throw new TypeError('"size" argument must be of type number');if(f<0)throw new RangeError('The value "'+f+'" is invalid for option "size"')}function m(f,r,s){return l(f),f<=0?a(f):r!==void 0?typeof s=="string"?a(f).fill(r,s):a(f).fill(r):a(f)}u.alloc=function(f,r,s){return m(f,r,s)};function y(f){return l(f),a(f<0?0:J(f)|0)}u.allocUnsafe=function(f){return y(f)},u.allocUnsafeSlow=function(f){return y(f)};function B(f,r){if((typeof r!="string"||r==="")&&(r="utf8"),!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r);const s=b(f,r)|0;let d=a(s);const E=d.write(f,r);return E!==s&&(d=d.slice(0,E)),d}function v(f){const r=f.length<0?0:J(f.length)|0,s=a(r);for(let d=0;d<r;d+=1)s[d]=f[d]&255;return s}function T(f){if(He(f,Uint8Array)){const r=new Uint8Array(f);return N(r.buffer,r.byteOffset,r.byteLength)}return v(f)}function N(f,r,s){if(r<0||f.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(f.byteLength<r+(s||0))throw new RangeError('"length" is outside of buffer bounds');let d;return r===void 0&&s===void 0?d=new Uint8Array(f):s===void 0?d=new Uint8Array(f,r):d=new Uint8Array(f,r,s),Object.setPrototypeOf(d,u.prototype),d}function K(f){if(u.isBuffer(f)){const r=J(f.length)|0,s=a(r);return s.length===0||f.copy(s,0,0,r),s}if(f.length!==void 0)return typeof f.length!="number"||Be(f.length)?a(0):v(f);if(f.type==="Buffer"&&Array.isArray(f.data))return v(f.data)}function J(f){if(f>=c)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+c.toString(16)+" bytes");return f|0}function F(f){return+f!=f&&(f=0),u.alloc(+f)}u.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==u.prototype},u.compare=function(r,s){if(He(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),He(s,Uint8Array)&&(s=u.from(s,s.offset,s.byteLength)),!u.isBuffer(r)||!u.isBuffer(s))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(r===s)return 0;let d=r.length,E=s.length;for(let A=0,M=Math.min(d,E);A<M;++A)if(r[A]!==s[A]){d=r[A],E=s[A];break}return d<E?-1:E<d?1:0},u.isEncoding=function(r){switch(String(r).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}},u.concat=function(r,s){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return u.alloc(0);let d;if(s===void 0)for(s=0,d=0;d<r.length;++d)s+=r[d].length;const E=u.allocUnsafe(s);let A=0;for(d=0;d<r.length;++d){let M=r[d];if(He(M,Uint8Array))A+M.length>E.length?(u.isBuffer(M)||(M=u.from(M)),M.copy(E,A)):Uint8Array.prototype.set.call(E,M,A);else if(u.isBuffer(M))M.copy(E,A);else throw new TypeError('"list" argument must be an Array of Buffers');A+=M.length}return E};function b(f,r){if(u.isBuffer(f))return f.length;if(ArrayBuffer.isView(f)||He(f,ArrayBuffer))return f.byteLength;if(typeof f!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof f);const s=f.length,d=arguments.length>2&&arguments[2]===!0;if(!d&&s===0)return 0;let E=!1;for(;;)switch(r){case"ascii":case"latin1":case"binary":return s;case"utf8":case"utf-8":return Oe(f).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s*2;case"hex":return s>>>1;case"base64":return Ee(f).length;default:if(E)return d?-1:Oe(f).length;r=(""+r).toLowerCase(),E=!0}}u.byteLength=b;function P(f,r,s){let d=!1;if((r===void 0||r<0)&&(r=0),r>this.length||((s===void 0||s>this.length)&&(s=this.length),s<=0)||(s>>>=0,r>>>=0,s<=r))return"";for(f||(f="utf8");;)switch(f){case"hex":return x(this,r,s);case"utf8":case"utf-8":return $(this,r,s);case"ascii":return _(this,r,s);case"latin1":case"binary":return p(this,r,s);case"base64":return V(this,r,s);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,r,s);default:if(d)throw new TypeError("Unknown encoding: "+f);f=(f+"").toLowerCase(),d=!0}}u.prototype._isBuffer=!0;function I(f,r,s){const d=f[r];f[r]=f[s],f[s]=d}u.prototype.swap16=function(){const r=this.length;if(r%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let s=0;s<r;s+=2)I(this,s,s+1);return this},u.prototype.swap32=function(){const r=this.length;if(r%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let s=0;s<r;s+=4)I(this,s,s+3),I(this,s+1,s+2);return this},u.prototype.swap64=function(){const r=this.length;if(r%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let s=0;s<r;s+=8)I(this,s,s+7),I(this,s+1,s+6),I(this,s+2,s+5),I(this,s+3,s+4);return this},u.prototype.toString=function(){const r=this.length;return r===0?"":arguments.length===0?$(this,0,r):P.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(r){if(!u.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:u.compare(this,r)===0},u.prototype.inspect=function(){let r="";const s=e.INSPECT_MAX_BYTES;return r=this.toString("hex",0,s).replace(/(.{2})/g,"$1 ").trim(),this.length>s&&(r+=" ... "),"<Buffer "+r+">"},i&&(u.prototype[i]=u.prototype.inspect),u.prototype.compare=function(r,s,d,E,A){if(He(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),!u.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(s===void 0&&(s=0),d===void 0&&(d=r?r.length:0),E===void 0&&(E=0),A===void 0&&(A=this.length),s<0||d>r.length||E<0||A>this.length)throw new RangeError("out of range index");if(E>=A&&s>=d)return 0;if(E>=A)return-1;if(s>=d)return 1;if(s>>>=0,d>>>=0,E>>>=0,A>>>=0,this===r)return 0;let M=A-E,ue=d-s;const de=Math.min(M,ue),ae=this.slice(E,A),ye=r.slice(s,d);for(let pe=0;pe<de;++pe)if(ae[pe]!==ye[pe]){M=ae[pe],ue=ye[pe];break}return M<ue?-1:ue<M?1:0};function O(f,r,s,d,E){if(f.length===0)return-1;if(typeof s=="string"?(d=s,s=0):s>2147483647?s=2147483647:s<-2147483648&&(s=-2147483648),s=+s,Be(s)&&(s=E?0:f.length-1),s<0&&(s=f.length+s),s>=f.length){if(E)return-1;s=f.length-1}else if(s<0)if(E)s=0;else return-1;if(typeof r=="string"&&(r=u.from(r,d)),u.isBuffer(r))return r.length===0?-1:U(f,r,s,d,E);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?E?Uint8Array.prototype.indexOf.call(f,r,s):Uint8Array.prototype.lastIndexOf.call(f,r,s):U(f,[r],s,d,E);throw new TypeError("val must be string, number or Buffer")}function U(f,r,s,d,E){let A=1,M=f.length,ue=r.length;if(d!==void 0&&(d=String(d).toLowerCase(),d==="ucs2"||d==="ucs-2"||d==="utf16le"||d==="utf-16le")){if(f.length<2||r.length<2)return-1;A=2,M/=2,ue/=2,s/=2}function de(ye,pe){return A===1?ye[pe]:ye.readUInt16BE(pe*A)}let ae;if(E){let ye=-1;for(ae=s;ae<M;ae++)if(de(f,ae)===de(r,ye===-1?0:ae-ye)){if(ye===-1&&(ye=ae),ae-ye+1===ue)return ye*A}else ye!==-1&&(ae-=ae-ye),ye=-1}else for(s+ue>M&&(s=M-ue),ae=s;ae>=0;ae--){let ye=!0;for(let pe=0;pe<ue;pe++)if(de(f,ae+pe)!==de(r,pe)){ye=!1;break}if(ye)return ae}return-1}u.prototype.includes=function(r,s,d){return this.indexOf(r,s,d)!==-1},u.prototype.indexOf=function(r,s,d){return O(this,r,s,d,!0)},u.prototype.lastIndexOf=function(r,s,d){return O(this,r,s,d,!1)};function Z(f,r,s,d){s=Number(s)||0;const E=f.length-s;d?(d=Number(d),d>E&&(d=E)):d=E;const A=r.length;d>A/2&&(d=A/2);let M;for(M=0;M<d;++M){const ue=parseInt(r.substr(M*2,2),16);if(Be(ue))return M;f[s+M]=ue}return M}function R(f,r,s,d){return Ke(Oe(r,f.length-s),f,s,d)}function C(f,r,s,d){return Ke(qe(r),f,s,d)}function j(f,r,s,d){return Ke(Ee(r),f,s,d)}function Q(f,r,s,d){return Ke(ke(r,f.length-s),f,s,d)}u.prototype.write=function(r,s,d,E){if(s===void 0)E="utf8",d=this.length,s=0;else if(d===void 0&&typeof s=="string")E=s,d=this.length,s=0;else if(isFinite(s))s=s>>>0,isFinite(d)?(d=d>>>0,E===void 0&&(E="utf8")):(E=d,d=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const A=this.length-s;if((d===void 0||d>A)&&(d=A),r.length>0&&(d<0||s<0)||s>this.length)throw new RangeError("Attempt to write outside buffer bounds");E||(E="utf8");let M=!1;for(;;)switch(E){case"hex":return Z(this,r,s,d);case"utf8":case"utf-8":return R(this,r,s,d);case"ascii":case"latin1":case"binary":return C(this,r,s,d);case"base64":return j(this,r,s,d);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Q(this,r,s,d);default:if(M)throw new TypeError("Unknown encoding: "+E);E=(""+E).toLowerCase(),M=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function V(f,r,s){return r===0&&s===f.length?t.fromByteArray(f):t.fromByteArray(f.slice(r,s))}function $(f,r,s){s=Math.min(f.length,s);const d=[];let E=r;for(;E<s;){const A=f[E];let M=null,ue=A>239?4:A>223?3:A>191?2:1;if(E+ue<=s){let de,ae,ye,pe;switch(ue){case 1:A<128&&(M=A);break;case 2:de=f[E+1],(de&192)===128&&(pe=(A&31)<<6|de&63,pe>127&&(M=pe));break;case 3:de=f[E+1],ae=f[E+2],(de&192)===128&&(ae&192)===128&&(pe=(A&15)<<12|(de&63)<<6|ae&63,pe>2047&&(pe<55296||pe>57343)&&(M=pe));break;case 4:de=f[E+1],ae=f[E+2],ye=f[E+3],(de&192)===128&&(ae&192)===128&&(ye&192)===128&&(pe=(A&15)<<18|(de&63)<<12|(ae&63)<<6|ye&63,pe>65535&&pe<1114112&&(M=pe))}}M===null?(M=65533,ue=1):M>65535&&(M-=65536,d.push(M>>>10&1023|55296),M=56320|M&1023),d.push(M),E+=ue}return H(d)}const w=4096;function H(f){const r=f.length;if(r<=w)return String.fromCharCode.apply(String,f);let s="",d=0;for(;d<r;)s+=String.fromCharCode.apply(String,f.slice(d,d+=w));return s}function _(f,r,s){let d="";s=Math.min(f.length,s);for(let E=r;E<s;++E)d+=String.fromCharCode(f[E]&127);return d}function p(f,r,s){let d="";s=Math.min(f.length,s);for(let E=r;E<s;++E)d+=String.fromCharCode(f[E]);return d}function x(f,r,s){const d=f.length;(!r||r<0)&&(r=0),(!s||s<0||s>d)&&(s=d);let E="";for(let A=r;A<s;++A)E+=te[f[A]];return E}function k(f,r,s){const d=f.slice(r,s);let E="";for(let A=0;A<d.length-1;A+=2)E+=String.fromCharCode(d[A]+d[A+1]*256);return E}u.prototype.slice=function(r,s){const d=this.length;r=~~r,s=s===void 0?d:~~s,r<0?(r+=d,r<0&&(r=0)):r>d&&(r=d),s<0?(s+=d,s<0&&(s=0)):s>d&&(s=d),s<r&&(s=r);const E=this.subarray(r,s);return Object.setPrototypeOf(E,u.prototype),E};function g(f,r,s){if(f%1!==0||f<0)throw new RangeError("offset is not uint");if(f+r>s)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=this[r],A=1,M=0;for(;++M<s&&(A*=256);)E+=this[r+M]*A;return E},u.prototype.readUintBE=u.prototype.readUIntBE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=this[r+--s],A=1;for(;s>0&&(A*=256);)E+=this[r+--s]*A;return E},u.prototype.readUint8=u.prototype.readUInt8=function(r,s){return r=r>>>0,s||g(r,1,this.length),this[r]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(r,s){return r=r>>>0,s||g(r,2,this.length),this[r]|this[r+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(r,s){return r=r>>>0,s||g(r,2,this.length),this[r]<<8|this[r+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(r,s){return r=r>>>0,s||g(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(r,s){return r=r>>>0,s||g(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])},u.prototype.readBigUInt64LE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=s+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24,A=this[++r]+this[++r]*2**8+this[++r]*2**16+d*2**24;return BigInt(E)+(BigInt(A)<<BigInt(32))}),u.prototype.readBigUInt64BE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=s*2**24+this[++r]*2**16+this[++r]*2**8+this[++r],A=this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+d;return(BigInt(E)<<BigInt(32))+BigInt(A)}),u.prototype.readIntLE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=this[r],A=1,M=0;for(;++M<s&&(A*=256);)E+=this[r+M]*A;return A*=128,E>=A&&(E-=Math.pow(2,8*s)),E},u.prototype.readIntBE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=s,A=1,M=this[r+--E];for(;E>0&&(A*=256);)M+=this[r+--E]*A;return A*=128,M>=A&&(M-=Math.pow(2,8*s)),M},u.prototype.readInt8=function(r,s){return r=r>>>0,s||g(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]},u.prototype.readInt16LE=function(r,s){r=r>>>0,s||g(r,2,this.length);const d=this[r]|this[r+1]<<8;return d&32768?d|4294901760:d},u.prototype.readInt16BE=function(r,s){r=r>>>0,s||g(r,2,this.length);const d=this[r+1]|this[r]<<8;return d&32768?d|4294901760:d},u.prototype.readInt32LE=function(r,s){return r=r>>>0,s||g(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24},u.prototype.readInt32BE=function(r,s){return r=r>>>0,s||g(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]},u.prototype.readBigInt64LE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=this[r+4]+this[r+5]*2**8+this[r+6]*2**16+(d<<24);return(BigInt(E)<<BigInt(32))+BigInt(s+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24)}),u.prototype.readBigInt64BE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=(s<<24)+this[++r]*2**16+this[++r]*2**8+this[++r];return(BigInt(E)<<BigInt(32))+BigInt(this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+d)}),u.prototype.readFloatLE=function(r,s){return r=r>>>0,s||g(r,4,this.length),n.read(this,r,!0,23,4)},u.prototype.readFloatBE=function(r,s){return r=r>>>0,s||g(r,4,this.length),n.read(this,r,!1,23,4)},u.prototype.readDoubleLE=function(r,s){return r=r>>>0,s||g(r,8,this.length),n.read(this,r,!0,52,8)},u.prototype.readDoubleBE=function(r,s){return r=r>>>0,s||g(r,8,this.length),n.read(this,r,!1,52,8)};function S(f,r,s,d,E,A){if(!u.isBuffer(f))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>E||r<A)throw new RangeError('"value" argument is out of bounds');if(s+d>f.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(r,s,d,E){if(r=+r,s=s>>>0,d=d>>>0,!E){const ue=Math.pow(2,8*d)-1;S(this,r,s,d,ue,0)}let A=1,M=0;for(this[s]=r&255;++M<d&&(A*=256);)this[s+M]=r/A&255;return s+d},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(r,s,d,E){if(r=+r,s=s>>>0,d=d>>>0,!E){const ue=Math.pow(2,8*d)-1;S(this,r,s,d,ue,0)}let A=d-1,M=1;for(this[s+A]=r&255;--A>=0&&(M*=256);)this[s+A]=r/M&255;return s+d},u.prototype.writeUint8=u.prototype.writeUInt8=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,1,255,0),this[s]=r&255,s+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,65535,0),this[s]=r&255,this[s+1]=r>>>8,s+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,65535,0),this[s]=r>>>8,this[s+1]=r&255,s+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,4294967295,0),this[s+3]=r>>>24,this[s+2]=r>>>16,this[s+1]=r>>>8,this[s]=r&255,s+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,4294967295,0),this[s]=r>>>24,this[s+1]=r>>>16,this[s+2]=r>>>8,this[s+3]=r&255,s+4};function q(f,r,s,d,E){ce(r,d,E,f,s,7);let A=Number(r&BigInt(4294967295));f[s++]=A,A=A>>8,f[s++]=A,A=A>>8,f[s++]=A,A=A>>8,f[s++]=A;let M=Number(r>>BigInt(32)&BigInt(4294967295));return f[s++]=M,M=M>>8,f[s++]=M,M=M>>8,f[s++]=M,M=M>>8,f[s++]=M,s}function G(f,r,s,d,E){ce(r,d,E,f,s,7);let A=Number(r&BigInt(4294967295));f[s+7]=A,A=A>>8,f[s+6]=A,A=A>>8,f[s+5]=A,A=A>>8,f[s+4]=A;let M=Number(r>>BigInt(32)&BigInt(4294967295));return f[s+3]=M,M=M>>8,f[s+2]=M,M=M>>8,f[s+1]=M,M=M>>8,f[s]=M,s+8}u.prototype.writeBigUInt64LE=Y(function(r,s=0){return q(this,r,s,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeBigUInt64BE=Y(function(r,s=0){return G(this,r,s,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeIntLE=function(r,s,d,E){if(r=+r,s=s>>>0,!E){const de=Math.pow(2,8*d-1);S(this,r,s,d,de-1,-de)}let A=0,M=1,ue=0;for(this[s]=r&255;++A<d&&(M*=256);)r<0&&ue===0&&this[s+A-1]!==0&&(ue=1),this[s+A]=(r/M>>0)-ue&255;return s+d},u.prototype.writeIntBE=function(r,s,d,E){if(r=+r,s=s>>>0,!E){const de=Math.pow(2,8*d-1);S(this,r,s,d,de-1,-de)}let A=d-1,M=1,ue=0;for(this[s+A]=r&255;--A>=0&&(M*=256);)r<0&&ue===0&&this[s+A+1]!==0&&(ue=1),this[s+A]=(r/M>>0)-ue&255;return s+d},u.prototype.writeInt8=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,1,127,-128),r<0&&(r=255+r+1),this[s]=r&255,s+1},u.prototype.writeInt16LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,32767,-32768),this[s]=r&255,this[s+1]=r>>>8,s+2},u.prototype.writeInt16BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,32767,-32768),this[s]=r>>>8,this[s+1]=r&255,s+2},u.prototype.writeInt32LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,2147483647,-2147483648),this[s]=r&255,this[s+1]=r>>>8,this[s+2]=r>>>16,this[s+3]=r>>>24,s+4},u.prototype.writeInt32BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,2147483647,-2147483648),r<0&&(r=4294967295+r+1),this[s]=r>>>24,this[s+1]=r>>>16,this[s+2]=r>>>8,this[s+3]=r&255,s+4},u.prototype.writeBigInt64LE=Y(function(r,s=0){return q(this,r,s,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeBigInt64BE=Y(function(r,s=0){return G(this,r,s,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ee(f,r,s,d,E,A){if(s+d>f.length)throw new RangeError("Index out of range");if(s<0)throw new RangeError("Index out of range")}function ne(f,r,s,d,E){return r=+r,s=s>>>0,E||ee(f,r,s,4),n.write(f,r,s,d,23,4),s+4}u.prototype.writeFloatLE=function(r,s,d){return ne(this,r,s,!0,d)},u.prototype.writeFloatBE=function(r,s,d){return ne(this,r,s,!1,d)};function ie(f,r,s,d,E){return r=+r,s=s>>>0,E||ee(f,r,s,8),n.write(f,r,s,d,52,8),s+8}u.prototype.writeDoubleLE=function(r,s,d){return ie(this,r,s,!0,d)},u.prototype.writeDoubleBE=function(r,s,d){return ie(this,r,s,!1,d)},u.prototype.copy=function(r,s,d,E){if(!u.isBuffer(r))throw new TypeError("argument should be a Buffer");if(d||(d=0),!E&&E!==0&&(E=this.length),s>=r.length&&(s=r.length),s||(s=0),E>0&&E<d&&(E=d),E===d||r.length===0||this.length===0)return 0;if(s<0)throw new RangeError("targetStart out of bounds");if(d<0||d>=this.length)throw new RangeError("Index out of range");if(E<0)throw new RangeError("sourceEnd out of bounds");E>this.length&&(E=this.length),r.length-s<E-d&&(E=r.length-s+d);const A=E-d;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(s,d,E):Uint8Array.prototype.set.call(r,this.subarray(d,E),s),A},u.prototype.fill=function(r,s,d,E){if(typeof r=="string"){if(typeof s=="string"?(E=s,s=0,d=this.length):typeof d=="string"&&(E=d,d=this.length),E!==void 0&&typeof E!="string")throw new TypeError("encoding must be a string");if(typeof E=="string"&&!u.isEncoding(E))throw new TypeError("Unknown encoding: "+E);if(r.length===1){const M=r.charCodeAt(0);(E==="utf8"&&M<128||E==="latin1")&&(r=M)}}else typeof r=="number"?r=r&255:typeof r=="boolean"&&(r=Number(r));if(s<0||this.length<s||this.length<d)throw new RangeError("Out of range index");if(d<=s)return this;s=s>>>0,d=d===void 0?this.length:d>>>0,r||(r=0);let A;if(typeof r=="number")for(A=s;A<d;++A)this[A]=r;else{const M=u.isBuffer(r)?r:u.from(r,E),ue=M.length;if(ue===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(A=0;A<d-s;++A)this[A+s]=M[A%ue]}return this};const L={};function D(f,r,s){L[f]=class extends s{constructor(){super(),Object.defineProperty(this,"message",{value:r.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${f}]`,this.stack,delete this.name}get code(){return f}set code(E){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:E,writable:!0})}toString(){return`${this.name} [${f}]: ${this.message}`}}}D("ERR_BUFFER_OUT_OF_BOUNDS",function(f){return f?`${f} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(f,r){return`The "${f}" argument must be of type number. Received type ${typeof r}`},TypeError),D("ERR_OUT_OF_RANGE",function(f,r,s){let d=`The value of "${f}" is out of range.`,E=s;return Number.isInteger(s)&&Math.abs(s)>2**32?E=re(String(s)):typeof s=="bigint"&&(E=String(s),(s>BigInt(2)**BigInt(32)||s<-(BigInt(2)**BigInt(32)))&&(E=re(E)),E+="n"),d+=` It must be ${r}. Received ${E}`,d},RangeError);function re(f){let r="",s=f.length;const d=f[0]==="-"?1:0;for(;s>=d+4;s-=3)r=`_${f.slice(s-3,s)}${r}`;return`${f.slice(0,s)}${r}`}function le(f,r,s){W(r,"offset"),(f[r]===void 0||f[r+s]===void 0)&&oe(r,f.length-(s+1))}function ce(f,r,s,d,E,A){if(f>s||f<r){const M=typeof r=="bigint"?"n":"";let ue;throw r===0||r===BigInt(0)?ue=`>= 0${M} and < 2${M} ** ${(A+1)*8}${M}`:ue=`>= -(2${M} ** ${(A+1)*8-1}${M}) and < 2 ** ${(A+1)*8-1}${M}`,new L.ERR_OUT_OF_RANGE("value",ue,f)}le(d,E,A)}function W(f,r){if(typeof f!="number")throw new L.ERR_INVALID_ARG_TYPE(r,"number",f)}function oe(f,r,s){throw Math.floor(f)!==f?(W(f,s),new L.ERR_OUT_OF_RANGE("offset","an integer",f)):r<0?new L.ERR_BUFFER_OUT_OF_BOUNDS:new L.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${r}`,f)}const be=/[^+/0-9A-Za-z-_]/g;function Se(f){if(f=f.split("=")[0],f=f.trim().replace(be,""),f.length<2)return"";for(;f.length%4!==0;)f=f+"=";return f}function Oe(f,r){r=r||1/0;let s;const d=f.length;let E=null;const A=[];for(let M=0;M<d;++M){if(s=f.charCodeAt(M),s>55295&&s<57344){if(!E){if(s>56319){(r-=3)>-1&&A.push(239,191,189);continue}else if(M+1===d){(r-=3)>-1&&A.push(239,191,189);continue}E=s;continue}if(s<56320){(r-=3)>-1&&A.push(239,191,189),E=s;continue}s=(E-55296<<10|s-56320)+65536}else E&&(r-=3)>-1&&A.push(239,191,189);if(E=null,s<128){if((r-=1)<0)break;A.push(s)}else if(s<2048){if((r-=2)<0)break;A.push(s>>6|192,s&63|128)}else if(s<65536){if((r-=3)<0)break;A.push(s>>12|224,s>>6&63|128,s&63|128)}else if(s<1114112){if((r-=4)<0)break;A.push(s>>18|240,s>>12&63|128,s>>6&63|128,s&63|128)}else throw new Error("Invalid code point")}return A}function qe(f){const r=[];for(let s=0;s<f.length;++s)r.push(f.charCodeAt(s)&255);return r}function ke(f,r){let s,d,E;const A=[];for(let M=0;M<f.length&&!((r-=2)<0);++M)s=f.charCodeAt(M),d=s>>8,E=s%256,A.push(E),A.push(d);return A}function Ee(f){return t.toByteArray(Se(f))}function Ke(f,r,s,d){let E;for(E=0;E<d&&!(E+s>=r.length||E>=f.length);++E)r[E+s]=f[E];return E}function He(f,r){return f instanceof r||f!=null&&f.constructor!=null&&f.constructor.name!=null&&f.constructor.name===r.name}function Be(f){return f!==f}const te=(function(){const f="0123456789abcdef",r=new Array(256);for(let s=0;s<16;++s){const d=s*16;for(let E=0;E<16;++E)r[d+E]=f[s]+f[E]}return r})();function Y(f){return typeof BigInt>"u"?z:f}function z(){throw new Error("BigInt not supported")}})(It)),It}var Br=Er(),kt={exports:{}},ln;function xr(){if(ln)return kt.exports;ln=1;var e=kt.exports={},t,n;function i(){throw new Error("setTimeout has not been defined")}function c(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?t=setTimeout:t=i}catch{t=i}try{typeof clearTimeout=="function"?n=clearTimeout:n=c}catch{n=c}})();function o(N){if(t===setTimeout)return setTimeout(N,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(N,0);try{return t(N,0)}catch{try{return t.call(null,N,0)}catch{return t.call(this,N,0)}}}function a(N){if(n===clearTimeout)return clearTimeout(N);if((n===c||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(N);try{return n(N)}catch{try{return n.call(null,N)}catch{return n.call(this,N)}}}var u=[],h=!1,l,m=-1;function y(){!h||!l||(h=!1,l.length?u=l.concat(u):m=-1,u.length&&B())}function B(){if(!h){var N=o(y);h=!0;for(var K=u.length;K;){for(l=u,u=[];++m<K;)l&&l[m].run();m=-1,K=u.length}l=null,h=!1,a(N)}}e.nextTick=function(N){var K=new Array(arguments.length-1);if(arguments.length>1)for(var J=1;J<arguments.length;J++)K[J-1]=arguments[J];u.push(new v(N,K)),u.length===1&&!h&&o(B)};function v(N,K){this.fun=N,this.array=K}v.prototype.run=function(){this.fun.apply(null,this.array)},e.title="browser",e.browser=!0,e.env={},e.argv=[],e.version="",e.versions={};function T(){}return e.on=T,e.addListener=T,e.once=T,e.off=T,e.removeListener=T,e.removeAllListeners=T,e.emit=T,e.prependListener=T,e.prependOnceListener=T,e.listeners=function(N){return[]},e.binding=function(N){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(N){throw new Error("process.chdir is not supported")},e.umask=function(){return 0},kt.exports}var _r=xr();const vr=cn(_r);typeof globalThis>"u"&&(globalThis.global=globalThis),typeof globalThis.Buffer>"u"&&(globalThis.Buffer=Br.Buffer),typeof globalThis.process>"u"&&(globalThis.process=vr);var Ne={},Mt={},xe={},Ce={},Ft={},gt={},hn;function Sr(){return hn||(hn=1,Object.defineProperty(gt,"__esModule",{value:!0}),gt.crypto=void 0,gt.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),gt}var dn;function nt(){return dn||(dn=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=i,e.abytes=c,e.ahash=o,e.aexists=a,e.aoutput=u,e.u8=h,e.u32=l,e.clean=m,e.createView=y,e.rotr=B,e.rotl=v,e.byteSwap=T,e.byteSwap32=N,e.bytesToHex=F,e.hexToBytes=I,e.asyncLoop=U,e.utf8ToBytes=Z,e.bytesToUtf8=R,e.toBytes=C,e.kdfInputToBytes=j,e.concatBytes=Q,e.checkOpts=V,e.createHasher=w,e.createOptHasher=H,e.createXOFer=_,e.randomBytes=p;const t=Sr();function n(x){return x instanceof Uint8Array||ArrayBuffer.isView(x)&&x.constructor.name==="Uint8Array"}function i(x){if(!Number.isSafeInteger(x)||x<0)throw new Error("positive integer expected, got "+x)}function c(x,...k){if(!n(x))throw new Error("Uint8Array expected");if(k.length>0&&!k.includes(x.length))throw new Error("Uint8Array expected of length "+k+", got length="+x.length)}function o(x){if(typeof x!="function"||typeof x.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");i(x.outputLen),i(x.blockLen)}function a(x,k=!0){if(x.destroyed)throw new Error("Hash instance has been destroyed");if(k&&x.finished)throw new Error("Hash#digest() has already been called")}function u(x,k){c(x);const g=k.outputLen;if(x.length<g)throw new Error("digestInto() expects output buffer of length at least "+g)}function h(x){return new Uint8Array(x.buffer,x.byteOffset,x.byteLength)}function l(x){return new Uint32Array(x.buffer,x.byteOffset,Math.floor(x.byteLength/4))}function m(...x){for(let k=0;k<x.length;k++)x[k].fill(0)}function y(x){return new DataView(x.buffer,x.byteOffset,x.byteLength)}function B(x,k){return x<<32-k|x>>>k}function v(x,k){return x<<k|x>>>32-k>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function T(x){return x<<24&4278190080|x<<8&16711680|x>>>8&65280|x>>>24&255}e.swap8IfBE=e.isLE?x=>x:x=>T(x),e.byteSwapIfBE=e.swap8IfBE;function N(x){for(let k=0;k<x.length;k++)x[k]=T(x[k]);return x}e.swap32IfBE=e.isLE?x=>x:N;const K=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",J=Array.from({length:256},(x,k)=>k.toString(16).padStart(2,"0"));function F(x){if(c(x),K)return x.toHex();let k="";for(let g=0;g<x.length;g++)k+=J[x[g]];return k}const b={_0:48,_9:57,A:65,F:70,a:97,f:102};function P(x){if(x>=b._0&&x<=b._9)return x-b._0;if(x>=b.A&&x<=b.F)return x-(b.A-10);if(x>=b.a&&x<=b.f)return x-(b.a-10)}function I(x){if(typeof x!="string")throw new Error("hex string expected, got "+typeof x);if(K)return Uint8Array.fromHex(x);const k=x.length,g=k/2;if(k%2)throw new Error("hex string expected, got unpadded hex of length "+k);const S=new Uint8Array(g);for(let q=0,G=0;q<g;q++,G+=2){const ee=P(x.charCodeAt(G)),ne=P(x.charCodeAt(G+1));if(ee===void 0||ne===void 0){const ie=x[G]+x[G+1];throw new Error('hex string expected, got non-hex character "'+ie+'" at index '+G)}S[q]=ee*16+ne}return S}const O=async()=>{};e.nextTick=O;async function U(x,k,g){let S=Date.now();for(let q=0;q<x;q++){g(q);const G=Date.now()-S;G>=0&&G<k||(await(0,e.nextTick)(),S+=G)}}function Z(x){if(typeof x!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(x))}function R(x){return new TextDecoder().decode(x)}function C(x){return typeof x=="string"&&(x=Z(x)),c(x),x}function j(x){return typeof x=="string"&&(x=Z(x)),c(x),x}function Q(...x){let k=0;for(let S=0;S<x.length;S++){const q=x[S];c(q),k+=q.length}const g=new Uint8Array(k);for(let S=0,q=0;S<x.length;S++){const G=x[S];g.set(G,q),q+=G.length}return g}function V(x,k){if(k!==void 0&&{}.toString.call(k)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(x,k)}class ${}e.Hash=$;function w(x){const k=S=>x().update(C(S)).digest(),g=x();return k.outputLen=g.outputLen,k.blockLen=g.blockLen,k.create=()=>x(),k}function H(x){const k=(S,q)=>x(q).update(C(S)).digest(),g=x({});return k.outputLen=g.outputLen,k.blockLen=g.blockLen,k.create=S=>x(S),k}function _(x){const k=(S,q)=>x(q).update(C(S)).digest(),g=x({});return k.outputLen=g.outputLen,k.blockLen=g.blockLen,k.create=S=>x(S),k}e.wrapConstructor=w,e.wrapConstructorWithOpts=H,e.wrapXOFConstructorWithOpts=_;function p(x=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(x));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(x));throw new Error("crypto.getRandomValues must be defined")}})(Ft)),Ft}var pn;function Ar(){if(pn)return Ce;pn=1,Object.defineProperty(Ce,"__esModule",{value:!0}),Ce.SHA512_IV=Ce.SHA384_IV=Ce.SHA224_IV=Ce.SHA256_IV=Ce.HashMD=void 0,Ce.setBigUint64=t,Ce.Chi=n,Ce.Maj=i;const e=nt();function t(o,a,u,h){if(typeof o.setBigUint64=="function")return o.setBigUint64(a,u,h);const l=BigInt(32),m=BigInt(4294967295),y=Number(u>>l&m),B=Number(u&m),v=h?4:0,T=h?0:4;o.setUint32(a+v,y,h),o.setUint32(a+T,B,h)}function n(o,a,u){return o&a^~o&u}function i(o,a,u){return o&a^o&u^a&u}class c extends e.Hash{constructor(a,u,h,l){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=a,this.outputLen=u,this.padOffset=h,this.isLE=l,this.buffer=new Uint8Array(a),this.view=(0,e.createView)(this.buffer)}update(a){(0,e.aexists)(this),a=(0,e.toBytes)(a),(0,e.abytes)(a);const{view:u,buffer:h,blockLen:l}=this,m=a.length;for(let y=0;y<m;){const B=Math.min(l-this.pos,m-y);if(B===l){const v=(0,e.createView)(a);for(;l<=m-y;y+=l)this.process(v,y);continue}h.set(a.subarray(y,y+B),this.pos),this.pos+=B,y+=B,this.pos===l&&(this.process(u,0),this.pos=0)}return this.length+=a.length,this.roundClean(),this}digestInto(a){(0,e.aexists)(this),(0,e.aoutput)(a,this),this.finished=!0;const{buffer:u,view:h,blockLen:l,isLE:m}=this;let{pos:y}=this;u[y++]=128,(0,e.clean)(this.buffer.subarray(y)),this.padOffset>l-y&&(this.process(h,0),y=0);for(let K=y;K<l;K++)u[K]=0;t(h,l-8,BigInt(this.length*8),m),this.process(h,0);const B=(0,e.createView)(a),v=this.outputLen;if(v%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const T=v/4,N=this.get();if(T>N.length)throw new Error("_sha2: outputLen bigger than state");for(let K=0;K<T;K++)B.setUint32(4*K,N[K],m)}digest(){const{buffer:a,outputLen:u}=this;this.digestInto(a);const h=a.slice(0,u);return this.destroy(),h}_cloneInto(a){a||(a=new this.constructor),a.set(...this.get());const{blockLen:u,buffer:h,length:l,finished:m,destroyed:y,pos:B}=this;return a.destroyed=y,a.finished=m,a.length=l,a.pos=B,l%u&&a.buffer.set(h),a}clone(){return this._cloneInto()}}return Ce.HashMD=c,Ce.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ce.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Ce.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Ce.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Ce}var we={},gn;function Tr(){if(gn)return we;gn=1,Object.defineProperty(we,"__esModule",{value:!0}),we.toBig=we.shrSL=we.shrSH=we.rotrSL=we.rotrSH=we.rotrBL=we.rotrBH=we.rotr32L=we.rotr32H=we.rotlSL=we.rotlSH=we.rotlBL=we.rotlBH=we.add5L=we.add5H=we.add4L=we.add4H=we.add3L=we.add3H=void 0,we.add=J,we.fromBig=n,we.split=i;const e=BigInt(2**32-1),t=BigInt(32);function n(R,C=!1){return C?{h:Number(R&e),l:Number(R>>t&e)}:{h:Number(R>>t&e)|0,l:Number(R&e)|0}}function i(R,C=!1){const j=R.length;let Q=new Uint32Array(j),V=new Uint32Array(j);for(let $=0;$<j;$++){const{h:w,l:H}=n(R[$],C);[Q[$],V[$]]=[w,H]}return[Q,V]}const c=(R,C)=>BigInt(R>>>0)<<t|BigInt(C>>>0);we.toBig=c;const o=(R,C,j)=>R>>>j;we.shrSH=o;const a=(R,C,j)=>R<<32-j|C>>>j;we.shrSL=a;const u=(R,C,j)=>R>>>j|C<<32-j;we.rotrSH=u;const h=(R,C,j)=>R<<32-j|C>>>j;we.rotrSL=h;const l=(R,C,j)=>R<<64-j|C>>>j-32;we.rotrBH=l;const m=(R,C,j)=>R>>>j-32|C<<64-j;we.rotrBL=m;const y=(R,C)=>C;we.rotr32H=y;const B=(R,C)=>R;we.rotr32L=B;const v=(R,C,j)=>R<<j|C>>>32-j;we.rotlSH=v;const T=(R,C,j)=>C<<j|R>>>32-j;we.rotlSL=T;const N=(R,C,j)=>C<<j-32|R>>>64-j;we.rotlBH=N;const K=(R,C,j)=>R<<j-32|C>>>64-j;we.rotlBL=K;function J(R,C,j,Q){const V=(C>>>0)+(Q>>>0);return{h:R+j+(V/2**32|0)|0,l:V|0}}const F=(R,C,j)=>(R>>>0)+(C>>>0)+(j>>>0);we.add3L=F;const b=(R,C,j,Q)=>C+j+Q+(R/2**32|0)|0;we.add3H=b;const P=(R,C,j,Q)=>(R>>>0)+(C>>>0)+(j>>>0)+(Q>>>0);we.add4L=P;const I=(R,C,j,Q,V)=>C+j+Q+V+(R/2**32|0)|0;we.add4H=I;const O=(R,C,j,Q,V)=>(R>>>0)+(C>>>0)+(j>>>0)+(Q>>>0)+(V>>>0);we.add5L=O;const U=(R,C,j,Q,V,$)=>C+j+Q+V+$+(R/2**32|0)|0;we.add5H=U;const Z={fromBig:n,split:i,toBig:c,shrSH:o,shrSL:a,rotrSH:u,rotrSL:h,rotrBH:l,rotrBL:m,rotr32H:y,rotr32L:B,rotlSH:v,rotlSL:T,rotlBH:N,rotlBL:K,add:J,add3L:F,add3H:b,add4L:P,add4H:I,add5H:U,add5L:O};return we.default=Z,we}var mn;function Nr(){if(mn)return xe;mn=1,Object.defineProperty(xe,"__esModule",{value:!0}),xe.sha512_224=xe.sha512_256=xe.sha384=xe.sha512=xe.sha224=xe.sha256=xe.SHA512_256=xe.SHA512_224=xe.SHA384=xe.SHA512=xe.SHA224=xe.SHA256=void 0;const e=Ar(),t=Tr(),n=nt(),i=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]),c=new Uint32Array(64);class o extends e.HashMD{constructor(b=32){super(64,b,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:b,B:P,C:I,D:O,E:U,F:Z,G:R,H:C}=this;return[b,P,I,O,U,Z,R,C]}set(b,P,I,O,U,Z,R,C){this.A=b|0,this.B=P|0,this.C=I|0,this.D=O|0,this.E=U|0,this.F=Z|0,this.G=R|0,this.H=C|0}process(b,P){for(let V=0;V<16;V++,P+=4)c[V]=b.getUint32(P,!1);for(let V=16;V<64;V++){const $=c[V-15],w=c[V-2],H=(0,n.rotr)($,7)^(0,n.rotr)($,18)^$>>>3,_=(0,n.rotr)(w,17)^(0,n.rotr)(w,19)^w>>>10;c[V]=_+c[V-7]+H+c[V-16]|0}let{A:I,B:O,C:U,D:Z,E:R,F:C,G:j,H:Q}=this;for(let V=0;V<64;V++){const $=(0,n.rotr)(R,6)^(0,n.rotr)(R,11)^(0,n.rotr)(R,25),w=Q+$+(0,e.Chi)(R,C,j)+i[V]+c[V]|0,_=((0,n.rotr)(I,2)^(0,n.rotr)(I,13)^(0,n.rotr)(I,22))+(0,e.Maj)(I,O,U)|0;Q=j,j=C,C=R,R=Z+w|0,Z=U,U=O,O=I,I=w+_|0}I=I+this.A|0,O=O+this.B|0,U=U+this.C|0,Z=Z+this.D|0,R=R+this.E|0,C=C+this.F|0,j=j+this.G|0,Q=Q+this.H|0,this.set(I,O,U,Z,R,C,j,Q)}roundClean(){(0,n.clean)(c)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}xe.SHA256=o;class a extends o{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}}xe.SHA224=a;const u=t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(F=>BigInt(F))),h=u[0],l=u[1],m=new Uint32Array(80),y=new Uint32Array(80);class B extends e.HashMD{constructor(b=64){super(128,b,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:b,Al:P,Bh:I,Bl:O,Ch:U,Cl:Z,Dh:R,Dl:C,Eh:j,El:Q,Fh:V,Fl:$,Gh:w,Gl:H,Hh:_,Hl:p}=this;return[b,P,I,O,U,Z,R,C,j,Q,V,$,w,H,_,p]}set(b,P,I,O,U,Z,R,C,j,Q,V,$,w,H,_,p){this.Ah=b|0,this.Al=P|0,this.Bh=I|0,this.Bl=O|0,this.Ch=U|0,this.Cl=Z|0,this.Dh=R|0,this.Dl=C|0,this.Eh=j|0,this.El=Q|0,this.Fh=V|0,this.Fl=$|0,this.Gh=w|0,this.Gl=H|0,this.Hh=_|0,this.Hl=p|0}process(b,P){for(let g=0;g<16;g++,P+=4)m[g]=b.getUint32(P),y[g]=b.getUint32(P+=4);for(let g=16;g<80;g++){const S=m[g-15]|0,q=y[g-15]|0,G=t.rotrSH(S,q,1)^t.rotrSH(S,q,8)^t.shrSH(S,q,7),ee=t.rotrSL(S,q,1)^t.rotrSL(S,q,8)^t.shrSL(S,q,7),ne=m[g-2]|0,ie=y[g-2]|0,L=t.rotrSH(ne,ie,19)^t.rotrBH(ne,ie,61)^t.shrSH(ne,ie,6),D=t.rotrSL(ne,ie,19)^t.rotrBL(ne,ie,61)^t.shrSL(ne,ie,6),re=t.add4L(ee,D,y[g-7],y[g-16]),le=t.add4H(re,G,L,m[g-7],m[g-16]);m[g]=le|0,y[g]=re|0}let{Ah:I,Al:O,Bh:U,Bl:Z,Ch:R,Cl:C,Dh:j,Dl:Q,Eh:V,El:$,Fh:w,Fl:H,Gh:_,Gl:p,Hh:x,Hl:k}=this;for(let g=0;g<80;g++){const S=t.rotrSH(V,$,14)^t.rotrSH(V,$,18)^t.rotrBH(V,$,41),q=t.rotrSL(V,$,14)^t.rotrSL(V,$,18)^t.rotrBL(V,$,41),G=V&w^~V&_,ee=$&H^~$&p,ne=t.add5L(k,q,ee,l[g],y[g]),ie=t.add5H(ne,x,S,G,h[g],m[g]),L=ne|0,D=t.rotrSH(I,O,28)^t.rotrBH(I,O,34)^t.rotrBH(I,O,39),re=t.rotrSL(I,O,28)^t.rotrBL(I,O,34)^t.rotrBL(I,O,39),le=I&U^I&R^U&R,ce=O&Z^O&C^Z&C;x=_|0,k=p|0,_=w|0,p=H|0,w=V|0,H=$|0,{h:V,l:$}=t.add(j|0,Q|0,ie|0,L|0),j=R|0,Q=C|0,R=U|0,C=Z|0,U=I|0,Z=O|0;const W=t.add3L(L,re,ce);I=t.add3H(W,ie,D,le),O=W|0}({h:I,l:O}=t.add(this.Ah|0,this.Al|0,I|0,O|0)),{h:U,l:Z}=t.add(this.Bh|0,this.Bl|0,U|0,Z|0),{h:R,l:C}=t.add(this.Ch|0,this.Cl|0,R|0,C|0),{h:j,l:Q}=t.add(this.Dh|0,this.Dl|0,j|0,Q|0),{h:V,l:$}=t.add(this.Eh|0,this.El|0,V|0,$|0),{h:w,l:H}=t.add(this.Fh|0,this.Fl|0,w|0,H|0),{h:_,l:p}=t.add(this.Gh|0,this.Gl|0,_|0,p|0),{h:x,l:k}=t.add(this.Hh|0,this.Hl|0,x|0,k|0),this.set(I,O,U,Z,R,C,j,Q,V,$,w,H,_,p,x,k)}roundClean(){(0,n.clean)(m,y)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}xe.SHA512=B;class v extends B{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}}xe.SHA384=v;const T=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),N=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class K extends B{constructor(){super(28),this.Ah=T[0]|0,this.Al=T[1]|0,this.Bh=T[2]|0,this.Bl=T[3]|0,this.Ch=T[4]|0,this.Cl=T[5]|0,this.Dh=T[6]|0,this.Dl=T[7]|0,this.Eh=T[8]|0,this.El=T[9]|0,this.Fh=T[10]|0,this.Fl=T[11]|0,this.Gh=T[12]|0,this.Gl=T[13]|0,this.Hh=T[14]|0,this.Hl=T[15]|0}}xe.SHA512_224=K;class J extends B{constructor(){super(32),this.Ah=N[0]|0,this.Al=N[1]|0,this.Bh=N[2]|0,this.Bl=N[3]|0,this.Ch=N[4]|0,this.Cl=N[5]|0,this.Dh=N[6]|0,this.Dl=N[7]|0,this.Eh=N[8]|0,this.El=N[9]|0,this.Fh=N[10]|0,this.Fl=N[11]|0,this.Gh=N[12]|0,this.Gl=N[13]|0,this.Hh=N[14]|0,this.Hl=N[15]|0}}return xe.SHA512_256=J,xe.sha256=(0,n.createHasher)(()=>new o),xe.sha224=(0,n.createHasher)(()=>new a),xe.sha512=(0,n.createHasher)(()=>new B),xe.sha384=(0,n.createHasher)(()=>new v),xe.sha512_256=(0,n.createHasher)(()=>new J),xe.sha512_224=(0,n.createHasher)(()=>new K),xe}var mt={},Vt={},jt={},wn;function Rr(){return wn||(wn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=nt();class n extends t.Hash{constructor(o,a){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(o);const u=(0,t.toBytes)(a);if(this.iHash=o.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 h=this.blockLen,l=new Uint8Array(h);l.set(u.length>h?o.create().update(u).digest():u);for(let m=0;m<l.length;m++)l[m]^=54;this.iHash.update(l),this.oHash=o.create();for(let m=0;m<l.length;m++)l[m]^=106;this.oHash.update(l),(0,t.clean)(l)}update(o){return(0,t.aexists)(this),this.iHash.update(o),this}digestInto(o){(0,t.aexists)(this),(0,t.abytes)(o,this.outputLen),this.finished=!0,this.iHash.digestInto(o),this.oHash.update(o),this.oHash.digestInto(o),this.destroy()}digest(){const o=new Uint8Array(this.oHash.outputLen);return this.digestInto(o),o}_cloneInto(o){o||(o=Object.create(Object.getPrototypeOf(this),{}));const{oHash:a,iHash:u,finished:h,destroyed:l,blockLen:m,outputLen:y}=this;return o=o,o.finished=h,o.destroyed=l,o.blockLen=m,o.outputLen=y,o.oHash=a._cloneInto(o.oHash),o.iHash=u._cloneInto(o.iHash),o}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=n;const i=(c,o,a)=>new n(c,o).update(a).digest();e.hmac=i,e.hmac.create=(c,o)=>new n(c,o)})(jt)),jt}var $t={},yn;function at(){return yn||(yn=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=o,e._abool2=a,e._abytes2=u,e.numberToHexUnpadded=h,e.hexToNumber=l,e.bytesToNumberBE=m,e.bytesToNumberLE=y,e.numberToBytesBE=B,e.numberToBytesLE=v,e.numberToVarBytesBE=T,e.ensureBytes=N,e.equalBytes=K,e.copyBytes=J,e.asciiToBytes=F,e.inRange=P,e.aInRange=I,e.bitLen=O,e.bitGet=U,e.bitSet=Z,e.createHmacDrbg=C,e.validateObject=Q,e.isHash=V,e._validateObject=$,e.memoized=H;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=nt();var n=nt();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 i=BigInt(0),c=BigInt(1);function o(_,p){if(typeof p!="boolean")throw new Error(_+" boolean expected, got "+p)}function a(_,p=""){if(typeof _!="boolean"){const x=p&&`"${p}"`;throw new Error(x+"expected boolean, got type="+typeof _)}return _}function u(_,p,x=""){const k=(0,t.isBytes)(_),g=_?.length,S=p!==void 0;if(!k||S&&g!==p){const q=x&&`"${x}" `,G=S?` of length ${p}`:"",ee=k?`length=${g}`:`type=${typeof _}`;throw new Error(q+"expected Uint8Array"+G+", got "+ee)}return _}function h(_){const p=_.toString(16);return p.length&1?"0"+p:p}function l(_){if(typeof _!="string")throw new Error("hex string expected, got "+typeof _);return _===""?i:BigInt("0x"+_)}function m(_){return l((0,t.bytesToHex)(_))}function y(_){return(0,t.abytes)(_),l((0,t.bytesToHex)(Uint8Array.from(_).reverse()))}function B(_,p){return(0,t.hexToBytes)(_.toString(16).padStart(p*2,"0"))}function v(_,p){return B(_,p).reverse()}function T(_){return(0,t.hexToBytes)(h(_))}function N(_,p,x){let k;if(typeof p=="string")try{k=(0,t.hexToBytes)(p)}catch(S){throw new Error(_+" must be hex string or Uint8Array, cause: "+S)}else if((0,t.isBytes)(p))k=Uint8Array.from(p);else throw new Error(_+" must be hex string or Uint8Array");const g=k.length;if(typeof x=="number"&&g!==x)throw new Error(_+" of length "+x+" expected, got "+g);return k}function K(_,p){if(_.length!==p.length)return!1;let x=0;for(let k=0;k<_.length;k++)x|=_[k]^p[k];return x===0}function J(_){return Uint8Array.from(_)}function F(_){return Uint8Array.from(_,(p,x)=>{const k=p.charCodeAt(0);if(p.length!==1||k>127)throw new Error(`string contains non-ASCII character "${_[x]}" with code ${k} at position ${x}`);return k})}const b=_=>typeof _=="bigint"&&i<=_;function P(_,p,x){return b(_)&&b(p)&&b(x)&&p<=_&&_<x}function I(_,p,x,k){if(!P(p,x,k))throw new Error("expected valid "+_+": "+x+" <= n < "+k+", got "+p)}function O(_){let p;for(p=0;_>i;_>>=c,p+=1);return p}function U(_,p){return _>>BigInt(p)&c}function Z(_,p,x){return _|(x?c:i)<<BigInt(p)}const R=_=>(c<<BigInt(_))-c;e.bitMask=R;function C(_,p,x){if(typeof _!="number"||_<2)throw new Error("hashLen must be a number");if(typeof p!="number"||p<2)throw new Error("qByteLen must be a number");if(typeof x!="function")throw new Error("hmacFn must be a function");const k=re=>new Uint8Array(re),g=re=>Uint8Array.of(re);let S=k(_),q=k(_),G=0;const ee=()=>{S.fill(1),q.fill(0),G=0},ne=(...re)=>x(q,S,...re),ie=(re=k(0))=>{q=ne(g(0),re),S=ne(),re.length!==0&&(q=ne(g(1),re),S=ne())},L=()=>{if(G++>=1e3)throw new Error("drbg: tried 1000 values");let re=0;const le=[];for(;re<p;){S=ne();const ce=S.slice();le.push(ce),re+=S.length}return(0,t.concatBytes)(...le)};return(re,le)=>{ee(),ie(re);let ce;for(;!(ce=le(L()));)ie();return ee(),ce}}const j={bigint:_=>typeof _=="bigint",function:_=>typeof _=="function",boolean:_=>typeof _=="boolean",string:_=>typeof _=="string",stringOrUint8Array:_=>typeof _=="string"||(0,t.isBytes)(_),isSafeInteger:_=>Number.isSafeInteger(_),array:_=>Array.isArray(_),field:(_,p)=>p.Fp.isValid(_),hash:_=>typeof _=="function"&&Number.isSafeInteger(_.outputLen)};function Q(_,p,x={}){const k=(g,S,q)=>{const G=j[S];if(typeof G!="function")throw new Error("invalid validator function");const ee=_[g];if(!(q&&ee===void 0)&&!G(ee,_))throw new Error("param "+String(g)+" is invalid. Expected "+S+", got "+ee)};for(const[g,S]of Object.entries(p))k(g,S,!1);for(const[g,S]of Object.entries(x))k(g,S,!0);return _}function V(_){return typeof _=="function"&&Number.isSafeInteger(_.outputLen)}function $(_,p,x={}){if(!_||typeof _!="object")throw new Error("expected valid options object");function k(g,S,q){const G=_[g];if(q&&G===void 0)return;const ee=typeof G;if(ee!==S||G===null)throw new Error(`param "${g}" is invalid: expected ${S}, got ${ee}`)}Object.entries(p).forEach(([g,S])=>k(g,S,!1)),Object.entries(x).forEach(([g,S])=>k(g,S,!0))}const w=()=>{throw new Error("not implemented")};e.notImplemented=w;function H(_){const p=new WeakMap;return(x,...k)=>{const g=p.get(x);if(g!==void 0)return g;const S=_(x,...k);return p.set(x,S),S}}})($t)),$t}var je={},Te={},bn;function wt(){if(bn)return Te;bn=1,Object.defineProperty(Te,"__esModule",{value:!0}),Te.isNegativeLE=void 0,Te.mod=y,Te.pow=B,Te.pow2=v,Te.invert=T,Te.tonelliShanks=b,Te.FpSqrt=P,Te.validateField=U,Te.FpPow=Z,Te.FpInvertBatch=R,Te.FpDiv=C,Te.FpLegendre=j,Te.FpIsSquare=Q,Te.nLength=V,Te.Field=$,Te.FpSqrtOdd=w,Te.FpSqrtEven=H,Te.hashToPrivateScalar=_,Te.getFieldBytesLength=p,Te.getMinHashLength=x,Te.mapHashToField=k;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=at(),t=BigInt(0),n=BigInt(1),i=BigInt(2),c=BigInt(3),o=BigInt(4),a=BigInt(5),u=BigInt(7),h=BigInt(8),l=BigInt(9),m=BigInt(16);function y(g,S){const q=g%S;return q>=t?q:S+q}function B(g,S,q){return Z($(q),g,S)}function v(g,S,q){let G=g;for(;S-- >t;)G*=G,G%=q;return G}function T(g,S){if(g===t)throw new Error("invert: expected non-zero number");if(S<=t)throw new Error("invert: expected positive modulus, got "+S);let q=y(g,S),G=S,ee=t,ne=n;for(;q!==t;){const L=G/q,D=G%q,re=ee-ne*L;G=q,q=D,ee=ne,ne=re}if(G!==n)throw new Error("invert: does not exist");return y(ee,S)}function N(g,S,q){if(!g.eql(g.sqr(S),q))throw new Error("Cannot find square root")}function K(g,S){const q=(g.ORDER+n)/o,G=g.pow(S,q);return N(g,G,S),G}function J(g,S){const q=(g.ORDER-a)/h,G=g.mul(S,i),ee=g.pow(G,q),ne=g.mul(S,ee),ie=g.mul(g.mul(ne,i),ee),L=g.mul(ne,g.sub(ie,g.ONE));return N(g,L,S),L}function F(g){const S=$(g),q=b(g),G=q(S,S.neg(S.ONE)),ee=q(S,G),ne=q(S,S.neg(G)),ie=(g+u)/m;return(L,D)=>{let re=L.pow(D,ie),le=L.mul(re,G);const ce=L.mul(re,ee),W=L.mul(re,ne),oe=L.eql(L.sqr(le),D),be=L.eql(L.sqr(ce),D);re=L.cmov(re,le,oe),le=L.cmov(W,ce,be);const Se=L.eql(L.sqr(le),D),Oe=L.cmov(re,le,Se);return N(L,Oe,D),Oe}}function b(g){if(g<c)throw new Error("sqrt is not defined for small field");let S=g-n,q=0;for(;S%i===t;)S/=i,q++;let G=i;const ee=$(g);for(;j(ee,G)===1;)if(G++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(q===1)return K;let ne=ee.pow(G,S);const ie=(S+n)/i;return function(D,re){if(D.is0(re))return re;if(j(D,re)!==1)throw new Error("Cannot find square root");let le=q,ce=D.mul(D.ONE,ne),W=D.pow(re,S),oe=D.pow(re,ie);for(;!D.eql(W,D.ONE);){if(D.is0(W))return D.ZERO;let be=1,Se=D.sqr(W);for(;!D.eql(Se,D.ONE);)if(be++,Se=D.sqr(Se),be===le)throw new Error("Cannot find square root");const Oe=n<<BigInt(le-be-1),qe=D.pow(ce,Oe);le=be,ce=D.sqr(qe),W=D.mul(W,ce),oe=D.mul(oe,qe)}return oe}}function P(g){return g%o===c?K:g%h===a?J:g%m===l?F(g):b(g)}const I=(g,S)=>(y(g,S)&n)===n;Te.isNegativeLE=I;const O=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function U(g){const S={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},q=O.reduce((G,ee)=>(G[ee]="function",G),S);return(0,e._validateObject)(g,q),g}function Z(g,S,q){if(q<t)throw new Error("invalid exponent, negatives unsupported");if(q===t)return g.ONE;if(q===n)return S;let G=g.ONE,ee=S;for(;q>t;)q&n&&(G=g.mul(G,ee)),ee=g.sqr(ee),q>>=n;return G}function R(g,S,q=!1){const G=new Array(S.length).fill(q?g.ZERO:void 0),ee=S.reduce((ie,L,D)=>g.is0(L)?ie:(G[D]=ie,g.mul(ie,L)),g.ONE),ne=g.inv(ee);return S.reduceRight((ie,L,D)=>g.is0(L)?ie:(G[D]=g.mul(ie,G[D]),g.mul(ie,L)),ne),G}function C(g,S,q){return g.mul(S,typeof q=="bigint"?T(q,g.ORDER):g.inv(q))}function j(g,S){const q=(g.ORDER-n)/i,G=g.pow(S,q),ee=g.eql(G,g.ONE),ne=g.eql(G,g.ZERO),ie=g.eql(G,g.neg(g.ONE));if(!ee&&!ne&&!ie)throw new Error("invalid Legendre symbol result");return ee?1:ne?0:-1}function Q(g,S){return j(g,S)===1}function V(g,S){S!==void 0&&(0,e.anumber)(S);const q=S!==void 0?S:g.toString(2).length,G=Math.ceil(q/8);return{nBitLength:q,nByteLength:G}}function $(g,S,q=!1,G={}){if(g<=t)throw new Error("invalid field: expected ORDER > 0, got "+g);let ee,ne,ie=!1,L;if(typeof S=="object"&&S!=null){if(G.sqrt||q)throw new Error("cannot specify opts in two arguments");const W=S;W.BITS&&(ee=W.BITS),W.sqrt&&(ne=W.sqrt),typeof W.isLE=="boolean"&&(q=W.isLE),typeof W.modFromBytes=="boolean"&&(ie=W.modFromBytes),L=W.allowedLengths}else typeof S=="number"&&(ee=S),G.sqrt&&(ne=G.sqrt);const{nBitLength:D,nByteLength:re}=V(g,ee);if(re>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let le;const ce=Object.freeze({ORDER:g,isLE:q,BITS:D,BYTES:re,MASK:(0,e.bitMask)(D),ZERO:t,ONE:n,allowedLengths:L,create:W=>y(W,g),isValid:W=>{if(typeof W!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof W);return t<=W&&W<g},is0:W=>W===t,isValidNot0:W=>!ce.is0(W)&&ce.isValid(W),isOdd:W=>(W&n)===n,neg:W=>y(-W,g),eql:(W,oe)=>W===oe,sqr:W=>y(W*W,g),add:(W,oe)=>y(W+oe,g),sub:(W,oe)=>y(W-oe,g),mul:(W,oe)=>y(W*oe,g),pow:(W,oe)=>Z(ce,W,oe),div:(W,oe)=>y(W*T(oe,g),g),sqrN:W=>W*W,addN:(W,oe)=>W+oe,subN:(W,oe)=>W-oe,mulN:(W,oe)=>W*oe,inv:W=>T(W,g),sqrt:ne||(W=>(le||(le=P(g)),le(ce,W))),toBytes:W=>q?(0,e.numberToBytesLE)(W,re):(0,e.numberToBytesBE)(W,re),fromBytes:(W,oe=!0)=>{if(L){if(!L.includes(W.length)||W.length>re)throw new Error("Field.fromBytes: expected "+L+" bytes, got "+W.length);const Se=new Uint8Array(re);Se.set(W,q?0:Se.length-W.length),W=Se}if(W.length!==re)throw new Error("Field.fromBytes: expected "+re+" bytes, got "+W.length);let be=q?(0,e.bytesToNumberLE)(W):(0,e.bytesToNumberBE)(W);if(ie&&(be=y(be,g)),!oe&&!ce.isValid(be))throw new Error("invalid field element: outside of range 0..ORDER");return be},invertBatch:W=>R(ce,W),cmov:(W,oe,be)=>be?oe:W});return Object.freeze(ce)}function w(g,S){if(!g.isOdd)throw new Error("Field doesn't have isOdd");const q=g.sqrt(S);return g.isOdd(q)?q:g.neg(q)}function H(g,S){if(!g.isOdd)throw new Error("Field doesn't have isOdd");const q=g.sqrt(S);return g.isOdd(q)?g.neg(q):q}function _(g,S,q=!1){g=(0,e.ensureBytes)("privateHash",g);const G=g.length,ee=V(S).nByteLength+8;if(ee<24||G<ee||G>1024)throw new Error("hashToPrivateScalar: expected "+ee+"-1024 bytes of input, got "+G);const ne=q?(0,e.bytesToNumberLE)(g):(0,e.bytesToNumberBE)(g);return y(ne,S-n)+n}function p(g){if(typeof g!="bigint")throw new Error("field order must be bigint");const S=g.toString(2).length;return Math.ceil(S/8)}function x(g){const S=p(g);return S+Math.ceil(S/2)}function k(g,S,q=!1){const G=g.length,ee=p(S),ne=x(S);if(G<16||G<ne||G>1024)throw new Error("expected "+ne+"-1024 bytes of input, got "+G);const ie=q?(0,e.bytesToNumberLE)(g):(0,e.bytesToNumberBE)(g),L=y(ie,S-n)+n;return q?(0,e.numberToBytesLE)(L,ee):(0,e.numberToBytesBE)(L,ee)}return Te}var En;function Or(){if(En)return je;En=1,Object.defineProperty(je,"__esModule",{value:!0}),je.wNAF=void 0,je.negateCt=c,je.normalizeZ=o,je.mulEndoUnsafe=K,je.pippenger=J,je.precomputeMSMUnsafe=F,je.validateBasic=b,je._createCurveFields=I;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=at(),t=wt(),n=BigInt(0),i=BigInt(1);function c(O,U){const Z=U.negate();return O?Z:U}function o(O,U){const Z=(0,t.FpInvertBatch)(O.Fp,U.map(R=>R.Z));return U.map((R,C)=>O.fromAffine(R.toAffine(Z[C])))}function a(O,U){if(!Number.isSafeInteger(O)||O<=0||O>U)throw new Error("invalid window size, expected [1.."+U+"], got W="+O)}function u(O,U){a(O,U);const Z=Math.ceil(U/O)+1,R=2**(O-1),C=2**O,j=(0,e.bitMask)(O),Q=BigInt(O);return{windows:Z,windowSize:R,mask:j,maxNumber:C,shiftBy:Q}}function h(O,U,Z){const{windowSize:R,mask:C,maxNumber:j,shiftBy:Q}=Z;let V=Number(O&C),$=O>>Q;V>R&&(V-=j,$+=i);const w=U*R,H=w+Math.abs(V)-1,_=V===0,p=V<0,x=U%2!==0;return{nextN:$,offset:H,isZero:_,isNeg:p,isNegF:x,offsetF:w}}function l(O,U){if(!Array.isArray(O))throw new Error("array expected");O.forEach((Z,R)=>{if(!(Z instanceof U))throw new Error("invalid point at index "+R)})}function m(O,U){if(!Array.isArray(O))throw new Error("array of scalars expected");O.forEach((Z,R)=>{if(!U.isValid(Z))throw new Error("invalid scalar at index "+R)})}const y=new WeakMap,B=new WeakMap;function v(O){return B.get(O)||1}function T(O){if(O!==n)throw new Error("invalid wNAF")}class N{constructor(U,Z){this.BASE=U.BASE,this.ZERO=U.ZERO,this.Fn=U.Fn,this.bits=Z}_unsafeLadder(U,Z,R=this.ZERO){let C=U;for(;Z>n;)Z&i&&(R=R.add(C)),C=C.double(),Z>>=i;return R}precomputeWindow(U,Z){const{windows:R,windowSize:C}=u(Z,this.bits),j=[];let Q=U,V=Q;for(let $=0;$<R;$++){V=Q,j.push(V);for(let w=1;w<C;w++)V=V.add(Q),j.push(V);Q=V.double()}return j}wNAF(U,Z,R){if(!this.Fn.isValid(R))throw new Error("invalid scalar");let C=this.ZERO,j=this.BASE;const Q=u(U,this.bits);for(let V=0;V<Q.windows;V++){const{nextN:$,offset:w,isZero:H,isNeg:_,isNegF:p,offsetF:x}=h(R,V,Q);R=$,H?j=j.add(c(p,Z[x])):C=C.add(c(_,Z[w]))}return T(R),{p:C,f:j}}wNAFUnsafe(U,Z,R,C=this.ZERO){const j=u(U,this.bits);for(let Q=0;Q<j.windows&&R!==n;Q++){const{nextN:V,offset:$,isZero:w,isNeg:H}=h(R,Q,j);if(R=V,!w){const _=Z[$];C=C.add(H?_.negate():_)}}return T(R),C}getPrecomputes(U,Z,R){let C=y.get(Z);return C||(C=this.precomputeWindow(Z,U),U!==1&&(typeof R=="function"&&(C=R(C)),y.set(Z,C))),C}cached(U,Z,R){const C=v(U);return this.wNAF(C,this.getPrecomputes(C,U,R),Z)}unsafe(U,Z,R,C){const j=v(U);return j===1?this._unsafeLadder(U,Z,C):this.wNAFUnsafe(j,this.getPrecomputes(j,U,R),Z,C)}createCache(U,Z){a(Z,this.bits),B.set(U,Z),y.delete(U)}hasCache(U){return v(U)!==1}}je.wNAF=N;function K(O,U,Z,R){let C=U,j=O.ZERO,Q=O.ZERO;for(;Z>n||R>n;)Z&i&&(j=j.add(C)),R&i&&(Q=Q.add(C)),C=C.double(),Z>>=i,R>>=i;return{p1:j,p2:Q}}function J(O,U,Z,R){l(Z,O),m(R,U);const C=Z.length,j=R.length;if(C!==j)throw new Error("arrays of points and scalars must have equal length");const Q=O.ZERO,V=(0,e.bitLen)(BigInt(C));let $=1;V>12?$=V-3:V>4?$=V-2:V>0&&($=2);const w=(0,e.bitMask)($),H=new Array(Number(w)+1).fill(Q),_=Math.floor((U.BITS-1)/$)*$;let p=Q;for(let x=_;x>=0;x-=$){H.fill(Q);for(let g=0;g<j;g++){const S=R[g],q=Number(S>>BigInt(x)&w);H[q]=H[q].add(Z[g])}let k=Q;for(let g=H.length-1,S=Q;g>0;g--)S=S.add(H[g]),k=k.add(S);if(p=p.add(k),x!==0)for(let g=0;g<$;g++)p=p.double()}return p}function F(O,U,Z,R){a(R,U.BITS),l(Z,O);const C=O.ZERO,j=2**R-1,Q=Math.ceil(U.BITS/R),V=(0,e.bitMask)(R),$=Z.map(w=>{const H=[];for(let _=0,p=w;_<j;_++)H.push(p),p=p.add(w);return H});return w=>{if(m(w,U),w.length>Z.length)throw new Error("array of scalars must be smaller than array of points");let H=C;for(let _=0;_<Q;_++){if(H!==C)for(let x=0;x<R;x++)H=H.double();const p=BigInt(Q*R-(_+1)*R);for(let x=0;x<w.length;x++){const k=w[x],g=Number(k>>p&V);g&&(H=H.add($[x][g-1]))}}return H}}function b(O){return(0,t.validateField)(O.Fp),(0,e.validateObject)(O,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(O.n,O.nBitLength),...O,p:O.Fp.ORDER})}function P(O,U,Z){if(U){if(U.ORDER!==O)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(U),U}else return(0,t.Field)(O,{isLE:Z})}function I(O,U,Z={},R){if(R===void 0&&(R=O==="edwards"),!U||typeof U!="object")throw new Error(`expected valid ${O} CURVE object`);for(const $ of["p","n","h"]){const w=U[$];if(!(typeof w=="bigint"&&w>n))throw new Error(`CURVE.${$} must be positive bigint`)}const C=P(U.p,Z.Fp,R),j=P(U.n,Z.Fn,R),V=["Gx","Gy","a",O==="weierstrass"?"b":"d"];for(const $ of V)if(!C.isValid(U[$]))throw new Error(`CURVE.${$} must be valid field element of CURVE.Fp`);return U=Object.freeze(Object.assign({},U)),{CURVE:U,Fp:C,Fn:j}}return je}var Bn;function xn(){return Bn||(Bn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=u,e._normFnElement=K,e.weierstrassN=J,e.SWUFpSqrtRatio=b,e.mapToCurveSimpleSWU=P,e.ecdh=O,e.ecdsa=U,e.weierstrassPoints=Z,e._legacyHelperEquat=j,e.weierstrass=$;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Rr(),n=nt(),i=at(),c=Or(),o=wt(),a=(w,H)=>(w+(w>=0?H:-H)/v)/H;function u(w,H,_){const[[p,x],[k,g]]=H,S=a(g*w,_),q=a(-x*w,_);let G=w-S*p-q*k,ee=-S*x-q*g;const ne=G<y,ie=ee<y;ne&&(G=-G),ie&&(ee=-ee);const L=(0,i.bitMask)(Math.ceil((0,i.bitLen)(_)/2))+B;if(G<y||G>=L||ee<y||ee>=L)throw new Error("splitScalar (endomorphism): failed, k="+w);return{k1neg:ne,k1:G,k2neg:ie,k2:ee}}function h(w){if(!["compact","recovered","der"].includes(w))throw new Error('Signature format must be "compact", "recovered", or "der"');return w}function l(w,H){const _={};for(let p of Object.keys(H))_[p]=w[p]===void 0?H[p]:w[p];return(0,i._abool2)(_.lowS,"lowS"),(0,i._abool2)(_.prehash,"prehash"),_.format!==void 0&&h(_.format),_}class m extends Error{constructor(H=""){super(H)}}e.DERErr=m,e.DER={Err:m,_tlv:{encode:(w,H)=>{const{Err:_}=e.DER;if(w<0||w>256)throw new _("tlv.encode: wrong tag");if(H.length&1)throw new _("tlv.encode: unpadded data");const p=H.length/2,x=(0,i.numberToHexUnpadded)(p);if(x.length/2&128)throw new _("tlv.encode: long form length too big");const k=p>127?(0,i.numberToHexUnpadded)(x.length/2|128):"";return(0,i.numberToHexUnpadded)(w)+k+x+H},decode(w,H){const{Err:_}=e.DER;let p=0;if(w<0||w>256)throw new _("tlv.encode: wrong tag");if(H.length<2||H[p++]!==w)throw new _("tlv.decode: wrong tlv");const x=H[p++],k=!!(x&128);let g=0;if(!k)g=x;else{const q=x&127;if(!q)throw new _("tlv.decode(long): indefinite length not supported");if(q>4)throw new _("tlv.decode(long): byte length is too big");const G=H.subarray(p,p+q);if(G.length!==q)throw new _("tlv.decode: length bytes not complete");if(G[0]===0)throw new _("tlv.decode(long): zero leftmost byte");for(const ee of G)g=g<<8|ee;if(p+=q,g<128)throw new _("tlv.decode(long): not minimal encoding")}const S=H.subarray(p,p+g);if(S.length!==g)throw new _("tlv.decode: wrong value length");return{v:S,l:H.subarray(p+g)}}},_int:{encode(w){const{Err:H}=e.DER;if(w<y)throw new H("integer: negative integers are not allowed");let _=(0,i.numberToHexUnpadded)(w);if(Number.parseInt(_[0],16)&8&&(_="00"+_),_.length&1)throw new H("unexpected DER parsing assertion: unpadded hex");return _},decode(w){const{Err:H}=e.DER;if(w[0]&128)throw new H("invalid signature integer: negative");if(w[0]===0&&!(w[1]&128))throw new H("invalid signature integer: unnecessary leading zero");return(0,i.bytesToNumberBE)(w)}},toSig(w){const{Err:H,_int:_,_tlv:p}=e.DER,x=(0,i.ensureBytes)("signature",w),{v:k,l:g}=p.decode(48,x);if(g.length)throw new H("invalid signature: left bytes after parsing");const{v:S,l:q}=p.decode(2,k),{v:G,l:ee}=p.decode(2,q);if(ee.length)throw new H("invalid signature: left bytes after parsing");return{r:_.decode(S),s:_.decode(G)}},hexFromSig(w){const{_tlv:H,_int:_}=e.DER,p=H.encode(2,_.encode(w.r)),x=H.encode(2,_.encode(w.s)),k=p+x;return H.encode(48,k)}};const y=BigInt(0),B=BigInt(1),v=BigInt(2),T=BigInt(3),N=BigInt(4);function K(w,H){const{BYTES:_}=w;let p;if(typeof H=="bigint")p=H;else{let x=(0,i.ensureBytes)("private key",H);try{p=w.fromBytes(x)}catch{throw new Error(`invalid private key: expected ui8a of size ${_}, got ${typeof H}`)}}if(!w.isValidNot0(p))throw new Error("invalid private key: out of range [1..N-1]");return p}function J(w,H={}){const _=(0,c._createCurveFields)("weierstrass",w,H),{Fp:p,Fn:x}=_;let k=_.CURVE;const{h:g,n:S}=k;(0,i._validateObject)(H,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:q}=H;if(q&&(!p.is0(k.a)||typeof q.beta!="bigint"||!Array.isArray(q.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const G=I(p,x);function ee(){if(!p.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function ne(Be,te,Y){const{x:z,y:f}=te.toAffine(),r=p.toBytes(z);if((0,i._abool2)(Y,"isCompressed"),Y){ee();const s=!p.isOdd(f);return(0,i.concatBytes)(F(s),r)}else return(0,i.concatBytes)(Uint8Array.of(4),r,p.toBytes(f))}function ie(Be){(0,i._abytes2)(Be,void 0,"Point");const{publicKey:te,publicKeyUncompressed:Y}=G,z=Be.length,f=Be[0],r=Be.subarray(1);if(z===te&&(f===2||f===3)){const s=p.fromBytes(r);if(!p.isValid(s))throw new Error("bad point: is not on curve, wrong x");const d=re(s);let E;try{E=p.sqrt(d)}catch(ue){const de=ue instanceof Error?": "+ue.message:"";throw new Error("bad point: is not on curve, sqrt error"+de)}ee();const A=p.isOdd(E);return(f&1)===1!==A&&(E=p.neg(E)),{x:s,y:E}}else if(z===Y&&f===4){const s=p.BYTES,d=p.fromBytes(r.subarray(0,s)),E=p.fromBytes(r.subarray(s,s*2));if(!le(d,E))throw new Error("bad point: is not on curve");return{x:d,y:E}}else throw new Error(`bad point: got length ${z}, expected compressed=${te} or uncompressed=${Y}`)}const L=H.toBytes||ne,D=H.fromBytes||ie;function re(Be){const te=p.sqr(Be),Y=p.mul(te,Be);return p.add(p.add(Y,p.mul(Be,k.a)),k.b)}function le(Be,te){const Y=p.sqr(te),z=re(Be);return p.eql(Y,z)}if(!le(k.Gx,k.Gy))throw new Error("bad curve params: generator point");const ce=p.mul(p.pow(k.a,T),N),W=p.mul(p.sqr(k.b),BigInt(27));if(p.is0(p.add(ce,W)))throw new Error("bad curve params: a or b");function oe(Be,te,Y=!1){if(!p.isValid(te)||Y&&p.is0(te))throw new Error(`bad point coordinate ${Be}`);return te}function be(Be){if(!(Be instanceof Ee))throw new Error("ProjectivePoint expected")}function Se(Be){if(!q||!q.basises)throw new Error("no endo");return u(Be,q.basises,x.ORDER)}const Oe=(0,i.memoized)((Be,te)=>{const{X:Y,Y:z,Z:f}=Be;if(p.eql(f,p.ONE))return{x:Y,y:z};const r=Be.is0();te==null&&(te=r?p.ONE:p.inv(f));const s=p.mul(Y,te),d=p.mul(z,te),E=p.mul(f,te);if(r)return{x:p.ZERO,y:p.ZERO};if(!p.eql(E,p.ONE))throw new Error("invZ was invalid");return{x:s,y:d}}),qe=(0,i.memoized)(Be=>{if(Be.is0()){if(H.allowInfinityPoint&&!p.is0(Be.Y))return;throw new Error("bad point: ZERO")}const{x:te,y:Y}=Be.toAffine();if(!p.isValid(te)||!p.isValid(Y))throw new Error("bad point: x or y not field elements");if(!le(te,Y))throw new Error("bad point: equation left != right");if(!Be.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function ke(Be,te,Y,z,f){return Y=new Ee(p.mul(Y.X,Be),Y.Y,Y.Z),te=(0,c.negateCt)(z,te),Y=(0,c.negateCt)(f,Y),te.add(Y)}class Ee{constructor(te,Y,z){this.X=oe("x",te),this.Y=oe("y",Y,!0),this.Z=oe("z",z),Object.freeze(this)}static CURVE(){return k}static fromAffine(te){const{x:Y,y:z}=te||{};if(!te||!p.isValid(Y)||!p.isValid(z))throw new Error("invalid affine point");if(te instanceof Ee)throw new Error("projective point not allowed");return p.is0(Y)&&p.is0(z)?Ee.ZERO:new Ee(Y,z,p.ONE)}static fromBytes(te){const Y=Ee.fromAffine(D((0,i._abytes2)(te,void 0,"point")));return Y.assertValidity(),Y}static fromHex(te){return Ee.fromBytes((0,i.ensureBytes)("pointHex",te))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(te=8,Y=!0){return He.createCache(this,te),Y||this.multiply(T),this}assertValidity(){qe(this)}hasEvenY(){const{y:te}=this.toAffine();if(!p.isOdd)throw new Error("Field doesn't support isOdd");return!p.isOdd(te)}equals(te){be(te);const{X:Y,Y:z,Z:f}=this,{X:r,Y:s,Z:d}=te,E=p.eql(p.mul(Y,d),p.mul(r,f)),A=p.eql(p.mul(z,d),p.mul(s,f));return E&&A}negate(){return new Ee(this.X,p.neg(this.Y),this.Z)}double(){const{a:te,b:Y}=k,z=p.mul(Y,T),{X:f,Y:r,Z:s}=this;let d=p.ZERO,E=p.ZERO,A=p.ZERO,M=p.mul(f,f),ue=p.mul(r,r),de=p.mul(s,s),ae=p.mul(f,r);return ae=p.add(ae,ae),A=p.mul(f,s),A=p.add(A,A),d=p.mul(te,A),E=p.mul(z,de),E=p.add(d,E),d=p.sub(ue,E),E=p.add(ue,E),E=p.mul(d,E),d=p.mul(ae,d),A=p.mul(z,A),de=p.mul(te,de),ae=p.sub(M,de),ae=p.mul(te,ae),ae=p.add(ae,A),A=p.add(M,M),M=p.add(A,M),M=p.add(M,de),M=p.mul(M,ae),E=p.add(E,M),de=p.mul(r,s),de=p.add(de,de),M=p.mul(de,ae),d=p.sub(d,M),A=p.mul(de,ue),A=p.add(A,A),A=p.add(A,A),new Ee(d,E,A)}add(te){be(te);const{X:Y,Y:z,Z:f}=this,{X:r,Y:s,Z:d}=te;let E=p.ZERO,A=p.ZERO,M=p.ZERO;const ue=k.a,de=p.mul(k.b,T);let ae=p.mul(Y,r),ye=p.mul(z,s),pe=p.mul(f,d),Ve=p.add(Y,z),Re=p.add(r,s);Ve=p.mul(Ve,Re),Re=p.add(ae,ye),Ve=p.sub(Ve,Re),Re=p.add(Y,f);let Me=p.add(r,d);return Re=p.mul(Re,Me),Me=p.add(ae,pe),Re=p.sub(Re,Me),Me=p.add(z,f),E=p.add(s,d),Me=p.mul(Me,E),E=p.add(ye,pe),Me=p.sub(Me,E),M=p.mul(ue,Re),E=p.mul(de,pe),M=p.add(E,M),E=p.sub(ye,M),M=p.add(ye,M),A=p.mul(E,M),ye=p.add(ae,ae),ye=p.add(ye,ae),pe=p.mul(ue,pe),Re=p.mul(de,Re),ye=p.add(ye,pe),pe=p.sub(ae,pe),pe=p.mul(ue,pe),Re=p.add(Re,pe),ae=p.mul(ye,Re),A=p.add(A,ae),ae=p.mul(Me,Re),E=p.mul(Ve,E),E=p.sub(E,ae),ae=p.mul(Ve,ye),M=p.mul(Me,M),M=p.add(M,ae),new Ee(E,A,M)}subtract(te){return this.add(te.negate())}is0(){return this.equals(Ee.ZERO)}multiply(te){const{endo:Y}=H;if(!x.isValidNot0(te))throw new Error("invalid scalar: out of range");let z,f;const r=s=>He.cached(this,s,d=>(0,c.normalizeZ)(Ee,d));if(Y){const{k1neg:s,k1:d,k2neg:E,k2:A}=Se(te),{p:M,f:ue}=r(d),{p:de,f:ae}=r(A);f=ue.add(ae),z=ke(Y.beta,M,de,s,E)}else{const{p:s,f:d}=r(te);z=s,f=d}return(0,c.normalizeZ)(Ee,[z,f])[0]}multiplyUnsafe(te){const{endo:Y}=H,z=this;if(!x.isValid(te))throw new Error("invalid scalar: out of range");if(te===y||z.is0())return Ee.ZERO;if(te===B)return z;if(He.hasCache(this))return this.multiply(te);if(Y){const{k1neg:f,k1:r,k2neg:s,k2:d}=Se(te),{p1:E,p2:A}=(0,c.mulEndoUnsafe)(Ee,z,r,d);return ke(Y.beta,E,A,f,s)}else return He.unsafe(z,te)}multiplyAndAddUnsafe(te,Y,z){const f=this.multiplyUnsafe(Y).add(te.multiplyUnsafe(z));return f.is0()?void 0:f}toAffine(te){return Oe(this,te)}isTorsionFree(){const{isTorsionFree:te}=H;return g===B?!0:te?te(Ee,this):He.unsafe(this,S).is0()}clearCofactor(){const{clearCofactor:te}=H;return g===B?this:te?te(Ee,this):this.multiplyUnsafe(g)}isSmallOrder(){return this.multiplyUnsafe(g).is0()}toBytes(te=!0){return(0,i._abool2)(te,"isCompressed"),this.assertValidity(),L(Ee,this,te)}toHex(te=!0){return(0,i.bytesToHex)(this.toBytes(te))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(te=!0){return this.toBytes(te)}_setWindowSize(te){this.precompute(te)}static normalizeZ(te){return(0,c.normalizeZ)(Ee,te)}static msm(te,Y){return(0,c.pippenger)(Ee,x,te,Y)}static fromPrivateKey(te){return Ee.BASE.multiply(K(x,te))}}Ee.BASE=new Ee(k.Gx,k.Gy,p.ONE),Ee.ZERO=new Ee(p.ZERO,p.ONE,p.ZERO),Ee.Fp=p,Ee.Fn=x;const Ke=x.BITS,He=new c.wNAF(Ee,H.endo?Math.ceil(Ke/2):Ke);return Ee.BASE.precompute(8),Ee}function F(w){return Uint8Array.of(w?2:3)}function b(w,H){const _=w.ORDER;let p=y;for(let D=_-B;D%v===y;D/=v)p+=B;const x=p,k=v<<x-B-B,g=k*v,S=(_-B)/g,q=(S-B)/v,G=g-B,ee=k,ne=w.pow(H,S),ie=w.pow(H,(S+B)/v);let L=(D,re)=>{let le=ne,ce=w.pow(re,G),W=w.sqr(ce);W=w.mul(W,re);let oe=w.mul(D,W);oe=w.pow(oe,q),oe=w.mul(oe,ce),ce=w.mul(oe,re),W=w.mul(oe,D);let be=w.mul(W,ce);oe=w.pow(be,ee);let Se=w.eql(oe,w.ONE);ce=w.mul(W,ie),oe=w.mul(be,le),W=w.cmov(ce,W,Se),be=w.cmov(oe,be,Se);for(let Oe=x;Oe>B;Oe--){let qe=Oe-v;qe=v<<qe-B;let ke=w.pow(be,qe);const Ee=w.eql(ke,w.ONE);ce=w.mul(W,le),le=w.mul(le,le),ke=w.mul(be,le),W=w.cmov(ce,W,Ee),be=w.cmov(ke,be,Ee)}return{isValid:Se,value:W}};if(w.ORDER%N===T){const D=(w.ORDER-T)/N,re=w.sqrt(w.neg(H));L=(le,ce)=>{let W=w.sqr(ce);const oe=w.mul(le,ce);W=w.mul(W,oe);let be=w.pow(W,D);be=w.mul(be,oe);const Se=w.mul(be,re),Oe=w.mul(w.sqr(be),ce),qe=w.eql(Oe,le);let ke=w.cmov(Se,be,qe);return{isValid:qe,value:ke}}}return L}function P(w,H){(0,o.validateField)(w);const{A:_,B:p,Z:x}=H;if(!w.isValid(_)||!w.isValid(p)||!w.isValid(x))throw new Error("mapToCurveSimpleSWU: invalid opts");const k=b(w,x);if(!w.isOdd)throw new Error("Field does not have .isOdd()");return g=>{let S,q,G,ee,ne,ie,L,D;S=w.sqr(g),S=w.mul(S,x),q=w.sqr(S),q=w.add(q,S),G=w.add(q,w.ONE),G=w.mul(G,p),ee=w.cmov(x,w.neg(q),!w.eql(q,w.ZERO)),ee=w.mul(ee,_),q=w.sqr(G),ie=w.sqr(ee),ne=w.mul(ie,_),q=w.add(q,ne),q=w.mul(q,G),ie=w.mul(ie,ee),ne=w.mul(ie,p),q=w.add(q,ne),L=w.mul(S,G);const{isValid:re,value:le}=k(q,ie);D=w.mul(S,g),D=w.mul(D,le),L=w.cmov(L,G,re),D=w.cmov(D,le,re);const ce=w.isOdd(g)===w.isOdd(D);D=w.cmov(w.neg(D),D,ce);const W=(0,o.FpInvertBatch)(w,[ee],!0)[0];return L=w.mul(L,W),{x:L,y:D}}}function I(w,H){return{secretKey:H.BYTES,publicKey:1+w.BYTES,publicKeyUncompressed:1+2*w.BYTES,publicKeyHasPrefix:!0,signature:2*H.BYTES}}function O(w,H={}){const{Fn:_}=w,p=H.randomBytes||i.randomBytes,x=Object.assign(I(w.Fp,_),{seed:(0,o.getMinHashLength)(_.ORDER)});function k(L){try{return!!K(_,L)}catch{return!1}}function g(L,D){const{publicKey:re,publicKeyUncompressed:le}=x;try{const ce=L.length;return D===!0&&ce!==re||D===!1&&ce!==le?!1:!!w.fromBytes(L)}catch{return!1}}function S(L=p(x.seed)){return(0,o.mapHashToField)((0,i._abytes2)(L,x.seed,"seed"),_.ORDER)}function q(L,D=!0){return w.BASE.multiply(K(_,L)).toBytes(D)}function G(L){const D=S(L);return{secretKey:D,publicKey:q(D)}}function ee(L){if(typeof L=="bigint")return!1;if(L instanceof w)return!0;const{secretKey:D,publicKey:re,publicKeyUncompressed:le}=x;if(_.allowedLengths||D===re)return;const ce=(0,i.ensureBytes)("key",L).length;return ce===re||ce===le}function ne(L,D,re=!0){if(ee(L)===!0)throw new Error("first arg must be private key");if(ee(D)===!1)throw new Error("second arg must be public key");const le=K(_,L);return w.fromHex(D).multiply(le).toBytes(re)}return Object.freeze({getPublicKey:q,getSharedSecret:ne,keygen:G,Point:w,utils:{isValidSecretKey:k,isValidPublicKey:g,randomSecretKey:S,isValidPrivateKey:k,randomPrivateKey:S,normPrivateKeyToScalar:L=>K(_,L),precompute(L=8,D=w.BASE){return D.precompute(L,!1)}},lengths:x})}function U(w,H,_={}){(0,n.ahash)(H),(0,i._validateObject)(_,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const p=_.randomBytes||i.randomBytes,x=_.hmac||((Y,...z)=>(0,t.hmac)(H,Y,(0,i.concatBytes)(...z))),{Fp:k,Fn:g}=w,{ORDER:S,BITS:q}=g,{keygen:G,getPublicKey:ee,getSharedSecret:ne,utils:ie,lengths:L}=O(w,_),D={prehash:!1,lowS:typeof _.lowS=="boolean"?_.lowS:!1,format:void 0,extraEntropy:!1},re="compact";function le(Y){const z=S>>B;return Y>z}function ce(Y,z){if(!g.isValidNot0(z))throw new Error(`invalid signature ${Y}: out of range 1..Point.Fn.ORDER`);return z}function W(Y,z){h(z);const f=L.signature,r=z==="compact"?f:z==="recovered"?f+1:void 0;return(0,i._abytes2)(Y,r,`${z} signature`)}class oe{constructor(z,f,r){this.r=ce("r",z),this.s=ce("s",f),r!=null&&(this.recovery=r),Object.freeze(this)}static fromBytes(z,f=re){W(z,f);let r;if(f==="der"){const{r:A,s:M}=e.DER.toSig((0,i._abytes2)(z));return new oe(A,M)}f==="recovered"&&(r=z[0],f="compact",z=z.subarray(1));const s=g.BYTES,d=z.subarray(0,s),E=z.subarray(s,s*2);return new oe(g.fromBytes(d),g.fromBytes(E),r)}static fromHex(z,f){return this.fromBytes((0,i.hexToBytes)(z),f)}addRecoveryBit(z){return new oe(this.r,this.s,z)}recoverPublicKey(z){const f=k.ORDER,{r,s,recovery:d}=this;if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");if(S*v<f&&d>1)throw new Error("recovery id is ambiguous for h>1 curve");const A=d===2||d===3?r+S:r;if(!k.isValid(A))throw new Error("recovery id 2 or 3 invalid");const M=k.toBytes(A),ue=w.fromBytes((0,i.concatBytes)(F((d&1)===0),M)),de=g.inv(A),ae=Se((0,i.ensureBytes)("msgHash",z)),ye=g.create(-ae*de),pe=g.create(s*de),Ve=w.BASE.multiplyUnsafe(ye).add(ue.multiplyUnsafe(pe));if(Ve.is0())throw new Error("point at infinify");return Ve.assertValidity(),Ve}hasHighS(){return le(this.s)}toBytes(z=re){if(h(z),z==="der")return(0,i.hexToBytes)(e.DER.hexFromSig(this));const f=g.toBytes(this.r),r=g.toBytes(this.s);if(z==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,i.concatBytes)(Uint8Array.of(this.recovery),f,r)}return(0,i.concatBytes)(f,r)}toHex(z){return(0,i.bytesToHex)(this.toBytes(z))}assertValidity(){}static fromCompact(z){return oe.fromBytes((0,i.ensureBytes)("sig",z),"compact")}static fromDER(z){return oe.fromBytes((0,i.ensureBytes)("sig",z),"der")}normalizeS(){return this.hasHighS()?new oe(this.r,g.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,i.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,i.bytesToHex)(this.toBytes("compact"))}}const be=_.bits2int||function(z){if(z.length>8192)throw new Error("input is too large");const f=(0,i.bytesToNumberBE)(z),r=z.length*8-q;return r>0?f>>BigInt(r):f},Se=_.bits2int_modN||function(z){return g.create(be(z))},Oe=(0,i.bitMask)(q);function qe(Y){return(0,i.aInRange)("num < 2^"+q,Y,y,Oe),g.toBytes(Y)}function ke(Y,z){return(0,i._abytes2)(Y,void 0,"message"),z?(0,i._abytes2)(H(Y),void 0,"prehashed message"):Y}function Ee(Y,z,f){if(["recovered","canonical"].some(ye=>ye in f))throw new Error("sign() legacy options not supported");const{lowS:r,prehash:s,extraEntropy:d}=l(f,D);Y=ke(Y,s);const E=Se(Y),A=K(g,z),M=[qe(A),qe(E)];if(d!=null&&d!==!1){const ye=d===!0?p(L.secretKey):d;M.push((0,i.ensureBytes)("extraEntropy",ye))}const ue=(0,i.concatBytes)(...M),de=E;function ae(ye){const pe=be(ye);if(!g.isValidNot0(pe))return;const Ve=g.inv(pe),Re=w.BASE.multiply(pe).toAffine(),Me=g.create(Re.x);if(Me===y)return;const Pt=g.create(Ve*g.create(de+Me*A));if(Pt===y)return;let hr=(Re.x===Me?0:2)|Number(Re.y&B),dr=Pt;return r&&le(Pt)&&(dr=g.neg(Pt),hr^=1),new oe(Me,dr,hr)}return{seed:ue,k2sig:ae}}function Ke(Y,z,f={}){Y=(0,i.ensureBytes)("message",Y);const{seed:r,k2sig:s}=Ee(Y,z,f);return(0,i.createHmacDrbg)(H.outputLen,g.BYTES,x)(r,s)}function He(Y){let z;const f=typeof Y=="string"||(0,i.isBytes)(Y),r=!f&&Y!==null&&typeof Y=="object"&&typeof Y.r=="bigint"&&typeof Y.s=="bigint";if(!f&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)z=new oe(Y.r,Y.s);else if(f){try{z=oe.fromBytes((0,i.ensureBytes)("sig",Y),"der")}catch(s){if(!(s instanceof e.DER.Err))throw s}if(!z)try{z=oe.fromBytes((0,i.ensureBytes)("sig",Y),"compact")}catch{return!1}}return z||!1}function Be(Y,z,f,r={}){const{lowS:s,prehash:d,format:E}=l(r,D);if(f=(0,i.ensureBytes)("publicKey",f),z=ke((0,i.ensureBytes)("message",z),d),"strict"in r)throw new Error("options.strict was renamed to lowS");const A=E===void 0?He(Y):oe.fromBytes((0,i.ensureBytes)("sig",Y),E);if(A===!1)return!1;try{const M=w.fromBytes(f);if(s&&A.hasHighS())return!1;const{r:ue,s:de}=A,ae=Se(z),ye=g.inv(de),pe=g.create(ae*ye),Ve=g.create(ue*ye),Re=w.BASE.multiplyUnsafe(pe).add(M.multiplyUnsafe(Ve));return Re.is0()?!1:g.create(Re.x)===ue}catch{return!1}}function te(Y,z,f={}){const{prehash:r}=l(f,D);return z=ke(z,r),oe.fromBytes(Y,"recovered").recoverPublicKey(z).toBytes()}return Object.freeze({keygen:G,getPublicKey:ee,getSharedSecret:ne,utils:ie,lengths:L,Point:w,sign:Ke,verify:Be,recoverPublicKey:te,Signature:oe,hash:H})}function Z(w){const{CURVE:H,curveOpts:_}=R(w),p=J(H,_);return Q(w,p)}function R(w){const H={a:w.a,b:w.b,p:w.Fp.ORDER,n:w.n,h:w.h,Gx:w.Gx,Gy:w.Gy},_=w.Fp;let p=w.allowedPrivateKeyLengths?Array.from(new Set(w.allowedPrivateKeyLengths.map(g=>Math.ceil(g/2)))):void 0;const x=(0,o.Field)(H.n,{BITS:w.nBitLength,allowedLengths:p,modFromBytes:w.wrapPrivateKey}),k={Fp:_,Fn:x,allowInfinityPoint:w.allowInfinityPoint,endo:w.endo,isTorsionFree:w.isTorsionFree,clearCofactor:w.clearCofactor,fromBytes:w.fromBytes,toBytes:w.toBytes};return{CURVE:H,curveOpts:k}}function C(w){const{CURVE:H,curveOpts:_}=R(w),p={hmac:w.hmac,randomBytes:w.randomBytes,lowS:w.lowS,bits2int:w.bits2int,bits2int_modN:w.bits2int_modN};return{CURVE:H,curveOpts:_,hash:w.hash,ecdsaOpts:p}}function j(w,H,_){function p(x){const k=w.sqr(x),g=w.mul(k,x);return w.add(w.add(g,w.mul(x,H)),_)}return p}function Q(w,H){const{Fp:_,Fn:p}=H;function x(g){return(0,i.inRange)(g,B,p.ORDER)}const k=j(_,w.a,w.b);return Object.assign({},{CURVE:w,Point:H,ProjectivePoint:H,normPrivateKeyToScalar:g=>K(p,g),weierstrassEquation:k,isWithinCurveOrder:x})}function V(w,H){const _=H.Point;return Object.assign({},H,{ProjectivePoint:_,CURVE:Object.assign({},w,(0,o.nLength)(_.Fn.ORDER,_.Fn.BITS))})}function $(w){const{CURVE:H,curveOpts:_,hash:p,ecdsaOpts:x}=C(w),k=J(H,_),g=U(k,p,x);return V(w,g)}})(Vt)),Vt}var _n;function Hr(){if(_n)return mt;_n=1,Object.defineProperty(mt,"__esModule",{value:!0}),mt.getHash=t,mt.createCurve=n;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=xn();function t(i){return{hash:i}}function n(i,c){const o=a=>(0,e.weierstrass)({...i,hash:a});return{...o(c),create:o}}return mt}var Zt={},vn;function Ur(){return vn||(vn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=h,e.expand_message_xof=l,e.hash_to_field=m,e.isogenyMap=y,e.createHasher=B;const t=at(),n=wt(),i=t.bytesToNumberBE;function c(v,T){if(a(v),a(T),v<0||v>=1<<8*T)throw new Error("invalid I2OSP input: "+v);const N=Array.from({length:T}).fill(0);for(let K=T-1;K>=0;K--)N[K]=v&255,v>>>=8;return new Uint8Array(N)}function o(v,T){const N=new Uint8Array(v.length);for(let K=0;K<v.length;K++)N[K]=v[K]^T[K];return N}function a(v){if(!Number.isSafeInteger(v))throw new Error("number expected")}function u(v){if(!(0,t.isBytes)(v)&&typeof v!="string")throw new Error("DST must be Uint8Array or string");return typeof v=="string"?(0,t.utf8ToBytes)(v):v}function h(v,T,N,K){(0,t.abytes)(v),a(N),T=u(T),T.length>255&&(T=K((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),T)));const{outputLen:J,blockLen:F}=K,b=Math.ceil(N/J);if(N>65535||b>255)throw new Error("expand_message_xmd: invalid lenInBytes");const P=(0,t.concatBytes)(T,c(T.length,1)),I=c(0,F),O=c(N,2),U=new Array(b),Z=K((0,t.concatBytes)(I,v,O,c(0,1),P));U[0]=K((0,t.concatBytes)(Z,c(1,1),P));for(let C=1;C<=b;C++){const j=[o(Z,U[C-1]),c(C+1,1),P];U[C]=K((0,t.concatBytes)(...j))}return(0,t.concatBytes)(...U).slice(0,N)}function l(v,T,N,K,J){if((0,t.abytes)(v),a(N),T=u(T),T.length>255){const F=Math.ceil(2*K/8);T=J.create({dkLen:F}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(T).digest()}if(N>65535||T.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return J.create({dkLen:N}).update(v).update(c(N,2)).update(T).update(c(T.length,1)).digest()}function m(v,T,N){(0,t._validateObject)(N,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:K,k:J,m:F,hash:b,expand:P,DST:I}=N;if(!(0,t.isHash)(N.hash))throw new Error("expected valid hash");(0,t.abytes)(v),a(T);const O=K.toString(2).length,U=Math.ceil((O+J)/8),Z=T*F*U;let R;if(P==="xmd")R=h(v,I,Z,b);else if(P==="xof")R=l(v,I,Z,J,b);else if(P==="_internal_pass")R=v;else throw new Error('expand must be "xmd" or "xof"');const C=new Array(T);for(let j=0;j<T;j++){const Q=new Array(F);for(let V=0;V<F;V++){const $=U*(V+j*F),w=R.subarray($,$+U);Q[V]=(0,n.mod)(i(w),K)}C[j]=Q}return C}function y(v,T){const N=T.map(K=>Array.from(K).reverse());return(K,J)=>{const[F,b,P,I]=N.map(Z=>Z.reduce((R,C)=>v.add(v.mul(R,K),C))),[O,U]=(0,n.FpInvertBatch)(v,[b,I],!0);return K=v.mul(F,O),J=v.mul(J,v.mul(P,U)),{x:K,y:J}}}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-");function B(v,T,N){if(typeof T!="function")throw new Error("mapToCurve() must be defined");function K(F){return v.fromAffine(T(F))}function J(F){const b=F.clearCofactor();return b.equals(v.ZERO)?v.ZERO:(b.assertValidity(),b)}return{defaults:N,hashToCurve(F,b){const P=Object.assign({},N,b),I=m(F,2,P),O=K(I[0]),U=K(I[1]);return J(O.add(U))},encodeToCurve(F,b){const P=N.encodeDST?{DST:N.encodeDST}:{},I=Object.assign({},N,P,b),O=m(F,1,I),U=K(O[0]);return J(U)},mapToCurve(F){if(!Array.isArray(F))throw new Error("expected array of bigints");for(const b of F)if(typeof b!="bigint")throw new Error("expected array of bigints");return J(K(F))},hashToScalar(F,b){const P=v.Fn.ORDER,I=Object.assign({},N,{p:P,m:1,DST:e._DST_scalar},b);return m(F,1,I)[0][0]}}}})(Zt)),Zt}var Sn;function qr(){return Sn||(Sn=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=Nr(),n=nt(),i=Hr(),c=Ur(),o=wt(),a=xn(),u=at(),h={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},m=BigInt(0),y=BigInt(1),B=BigInt(2);function v(V){const $=h.p,w=BigInt(3),H=BigInt(6),_=BigInt(11),p=BigInt(22),x=BigInt(23),k=BigInt(44),g=BigInt(88),S=V*V*V%$,q=S*S*V%$,G=(0,o.pow2)(q,w,$)*q%$,ee=(0,o.pow2)(G,w,$)*q%$,ne=(0,o.pow2)(ee,B,$)*S%$,ie=(0,o.pow2)(ne,_,$)*ne%$,L=(0,o.pow2)(ie,p,$)*ie%$,D=(0,o.pow2)(L,k,$)*L%$,re=(0,o.pow2)(D,g,$)*D%$,le=(0,o.pow2)(re,k,$)*L%$,ce=(0,o.pow2)(le,w,$)*q%$,W=(0,o.pow2)(ce,x,$)*ie%$,oe=(0,o.pow2)(W,H,$)*S%$,be=(0,o.pow2)(oe,B,$);if(!T.eql(T.sqr(be),V))throw new Error("Cannot find square root");return be}const T=(0,o.Field)(h.p,{sqrt:v});e.secp256k1=(0,i.createCurve)({...h,Fp:T,lowS:!0,endo:l},t.sha256);const N={};function K(V,...$){let w=N[V];if(w===void 0){const H=(0,t.sha256)((0,u.utf8ToBytes)(V));w=(0,u.concatBytes)(H,H),N[V]=w}return(0,t.sha256)((0,u.concatBytes)(w,...$))}const J=V=>V.toBytes(!0).slice(1),F=e.secp256k1.Point,b=V=>V%B===m;function P(V){const{Fn:$,BASE:w}=F,H=(0,a._normFnElement)($,V),_=w.multiply(H);return{scalar:b(_.y)?H:$.neg(H),bytes:J(_)}}function I(V){const $=T;if(!$.isValidNot0(V))throw new Error("invalid x: Fail if x ≥ p");const w=$.create(V*V),H=$.create(w*V+BigInt(7));let _=$.sqrt(H);b(_)||(_=$.neg(_));const p=F.fromAffine({x:V,y:_});return p.assertValidity(),p}const O=u.bytesToNumberBE;function U(...V){return F.Fn.create(O(K("BIP0340/challenge",...V)))}function Z(V){return P(V).bytes}function R(V,$,w=(0,n.randomBytes)(32)){const{Fn:H}=F,_=(0,u.ensureBytes)("message",V),{bytes:p,scalar:x}=P($),k=(0,u.ensureBytes)("auxRand",w,32),g=H.toBytes(x^O(K("BIP0340/aux",k))),S=K("BIP0340/nonce",g,p,_),{bytes:q,scalar:G}=P(S),ee=U(q,p,_),ne=new Uint8Array(64);if(ne.set(q,0),ne.set(H.toBytes(H.create(G+ee*x)),32),!C(ne,_,p))throw new Error("sign: Invalid signature produced");return ne}function C(V,$,w){const{Fn:H,BASE:_}=F,p=(0,u.ensureBytes)("signature",V,64),x=(0,u.ensureBytes)("message",$),k=(0,u.ensureBytes)("publicKey",w,32);try{const g=I(O(k)),S=O(p.subarray(0,32));if(!(0,u.inRange)(S,y,h.p))return!1;const q=O(p.subarray(32,64));if(!(0,u.inRange)(q,y,h.n))return!1;const G=U(H.toBytes(S),J(g),x),ee=_.multiplyUnsafe(q).add(g.multiplyUnsafe(H.neg(G))),{x:ne,y:ie}=ee.toAffine();return!(ee.is0()||!b(ie)||ne!==S)}catch{return!1}}e.schnorr=(()=>{const w=(_=(0,n.randomBytes)(48))=>(0,o.mapHashToField)(_,h.n);e.secp256k1.utils.randomSecretKey;function H(_){const p=w(_);return{secretKey:p,publicKey:Z(p)}}return{keygen:H,getPublicKey:Z,sign:R,verify:C,Point:F,utils:{randomSecretKey:w,randomPrivateKey:w,taggedHash:K,lift_x:I,pointToBytes:J,numberToBytesBE:u.numberToBytesBE,bytesToNumberBE:u.bytesToNumberBE,mod:o.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const j=(0,c.isogenyMap)(T,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(V=>V.map($=>BigInt($)))),Q=(0,a.mapToCurveSimpleSWU)(T,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:T.create(BigInt("-11"))});e.secp256k1_hasher=(0,c.createHasher)(e.secp256k1.Point,V=>{const{x:$,y:w}=Q(T.create(V[0]));return j($,w)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:T.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve})(Mt)),Mt}var se={},An;function Pr(){if(An)return se;An=1,Object.defineProperty(se,"__esModule",{value:!0}),se.isHash=se.validateObject=se.memoized=se.notImplemented=se.createHmacDrbg=se.bitMask=se.bitSet=se.bitGet=se.bitLen=se.aInRange=se.inRange=se.asciiToBytes=se.copyBytes=se.equalBytes=se.ensureBytes=se.numberToVarBytesBE=se.numberToBytesLE=se.numberToBytesBE=se.bytesToNumberLE=se.bytesToNumberBE=se.hexToNumber=se.numberToHexUnpadded=se.abool=se.utf8ToBytes=se.randomBytes=se.isBytes=se.hexToBytes=se.concatBytes=se.bytesToUtf8=se.bytesToHex=se.anumber=se.abytes=void 0;const e=at();return se.abytes=e.abytes,se.anumber=e.anumber,se.bytesToHex=e.bytesToHex,se.bytesToUtf8=e.bytesToUtf8,se.concatBytes=e.concatBytes,se.hexToBytes=e.hexToBytes,se.isBytes=e.isBytes,se.randomBytes=e.randomBytes,se.utf8ToBytes=e.utf8ToBytes,se.abool=e.abool,se.numberToHexUnpadded=e.numberToHexUnpadded,se.hexToNumber=e.hexToNumber,se.bytesToNumberBE=e.bytesToNumberBE,se.bytesToNumberLE=e.bytesToNumberLE,se.numberToBytesBE=e.numberToBytesBE,se.numberToBytesLE=e.numberToBytesLE,se.numberToVarBytesBE=e.numberToVarBytesBE,se.ensureBytes=e.ensureBytes,se.equalBytes=e.equalBytes,se.copyBytes=e.copyBytes,se.asciiToBytes=e.asciiToBytes,se.inRange=e.inRange,se.aInRange=e.aInRange,se.bitLen=e.bitLen,se.bitGet=e.bitGet,se.bitSet=e.bitSet,se.bitMask=e.bitMask,se.createHmacDrbg=e.createHmacDrbg,se.notImplemented=e.notImplemented,se.memoized=e.memoized,se.validateObject=e.validateObject,se.isHash=e.isHash,se}var Tn;function Cr(){if(Tn)return Ne;Tn=1;var e=qr(),t=wt(),n=Pr();function i(r){var s=Object.create(null);return r&&Object.keys(r).forEach(function(d){if(d!=="default"){var E=Object.getOwnPropertyDescriptor(r,d);Object.defineProperty(s,d,E.get?E:{enumerable:!0,get:function(){return r[d]}})}}),s.default=r,Object.freeze(s)}var c=i(t),o=i(n);const a=e.secp256k1.ProjectivePoint,u="Expected Private",h="Expected Point",l="Expected Tweak",m="Expected Hash",y="Expected Signature",B="Expected Extra Data (32 bytes)",v="Expected Scalar",T="Bad Recovery Id",N=32,K=32,J=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]),F=32,b=new Uint8Array(32),P=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]),I=BigInt(1);function O(r){return r instanceof Uint8Array}function U(r,s){for(let d=0;d<32;++d)if(r[d]!==s[d])return r[d]<s[d]?-1:1;return 0}function Z(r){return U(r,b)===0}function R(r){return!(!(r instanceof Uint8Array)||r.length!==K||U(r,J)>=0)}function C(r){return r instanceof Uint8Array&&r.length===64&&U(r.subarray(0,32),J)<0&&U(r.subarray(32,64),J)<0}function j(r){return O(r)&&r.length===64&&U(r.subarray(0,32),P)<0}function Q(r){return!(Z(r.subarray(0,32))||Z(r.subarray(32,64)))}function V(r){return r instanceof Uint8Array&&r.length===N}function $(r){return r===void 0||r instanceof Uint8Array&&r.length===F}function w(r){let s;if(typeof r=="bigint")s=r;else if(typeof r=="number"&&Number.isSafeInteger(r)&&r>=0)s=BigInt(r);else if(typeof r=="string"){if(r.length!==64)throw new Error("Expected 32 bytes of private scalar");s=o.hexToNumber(r)}else if(r instanceof Uint8Array){if(r.length!==32)throw new Error("Expected 32 bytes of private scalar");s=o.bytesToNumberBE(r)}else throw new TypeError("Expected valid private scalar");if(s<0)throw new Error("Expected private scalar >= 0");return s}function H(r){return e.secp256k1.utils.normPrivateKeyToScalar(r)}function _(r,s){const d=H(r),E=w(s),A=o.numberToBytesBE(c.mod(d+E,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(A)?A:null}function p(r,s){const d=H(r),E=w(s),A=o.numberToBytesBE(c.mod(d-E,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(A)?A:null}function x(r){const s=H(r),d=o.numberToBytesBE(e.secp256k1.CURVE.n-s,32);return e.secp256k1.utils.isValidPrivateKey(d)?d:null}function k(r,s,d){const E=ee(r),A=w(s),M=a.BASE.multiplyAndAddUnsafe(E,A,I);if(!M)throw new Error("Tweaked point at infinity");return M.toRawBytes(d)}function g(r,s,d){const E=ee(r),A=typeof s=="string"?s:o.bytesToHex(s),M=o.hexToNumber(A);return E.multiply(M).toRawBytes(d)}function S(r,s){return r===void 0?s!==void 0?L(s):!0:!!r}function q(r){try{return r()}catch{return null}}function G(r){return e.schnorr.utils.lift_x(o.bytesToNumberBE(r))}function ee(r){return r.length===32?G(r):a.fromHex(r)}function ne(r,s){if(r.length===32!==s)return!1;try{return s?!!G(r):!!a.fromHex(r)}catch{return!1}}function ie(r){return ne(r,!1)}function L(r){return ne(r,!1)&&r.length===33}function D(r){return e.secp256k1.utils.isValidPrivateKey(r)}function re(r){return ne(r,!0)}function le(r,s){if(!re(r))throw new Error(h);if(!R(s))throw new Error(l);return q(()=>{const d=k(r,s,!0);return{parity:d[0]%2===1?1:0,xOnlyPubkey:d.slice(1)}})}function ce(r){if(!ie(r))throw new Error(h);return r.slice(1,33)}function W(r,s){if(!D(r))throw new Error(u);return q(()=>e.secp256k1.getPublicKey(r,S(s)))}function oe(r){if(!D(r))throw new Error(u);return ce(W(r))}function be(r,s){if(!ie(r))throw new Error(h);return ee(r).toRawBytes(S(s,r))}function Se(r,s,d){if(!ie(r))throw new Error(h);if(!R(s))throw new Error(l);return q(()=>g(r,s,S(d,r)))}function Oe(r,s,d){if(!ie(r)||!ie(s))throw new Error(h);return q(()=>{const E=ee(r),A=ee(s);return E.equals(A.negate())?null:E.add(A).toRawBytes(S(d,r))})}function qe(r,s,d){if(!ie(r))throw new Error(h);if(!R(s))throw new Error(l);return q(()=>k(r,s,S(d,r)))}function ke(r,s){if(!D(r))throw new Error(u);if(!R(s))throw new Error(l);return q(()=>_(r,s))}function Ee(r,s){if(!D(r))throw new Error(u);if(!R(s))throw new Error(l);return q(()=>p(r,s))}function Ke(r){if(!D(r))throw new Error(u);return x(r)}function He(r,s,d){if(!D(s))throw new Error(u);if(!V(r))throw new Error(v);if(!$(d))throw new Error(B);return e.secp256k1.sign(r,s,{extraEntropy:d}).toCompactRawBytes()}function Be(r,s,d){if(!D(s))throw new Error(u);if(!V(r))throw new Error(v);if(!$(d))throw new Error(B);const E=e.secp256k1.sign(r,s,{extraEntropy:d});return{signature:E.toCompactRawBytes(),recoveryId:E.recovery}}function te(r,s,d){if(!D(s))throw new Error(u);if(!V(r))throw new Error(v);if(!$(d))throw new Error(B);return e.schnorr.sign(r,s,d)}function Y(r,s,d,E){if(!V(r))throw new Error(m);if(!C(s)||!Q(s))throw new Error(y);if(d&2&&!j(s))throw new Error(T);if(!re(s.subarray(0,32)))throw new Error(y);const M=e.secp256k1.Signature.fromCompact(s).addRecoveryBit(d).recoverPublicKey(r);if(!M)throw new Error(y);return M.toRawBytes(S(E))}function z(r,s,d,E){if(!ie(s))throw new Error(h);if(!C(d))throw new Error(y);if(!V(r))throw new Error(v);return e.secp256k1.verify(d,r,s,{lowS:E})}function f(r,s,d){if(!re(s))throw new Error(h);if(!C(d))throw new Error(y);if(!V(r))throw new Error(v);return e.schnorr.verify(d,r,s)}return Ne.isPoint=ie,Ne.isPointCompressed=L,Ne.isPrivate=D,Ne.isXOnlyPoint=re,Ne.pointAdd=Oe,Ne.pointAddScalar=qe,Ne.pointCompress=be,Ne.pointFromScalar=W,Ne.pointMultiply=Se,Ne.privateAdd=ke,Ne.privateNegate=Ke,Ne.privateSub=Ee,Ne.recover=Y,Ne.sign=He,Ne.signRecoverable=Be,Ne.signSchnorr=te,Ne.verify=z,Ne.verifySchnorr=f,Ne.xOnlyPointAddTweak=le,Ne.xOnlyPointFromPoint=ce,Ne.xOnlyPointFromScalar=oe,Ne}var Nn=Cr();const Ir=wr({__proto__:null,default:cn(Nn)},[Nn]);tt.initEccLib(Ir);const yt={Mainnet:"mainnet",Testnet:"testnet"};class kr{axios;constructor(t){this.axios=pr.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(c=>c.data)}async inscriptionsByAddress(t,n){return await this.axios.get(`/addresses/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(c=>c.data)}async inscriptionIdsByCollectionSymbol(t,n){return await this.axios.get(`/assets/collections/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(c=>c.data)}async runeUtxosByAddress(t,n,i){return await this.axios.get(`/addresses/${t}/runes/utxos?order_by=height&order=asc&count=100&rune=${n}${i?`&cursor=${i}`:""}`).then(o=>o.data)}}var rt={},_e={},it={},Rn;function Mr(){if(Rn)return it;Rn=1,Object.defineProperty(it,"__esModule",{value:!0}),it.base26Decode=it.base26Encode=void 0;function e(n){let i=0n;for(let c=0;c<n.length;c++){const o=BigInt(n.charCodeAt(c)-65),a=BigInt(n.length)-1n-BigInt(c);if(a==0n)i+=o;else{const u=26n**a;i+=u*(o+1n)}}return i}it.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let i=[];for(;n>0;){const c=(n-1n)%26n;i.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(c))),n=(n-1n)/26n}return i.reverse().join("")}return it.base26Decode=t,it}var ot={},On;function Hn(){if(On)return ot;On=1,Object.defineProperty(ot,"__esModule",{value:!0}),ot.none=ot.some=void 0;class e{constructor(){}isSome(){return!1}map(o){return new e}value(){return null}}class t{constructor(o){this._value=o}isSome(){return!0}map(o){return new t(o(this.value()))}value(){return this._value}}function n(c){return new t(c)}ot.some=n;function i(){return new e}return ot.none=i,ot}var st={},Un;function Fr(){if(Un)return st;Un=1,Object.defineProperty(st,"__esModule",{value:!0}),st.decodeLEB128=st.encodeLEB128=void 0;function e(n){const i=[];let c=!0;for(;c;){let o=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?c=!1:o|=128,i.push(o)}return i}st.encodeLEB128=e;function t(n){let i=BigInt(0);for(let c=0;c<n.length;c++){const o=BigInt(n[c]);if(c>18)throw new Error("Overlong");let a=o&BigInt(127);if(c==18&&(a&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(i|=a<<BigInt(7)*BigInt(c),(o&BigInt(128))==BigInt(0))return{n:i,len:c+1}}throw new Error("Unterminated")}return st.decodeLEB128=t,st}var Kt={},qn;function Vr(){return qn||(qn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=o=>o.length%2===1?"0"+o:o;e.zero2=t;const n=o=>{let a="";for(let u=0;u<o.length;u++)a+=(0,e.zero2)(o[u].toString(16));return a};e.toHex=n;function i(o,a){const u=[];let h=0;for(;h<o.length;){const l=o.slice(h,h+a);u.push(l),h+=a}return u}e.chunks=i;function c(o){const a=[],u=o.length;if(u<76){const h=Buffer.alloc(1);h.writeUInt8(u),a.push(h)}else if(u<=255){a.push(Buffer.from("4c","hex"));const h=Buffer.alloc(1);h.writeUInt8(u),a.push(h)}else if(u<=65535){a.push(Buffer.from("4d","hex"));const h=Buffer.alloc(2);h.writeUint16LE(u),a.push(h)}else{a.push(Buffer.from("4e","hex"));const h=Buffer.alloc(4);h.writeUint32LE(u),a.push(h)}return a.push(o),Buffer.concat(a)}e.toPushData=c})(Kt)),Kt}var Xe={},Pn;function Cn(){if(Pn)return Xe;Pn=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.removeSpacers=Xe.getSpacersVal=Xe.applySpacers=void 0;function e(i,c){let o="";for(let a=0;a<i.length;a++)o+=i.charAt(a),c>0&&((c&1)===1&&(o+="•"),c>>=1);return o}Xe.applySpacers=e;function t(i){let c=0,o=0;for(let a=0;a<i.length;a++)i.charAt(a)==="•"&&(c+=1<<a-1-o,o++);return c}Xe.getSpacersVal=t;function n(i){return i.replace(/[•]+/g,"")}return Xe.removeSpacers=n,Xe}var In;function jr(){if(In)return _e;In=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=tt,t=Mr(),n=Hn(),i=Fr(),c=Vr(),o=Cn();class a{constructor(b,P){this.block=b,this.idx=P}next(b,P){if(b>BigInt(Number.MAX_SAFE_INTEGER)||P>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let I=BigInt(this.block)+b;if(I>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let O=b===0n?BigInt(this.idx)+P:P;return O>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new a(Number(I),Number(O)))}}_e.RuneId=a;class u{constructor(b,P,I){this.id=b,this.amount=P,this.output=I}static from_integers(b,P,I,O){return O>4294967295n||O<0n||Number(O)>b.outs.length?(0,n.none)():(0,n.some)(new u(P,I,Number(O)))}}_e.Edict=u;var h;(function(F){F[F.Etching=0]="Etching",F[F.Terms=1]="Terms",F[F.Turbo=2]="Turbo",F[F.Cenotaph=127]="Cenotaph"})(h||(_e.Flag=h={}));var l;(function(F){F[F.Body=0]="Body",F[F.Flags=2]="Flags",F[F.Rune=4]="Rune",F[F.Premine=6]="Premine",F[F.Cap=8]="Cap",F[F.Amount=10]="Amount",F[F.HeightStart=12]="HeightStart",F[F.HeightEnd=14]="HeightEnd",F[F.OffsetStart=16]="OffsetStart",F[F.OffsetEnd=18]="OffsetEnd",F[F.Mint=20]="Mint",F[F.Pointer=22]="Pointer",F[F.Cenotaph=126]="Cenotaph",F[F.Divisibility=1]="Divisibility",F[F.Spacers=3]="Spacers",F[F.Symbol=5]="Symbol",F[F.Nop=127]="Nop"})(l||(_e.Tag=l={}));var m;(function(F){F[F.EdictOutput=0]="EdictOutput",F[F.EdictRuneId=1]="EdictRuneId",F[F.InvalidScript=2]="InvalidScript",F[F.Opcode=3]="Opcode",F[F.SupplyOverflow=4]="SupplyOverflow",F[F.TrailingIntegers=5]="TrailingIntegers",F[F.TruncatedField=6]="TruncatedField",F[F.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",F[F.UnrecognizedFlag=8]="UnrecognizedFlag",F[F.Varint=9]="Varint"})(m||(_e.Flaw=m={}));class y{constructor(b,P){this.start=b,this.end=P}}_e.Range=y;class B{constructor(b,P,I,O){this.amount=b,this.cap=P,this.height=I,this.offset=O}}_e.Terms=B;class v{constructor(b){this.value=b}get name(){return v.toName(this.value)}static toName(b){return(0,t.base26Decode)(b)}static fromName(b){return new v((0,t.base26Encode)((0,o.removeSpacers)(b)))}toString(){return this.name}}_e.Rune=v;class T{constructor(b,P,I,O,U,Z,R){this.divisibility=b,this.premine=P,this.rune=I,this.spacers=O,this.symbol=U,this.terms=Z,this.turbo=R}}_e.Etching=T,T.MAX_DIVISIBILITY=38,T.MAX_SPACERS=134217727;class N{constructor(b=[],P,I,O){this.edicts=b,this.etching=P,this.mint=I,this.pointer=O}static create(b,P="etch"){if(P==="etch"){b=b;const I=v.fromName(b.name),O=new B(b.amount,b.cap,new y(b.startHeight?(0,n.some)(b.startHeight):(0,n.none)(),b.endHeight?(0,n.some)(b.endHeight):(0,n.none)()),new y(b.startOffset?(0,n.some)(b.startOffset):(0,n.none)(),b.endOffset?(0,n.some)(b.endOffset):(0,n.none)())),U=b.divisibility?(0,n.some)(b.divisibility):(0,n.none)(),Z=b.premine?(0,n.some)(b.premine):(0,n.none)(),R=b.name.indexOf("•")>-1?(0,n.some)((0,o.getSpacersVal)(b.name)):(0,n.none)(),C=b.symbol?(0,n.some)(b.symbol):(0,n.none)(),j=typeof b.pointer=="number"?(0,n.some)(b.pointer):(0,n.none)(),Q=new T(U,Z,(0,n.some)(I),R,C,(0,n.some)(O),!0);return new N([],(0,n.some)(Q),(0,n.none)(),j)}else if(P==="mint"){b=b;const I=typeof b.pointer=="number"?(0,n.some)(b.pointer):(0,n.none)();return new N([],(0,n.none)(),(0,n.some)(new a(b.block,b.txIdx)),I)}else throw new Error(`not ${P} support now`)}static decipher(b){const P=e.Transaction.fromHex(b),I=N.payload(P);if(I.isSome()){const O=N.integers(I.value()),U=K.from_integers(P,O.value()),Z=U.getEtching(),R=U.getMint(),C=U.getPointer();return(0,n.some)(new N(U.edicts,Z,R,C))}return(0,n.none)()}encipher(){const P=this.toMessage().toBuffer(),I=Buffer.from("6a5d","hex");let O;if(P.length<76)O=Buffer.alloc(1),O.writeUint8(P.length);else if(P.length<256)O=Buffer.alloc(2),O.writeUint8(76),O.writeUint8(P.length);else if(P.length<65536)O=Buffer.alloc(3),O.writeUint8(77),O.writeUint16LE(P.length);else if(P.length<4294967296)O=Buffer.alloc(5),O.writeUint8(78),O.writeUint32LE(P.length);else throw new Error("runestone too big!");return Buffer.concat([I,O,P])}static payload(b){for(const P of b.outs){const I=e.script.decompile(P.script);if(I[0]===e.script.OPS.OP_RETURN&&I[1]===N.MAGIC_NUMBER){for(let O=2;O<I.length;O++){const U=I[O];return U instanceof Uint8Array?(0,n.some)(Array.from(U)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(b){let P=[],I=0;for(;I<b.length;){let{n:O,len:U}=(0,i.decodeLEB128)(b.slice(I));P.push(O),I+=U}return(0,n.some)(P)}toMessage(){let b=new Map;const P=this.etching.value();if(P){let U=1;if(P.terms.isSome()){let $=1<<h.Terms;U|=$}if(P.turbo){let $=1<<h.Turbo;U|=$}b.set(l.Flags,[BigInt(U)]);const Z=P.rune.value();Z!==null&&b.set(l.Rune,[BigInt(Z.value)]);const R=P.divisibility.value();R!==null&&b.set(l.Divisibility,[BigInt(R)]);const C=P.spacers.value();C!==null&&b.set(l.Spacers,[BigInt(C)]);const j=P.symbol.value();j!==null&&b.set(l.Symbol,[BigInt(j.charCodeAt(0))]);const Q=P.premine.value();Q!==null&&b.set(l.Premine,[BigInt(Q)]);const V=P.terms.value();if(V!==null){b.set(l.Amount,[BigInt(V.amount)]),b.set(l.Cap,[BigInt(V.cap)]);const $=V.height.start.value();$&&b.set(l.HeightStart,[BigInt($)]);const w=V.height.end.value();w&&b.set(l.HeightEnd,[BigInt(w)]);const H=V.offset.start.value();H&&b.set(l.OffsetStart,[BigInt(H)]);const _=V.offset.end.value();_&&b.set(l.OffsetEnd,[BigInt(_)])}}const I=this.mint.value();I!==null&&b.set(l.Mint,[BigInt(I.block),BigInt(I.idx)]);const O=this.pointer.value();return O!==null&&b.set(l.Pointer,[BigInt(O)]),new K(b,this.edicts,0)}}_e.Runestone=N,N.MAGIC_NUMBER=93;class K{constructor(b=new Map,P=[],I=0){this.fields=b,this.edicts=P,this.flaws=I}static from_integers(b,P){let I=new Map,O=[],U=0,Z=!1;for(let R=0;R<P.length;){let C=P[R];if(Number(C)===l.Body){Z=!0,R+=1;continue}if(Z){let j=new a(0,0);for(const Q of(0,c.chunks)(P.slice(R),4)){if(Q.length!=4){U|=m.TrailingIntegers;break}let V=j.next(Q[0],Q[1]);if(!V.isSome()){U|=m.EdictRuneId;break}const $=u.from_integers(b,V.value(),Q[2],Q[3]);if(!$.isSome()){U|=m.EdictOutput;break}j=V.value(),O.push($.value())}R+=4}else{let j=P[R+1];const Q=I.get(Number(C))||[];Q.push(j),I.set(Number(C),Q),R+=2}}return new K(I,O,U)}addFieldVal(b,P){const I=this.fields.get(Number(b))||[];I.push(P),this.fields.set(Number(b),I)}addEdict(b){this.edicts.push(b)}toBuffer(){const b=[];for(const[P,I]of this.fields)for(const O of I){const U=Buffer.alloc(1);U.writeUInt8(P),b.push(U),b.push(Buffer.from((0,i.encodeLEB128)(O)))}if(this.edicts.length>0){b.push(Buffer.from("00","hex")),this.edicts.sort((O,U)=>O.id.block==U.id.block?O.id.idx-U.id.idx:O.id.block-U.id.block);let P=0n,I=0n;for(let O=0;O<this.edicts.length;O++){const U=this.edicts[O];if(O==0)P=BigInt(U.id.block),I=BigInt(U.id.idx),b.push(Buffer.from((0,i.encodeLEB128)(P))),b.push(Buffer.from((0,i.encodeLEB128)(I)));else{const Z=BigInt(U.id.block),R=BigInt(U.id.idx);if(Z==P){const C=R-I;I=R,b.push(Buffer.from((0,i.encodeLEB128)(0n))),b.push(Buffer.from((0,i.encodeLEB128)(C)))}else{const C=Z-P;P=Z,I=R,b.push(Buffer.from((0,i.encodeLEB128)(C))),b.push(Buffer.from((0,i.encodeLEB128)(R)))}}b.push(Buffer.from((0,i.encodeLEB128)(BigInt(U.amount)))),b.push(Buffer.from((0,i.encodeLEB128)(BigInt(U.output))))}}return Buffer.concat(b)}getFlags(){return Number(this.fields.get(l.Flags))}hasFlags(b){const P=this.getFlags(),I=1<<b;return(P&I)!=0}getMint(){if(!this.fields.has(l.Mint))return(0,n.none)();const[b,P]=this.fields.get(l.Mint);return(0,n.some)(new a(Number(b),Number(P)))}getEtching(){if(!this.hasFlags(h.Etching))return(0,n.none)();const b=this.getDivisibility(),P=this.getPremine(),I=this.getRune(),O=this.getSpacers(),U=this.getSymbol(),Z=this.getTerms(),R=this.hasFlags(h.Turbo);return(0,n.some)(new T(b,P,I,O,U,Z,R))}getDivisibility(){if(!this.fields.has(l.Divisibility))return(0,n.none)();const[b]=this.fields.get(l.Divisibility);if(b>T.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(b))}getPremine(){if(!this.fields.has(l.Premine))return(0,n.none)();const[b]=this.fields.get(l.Premine);return(0,n.some)(Number(b))}getRune(){if(!this.fields.has(l.Rune))return(0,n.none)();const[b]=this.fields.get(l.Rune);return(0,n.some)(new v(b))}getSpacers(){if(!this.fields.has(l.Spacers))return(0,n.none)();const[b]=this.fields.get(l.Spacers);if(b>T.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(b))}getHeightStart(){if(!this.fields.has(l.HeightStart))return(0,n.none)();const[b]=this.fields.get(l.HeightStart);return(0,n.some)(Number(b))}getHeightEnd(){if(!this.fields.has(l.HeightEnd))return(0,n.none)();const[b]=this.fields.get(l.HeightEnd);return(0,n.some)(Number(b))}getOffsetStart(){if(!this.fields.has(l.OffsetStart))return(0,n.none)();const[b]=this.fields.get(l.OffsetStart);return(0,n.some)(Number(b))}getOffsetEnd(){if(!this.fields.has(l.OffsetEnd))return(0,n.none)();const[b]=this.fields.get(l.OffsetEnd);return(0,n.some)(Number(b))}getCap(){if(!this.fields.has(l.Cap))return(0,n.none)();const[b]=this.fields.get(l.Cap);return(0,n.some)(Number(b))}getAmount(){if(!this.fields.has(l.Amount))return(0,n.none)();const[b]=this.fields.get(l.Amount);return(0,n.some)(Number(b))}getSymbol(){if(!this.fields.has(l.Symbol))return(0,n.none)();const[b]=this.fields.get(l.Symbol);return(0,n.some)(String.fromCharCode(Number(b)))}getTerms(){if(!this.hasFlags(h.Terms))return(0,n.none)();const b=this.getCap();if(!b.isSome())throw new Error("no cap field");const P=this.getAmount();if(!P.isSome())throw new Error("no amount field");const I=this.getHeightStart(),O=this.getHeightEnd(),U=this.getOffsetStart(),Z=this.getOffsetEnd(),R=new y(I,O),C=new y(U,Z);return(0,n.some)(new B(P.value(),b.value(),R,C))}getPointer(){if(!this.fields.has(l.Pointer))return(0,n.none)();const[b]=this.fields.get(l.Pointer);return(0,n.some)(Number(b))}}_e.Message=K;class J{constructor(b=new Map,P=Buffer.alloc(0)){this.fields=b,this.data=P}setContent(b,P){this.fields.set(1,Buffer.from(b,"utf8")),this.data=P}setRune(b){let I=(0,t.base26Encode)((0,o.removeSpacers)(b)).toString(16);I.length%2===1&&(I="0"+I),this.setField(J.Tag.RUNE,Buffer.from(I,"hex").reverse())}setField(b,P){this.fields.set(b,P)}static decipher(b,P){const U=e.Transaction.fromHex(b).ins[P].witness[1],Z=e.script.decompile(U),R=new Map,C=[];let j=!1;for(let Q=5;Q<Z.length-1;){const V=Z[Q];if(V===0){j=!0,Q++;continue}else if(j)C.push(V),Q++;else{const $=V-80,w=Z[Q+1];if(typeof w=="number"){const H=Buffer.alloc(1);H.writeUint8(w),R.set($,H)}else R.set($,w);Q+=2}}return new J(R,Buffer.concat(C))}encipher(){const b=[];if(this.data&&this.data.length>0){b.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((I,O)=>I[0]-O[0]).forEach(([I,O])=>{const U=Buffer.alloc(1);U.writeUInt8(I),b.push(Buffer.from("01","hex")),b.push(U),O.length!=1||O[0]!=0?b.push((0,c.toPushData)(O)):b.push(O)}),b.push(Buffer.from("00","hex"));const P=(0,c.chunks)(Array.from(this.data),520);for(const I of P)b.push((0,c.toPushData)(Buffer.from(I)))}else{b.push(Buffer.from("0063","hex"));const P=this.fields.get(J.Tag.RUNE);if(!P)throw new Error("No rune found!");b.push((0,c.toPushData)(P))}return b.push(Buffer.from("68","hex")),Buffer.concat(b)}}return _e.EtchInscription=J,J.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},_e}var kn;function $r(){return kn||(kn=1,(function(e){var t=rt&&rt.__createBinding||(Object.create?(function(o,a,u,h){h===void 0&&(h=u);var l=Object.getOwnPropertyDescriptor(a,u);(!l||("get"in l?!a.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(o,h,l)}):(function(o,a,u,h){h===void 0&&(h=u),o[h]=a[u]})),n=rt&&rt.__exportStar||function(o,a){for(var u in o)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,o,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(jr(),e);var i=Hn();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return i.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return i.some}});var c=Cn();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return c.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return c.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return c.removeSpacers}})})(rt)),rt}var ct=$r();function Zr(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 Gt(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Wt(e){return e===yt.Mainnet?ze.networks.bitcoin:ze.networks.testnet}const $e={P2PKH:{P2PKH:null},P2SH_P2WPKH:{P2SH_P2WPKH:null},P2WPKH:{P2WPKH:null},P2WSH:{P2WSH:null},P2SH:{P2SH:null},P2TR:{P2TR:null},UNKNOWN:{UNKNOWN:null}};function zt(e,t=yt.Testnet){const n=Wt(t);return ze.address.toOutputScript(e,n)}function bt(e){const t=ze.networks.bitcoin,n=ze.networks.testnet,i=ze.networks.regtest;let c,o,a=$e.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return o=ze.address.fromBech32(e),o.version===0?o.data.length===20?a=$e.P2WPKH:a=$e.P2WSH:a=$e.P2TR,a}catch{return $e.UNKNOWN}else try{return c=ze.address.fromBase58Check(e),c.version===t.pubKeyHash||c.version===n.pubKeyHash||c.version===i.pubKeyHash?a=$e.P2PKH:(c.version===t.scriptHash||(c.version,n.scriptHash),a=$e.P2SH_P2WPKH),a}catch{return $e.UNKNOWN}}const Kr=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:Gt,getAddressType:bt,getScriptByAddress:zt,hexToBytes:Zr,toBitcoinNetwork:Wt},Symbol.toStringTag,{value:"Module"})),Gr="kqs64-paaaa-aaaar-qamza-cai",Wr="hvyp5-5yaaa-aaaao-qjxha-cai",_t=BigInt(546),vt="0:0",zr="https://runescan-hasura-mainnet.omnity.network/v1/graphql",Xr="https://runescan-hasura-testnet.omnity.network/v1/graphql";class Mn{psbt;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);orchestrator;intentions=[];txFee=BigInt(0);additionalDustNeeded=BigInt(0);inputUtxos=[];constructor(t,n){this.config=t,this.psbt=new ze.Psbt({network:Wt(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(bt(n)),this.inputUtxos.push(t),(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(bt(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:0}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,i){const c=[];if(i==BigInt(0))return c;for(const o of t)if(o.runes.length){const a=o.runes.find(u=>u.id==n);if(a&&BigInt(a.amount)==i){c.push(o);break}}if(c.length==0){let o=BigInt(0);for(const a of t)if(a.runes.forEach(u=>{u.id==n&&(o=o+BigInt(u.amount))}),c.push(a),o>=i)break;if(o<i)throw new Error("INSUFFICIENT_RUNE_UTXOs")}return c}selectBtcUtxos(t,n){const i=[];if(n<=BigInt(0))return i;let c=BigInt(0);for(const o of t)if(!o.runes.length&&(c+=BigInt(o.satoshis),i.push(o),c>=n))break;if(c<n)throw new Error(`Insufficient BTC UTXOs: need ${n}, have ${c}`);return i}async addBtcAndFees(t,n){const i=this.config.paymentAddress,c=this.additionalDustNeeded;this.outputAddressTypes.push(bt(i));let o=BigInt(0),a=BigInt(0),u=[],h=BigInt(0),l=BigInt(0);const m=[...this.inputAddressTypes];do if(o=a,a=(await this.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes,pool_address:this.intentions.map(T=>T.poolAddress),output_types:this.outputAddressTypes})).Ok,h=n+a+c-this.userInputUtxoDusts,a>o&&h>0){const T=this.selectBtcUtxos(t,h);if(T.length===0)throw new Error("INSUFFICIENT_BTC_UTXOs");this.inputAddressTypes=m.concat([...T.map(()=>bt(i))]);const N=T.reduce((K,J)=>K+BigInt(J.satoshis),BigInt(0));N-h>0&&N-h>_t||this.outputAddressTypes.pop(),u=T}while(a>o&&h>0);let y=BigInt(0);u.forEach(v=>{this.addInput(v),y+=BigInt(v.satoshis)});const B=y-h;if(B<0)throw new Error("Insufficient UTXO(s)");B>_t?this.psbt.addOutput({address:i,value:Number(B)}):B>BigInt(0)&&(l=B),this.txFee=l+a}addInputAndCalculateOutputs(){if(!this.intentions.length)throw new Error("No intentions added");const t={},n={};let i=BigInt(0);const c={},o={},a=new Set;return this.intentions.forEach(h=>{a.add(h.poolAddress)}),a.forEach(h=>{(this.config.involvedPoolUtxos[h]??[]).forEach(m=>{t[h]=(t[h]??BigInt(0))+BigInt(m.satoshis),m.runes.forEach(y=>{n[h]??={},n[h][y.id]=(n[h][y.id]??BigInt(0))+BigInt(y.amount)}),this.addInput(m)})}),this.intentions.forEach(h=>{const l=h.poolAddress;h.inputCoins.forEach(m=>{if(m.id===vt){i-=BigInt(m.value),t[l]+=BigInt(m.value);return}c[m.id]=(c[m.id]??BigInt(0))+BigInt(m.value),n[l]??={},n[l][m.id]=(n[l][m.id]??BigInt(0))+BigInt(m.value)}),h.outputCoins.forEach(m=>{if(m.id===vt){i+=BigInt(m.value);const v=t[l]-BigInt(m.value);if(v<BigInt(0))throw new Error(`Pool ${l} insufficient BTC: need ${m.value}, have ${t[l]}`);t[l]=v;return}o[m.id]=(o[m.id]??BigInt(0))+BigInt(m.value),n[l]??={};const y=n[l][m.id]??BigInt(0),B=y-BigInt(m.value);if(B<BigInt(0))throw new Error(`Pool ${l} insufficient rune ${m.id}: need ${m.value}, have ${y}`);n[l][m.id]=B})}),Object.keys(c).forEach(h=>{const l=c[h];if(l<=BigInt(0))return;const m=this.selectRuneUtxos(this.config.involvedRuneUtxos?.[h]??[],h,l),B=m.reduce((v,T)=>v+BigInt(T.runes.find(N=>N.id===h)?.amount??0),BigInt(0))-l;B>BigInt(0)&&(o[h]=(o[h]??BigInt(0))+B),m.forEach(v=>{this.addInput(v)})}),{userOutputBtcAmount:i,userOutputRuneAmounts:o,poolOutputBtcAmounts:t,poolOutputRuneAmounts:n}}addRuneOutputs(t,n,i){const c=new Set,o=Object.keys(i);for(const y in t)c.add(y);o.forEach(y=>{for(const B in n[y])c.add(B)});const a=Array.from(c),u=[],h=[];let l=1;a.forEach(y=>{const B=new ct.RuneId(Number(y.split(":")[0]),Number(y.split(":")[1])),v=t[y]??BigInt(0);v>BigInt(0)&&(u.push(new ct.Edict(B,v,l)),h.push(this.config.address),l++),o.forEach(T=>{const N=n[T][y]??BigInt(0);N>BigInt(0)&&(u.push(new ct.Edict(B,N,l)),h.push(T),l++)})}),console.log("edicts",u);const m=new ct.Runestone(u,ct.none(),ct.none(),ct.none());return this.addScriptOutput(m.encipher()),h.forEach(y=>{let B=_t;!i[y]||y===this.config.address?this.additionalDustNeeded+=_t:(B=i[y],delete i[y]),this.addOutput(y,B)}),i}addIntention(t){this.intentions.push(t)}async build(){const{userOutputBtcAmount:t,userOutputRuneAmounts:n,poolOutputBtcAmounts:i,poolOutputRuneAmounts:c}=this.addInputAndCalculateOutputs();console.log(t,n,i,c);const o=this.addRuneOutputs(n,c,i);return Object.keys(o).forEach(u=>{this.addOutput(u,o[u])}),await this.addBtcAndFees(this.config.btcUtxos,-t),this.psbt}async send(t){if(!this.intentions.length)throw new Error("No itentions added");return this.orchestrator.invoke({intention_set:{tx_fee_in_sats:this.txFee,initiator_address:this.config.paymentAddress,intentions:this.intentions.map(({action:n,actionParams:i,poolAddress:c,inputCoins:o,outputCoins:a,nonce:u})=>({exchange_id:this.config.exchangeId,input_coins:o.map(h=>({coin:h,from:h.id===vt?this.config.paymentAddress:this.config.address})),output_coins:a.map(h=>({coin:h,to:h.id===vt?this.config.paymentAddress:this.config.address})),pool_address:c,action:n,action_params:i??"",pool_utxo_spent:[],pool_utxo_received:[],nonce:u}))},initiator_utxo_proof:[],psbt_hex:t}).then(n=>{if(n?.Ok)return n.Ok;{const i=n?.Err??{},c=Object.keys(i)[0],o=i[c];throw new Error(o?c==="ErrorOccurredDuringExecution"?`${c}: ${o.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(n)}`:`Invoke Error: ${JSON.stringify(n)}`)}})}}class ft extends Error{response;request;constructor(t,n){const i=`${ft.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(i),Object.setPrototypeOf(this,ft.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,ft)}static extractMessage(t){return t.errors?.[0]?.message??`GraphQL Error (Code: ${String(t.status)})`}}const Fn=e=>e.toUpperCase(),Xt=e=>typeof e=="function"?e():e,Vn=(e,t)=>e.map((n,i)=>[n,t[i]]),lt=e=>{let t={};return e instanceof Headers?t=Yr(e):Array.isArray(e)?e.forEach(([n,i])=>{n&&i!==void 0&&(t[n]=i)}):e&&(t=e),t},Yr=e=>{const t={};return e.forEach((n,i)=>{t[i]=n}),t},Qr=e=>{try{const t=e();return Jr(t)?t.catch(n=>jn(n)):t}catch(t){return jn(t)}},jn=e=>e instanceof Error?e:new Error(String(e)),Jr=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",Yt=e=>{throw new Error(`Unhandled case: ${String(e)}`)},St=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Lr=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},Dr=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0},$n="Accept",Qt="Content-Type",Jt="application/json",Zn="application/graphql-response+json",Kn=e=>e.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),ei=e=>{const t=e.toLowerCase();return t.includes(Zn)||t.includes(Jt)},Gn=e=>{try{if(Array.isArray(e))return{_tag:"Batch",executionResults:e.map(Wn)};if(St(e))return{_tag:"Single",executionResult:Wn(e)};throw new Error(`Invalid execution result: result is not object or array.
|
|
6
|
+
*/var fn;function _r(){return fn||(fn=1,(function(e){const t=Er(),n=Br(),i=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=F,e.INSPECT_MAX_BYTES=50;const c=2147483647;e.kMaxLength=c,u.TYPED_ARRAY_SUPPORT=o(),!u.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 o(){try{const f=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(f,r),f.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function a(f){if(f>c)throw new RangeError('The value "'+f+'" is invalid for option "size"');const r=new Uint8Array(f);return Object.setPrototypeOf(r,u.prototype),r}function u(f,r,s){if(typeof f=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return y(f)}return h(f,r,s)}u.poolSize=8192;function h(f,r,s){if(typeof f=="string")return B(f,r);if(ArrayBuffer.isView(f))return T(f);if(f==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f);if(He(f,ArrayBuffer)||f&&He(f.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(He(f,SharedArrayBuffer)||f&&He(f.buffer,SharedArrayBuffer)))return N(f,r,s);if(typeof f=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const d=f.valueOf&&f.valueOf();if(d!=null&&d!==f)return u.from(d,r,s);const E=K(f);if(E)return E;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof f[Symbol.toPrimitive]=="function")return u.from(f[Symbol.toPrimitive]("string"),r,s);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f)}u.from=function(f,r,s){return h(f,r,s)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array);function l(f){if(typeof f!="number")throw new TypeError('"size" argument must be of type number');if(f<0)throw new RangeError('The value "'+f+'" is invalid for option "size"')}function m(f,r,s){return l(f),f<=0?a(f):r!==void 0?typeof s=="string"?a(f).fill(r,s):a(f).fill(r):a(f)}u.alloc=function(f,r,s){return m(f,r,s)};function y(f){return l(f),a(f<0?0:J(f)|0)}u.allocUnsafe=function(f){return y(f)},u.allocUnsafeSlow=function(f){return y(f)};function B(f,r){if((typeof r!="string"||r==="")&&(r="utf8"),!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r);const s=b(f,r)|0;let d=a(s);const E=d.write(f,r);return E!==s&&(d=d.slice(0,E)),d}function v(f){const r=f.length<0?0:J(f.length)|0,s=a(r);for(let d=0;d<r;d+=1)s[d]=f[d]&255;return s}function T(f){if(He(f,Uint8Array)){const r=new Uint8Array(f);return N(r.buffer,r.byteOffset,r.byteLength)}return v(f)}function N(f,r,s){if(r<0||f.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(f.byteLength<r+(s||0))throw new RangeError('"length" is outside of buffer bounds');let d;return r===void 0&&s===void 0?d=new Uint8Array(f):s===void 0?d=new Uint8Array(f,r):d=new Uint8Array(f,r,s),Object.setPrototypeOf(d,u.prototype),d}function K(f){if(u.isBuffer(f)){const r=J(f.length)|0,s=a(r);return s.length===0||f.copy(s,0,0,r),s}if(f.length!==void 0)return typeof f.length!="number"||Be(f.length)?a(0):v(f);if(f.type==="Buffer"&&Array.isArray(f.data))return v(f.data)}function J(f){if(f>=c)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+c.toString(16)+" bytes");return f|0}function F(f){return+f!=f&&(f=0),u.alloc(+f)}u.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==u.prototype},u.compare=function(r,s){if(He(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),He(s,Uint8Array)&&(s=u.from(s,s.offset,s.byteLength)),!u.isBuffer(r)||!u.isBuffer(s))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(r===s)return 0;let d=r.length,E=s.length;for(let A=0,M=Math.min(d,E);A<M;++A)if(r[A]!==s[A]){d=r[A],E=s[A];break}return d<E?-1:E<d?1:0},u.isEncoding=function(r){switch(String(r).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}},u.concat=function(r,s){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return u.alloc(0);let d;if(s===void 0)for(s=0,d=0;d<r.length;++d)s+=r[d].length;const E=u.allocUnsafe(s);let A=0;for(d=0;d<r.length;++d){let M=r[d];if(He(M,Uint8Array))A+M.length>E.length?(u.isBuffer(M)||(M=u.from(M)),M.copy(E,A)):Uint8Array.prototype.set.call(E,M,A);else if(u.isBuffer(M))M.copy(E,A);else throw new TypeError('"list" argument must be an Array of Buffers');A+=M.length}return E};function b(f,r){if(u.isBuffer(f))return f.length;if(ArrayBuffer.isView(f)||He(f,ArrayBuffer))return f.byteLength;if(typeof f!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof f);const s=f.length,d=arguments.length>2&&arguments[2]===!0;if(!d&&s===0)return 0;let E=!1;for(;;)switch(r){case"ascii":case"latin1":case"binary":return s;case"utf8":case"utf-8":return Oe(f).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s*2;case"hex":return s>>>1;case"base64":return Ee(f).length;default:if(E)return d?-1:Oe(f).length;r=(""+r).toLowerCase(),E=!0}}u.byteLength=b;function P(f,r,s){let d=!1;if((r===void 0||r<0)&&(r=0),r>this.length||((s===void 0||s>this.length)&&(s=this.length),s<=0)||(s>>>=0,r>>>=0,s<=r))return"";for(f||(f="utf8");;)switch(f){case"hex":return _(this,r,s);case"utf8":case"utf-8":return $(this,r,s);case"ascii":return x(this,r,s);case"latin1":case"binary":return p(this,r,s);case"base64":return V(this,r,s);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,r,s);default:if(d)throw new TypeError("Unknown encoding: "+f);f=(f+"").toLowerCase(),d=!0}}u.prototype._isBuffer=!0;function I(f,r,s){const d=f[r];f[r]=f[s],f[s]=d}u.prototype.swap16=function(){const r=this.length;if(r%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let s=0;s<r;s+=2)I(this,s,s+1);return this},u.prototype.swap32=function(){const r=this.length;if(r%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let s=0;s<r;s+=4)I(this,s,s+3),I(this,s+1,s+2);return this},u.prototype.swap64=function(){const r=this.length;if(r%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let s=0;s<r;s+=8)I(this,s,s+7),I(this,s+1,s+6),I(this,s+2,s+5),I(this,s+3,s+4);return this},u.prototype.toString=function(){const r=this.length;return r===0?"":arguments.length===0?$(this,0,r):P.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(r){if(!u.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:u.compare(this,r)===0},u.prototype.inspect=function(){let r="";const s=e.INSPECT_MAX_BYTES;return r=this.toString("hex",0,s).replace(/(.{2})/g,"$1 ").trim(),this.length>s&&(r+=" ... "),"<Buffer "+r+">"},i&&(u.prototype[i]=u.prototype.inspect),u.prototype.compare=function(r,s,d,E,A){if(He(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),!u.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(s===void 0&&(s=0),d===void 0&&(d=r?r.length:0),E===void 0&&(E=0),A===void 0&&(A=this.length),s<0||d>r.length||E<0||A>this.length)throw new RangeError("out of range index");if(E>=A&&s>=d)return 0;if(E>=A)return-1;if(s>=d)return 1;if(s>>>=0,d>>>=0,E>>>=0,A>>>=0,this===r)return 0;let M=A-E,ue=d-s;const de=Math.min(M,ue),ae=this.slice(E,A),ye=r.slice(s,d);for(let pe=0;pe<de;++pe)if(ae[pe]!==ye[pe]){M=ae[pe],ue=ye[pe];break}return M<ue?-1:ue<M?1:0};function O(f,r,s,d,E){if(f.length===0)return-1;if(typeof s=="string"?(d=s,s=0):s>2147483647?s=2147483647:s<-2147483648&&(s=-2147483648),s=+s,Be(s)&&(s=E?0:f.length-1),s<0&&(s=f.length+s),s>=f.length){if(E)return-1;s=f.length-1}else if(s<0)if(E)s=0;else return-1;if(typeof r=="string"&&(r=u.from(r,d)),u.isBuffer(r))return r.length===0?-1:U(f,r,s,d,E);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?E?Uint8Array.prototype.indexOf.call(f,r,s):Uint8Array.prototype.lastIndexOf.call(f,r,s):U(f,[r],s,d,E);throw new TypeError("val must be string, number or Buffer")}function U(f,r,s,d,E){let A=1,M=f.length,ue=r.length;if(d!==void 0&&(d=String(d).toLowerCase(),d==="ucs2"||d==="ucs-2"||d==="utf16le"||d==="utf-16le")){if(f.length<2||r.length<2)return-1;A=2,M/=2,ue/=2,s/=2}function de(ye,pe){return A===1?ye[pe]:ye.readUInt16BE(pe*A)}let ae;if(E){let ye=-1;for(ae=s;ae<M;ae++)if(de(f,ae)===de(r,ye===-1?0:ae-ye)){if(ye===-1&&(ye=ae),ae-ye+1===ue)return ye*A}else ye!==-1&&(ae-=ae-ye),ye=-1}else for(s+ue>M&&(s=M-ue),ae=s;ae>=0;ae--){let ye=!0;for(let pe=0;pe<ue;pe++)if(de(f,ae+pe)!==de(r,pe)){ye=!1;break}if(ye)return ae}return-1}u.prototype.includes=function(r,s,d){return this.indexOf(r,s,d)!==-1},u.prototype.indexOf=function(r,s,d){return O(this,r,s,d,!0)},u.prototype.lastIndexOf=function(r,s,d){return O(this,r,s,d,!1)};function Z(f,r,s,d){s=Number(s)||0;const E=f.length-s;d?(d=Number(d),d>E&&(d=E)):d=E;const A=r.length;d>A/2&&(d=A/2);let M;for(M=0;M<d;++M){const ue=parseInt(r.substr(M*2,2),16);if(Be(ue))return M;f[s+M]=ue}return M}function R(f,r,s,d){return Ke(Oe(r,f.length-s),f,s,d)}function C(f,r,s,d){return Ke(qe(r),f,s,d)}function j(f,r,s,d){return Ke(Ee(r),f,s,d)}function Q(f,r,s,d){return Ke(ke(r,f.length-s),f,s,d)}u.prototype.write=function(r,s,d,E){if(s===void 0)E="utf8",d=this.length,s=0;else if(d===void 0&&typeof s=="string")E=s,d=this.length,s=0;else if(isFinite(s))s=s>>>0,isFinite(d)?(d=d>>>0,E===void 0&&(E="utf8")):(E=d,d=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const A=this.length-s;if((d===void 0||d>A)&&(d=A),r.length>0&&(d<0||s<0)||s>this.length)throw new RangeError("Attempt to write outside buffer bounds");E||(E="utf8");let M=!1;for(;;)switch(E){case"hex":return Z(this,r,s,d);case"utf8":case"utf-8":return R(this,r,s,d);case"ascii":case"latin1":case"binary":return C(this,r,s,d);case"base64":return j(this,r,s,d);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Q(this,r,s,d);default:if(M)throw new TypeError("Unknown encoding: "+E);E=(""+E).toLowerCase(),M=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function V(f,r,s){return r===0&&s===f.length?t.fromByteArray(f):t.fromByteArray(f.slice(r,s))}function $(f,r,s){s=Math.min(f.length,s);const d=[];let E=r;for(;E<s;){const A=f[E];let M=null,ue=A>239?4:A>223?3:A>191?2:1;if(E+ue<=s){let de,ae,ye,pe;switch(ue){case 1:A<128&&(M=A);break;case 2:de=f[E+1],(de&192)===128&&(pe=(A&31)<<6|de&63,pe>127&&(M=pe));break;case 3:de=f[E+1],ae=f[E+2],(de&192)===128&&(ae&192)===128&&(pe=(A&15)<<12|(de&63)<<6|ae&63,pe>2047&&(pe<55296||pe>57343)&&(M=pe));break;case 4:de=f[E+1],ae=f[E+2],ye=f[E+3],(de&192)===128&&(ae&192)===128&&(ye&192)===128&&(pe=(A&15)<<18|(de&63)<<12|(ae&63)<<6|ye&63,pe>65535&&pe<1114112&&(M=pe))}}M===null?(M=65533,ue=1):M>65535&&(M-=65536,d.push(M>>>10&1023|55296),M=56320|M&1023),d.push(M),E+=ue}return H(d)}const w=4096;function H(f){const r=f.length;if(r<=w)return String.fromCharCode.apply(String,f);let s="",d=0;for(;d<r;)s+=String.fromCharCode.apply(String,f.slice(d,d+=w));return s}function x(f,r,s){let d="";s=Math.min(f.length,s);for(let E=r;E<s;++E)d+=String.fromCharCode(f[E]&127);return d}function p(f,r,s){let d="";s=Math.min(f.length,s);for(let E=r;E<s;++E)d+=String.fromCharCode(f[E]);return d}function _(f,r,s){const d=f.length;(!r||r<0)&&(r=0),(!s||s<0||s>d)&&(s=d);let E="";for(let A=r;A<s;++A)E+=te[f[A]];return E}function k(f,r,s){const d=f.slice(r,s);let E="";for(let A=0;A<d.length-1;A+=2)E+=String.fromCharCode(d[A]+d[A+1]*256);return E}u.prototype.slice=function(r,s){const d=this.length;r=~~r,s=s===void 0?d:~~s,r<0?(r+=d,r<0&&(r=0)):r>d&&(r=d),s<0?(s+=d,s<0&&(s=0)):s>d&&(s=d),s<r&&(s=r);const E=this.subarray(r,s);return Object.setPrototypeOf(E,u.prototype),E};function g(f,r,s){if(f%1!==0||f<0)throw new RangeError("offset is not uint");if(f+r>s)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=this[r],A=1,M=0;for(;++M<s&&(A*=256);)E+=this[r+M]*A;return E},u.prototype.readUintBE=u.prototype.readUIntBE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=this[r+--s],A=1;for(;s>0&&(A*=256);)E+=this[r+--s]*A;return E},u.prototype.readUint8=u.prototype.readUInt8=function(r,s){return r=r>>>0,s||g(r,1,this.length),this[r]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(r,s){return r=r>>>0,s||g(r,2,this.length),this[r]|this[r+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(r,s){return r=r>>>0,s||g(r,2,this.length),this[r]<<8|this[r+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(r,s){return r=r>>>0,s||g(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(r,s){return r=r>>>0,s||g(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])},u.prototype.readBigUInt64LE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=s+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24,A=this[++r]+this[++r]*2**8+this[++r]*2**16+d*2**24;return BigInt(E)+(BigInt(A)<<BigInt(32))}),u.prototype.readBigUInt64BE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=s*2**24+this[++r]*2**16+this[++r]*2**8+this[++r],A=this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+d;return(BigInt(E)<<BigInt(32))+BigInt(A)}),u.prototype.readIntLE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=this[r],A=1,M=0;for(;++M<s&&(A*=256);)E+=this[r+M]*A;return A*=128,E>=A&&(E-=Math.pow(2,8*s)),E},u.prototype.readIntBE=function(r,s,d){r=r>>>0,s=s>>>0,d||g(r,s,this.length);let E=s,A=1,M=this[r+--E];for(;E>0&&(A*=256);)M+=this[r+--E]*A;return A*=128,M>=A&&(M-=Math.pow(2,8*s)),M},u.prototype.readInt8=function(r,s){return r=r>>>0,s||g(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]},u.prototype.readInt16LE=function(r,s){r=r>>>0,s||g(r,2,this.length);const d=this[r]|this[r+1]<<8;return d&32768?d|4294901760:d},u.prototype.readInt16BE=function(r,s){r=r>>>0,s||g(r,2,this.length);const d=this[r+1]|this[r]<<8;return d&32768?d|4294901760:d},u.prototype.readInt32LE=function(r,s){return r=r>>>0,s||g(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24},u.prototype.readInt32BE=function(r,s){return r=r>>>0,s||g(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]},u.prototype.readBigInt64LE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=this[r+4]+this[r+5]*2**8+this[r+6]*2**16+(d<<24);return(BigInt(E)<<BigInt(32))+BigInt(s+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24)}),u.prototype.readBigInt64BE=Y(function(r){r=r>>>0,W(r,"offset");const s=this[r],d=this[r+7];(s===void 0||d===void 0)&&oe(r,this.length-8);const E=(s<<24)+this[++r]*2**16+this[++r]*2**8+this[++r];return(BigInt(E)<<BigInt(32))+BigInt(this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+d)}),u.prototype.readFloatLE=function(r,s){return r=r>>>0,s||g(r,4,this.length),n.read(this,r,!0,23,4)},u.prototype.readFloatBE=function(r,s){return r=r>>>0,s||g(r,4,this.length),n.read(this,r,!1,23,4)},u.prototype.readDoubleLE=function(r,s){return r=r>>>0,s||g(r,8,this.length),n.read(this,r,!0,52,8)},u.prototype.readDoubleBE=function(r,s){return r=r>>>0,s||g(r,8,this.length),n.read(this,r,!1,52,8)};function S(f,r,s,d,E,A){if(!u.isBuffer(f))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>E||r<A)throw new RangeError('"value" argument is out of bounds');if(s+d>f.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(r,s,d,E){if(r=+r,s=s>>>0,d=d>>>0,!E){const ue=Math.pow(2,8*d)-1;S(this,r,s,d,ue,0)}let A=1,M=0;for(this[s]=r&255;++M<d&&(A*=256);)this[s+M]=r/A&255;return s+d},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(r,s,d,E){if(r=+r,s=s>>>0,d=d>>>0,!E){const ue=Math.pow(2,8*d)-1;S(this,r,s,d,ue,0)}let A=d-1,M=1;for(this[s+A]=r&255;--A>=0&&(M*=256);)this[s+A]=r/M&255;return s+d},u.prototype.writeUint8=u.prototype.writeUInt8=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,1,255,0),this[s]=r&255,s+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,65535,0),this[s]=r&255,this[s+1]=r>>>8,s+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,65535,0),this[s]=r>>>8,this[s+1]=r&255,s+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,4294967295,0),this[s+3]=r>>>24,this[s+2]=r>>>16,this[s+1]=r>>>8,this[s]=r&255,s+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,4294967295,0),this[s]=r>>>24,this[s+1]=r>>>16,this[s+2]=r>>>8,this[s+3]=r&255,s+4};function q(f,r,s,d,E){ce(r,d,E,f,s,7);let A=Number(r&BigInt(4294967295));f[s++]=A,A=A>>8,f[s++]=A,A=A>>8,f[s++]=A,A=A>>8,f[s++]=A;let M=Number(r>>BigInt(32)&BigInt(4294967295));return f[s++]=M,M=M>>8,f[s++]=M,M=M>>8,f[s++]=M,M=M>>8,f[s++]=M,s}function G(f,r,s,d,E){ce(r,d,E,f,s,7);let A=Number(r&BigInt(4294967295));f[s+7]=A,A=A>>8,f[s+6]=A,A=A>>8,f[s+5]=A,A=A>>8,f[s+4]=A;let M=Number(r>>BigInt(32)&BigInt(4294967295));return f[s+3]=M,M=M>>8,f[s+2]=M,M=M>>8,f[s+1]=M,M=M>>8,f[s]=M,s+8}u.prototype.writeBigUInt64LE=Y(function(r,s=0){return q(this,r,s,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeBigUInt64BE=Y(function(r,s=0){return G(this,r,s,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeIntLE=function(r,s,d,E){if(r=+r,s=s>>>0,!E){const de=Math.pow(2,8*d-1);S(this,r,s,d,de-1,-de)}let A=0,M=1,ue=0;for(this[s]=r&255;++A<d&&(M*=256);)r<0&&ue===0&&this[s+A-1]!==0&&(ue=1),this[s+A]=(r/M>>0)-ue&255;return s+d},u.prototype.writeIntBE=function(r,s,d,E){if(r=+r,s=s>>>0,!E){const de=Math.pow(2,8*d-1);S(this,r,s,d,de-1,-de)}let A=d-1,M=1,ue=0;for(this[s+A]=r&255;--A>=0&&(M*=256);)r<0&&ue===0&&this[s+A+1]!==0&&(ue=1),this[s+A]=(r/M>>0)-ue&255;return s+d},u.prototype.writeInt8=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,1,127,-128),r<0&&(r=255+r+1),this[s]=r&255,s+1},u.prototype.writeInt16LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,32767,-32768),this[s]=r&255,this[s+1]=r>>>8,s+2},u.prototype.writeInt16BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,2,32767,-32768),this[s]=r>>>8,this[s+1]=r&255,s+2},u.prototype.writeInt32LE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,2147483647,-2147483648),this[s]=r&255,this[s+1]=r>>>8,this[s+2]=r>>>16,this[s+3]=r>>>24,s+4},u.prototype.writeInt32BE=function(r,s,d){return r=+r,s=s>>>0,d||S(this,r,s,4,2147483647,-2147483648),r<0&&(r=4294967295+r+1),this[s]=r>>>24,this[s+1]=r>>>16,this[s+2]=r>>>8,this[s+3]=r&255,s+4},u.prototype.writeBigInt64LE=Y(function(r,s=0){return q(this,r,s,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeBigInt64BE=Y(function(r,s=0){return G(this,r,s,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ee(f,r,s,d,E,A){if(s+d>f.length)throw new RangeError("Index out of range");if(s<0)throw new RangeError("Index out of range")}function ne(f,r,s,d,E){return r=+r,s=s>>>0,E||ee(f,r,s,4),n.write(f,r,s,d,23,4),s+4}u.prototype.writeFloatLE=function(r,s,d){return ne(this,r,s,!0,d)},u.prototype.writeFloatBE=function(r,s,d){return ne(this,r,s,!1,d)};function ie(f,r,s,d,E){return r=+r,s=s>>>0,E||ee(f,r,s,8),n.write(f,r,s,d,52,8),s+8}u.prototype.writeDoubleLE=function(r,s,d){return ie(this,r,s,!0,d)},u.prototype.writeDoubleBE=function(r,s,d){return ie(this,r,s,!1,d)},u.prototype.copy=function(r,s,d,E){if(!u.isBuffer(r))throw new TypeError("argument should be a Buffer");if(d||(d=0),!E&&E!==0&&(E=this.length),s>=r.length&&(s=r.length),s||(s=0),E>0&&E<d&&(E=d),E===d||r.length===0||this.length===0)return 0;if(s<0)throw new RangeError("targetStart out of bounds");if(d<0||d>=this.length)throw new RangeError("Index out of range");if(E<0)throw new RangeError("sourceEnd out of bounds");E>this.length&&(E=this.length),r.length-s<E-d&&(E=r.length-s+d);const A=E-d;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(s,d,E):Uint8Array.prototype.set.call(r,this.subarray(d,E),s),A},u.prototype.fill=function(r,s,d,E){if(typeof r=="string"){if(typeof s=="string"?(E=s,s=0,d=this.length):typeof d=="string"&&(E=d,d=this.length),E!==void 0&&typeof E!="string")throw new TypeError("encoding must be a string");if(typeof E=="string"&&!u.isEncoding(E))throw new TypeError("Unknown encoding: "+E);if(r.length===1){const M=r.charCodeAt(0);(E==="utf8"&&M<128||E==="latin1")&&(r=M)}}else typeof r=="number"?r=r&255:typeof r=="boolean"&&(r=Number(r));if(s<0||this.length<s||this.length<d)throw new RangeError("Out of range index");if(d<=s)return this;s=s>>>0,d=d===void 0?this.length:d>>>0,r||(r=0);let A;if(typeof r=="number")for(A=s;A<d;++A)this[A]=r;else{const M=u.isBuffer(r)?r:u.from(r,E),ue=M.length;if(ue===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(A=0;A<d-s;++A)this[A+s]=M[A%ue]}return this};const L={};function D(f,r,s){L[f]=class extends s{constructor(){super(),Object.defineProperty(this,"message",{value:r.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${f}]`,this.stack,delete this.name}get code(){return f}set code(E){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:E,writable:!0})}toString(){return`${this.name} [${f}]: ${this.message}`}}}D("ERR_BUFFER_OUT_OF_BOUNDS",function(f){return f?`${f} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(f,r){return`The "${f}" argument must be of type number. Received type ${typeof r}`},TypeError),D("ERR_OUT_OF_RANGE",function(f,r,s){let d=`The value of "${f}" is out of range.`,E=s;return Number.isInteger(s)&&Math.abs(s)>2**32?E=re(String(s)):typeof s=="bigint"&&(E=String(s),(s>BigInt(2)**BigInt(32)||s<-(BigInt(2)**BigInt(32)))&&(E=re(E)),E+="n"),d+=` It must be ${r}. Received ${E}`,d},RangeError);function re(f){let r="",s=f.length;const d=f[0]==="-"?1:0;for(;s>=d+4;s-=3)r=`_${f.slice(s-3,s)}${r}`;return`${f.slice(0,s)}${r}`}function le(f,r,s){W(r,"offset"),(f[r]===void 0||f[r+s]===void 0)&&oe(r,f.length-(s+1))}function ce(f,r,s,d,E,A){if(f>s||f<r){const M=typeof r=="bigint"?"n":"";let ue;throw r===0||r===BigInt(0)?ue=`>= 0${M} and < 2${M} ** ${(A+1)*8}${M}`:ue=`>= -(2${M} ** ${(A+1)*8-1}${M}) and < 2 ** ${(A+1)*8-1}${M}`,new L.ERR_OUT_OF_RANGE("value",ue,f)}le(d,E,A)}function W(f,r){if(typeof f!="number")throw new L.ERR_INVALID_ARG_TYPE(r,"number",f)}function oe(f,r,s){throw Math.floor(f)!==f?(W(f,s),new L.ERR_OUT_OF_RANGE("offset","an integer",f)):r<0?new L.ERR_BUFFER_OUT_OF_BOUNDS:new L.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${r}`,f)}const be=/[^+/0-9A-Za-z-_]/g;function Se(f){if(f=f.split("=")[0],f=f.trim().replace(be,""),f.length<2)return"";for(;f.length%4!==0;)f=f+"=";return f}function Oe(f,r){r=r||1/0;let s;const d=f.length;let E=null;const A=[];for(let M=0;M<d;++M){if(s=f.charCodeAt(M),s>55295&&s<57344){if(!E){if(s>56319){(r-=3)>-1&&A.push(239,191,189);continue}else if(M+1===d){(r-=3)>-1&&A.push(239,191,189);continue}E=s;continue}if(s<56320){(r-=3)>-1&&A.push(239,191,189),E=s;continue}s=(E-55296<<10|s-56320)+65536}else E&&(r-=3)>-1&&A.push(239,191,189);if(E=null,s<128){if((r-=1)<0)break;A.push(s)}else if(s<2048){if((r-=2)<0)break;A.push(s>>6|192,s&63|128)}else if(s<65536){if((r-=3)<0)break;A.push(s>>12|224,s>>6&63|128,s&63|128)}else if(s<1114112){if((r-=4)<0)break;A.push(s>>18|240,s>>12&63|128,s>>6&63|128,s&63|128)}else throw new Error("Invalid code point")}return A}function qe(f){const r=[];for(let s=0;s<f.length;++s)r.push(f.charCodeAt(s)&255);return r}function ke(f,r){let s,d,E;const A=[];for(let M=0;M<f.length&&!((r-=2)<0);++M)s=f.charCodeAt(M),d=s>>8,E=s%256,A.push(E),A.push(d);return A}function Ee(f){return t.toByteArray(Se(f))}function Ke(f,r,s,d){let E;for(E=0;E<d&&!(E+s>=r.length||E>=f.length);++E)r[E+s]=f[E];return E}function He(f,r){return f instanceof r||f!=null&&f.constructor!=null&&f.constructor.name!=null&&f.constructor.name===r.name}function Be(f){return f!==f}const te=(function(){const f="0123456789abcdef",r=new Array(256);for(let s=0;s<16;++s){const d=s*16;for(let E=0;E<16;++E)r[d+E]=f[s]+f[E]}return r})();function Y(f){return typeof BigInt>"u"?z:f}function z(){throw new Error("BigInt not supported")}})(It)),It}var xr=_r(),kt={exports:{}},ln;function vr(){if(ln)return kt.exports;ln=1;var e=kt.exports={},t,n;function i(){throw new Error("setTimeout has not been defined")}function c(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?t=setTimeout:t=i}catch{t=i}try{typeof clearTimeout=="function"?n=clearTimeout:n=c}catch{n=c}})();function o(N){if(t===setTimeout)return setTimeout(N,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(N,0);try{return t(N,0)}catch{try{return t.call(null,N,0)}catch{return t.call(this,N,0)}}}function a(N){if(n===clearTimeout)return clearTimeout(N);if((n===c||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(N);try{return n(N)}catch{try{return n.call(null,N)}catch{return n.call(this,N)}}}var u=[],h=!1,l,m=-1;function y(){!h||!l||(h=!1,l.length?u=l.concat(u):m=-1,u.length&&B())}function B(){if(!h){var N=o(y);h=!0;for(var K=u.length;K;){for(l=u,u=[];++m<K;)l&&l[m].run();m=-1,K=u.length}l=null,h=!1,a(N)}}e.nextTick=function(N){var K=new Array(arguments.length-1);if(arguments.length>1)for(var J=1;J<arguments.length;J++)K[J-1]=arguments[J];u.push(new v(N,K)),u.length===1&&!h&&o(B)};function v(N,K){this.fun=N,this.array=K}v.prototype.run=function(){this.fun.apply(null,this.array)},e.title="browser",e.browser=!0,e.env={},e.argv=[],e.version="",e.versions={};function T(){}return e.on=T,e.addListener=T,e.once=T,e.off=T,e.removeListener=T,e.removeAllListeners=T,e.emit=T,e.prependListener=T,e.prependOnceListener=T,e.listeners=function(N){return[]},e.binding=function(N){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(N){throw new Error("process.chdir is not supported")},e.umask=function(){return 0},kt.exports}var Sr=vr();const Ar=cn(Sr);typeof globalThis>"u"&&(globalThis.global=globalThis),typeof globalThis.Buffer>"u"&&(globalThis.Buffer=xr.Buffer),typeof globalThis.process>"u"&&(globalThis.process=Ar);var Ne={},Mt={},_e={},Ce={},Ft={},gt={},hn;function Tr(){return hn||(hn=1,Object.defineProperty(gt,"__esModule",{value:!0}),gt.crypto=void 0,gt.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),gt}var dn;function tt(){return dn||(dn=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=i,e.abytes=c,e.ahash=o,e.aexists=a,e.aoutput=u,e.u8=h,e.u32=l,e.clean=m,e.createView=y,e.rotr=B,e.rotl=v,e.byteSwap=T,e.byteSwap32=N,e.bytesToHex=F,e.hexToBytes=I,e.asyncLoop=U,e.utf8ToBytes=Z,e.bytesToUtf8=R,e.toBytes=C,e.kdfInputToBytes=j,e.concatBytes=Q,e.checkOpts=V,e.createHasher=w,e.createOptHasher=H,e.createXOFer=x,e.randomBytes=p;const t=Tr();function n(_){return _ instanceof Uint8Array||ArrayBuffer.isView(_)&&_.constructor.name==="Uint8Array"}function i(_){if(!Number.isSafeInteger(_)||_<0)throw new Error("positive integer expected, got "+_)}function c(_,...k){if(!n(_))throw new Error("Uint8Array expected");if(k.length>0&&!k.includes(_.length))throw new Error("Uint8Array expected of length "+k+", got length="+_.length)}function o(_){if(typeof _!="function"||typeof _.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");i(_.outputLen),i(_.blockLen)}function a(_,k=!0){if(_.destroyed)throw new Error("Hash instance has been destroyed");if(k&&_.finished)throw new Error("Hash#digest() has already been called")}function u(_,k){c(_);const g=k.outputLen;if(_.length<g)throw new Error("digestInto() expects output buffer of length at least "+g)}function h(_){return new Uint8Array(_.buffer,_.byteOffset,_.byteLength)}function l(_){return new Uint32Array(_.buffer,_.byteOffset,Math.floor(_.byteLength/4))}function m(..._){for(let k=0;k<_.length;k++)_[k].fill(0)}function y(_){return new DataView(_.buffer,_.byteOffset,_.byteLength)}function B(_,k){return _<<32-k|_>>>k}function v(_,k){return _<<k|_>>>32-k>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function T(_){return _<<24&4278190080|_<<8&16711680|_>>>8&65280|_>>>24&255}e.swap8IfBE=e.isLE?_=>_:_=>T(_),e.byteSwapIfBE=e.swap8IfBE;function N(_){for(let k=0;k<_.length;k++)_[k]=T(_[k]);return _}e.swap32IfBE=e.isLE?_=>_:N;const K=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",J=Array.from({length:256},(_,k)=>k.toString(16).padStart(2,"0"));function F(_){if(c(_),K)return _.toHex();let k="";for(let g=0;g<_.length;g++)k+=J[_[g]];return k}const b={_0:48,_9:57,A:65,F:70,a:97,f:102};function P(_){if(_>=b._0&&_<=b._9)return _-b._0;if(_>=b.A&&_<=b.F)return _-(b.A-10);if(_>=b.a&&_<=b.f)return _-(b.a-10)}function I(_){if(typeof _!="string")throw new Error("hex string expected, got "+typeof _);if(K)return Uint8Array.fromHex(_);const k=_.length,g=k/2;if(k%2)throw new Error("hex string expected, got unpadded hex of length "+k);const S=new Uint8Array(g);for(let q=0,G=0;q<g;q++,G+=2){const ee=P(_.charCodeAt(G)),ne=P(_.charCodeAt(G+1));if(ee===void 0||ne===void 0){const ie=_[G]+_[G+1];throw new Error('hex string expected, got non-hex character "'+ie+'" at index '+G)}S[q]=ee*16+ne}return S}const O=async()=>{};e.nextTick=O;async function U(_,k,g){let S=Date.now();for(let q=0;q<_;q++){g(q);const G=Date.now()-S;G>=0&&G<k||(await(0,e.nextTick)(),S+=G)}}function Z(_){if(typeof _!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(_))}function R(_){return new TextDecoder().decode(_)}function C(_){return typeof _=="string"&&(_=Z(_)),c(_),_}function j(_){return typeof _=="string"&&(_=Z(_)),c(_),_}function Q(..._){let k=0;for(let S=0;S<_.length;S++){const q=_[S];c(q),k+=q.length}const g=new Uint8Array(k);for(let S=0,q=0;S<_.length;S++){const G=_[S];g.set(G,q),q+=G.length}return g}function V(_,k){if(k!==void 0&&{}.toString.call(k)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(_,k)}class ${}e.Hash=$;function w(_){const k=S=>_().update(C(S)).digest(),g=_();return k.outputLen=g.outputLen,k.blockLen=g.blockLen,k.create=()=>_(),k}function H(_){const k=(S,q)=>_(q).update(C(S)).digest(),g=_({});return k.outputLen=g.outputLen,k.blockLen=g.blockLen,k.create=S=>_(S),k}function x(_){const k=(S,q)=>_(q).update(C(S)).digest(),g=_({});return k.outputLen=g.outputLen,k.blockLen=g.blockLen,k.create=S=>_(S),k}e.wrapConstructor=w,e.wrapConstructorWithOpts=H,e.wrapXOFConstructorWithOpts=x;function p(_=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(_));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(_));throw new Error("crypto.getRandomValues must be defined")}})(Ft)),Ft}var pn;function Nr(){if(pn)return Ce;pn=1,Object.defineProperty(Ce,"__esModule",{value:!0}),Ce.SHA512_IV=Ce.SHA384_IV=Ce.SHA224_IV=Ce.SHA256_IV=Ce.HashMD=void 0,Ce.setBigUint64=t,Ce.Chi=n,Ce.Maj=i;const e=tt();function t(o,a,u,h){if(typeof o.setBigUint64=="function")return o.setBigUint64(a,u,h);const l=BigInt(32),m=BigInt(4294967295),y=Number(u>>l&m),B=Number(u&m),v=h?4:0,T=h?0:4;o.setUint32(a+v,y,h),o.setUint32(a+T,B,h)}function n(o,a,u){return o&a^~o&u}function i(o,a,u){return o&a^o&u^a&u}class c extends e.Hash{constructor(a,u,h,l){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=a,this.outputLen=u,this.padOffset=h,this.isLE=l,this.buffer=new Uint8Array(a),this.view=(0,e.createView)(this.buffer)}update(a){(0,e.aexists)(this),a=(0,e.toBytes)(a),(0,e.abytes)(a);const{view:u,buffer:h,blockLen:l}=this,m=a.length;for(let y=0;y<m;){const B=Math.min(l-this.pos,m-y);if(B===l){const v=(0,e.createView)(a);for(;l<=m-y;y+=l)this.process(v,y);continue}h.set(a.subarray(y,y+B),this.pos),this.pos+=B,y+=B,this.pos===l&&(this.process(u,0),this.pos=0)}return this.length+=a.length,this.roundClean(),this}digestInto(a){(0,e.aexists)(this),(0,e.aoutput)(a,this),this.finished=!0;const{buffer:u,view:h,blockLen:l,isLE:m}=this;let{pos:y}=this;u[y++]=128,(0,e.clean)(this.buffer.subarray(y)),this.padOffset>l-y&&(this.process(h,0),y=0);for(let K=y;K<l;K++)u[K]=0;t(h,l-8,BigInt(this.length*8),m),this.process(h,0);const B=(0,e.createView)(a),v=this.outputLen;if(v%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const T=v/4,N=this.get();if(T>N.length)throw new Error("_sha2: outputLen bigger than state");for(let K=0;K<T;K++)B.setUint32(4*K,N[K],m)}digest(){const{buffer:a,outputLen:u}=this;this.digestInto(a);const h=a.slice(0,u);return this.destroy(),h}_cloneInto(a){a||(a=new this.constructor),a.set(...this.get());const{blockLen:u,buffer:h,length:l,finished:m,destroyed:y,pos:B}=this;return a.destroyed=y,a.finished=m,a.length=l,a.pos=B,l%u&&a.buffer.set(h),a}clone(){return this._cloneInto()}}return Ce.HashMD=c,Ce.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ce.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Ce.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Ce.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Ce}var we={},gn;function Rr(){if(gn)return we;gn=1,Object.defineProperty(we,"__esModule",{value:!0}),we.toBig=we.shrSL=we.shrSH=we.rotrSL=we.rotrSH=we.rotrBL=we.rotrBH=we.rotr32L=we.rotr32H=we.rotlSL=we.rotlSH=we.rotlBL=we.rotlBH=we.add5L=we.add5H=we.add4L=we.add4H=we.add3L=we.add3H=void 0,we.add=J,we.fromBig=n,we.split=i;const e=BigInt(2**32-1),t=BigInt(32);function n(R,C=!1){return C?{h:Number(R&e),l:Number(R>>t&e)}:{h:Number(R>>t&e)|0,l:Number(R&e)|0}}function i(R,C=!1){const j=R.length;let Q=new Uint32Array(j),V=new Uint32Array(j);for(let $=0;$<j;$++){const{h:w,l:H}=n(R[$],C);[Q[$],V[$]]=[w,H]}return[Q,V]}const c=(R,C)=>BigInt(R>>>0)<<t|BigInt(C>>>0);we.toBig=c;const o=(R,C,j)=>R>>>j;we.shrSH=o;const a=(R,C,j)=>R<<32-j|C>>>j;we.shrSL=a;const u=(R,C,j)=>R>>>j|C<<32-j;we.rotrSH=u;const h=(R,C,j)=>R<<32-j|C>>>j;we.rotrSL=h;const l=(R,C,j)=>R<<64-j|C>>>j-32;we.rotrBH=l;const m=(R,C,j)=>R>>>j-32|C<<64-j;we.rotrBL=m;const y=(R,C)=>C;we.rotr32H=y;const B=(R,C)=>R;we.rotr32L=B;const v=(R,C,j)=>R<<j|C>>>32-j;we.rotlSH=v;const T=(R,C,j)=>C<<j|R>>>32-j;we.rotlSL=T;const N=(R,C,j)=>C<<j-32|R>>>64-j;we.rotlBH=N;const K=(R,C,j)=>R<<j-32|C>>>64-j;we.rotlBL=K;function J(R,C,j,Q){const V=(C>>>0)+(Q>>>0);return{h:R+j+(V/2**32|0)|0,l:V|0}}const F=(R,C,j)=>(R>>>0)+(C>>>0)+(j>>>0);we.add3L=F;const b=(R,C,j,Q)=>C+j+Q+(R/2**32|0)|0;we.add3H=b;const P=(R,C,j,Q)=>(R>>>0)+(C>>>0)+(j>>>0)+(Q>>>0);we.add4L=P;const I=(R,C,j,Q,V)=>C+j+Q+V+(R/2**32|0)|0;we.add4H=I;const O=(R,C,j,Q,V)=>(R>>>0)+(C>>>0)+(j>>>0)+(Q>>>0)+(V>>>0);we.add5L=O;const U=(R,C,j,Q,V,$)=>C+j+Q+V+$+(R/2**32|0)|0;we.add5H=U;const Z={fromBig:n,split:i,toBig:c,shrSH:o,shrSL:a,rotrSH:u,rotrSL:h,rotrBH:l,rotrBL:m,rotr32H:y,rotr32L:B,rotlSH:v,rotlSL:T,rotlBH:N,rotlBL:K,add:J,add3L:F,add3H:b,add4L:P,add4H:I,add5H:U,add5L:O};return we.default=Z,we}var mn;function Or(){if(mn)return _e;mn=1,Object.defineProperty(_e,"__esModule",{value:!0}),_e.sha512_224=_e.sha512_256=_e.sha384=_e.sha512=_e.sha224=_e.sha256=_e.SHA512_256=_e.SHA512_224=_e.SHA384=_e.SHA512=_e.SHA224=_e.SHA256=void 0;const e=Nr(),t=Rr(),n=tt(),i=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]),c=new Uint32Array(64);class o extends e.HashMD{constructor(b=32){super(64,b,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:b,B:P,C:I,D:O,E:U,F:Z,G:R,H:C}=this;return[b,P,I,O,U,Z,R,C]}set(b,P,I,O,U,Z,R,C){this.A=b|0,this.B=P|0,this.C=I|0,this.D=O|0,this.E=U|0,this.F=Z|0,this.G=R|0,this.H=C|0}process(b,P){for(let V=0;V<16;V++,P+=4)c[V]=b.getUint32(P,!1);for(let V=16;V<64;V++){const $=c[V-15],w=c[V-2],H=(0,n.rotr)($,7)^(0,n.rotr)($,18)^$>>>3,x=(0,n.rotr)(w,17)^(0,n.rotr)(w,19)^w>>>10;c[V]=x+c[V-7]+H+c[V-16]|0}let{A:I,B:O,C:U,D:Z,E:R,F:C,G:j,H:Q}=this;for(let V=0;V<64;V++){const $=(0,n.rotr)(R,6)^(0,n.rotr)(R,11)^(0,n.rotr)(R,25),w=Q+$+(0,e.Chi)(R,C,j)+i[V]+c[V]|0,x=((0,n.rotr)(I,2)^(0,n.rotr)(I,13)^(0,n.rotr)(I,22))+(0,e.Maj)(I,O,U)|0;Q=j,j=C,C=R,R=Z+w|0,Z=U,U=O,O=I,I=w+x|0}I=I+this.A|0,O=O+this.B|0,U=U+this.C|0,Z=Z+this.D|0,R=R+this.E|0,C=C+this.F|0,j=j+this.G|0,Q=Q+this.H|0,this.set(I,O,U,Z,R,C,j,Q)}roundClean(){(0,n.clean)(c)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}_e.SHA256=o;class a extends o{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}}_e.SHA224=a;const u=t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(F=>BigInt(F))),h=u[0],l=u[1],m=new Uint32Array(80),y=new Uint32Array(80);class B extends e.HashMD{constructor(b=64){super(128,b,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:b,Al:P,Bh:I,Bl:O,Ch:U,Cl:Z,Dh:R,Dl:C,Eh:j,El:Q,Fh:V,Fl:$,Gh:w,Gl:H,Hh:x,Hl:p}=this;return[b,P,I,O,U,Z,R,C,j,Q,V,$,w,H,x,p]}set(b,P,I,O,U,Z,R,C,j,Q,V,$,w,H,x,p){this.Ah=b|0,this.Al=P|0,this.Bh=I|0,this.Bl=O|0,this.Ch=U|0,this.Cl=Z|0,this.Dh=R|0,this.Dl=C|0,this.Eh=j|0,this.El=Q|0,this.Fh=V|0,this.Fl=$|0,this.Gh=w|0,this.Gl=H|0,this.Hh=x|0,this.Hl=p|0}process(b,P){for(let g=0;g<16;g++,P+=4)m[g]=b.getUint32(P),y[g]=b.getUint32(P+=4);for(let g=16;g<80;g++){const S=m[g-15]|0,q=y[g-15]|0,G=t.rotrSH(S,q,1)^t.rotrSH(S,q,8)^t.shrSH(S,q,7),ee=t.rotrSL(S,q,1)^t.rotrSL(S,q,8)^t.shrSL(S,q,7),ne=m[g-2]|0,ie=y[g-2]|0,L=t.rotrSH(ne,ie,19)^t.rotrBH(ne,ie,61)^t.shrSH(ne,ie,6),D=t.rotrSL(ne,ie,19)^t.rotrBL(ne,ie,61)^t.shrSL(ne,ie,6),re=t.add4L(ee,D,y[g-7],y[g-16]),le=t.add4H(re,G,L,m[g-7],m[g-16]);m[g]=le|0,y[g]=re|0}let{Ah:I,Al:O,Bh:U,Bl:Z,Ch:R,Cl:C,Dh:j,Dl:Q,Eh:V,El:$,Fh:w,Fl:H,Gh:x,Gl:p,Hh:_,Hl:k}=this;for(let g=0;g<80;g++){const S=t.rotrSH(V,$,14)^t.rotrSH(V,$,18)^t.rotrBH(V,$,41),q=t.rotrSL(V,$,14)^t.rotrSL(V,$,18)^t.rotrBL(V,$,41),G=V&w^~V&x,ee=$&H^~$&p,ne=t.add5L(k,q,ee,l[g],y[g]),ie=t.add5H(ne,_,S,G,h[g],m[g]),L=ne|0,D=t.rotrSH(I,O,28)^t.rotrBH(I,O,34)^t.rotrBH(I,O,39),re=t.rotrSL(I,O,28)^t.rotrBL(I,O,34)^t.rotrBL(I,O,39),le=I&U^I&R^U&R,ce=O&Z^O&C^Z&C;_=x|0,k=p|0,x=w|0,p=H|0,w=V|0,H=$|0,{h:V,l:$}=t.add(j|0,Q|0,ie|0,L|0),j=R|0,Q=C|0,R=U|0,C=Z|0,U=I|0,Z=O|0;const W=t.add3L(L,re,ce);I=t.add3H(W,ie,D,le),O=W|0}({h:I,l:O}=t.add(this.Ah|0,this.Al|0,I|0,O|0)),{h:U,l:Z}=t.add(this.Bh|0,this.Bl|0,U|0,Z|0),{h:R,l:C}=t.add(this.Ch|0,this.Cl|0,R|0,C|0),{h:j,l:Q}=t.add(this.Dh|0,this.Dl|0,j|0,Q|0),{h:V,l:$}=t.add(this.Eh|0,this.El|0,V|0,$|0),{h:w,l:H}=t.add(this.Fh|0,this.Fl|0,w|0,H|0),{h:x,l:p}=t.add(this.Gh|0,this.Gl|0,x|0,p|0),{h:_,l:k}=t.add(this.Hh|0,this.Hl|0,_|0,k|0),this.set(I,O,U,Z,R,C,j,Q,V,$,w,H,x,p,_,k)}roundClean(){(0,n.clean)(m,y)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}_e.SHA512=B;class v extends B{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}}_e.SHA384=v;const T=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),N=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class K extends B{constructor(){super(28),this.Ah=T[0]|0,this.Al=T[1]|0,this.Bh=T[2]|0,this.Bl=T[3]|0,this.Ch=T[4]|0,this.Cl=T[5]|0,this.Dh=T[6]|0,this.Dl=T[7]|0,this.Eh=T[8]|0,this.El=T[9]|0,this.Fh=T[10]|0,this.Fl=T[11]|0,this.Gh=T[12]|0,this.Gl=T[13]|0,this.Hh=T[14]|0,this.Hl=T[15]|0}}_e.SHA512_224=K;class J extends B{constructor(){super(32),this.Ah=N[0]|0,this.Al=N[1]|0,this.Bh=N[2]|0,this.Bl=N[3]|0,this.Ch=N[4]|0,this.Cl=N[5]|0,this.Dh=N[6]|0,this.Dl=N[7]|0,this.Eh=N[8]|0,this.El=N[9]|0,this.Fh=N[10]|0,this.Fl=N[11]|0,this.Gh=N[12]|0,this.Gl=N[13]|0,this.Hh=N[14]|0,this.Hl=N[15]|0}}return _e.SHA512_256=J,_e.sha256=(0,n.createHasher)(()=>new o),_e.sha224=(0,n.createHasher)(()=>new a),_e.sha512=(0,n.createHasher)(()=>new B),_e.sha384=(0,n.createHasher)(()=>new v),_e.sha512_256=(0,n.createHasher)(()=>new J),_e.sha512_224=(0,n.createHasher)(()=>new K),_e}var mt={},Vt={},jt={},wn;function Hr(){return wn||(wn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=tt();class n extends t.Hash{constructor(o,a){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(o);const u=(0,t.toBytes)(a);if(this.iHash=o.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 h=this.blockLen,l=new Uint8Array(h);l.set(u.length>h?o.create().update(u).digest():u);for(let m=0;m<l.length;m++)l[m]^=54;this.iHash.update(l),this.oHash=o.create();for(let m=0;m<l.length;m++)l[m]^=106;this.oHash.update(l),(0,t.clean)(l)}update(o){return(0,t.aexists)(this),this.iHash.update(o),this}digestInto(o){(0,t.aexists)(this),(0,t.abytes)(o,this.outputLen),this.finished=!0,this.iHash.digestInto(o),this.oHash.update(o),this.oHash.digestInto(o),this.destroy()}digest(){const o=new Uint8Array(this.oHash.outputLen);return this.digestInto(o),o}_cloneInto(o){o||(o=Object.create(Object.getPrototypeOf(this),{}));const{oHash:a,iHash:u,finished:h,destroyed:l,blockLen:m,outputLen:y}=this;return o=o,o.finished=h,o.destroyed=l,o.blockLen=m,o.outputLen=y,o.oHash=a._cloneInto(o.oHash),o.iHash=u._cloneInto(o.iHash),o}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=n;const i=(c,o,a)=>new n(c,o).update(a).digest();e.hmac=i,e.hmac.create=(c,o)=>new n(c,o)})(jt)),jt}var $t={},yn;function at(){return yn||(yn=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=o,e._abool2=a,e._abytes2=u,e.numberToHexUnpadded=h,e.hexToNumber=l,e.bytesToNumberBE=m,e.bytesToNumberLE=y,e.numberToBytesBE=B,e.numberToBytesLE=v,e.numberToVarBytesBE=T,e.ensureBytes=N,e.equalBytes=K,e.copyBytes=J,e.asciiToBytes=F,e.inRange=P,e.aInRange=I,e.bitLen=O,e.bitGet=U,e.bitSet=Z,e.createHmacDrbg=C,e.validateObject=Q,e.isHash=V,e._validateObject=$,e.memoized=H;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=tt();var n=tt();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 i=BigInt(0),c=BigInt(1);function o(x,p){if(typeof p!="boolean")throw new Error(x+" boolean expected, got "+p)}function a(x,p=""){if(typeof x!="boolean"){const _=p&&`"${p}"`;throw new Error(_+"expected boolean, got type="+typeof x)}return x}function u(x,p,_=""){const k=(0,t.isBytes)(x),g=x?.length,S=p!==void 0;if(!k||S&&g!==p){const q=_&&`"${_}" `,G=S?` of length ${p}`:"",ee=k?`length=${g}`:`type=${typeof x}`;throw new Error(q+"expected Uint8Array"+G+", got "+ee)}return x}function h(x){const p=x.toString(16);return p.length&1?"0"+p:p}function l(x){if(typeof x!="string")throw new Error("hex string expected, got "+typeof x);return x===""?i:BigInt("0x"+x)}function m(x){return l((0,t.bytesToHex)(x))}function y(x){return(0,t.abytes)(x),l((0,t.bytesToHex)(Uint8Array.from(x).reverse()))}function B(x,p){return(0,t.hexToBytes)(x.toString(16).padStart(p*2,"0"))}function v(x,p){return B(x,p).reverse()}function T(x){return(0,t.hexToBytes)(h(x))}function N(x,p,_){let k;if(typeof p=="string")try{k=(0,t.hexToBytes)(p)}catch(S){throw new Error(x+" must be hex string or Uint8Array, cause: "+S)}else if((0,t.isBytes)(p))k=Uint8Array.from(p);else throw new Error(x+" must be hex string or Uint8Array");const g=k.length;if(typeof _=="number"&&g!==_)throw new Error(x+" of length "+_+" expected, got "+g);return k}function K(x,p){if(x.length!==p.length)return!1;let _=0;for(let k=0;k<x.length;k++)_|=x[k]^p[k];return _===0}function J(x){return Uint8Array.from(x)}function F(x){return Uint8Array.from(x,(p,_)=>{const k=p.charCodeAt(0);if(p.length!==1||k>127)throw new Error(`string contains non-ASCII character "${x[_]}" with code ${k} at position ${_}`);return k})}const b=x=>typeof x=="bigint"&&i<=x;function P(x,p,_){return b(x)&&b(p)&&b(_)&&p<=x&&x<_}function I(x,p,_,k){if(!P(p,_,k))throw new Error("expected valid "+x+": "+_+" <= n < "+k+", got "+p)}function O(x){let p;for(p=0;x>i;x>>=c,p+=1);return p}function U(x,p){return x>>BigInt(p)&c}function Z(x,p,_){return x|(_?c:i)<<BigInt(p)}const R=x=>(c<<BigInt(x))-c;e.bitMask=R;function C(x,p,_){if(typeof x!="number"||x<2)throw new Error("hashLen must be a number");if(typeof p!="number"||p<2)throw new Error("qByteLen must be a number");if(typeof _!="function")throw new Error("hmacFn must be a function");const k=re=>new Uint8Array(re),g=re=>Uint8Array.of(re);let S=k(x),q=k(x),G=0;const ee=()=>{S.fill(1),q.fill(0),G=0},ne=(...re)=>_(q,S,...re),ie=(re=k(0))=>{q=ne(g(0),re),S=ne(),re.length!==0&&(q=ne(g(1),re),S=ne())},L=()=>{if(G++>=1e3)throw new Error("drbg: tried 1000 values");let re=0;const le=[];for(;re<p;){S=ne();const ce=S.slice();le.push(ce),re+=S.length}return(0,t.concatBytes)(...le)};return(re,le)=>{ee(),ie(re);let ce;for(;!(ce=le(L()));)ie();return ee(),ce}}const j={bigint:x=>typeof x=="bigint",function:x=>typeof x=="function",boolean:x=>typeof x=="boolean",string:x=>typeof x=="string",stringOrUint8Array:x=>typeof x=="string"||(0,t.isBytes)(x),isSafeInteger:x=>Number.isSafeInteger(x),array:x=>Array.isArray(x),field:(x,p)=>p.Fp.isValid(x),hash:x=>typeof x=="function"&&Number.isSafeInteger(x.outputLen)};function Q(x,p,_={}){const k=(g,S,q)=>{const G=j[S];if(typeof G!="function")throw new Error("invalid validator function");const ee=x[g];if(!(q&&ee===void 0)&&!G(ee,x))throw new Error("param "+String(g)+" is invalid. Expected "+S+", got "+ee)};for(const[g,S]of Object.entries(p))k(g,S,!1);for(const[g,S]of Object.entries(_))k(g,S,!0);return x}function V(x){return typeof x=="function"&&Number.isSafeInteger(x.outputLen)}function $(x,p,_={}){if(!x||typeof x!="object")throw new Error("expected valid options object");function k(g,S,q){const G=x[g];if(q&&G===void 0)return;const ee=typeof G;if(ee!==S||G===null)throw new Error(`param "${g}" is invalid: expected ${S}, got ${ee}`)}Object.entries(p).forEach(([g,S])=>k(g,S,!1)),Object.entries(_).forEach(([g,S])=>k(g,S,!0))}const w=()=>{throw new Error("not implemented")};e.notImplemented=w;function H(x){const p=new WeakMap;return(_,...k)=>{const g=p.get(_);if(g!==void 0)return g;const S=x(_,...k);return p.set(_,S),S}}})($t)),$t}var je={},Te={},bn;function wt(){if(bn)return Te;bn=1,Object.defineProperty(Te,"__esModule",{value:!0}),Te.isNegativeLE=void 0,Te.mod=y,Te.pow=B,Te.pow2=v,Te.invert=T,Te.tonelliShanks=b,Te.FpSqrt=P,Te.validateField=U,Te.FpPow=Z,Te.FpInvertBatch=R,Te.FpDiv=C,Te.FpLegendre=j,Te.FpIsSquare=Q,Te.nLength=V,Te.Field=$,Te.FpSqrtOdd=w,Te.FpSqrtEven=H,Te.hashToPrivateScalar=x,Te.getFieldBytesLength=p,Te.getMinHashLength=_,Te.mapHashToField=k;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=at(),t=BigInt(0),n=BigInt(1),i=BigInt(2),c=BigInt(3),o=BigInt(4),a=BigInt(5),u=BigInt(7),h=BigInt(8),l=BigInt(9),m=BigInt(16);function y(g,S){const q=g%S;return q>=t?q:S+q}function B(g,S,q){return Z($(q),g,S)}function v(g,S,q){let G=g;for(;S-- >t;)G*=G,G%=q;return G}function T(g,S){if(g===t)throw new Error("invert: expected non-zero number");if(S<=t)throw new Error("invert: expected positive modulus, got "+S);let q=y(g,S),G=S,ee=t,ne=n;for(;q!==t;){const L=G/q,D=G%q,re=ee-ne*L;G=q,q=D,ee=ne,ne=re}if(G!==n)throw new Error("invert: does not exist");return y(ee,S)}function N(g,S,q){if(!g.eql(g.sqr(S),q))throw new Error("Cannot find square root")}function K(g,S){const q=(g.ORDER+n)/o,G=g.pow(S,q);return N(g,G,S),G}function J(g,S){const q=(g.ORDER-a)/h,G=g.mul(S,i),ee=g.pow(G,q),ne=g.mul(S,ee),ie=g.mul(g.mul(ne,i),ee),L=g.mul(ne,g.sub(ie,g.ONE));return N(g,L,S),L}function F(g){const S=$(g),q=b(g),G=q(S,S.neg(S.ONE)),ee=q(S,G),ne=q(S,S.neg(G)),ie=(g+u)/m;return(L,D)=>{let re=L.pow(D,ie),le=L.mul(re,G);const ce=L.mul(re,ee),W=L.mul(re,ne),oe=L.eql(L.sqr(le),D),be=L.eql(L.sqr(ce),D);re=L.cmov(re,le,oe),le=L.cmov(W,ce,be);const Se=L.eql(L.sqr(le),D),Oe=L.cmov(re,le,Se);return N(L,Oe,D),Oe}}function b(g){if(g<c)throw new Error("sqrt is not defined for small field");let S=g-n,q=0;for(;S%i===t;)S/=i,q++;let G=i;const ee=$(g);for(;j(ee,G)===1;)if(G++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(q===1)return K;let ne=ee.pow(G,S);const ie=(S+n)/i;return function(D,re){if(D.is0(re))return re;if(j(D,re)!==1)throw new Error("Cannot find square root");let le=q,ce=D.mul(D.ONE,ne),W=D.pow(re,S),oe=D.pow(re,ie);for(;!D.eql(W,D.ONE);){if(D.is0(W))return D.ZERO;let be=1,Se=D.sqr(W);for(;!D.eql(Se,D.ONE);)if(be++,Se=D.sqr(Se),be===le)throw new Error("Cannot find square root");const Oe=n<<BigInt(le-be-1),qe=D.pow(ce,Oe);le=be,ce=D.sqr(qe),W=D.mul(W,ce),oe=D.mul(oe,qe)}return oe}}function P(g){return g%o===c?K:g%h===a?J:g%m===l?F(g):b(g)}const I=(g,S)=>(y(g,S)&n)===n;Te.isNegativeLE=I;const O=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function U(g){const S={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},q=O.reduce((G,ee)=>(G[ee]="function",G),S);return(0,e._validateObject)(g,q),g}function Z(g,S,q){if(q<t)throw new Error("invalid exponent, negatives unsupported");if(q===t)return g.ONE;if(q===n)return S;let G=g.ONE,ee=S;for(;q>t;)q&n&&(G=g.mul(G,ee)),ee=g.sqr(ee),q>>=n;return G}function R(g,S,q=!1){const G=new Array(S.length).fill(q?g.ZERO:void 0),ee=S.reduce((ie,L,D)=>g.is0(L)?ie:(G[D]=ie,g.mul(ie,L)),g.ONE),ne=g.inv(ee);return S.reduceRight((ie,L,D)=>g.is0(L)?ie:(G[D]=g.mul(ie,G[D]),g.mul(ie,L)),ne),G}function C(g,S,q){return g.mul(S,typeof q=="bigint"?T(q,g.ORDER):g.inv(q))}function j(g,S){const q=(g.ORDER-n)/i,G=g.pow(S,q),ee=g.eql(G,g.ONE),ne=g.eql(G,g.ZERO),ie=g.eql(G,g.neg(g.ONE));if(!ee&&!ne&&!ie)throw new Error("invalid Legendre symbol result");return ee?1:ne?0:-1}function Q(g,S){return j(g,S)===1}function V(g,S){S!==void 0&&(0,e.anumber)(S);const q=S!==void 0?S:g.toString(2).length,G=Math.ceil(q/8);return{nBitLength:q,nByteLength:G}}function $(g,S,q=!1,G={}){if(g<=t)throw new Error("invalid field: expected ORDER > 0, got "+g);let ee,ne,ie=!1,L;if(typeof S=="object"&&S!=null){if(G.sqrt||q)throw new Error("cannot specify opts in two arguments");const W=S;W.BITS&&(ee=W.BITS),W.sqrt&&(ne=W.sqrt),typeof W.isLE=="boolean"&&(q=W.isLE),typeof W.modFromBytes=="boolean"&&(ie=W.modFromBytes),L=W.allowedLengths}else typeof S=="number"&&(ee=S),G.sqrt&&(ne=G.sqrt);const{nBitLength:D,nByteLength:re}=V(g,ee);if(re>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let le;const ce=Object.freeze({ORDER:g,isLE:q,BITS:D,BYTES:re,MASK:(0,e.bitMask)(D),ZERO:t,ONE:n,allowedLengths:L,create:W=>y(W,g),isValid:W=>{if(typeof W!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof W);return t<=W&&W<g},is0:W=>W===t,isValidNot0:W=>!ce.is0(W)&&ce.isValid(W),isOdd:W=>(W&n)===n,neg:W=>y(-W,g),eql:(W,oe)=>W===oe,sqr:W=>y(W*W,g),add:(W,oe)=>y(W+oe,g),sub:(W,oe)=>y(W-oe,g),mul:(W,oe)=>y(W*oe,g),pow:(W,oe)=>Z(ce,W,oe),div:(W,oe)=>y(W*T(oe,g),g),sqrN:W=>W*W,addN:(W,oe)=>W+oe,subN:(W,oe)=>W-oe,mulN:(W,oe)=>W*oe,inv:W=>T(W,g),sqrt:ne||(W=>(le||(le=P(g)),le(ce,W))),toBytes:W=>q?(0,e.numberToBytesLE)(W,re):(0,e.numberToBytesBE)(W,re),fromBytes:(W,oe=!0)=>{if(L){if(!L.includes(W.length)||W.length>re)throw new Error("Field.fromBytes: expected "+L+" bytes, got "+W.length);const Se=new Uint8Array(re);Se.set(W,q?0:Se.length-W.length),W=Se}if(W.length!==re)throw new Error("Field.fromBytes: expected "+re+" bytes, got "+W.length);let be=q?(0,e.bytesToNumberLE)(W):(0,e.bytesToNumberBE)(W);if(ie&&(be=y(be,g)),!oe&&!ce.isValid(be))throw new Error("invalid field element: outside of range 0..ORDER");return be},invertBatch:W=>R(ce,W),cmov:(W,oe,be)=>be?oe:W});return Object.freeze(ce)}function w(g,S){if(!g.isOdd)throw new Error("Field doesn't have isOdd");const q=g.sqrt(S);return g.isOdd(q)?q:g.neg(q)}function H(g,S){if(!g.isOdd)throw new Error("Field doesn't have isOdd");const q=g.sqrt(S);return g.isOdd(q)?g.neg(q):q}function x(g,S,q=!1){g=(0,e.ensureBytes)("privateHash",g);const G=g.length,ee=V(S).nByteLength+8;if(ee<24||G<ee||G>1024)throw new Error("hashToPrivateScalar: expected "+ee+"-1024 bytes of input, got "+G);const ne=q?(0,e.bytesToNumberLE)(g):(0,e.bytesToNumberBE)(g);return y(ne,S-n)+n}function p(g){if(typeof g!="bigint")throw new Error("field order must be bigint");const S=g.toString(2).length;return Math.ceil(S/8)}function _(g){const S=p(g);return S+Math.ceil(S/2)}function k(g,S,q=!1){const G=g.length,ee=p(S),ne=_(S);if(G<16||G<ne||G>1024)throw new Error("expected "+ne+"-1024 bytes of input, got "+G);const ie=q?(0,e.bytesToNumberLE)(g):(0,e.bytesToNumberBE)(g),L=y(ie,S-n)+n;return q?(0,e.numberToBytesLE)(L,ee):(0,e.numberToBytesBE)(L,ee)}return Te}var En;function Ur(){if(En)return je;En=1,Object.defineProperty(je,"__esModule",{value:!0}),je.wNAF=void 0,je.negateCt=c,je.normalizeZ=o,je.mulEndoUnsafe=K,je.pippenger=J,je.precomputeMSMUnsafe=F,je.validateBasic=b,je._createCurveFields=I;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=at(),t=wt(),n=BigInt(0),i=BigInt(1);function c(O,U){const Z=U.negate();return O?Z:U}function o(O,U){const Z=(0,t.FpInvertBatch)(O.Fp,U.map(R=>R.Z));return U.map((R,C)=>O.fromAffine(R.toAffine(Z[C])))}function a(O,U){if(!Number.isSafeInteger(O)||O<=0||O>U)throw new Error("invalid window size, expected [1.."+U+"], got W="+O)}function u(O,U){a(O,U);const Z=Math.ceil(U/O)+1,R=2**(O-1),C=2**O,j=(0,e.bitMask)(O),Q=BigInt(O);return{windows:Z,windowSize:R,mask:j,maxNumber:C,shiftBy:Q}}function h(O,U,Z){const{windowSize:R,mask:C,maxNumber:j,shiftBy:Q}=Z;let V=Number(O&C),$=O>>Q;V>R&&(V-=j,$+=i);const w=U*R,H=w+Math.abs(V)-1,x=V===0,p=V<0,_=U%2!==0;return{nextN:$,offset:H,isZero:x,isNeg:p,isNegF:_,offsetF:w}}function l(O,U){if(!Array.isArray(O))throw new Error("array expected");O.forEach((Z,R)=>{if(!(Z instanceof U))throw new Error("invalid point at index "+R)})}function m(O,U){if(!Array.isArray(O))throw new Error("array of scalars expected");O.forEach((Z,R)=>{if(!U.isValid(Z))throw new Error("invalid scalar at index "+R)})}const y=new WeakMap,B=new WeakMap;function v(O){return B.get(O)||1}function T(O){if(O!==n)throw new Error("invalid wNAF")}class N{constructor(U,Z){this.BASE=U.BASE,this.ZERO=U.ZERO,this.Fn=U.Fn,this.bits=Z}_unsafeLadder(U,Z,R=this.ZERO){let C=U;for(;Z>n;)Z&i&&(R=R.add(C)),C=C.double(),Z>>=i;return R}precomputeWindow(U,Z){const{windows:R,windowSize:C}=u(Z,this.bits),j=[];let Q=U,V=Q;for(let $=0;$<R;$++){V=Q,j.push(V);for(let w=1;w<C;w++)V=V.add(Q),j.push(V);Q=V.double()}return j}wNAF(U,Z,R){if(!this.Fn.isValid(R))throw new Error("invalid scalar");let C=this.ZERO,j=this.BASE;const Q=u(U,this.bits);for(let V=0;V<Q.windows;V++){const{nextN:$,offset:w,isZero:H,isNeg:x,isNegF:p,offsetF:_}=h(R,V,Q);R=$,H?j=j.add(c(p,Z[_])):C=C.add(c(x,Z[w]))}return T(R),{p:C,f:j}}wNAFUnsafe(U,Z,R,C=this.ZERO){const j=u(U,this.bits);for(let Q=0;Q<j.windows&&R!==n;Q++){const{nextN:V,offset:$,isZero:w,isNeg:H}=h(R,Q,j);if(R=V,!w){const x=Z[$];C=C.add(H?x.negate():x)}}return T(R),C}getPrecomputes(U,Z,R){let C=y.get(Z);return C||(C=this.precomputeWindow(Z,U),U!==1&&(typeof R=="function"&&(C=R(C)),y.set(Z,C))),C}cached(U,Z,R){const C=v(U);return this.wNAF(C,this.getPrecomputes(C,U,R),Z)}unsafe(U,Z,R,C){const j=v(U);return j===1?this._unsafeLadder(U,Z,C):this.wNAFUnsafe(j,this.getPrecomputes(j,U,R),Z,C)}createCache(U,Z){a(Z,this.bits),B.set(U,Z),y.delete(U)}hasCache(U){return v(U)!==1}}je.wNAF=N;function K(O,U,Z,R){let C=U,j=O.ZERO,Q=O.ZERO;for(;Z>n||R>n;)Z&i&&(j=j.add(C)),R&i&&(Q=Q.add(C)),C=C.double(),Z>>=i,R>>=i;return{p1:j,p2:Q}}function J(O,U,Z,R){l(Z,O),m(R,U);const C=Z.length,j=R.length;if(C!==j)throw new Error("arrays of points and scalars must have equal length");const Q=O.ZERO,V=(0,e.bitLen)(BigInt(C));let $=1;V>12?$=V-3:V>4?$=V-2:V>0&&($=2);const w=(0,e.bitMask)($),H=new Array(Number(w)+1).fill(Q),x=Math.floor((U.BITS-1)/$)*$;let p=Q;for(let _=x;_>=0;_-=$){H.fill(Q);for(let g=0;g<j;g++){const S=R[g],q=Number(S>>BigInt(_)&w);H[q]=H[q].add(Z[g])}let k=Q;for(let g=H.length-1,S=Q;g>0;g--)S=S.add(H[g]),k=k.add(S);if(p=p.add(k),_!==0)for(let g=0;g<$;g++)p=p.double()}return p}function F(O,U,Z,R){a(R,U.BITS),l(Z,O);const C=O.ZERO,j=2**R-1,Q=Math.ceil(U.BITS/R),V=(0,e.bitMask)(R),$=Z.map(w=>{const H=[];for(let x=0,p=w;x<j;x++)H.push(p),p=p.add(w);return H});return w=>{if(m(w,U),w.length>Z.length)throw new Error("array of scalars must be smaller than array of points");let H=C;for(let x=0;x<Q;x++){if(H!==C)for(let _=0;_<R;_++)H=H.double();const p=BigInt(Q*R-(x+1)*R);for(let _=0;_<w.length;_++){const k=w[_],g=Number(k>>p&V);g&&(H=H.add($[_][g-1]))}}return H}}function b(O){return(0,t.validateField)(O.Fp),(0,e.validateObject)(O,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(O.n,O.nBitLength),...O,p:O.Fp.ORDER})}function P(O,U,Z){if(U){if(U.ORDER!==O)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(U),U}else return(0,t.Field)(O,{isLE:Z})}function I(O,U,Z={},R){if(R===void 0&&(R=O==="edwards"),!U||typeof U!="object")throw new Error(`expected valid ${O} CURVE object`);for(const $ of["p","n","h"]){const w=U[$];if(!(typeof w=="bigint"&&w>n))throw new Error(`CURVE.${$} must be positive bigint`)}const C=P(U.p,Z.Fp,R),j=P(U.n,Z.Fn,R),V=["Gx","Gy","a",O==="weierstrass"?"b":"d"];for(const $ of V)if(!C.isValid(U[$]))throw new Error(`CURVE.${$} must be valid field element of CURVE.Fp`);return U=Object.freeze(Object.assign({},U)),{CURVE:U,Fp:C,Fn:j}}return je}var Bn;function _n(){return Bn||(Bn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=u,e._normFnElement=K,e.weierstrassN=J,e.SWUFpSqrtRatio=b,e.mapToCurveSimpleSWU=P,e.ecdh=O,e.ecdsa=U,e.weierstrassPoints=Z,e._legacyHelperEquat=j,e.weierstrass=$;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Hr(),n=tt(),i=at(),c=Ur(),o=wt(),a=(w,H)=>(w+(w>=0?H:-H)/v)/H;function u(w,H,x){const[[p,_],[k,g]]=H,S=a(g*w,x),q=a(-_*w,x);let G=w-S*p-q*k,ee=-S*_-q*g;const ne=G<y,ie=ee<y;ne&&(G=-G),ie&&(ee=-ee);const L=(0,i.bitMask)(Math.ceil((0,i.bitLen)(x)/2))+B;if(G<y||G>=L||ee<y||ee>=L)throw new Error("splitScalar (endomorphism): failed, k="+w);return{k1neg:ne,k1:G,k2neg:ie,k2:ee}}function h(w){if(!["compact","recovered","der"].includes(w))throw new Error('Signature format must be "compact", "recovered", or "der"');return w}function l(w,H){const x={};for(let p of Object.keys(H))x[p]=w[p]===void 0?H[p]:w[p];return(0,i._abool2)(x.lowS,"lowS"),(0,i._abool2)(x.prehash,"prehash"),x.format!==void 0&&h(x.format),x}class m extends Error{constructor(H=""){super(H)}}e.DERErr=m,e.DER={Err:m,_tlv:{encode:(w,H)=>{const{Err:x}=e.DER;if(w<0||w>256)throw new x("tlv.encode: wrong tag");if(H.length&1)throw new x("tlv.encode: unpadded data");const p=H.length/2,_=(0,i.numberToHexUnpadded)(p);if(_.length/2&128)throw new x("tlv.encode: long form length too big");const k=p>127?(0,i.numberToHexUnpadded)(_.length/2|128):"";return(0,i.numberToHexUnpadded)(w)+k+_+H},decode(w,H){const{Err:x}=e.DER;let p=0;if(w<0||w>256)throw new x("tlv.encode: wrong tag");if(H.length<2||H[p++]!==w)throw new x("tlv.decode: wrong tlv");const _=H[p++],k=!!(_&128);let g=0;if(!k)g=_;else{const q=_&127;if(!q)throw new x("tlv.decode(long): indefinite length not supported");if(q>4)throw new x("tlv.decode(long): byte length is too big");const G=H.subarray(p,p+q);if(G.length!==q)throw new x("tlv.decode: length bytes not complete");if(G[0]===0)throw new x("tlv.decode(long): zero leftmost byte");for(const ee of G)g=g<<8|ee;if(p+=q,g<128)throw new x("tlv.decode(long): not minimal encoding")}const S=H.subarray(p,p+g);if(S.length!==g)throw new x("tlv.decode: wrong value length");return{v:S,l:H.subarray(p+g)}}},_int:{encode(w){const{Err:H}=e.DER;if(w<y)throw new H("integer: negative integers are not allowed");let x=(0,i.numberToHexUnpadded)(w);if(Number.parseInt(x[0],16)&8&&(x="00"+x),x.length&1)throw new H("unexpected DER parsing assertion: unpadded hex");return x},decode(w){const{Err:H}=e.DER;if(w[0]&128)throw new H("invalid signature integer: negative");if(w[0]===0&&!(w[1]&128))throw new H("invalid signature integer: unnecessary leading zero");return(0,i.bytesToNumberBE)(w)}},toSig(w){const{Err:H,_int:x,_tlv:p}=e.DER,_=(0,i.ensureBytes)("signature",w),{v:k,l:g}=p.decode(48,_);if(g.length)throw new H("invalid signature: left bytes after parsing");const{v:S,l:q}=p.decode(2,k),{v:G,l:ee}=p.decode(2,q);if(ee.length)throw new H("invalid signature: left bytes after parsing");return{r:x.decode(S),s:x.decode(G)}},hexFromSig(w){const{_tlv:H,_int:x}=e.DER,p=H.encode(2,x.encode(w.r)),_=H.encode(2,x.encode(w.s)),k=p+_;return H.encode(48,k)}};const y=BigInt(0),B=BigInt(1),v=BigInt(2),T=BigInt(3),N=BigInt(4);function K(w,H){const{BYTES:x}=w;let p;if(typeof H=="bigint")p=H;else{let _=(0,i.ensureBytes)("private key",H);try{p=w.fromBytes(_)}catch{throw new Error(`invalid private key: expected ui8a of size ${x}, got ${typeof H}`)}}if(!w.isValidNot0(p))throw new Error("invalid private key: out of range [1..N-1]");return p}function J(w,H={}){const x=(0,c._createCurveFields)("weierstrass",w,H),{Fp:p,Fn:_}=x;let k=x.CURVE;const{h:g,n:S}=k;(0,i._validateObject)(H,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:q}=H;if(q&&(!p.is0(k.a)||typeof q.beta!="bigint"||!Array.isArray(q.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const G=I(p,_);function ee(){if(!p.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function ne(Be,te,Y){const{x:z,y:f}=te.toAffine(),r=p.toBytes(z);if((0,i._abool2)(Y,"isCompressed"),Y){ee();const s=!p.isOdd(f);return(0,i.concatBytes)(F(s),r)}else return(0,i.concatBytes)(Uint8Array.of(4),r,p.toBytes(f))}function ie(Be){(0,i._abytes2)(Be,void 0,"Point");const{publicKey:te,publicKeyUncompressed:Y}=G,z=Be.length,f=Be[0],r=Be.subarray(1);if(z===te&&(f===2||f===3)){const s=p.fromBytes(r);if(!p.isValid(s))throw new Error("bad point: is not on curve, wrong x");const d=re(s);let E;try{E=p.sqrt(d)}catch(ue){const de=ue instanceof Error?": "+ue.message:"";throw new Error("bad point: is not on curve, sqrt error"+de)}ee();const A=p.isOdd(E);return(f&1)===1!==A&&(E=p.neg(E)),{x:s,y:E}}else if(z===Y&&f===4){const s=p.BYTES,d=p.fromBytes(r.subarray(0,s)),E=p.fromBytes(r.subarray(s,s*2));if(!le(d,E))throw new Error("bad point: is not on curve");return{x:d,y:E}}else throw new Error(`bad point: got length ${z}, expected compressed=${te} or uncompressed=${Y}`)}const L=H.toBytes||ne,D=H.fromBytes||ie;function re(Be){const te=p.sqr(Be),Y=p.mul(te,Be);return p.add(p.add(Y,p.mul(Be,k.a)),k.b)}function le(Be,te){const Y=p.sqr(te),z=re(Be);return p.eql(Y,z)}if(!le(k.Gx,k.Gy))throw new Error("bad curve params: generator point");const ce=p.mul(p.pow(k.a,T),N),W=p.mul(p.sqr(k.b),BigInt(27));if(p.is0(p.add(ce,W)))throw new Error("bad curve params: a or b");function oe(Be,te,Y=!1){if(!p.isValid(te)||Y&&p.is0(te))throw new Error(`bad point coordinate ${Be}`);return te}function be(Be){if(!(Be instanceof Ee))throw new Error("ProjectivePoint expected")}function Se(Be){if(!q||!q.basises)throw new Error("no endo");return u(Be,q.basises,_.ORDER)}const Oe=(0,i.memoized)((Be,te)=>{const{X:Y,Y:z,Z:f}=Be;if(p.eql(f,p.ONE))return{x:Y,y:z};const r=Be.is0();te==null&&(te=r?p.ONE:p.inv(f));const s=p.mul(Y,te),d=p.mul(z,te),E=p.mul(f,te);if(r)return{x:p.ZERO,y:p.ZERO};if(!p.eql(E,p.ONE))throw new Error("invZ was invalid");return{x:s,y:d}}),qe=(0,i.memoized)(Be=>{if(Be.is0()){if(H.allowInfinityPoint&&!p.is0(Be.Y))return;throw new Error("bad point: ZERO")}const{x:te,y:Y}=Be.toAffine();if(!p.isValid(te)||!p.isValid(Y))throw new Error("bad point: x or y not field elements");if(!le(te,Y))throw new Error("bad point: equation left != right");if(!Be.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function ke(Be,te,Y,z,f){return Y=new Ee(p.mul(Y.X,Be),Y.Y,Y.Z),te=(0,c.negateCt)(z,te),Y=(0,c.negateCt)(f,Y),te.add(Y)}class Ee{constructor(te,Y,z){this.X=oe("x",te),this.Y=oe("y",Y,!0),this.Z=oe("z",z),Object.freeze(this)}static CURVE(){return k}static fromAffine(te){const{x:Y,y:z}=te||{};if(!te||!p.isValid(Y)||!p.isValid(z))throw new Error("invalid affine point");if(te instanceof Ee)throw new Error("projective point not allowed");return p.is0(Y)&&p.is0(z)?Ee.ZERO:new Ee(Y,z,p.ONE)}static fromBytes(te){const Y=Ee.fromAffine(D((0,i._abytes2)(te,void 0,"point")));return Y.assertValidity(),Y}static fromHex(te){return Ee.fromBytes((0,i.ensureBytes)("pointHex",te))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(te=8,Y=!0){return He.createCache(this,te),Y||this.multiply(T),this}assertValidity(){qe(this)}hasEvenY(){const{y:te}=this.toAffine();if(!p.isOdd)throw new Error("Field doesn't support isOdd");return!p.isOdd(te)}equals(te){be(te);const{X:Y,Y:z,Z:f}=this,{X:r,Y:s,Z:d}=te,E=p.eql(p.mul(Y,d),p.mul(r,f)),A=p.eql(p.mul(z,d),p.mul(s,f));return E&&A}negate(){return new Ee(this.X,p.neg(this.Y),this.Z)}double(){const{a:te,b:Y}=k,z=p.mul(Y,T),{X:f,Y:r,Z:s}=this;let d=p.ZERO,E=p.ZERO,A=p.ZERO,M=p.mul(f,f),ue=p.mul(r,r),de=p.mul(s,s),ae=p.mul(f,r);return ae=p.add(ae,ae),A=p.mul(f,s),A=p.add(A,A),d=p.mul(te,A),E=p.mul(z,de),E=p.add(d,E),d=p.sub(ue,E),E=p.add(ue,E),E=p.mul(d,E),d=p.mul(ae,d),A=p.mul(z,A),de=p.mul(te,de),ae=p.sub(M,de),ae=p.mul(te,ae),ae=p.add(ae,A),A=p.add(M,M),M=p.add(A,M),M=p.add(M,de),M=p.mul(M,ae),E=p.add(E,M),de=p.mul(r,s),de=p.add(de,de),M=p.mul(de,ae),d=p.sub(d,M),A=p.mul(de,ue),A=p.add(A,A),A=p.add(A,A),new Ee(d,E,A)}add(te){be(te);const{X:Y,Y:z,Z:f}=this,{X:r,Y:s,Z:d}=te;let E=p.ZERO,A=p.ZERO,M=p.ZERO;const ue=k.a,de=p.mul(k.b,T);let ae=p.mul(Y,r),ye=p.mul(z,s),pe=p.mul(f,d),Ve=p.add(Y,z),Re=p.add(r,s);Ve=p.mul(Ve,Re),Re=p.add(ae,ye),Ve=p.sub(Ve,Re),Re=p.add(Y,f);let Me=p.add(r,d);return Re=p.mul(Re,Me),Me=p.add(ae,pe),Re=p.sub(Re,Me),Me=p.add(z,f),E=p.add(s,d),Me=p.mul(Me,E),E=p.add(ye,pe),Me=p.sub(Me,E),M=p.mul(ue,Re),E=p.mul(de,pe),M=p.add(E,M),E=p.sub(ye,M),M=p.add(ye,M),A=p.mul(E,M),ye=p.add(ae,ae),ye=p.add(ye,ae),pe=p.mul(ue,pe),Re=p.mul(de,Re),ye=p.add(ye,pe),pe=p.sub(ae,pe),pe=p.mul(ue,pe),Re=p.add(Re,pe),ae=p.mul(ye,Re),A=p.add(A,ae),ae=p.mul(Me,Re),E=p.mul(Ve,E),E=p.sub(E,ae),ae=p.mul(Ve,ye),M=p.mul(Me,M),M=p.add(M,ae),new Ee(E,A,M)}subtract(te){return this.add(te.negate())}is0(){return this.equals(Ee.ZERO)}multiply(te){const{endo:Y}=H;if(!_.isValidNot0(te))throw new Error("invalid scalar: out of range");let z,f;const r=s=>He.cached(this,s,d=>(0,c.normalizeZ)(Ee,d));if(Y){const{k1neg:s,k1:d,k2neg:E,k2:A}=Se(te),{p:M,f:ue}=r(d),{p:de,f:ae}=r(A);f=ue.add(ae),z=ke(Y.beta,M,de,s,E)}else{const{p:s,f:d}=r(te);z=s,f=d}return(0,c.normalizeZ)(Ee,[z,f])[0]}multiplyUnsafe(te){const{endo:Y}=H,z=this;if(!_.isValid(te))throw new Error("invalid scalar: out of range");if(te===y||z.is0())return Ee.ZERO;if(te===B)return z;if(He.hasCache(this))return this.multiply(te);if(Y){const{k1neg:f,k1:r,k2neg:s,k2:d}=Se(te),{p1:E,p2:A}=(0,c.mulEndoUnsafe)(Ee,z,r,d);return ke(Y.beta,E,A,f,s)}else return He.unsafe(z,te)}multiplyAndAddUnsafe(te,Y,z){const f=this.multiplyUnsafe(Y).add(te.multiplyUnsafe(z));return f.is0()?void 0:f}toAffine(te){return Oe(this,te)}isTorsionFree(){const{isTorsionFree:te}=H;return g===B?!0:te?te(Ee,this):He.unsafe(this,S).is0()}clearCofactor(){const{clearCofactor:te}=H;return g===B?this:te?te(Ee,this):this.multiplyUnsafe(g)}isSmallOrder(){return this.multiplyUnsafe(g).is0()}toBytes(te=!0){return(0,i._abool2)(te,"isCompressed"),this.assertValidity(),L(Ee,this,te)}toHex(te=!0){return(0,i.bytesToHex)(this.toBytes(te))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(te=!0){return this.toBytes(te)}_setWindowSize(te){this.precompute(te)}static normalizeZ(te){return(0,c.normalizeZ)(Ee,te)}static msm(te,Y){return(0,c.pippenger)(Ee,_,te,Y)}static fromPrivateKey(te){return Ee.BASE.multiply(K(_,te))}}Ee.BASE=new Ee(k.Gx,k.Gy,p.ONE),Ee.ZERO=new Ee(p.ZERO,p.ONE,p.ZERO),Ee.Fp=p,Ee.Fn=_;const Ke=_.BITS,He=new c.wNAF(Ee,H.endo?Math.ceil(Ke/2):Ke);return Ee.BASE.precompute(8),Ee}function F(w){return Uint8Array.of(w?2:3)}function b(w,H){const x=w.ORDER;let p=y;for(let D=x-B;D%v===y;D/=v)p+=B;const _=p,k=v<<_-B-B,g=k*v,S=(x-B)/g,q=(S-B)/v,G=g-B,ee=k,ne=w.pow(H,S),ie=w.pow(H,(S+B)/v);let L=(D,re)=>{let le=ne,ce=w.pow(re,G),W=w.sqr(ce);W=w.mul(W,re);let oe=w.mul(D,W);oe=w.pow(oe,q),oe=w.mul(oe,ce),ce=w.mul(oe,re),W=w.mul(oe,D);let be=w.mul(W,ce);oe=w.pow(be,ee);let Se=w.eql(oe,w.ONE);ce=w.mul(W,ie),oe=w.mul(be,le),W=w.cmov(ce,W,Se),be=w.cmov(oe,be,Se);for(let Oe=_;Oe>B;Oe--){let qe=Oe-v;qe=v<<qe-B;let ke=w.pow(be,qe);const Ee=w.eql(ke,w.ONE);ce=w.mul(W,le),le=w.mul(le,le),ke=w.mul(be,le),W=w.cmov(ce,W,Ee),be=w.cmov(ke,be,Ee)}return{isValid:Se,value:W}};if(w.ORDER%N===T){const D=(w.ORDER-T)/N,re=w.sqrt(w.neg(H));L=(le,ce)=>{let W=w.sqr(ce);const oe=w.mul(le,ce);W=w.mul(W,oe);let be=w.pow(W,D);be=w.mul(be,oe);const Se=w.mul(be,re),Oe=w.mul(w.sqr(be),ce),qe=w.eql(Oe,le);let ke=w.cmov(Se,be,qe);return{isValid:qe,value:ke}}}return L}function P(w,H){(0,o.validateField)(w);const{A:x,B:p,Z:_}=H;if(!w.isValid(x)||!w.isValid(p)||!w.isValid(_))throw new Error("mapToCurveSimpleSWU: invalid opts");const k=b(w,_);if(!w.isOdd)throw new Error("Field does not have .isOdd()");return g=>{let S,q,G,ee,ne,ie,L,D;S=w.sqr(g),S=w.mul(S,_),q=w.sqr(S),q=w.add(q,S),G=w.add(q,w.ONE),G=w.mul(G,p),ee=w.cmov(_,w.neg(q),!w.eql(q,w.ZERO)),ee=w.mul(ee,x),q=w.sqr(G),ie=w.sqr(ee),ne=w.mul(ie,x),q=w.add(q,ne),q=w.mul(q,G),ie=w.mul(ie,ee),ne=w.mul(ie,p),q=w.add(q,ne),L=w.mul(S,G);const{isValid:re,value:le}=k(q,ie);D=w.mul(S,g),D=w.mul(D,le),L=w.cmov(L,G,re),D=w.cmov(D,le,re);const ce=w.isOdd(g)===w.isOdd(D);D=w.cmov(w.neg(D),D,ce);const W=(0,o.FpInvertBatch)(w,[ee],!0)[0];return L=w.mul(L,W),{x:L,y:D}}}function I(w,H){return{secretKey:H.BYTES,publicKey:1+w.BYTES,publicKeyUncompressed:1+2*w.BYTES,publicKeyHasPrefix:!0,signature:2*H.BYTES}}function O(w,H={}){const{Fn:x}=w,p=H.randomBytes||i.randomBytes,_=Object.assign(I(w.Fp,x),{seed:(0,o.getMinHashLength)(x.ORDER)});function k(L){try{return!!K(x,L)}catch{return!1}}function g(L,D){const{publicKey:re,publicKeyUncompressed:le}=_;try{const ce=L.length;return D===!0&&ce!==re||D===!1&&ce!==le?!1:!!w.fromBytes(L)}catch{return!1}}function S(L=p(_.seed)){return(0,o.mapHashToField)((0,i._abytes2)(L,_.seed,"seed"),x.ORDER)}function q(L,D=!0){return w.BASE.multiply(K(x,L)).toBytes(D)}function G(L){const D=S(L);return{secretKey:D,publicKey:q(D)}}function ee(L){if(typeof L=="bigint")return!1;if(L instanceof w)return!0;const{secretKey:D,publicKey:re,publicKeyUncompressed:le}=_;if(x.allowedLengths||D===re)return;const ce=(0,i.ensureBytes)("key",L).length;return ce===re||ce===le}function ne(L,D,re=!0){if(ee(L)===!0)throw new Error("first arg must be private key");if(ee(D)===!1)throw new Error("second arg must be public key");const le=K(x,L);return w.fromHex(D).multiply(le).toBytes(re)}return Object.freeze({getPublicKey:q,getSharedSecret:ne,keygen:G,Point:w,utils:{isValidSecretKey:k,isValidPublicKey:g,randomSecretKey:S,isValidPrivateKey:k,randomPrivateKey:S,normPrivateKeyToScalar:L=>K(x,L),precompute(L=8,D=w.BASE){return D.precompute(L,!1)}},lengths:_})}function U(w,H,x={}){(0,n.ahash)(H),(0,i._validateObject)(x,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const p=x.randomBytes||i.randomBytes,_=x.hmac||((Y,...z)=>(0,t.hmac)(H,Y,(0,i.concatBytes)(...z))),{Fp:k,Fn:g}=w,{ORDER:S,BITS:q}=g,{keygen:G,getPublicKey:ee,getSharedSecret:ne,utils:ie,lengths:L}=O(w,x),D={prehash:!1,lowS:typeof x.lowS=="boolean"?x.lowS:!1,format:void 0,extraEntropy:!1},re="compact";function le(Y){const z=S>>B;return Y>z}function ce(Y,z){if(!g.isValidNot0(z))throw new Error(`invalid signature ${Y}: out of range 1..Point.Fn.ORDER`);return z}function W(Y,z){h(z);const f=L.signature,r=z==="compact"?f:z==="recovered"?f+1:void 0;return(0,i._abytes2)(Y,r,`${z} signature`)}class oe{constructor(z,f,r){this.r=ce("r",z),this.s=ce("s",f),r!=null&&(this.recovery=r),Object.freeze(this)}static fromBytes(z,f=re){W(z,f);let r;if(f==="der"){const{r:A,s:M}=e.DER.toSig((0,i._abytes2)(z));return new oe(A,M)}f==="recovered"&&(r=z[0],f="compact",z=z.subarray(1));const s=g.BYTES,d=z.subarray(0,s),E=z.subarray(s,s*2);return new oe(g.fromBytes(d),g.fromBytes(E),r)}static fromHex(z,f){return this.fromBytes((0,i.hexToBytes)(z),f)}addRecoveryBit(z){return new oe(this.r,this.s,z)}recoverPublicKey(z){const f=k.ORDER,{r,s,recovery:d}=this;if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");if(S*v<f&&d>1)throw new Error("recovery id is ambiguous for h>1 curve");const A=d===2||d===3?r+S:r;if(!k.isValid(A))throw new Error("recovery id 2 or 3 invalid");const M=k.toBytes(A),ue=w.fromBytes((0,i.concatBytes)(F((d&1)===0),M)),de=g.inv(A),ae=Se((0,i.ensureBytes)("msgHash",z)),ye=g.create(-ae*de),pe=g.create(s*de),Ve=w.BASE.multiplyUnsafe(ye).add(ue.multiplyUnsafe(pe));if(Ve.is0())throw new Error("point at infinify");return Ve.assertValidity(),Ve}hasHighS(){return le(this.s)}toBytes(z=re){if(h(z),z==="der")return(0,i.hexToBytes)(e.DER.hexFromSig(this));const f=g.toBytes(this.r),r=g.toBytes(this.s);if(z==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,i.concatBytes)(Uint8Array.of(this.recovery),f,r)}return(0,i.concatBytes)(f,r)}toHex(z){return(0,i.bytesToHex)(this.toBytes(z))}assertValidity(){}static fromCompact(z){return oe.fromBytes((0,i.ensureBytes)("sig",z),"compact")}static fromDER(z){return oe.fromBytes((0,i.ensureBytes)("sig",z),"der")}normalizeS(){return this.hasHighS()?new oe(this.r,g.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,i.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,i.bytesToHex)(this.toBytes("compact"))}}const be=x.bits2int||function(z){if(z.length>8192)throw new Error("input is too large");const f=(0,i.bytesToNumberBE)(z),r=z.length*8-q;return r>0?f>>BigInt(r):f},Se=x.bits2int_modN||function(z){return g.create(be(z))},Oe=(0,i.bitMask)(q);function qe(Y){return(0,i.aInRange)("num < 2^"+q,Y,y,Oe),g.toBytes(Y)}function ke(Y,z){return(0,i._abytes2)(Y,void 0,"message"),z?(0,i._abytes2)(H(Y),void 0,"prehashed message"):Y}function Ee(Y,z,f){if(["recovered","canonical"].some(ye=>ye in f))throw new Error("sign() legacy options not supported");const{lowS:r,prehash:s,extraEntropy:d}=l(f,D);Y=ke(Y,s);const E=Se(Y),A=K(g,z),M=[qe(A),qe(E)];if(d!=null&&d!==!1){const ye=d===!0?p(L.secretKey):d;M.push((0,i.ensureBytes)("extraEntropy",ye))}const ue=(0,i.concatBytes)(...M),de=E;function ae(ye){const pe=be(ye);if(!g.isValidNot0(pe))return;const Ve=g.inv(pe),Re=w.BASE.multiply(pe).toAffine(),Me=g.create(Re.x);if(Me===y)return;const Pt=g.create(Ve*g.create(de+Me*A));if(Pt===y)return;let hr=(Re.x===Me?0:2)|Number(Re.y&B),dr=Pt;return r&&le(Pt)&&(dr=g.neg(Pt),hr^=1),new oe(Me,dr,hr)}return{seed:ue,k2sig:ae}}function Ke(Y,z,f={}){Y=(0,i.ensureBytes)("message",Y);const{seed:r,k2sig:s}=Ee(Y,z,f);return(0,i.createHmacDrbg)(H.outputLen,g.BYTES,_)(r,s)}function He(Y){let z;const f=typeof Y=="string"||(0,i.isBytes)(Y),r=!f&&Y!==null&&typeof Y=="object"&&typeof Y.r=="bigint"&&typeof Y.s=="bigint";if(!f&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)z=new oe(Y.r,Y.s);else if(f){try{z=oe.fromBytes((0,i.ensureBytes)("sig",Y),"der")}catch(s){if(!(s instanceof e.DER.Err))throw s}if(!z)try{z=oe.fromBytes((0,i.ensureBytes)("sig",Y),"compact")}catch{return!1}}return z||!1}function Be(Y,z,f,r={}){const{lowS:s,prehash:d,format:E}=l(r,D);if(f=(0,i.ensureBytes)("publicKey",f),z=ke((0,i.ensureBytes)("message",z),d),"strict"in r)throw new Error("options.strict was renamed to lowS");const A=E===void 0?He(Y):oe.fromBytes((0,i.ensureBytes)("sig",Y),E);if(A===!1)return!1;try{const M=w.fromBytes(f);if(s&&A.hasHighS())return!1;const{r:ue,s:de}=A,ae=Se(z),ye=g.inv(de),pe=g.create(ae*ye),Ve=g.create(ue*ye),Re=w.BASE.multiplyUnsafe(pe).add(M.multiplyUnsafe(Ve));return Re.is0()?!1:g.create(Re.x)===ue}catch{return!1}}function te(Y,z,f={}){const{prehash:r}=l(f,D);return z=ke(z,r),oe.fromBytes(Y,"recovered").recoverPublicKey(z).toBytes()}return Object.freeze({keygen:G,getPublicKey:ee,getSharedSecret:ne,utils:ie,lengths:L,Point:w,sign:Ke,verify:Be,recoverPublicKey:te,Signature:oe,hash:H})}function Z(w){const{CURVE:H,curveOpts:x}=R(w),p=J(H,x);return Q(w,p)}function R(w){const H={a:w.a,b:w.b,p:w.Fp.ORDER,n:w.n,h:w.h,Gx:w.Gx,Gy:w.Gy},x=w.Fp;let p=w.allowedPrivateKeyLengths?Array.from(new Set(w.allowedPrivateKeyLengths.map(g=>Math.ceil(g/2)))):void 0;const _=(0,o.Field)(H.n,{BITS:w.nBitLength,allowedLengths:p,modFromBytes:w.wrapPrivateKey}),k={Fp:x,Fn:_,allowInfinityPoint:w.allowInfinityPoint,endo:w.endo,isTorsionFree:w.isTorsionFree,clearCofactor:w.clearCofactor,fromBytes:w.fromBytes,toBytes:w.toBytes};return{CURVE:H,curveOpts:k}}function C(w){const{CURVE:H,curveOpts:x}=R(w),p={hmac:w.hmac,randomBytes:w.randomBytes,lowS:w.lowS,bits2int:w.bits2int,bits2int_modN:w.bits2int_modN};return{CURVE:H,curveOpts:x,hash:w.hash,ecdsaOpts:p}}function j(w,H,x){function p(_){const k=w.sqr(_),g=w.mul(k,_);return w.add(w.add(g,w.mul(_,H)),x)}return p}function Q(w,H){const{Fp:x,Fn:p}=H;function _(g){return(0,i.inRange)(g,B,p.ORDER)}const k=j(x,w.a,w.b);return Object.assign({},{CURVE:w,Point:H,ProjectivePoint:H,normPrivateKeyToScalar:g=>K(p,g),weierstrassEquation:k,isWithinCurveOrder:_})}function V(w,H){const x=H.Point;return Object.assign({},H,{ProjectivePoint:x,CURVE:Object.assign({},w,(0,o.nLength)(x.Fn.ORDER,x.Fn.BITS))})}function $(w){const{CURVE:H,curveOpts:x,hash:p,ecdsaOpts:_}=C(w),k=J(H,x),g=U(k,p,_);return V(w,g)}})(Vt)),Vt}var xn;function qr(){if(xn)return mt;xn=1,Object.defineProperty(mt,"__esModule",{value:!0}),mt.getHash=t,mt.createCurve=n;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=_n();function t(i){return{hash:i}}function n(i,c){const o=a=>(0,e.weierstrass)({...i,hash:a});return{...o(c),create:o}}return mt}var Zt={},vn;function Pr(){return vn||(vn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=h,e.expand_message_xof=l,e.hash_to_field=m,e.isogenyMap=y,e.createHasher=B;const t=at(),n=wt(),i=t.bytesToNumberBE;function c(v,T){if(a(v),a(T),v<0||v>=1<<8*T)throw new Error("invalid I2OSP input: "+v);const N=Array.from({length:T}).fill(0);for(let K=T-1;K>=0;K--)N[K]=v&255,v>>>=8;return new Uint8Array(N)}function o(v,T){const N=new Uint8Array(v.length);for(let K=0;K<v.length;K++)N[K]=v[K]^T[K];return N}function a(v){if(!Number.isSafeInteger(v))throw new Error("number expected")}function u(v){if(!(0,t.isBytes)(v)&&typeof v!="string")throw new Error("DST must be Uint8Array or string");return typeof v=="string"?(0,t.utf8ToBytes)(v):v}function h(v,T,N,K){(0,t.abytes)(v),a(N),T=u(T),T.length>255&&(T=K((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),T)));const{outputLen:J,blockLen:F}=K,b=Math.ceil(N/J);if(N>65535||b>255)throw new Error("expand_message_xmd: invalid lenInBytes");const P=(0,t.concatBytes)(T,c(T.length,1)),I=c(0,F),O=c(N,2),U=new Array(b),Z=K((0,t.concatBytes)(I,v,O,c(0,1),P));U[0]=K((0,t.concatBytes)(Z,c(1,1),P));for(let C=1;C<=b;C++){const j=[o(Z,U[C-1]),c(C+1,1),P];U[C]=K((0,t.concatBytes)(...j))}return(0,t.concatBytes)(...U).slice(0,N)}function l(v,T,N,K,J){if((0,t.abytes)(v),a(N),T=u(T),T.length>255){const F=Math.ceil(2*K/8);T=J.create({dkLen:F}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(T).digest()}if(N>65535||T.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return J.create({dkLen:N}).update(v).update(c(N,2)).update(T).update(c(T.length,1)).digest()}function m(v,T,N){(0,t._validateObject)(N,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:K,k:J,m:F,hash:b,expand:P,DST:I}=N;if(!(0,t.isHash)(N.hash))throw new Error("expected valid hash");(0,t.abytes)(v),a(T);const O=K.toString(2).length,U=Math.ceil((O+J)/8),Z=T*F*U;let R;if(P==="xmd")R=h(v,I,Z,b);else if(P==="xof")R=l(v,I,Z,J,b);else if(P==="_internal_pass")R=v;else throw new Error('expand must be "xmd" or "xof"');const C=new Array(T);for(let j=0;j<T;j++){const Q=new Array(F);for(let V=0;V<F;V++){const $=U*(V+j*F),w=R.subarray($,$+U);Q[V]=(0,n.mod)(i(w),K)}C[j]=Q}return C}function y(v,T){const N=T.map(K=>Array.from(K).reverse());return(K,J)=>{const[F,b,P,I]=N.map(Z=>Z.reduce((R,C)=>v.add(v.mul(R,K),C))),[O,U]=(0,n.FpInvertBatch)(v,[b,I],!0);return K=v.mul(F,O),J=v.mul(J,v.mul(P,U)),{x:K,y:J}}}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-");function B(v,T,N){if(typeof T!="function")throw new Error("mapToCurve() must be defined");function K(F){return v.fromAffine(T(F))}function J(F){const b=F.clearCofactor();return b.equals(v.ZERO)?v.ZERO:(b.assertValidity(),b)}return{defaults:N,hashToCurve(F,b){const P=Object.assign({},N,b),I=m(F,2,P),O=K(I[0]),U=K(I[1]);return J(O.add(U))},encodeToCurve(F,b){const P=N.encodeDST?{DST:N.encodeDST}:{},I=Object.assign({},N,P,b),O=m(F,1,I),U=K(O[0]);return J(U)},mapToCurve(F){if(!Array.isArray(F))throw new Error("expected array of bigints");for(const b of F)if(typeof b!="bigint")throw new Error("expected array of bigints");return J(K(F))},hashToScalar(F,b){const P=v.Fn.ORDER,I=Object.assign({},N,{p:P,m:1,DST:e._DST_scalar},b);return m(F,1,I)[0][0]}}}})(Zt)),Zt}var Sn;function Cr(){return Sn||(Sn=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=Or(),n=tt(),i=qr(),c=Pr(),o=wt(),a=_n(),u=at(),h={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},m=BigInt(0),y=BigInt(1),B=BigInt(2);function v(V){const $=h.p,w=BigInt(3),H=BigInt(6),x=BigInt(11),p=BigInt(22),_=BigInt(23),k=BigInt(44),g=BigInt(88),S=V*V*V%$,q=S*S*V%$,G=(0,o.pow2)(q,w,$)*q%$,ee=(0,o.pow2)(G,w,$)*q%$,ne=(0,o.pow2)(ee,B,$)*S%$,ie=(0,o.pow2)(ne,x,$)*ne%$,L=(0,o.pow2)(ie,p,$)*ie%$,D=(0,o.pow2)(L,k,$)*L%$,re=(0,o.pow2)(D,g,$)*D%$,le=(0,o.pow2)(re,k,$)*L%$,ce=(0,o.pow2)(le,w,$)*q%$,W=(0,o.pow2)(ce,_,$)*ie%$,oe=(0,o.pow2)(W,H,$)*S%$,be=(0,o.pow2)(oe,B,$);if(!T.eql(T.sqr(be),V))throw new Error("Cannot find square root");return be}const T=(0,o.Field)(h.p,{sqrt:v});e.secp256k1=(0,i.createCurve)({...h,Fp:T,lowS:!0,endo:l},t.sha256);const N={};function K(V,...$){let w=N[V];if(w===void 0){const H=(0,t.sha256)((0,u.utf8ToBytes)(V));w=(0,u.concatBytes)(H,H),N[V]=w}return(0,t.sha256)((0,u.concatBytes)(w,...$))}const J=V=>V.toBytes(!0).slice(1),F=e.secp256k1.Point,b=V=>V%B===m;function P(V){const{Fn:$,BASE:w}=F,H=(0,a._normFnElement)($,V),x=w.multiply(H);return{scalar:b(x.y)?H:$.neg(H),bytes:J(x)}}function I(V){const $=T;if(!$.isValidNot0(V))throw new Error("invalid x: Fail if x ≥ p");const w=$.create(V*V),H=$.create(w*V+BigInt(7));let x=$.sqrt(H);b(x)||(x=$.neg(x));const p=F.fromAffine({x:V,y:x});return p.assertValidity(),p}const O=u.bytesToNumberBE;function U(...V){return F.Fn.create(O(K("BIP0340/challenge",...V)))}function Z(V){return P(V).bytes}function R(V,$,w=(0,n.randomBytes)(32)){const{Fn:H}=F,x=(0,u.ensureBytes)("message",V),{bytes:p,scalar:_}=P($),k=(0,u.ensureBytes)("auxRand",w,32),g=H.toBytes(_^O(K("BIP0340/aux",k))),S=K("BIP0340/nonce",g,p,x),{bytes:q,scalar:G}=P(S),ee=U(q,p,x),ne=new Uint8Array(64);if(ne.set(q,0),ne.set(H.toBytes(H.create(G+ee*_)),32),!C(ne,x,p))throw new Error("sign: Invalid signature produced");return ne}function C(V,$,w){const{Fn:H,BASE:x}=F,p=(0,u.ensureBytes)("signature",V,64),_=(0,u.ensureBytes)("message",$),k=(0,u.ensureBytes)("publicKey",w,32);try{const g=I(O(k)),S=O(p.subarray(0,32));if(!(0,u.inRange)(S,y,h.p))return!1;const q=O(p.subarray(32,64));if(!(0,u.inRange)(q,y,h.n))return!1;const G=U(H.toBytes(S),J(g),_),ee=x.multiplyUnsafe(q).add(g.multiplyUnsafe(H.neg(G))),{x:ne,y:ie}=ee.toAffine();return!(ee.is0()||!b(ie)||ne!==S)}catch{return!1}}e.schnorr=(()=>{const w=(x=(0,n.randomBytes)(48))=>(0,o.mapHashToField)(x,h.n);e.secp256k1.utils.randomSecretKey;function H(x){const p=w(x);return{secretKey:p,publicKey:Z(p)}}return{keygen:H,getPublicKey:Z,sign:R,verify:C,Point:F,utils:{randomSecretKey:w,randomPrivateKey:w,taggedHash:K,lift_x:I,pointToBytes:J,numberToBytesBE:u.numberToBytesBE,bytesToNumberBE:u.bytesToNumberBE,mod:o.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const j=(0,c.isogenyMap)(T,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(V=>V.map($=>BigInt($)))),Q=(0,a.mapToCurveSimpleSWU)(T,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:T.create(BigInt("-11"))});e.secp256k1_hasher=(0,c.createHasher)(e.secp256k1.Point,V=>{const{x:$,y:w}=Q(T.create(V[0]));return j($,w)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:T.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve})(Mt)),Mt}var se={},An;function Ir(){if(An)return se;An=1,Object.defineProperty(se,"__esModule",{value:!0}),se.isHash=se.validateObject=se.memoized=se.notImplemented=se.createHmacDrbg=se.bitMask=se.bitSet=se.bitGet=se.bitLen=se.aInRange=se.inRange=se.asciiToBytes=se.copyBytes=se.equalBytes=se.ensureBytes=se.numberToVarBytesBE=se.numberToBytesLE=se.numberToBytesBE=se.bytesToNumberLE=se.bytesToNumberBE=se.hexToNumber=se.numberToHexUnpadded=se.abool=se.utf8ToBytes=se.randomBytes=se.isBytes=se.hexToBytes=se.concatBytes=se.bytesToUtf8=se.bytesToHex=se.anumber=se.abytes=void 0;const e=at();return se.abytes=e.abytes,se.anumber=e.anumber,se.bytesToHex=e.bytesToHex,se.bytesToUtf8=e.bytesToUtf8,se.concatBytes=e.concatBytes,se.hexToBytes=e.hexToBytes,se.isBytes=e.isBytes,se.randomBytes=e.randomBytes,se.utf8ToBytes=e.utf8ToBytes,se.abool=e.abool,se.numberToHexUnpadded=e.numberToHexUnpadded,se.hexToNumber=e.hexToNumber,se.bytesToNumberBE=e.bytesToNumberBE,se.bytesToNumberLE=e.bytesToNumberLE,se.numberToBytesBE=e.numberToBytesBE,se.numberToBytesLE=e.numberToBytesLE,se.numberToVarBytesBE=e.numberToVarBytesBE,se.ensureBytes=e.ensureBytes,se.equalBytes=e.equalBytes,se.copyBytes=e.copyBytes,se.asciiToBytes=e.asciiToBytes,se.inRange=e.inRange,se.aInRange=e.aInRange,se.bitLen=e.bitLen,se.bitGet=e.bitGet,se.bitSet=e.bitSet,se.bitMask=e.bitMask,se.createHmacDrbg=e.createHmacDrbg,se.notImplemented=e.notImplemented,se.memoized=e.memoized,se.validateObject=e.validateObject,se.isHash=e.isHash,se}var Tn;function kr(){if(Tn)return Ne;Tn=1;var e=Cr(),t=wt(),n=Ir();function i(r){var s=Object.create(null);return r&&Object.keys(r).forEach(function(d){if(d!=="default"){var E=Object.getOwnPropertyDescriptor(r,d);Object.defineProperty(s,d,E.get?E:{enumerable:!0,get:function(){return r[d]}})}}),s.default=r,Object.freeze(s)}var c=i(t),o=i(n);const a=e.secp256k1.ProjectivePoint,u="Expected Private",h="Expected Point",l="Expected Tweak",m="Expected Hash",y="Expected Signature",B="Expected Extra Data (32 bytes)",v="Expected Scalar",T="Bad Recovery Id",N=32,K=32,J=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]),F=32,b=new Uint8Array(32),P=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]),I=BigInt(1);function O(r){return r instanceof Uint8Array}function U(r,s){for(let d=0;d<32;++d)if(r[d]!==s[d])return r[d]<s[d]?-1:1;return 0}function Z(r){return U(r,b)===0}function R(r){return!(!(r instanceof Uint8Array)||r.length!==K||U(r,J)>=0)}function C(r){return r instanceof Uint8Array&&r.length===64&&U(r.subarray(0,32),J)<0&&U(r.subarray(32,64),J)<0}function j(r){return O(r)&&r.length===64&&U(r.subarray(0,32),P)<0}function Q(r){return!(Z(r.subarray(0,32))||Z(r.subarray(32,64)))}function V(r){return r instanceof Uint8Array&&r.length===N}function $(r){return r===void 0||r instanceof Uint8Array&&r.length===F}function w(r){let s;if(typeof r=="bigint")s=r;else if(typeof r=="number"&&Number.isSafeInteger(r)&&r>=0)s=BigInt(r);else if(typeof r=="string"){if(r.length!==64)throw new Error("Expected 32 bytes of private scalar");s=o.hexToNumber(r)}else if(r instanceof Uint8Array){if(r.length!==32)throw new Error("Expected 32 bytes of private scalar");s=o.bytesToNumberBE(r)}else throw new TypeError("Expected valid private scalar");if(s<0)throw new Error("Expected private scalar >= 0");return s}function H(r){return e.secp256k1.utils.normPrivateKeyToScalar(r)}function x(r,s){const d=H(r),E=w(s),A=o.numberToBytesBE(c.mod(d+E,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(A)?A:null}function p(r,s){const d=H(r),E=w(s),A=o.numberToBytesBE(c.mod(d-E,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(A)?A:null}function _(r){const s=H(r),d=o.numberToBytesBE(e.secp256k1.CURVE.n-s,32);return e.secp256k1.utils.isValidPrivateKey(d)?d:null}function k(r,s,d){const E=ee(r),A=w(s),M=a.BASE.multiplyAndAddUnsafe(E,A,I);if(!M)throw new Error("Tweaked point at infinity");return M.toRawBytes(d)}function g(r,s,d){const E=ee(r),A=typeof s=="string"?s:o.bytesToHex(s),M=o.hexToNumber(A);return E.multiply(M).toRawBytes(d)}function S(r,s){return r===void 0?s!==void 0?L(s):!0:!!r}function q(r){try{return r()}catch{return null}}function G(r){return e.schnorr.utils.lift_x(o.bytesToNumberBE(r))}function ee(r){return r.length===32?G(r):a.fromHex(r)}function ne(r,s){if(r.length===32!==s)return!1;try{return s?!!G(r):!!a.fromHex(r)}catch{return!1}}function ie(r){return ne(r,!1)}function L(r){return ne(r,!1)&&r.length===33}function D(r){return e.secp256k1.utils.isValidPrivateKey(r)}function re(r){return ne(r,!0)}function le(r,s){if(!re(r))throw new Error(h);if(!R(s))throw new Error(l);return q(()=>{const d=k(r,s,!0);return{parity:d[0]%2===1?1:0,xOnlyPubkey:d.slice(1)}})}function ce(r){if(!ie(r))throw new Error(h);return r.slice(1,33)}function W(r,s){if(!D(r))throw new Error(u);return q(()=>e.secp256k1.getPublicKey(r,S(s)))}function oe(r){if(!D(r))throw new Error(u);return ce(W(r))}function be(r,s){if(!ie(r))throw new Error(h);return ee(r).toRawBytes(S(s,r))}function Se(r,s,d){if(!ie(r))throw new Error(h);if(!R(s))throw new Error(l);return q(()=>g(r,s,S(d,r)))}function Oe(r,s,d){if(!ie(r)||!ie(s))throw new Error(h);return q(()=>{const E=ee(r),A=ee(s);return E.equals(A.negate())?null:E.add(A).toRawBytes(S(d,r))})}function qe(r,s,d){if(!ie(r))throw new Error(h);if(!R(s))throw new Error(l);return q(()=>k(r,s,S(d,r)))}function ke(r,s){if(!D(r))throw new Error(u);if(!R(s))throw new Error(l);return q(()=>x(r,s))}function Ee(r,s){if(!D(r))throw new Error(u);if(!R(s))throw new Error(l);return q(()=>p(r,s))}function Ke(r){if(!D(r))throw new Error(u);return _(r)}function He(r,s,d){if(!D(s))throw new Error(u);if(!V(r))throw new Error(v);if(!$(d))throw new Error(B);return e.secp256k1.sign(r,s,{extraEntropy:d}).toCompactRawBytes()}function Be(r,s,d){if(!D(s))throw new Error(u);if(!V(r))throw new Error(v);if(!$(d))throw new Error(B);const E=e.secp256k1.sign(r,s,{extraEntropy:d});return{signature:E.toCompactRawBytes(),recoveryId:E.recovery}}function te(r,s,d){if(!D(s))throw new Error(u);if(!V(r))throw new Error(v);if(!$(d))throw new Error(B);return e.schnorr.sign(r,s,d)}function Y(r,s,d,E){if(!V(r))throw new Error(m);if(!C(s)||!Q(s))throw new Error(y);if(d&2&&!j(s))throw new Error(T);if(!re(s.subarray(0,32)))throw new Error(y);const M=e.secp256k1.Signature.fromCompact(s).addRecoveryBit(d).recoverPublicKey(r);if(!M)throw new Error(y);return M.toRawBytes(S(E))}function z(r,s,d,E){if(!ie(s))throw new Error(h);if(!C(d))throw new Error(y);if(!V(r))throw new Error(v);return e.secp256k1.verify(d,r,s,{lowS:E})}function f(r,s,d){if(!re(s))throw new Error(h);if(!C(d))throw new Error(y);if(!V(r))throw new Error(v);return e.schnorr.verify(d,r,s)}return Ne.isPoint=ie,Ne.isPointCompressed=L,Ne.isPrivate=D,Ne.isXOnlyPoint=re,Ne.pointAdd=Oe,Ne.pointAddScalar=qe,Ne.pointCompress=be,Ne.pointFromScalar=W,Ne.pointMultiply=Se,Ne.privateAdd=ke,Ne.privateNegate=Ke,Ne.privateSub=Ee,Ne.recover=Y,Ne.sign=He,Ne.signRecoverable=Be,Ne.signSchnorr=te,Ne.verify=z,Ne.verifySchnorr=f,Ne.xOnlyPointAddTweak=le,Ne.xOnlyPointFromPoint=ce,Ne.xOnlyPointFromScalar=oe,Ne}var Nn=kr();const Mr=yr({__proto__:null,default:cn(Nn)},[Nn]);ut.initEccLib(Mr);const yt={Mainnet:"mainnet",Testnet:"testnet"};class Fr{axios;constructor(t){this.axios=br.default.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(c=>c.data)}async inscriptionsByAddress(t,n){return await this.axios.get(`/addresses/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(c=>c.data)}async inscriptionIdsByCollectionSymbol(t,n){return await this.axios.get(`/assets/collections/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(c=>c.data)}async runeUtxosByAddress(t,n,i){return await this.axios.get(`/addresses/${t}/runes/utxos?order_by=height&order=asc&count=100&rune=${n}${i?`&cursor=${i}`:""}`).then(o=>o.data)}}var nt={},xe={},rt={},Rn;function Vr(){if(Rn)return rt;Rn=1,Object.defineProperty(rt,"__esModule",{value:!0}),rt.base26Decode=rt.base26Encode=void 0;function e(n){let i=0n;for(let c=0;c<n.length;c++){const o=BigInt(n.charCodeAt(c)-65),a=BigInt(n.length)-1n-BigInt(c);if(a==0n)i+=o;else{const u=26n**a;i+=u*(o+1n)}}return i}rt.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let i=[];for(;n>0;){const c=(n-1n)%26n;i.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(c))),n=(n-1n)/26n}return i.reverse().join("")}return rt.base26Decode=t,rt}var it={},On;function Hn(){if(On)return it;On=1,Object.defineProperty(it,"__esModule",{value:!0}),it.none=it.some=void 0;class e{constructor(){}isSome(){return!1}map(o){return new e}value(){return null}}class t{constructor(o){this._value=o}isSome(){return!0}map(o){return new t(o(this.value()))}value(){return this._value}}function n(c){return new t(c)}it.some=n;function i(){return new e}return it.none=i,it}var ot={},Un;function jr(){if(Un)return ot;Un=1,Object.defineProperty(ot,"__esModule",{value:!0}),ot.decodeLEB128=ot.encodeLEB128=void 0;function e(n){const i=[];let c=!0;for(;c;){let o=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?c=!1:o|=128,i.push(o)}return i}ot.encodeLEB128=e;function t(n){let i=BigInt(0);for(let c=0;c<n.length;c++){const o=BigInt(n[c]);if(c>18)throw new Error("Overlong");let a=o&BigInt(127);if(c==18&&(a&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(i|=a<<BigInt(7)*BigInt(c),(o&BigInt(128))==BigInt(0))return{n:i,len:c+1}}throw new Error("Unterminated")}return ot.decodeLEB128=t,ot}var Kt={},qn;function $r(){return qn||(qn=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=o=>o.length%2===1?"0"+o:o;e.zero2=t;const n=o=>{let a="";for(let u=0;u<o.length;u++)a+=(0,e.zero2)(o[u].toString(16));return a};e.toHex=n;function i(o,a){const u=[];let h=0;for(;h<o.length;){const l=o.slice(h,h+a);u.push(l),h+=a}return u}e.chunks=i;function c(o){const a=[],u=o.length;if(u<76){const h=Buffer.alloc(1);h.writeUInt8(u),a.push(h)}else if(u<=255){a.push(Buffer.from("4c","hex"));const h=Buffer.alloc(1);h.writeUInt8(u),a.push(h)}else if(u<=65535){a.push(Buffer.from("4d","hex"));const h=Buffer.alloc(2);h.writeUint16LE(u),a.push(h)}else{a.push(Buffer.from("4e","hex"));const h=Buffer.alloc(4);h.writeUint32LE(u),a.push(h)}return a.push(o),Buffer.concat(a)}e.toPushData=c})(Kt)),Kt}var Xe={},Pn;function Cn(){if(Pn)return Xe;Pn=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.removeSpacers=Xe.getSpacersVal=Xe.applySpacers=void 0;function e(i,c){let o="";for(let a=0;a<i.length;a++)o+=i.charAt(a),c>0&&((c&1)===1&&(o+="•"),c>>=1);return o}Xe.applySpacers=e;function t(i){let c=0,o=0;for(let a=0;a<i.length;a++)i.charAt(a)==="•"&&(c+=1<<a-1-o,o++);return c}Xe.getSpacersVal=t;function n(i){return i.replace(/[•]+/g,"")}return Xe.removeSpacers=n,Xe}var In;function Zr(){if(In)return xe;In=1,Object.defineProperty(xe,"__esModule",{value:!0}),xe.EtchInscription=xe.Message=xe.Runestone=xe.Etching=xe.Rune=xe.Terms=xe.Range=xe.Flaw=xe.Tag=xe.Flag=xe.Edict=xe.RuneId=void 0;const e=Ge.default,t=Vr(),n=Hn(),i=jr(),c=$r(),o=Cn();class a{constructor(b,P){this.block=b,this.idx=P}next(b,P){if(b>BigInt(Number.MAX_SAFE_INTEGER)||P>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let I=BigInt(this.block)+b;if(I>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let O=b===0n?BigInt(this.idx)+P:P;return O>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new a(Number(I),Number(O)))}}xe.RuneId=a;class u{constructor(b,P,I){this.id=b,this.amount=P,this.output=I}static from_integers(b,P,I,O){return O>4294967295n||O<0n||Number(O)>b.outs.length?(0,n.none)():(0,n.some)(new u(P,I,Number(O)))}}xe.Edict=u;var h;(function(F){F[F.Etching=0]="Etching",F[F.Terms=1]="Terms",F[F.Turbo=2]="Turbo",F[F.Cenotaph=127]="Cenotaph"})(h||(xe.Flag=h={}));var l;(function(F){F[F.Body=0]="Body",F[F.Flags=2]="Flags",F[F.Rune=4]="Rune",F[F.Premine=6]="Premine",F[F.Cap=8]="Cap",F[F.Amount=10]="Amount",F[F.HeightStart=12]="HeightStart",F[F.HeightEnd=14]="HeightEnd",F[F.OffsetStart=16]="OffsetStart",F[F.OffsetEnd=18]="OffsetEnd",F[F.Mint=20]="Mint",F[F.Pointer=22]="Pointer",F[F.Cenotaph=126]="Cenotaph",F[F.Divisibility=1]="Divisibility",F[F.Spacers=3]="Spacers",F[F.Symbol=5]="Symbol",F[F.Nop=127]="Nop"})(l||(xe.Tag=l={}));var m;(function(F){F[F.EdictOutput=0]="EdictOutput",F[F.EdictRuneId=1]="EdictRuneId",F[F.InvalidScript=2]="InvalidScript",F[F.Opcode=3]="Opcode",F[F.SupplyOverflow=4]="SupplyOverflow",F[F.TrailingIntegers=5]="TrailingIntegers",F[F.TruncatedField=6]="TruncatedField",F[F.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",F[F.UnrecognizedFlag=8]="UnrecognizedFlag",F[F.Varint=9]="Varint"})(m||(xe.Flaw=m={}));class y{constructor(b,P){this.start=b,this.end=P}}xe.Range=y;class B{constructor(b,P,I,O){this.amount=b,this.cap=P,this.height=I,this.offset=O}}xe.Terms=B;class v{constructor(b){this.value=b}get name(){return v.toName(this.value)}static toName(b){return(0,t.base26Decode)(b)}static fromName(b){return new v((0,t.base26Encode)((0,o.removeSpacers)(b)))}toString(){return this.name}}xe.Rune=v;class T{constructor(b,P,I,O,U,Z,R){this.divisibility=b,this.premine=P,this.rune=I,this.spacers=O,this.symbol=U,this.terms=Z,this.turbo=R}}xe.Etching=T,T.MAX_DIVISIBILITY=38,T.MAX_SPACERS=134217727;class N{constructor(b=[],P,I,O){this.edicts=b,this.etching=P,this.mint=I,this.pointer=O}static create(b,P="etch"){if(P==="etch"){b=b;const I=v.fromName(b.name),O=new B(b.amount,b.cap,new y(b.startHeight?(0,n.some)(b.startHeight):(0,n.none)(),b.endHeight?(0,n.some)(b.endHeight):(0,n.none)()),new y(b.startOffset?(0,n.some)(b.startOffset):(0,n.none)(),b.endOffset?(0,n.some)(b.endOffset):(0,n.none)())),U=b.divisibility?(0,n.some)(b.divisibility):(0,n.none)(),Z=b.premine?(0,n.some)(b.premine):(0,n.none)(),R=b.name.indexOf("•")>-1?(0,n.some)((0,o.getSpacersVal)(b.name)):(0,n.none)(),C=b.symbol?(0,n.some)(b.symbol):(0,n.none)(),j=typeof b.pointer=="number"?(0,n.some)(b.pointer):(0,n.none)(),Q=new T(U,Z,(0,n.some)(I),R,C,(0,n.some)(O),!0);return new N([],(0,n.some)(Q),(0,n.none)(),j)}else if(P==="mint"){b=b;const I=typeof b.pointer=="number"?(0,n.some)(b.pointer):(0,n.none)();return new N([],(0,n.none)(),(0,n.some)(new a(b.block,b.txIdx)),I)}else throw new Error(`not ${P} support now`)}static decipher(b){const P=e.Transaction.fromHex(b),I=N.payload(P);if(I.isSome()){const O=N.integers(I.value()),U=K.from_integers(P,O.value()),Z=U.getEtching(),R=U.getMint(),C=U.getPointer();return(0,n.some)(new N(U.edicts,Z,R,C))}return(0,n.none)()}encipher(){const P=this.toMessage().toBuffer(),I=Buffer.from("6a5d","hex");let O;if(P.length<76)O=Buffer.alloc(1),O.writeUint8(P.length);else if(P.length<256)O=Buffer.alloc(2),O.writeUint8(76),O.writeUint8(P.length);else if(P.length<65536)O=Buffer.alloc(3),O.writeUint8(77),O.writeUint16LE(P.length);else if(P.length<4294967296)O=Buffer.alloc(5),O.writeUint8(78),O.writeUint32LE(P.length);else throw new Error("runestone too big!");return Buffer.concat([I,O,P])}static payload(b){for(const P of b.outs){const I=e.script.decompile(P.script);if(I[0]===e.script.OPS.OP_RETURN&&I[1]===N.MAGIC_NUMBER){for(let O=2;O<I.length;O++){const U=I[O];return U instanceof Uint8Array?(0,n.some)(Array.from(U)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(b){let P=[],I=0;for(;I<b.length;){let{n:O,len:U}=(0,i.decodeLEB128)(b.slice(I));P.push(O),I+=U}return(0,n.some)(P)}toMessage(){let b=new Map;const P=this.etching.value();if(P){let U=1;if(P.terms.isSome()){let $=1<<h.Terms;U|=$}if(P.turbo){let $=1<<h.Turbo;U|=$}b.set(l.Flags,[BigInt(U)]);const Z=P.rune.value();Z!==null&&b.set(l.Rune,[BigInt(Z.value)]);const R=P.divisibility.value();R!==null&&b.set(l.Divisibility,[BigInt(R)]);const C=P.spacers.value();C!==null&&b.set(l.Spacers,[BigInt(C)]);const j=P.symbol.value();j!==null&&b.set(l.Symbol,[BigInt(j.charCodeAt(0))]);const Q=P.premine.value();Q!==null&&b.set(l.Premine,[BigInt(Q)]);const V=P.terms.value();if(V!==null){b.set(l.Amount,[BigInt(V.amount)]),b.set(l.Cap,[BigInt(V.cap)]);const $=V.height.start.value();$&&b.set(l.HeightStart,[BigInt($)]);const w=V.height.end.value();w&&b.set(l.HeightEnd,[BigInt(w)]);const H=V.offset.start.value();H&&b.set(l.OffsetStart,[BigInt(H)]);const x=V.offset.end.value();x&&b.set(l.OffsetEnd,[BigInt(x)])}}const I=this.mint.value();I!==null&&b.set(l.Mint,[BigInt(I.block),BigInt(I.idx)]);const O=this.pointer.value();return O!==null&&b.set(l.Pointer,[BigInt(O)]),new K(b,this.edicts,0)}}xe.Runestone=N,N.MAGIC_NUMBER=93;class K{constructor(b=new Map,P=[],I=0){this.fields=b,this.edicts=P,this.flaws=I}static from_integers(b,P){let I=new Map,O=[],U=0,Z=!1;for(let R=0;R<P.length;){let C=P[R];if(Number(C)===l.Body){Z=!0,R+=1;continue}if(Z){let j=new a(0,0);for(const Q of(0,c.chunks)(P.slice(R),4)){if(Q.length!=4){U|=m.TrailingIntegers;break}let V=j.next(Q[0],Q[1]);if(!V.isSome()){U|=m.EdictRuneId;break}const $=u.from_integers(b,V.value(),Q[2],Q[3]);if(!$.isSome()){U|=m.EdictOutput;break}j=V.value(),O.push($.value())}R+=4}else{let j=P[R+1];const Q=I.get(Number(C))||[];Q.push(j),I.set(Number(C),Q),R+=2}}return new K(I,O,U)}addFieldVal(b,P){const I=this.fields.get(Number(b))||[];I.push(P),this.fields.set(Number(b),I)}addEdict(b){this.edicts.push(b)}toBuffer(){const b=[];for(const[P,I]of this.fields)for(const O of I){const U=Buffer.alloc(1);U.writeUInt8(P),b.push(U),b.push(Buffer.from((0,i.encodeLEB128)(O)))}if(this.edicts.length>0){b.push(Buffer.from("00","hex")),this.edicts.sort((O,U)=>O.id.block==U.id.block?O.id.idx-U.id.idx:O.id.block-U.id.block);let P=0n,I=0n;for(let O=0;O<this.edicts.length;O++){const U=this.edicts[O];if(O==0)P=BigInt(U.id.block),I=BigInt(U.id.idx),b.push(Buffer.from((0,i.encodeLEB128)(P))),b.push(Buffer.from((0,i.encodeLEB128)(I)));else{const Z=BigInt(U.id.block),R=BigInt(U.id.idx);if(Z==P){const C=R-I;I=R,b.push(Buffer.from((0,i.encodeLEB128)(0n))),b.push(Buffer.from((0,i.encodeLEB128)(C)))}else{const C=Z-P;P=Z,I=R,b.push(Buffer.from((0,i.encodeLEB128)(C))),b.push(Buffer.from((0,i.encodeLEB128)(R)))}}b.push(Buffer.from((0,i.encodeLEB128)(BigInt(U.amount)))),b.push(Buffer.from((0,i.encodeLEB128)(BigInt(U.output))))}}return Buffer.concat(b)}getFlags(){return Number(this.fields.get(l.Flags))}hasFlags(b){const P=this.getFlags(),I=1<<b;return(P&I)!=0}getMint(){if(!this.fields.has(l.Mint))return(0,n.none)();const[b,P]=this.fields.get(l.Mint);return(0,n.some)(new a(Number(b),Number(P)))}getEtching(){if(!this.hasFlags(h.Etching))return(0,n.none)();const b=this.getDivisibility(),P=this.getPremine(),I=this.getRune(),O=this.getSpacers(),U=this.getSymbol(),Z=this.getTerms(),R=this.hasFlags(h.Turbo);return(0,n.some)(new T(b,P,I,O,U,Z,R))}getDivisibility(){if(!this.fields.has(l.Divisibility))return(0,n.none)();const[b]=this.fields.get(l.Divisibility);if(b>T.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(b))}getPremine(){if(!this.fields.has(l.Premine))return(0,n.none)();const[b]=this.fields.get(l.Premine);return(0,n.some)(Number(b))}getRune(){if(!this.fields.has(l.Rune))return(0,n.none)();const[b]=this.fields.get(l.Rune);return(0,n.some)(new v(b))}getSpacers(){if(!this.fields.has(l.Spacers))return(0,n.none)();const[b]=this.fields.get(l.Spacers);if(b>T.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(b))}getHeightStart(){if(!this.fields.has(l.HeightStart))return(0,n.none)();const[b]=this.fields.get(l.HeightStart);return(0,n.some)(Number(b))}getHeightEnd(){if(!this.fields.has(l.HeightEnd))return(0,n.none)();const[b]=this.fields.get(l.HeightEnd);return(0,n.some)(Number(b))}getOffsetStart(){if(!this.fields.has(l.OffsetStart))return(0,n.none)();const[b]=this.fields.get(l.OffsetStart);return(0,n.some)(Number(b))}getOffsetEnd(){if(!this.fields.has(l.OffsetEnd))return(0,n.none)();const[b]=this.fields.get(l.OffsetEnd);return(0,n.some)(Number(b))}getCap(){if(!this.fields.has(l.Cap))return(0,n.none)();const[b]=this.fields.get(l.Cap);return(0,n.some)(Number(b))}getAmount(){if(!this.fields.has(l.Amount))return(0,n.none)();const[b]=this.fields.get(l.Amount);return(0,n.some)(Number(b))}getSymbol(){if(!this.fields.has(l.Symbol))return(0,n.none)();const[b]=this.fields.get(l.Symbol);return(0,n.some)(String.fromCharCode(Number(b)))}getTerms(){if(!this.hasFlags(h.Terms))return(0,n.none)();const b=this.getCap();if(!b.isSome())throw new Error("no cap field");const P=this.getAmount();if(!P.isSome())throw new Error("no amount field");const I=this.getHeightStart(),O=this.getHeightEnd(),U=this.getOffsetStart(),Z=this.getOffsetEnd(),R=new y(I,O),C=new y(U,Z);return(0,n.some)(new B(P.value(),b.value(),R,C))}getPointer(){if(!this.fields.has(l.Pointer))return(0,n.none)();const[b]=this.fields.get(l.Pointer);return(0,n.some)(Number(b))}}xe.Message=K;class J{constructor(b=new Map,P=Buffer.alloc(0)){this.fields=b,this.data=P}setContent(b,P){this.fields.set(1,Buffer.from(b,"utf8")),this.data=P}setRune(b){let I=(0,t.base26Encode)((0,o.removeSpacers)(b)).toString(16);I.length%2===1&&(I="0"+I),this.setField(J.Tag.RUNE,Buffer.from(I,"hex").reverse())}setField(b,P){this.fields.set(b,P)}static decipher(b,P){const U=e.Transaction.fromHex(b).ins[P].witness[1],Z=e.script.decompile(U),R=new Map,C=[];let j=!1;for(let Q=5;Q<Z.length-1;){const V=Z[Q];if(V===0){j=!0,Q++;continue}else if(j)C.push(V),Q++;else{const $=V-80,w=Z[Q+1];if(typeof w=="number"){const H=Buffer.alloc(1);H.writeUint8(w),R.set($,H)}else R.set($,w);Q+=2}}return new J(R,Buffer.concat(C))}encipher(){const b=[];if(this.data&&this.data.length>0){b.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((I,O)=>I[0]-O[0]).forEach(([I,O])=>{const U=Buffer.alloc(1);U.writeUInt8(I),b.push(Buffer.from("01","hex")),b.push(U),O.length!=1||O[0]!=0?b.push((0,c.toPushData)(O)):b.push(O)}),b.push(Buffer.from("00","hex"));const P=(0,c.chunks)(Array.from(this.data),520);for(const I of P)b.push((0,c.toPushData)(Buffer.from(I)))}else{b.push(Buffer.from("0063","hex"));const P=this.fields.get(J.Tag.RUNE);if(!P)throw new Error("No rune found!");b.push((0,c.toPushData)(P))}return b.push(Buffer.from("68","hex")),Buffer.concat(b)}}return xe.EtchInscription=J,J.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},xe}var kn;function Kr(){return kn||(kn=1,(function(e){var t=nt&&nt.__createBinding||(Object.create?(function(o,a,u,h){h===void 0&&(h=u);var l=Object.getOwnPropertyDescriptor(a,u);(!l||("get"in l?!a.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(o,h,l)}):(function(o,a,u,h){h===void 0&&(h=u),o[h]=a[u]})),n=nt&&nt.__exportStar||function(o,a){for(var u in o)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,o,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(Zr(),e);var i=Hn();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return i.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return i.some}});var c=Cn();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return c.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return c.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return c.removeSpacers}})})(nt)),nt}var st=Kr();function Gr(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 Gt(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Wt(e){return e===yt.Mainnet?Ge.networks.bitcoin:Ge.networks.testnet}const $e={P2PKH:{P2PKH:null},P2SH_P2WPKH:{P2SH_P2WPKH:null},P2WPKH:{P2WPKH:null},P2WSH:{P2WSH:null},P2SH:{P2SH:null},P2TR:{P2TR:null},UNKNOWN:{UNKNOWN:null}};function zt(e,t=yt.Testnet){const n=Wt(t);return Ge.address.toOutputScript(e,n)}function bt(e){const t=Ge.networks.bitcoin,n=Ge.networks.testnet,i=Ge.networks.regtest;let c,o,a=$e.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return o=Ge.address.fromBech32(e),o.version===0?o.data.length===20?a=$e.P2WPKH:a=$e.P2WSH:a=$e.P2TR,a}catch{return $e.UNKNOWN}else try{return c=Ge.address.fromBase58Check(e),c.version===t.pubKeyHash||c.version===n.pubKeyHash||c.version===i.pubKeyHash?a=$e.P2PKH:(c.version===t.scriptHash||(c.version,n.scriptHash),a=$e.P2SH_P2WPKH),a}catch{return $e.UNKNOWN}}const Wr=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:Gt,getAddressType:bt,getScriptByAddress:zt,hexToBytes:Gr,toBitcoinNetwork:Wt},Symbol.toStringTag,{value:"Module"})),zr="kqs64-paaaa-aaaar-qamza-cai",Xr="hvyp5-5yaaa-aaaao-qjxha-cai",xt=BigInt(546),vt="0:0",Yr="https://runescan-hasura-mainnet.omnity.network/v1/graphql",Qr="https://runescan-hasura-testnet.omnity.network/v1/graphql";class Mn{psbt;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);orchestrator;intentions=[];txFee=BigInt(0);additionalDustNeeded=BigInt(0);inputUtxos=[];constructor(t,n){this.config=t,this.psbt=new Ge.Psbt({network:Wt(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(bt(n)),this.inputUtxos.push(t),(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(bt(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:0}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,i){const c=[];if(i==BigInt(0))return c;for(const o of t)if(o.runes.length){const a=o.runes.find(u=>u.id==n);if(a&&BigInt(a.amount)==i){c.push(o);break}}if(c.length==0){let o=BigInt(0);for(const a of t)if(a.runes.forEach(u=>{u.id==n&&(o=o+BigInt(u.amount))}),c.push(a),o>=i)break;if(o<i)throw new Error("INSUFFICIENT_RUNE_UTXOs")}return c}selectBtcUtxos(t,n){const i=[];if(n<=BigInt(0))return i;let c=BigInt(0);for(const o of t)if(!o.runes.length&&(c+=BigInt(o.satoshis),i.push(o),c>=n))break;if(c<n)throw new Error(`Insufficient BTC UTXOs: need ${n}, have ${c}`);return i}async addBtcAndFees(t,n){const i=this.config.paymentAddress,c=this.additionalDustNeeded;this.outputAddressTypes.push(bt(i));let o=BigInt(0),a=BigInt(0),u=[],h=BigInt(0),l=BigInt(0);const m=[...this.inputAddressTypes];do if(o=a,a=(await this.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes,pool_address:this.intentions.map(T=>T.poolAddress),output_types:this.outputAddressTypes})).Ok,h=n+a+c-this.userInputUtxoDusts,a>o&&h>0){const T=this.selectBtcUtxos(t,h);if(T.length===0)throw new Error("INSUFFICIENT_BTC_UTXOs");this.inputAddressTypes=m.concat([...T.map(()=>bt(i))]);const N=T.reduce((K,J)=>K+BigInt(J.satoshis),BigInt(0));N-h>0&&N-h>xt||this.outputAddressTypes.pop(),u=T}while(a>o&&h>0);let y=BigInt(0);u.forEach(v=>{this.addInput(v),y+=BigInt(v.satoshis)});const B=y-h;if(B<0)throw new Error("Insufficient UTXO(s)");B>xt?this.psbt.addOutput({address:i,value:Number(B)}):B>BigInt(0)&&(l=B),this.txFee=l+a}addInputAndCalculateOutputs(){if(!this.intentions.length)throw new Error("No intentions added");const t={},n={};let i=BigInt(0);const c={},o={},a=new Set;return this.intentions.forEach(h=>{a.add(h.poolAddress)}),a.forEach(h=>{(this.config.involvedPoolUtxos[h]??[]).forEach(m=>{t[h]=(t[h]??BigInt(0))+BigInt(m.satoshis),m.runes.forEach(y=>{n[h]??={},n[h][y.id]=(n[h][y.id]??BigInt(0))+BigInt(y.amount)}),this.addInput(m)})}),this.intentions.forEach(h=>{const l=h.poolAddress;h.inputCoins.forEach(m=>{if(m.id===vt){i-=BigInt(m.value),t[l]+=BigInt(m.value);return}c[m.id]=(c[m.id]??BigInt(0))+BigInt(m.value),n[l]??={},n[l][m.id]=(n[l][m.id]??BigInt(0))+BigInt(m.value)}),h.outputCoins.forEach(m=>{if(m.id===vt){i+=BigInt(m.value);const v=t[l]-BigInt(m.value);if(v<BigInt(0))throw new Error(`Pool ${l} insufficient BTC: need ${m.value}, have ${t[l]}`);t[l]=v;return}o[m.id]=(o[m.id]??BigInt(0))+BigInt(m.value),n[l]??={};const y=n[l][m.id]??BigInt(0),B=y-BigInt(m.value);if(B<BigInt(0))throw new Error(`Pool ${l} insufficient rune ${m.id}: need ${m.value}, have ${y}`);n[l][m.id]=B})}),Object.keys(c).forEach(h=>{const l=c[h];if(l<=BigInt(0))return;const m=this.selectRuneUtxos(this.config.involvedRuneUtxos?.[h]??[],h,l),B=m.reduce((v,T)=>v+BigInt(T.runes.find(N=>N.id===h)?.amount??0),BigInt(0))-l;B>BigInt(0)&&(o[h]=(o[h]??BigInt(0))+B),m.forEach(v=>{this.addInput(v)})}),{userOutputBtcAmount:i,userOutputRuneAmounts:o,poolOutputBtcAmounts:t,poolOutputRuneAmounts:n}}addRuneOutputs(t,n,i){const c=new Set,o=Object.keys(i);for(const y in t)c.add(y);o.forEach(y=>{for(const B in n[y])c.add(B)});const a=Array.from(c),u=[],h=[];let l=1;a.forEach(y=>{const B=new st.RuneId(Number(y.split(":")[0]),Number(y.split(":")[1])),v=t[y]??BigInt(0);v>BigInt(0)&&(u.push(new st.Edict(B,v,l)),h.push(this.config.address),l++),o.forEach(T=>{const N=n[T][y]??BigInt(0);N>BigInt(0)&&(u.push(new st.Edict(B,N,l)),h.push(T),l++)})}),console.log("edicts",u);const m=new st.Runestone(u,st.none(),st.none(),st.none());return this.addScriptOutput(m.encipher()),h.forEach(y=>{let B=xt;!i[y]||y===this.config.address?this.additionalDustNeeded+=xt:(B=i[y],delete i[y]),this.addOutput(y,B)}),i}addIntention(t){this.intentions.push(t)}async build(){const{userOutputBtcAmount:t,userOutputRuneAmounts:n,poolOutputBtcAmounts:i,poolOutputRuneAmounts:c}=this.addInputAndCalculateOutputs();console.log(t,n,i,c);const o=this.addRuneOutputs(n,c,i);return Object.keys(o).forEach(u=>{this.addOutput(u,o[u])}),await this.addBtcAndFees(this.config.btcUtxos,-t),this.psbt}async send(t){if(!this.intentions.length)throw new Error("No itentions added");return this.orchestrator.invoke({intention_set:{tx_fee_in_sats:this.txFee,initiator_address:this.config.paymentAddress,intentions:this.intentions.map(({action:n,actionParams:i,poolAddress:c,inputCoins:o,outputCoins:a,nonce:u})=>({exchange_id:this.config.exchangeId,input_coins:o.map(h=>({coin:h,from:h.id===vt?this.config.paymentAddress:this.config.address})),output_coins:a.map(h=>({coin:h,to:h.id===vt?this.config.paymentAddress:this.config.address})),pool_address:c,action:n,action_params:i??"",pool_utxo_spent:[],pool_utxo_received:[],nonce:u}))},initiator_utxo_proof:[],psbt_hex:t}).then(n=>{if(n?.Ok)return n.Ok;{const i=n?.Err??{},c=Object.keys(i)[0],o=i[c];throw new Error(o?c==="ErrorOccurredDuringExecution"?`${c}: ${o.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(n)}`:`Invoke Error: ${JSON.stringify(n)}`)}})}}class ft extends Error{response;request;constructor(t,n){const i=`${ft.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(i),Object.setPrototypeOf(this,ft.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,ft)}static extractMessage(t){return t.errors?.[0]?.message??`GraphQL Error (Code: ${String(t.status)})`}}const Fn=e=>e.toUpperCase(),Xt=e=>typeof e=="function"?e():e,Vn=(e,t)=>e.map((n,i)=>[n,t[i]]),lt=e=>{let t={};return e instanceof Headers?t=Jr(e):Array.isArray(e)?e.forEach(([n,i])=>{n&&i!==void 0&&(t[n]=i)}):e&&(t=e),t},Jr=e=>{const t={};return e.forEach((n,i)=>{t[i]=n}),t},Lr=e=>{try{const t=e();return Dr(t)?t.catch(n=>jn(n)):t}catch(t){return jn(t)}},jn=e=>e instanceof Error?e:new Error(String(e)),Dr=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",Yt=e=>{throw new Error(`Unhandled case: ${String(e)}`)},St=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ei=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},ti=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0},$n="Accept",Qt="Content-Type",Jt="application/json",Zn="application/graphql-response+json",Kn=e=>e.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),ni=e=>{const t=e.toLowerCase();return t.includes(Zn)||t.includes(Jt)},Gn=e=>{try{if(Array.isArray(e))return{_tag:"Batch",executionResults:e.map(Wn)};if(St(e))return{_tag:"Single",executionResult:Wn(e)};throw new Error(`Invalid execution result: result is not object or array.
|
|
7
7
|
Got:
|
|
8
|
-
${String(e)}`)}catch(t){return t}},Wn=e=>{if(typeof e!="object"||e===null)throw new Error("Invalid execution result: result is not object");let t,n,i;if("errors"in e){if(!St(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(!St(e.data)&&e.data!==null)throw new Error("Invalid execution result: data is not plain object");n=e.data}if("extensions"in e){if(!St(e.extensions))throw new Error("Invalid execution result: extensions is not plain object");i=e.extensions}return{data:n,errors:t,extensions:i}},
|
|
8
|
+
${String(e)}`)}catch(t){return t}},Wn=e=>{if(typeof e!="object"||e===null)throw new Error("Invalid execution result: result is not object");let t,n,i;if("errors"in e){if(!St(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(!St(e.data)&&e.data!==null)throw new Error("Invalid execution result: data is not plain object");n=e.data}if("extensions"in e){if(!St(e.extensions))throw new Error("Invalid execution result: extensions is not plain object");i=e.extensions}return{data:n,errors:t,extensions:i}},ri=e=>e._tag==="Batch"?e.executionResults.some(zn):zn(e.executionResult),zn=e=>Array.isArray(e.errors)?e.errors.length>0:!!e.errors,Xn=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===Ct.Kind.OPERATION_DEFINITION,ii=e=>{let t;const n=e.definitions.filter(Xn);return n.length===1&&(t=n[0].name?.value),t},oi=e=>{let t=!1;const n=e.definitions.filter(Xn);return n.length===1&&(t=n[0].operation==="mutation"),t},Lt=(e,t)=>{const n=typeof e=="string"?e:Ct.print(e);let i=!1,c;if(t)return{expression:n,isMutation:i,operationName:c};const o=Lr(()=>typeof e=="string"?Ct.parse(e):e);return o instanceof Error?{expression:n,isMutation:i,operationName:c}:(c=ii(o),i=oi(o),{expression:n,operationName:c,isMutation:i})},Dt=JSON,en=async e=>{const t={...e,method:e.request._tag==="Single"?e.request.document.isMutation?"POST":Fn(e.method??"post"):e.request.hasMutations?"POST":Fn(e.method??"post"),fetchOptions:{...e.fetchOptions,errorPolicy:e.fetchOptions.errorPolicy??"none"}},i=await ci(t.method)(t);if(!i.ok)return new ft({status:i.status,headers:i.headers},{query:e.request._tag==="Single"?e.request.document.expression:e.request.query,variables:e.request.variables});const c=await si(i,e.fetchOptions.jsonSerializer??Dt);if(c instanceof Error)throw c;const o={status:i.status,headers:i.headers};if(ri(c)&&t.fetchOptions.errorPolicy==="none"){const a=c._tag==="Batch"?{...c.executionResults,...o}:{...c.executionResult,...o};return new ft(a,{query:e.request._tag==="Single"?e.request.document.expression:e.request.query,variables:e.request.variables})}switch(c._tag){case"Single":return{...o,...Yn(t)(c.executionResult)};case"Batch":return{...o,data:c.executionResults.map(Yn(t))};default:Yt(c)}},Yn=e=>t=>({extensions:t.extensions,data:t.data,errors:e.fetchOptions.errorPolicy==="all"?t.errors:void 0}),si=async(e,t)=>{const n=e.headers.get(Qt),i=await e.text();return n&&ni(n)?Gn(t.parse(i)):Gn(i)},ci=e=>async t=>{const n=new Headers(t.headers);let i=null,c;n.has($n)||n.set($n,[Zn,Jt].join(", ")),e==="POST"?(c=(t.fetchOptions.jsonSerializer??Dt).stringify(ui(t)),typeof c=="string"&&!n.has(Qt)&&n.set(Qt,Jt)):i=ai(t);const o={method:e,headers:n,body:c,...t.fetchOptions};let a=new URL(t.url),u=o;if(t.middleware){const l=await Promise.resolve(t.middleware({...o,url:t.url,operationName:t.request._tag==="Single"?t.request.document.operationName:void 0,variables:t.request.variables})),{url:m,...y}=l;a=new URL(m),u=y}return i&&i.forEach((l,m)=>{a.searchParams.append(m,l)}),await(t.fetch??fetch)(a,u)},ui=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 Vn(e.request.query,e.request.variables??[]).map(([t,n])=>({query:t,variables:n}));default:throw Yt(e.request)}},ai=e=>{const t=e.fetchOptions.jsonSerializer??Dt,n=new URLSearchParams;switch(e.request._tag){case"Single":return n.append("query",Kn(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 i=e.request.variables?.map(a=>t.stringify(a))??[],c=e.request.query.map(Kn),o=Vn(c,i).map(([a,u])=>({query:a,variables:u}));return n.append("query",t.stringify(o)),n}default:throw Yt(e.request)}};class fi{url;requestConfig;constructor(t,n={}){this.url=t,this.requestConfig=n}rawRequest=async(...t)=>{const[n,i,c]=t,o=ti(n,i,c),{headers:a,fetch:u=globalThis.fetch,method:h="POST",requestMiddleware:l,responseMiddleware:m,excludeOperationName:y,...B}=this.requestConfig,{url:v}=this;o.signal!==void 0&&(B.signal=o.signal);const T=Lt(o.query,y),N=await en({url:v,request:{_tag:"Single",document:T,variables:o.variables},headers:{...lt(Xt(a)),...lt(o.requestHeaders)},fetch:u,method:h,fetchOptions:B,middleware:l});if(m&&await m(N,{operationName:T.operationName,variables:i,url:this.url}),N instanceof Error)throw N;return N};async request(t,...n){const[i,c]=n,o=li(t,i,c),{headers:a,fetch:u=globalThis.fetch,method:h="POST",requestMiddleware:l,responseMiddleware:m,excludeOperationName:y,...B}=this.requestConfig,{url:v}=this;o.signal!==void 0&&(B.signal=o.signal);const T=Lt(o.document,y),N=await en({url:v,request:{_tag:"Single",document:T,variables:o.variables},headers:{...lt(Xt(a)),...lt(o.requestHeaders)},fetch:u,method:h,fetchOptions:B,middleware:l});if(m&&await m(N,{operationName:T.operationName,variables:o.variables,url:this.url}),N instanceof Error)throw N;return N.data}async batchRequests(t,n){const i=ei(t,n),{headers:c,excludeOperationName:o,...a}=this.requestConfig;i.signal!==void 0&&(a.signal=i.signal);const u=i.documents.map(({document:B})=>Lt(B,o)),h=u.map(({expression:B})=>B),l=u.some(({isMutation:B})=>B),m=i.documents.map(({variables:B})=>B),y=await en({url:this.url,request:{_tag:"Batch",operationName:void 0,query:h,hasMutations:l,variables:m},headers:{...lt(Xt(c)),...lt(i.requestHeaders)},fetch:this.requestConfig.fetch??globalThis.fetch,method:this.requestConfig.method||"POST",fetchOptions:a,middleware:this.requestConfig.requestMiddleware});if(this.requestConfig.responseMiddleware&&await this.requestConfig.responseMiddleware(y,{operationName:void 0,variables:m,url:this.url}),y instanceof Error)throw y;return y.data}setHeaders(t){return this.requestConfig.headers=t,this}setHeader(t,n){const{headers:i}=this.requestConfig;return i?i[t]=n:this.requestConfig.headers={[t]:n},this}setEndpoint(t){return this.url=t,this}}const li=(e,t,n)=>e.document?e:{document:e,variables:t,requestHeaders:n,signal:void 0},hi=(e,...t)=>e.reduce((n,i,c)=>`${n}${i}${c in t?String(t[c]):""}`,"");/*!
|
|
9
9
|
* decimal.js v10.6.0
|
|
10
10
|
* An arbitrary-precision Decimal type for JavaScript.
|
|
11
11
|
* https://github.com/MikeMcl/decimal.js
|
|
12
12
|
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
13
13
|
* MIT Licence
|
|
14
|
-
*/var ht=9e15,Je=1e9,tn="0123456789abcdef",At="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Tt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",nn={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ht,maxE:ht,crypto:!1},Qn,Ye,me=!0,Nt="[DecimalError] ",Le=Nt+"Invalid argument: ",Jn=Nt+"Precision limit exceeded",Ln=Nt+"crypto unavailable",Dn="[object Decimal]",Ie=Math.floor,Ue=Math.pow,li=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,hi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,di=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,er=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Ze=1e7,he=7,pi=9007199254740991,gi=At.length-1,rn=Tt.length-1,X={toStringTag:Dn};X.absoluteValue=X.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),fe(e)},X.ceil=function(){return fe(new this.constructor(this),this.e+1,2)},X.clampedTo=X.clamp=function(e,t){var n,i=this,c=i.constructor;if(e=new c(e),t=new c(t),!e.s||!t.s)return new c(NaN);if(e.gt(t))throw Error(Le+t);return n=i.cmp(e),n<0?e:i.cmp(t)>0?t:new c(i)},X.comparedTo=X.cmp=function(e){var t,n,i,c,o=this,a=o.d,u=(e=new o.constructor(e)).d,h=o.s,l=e.s;if(!a||!u)return!h||!l?NaN:h!==l?h:a===u?0:!a^h<0?1:-1;if(!a[0]||!u[0])return a[0]?h:u[0]?-l:0;if(h!==l)return h;if(o.e!==e.e)return o.e>e.e^h<0?1:-1;for(i=a.length,c=u.length,t=0,n=i<c?i:c;t<n;++t)if(a[t]!==u[t])return a[t]>u[t]^h<0?1:-1;return i===c?0:i>c^h<0?1:-1},X.cosine=X.cos=function(){var e,t,n=this,i=n.constructor;return n.d?n.d[0]?(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+he,i.rounding=1,n=mi(i,sr(i,n)),i.precision=e,i.rounding=t,fe(Ye==2||Ye==3?n.neg():n,e,t,!0)):new i(1):new i(NaN)},X.cubeRoot=X.cbrt=function(){var e,t,n,i,c,o,a,u,h,l,m=this,y=m.constructor;if(!m.isFinite()||m.isZero())return new y(m);for(me=!1,o=m.s*Ue(m.s*m,1/3),!o||Math.abs(o)==1/0?(n=Pe(m.d),e=m.e,(o=(e-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=Ue(n,1/3),e=Ie((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?n="5e"+e:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),i=new y(n),i.s=m.s):i=new y(o.toString()),a=(e=y.precision)+3;;)if(u=i,h=u.times(u).times(u),l=h.plus(m),i=ve(l.plus(m).times(u),l.plus(h),a+2,1),Pe(u.d).slice(0,a)===(n=Pe(i.d)).slice(0,a))if(n=n.slice(a-3,a+1),n=="9999"||!c&&n=="4999"){if(!c&&(fe(u,e+1,0),u.times(u).times(u).eq(m))){i=u;break}a+=4,c=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(fe(i,e+1,1),t=!i.times(i).times(i).eq(m));break}return me=!0,fe(i,e,y.rounding,t)},X.decimalPlaces=X.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Ie(this.e/he))*he,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},X.dividedBy=X.div=function(e){return ve(this,new this.constructor(e))},X.dividedToIntegerBy=X.divToInt=function(e){var t=this,n=t.constructor;return fe(ve(t,new n(e),0,1,1),n.precision,n.rounding)},X.equals=X.eq=function(e){return this.cmp(e)===0},X.floor=function(){return fe(new this.constructor(this),this.e+1,3)},X.greaterThan=X.gt=function(e){return this.cmp(e)>0},X.greaterThanOrEqualTo=X.gte=function(e){var t=this.cmp(e);return t==1||t===0},X.hyperbolicCosine=X.cosh=function(){var e,t,n,i,c,o=this,a=o.constructor,u=new a(1);if(!o.isFinite())return new a(o.s?1/0:NaN);if(o.isZero())return u;n=a.precision,i=a.rounding,a.precision=n+Math.max(o.e,o.sd())+4,a.rounding=1,c=o.d.length,c<32?(e=Math.ceil(c/3),t=(1/qt(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=dt(a,1,o.times(t),new a(1),!0);for(var h,l=e,m=new a(8);l--;)h=o.times(o),o=u.minus(h.times(m.minus(h.times(m))));return fe(o,a.precision=n,a.rounding=i,!0)},X.hyperbolicSine=X.sinh=function(){var e,t,n,i,c=this,o=c.constructor;if(!c.isFinite()||c.isZero())return new o(c);if(t=o.precision,n=o.rounding,o.precision=t+Math.max(c.e,c.sd())+4,o.rounding=1,i=c.d.length,i<3)c=dt(o,2,c,c,!0);else{e=1.4*Math.sqrt(i),e=e>16?16:e|0,c=c.times(1/qt(5,e)),c=dt(o,2,c,c,!0);for(var a,u=new o(5),h=new o(16),l=new o(20);e--;)a=c.times(c),c=c.times(u.plus(a.times(h.times(a).plus(l))))}return o.precision=t,o.rounding=n,fe(c,t,n,!0)},X.hyperbolicTangent=X.tanh=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+7,i.rounding=1,ve(n.sinh(),n.cosh(),i.precision=e,i.rounding=t)):new i(n.s)},X.inverseCosine=X.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),i=t.precision,c=t.rounding;return n!==-1?n===0?e.isNeg()?We(t,i,c):new t(0):new t(NaN):e.isZero()?We(t,i+4,c).times(.5):(t.precision=i+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=i,t.rounding=c,e.times(2))},X.inverseHyperbolicCosine=X.acosh=function(){var e,t,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(e=i.precision,t=i.rounding,i.precision=e+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,me=!1,n=n.times(n).minus(1).sqrt().plus(n),me=!0,i.precision=e,i.rounding=t,n.ln()):new i(n)},X.inverseHyperbolicSine=X.asinh=function(){var e,t,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,me=!1,n=n.times(n).plus(1).sqrt().plus(n),me=!0,i.precision=e,i.rounding=t,n.ln())},X.inverseHyperbolicTangent=X.atanh=function(){var e,t,n,i,c=this,o=c.constructor;return c.isFinite()?c.e>=0?new o(c.abs().eq(1)?c.s/0:c.isZero()?c:NaN):(e=o.precision,t=o.rounding,i=c.sd(),Math.max(i,e)<2*-c.e-1?fe(new o(c),e,t,!0):(o.precision=n=i-c.e,c=ve(c.plus(1),new o(1).minus(c),n+e,1),o.precision=e+4,o.rounding=1,c=c.ln(),o.precision=e,o.rounding=t,c.times(.5))):new o(NaN)},X.inverseSine=X.asin=function(){var e,t,n,i,c=this,o=c.constructor;return c.isZero()?new o(c):(t=c.abs().cmp(1),n=o.precision,i=o.rounding,t!==-1?t===0?(e=We(o,n+4,i).times(.5),e.s=c.s,e):new o(NaN):(o.precision=n+6,o.rounding=1,c=c.div(new o(1).minus(c.times(c)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=i,c.times(2)))},X.inverseTangent=X.atan=function(){var e,t,n,i,c,o,a,u,h,l=this,m=l.constructor,y=m.precision,B=m.rounding;if(l.isFinite()){if(l.isZero())return new m(l);if(l.abs().eq(1)&&y+4<=rn)return a=We(m,y+4,B).times(.25),a.s=l.s,a}else{if(!l.s)return new m(NaN);if(y+4<=rn)return a=We(m,y+4,B).times(.5),a.s=l.s,a}for(m.precision=u=y+10,m.rounding=1,n=Math.min(28,u/he+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(me=!1,t=Math.ceil(u/he),i=1,h=l.times(l),a=new m(l),c=l;e!==-1;)if(c=c.times(h),o=a.minus(c.div(i+=2)),c=c.times(h),a=o.plus(c.div(i+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===o.d[e]&&e--;);return n&&(a=a.times(2<<n-1)),me=!0,fe(a,m.precision=y,m.rounding=B,!0)},X.isFinite=function(){return!!this.d},X.isInteger=X.isInt=function(){return!!this.d&&Ie(this.e/he)>this.d.length-2},X.isNaN=function(){return!this.s},X.isNegative=X.isNeg=function(){return this.s<0},X.isPositive=X.isPos=function(){return this.s>0},X.isZero=function(){return!!this.d&&this.d[0]===0},X.lessThan=X.lt=function(e){return this.cmp(e)<0},X.lessThanOrEqualTo=X.lte=function(e){return this.cmp(e)<1},X.logarithm=X.log=function(e){var t,n,i,c,o,a,u,h,l=this,m=l.constructor,y=m.precision,B=m.rounding,v=5;if(e==null)e=new m(10),t=!0;else{if(e=new m(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new m(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new m(n&&!n[0]?-1/0:l.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)o=!0;else{for(c=n[0];c%10===0;)c/=10;o=c!==1}if(me=!1,u=y+v,a=et(l,u),i=t?Ht(m,u+10):et(e,u),h=ve(a,i,u,1),Et(h.d,c=y,B))do if(u+=10,a=et(l,u),i=t?Ht(m,u+10):et(e,u),h=ve(a,i,u,1),!o){+Pe(h.d).slice(c+1,c+15)+1==1e14&&(h=fe(h,y+1,0));break}while(Et(h.d,c+=10,B));return me=!0,fe(h,y,B)},X.minus=X.sub=function(e){var t,n,i,c,o,a,u,h,l,m,y,B,v=this,T=v.constructor;if(e=new T(e),!v.d||!e.d)return!v.s||!e.s?e=new T(NaN):v.d?e.s=-e.s:e=new T(e.d||v.s!==e.s?v:NaN),e;if(v.s!=e.s)return e.s=-e.s,v.plus(e);if(l=v.d,B=e.d,u=T.precision,h=T.rounding,!l[0]||!B[0]){if(B[0])e.s=-e.s;else if(l[0])e=new T(v);else return new T(h===3?-0:0);return me?fe(e,u,h):e}if(n=Ie(e.e/he),m=Ie(v.e/he),l=l.slice(),o=m-n,o){for(y=o<0,y?(t=l,o=-o,a=B.length):(t=B,n=m,a=l.length),i=Math.max(Math.ceil(u/he),a)+2,o>i&&(o=i,t.length=1),t.reverse(),i=o;i--;)t.push(0);t.reverse()}else{for(i=l.length,a=B.length,y=i<a,y&&(a=i),i=0;i<a;i++)if(l[i]!=B[i]){y=l[i]<B[i];break}o=0}for(y&&(t=l,l=B,B=t,e.s=-e.s),a=l.length,i=B.length-a;i>0;--i)l[a++]=0;for(i=B.length;i>o;){if(l[--i]<B[i]){for(c=i;c&&l[--c]===0;)l[c]=Ze-1;--l[c],l[i]+=Ze}l[i]-=B[i]}for(;l[--a]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=Ot(l,n),me?fe(e,u,h):e):new T(h===3?-0:0)},X.modulo=X.mod=function(e){var t,n=this,i=n.constructor;return e=new i(e),!n.d||!e.s||e.d&&!e.d[0]?new i(NaN):!e.d||n.d&&!n.d[0]?fe(new i(n),i.precision,i.rounding):(me=!1,i.modulo==9?(t=ve(n,e.abs(),0,3,1),t.s*=e.s):t=ve(n,e,0,i.modulo,1),t=t.times(e),me=!0,n.minus(t))},X.naturalExponential=X.exp=function(){return on(this)},X.naturalLogarithm=X.ln=function(){return et(this)},X.negated=X.neg=function(){var e=new this.constructor(this);return e.s=-e.s,fe(e)},X.plus=X.add=function(e){var t,n,i,c,o,a,u,h,l,m,y=this,B=y.constructor;if(e=new B(e),!y.d||!e.d)return!y.s||!e.s?e=new B(NaN):y.d||(e=new B(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(l=y.d,m=e.d,u=B.precision,h=B.rounding,!l[0]||!m[0])return m[0]||(e=new B(y)),me?fe(e,u,h):e;if(o=Ie(y.e/he),i=Ie(e.e/he),l=l.slice(),c=o-i,c){for(c<0?(n=l,c=-c,a=m.length):(n=m,i=o,a=l.length),o=Math.ceil(u/he),a=o>a?o+1:a+1,c>a&&(c=a,n.length=1),n.reverse();c--;)n.push(0);n.reverse()}for(a=l.length,c=m.length,a-c<0&&(c=a,n=m,m=l,l=n),t=0;c;)t=(l[--c]=l[c]+m[c]+t)/Ze|0,l[c]%=Ze;for(t&&(l.unshift(t),++i),a=l.length;l[--a]==0;)l.pop();return e.d=l,e.e=Ot(l,i),me?fe(e,u,h):e},X.precision=X.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Le+e);return n.d?(t=tr(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},X.round=function(){var e=this,t=e.constructor;return fe(new t(e),e.e+1,t.rounding)},X.sine=X.sin=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+he,i.rounding=1,n=yi(i,sr(i,n)),i.precision=e,i.rounding=t,fe(Ye>2?n.neg():n,e,t,!0)):new i(NaN)},X.squareRoot=X.sqrt=function(){var e,t,n,i,c,o,a=this,u=a.d,h=a.e,l=a.s,m=a.constructor;if(l!==1||!u||!u[0])return new m(!l||l<0&&(!u||u[0])?NaN:u?a:1/0);for(me=!1,l=Math.sqrt(+a),l==0||l==1/0?(t=Pe(u),(t.length+h)%2==0&&(t+="0"),l=Math.sqrt(t),h=Ie((h+1)/2)-(h<0||h%2),l==1/0?t="5e"+h:(t=l.toExponential(),t=t.slice(0,t.indexOf("e")+1)+h),i=new m(t)):i=new m(l.toString()),n=(h=m.precision)+3;;)if(o=i,i=o.plus(ve(a,o,n+2,1)).times(.5),Pe(o.d).slice(0,n)===(t=Pe(i.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!c&&t=="4999"){if(!c&&(fe(o,h+1,0),o.times(o).eq(a))){i=o;break}n+=4,c=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(fe(i,h+1,1),e=!i.times(i).eq(a));break}return me=!0,fe(i,h,m.rounding,e)},X.tangent=X.tan=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+10,i.rounding=1,n=n.sin(),n.s=1,n=ve(n,new i(1).minus(n.times(n)).sqrt(),e+10,0),i.precision=e,i.rounding=t,fe(Ye==2||Ye==4?n.neg():n,e,t,!0)):new i(NaN)},X.times=X.mul=function(e){var t,n,i,c,o,a,u,h,l,m=this,y=m.constructor,B=m.d,v=(e=new y(e)).d;if(e.s*=m.s,!B||!B[0]||!v||!v[0])return new y(!e.s||B&&!B[0]&&!v||v&&!v[0]&&!B?NaN:!B||!v?e.s/0:e.s*0);for(n=Ie(m.e/he)+Ie(e.e/he),h=B.length,l=v.length,h<l&&(o=B,B=v,v=o,a=h,h=l,l=a),o=[],a=h+l,i=a;i--;)o.push(0);for(i=l;--i>=0;){for(t=0,c=h+i;c>i;)u=o[c]+v[i]*B[c-i-1]+t,o[c--]=u%Ze|0,t=u/Ze|0;o[c]=(o[c]+t)%Ze|0}for(;!o[--a];)o.pop();return t?++n:o.shift(),e.d=o,e.e=Ot(o,n),me?fe(e,y.precision,y.rounding):e},X.toBinary=function(e,t){return sn(this,2,e,t)},X.toDecimalPlaces=X.toDP=function(e,t){var n=this,i=n.constructor;return n=new i(n),e===void 0?n:(Fe(e,0,Je),t===void 0?t=i.rounding:Fe(t,0,8),fe(n,e+n.e+1,t))},X.toExponential=function(e,t){var n,i=this,c=i.constructor;return e===void 0?n=Ge(i,!0):(Fe(e,0,Je),t===void 0?t=c.rounding:Fe(t,0,8),i=fe(new c(i),e+1,t),n=Ge(i,!0,e+1)),i.isNeg()&&!i.isZero()?"-"+n:n},X.toFixed=function(e,t){var n,i,c=this,o=c.constructor;return e===void 0?n=Ge(c):(Fe(e,0,Je),t===void 0?t=o.rounding:Fe(t,0,8),i=fe(new o(c),e+c.e+1,t),n=Ge(i,!1,e+i.e+1)),c.isNeg()&&!c.isZero()?"-"+n:n},X.toFraction=function(e){var t,n,i,c,o,a,u,h,l,m,y,B,v=this,T=v.d,N=v.constructor;if(!T)return new N(v);if(l=n=new N(1),i=h=new N(0),t=new N(i),o=t.e=tr(T)-v.e-1,a=o%he,t.d[0]=Ue(10,a<0?he+a:a),e==null)e=o>0?t:l;else{if(u=new N(e),!u.isInt()||u.lt(l))throw Error(Le+u);e=u.gt(t)?o>0?t:l:u}for(me=!1,u=new N(Pe(T)),m=N.precision,N.precision=o=T.length*he*2;y=ve(u,t,0,1,1),c=n.plus(y.times(i)),c.cmp(e)!=1;)n=i,i=c,c=l,l=h.plus(y.times(c)),h=c,c=t,t=u.minus(y.times(c)),u=c;return c=ve(e.minus(n),i,0,1,1),h=h.plus(c.times(l)),n=n.plus(c.times(i)),h.s=l.s=v.s,B=ve(l,i,o,1).minus(v).abs().cmp(ve(h,n,o,1).minus(v).abs())<1?[l,i]:[h,n],N.precision=m,me=!0,B},X.toHexadecimal=X.toHex=function(e,t){return sn(this,16,e,t)},X.toNearest=function(e,t){var n=this,i=n.constructor;if(n=new i(n),e==null){if(!n.d)return n;e=new i(1),t=i.rounding}else{if(e=new i(e),t===void 0?t=i.rounding:Fe(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]?(me=!1,n=ve(n,e,0,t,1).times(e),me=!0,fe(n)):(e.s=n.s,n=e),n},X.toNumber=function(){return+this},X.toOctal=function(e,t){return sn(this,8,e,t)},X.toPower=X.pow=function(e){var t,n,i,c,o,a,u=this,h=u.constructor,l=+(e=new h(e));if(!u.d||!e.d||!u.d[0]||!e.d[0])return new h(Ue(+u,l));if(u=new h(u),u.eq(1))return u;if(i=h.precision,o=h.rounding,e.eq(1))return fe(u,i,o);if(t=Ie(e.e/he),t>=e.d.length-1&&(n=l<0?-l:l)<=pi)return c=nr(h,u,n,i),e.s<0?new h(1).div(c):fe(c,i,o);if(a=u.s,a<0){if(t<e.d.length-1)return new h(NaN);if((e.d[t]&1)==0&&(a=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=a,u}return n=Ue(+u,l),t=n==0||!isFinite(n)?Ie(l*(Math.log("0."+Pe(u.d))/Math.LN10+u.e+1)):new h(n+"").e,t>h.maxE+1||t<h.minE-1?new h(t>0?a/0:0):(me=!1,h.rounding=u.s=1,n=Math.min(12,(t+"").length),c=on(e.times(et(u,i+n)),i),c.d&&(c=fe(c,i+5,1),Et(c.d,i,o)&&(t=i+10,c=fe(on(e.times(et(u,t+n)),t),t+5,1),+Pe(c.d).slice(i+1,i+15)+1==1e14&&(c=fe(c,i+1,0)))),c.s=a,me=!0,h.rounding=o,fe(c,i,o))},X.toPrecision=function(e,t){var n,i=this,c=i.constructor;return e===void 0?n=Ge(i,i.e<=c.toExpNeg||i.e>=c.toExpPos):(Fe(e,1,Je),t===void 0?t=c.rounding:Fe(t,0,8),i=fe(new c(i),e,t),n=Ge(i,e<=i.e||i.e<=c.toExpNeg,e)),i.isNeg()&&!i.isZero()?"-"+n:n},X.toSignificantDigits=X.toSD=function(e,t){var n=this,i=n.constructor;return e===void 0?(e=i.precision,t=i.rounding):(Fe(e,1,Je),t===void 0?t=i.rounding:Fe(t,0,8)),fe(new i(n),e,t)},X.toString=function(){var e=this,t=e.constructor,n=Ge(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n},X.truncated=X.trunc=function(){return fe(new this.constructor(this),this.e+1,1)},X.valueOf=X.toJSON=function(){var e=this,t=e.constructor,n=Ge(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function Pe(e){var t,n,i,c=e.length-1,o="",a=e[0];if(c>0){for(o+=a,t=1;t<c;t++)i=e[t]+"",n=he-i.length,n&&(o+=De(n)),o+=i;a=e[t],i=a+"",n=he-i.length,n&&(o+=De(n))}else if(a===0)return"0";for(;a%10===0;)a/=10;return o+a}function Fe(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Le+e)}function Et(e,t,n,i){var c,o,a,u;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=he,c=0):(c=Math.ceil((t+1)/he),t%=he),o=Ue(10,he-t),u=e[c]%o|0,i==null?t<3?(t==0?u=u/100|0:t==1&&(u=u/10|0),a=n<4&&u==99999||n>3&&u==49999||u==5e4||u==0):a=(n<4&&u+1==o||n>3&&u+1==o/2)&&(e[c+1]/o/100|0)==Ue(10,t-2)-1||(u==o/2||u==0)&&(e[c+1]/o/100|0)==0:t<4?(t==0?u=u/1e3|0:t==1?u=u/100|0:t==2&&(u=u/10|0),a=(i||n<4)&&u==9999||!i&&n>3&&u==4999):a=((i||n<4)&&u+1==o||!i&&n>3&&u+1==o/2)&&(e[c+1]/o/1e3|0)==Ue(10,t-3)-1,a}function Rt(e,t,n){for(var i,c=[0],o,a=0,u=e.length;a<u;){for(o=c.length;o--;)c[o]*=t;for(c[0]+=tn.indexOf(e.charAt(a++)),i=0;i<c.length;i++)c[i]>n-1&&(c[i+1]===void 0&&(c[i+1]=0),c[i+1]+=c[i]/n|0,c[i]%=n)}return c.reverse()}function mi(e,t){var n,i,c;if(t.isZero())return t;i=t.d.length,i<32?(n=Math.ceil(i/3),c=(1/qt(4,n)).toString()):(n=16,c="2.3283064365386962890625e-10"),e.precision+=n,t=dt(e,1,t.times(c),new e(1));for(var o=n;o--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=n,t}var ve=(function(){function e(i,c,o){var a,u=0,h=i.length;for(i=i.slice();h--;)a=i[h]*c+u,i[h]=a%o|0,u=a/o|0;return u&&i.unshift(u),i}function t(i,c,o,a){var u,h;if(o!=a)h=o>a?1:-1;else for(u=h=0;u<o;u++)if(i[u]!=c[u]){h=i[u]>c[u]?1:-1;break}return h}function n(i,c,o,a){for(var u=0;o--;)i[o]-=u,u=i[o]<c[o]?1:0,i[o]=u*a+i[o]-c[o];for(;!i[0]&&i.length>1;)i.shift()}return function(i,c,o,a,u,h){var l,m,y,B,v,T,N,K,J,F,b,P,I,O,U,Z,R,C,j,Q,V=i.constructor,$=i.s==c.s?1:-1,w=i.d,H=c.d;if(!w||!w[0]||!H||!H[0])return new V(!i.s||!c.s||(w?H&&w[0]==H[0]:!H)?NaN:w&&w[0]==0||!H?$*0:$/0);for(h?(v=1,m=i.e-c.e):(h=Ze,v=he,m=Ie(i.e/v)-Ie(c.e/v)),j=H.length,R=w.length,J=new V($),F=J.d=[],y=0;H[y]==(w[y]||0);y++);if(H[y]>(w[y]||0)&&m--,o==null?(O=o=V.precision,a=V.rounding):u?O=o+(i.e-c.e)+1:O=o,O<0)F.push(1),T=!0;else{if(O=O/v+2|0,y=0,j==1){for(B=0,H=H[0],O++;(y<R||B)&&O--;y++)U=B*h+(w[y]||0),F[y]=U/H|0,B=U%H|0;T=B||y<R}else{for(B=h/(H[0]+1)|0,B>1&&(H=e(H,B,h),w=e(w,B,h),j=H.length,R=w.length),Z=j,b=w.slice(0,j),P=b.length;P<j;)b[P++]=0;Q=H.slice(),Q.unshift(0),C=H[0],H[1]>=h/2&&++C;do B=0,l=t(H,b,j,P),l<0?(I=b[0],j!=P&&(I=I*h+(b[1]||0)),B=I/C|0,B>1?(B>=h&&(B=h-1),N=e(H,B,h),K=N.length,P=b.length,l=t(N,b,K,P),l==1&&(B--,n(N,j<K?Q:H,K,h))):(B==0&&(l=B=1),N=H.slice()),K=N.length,K<P&&N.unshift(0),n(b,N,P,h),l==-1&&(P=b.length,l=t(H,b,j,P),l<1&&(B++,n(b,j<P?Q:H,P,h))),P=b.length):l===0&&(B++,b=[0]),F[y++]=B,l&&b[0]?b[P++]=w[Z]||0:(b=[w[Z]],P=1);while((Z++<R||b[0]!==void 0)&&O--);T=b[0]!==void 0}F[0]||F.shift()}if(v==1)J.e=m,Qn=T;else{for(y=1,B=F[0];B>=10;B/=10)y++;J.e=y+m*v-1,fe(J,u?o+J.e+1:o,a,T)}return J}})();function fe(e,t,n,i){var c,o,a,u,h,l,m,y,B,v=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(c=1,u=y[0];u>=10;u/=10)c++;if(o=t-c,o<0)o+=he,a=t,m=y[B=0],h=m/Ue(10,c-a-1)%10|0;else if(B=Math.ceil((o+1)/he),u=y.length,B>=u)if(i){for(;u++<=B;)y.push(0);m=h=0,c=1,o%=he,a=o-he+1}else break e;else{for(m=u=y[B],c=1;u>=10;u/=10)c++;o%=he,a=o-he+c,h=a<0?0:m/Ue(10,c-a-1)%10|0}if(i=i||t<0||y[B+1]!==void 0||(a<0?m:m%Ue(10,c-a-1)),l=n<4?(h||i)&&(n==0||n==(e.s<0?3:2)):h>5||h==5&&(n==4||i||n==6&&(o>0?a>0?m/Ue(10,c-a):0:y[B-1])%10&1||n==(e.s<0?8:7)),t<1||!y[0])return y.length=0,l?(t-=e.e+1,y[0]=Ue(10,(he-t%he)%he),e.e=-t||0):y[0]=e.e=0,e;if(o==0?(y.length=B,u=1,B--):(y.length=B+1,u=Ue(10,he-o),y[B]=a>0?(m/Ue(10,c-a)%Ue(10,a)|0)*u:0),l)for(;;)if(B==0){for(o=1,a=y[0];a>=10;a/=10)o++;for(a=y[0]+=u,u=1;a>=10;a/=10)u++;o!=u&&(e.e++,y[0]==Ze&&(y[0]=1));break}else{if(y[B]+=u,y[B]!=Ze)break;y[B--]=0,u=1}for(o=y.length;y[--o]===0;)y.pop()}return me&&(e.e>v.maxE?(e.d=null,e.e=NaN):e.e<v.minE&&(e.e=0,e.d=[0])),e}function Ge(e,t,n){if(!e.isFinite())return or(e);var i,c=e.e,o=Pe(e.d),a=o.length;return t?(n&&(i=n-a)>0?o=o.charAt(0)+"."+o.slice(1)+De(i):a>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):c<0?(o="0."+De(-c-1)+o,n&&(i=n-a)>0&&(o+=De(i))):c>=a?(o+=De(c+1-a),n&&(i=n-c-1)>0&&(o=o+"."+De(i))):((i=c+1)<a&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-a)>0&&(c+1===a&&(o+="."),o+=De(i))),o}function Ot(e,t){var n=e[0];for(t*=he;n>=10;n/=10)t++;return t}function Ht(e,t,n){if(t>gi)throw me=!0,n&&(e.precision=n),Error(Jn);return fe(new e(At),t,1,!0)}function We(e,t,n){if(t>rn)throw Error(Jn);return fe(new e(Tt),t,n,!0)}function tr(e){var t=e.length-1,n=t*he+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 De(e){for(var t="";e--;)t+="0";return t}function nr(e,t,n,i){var c,o=new e(1),a=Math.ceil(i/he+4);for(me=!1;;){if(n%2&&(o=o.times(t),cr(o.d,a)&&(c=!0)),n=Ie(n/2),n===0){n=o.d.length-1,c&&o.d[n]===0&&++o.d[n];break}t=t.times(t),cr(t.d,a)}return me=!0,o}function rr(e){return e.d[e.d.length-1]&1}function ir(e,t,n){for(var i,c,o=new e(t[0]),a=0;++a<t.length;){if(c=new e(t[a]),!c.s){o=c;break}i=o.cmp(c),(i===n||i===0&&o.s===n)&&(o=c)}return o}function on(e,t){var n,i,c,o,a,u,h,l=0,m=0,y=0,B=e.constructor,v=B.rounding,T=B.precision;if(!e.d||!e.d[0]||e.e>17)return new B(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(me=!1,h=T):h=t,u=new B(.03125);e.e>-2;)e=e.times(u),y+=5;for(i=Math.log(Ue(2,y))/Math.LN10*2+5|0,h+=i,n=o=a=new B(1),B.precision=h;;){if(o=fe(o.times(e),h,1),n=n.times(++m),u=a.plus(ve(o,n,h,1)),Pe(u.d).slice(0,h)===Pe(a.d).slice(0,h)){for(c=y;c--;)a=fe(a.times(a),h,1);if(t==null)if(l<3&&Et(a.d,h-i,v,l))B.precision=h+=10,n=o=u=new B(1),m=0,l++;else return fe(a,B.precision=T,v,me=!0);else return B.precision=T,a}a=u}}function et(e,t){var n,i,c,o,a,u,h,l,m,y,B,v=1,T=10,N=e,K=N.d,J=N.constructor,F=J.rounding,b=J.precision;if(N.s<0||!K||!K[0]||!N.e&&K[0]==1&&K.length==1)return new J(K&&!K[0]?-1/0:N.s!=1?NaN:K?0:N);if(t==null?(me=!1,m=b):m=t,J.precision=m+=T,n=Pe(K),i=n.charAt(0),Math.abs(o=N.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)N=N.times(e),n=Pe(N.d),i=n.charAt(0),v++;o=N.e,i>1?(N=new J("0."+n),o++):N=new J(i+"."+n.slice(1))}else return l=Ht(J,m+2,b).times(o+""),N=et(new J(i+"."+n.slice(1)),m-T).plus(l),J.precision=b,t==null?fe(N,b,F,me=!0):N;for(y=N,h=a=N=ve(N.minus(1),N.plus(1),m,1),B=fe(N.times(N),m,1),c=3;;){if(a=fe(a.times(B),m,1),l=h.plus(ve(a,new J(c),m,1)),Pe(l.d).slice(0,m)===Pe(h.d).slice(0,m))if(h=h.times(2),o!==0&&(h=h.plus(Ht(J,m+2,b).times(o+""))),h=ve(h,new J(v),m,1),t==null)if(Et(h.d,m-T,F,u))J.precision=m+=T,l=a=N=ve(y.minus(1),y.plus(1),m,1),B=fe(N.times(N),m,1),c=u=1;else return fe(h,J.precision=b,F,me=!0);else return J.precision=b,h;h=l,c+=2}}function or(e){return String(e.s*e.s/0)}function Ut(e,t){var n,i,c;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(n<0&&(n=i),n+=+t.slice(i+1),t=t.substring(0,i)):n<0&&(n=t.length),i=0;t.charCodeAt(i)===48;i++);for(c=t.length;t.charCodeAt(c-1)===48;--c);if(t=t.slice(i,c),t){if(c-=i,e.e=n=n-i-1,e.d=[],i=(n+1)%he,n<0&&(i+=he),i<c){for(i&&e.d.push(+t.slice(0,i)),c-=he;i<c;)e.d.push(+t.slice(i,i+=he));t=t.slice(i),i=he-t.length}else i-=c;for(;i--;)t+="0";e.d.push(+t),me&&(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 wi(e,t){var n,i,c,o,a,u,h,l,m;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),er.test(t))return Ut(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(hi.test(t))n=16,t=t.toLowerCase();else if(li.test(t))n=2;else if(di.test(t))n=8;else throw Error(Le+t);for(o=t.search(/p/i),o>0?(h=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),a=o>=0,i=e.constructor,a&&(t=t.replace(".",""),u=t.length,o=u-o,c=nr(i,new i(n),o,o*2)),l=Rt(t,n,Ze),m=l.length-1,o=m;l[o]===0;--o)l.pop();return o<0?new i(e.s*0):(e.e=Ot(l,m),e.d=l,me=!1,a&&(e=ve(e,c,u*4)),h&&(e=e.times(Math.abs(h)<54?Ue(2,h):ut.pow(2,h))),me=!0,e)}function yi(e,t){var n,i=t.d.length;if(i<3)return t.isZero()?t:dt(e,2,t,t);n=1.4*Math.sqrt(i),n=n>16?16:n|0,t=t.times(1/qt(5,n)),t=dt(e,2,t,t);for(var c,o=new e(5),a=new e(16),u=new e(20);n--;)c=t.times(t),t=t.times(o.plus(c.times(a.times(c).minus(u))));return t}function dt(e,t,n,i,c){var o,a,u,h,l=e.precision,m=Math.ceil(l/he);for(me=!1,h=n.times(n),u=new e(i);;){if(a=ve(u.times(h),new e(t++*t++),l,1),u=c?i.plus(a):i.minus(a),i=ve(a.times(h),new e(t++*t++),l,1),a=u.plus(i),a.d[m]!==void 0){for(o=m;a.d[o]===u.d[o]&&o--;);if(o==-1)break}o=u,u=i,i=a,a=o}return me=!0,a.d.length=m+1,a}function qt(e,t){for(var n=e;--t;)n*=e;return n}function sr(e,t){var n,i=t.s<0,c=We(e,e.precision,1),o=c.times(.5);if(t=t.abs(),t.lte(o))return Ye=i?4:1,t;if(n=t.divToInt(c),n.isZero())Ye=i?3:2;else{if(t=t.minus(n.times(c)),t.lte(o))return Ye=rr(n)?i?2:3:i?4:1,t;Ye=rr(n)?i?1:4:i?3:2}return t.minus(c).abs()}function sn(e,t,n,i){var c,o,a,u,h,l,m,y,B,v=e.constructor,T=n!==void 0;if(T?(Fe(n,1,Je),i===void 0?i=v.rounding:Fe(i,0,8)):(n=v.precision,i=v.rounding),!e.isFinite())m=or(e);else{for(m=Ge(e),a=m.indexOf("."),T?(c=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):c=t,a>=0&&(m=m.replace(".",""),B=new v(1),B.e=m.length-a,B.d=Rt(Ge(B),10,c),B.e=B.d.length),y=Rt(m,10,c),o=h=y.length;y[--h]==0;)y.pop();if(!y[0])m=T?"0p+0":"0";else{if(a<0?o--:(e=new v(e),e.d=y,e.e=o,e=ve(e,B,n,i,0,c),y=e.d,o=e.e,l=Qn),a=y[n],u=c/2,l=l||y[n+1]!==void 0,l=i<4?(a!==void 0||l)&&(i===0||i===(e.s<0?3:2)):a>u||a===u&&(i===4||l||i===6&&y[n-1]&1||i===(e.s<0?8:7)),y.length=n,l)for(;++y[--n]>c-1;)y[n]=0,n||(++o,y.unshift(1));for(h=y.length;!y[h-1];--h);for(a=0,m="";a<h;a++)m+=tn.charAt(y[a]);if(T){if(h>1)if(t==16||t==8){for(a=t==16?4:3,--h;h%a;h++)m+="0";for(y=Rt(m,c,t),h=y.length;!y[h-1];--h);for(a=1,m="1.";a<h;a++)m+=tn.charAt(y[a])}else m=m.charAt(0)+"."+m.slice(1);m=m+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)m="0"+m;m="0."+m}else if(++o>h)for(o-=h;o--;)m+="0";else o<h&&(m=m.slice(0,o)+"."+m.slice(o))}m=(t==16?"0x":t==2?"0b":t==8?"0o":"")+m}return e.s<0?"-"+m:m}function cr(e,t){if(e.length>t)return e.length=t,!0}function bi(e){return new this(e).abs()}function Ei(e){return new this(e).acos()}function Bi(e){return new this(e).acosh()}function xi(e,t){return new this(e).plus(t)}function _i(e){return new this(e).asin()}function vi(e){return new this(e).asinh()}function Si(e){return new this(e).atan()}function Ai(e){return new this(e).atanh()}function Ti(e,t){e=new this(e),t=new this(t);var n,i=this.precision,c=this.rounding,o=i+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=We(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?We(this,i,c):new this(0),n.s=e.s):!e.d||t.isZero()?(n=We(this,o,1).times(.5),n.s=e.s):t.s<0?(this.precision=o,this.rounding=1,n=this.atan(ve(e,t,o,1)),t=We(this,o,1),this.precision=i,this.rounding=c,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(ve(e,t,o,1)),n}function Ni(e){return new this(e).cbrt()}function Ri(e){return fe(e=new this(e),e.e+1,2)}function Oi(e,t,n){return new this(e).clamp(t,n)}function Hi(e){if(!e||typeof e!="object")throw Error(Nt+"Object expected");var t,n,i,c=e.defaults===!0,o=["precision",1,Je,"rounding",0,8,"toExpNeg",-ht,0,"toExpPos",0,ht,"maxE",0,ht,"minE",-ht,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],c&&(this[n]=nn[n]),(i=e[n])!==void 0)if(Ie(i)===i&&i>=o[t+1]&&i<=o[t+2])this[n]=i;else throw Error(Le+n+": "+i);if(n="crypto",c&&(this[n]=nn[n]),(i=e[n])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Ln);else this[n]=!1;else throw Error(Le+n+": "+i);return this}function Ui(e){return new this(e).cos()}function qi(e){return new this(e).cosh()}function ur(e){var t,n,i;function c(o){var a,u,h,l=this;if(!(l instanceof c))return new c(o);if(l.constructor=c,ar(o)){l.s=o.s,me?!o.d||o.e>c.maxE?(l.e=NaN,l.d=null):o.e<c.minE?(l.e=0,l.d=[0]):(l.e=o.e,l.d=o.d.slice()):(l.e=o.e,l.d=o.d?o.d.slice():o.d);return}if(h=typeof o,h==="number"){if(o===0){l.s=1/o<0?-1:1,l.e=0,l.d=[0];return}if(o<0?(o=-o,l.s=-1):l.s=1,o===~~o&&o<1e7){for(a=0,u=o;u>=10;u/=10)a++;me?a>c.maxE?(l.e=NaN,l.d=null):a<c.minE?(l.e=0,l.d=[0]):(l.e=a,l.d=[o]):(l.e=a,l.d=[o]);return}if(o*0!==0){o||(l.s=NaN),l.e=NaN,l.d=null;return}return Ut(l,o.toString())}if(h==="string")return(u=o.charCodeAt(0))===45?(o=o.slice(1),l.s=-1):(u===43&&(o=o.slice(1)),l.s=1),er.test(o)?Ut(l,o):wi(l,o);if(h==="bigint")return o<0?(o=-o,l.s=-1):l.s=1,Ut(l,o.toString());throw Error(Le+o)}if(c.prototype=X,c.ROUND_UP=0,c.ROUND_DOWN=1,c.ROUND_CEIL=2,c.ROUND_FLOOR=3,c.ROUND_HALF_UP=4,c.ROUND_HALF_DOWN=5,c.ROUND_HALF_EVEN=6,c.ROUND_HALF_CEIL=7,c.ROUND_HALF_FLOOR=8,c.EUCLID=9,c.config=c.set=Hi,c.clone=ur,c.isDecimal=ar,c.abs=bi,c.acos=Ei,c.acosh=Bi,c.add=xi,c.asin=_i,c.asinh=vi,c.atan=Si,c.atanh=Ai,c.atan2=Ti,c.cbrt=Ni,c.ceil=Ri,c.clamp=Oi,c.cos=Ui,c.cosh=qi,c.div=Pi,c.exp=Ci,c.floor=Ii,c.hypot=ki,c.ln=Mi,c.log=Fi,c.log10=ji,c.log2=Vi,c.max=$i,c.min=Zi,c.mod=Ki,c.mul=Gi,c.pow=Wi,c.random=zi,c.round=Xi,c.sign=Yi,c.sin=Qi,c.sinh=Ji,c.sqrt=Li,c.sub=Di,c.sum=eo,c.tan=to,c.tanh=no,c.trunc=ro,e===void 0&&(e={}),e&&e.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)e.hasOwnProperty(n=i[t++])||(e[n]=this[n]);return c.config(e),c}function Pi(e,t){return new this(e).div(t)}function Ci(e){return new this(e).exp()}function Ii(e){return fe(e=new this(e),e.e+1,3)}function ki(){var e,t,n=new this(0);for(me=!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 me=!0,new this(1/0);n=t}return me=!0,n.sqrt()}function ar(e){return e instanceof ut||e&&e.toStringTag===Dn||!1}function Mi(e){return new this(e).ln()}function Fi(e,t){return new this(e).log(t)}function Vi(e){return new this(e).log(2)}function ji(e){return new this(e).log(10)}function $i(){return ir(this,arguments,-1)}function Zi(){return ir(this,arguments,1)}function Ki(e,t){return new this(e).mod(t)}function Gi(e,t){return new this(e).mul(t)}function Wi(e,t){return new this(e).pow(t)}function zi(e){var t,n,i,c,o=0,a=new this(1),u=[];if(e===void 0?e=this.precision:Fe(e,1,Je),i=Math.ceil(e/he),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));o<i;)c=t[o],c>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:u[o++]=c%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);o<i;)c=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),c>=214e7?crypto.randomBytes(4).copy(t,o):(u.push(c%1e7),o+=4);o=i/4}else throw Error(Ln);else for(;o<i;)u[o++]=Math.random()*1e7|0;for(i=u[--o],e%=he,i&&e&&(c=Ue(10,he-e),u[o]=(i/c|0)*c);u[o]===0;o--)u.pop();if(o<0)n=0,u=[0];else{for(n=-1;u[0]===0;n-=he)u.shift();for(i=1,c=u[0];c>=10;c/=10)i++;i<he&&(n-=he-i)}return a.e=n,a.d=u,a}function Xi(e){return fe(e=new this(e),e.e+1,this.rounding)}function Yi(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Qi(e){return new this(e).sin()}function Ji(e){return new this(e).sinh()}function Li(e){return new this(e).sqrt()}function Di(e,t){return new this(e).sub(t)}function eo(){var e=0,t=arguments,n=new this(t[e]);for(me=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return me=!0,fe(n,this.precision,this.rounding)}function to(e){return new this(e).tan()}function no(e){return new this(e).tanh()}function ro(e){return fe(e=new this(e),e.e+1,1)}X[Symbol.for("nodejs.util.inspect.custom")]=X.toString,X[Symbol.toStringTag]="Decimal";var ut=X.constructor=ur(nn);At=new ut(At),Tt=new ut(Tt);const io=({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}),i=e.Record({input_types:e.Vec(n),pool_address:e.Vec(e.Text),output_types:e.Vec(n)}),c=e.Variant({Ok:e.Nat64,Err:e.Text}),o=e.Record({user_id:e.Principal}),a=e.Record({canister_version:e.Opt(e.Nat64),canister_id:e.Principal}),u=e.Variant({from_user:o,from_canister:a}),h=e.Record({controllers:e.Vec(e.Principal)}),l=e.Variant({reinstall:e.Null,upgrade:e.Null,install:e.Null}),m=e.Record({mode:l,module_hash:e.Vec(e.Nat8)}),y=e.Record({canister_version:e.Nat64,taken_at_timestamp:e.Nat64,snapshot_id:e.Vec(e.Nat8)}),B=e.Variant({creation:h,code_deployment:m,load_snapshot:y,controllers_change:h,code_uninstall:e.Null}),v=e.Record({timestamp_nanos:e.Nat64,canister_version:e.Nat64,origin:u,details:B}),T=e.Record({controllers:e.Vec(e.Principal),module_hash:e.Opt(e.Vec(e.Nat8)),recent_changes:e.Vec(v),total_num_changes:e.Nat64}),N=e.Variant({Ok:T,Err:e.Text}),K=e.Record({exchange_id:e.Text,pool_address:e.Text,pool_key:e.Text}),J=e.Variant({All:e.Null,ByTxid:e.Text,ByAddress:e.Text,BySecondsPassed:e.Nat64}),F=e.Variant({Ok:e.Text,Err:e.Text}),b=e.Record({result:F,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}),P=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(b),processing_result:F,broadcasted_time:e.Opt(e.Text)}),I=e.Record({block_hash:e.Text,block_height:e.Nat32}),O=e.Record({processing_results:e.Vec(e.Text),block_basic:I,txids:e.Vec(e.Text),block_time:e.Text,received_time:e.Text}),U=e.Variant({Active:e.Null,Halted:e.Record({reason:e.Text})}),Z=e.Record({status:U,exchange_id:e.Text,canister_id:e.Principal,client_canisters:e.Vec(e.Principal)}),R=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}),j=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}),Q=e.Record({low:e.Nat64,high:e.Nat64,update_time:e.Text,medium:e.Nat64}),V=e.Variant({Enabled:e.Null,Disabled:e.Null,AllowEmpty:e.Null}),$=e.Record({last_block:e.Opt(I),pending_tx_count:e.Nat64,mempool_tx_fee_rate:Q,invoke_paused:e.Bool,utxo_proof_verification_status:V}),w=e.Variant({Confirmed:e.Nat32,Rejected:e.Text,Pending:e.Null}),H=e.Record({status:e.Opt(w),invoke_log:P,included_block:e.Opt(I),sent_tx_hex:e.Text}),_=e.Record({id:e.Text,value:e.Nat}),p=e.Record({maybe_rune:e.Opt(_),value:e.Nat64,script_pubkey_hex:e.Text,outpoint:e.Text}),x=e.Record({coin:_,from:e.Text}),k=e.Record({to:e.Text,coin:_}),g=e.Record({coins:e.Vec(_),sats:e.Nat64,txid:e.Text,vout:e.Nat32}),S=e.Record({input_coins:e.Vec(x),output_coins:e.Vec(k),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(g)}),q=e.Record({tx_fee_in_sats:e.Nat64,initiator_address:e.Text,intentions:e.Vec(S)}),G=e.Record({intention_set:q,initiator_utxo_proof:e.Vec(e.Nat8),psbt_hex:e.Text}),ee=e.Record({block_hash:e.Text,block_timestamp:e.Nat64,tx_ids:e.Vec(e.Text),block_height:e.Nat32}),ne=e.Variant({Ok:e.Vec(e.Text),Err:e.Text}),ie=e.Record({exchange_canister:e.Principal,exchange_id:e.Text,client_canisters:e.Vec(e.Principal)}),L=e.Record({txid:e.Text,timestamp:e.Nat64,block:I}),D=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([i],[c],["query"]),get_canister_info:e.Func([e.Nat64],[N],[]),get_exchange_pools:e.Func([],[e.Vec(K)],["query"]),get_failed_invoke_logs:e.Func([J],[e.Vec(e.Tuple(e.Text,P))],["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(O)],["query"]),get_registered_exchanges:e.Func([],[e.Vec(Z)],["query"]),get_rejected_txs:e.Func([e.Opt(e.Nat32)],[e.Vec(R)],["query"]),get_settings:e.Func([],[j],["query"]),get_status:e.Func([],[$],["query"]),get_tx_for_outpoint:e.Func([e.Text],[e.Opt(H)],["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(H)],["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(p)],["query"]),invoke:e.Func([G],[F],[]),new_block_detected:e.Func([ee],[t],[]),notify_exchange_for_blocks_from_height:e.Func([e.Text,e.Nat32],[ne],[]),register_exchange:e.Func([ie],[t],[]),save_included_block_for_tx:e.Func([L],[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([D],[t],[]),update_bitcoin_subnet_certificate:e.Func([e.Vec(e.Nat8)],[],[]),version:e.Func([],[e.Text],["query"])})};class fr{maestro;config;exchange;orchestrator;constructor(t){this.config=t;const n=t.network===yt.Testnet,i=n?"https://xbt-testnet.gomaestro-api.org/v0":"https://xbt-mainnet.gomaestro-api.org/v0";this.maestro=new kr({baseUrl:i,apiKey:t.maestroApiKey});const c="https://icp0.io";this.exchange=Bt.Actor.createActor(t.exchangeIdlFactory,{agent:Bt.HttpAgent.createSync({host:c,retryTimes:50,verifyQuerySignatures:!1}),canisterId:t.exchangeCanisterId}),this.orchestrator=Bt.Actor.createActor(io,{agent:Bt.HttpAgent.createSync({host:c,retryTimes:50,verifyQuerySignatures:!1}),canisterId:n?Wr:Gr})}async filterSpentUtxos(t,n){const i=await this.orchestrator.get_used_outpoints([t]);return n.filter(({txid:c,vout:o})=>i.findIndex(([a])=>`${c}:${o}`===a)<0)}async getBtcUtxos(t){let n=null;const i=[];do{const o=await this.maestro.utxosByAddress(t,n);i.push(...o.data),n=o.next_cursor}while(n!==null);const c=i.map(({txid:o,vout:a,runes:u,satoshis:h,script_pubkey:l,address:m})=>({txid:o,vout:a,address:m,runes:u.map(({rune_id:y,amount:B})=>({id:y,amount:B})),satoshis:h,scriptPk:l}));return this.filterSpentUtxos(t,c)}async getRuneUtxos(t,n){let i=null;const c=[];do{const a=await this.maestro.runeUtxosByAddress(t,n,i);c.push(...a.data),i=a.next_cursor}while(i!==null);const o=c.map(({txid:a,vout:u,runes:h,satoshis:l})=>{const m=zt(t,this.config.network);return{txid:a,vout:u,address:t,runes:h.map(({rune_id:y,amount:B})=>({id:y,amount:B})),satoshis:l,scriptPk:Gt(m)}});return this.filterSpentUtxos(t,o)}async searchRunes(t){const n=this.config.network===yt.Testnet?Xr:zr,i=fi`
|
|
14
|
+
*/var ht=9e15,Je=1e9,tn="0123456789abcdef",At="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Tt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",nn={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ht,maxE:ht,crypto:!1},Qn,Ye,me=!0,Nt="[DecimalError] ",Le=Nt+"Invalid argument: ",Jn=Nt+"Precision limit exceeded",Ln=Nt+"crypto unavailable",Dn="[object Decimal]",Ie=Math.floor,Ue=Math.pow,di=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,pi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,gi=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,er=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Ze=1e7,he=7,mi=9007199254740991,wi=At.length-1,rn=Tt.length-1,X={toStringTag:Dn};X.absoluteValue=X.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),fe(e)},X.ceil=function(){return fe(new this.constructor(this),this.e+1,2)},X.clampedTo=X.clamp=function(e,t){var n,i=this,c=i.constructor;if(e=new c(e),t=new c(t),!e.s||!t.s)return new c(NaN);if(e.gt(t))throw Error(Le+t);return n=i.cmp(e),n<0?e:i.cmp(t)>0?t:new c(i)},X.comparedTo=X.cmp=function(e){var t,n,i,c,o=this,a=o.d,u=(e=new o.constructor(e)).d,h=o.s,l=e.s;if(!a||!u)return!h||!l?NaN:h!==l?h:a===u?0:!a^h<0?1:-1;if(!a[0]||!u[0])return a[0]?h:u[0]?-l:0;if(h!==l)return h;if(o.e!==e.e)return o.e>e.e^h<0?1:-1;for(i=a.length,c=u.length,t=0,n=i<c?i:c;t<n;++t)if(a[t]!==u[t])return a[t]>u[t]^h<0?1:-1;return i===c?0:i>c^h<0?1:-1},X.cosine=X.cos=function(){var e,t,n=this,i=n.constructor;return n.d?n.d[0]?(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+he,i.rounding=1,n=yi(i,sr(i,n)),i.precision=e,i.rounding=t,fe(Ye==2||Ye==3?n.neg():n,e,t,!0)):new i(1):new i(NaN)},X.cubeRoot=X.cbrt=function(){var e,t,n,i,c,o,a,u,h,l,m=this,y=m.constructor;if(!m.isFinite()||m.isZero())return new y(m);for(me=!1,o=m.s*Ue(m.s*m,1/3),!o||Math.abs(o)==1/0?(n=Pe(m.d),e=m.e,(o=(e-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=Ue(n,1/3),e=Ie((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?n="5e"+e:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),i=new y(n),i.s=m.s):i=new y(o.toString()),a=(e=y.precision)+3;;)if(u=i,h=u.times(u).times(u),l=h.plus(m),i=ve(l.plus(m).times(u),l.plus(h),a+2,1),Pe(u.d).slice(0,a)===(n=Pe(i.d)).slice(0,a))if(n=n.slice(a-3,a+1),n=="9999"||!c&&n=="4999"){if(!c&&(fe(u,e+1,0),u.times(u).times(u).eq(m))){i=u;break}a+=4,c=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(fe(i,e+1,1),t=!i.times(i).times(i).eq(m));break}return me=!0,fe(i,e,y.rounding,t)},X.decimalPlaces=X.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Ie(this.e/he))*he,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},X.dividedBy=X.div=function(e){return ve(this,new this.constructor(e))},X.dividedToIntegerBy=X.divToInt=function(e){var t=this,n=t.constructor;return fe(ve(t,new n(e),0,1,1),n.precision,n.rounding)},X.equals=X.eq=function(e){return this.cmp(e)===0},X.floor=function(){return fe(new this.constructor(this),this.e+1,3)},X.greaterThan=X.gt=function(e){return this.cmp(e)>0},X.greaterThanOrEqualTo=X.gte=function(e){var t=this.cmp(e);return t==1||t===0},X.hyperbolicCosine=X.cosh=function(){var e,t,n,i,c,o=this,a=o.constructor,u=new a(1);if(!o.isFinite())return new a(o.s?1/0:NaN);if(o.isZero())return u;n=a.precision,i=a.rounding,a.precision=n+Math.max(o.e,o.sd())+4,a.rounding=1,c=o.d.length,c<32?(e=Math.ceil(c/3),t=(1/qt(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=dt(a,1,o.times(t),new a(1),!0);for(var h,l=e,m=new a(8);l--;)h=o.times(o),o=u.minus(h.times(m.minus(h.times(m))));return fe(o,a.precision=n,a.rounding=i,!0)},X.hyperbolicSine=X.sinh=function(){var e,t,n,i,c=this,o=c.constructor;if(!c.isFinite()||c.isZero())return new o(c);if(t=o.precision,n=o.rounding,o.precision=t+Math.max(c.e,c.sd())+4,o.rounding=1,i=c.d.length,i<3)c=dt(o,2,c,c,!0);else{e=1.4*Math.sqrt(i),e=e>16?16:e|0,c=c.times(1/qt(5,e)),c=dt(o,2,c,c,!0);for(var a,u=new o(5),h=new o(16),l=new o(20);e--;)a=c.times(c),c=c.times(u.plus(a.times(h.times(a).plus(l))))}return o.precision=t,o.rounding=n,fe(c,t,n,!0)},X.hyperbolicTangent=X.tanh=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+7,i.rounding=1,ve(n.sinh(),n.cosh(),i.precision=e,i.rounding=t)):new i(n.s)},X.inverseCosine=X.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),i=t.precision,c=t.rounding;return n!==-1?n===0?e.isNeg()?ze(t,i,c):new t(0):new t(NaN):e.isZero()?ze(t,i+4,c).times(.5):(t.precision=i+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=i,t.rounding=c,e.times(2))},X.inverseHyperbolicCosine=X.acosh=function(){var e,t,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(e=i.precision,t=i.rounding,i.precision=e+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,me=!1,n=n.times(n).minus(1).sqrt().plus(n),me=!0,i.precision=e,i.rounding=t,n.ln()):new i(n)},X.inverseHyperbolicSine=X.asinh=function(){var e,t,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,me=!1,n=n.times(n).plus(1).sqrt().plus(n),me=!0,i.precision=e,i.rounding=t,n.ln())},X.inverseHyperbolicTangent=X.atanh=function(){var e,t,n,i,c=this,o=c.constructor;return c.isFinite()?c.e>=0?new o(c.abs().eq(1)?c.s/0:c.isZero()?c:NaN):(e=o.precision,t=o.rounding,i=c.sd(),Math.max(i,e)<2*-c.e-1?fe(new o(c),e,t,!0):(o.precision=n=i-c.e,c=ve(c.plus(1),new o(1).minus(c),n+e,1),o.precision=e+4,o.rounding=1,c=c.ln(),o.precision=e,o.rounding=t,c.times(.5))):new o(NaN)},X.inverseSine=X.asin=function(){var e,t,n,i,c=this,o=c.constructor;return c.isZero()?new o(c):(t=c.abs().cmp(1),n=o.precision,i=o.rounding,t!==-1?t===0?(e=ze(o,n+4,i).times(.5),e.s=c.s,e):new o(NaN):(o.precision=n+6,o.rounding=1,c=c.div(new o(1).minus(c.times(c)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=i,c.times(2)))},X.inverseTangent=X.atan=function(){var e,t,n,i,c,o,a,u,h,l=this,m=l.constructor,y=m.precision,B=m.rounding;if(l.isFinite()){if(l.isZero())return new m(l);if(l.abs().eq(1)&&y+4<=rn)return a=ze(m,y+4,B).times(.25),a.s=l.s,a}else{if(!l.s)return new m(NaN);if(y+4<=rn)return a=ze(m,y+4,B).times(.5),a.s=l.s,a}for(m.precision=u=y+10,m.rounding=1,n=Math.min(28,u/he+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(me=!1,t=Math.ceil(u/he),i=1,h=l.times(l),a=new m(l),c=l;e!==-1;)if(c=c.times(h),o=a.minus(c.div(i+=2)),c=c.times(h),a=o.plus(c.div(i+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===o.d[e]&&e--;);return n&&(a=a.times(2<<n-1)),me=!0,fe(a,m.precision=y,m.rounding=B,!0)},X.isFinite=function(){return!!this.d},X.isInteger=X.isInt=function(){return!!this.d&&Ie(this.e/he)>this.d.length-2},X.isNaN=function(){return!this.s},X.isNegative=X.isNeg=function(){return this.s<0},X.isPositive=X.isPos=function(){return this.s>0},X.isZero=function(){return!!this.d&&this.d[0]===0},X.lessThan=X.lt=function(e){return this.cmp(e)<0},X.lessThanOrEqualTo=X.lte=function(e){return this.cmp(e)<1},X.logarithm=X.log=function(e){var t,n,i,c,o,a,u,h,l=this,m=l.constructor,y=m.precision,B=m.rounding,v=5;if(e==null)e=new m(10),t=!0;else{if(e=new m(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new m(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new m(n&&!n[0]?-1/0:l.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)o=!0;else{for(c=n[0];c%10===0;)c/=10;o=c!==1}if(me=!1,u=y+v,a=et(l,u),i=t?Ht(m,u+10):et(e,u),h=ve(a,i,u,1),Et(h.d,c=y,B))do if(u+=10,a=et(l,u),i=t?Ht(m,u+10):et(e,u),h=ve(a,i,u,1),!o){+Pe(h.d).slice(c+1,c+15)+1==1e14&&(h=fe(h,y+1,0));break}while(Et(h.d,c+=10,B));return me=!0,fe(h,y,B)},X.minus=X.sub=function(e){var t,n,i,c,o,a,u,h,l,m,y,B,v=this,T=v.constructor;if(e=new T(e),!v.d||!e.d)return!v.s||!e.s?e=new T(NaN):v.d?e.s=-e.s:e=new T(e.d||v.s!==e.s?v:NaN),e;if(v.s!=e.s)return e.s=-e.s,v.plus(e);if(l=v.d,B=e.d,u=T.precision,h=T.rounding,!l[0]||!B[0]){if(B[0])e.s=-e.s;else if(l[0])e=new T(v);else return new T(h===3?-0:0);return me?fe(e,u,h):e}if(n=Ie(e.e/he),m=Ie(v.e/he),l=l.slice(),o=m-n,o){for(y=o<0,y?(t=l,o=-o,a=B.length):(t=B,n=m,a=l.length),i=Math.max(Math.ceil(u/he),a)+2,o>i&&(o=i,t.length=1),t.reverse(),i=o;i--;)t.push(0);t.reverse()}else{for(i=l.length,a=B.length,y=i<a,y&&(a=i),i=0;i<a;i++)if(l[i]!=B[i]){y=l[i]<B[i];break}o=0}for(y&&(t=l,l=B,B=t,e.s=-e.s),a=l.length,i=B.length-a;i>0;--i)l[a++]=0;for(i=B.length;i>o;){if(l[--i]<B[i]){for(c=i;c&&l[--c]===0;)l[c]=Ze-1;--l[c],l[i]+=Ze}l[i]-=B[i]}for(;l[--a]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=Ot(l,n),me?fe(e,u,h):e):new T(h===3?-0:0)},X.modulo=X.mod=function(e){var t,n=this,i=n.constructor;return e=new i(e),!n.d||!e.s||e.d&&!e.d[0]?new i(NaN):!e.d||n.d&&!n.d[0]?fe(new i(n),i.precision,i.rounding):(me=!1,i.modulo==9?(t=ve(n,e.abs(),0,3,1),t.s*=e.s):t=ve(n,e,0,i.modulo,1),t=t.times(e),me=!0,n.minus(t))},X.naturalExponential=X.exp=function(){return on(this)},X.naturalLogarithm=X.ln=function(){return et(this)},X.negated=X.neg=function(){var e=new this.constructor(this);return e.s=-e.s,fe(e)},X.plus=X.add=function(e){var t,n,i,c,o,a,u,h,l,m,y=this,B=y.constructor;if(e=new B(e),!y.d||!e.d)return!y.s||!e.s?e=new B(NaN):y.d||(e=new B(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(l=y.d,m=e.d,u=B.precision,h=B.rounding,!l[0]||!m[0])return m[0]||(e=new B(y)),me?fe(e,u,h):e;if(o=Ie(y.e/he),i=Ie(e.e/he),l=l.slice(),c=o-i,c){for(c<0?(n=l,c=-c,a=m.length):(n=m,i=o,a=l.length),o=Math.ceil(u/he),a=o>a?o+1:a+1,c>a&&(c=a,n.length=1),n.reverse();c--;)n.push(0);n.reverse()}for(a=l.length,c=m.length,a-c<0&&(c=a,n=m,m=l,l=n),t=0;c;)t=(l[--c]=l[c]+m[c]+t)/Ze|0,l[c]%=Ze;for(t&&(l.unshift(t),++i),a=l.length;l[--a]==0;)l.pop();return e.d=l,e.e=Ot(l,i),me?fe(e,u,h):e},X.precision=X.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Le+e);return n.d?(t=tr(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},X.round=function(){var e=this,t=e.constructor;return fe(new t(e),e.e+1,t.rounding)},X.sine=X.sin=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+he,i.rounding=1,n=Ei(i,sr(i,n)),i.precision=e,i.rounding=t,fe(Ye>2?n.neg():n,e,t,!0)):new i(NaN)},X.squareRoot=X.sqrt=function(){var e,t,n,i,c,o,a=this,u=a.d,h=a.e,l=a.s,m=a.constructor;if(l!==1||!u||!u[0])return new m(!l||l<0&&(!u||u[0])?NaN:u?a:1/0);for(me=!1,l=Math.sqrt(+a),l==0||l==1/0?(t=Pe(u),(t.length+h)%2==0&&(t+="0"),l=Math.sqrt(t),h=Ie((h+1)/2)-(h<0||h%2),l==1/0?t="5e"+h:(t=l.toExponential(),t=t.slice(0,t.indexOf("e")+1)+h),i=new m(t)):i=new m(l.toString()),n=(h=m.precision)+3;;)if(o=i,i=o.plus(ve(a,o,n+2,1)).times(.5),Pe(o.d).slice(0,n)===(t=Pe(i.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!c&&t=="4999"){if(!c&&(fe(o,h+1,0),o.times(o).eq(a))){i=o;break}n+=4,c=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(fe(i,h+1,1),e=!i.times(i).eq(a));break}return me=!0,fe(i,h,m.rounding,e)},X.tangent=X.tan=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+10,i.rounding=1,n=n.sin(),n.s=1,n=ve(n,new i(1).minus(n.times(n)).sqrt(),e+10,0),i.precision=e,i.rounding=t,fe(Ye==2||Ye==4?n.neg():n,e,t,!0)):new i(NaN)},X.times=X.mul=function(e){var t,n,i,c,o,a,u,h,l,m=this,y=m.constructor,B=m.d,v=(e=new y(e)).d;if(e.s*=m.s,!B||!B[0]||!v||!v[0])return new y(!e.s||B&&!B[0]&&!v||v&&!v[0]&&!B?NaN:!B||!v?e.s/0:e.s*0);for(n=Ie(m.e/he)+Ie(e.e/he),h=B.length,l=v.length,h<l&&(o=B,B=v,v=o,a=h,h=l,l=a),o=[],a=h+l,i=a;i--;)o.push(0);for(i=l;--i>=0;){for(t=0,c=h+i;c>i;)u=o[c]+v[i]*B[c-i-1]+t,o[c--]=u%Ze|0,t=u/Ze|0;o[c]=(o[c]+t)%Ze|0}for(;!o[--a];)o.pop();return t?++n:o.shift(),e.d=o,e.e=Ot(o,n),me?fe(e,y.precision,y.rounding):e},X.toBinary=function(e,t){return sn(this,2,e,t)},X.toDecimalPlaces=X.toDP=function(e,t){var n=this,i=n.constructor;return n=new i(n),e===void 0?n:(Fe(e,0,Je),t===void 0?t=i.rounding:Fe(t,0,8),fe(n,e+n.e+1,t))},X.toExponential=function(e,t){var n,i=this,c=i.constructor;return e===void 0?n=We(i,!0):(Fe(e,0,Je),t===void 0?t=c.rounding:Fe(t,0,8),i=fe(new c(i),e+1,t),n=We(i,!0,e+1)),i.isNeg()&&!i.isZero()?"-"+n:n},X.toFixed=function(e,t){var n,i,c=this,o=c.constructor;return e===void 0?n=We(c):(Fe(e,0,Je),t===void 0?t=o.rounding:Fe(t,0,8),i=fe(new o(c),e+c.e+1,t),n=We(i,!1,e+i.e+1)),c.isNeg()&&!c.isZero()?"-"+n:n},X.toFraction=function(e){var t,n,i,c,o,a,u,h,l,m,y,B,v=this,T=v.d,N=v.constructor;if(!T)return new N(v);if(l=n=new N(1),i=h=new N(0),t=new N(i),o=t.e=tr(T)-v.e-1,a=o%he,t.d[0]=Ue(10,a<0?he+a:a),e==null)e=o>0?t:l;else{if(u=new N(e),!u.isInt()||u.lt(l))throw Error(Le+u);e=u.gt(t)?o>0?t:l:u}for(me=!1,u=new N(Pe(T)),m=N.precision,N.precision=o=T.length*he*2;y=ve(u,t,0,1,1),c=n.plus(y.times(i)),c.cmp(e)!=1;)n=i,i=c,c=l,l=h.plus(y.times(c)),h=c,c=t,t=u.minus(y.times(c)),u=c;return c=ve(e.minus(n),i,0,1,1),h=h.plus(c.times(l)),n=n.plus(c.times(i)),h.s=l.s=v.s,B=ve(l,i,o,1).minus(v).abs().cmp(ve(h,n,o,1).minus(v).abs())<1?[l,i]:[h,n],N.precision=m,me=!0,B},X.toHexadecimal=X.toHex=function(e,t){return sn(this,16,e,t)},X.toNearest=function(e,t){var n=this,i=n.constructor;if(n=new i(n),e==null){if(!n.d)return n;e=new i(1),t=i.rounding}else{if(e=new i(e),t===void 0?t=i.rounding:Fe(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]?(me=!1,n=ve(n,e,0,t,1).times(e),me=!0,fe(n)):(e.s=n.s,n=e),n},X.toNumber=function(){return+this},X.toOctal=function(e,t){return sn(this,8,e,t)},X.toPower=X.pow=function(e){var t,n,i,c,o,a,u=this,h=u.constructor,l=+(e=new h(e));if(!u.d||!e.d||!u.d[0]||!e.d[0])return new h(Ue(+u,l));if(u=new h(u),u.eq(1))return u;if(i=h.precision,o=h.rounding,e.eq(1))return fe(u,i,o);if(t=Ie(e.e/he),t>=e.d.length-1&&(n=l<0?-l:l)<=mi)return c=nr(h,u,n,i),e.s<0?new h(1).div(c):fe(c,i,o);if(a=u.s,a<0){if(t<e.d.length-1)return new h(NaN);if((e.d[t]&1)==0&&(a=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=a,u}return n=Ue(+u,l),t=n==0||!isFinite(n)?Ie(l*(Math.log("0."+Pe(u.d))/Math.LN10+u.e+1)):new h(n+"").e,t>h.maxE+1||t<h.minE-1?new h(t>0?a/0:0):(me=!1,h.rounding=u.s=1,n=Math.min(12,(t+"").length),c=on(e.times(et(u,i+n)),i),c.d&&(c=fe(c,i+5,1),Et(c.d,i,o)&&(t=i+10,c=fe(on(e.times(et(u,t+n)),t),t+5,1),+Pe(c.d).slice(i+1,i+15)+1==1e14&&(c=fe(c,i+1,0)))),c.s=a,me=!0,h.rounding=o,fe(c,i,o))},X.toPrecision=function(e,t){var n,i=this,c=i.constructor;return e===void 0?n=We(i,i.e<=c.toExpNeg||i.e>=c.toExpPos):(Fe(e,1,Je),t===void 0?t=c.rounding:Fe(t,0,8),i=fe(new c(i),e,t),n=We(i,e<=i.e||i.e<=c.toExpNeg,e)),i.isNeg()&&!i.isZero()?"-"+n:n},X.toSignificantDigits=X.toSD=function(e,t){var n=this,i=n.constructor;return e===void 0?(e=i.precision,t=i.rounding):(Fe(e,1,Je),t===void 0?t=i.rounding:Fe(t,0,8)),fe(new i(n),e,t)},X.toString=function(){var e=this,t=e.constructor,n=We(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n},X.truncated=X.trunc=function(){return fe(new this.constructor(this),this.e+1,1)},X.valueOf=X.toJSON=function(){var e=this,t=e.constructor,n=We(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function Pe(e){var t,n,i,c=e.length-1,o="",a=e[0];if(c>0){for(o+=a,t=1;t<c;t++)i=e[t]+"",n=he-i.length,n&&(o+=De(n)),o+=i;a=e[t],i=a+"",n=he-i.length,n&&(o+=De(n))}else if(a===0)return"0";for(;a%10===0;)a/=10;return o+a}function Fe(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Le+e)}function Et(e,t,n,i){var c,o,a,u;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=he,c=0):(c=Math.ceil((t+1)/he),t%=he),o=Ue(10,he-t),u=e[c]%o|0,i==null?t<3?(t==0?u=u/100|0:t==1&&(u=u/10|0),a=n<4&&u==99999||n>3&&u==49999||u==5e4||u==0):a=(n<4&&u+1==o||n>3&&u+1==o/2)&&(e[c+1]/o/100|0)==Ue(10,t-2)-1||(u==o/2||u==0)&&(e[c+1]/o/100|0)==0:t<4?(t==0?u=u/1e3|0:t==1?u=u/100|0:t==2&&(u=u/10|0),a=(i||n<4)&&u==9999||!i&&n>3&&u==4999):a=((i||n<4)&&u+1==o||!i&&n>3&&u+1==o/2)&&(e[c+1]/o/1e3|0)==Ue(10,t-3)-1,a}function Rt(e,t,n){for(var i,c=[0],o,a=0,u=e.length;a<u;){for(o=c.length;o--;)c[o]*=t;for(c[0]+=tn.indexOf(e.charAt(a++)),i=0;i<c.length;i++)c[i]>n-1&&(c[i+1]===void 0&&(c[i+1]=0),c[i+1]+=c[i]/n|0,c[i]%=n)}return c.reverse()}function yi(e,t){var n,i,c;if(t.isZero())return t;i=t.d.length,i<32?(n=Math.ceil(i/3),c=(1/qt(4,n)).toString()):(n=16,c="2.3283064365386962890625e-10"),e.precision+=n,t=dt(e,1,t.times(c),new e(1));for(var o=n;o--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=n,t}var ve=(function(){function e(i,c,o){var a,u=0,h=i.length;for(i=i.slice();h--;)a=i[h]*c+u,i[h]=a%o|0,u=a/o|0;return u&&i.unshift(u),i}function t(i,c,o,a){var u,h;if(o!=a)h=o>a?1:-1;else for(u=h=0;u<o;u++)if(i[u]!=c[u]){h=i[u]>c[u]?1:-1;break}return h}function n(i,c,o,a){for(var u=0;o--;)i[o]-=u,u=i[o]<c[o]?1:0,i[o]=u*a+i[o]-c[o];for(;!i[0]&&i.length>1;)i.shift()}return function(i,c,o,a,u,h){var l,m,y,B,v,T,N,K,J,F,b,P,I,O,U,Z,R,C,j,Q,V=i.constructor,$=i.s==c.s?1:-1,w=i.d,H=c.d;if(!w||!w[0]||!H||!H[0])return new V(!i.s||!c.s||(w?H&&w[0]==H[0]:!H)?NaN:w&&w[0]==0||!H?$*0:$/0);for(h?(v=1,m=i.e-c.e):(h=Ze,v=he,m=Ie(i.e/v)-Ie(c.e/v)),j=H.length,R=w.length,J=new V($),F=J.d=[],y=0;H[y]==(w[y]||0);y++);if(H[y]>(w[y]||0)&&m--,o==null?(O=o=V.precision,a=V.rounding):u?O=o+(i.e-c.e)+1:O=o,O<0)F.push(1),T=!0;else{if(O=O/v+2|0,y=0,j==1){for(B=0,H=H[0],O++;(y<R||B)&&O--;y++)U=B*h+(w[y]||0),F[y]=U/H|0,B=U%H|0;T=B||y<R}else{for(B=h/(H[0]+1)|0,B>1&&(H=e(H,B,h),w=e(w,B,h),j=H.length,R=w.length),Z=j,b=w.slice(0,j),P=b.length;P<j;)b[P++]=0;Q=H.slice(),Q.unshift(0),C=H[0],H[1]>=h/2&&++C;do B=0,l=t(H,b,j,P),l<0?(I=b[0],j!=P&&(I=I*h+(b[1]||0)),B=I/C|0,B>1?(B>=h&&(B=h-1),N=e(H,B,h),K=N.length,P=b.length,l=t(N,b,K,P),l==1&&(B--,n(N,j<K?Q:H,K,h))):(B==0&&(l=B=1),N=H.slice()),K=N.length,K<P&&N.unshift(0),n(b,N,P,h),l==-1&&(P=b.length,l=t(H,b,j,P),l<1&&(B++,n(b,j<P?Q:H,P,h))),P=b.length):l===0&&(B++,b=[0]),F[y++]=B,l&&b[0]?b[P++]=w[Z]||0:(b=[w[Z]],P=1);while((Z++<R||b[0]!==void 0)&&O--);T=b[0]!==void 0}F[0]||F.shift()}if(v==1)J.e=m,Qn=T;else{for(y=1,B=F[0];B>=10;B/=10)y++;J.e=y+m*v-1,fe(J,u?o+J.e+1:o,a,T)}return J}})();function fe(e,t,n,i){var c,o,a,u,h,l,m,y,B,v=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(c=1,u=y[0];u>=10;u/=10)c++;if(o=t-c,o<0)o+=he,a=t,m=y[B=0],h=m/Ue(10,c-a-1)%10|0;else if(B=Math.ceil((o+1)/he),u=y.length,B>=u)if(i){for(;u++<=B;)y.push(0);m=h=0,c=1,o%=he,a=o-he+1}else break e;else{for(m=u=y[B],c=1;u>=10;u/=10)c++;o%=he,a=o-he+c,h=a<0?0:m/Ue(10,c-a-1)%10|0}if(i=i||t<0||y[B+1]!==void 0||(a<0?m:m%Ue(10,c-a-1)),l=n<4?(h||i)&&(n==0||n==(e.s<0?3:2)):h>5||h==5&&(n==4||i||n==6&&(o>0?a>0?m/Ue(10,c-a):0:y[B-1])%10&1||n==(e.s<0?8:7)),t<1||!y[0])return y.length=0,l?(t-=e.e+1,y[0]=Ue(10,(he-t%he)%he),e.e=-t||0):y[0]=e.e=0,e;if(o==0?(y.length=B,u=1,B--):(y.length=B+1,u=Ue(10,he-o),y[B]=a>0?(m/Ue(10,c-a)%Ue(10,a)|0)*u:0),l)for(;;)if(B==0){for(o=1,a=y[0];a>=10;a/=10)o++;for(a=y[0]+=u,u=1;a>=10;a/=10)u++;o!=u&&(e.e++,y[0]==Ze&&(y[0]=1));break}else{if(y[B]+=u,y[B]!=Ze)break;y[B--]=0,u=1}for(o=y.length;y[--o]===0;)y.pop()}return me&&(e.e>v.maxE?(e.d=null,e.e=NaN):e.e<v.minE&&(e.e=0,e.d=[0])),e}function We(e,t,n){if(!e.isFinite())return or(e);var i,c=e.e,o=Pe(e.d),a=o.length;return t?(n&&(i=n-a)>0?o=o.charAt(0)+"."+o.slice(1)+De(i):a>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):c<0?(o="0."+De(-c-1)+o,n&&(i=n-a)>0&&(o+=De(i))):c>=a?(o+=De(c+1-a),n&&(i=n-c-1)>0&&(o=o+"."+De(i))):((i=c+1)<a&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-a)>0&&(c+1===a&&(o+="."),o+=De(i))),o}function Ot(e,t){var n=e[0];for(t*=he;n>=10;n/=10)t++;return t}function Ht(e,t,n){if(t>wi)throw me=!0,n&&(e.precision=n),Error(Jn);return fe(new e(At),t,1,!0)}function ze(e,t,n){if(t>rn)throw Error(Jn);return fe(new e(Tt),t,n,!0)}function tr(e){var t=e.length-1,n=t*he+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 De(e){for(var t="";e--;)t+="0";return t}function nr(e,t,n,i){var c,o=new e(1),a=Math.ceil(i/he+4);for(me=!1;;){if(n%2&&(o=o.times(t),cr(o.d,a)&&(c=!0)),n=Ie(n/2),n===0){n=o.d.length-1,c&&o.d[n]===0&&++o.d[n];break}t=t.times(t),cr(t.d,a)}return me=!0,o}function rr(e){return e.d[e.d.length-1]&1}function ir(e,t,n){for(var i,c,o=new e(t[0]),a=0;++a<t.length;){if(c=new e(t[a]),!c.s){o=c;break}i=o.cmp(c),(i===n||i===0&&o.s===n)&&(o=c)}return o}function on(e,t){var n,i,c,o,a,u,h,l=0,m=0,y=0,B=e.constructor,v=B.rounding,T=B.precision;if(!e.d||!e.d[0]||e.e>17)return new B(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(me=!1,h=T):h=t,u=new B(.03125);e.e>-2;)e=e.times(u),y+=5;for(i=Math.log(Ue(2,y))/Math.LN10*2+5|0,h+=i,n=o=a=new B(1),B.precision=h;;){if(o=fe(o.times(e),h,1),n=n.times(++m),u=a.plus(ve(o,n,h,1)),Pe(u.d).slice(0,h)===Pe(a.d).slice(0,h)){for(c=y;c--;)a=fe(a.times(a),h,1);if(t==null)if(l<3&&Et(a.d,h-i,v,l))B.precision=h+=10,n=o=u=new B(1),m=0,l++;else return fe(a,B.precision=T,v,me=!0);else return B.precision=T,a}a=u}}function et(e,t){var n,i,c,o,a,u,h,l,m,y,B,v=1,T=10,N=e,K=N.d,J=N.constructor,F=J.rounding,b=J.precision;if(N.s<0||!K||!K[0]||!N.e&&K[0]==1&&K.length==1)return new J(K&&!K[0]?-1/0:N.s!=1?NaN:K?0:N);if(t==null?(me=!1,m=b):m=t,J.precision=m+=T,n=Pe(K),i=n.charAt(0),Math.abs(o=N.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)N=N.times(e),n=Pe(N.d),i=n.charAt(0),v++;o=N.e,i>1?(N=new J("0."+n),o++):N=new J(i+"."+n.slice(1))}else return l=Ht(J,m+2,b).times(o+""),N=et(new J(i+"."+n.slice(1)),m-T).plus(l),J.precision=b,t==null?fe(N,b,F,me=!0):N;for(y=N,h=a=N=ve(N.minus(1),N.plus(1),m,1),B=fe(N.times(N),m,1),c=3;;){if(a=fe(a.times(B),m,1),l=h.plus(ve(a,new J(c),m,1)),Pe(l.d).slice(0,m)===Pe(h.d).slice(0,m))if(h=h.times(2),o!==0&&(h=h.plus(Ht(J,m+2,b).times(o+""))),h=ve(h,new J(v),m,1),t==null)if(Et(h.d,m-T,F,u))J.precision=m+=T,l=a=N=ve(y.minus(1),y.plus(1),m,1),B=fe(N.times(N),m,1),c=u=1;else return fe(h,J.precision=b,F,me=!0);else return J.precision=b,h;h=l,c+=2}}function or(e){return String(e.s*e.s/0)}function Ut(e,t){var n,i,c;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(n<0&&(n=i),n+=+t.slice(i+1),t=t.substring(0,i)):n<0&&(n=t.length),i=0;t.charCodeAt(i)===48;i++);for(c=t.length;t.charCodeAt(c-1)===48;--c);if(t=t.slice(i,c),t){if(c-=i,e.e=n=n-i-1,e.d=[],i=(n+1)%he,n<0&&(i+=he),i<c){for(i&&e.d.push(+t.slice(0,i)),c-=he;i<c;)e.d.push(+t.slice(i,i+=he));t=t.slice(i),i=he-t.length}else i-=c;for(;i--;)t+="0";e.d.push(+t),me&&(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 bi(e,t){var n,i,c,o,a,u,h,l,m;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),er.test(t))return Ut(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(pi.test(t))n=16,t=t.toLowerCase();else if(di.test(t))n=2;else if(gi.test(t))n=8;else throw Error(Le+t);for(o=t.search(/p/i),o>0?(h=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),a=o>=0,i=e.constructor,a&&(t=t.replace(".",""),u=t.length,o=u-o,c=nr(i,new i(n),o,o*2)),l=Rt(t,n,Ze),m=l.length-1,o=m;l[o]===0;--o)l.pop();return o<0?new i(e.s*0):(e.e=Ot(l,m),e.d=l,me=!1,a&&(e=ve(e,c,u*4)),h&&(e=e.times(Math.abs(h)<54?Ue(2,h):ct.pow(2,h))),me=!0,e)}function Ei(e,t){var n,i=t.d.length;if(i<3)return t.isZero()?t:dt(e,2,t,t);n=1.4*Math.sqrt(i),n=n>16?16:n|0,t=t.times(1/qt(5,n)),t=dt(e,2,t,t);for(var c,o=new e(5),a=new e(16),u=new e(20);n--;)c=t.times(t),t=t.times(o.plus(c.times(a.times(c).minus(u))));return t}function dt(e,t,n,i,c){var o,a,u,h,l=e.precision,m=Math.ceil(l/he);for(me=!1,h=n.times(n),u=new e(i);;){if(a=ve(u.times(h),new e(t++*t++),l,1),u=c?i.plus(a):i.minus(a),i=ve(a.times(h),new e(t++*t++),l,1),a=u.plus(i),a.d[m]!==void 0){for(o=m;a.d[o]===u.d[o]&&o--;);if(o==-1)break}o=u,u=i,i=a,a=o}return me=!0,a.d.length=m+1,a}function qt(e,t){for(var n=e;--t;)n*=e;return n}function sr(e,t){var n,i=t.s<0,c=ze(e,e.precision,1),o=c.times(.5);if(t=t.abs(),t.lte(o))return Ye=i?4:1,t;if(n=t.divToInt(c),n.isZero())Ye=i?3:2;else{if(t=t.minus(n.times(c)),t.lte(o))return Ye=rr(n)?i?2:3:i?4:1,t;Ye=rr(n)?i?1:4:i?3:2}return t.minus(c).abs()}function sn(e,t,n,i){var c,o,a,u,h,l,m,y,B,v=e.constructor,T=n!==void 0;if(T?(Fe(n,1,Je),i===void 0?i=v.rounding:Fe(i,0,8)):(n=v.precision,i=v.rounding),!e.isFinite())m=or(e);else{for(m=We(e),a=m.indexOf("."),T?(c=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):c=t,a>=0&&(m=m.replace(".",""),B=new v(1),B.e=m.length-a,B.d=Rt(We(B),10,c),B.e=B.d.length),y=Rt(m,10,c),o=h=y.length;y[--h]==0;)y.pop();if(!y[0])m=T?"0p+0":"0";else{if(a<0?o--:(e=new v(e),e.d=y,e.e=o,e=ve(e,B,n,i,0,c),y=e.d,o=e.e,l=Qn),a=y[n],u=c/2,l=l||y[n+1]!==void 0,l=i<4?(a!==void 0||l)&&(i===0||i===(e.s<0?3:2)):a>u||a===u&&(i===4||l||i===6&&y[n-1]&1||i===(e.s<0?8:7)),y.length=n,l)for(;++y[--n]>c-1;)y[n]=0,n||(++o,y.unshift(1));for(h=y.length;!y[h-1];--h);for(a=0,m="";a<h;a++)m+=tn.charAt(y[a]);if(T){if(h>1)if(t==16||t==8){for(a=t==16?4:3,--h;h%a;h++)m+="0";for(y=Rt(m,c,t),h=y.length;!y[h-1];--h);for(a=1,m="1.";a<h;a++)m+=tn.charAt(y[a])}else m=m.charAt(0)+"."+m.slice(1);m=m+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)m="0"+m;m="0."+m}else if(++o>h)for(o-=h;o--;)m+="0";else o<h&&(m=m.slice(0,o)+"."+m.slice(o))}m=(t==16?"0x":t==2?"0b":t==8?"0o":"")+m}return e.s<0?"-"+m:m}function cr(e,t){if(e.length>t)return e.length=t,!0}function Bi(e){return new this(e).abs()}function _i(e){return new this(e).acos()}function xi(e){return new this(e).acosh()}function vi(e,t){return new this(e).plus(t)}function Si(e){return new this(e).asin()}function Ai(e){return new this(e).asinh()}function Ti(e){return new this(e).atan()}function Ni(e){return new this(e).atanh()}function Ri(e,t){e=new this(e),t=new this(t);var n,i=this.precision,c=this.rounding,o=i+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=ze(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?ze(this,i,c):new this(0),n.s=e.s):!e.d||t.isZero()?(n=ze(this,o,1).times(.5),n.s=e.s):t.s<0?(this.precision=o,this.rounding=1,n=this.atan(ve(e,t,o,1)),t=ze(this,o,1),this.precision=i,this.rounding=c,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(ve(e,t,o,1)),n}function Oi(e){return new this(e).cbrt()}function Hi(e){return fe(e=new this(e),e.e+1,2)}function Ui(e,t,n){return new this(e).clamp(t,n)}function qi(e){if(!e||typeof e!="object")throw Error(Nt+"Object expected");var t,n,i,c=e.defaults===!0,o=["precision",1,Je,"rounding",0,8,"toExpNeg",-ht,0,"toExpPos",0,ht,"maxE",0,ht,"minE",-ht,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],c&&(this[n]=nn[n]),(i=e[n])!==void 0)if(Ie(i)===i&&i>=o[t+1]&&i<=o[t+2])this[n]=i;else throw Error(Le+n+": "+i);if(n="crypto",c&&(this[n]=nn[n]),(i=e[n])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Ln);else this[n]=!1;else throw Error(Le+n+": "+i);return this}function Pi(e){return new this(e).cos()}function Ci(e){return new this(e).cosh()}function ur(e){var t,n,i;function c(o){var a,u,h,l=this;if(!(l instanceof c))return new c(o);if(l.constructor=c,ar(o)){l.s=o.s,me?!o.d||o.e>c.maxE?(l.e=NaN,l.d=null):o.e<c.minE?(l.e=0,l.d=[0]):(l.e=o.e,l.d=o.d.slice()):(l.e=o.e,l.d=o.d?o.d.slice():o.d);return}if(h=typeof o,h==="number"){if(o===0){l.s=1/o<0?-1:1,l.e=0,l.d=[0];return}if(o<0?(o=-o,l.s=-1):l.s=1,o===~~o&&o<1e7){for(a=0,u=o;u>=10;u/=10)a++;me?a>c.maxE?(l.e=NaN,l.d=null):a<c.minE?(l.e=0,l.d=[0]):(l.e=a,l.d=[o]):(l.e=a,l.d=[o]);return}if(o*0!==0){o||(l.s=NaN),l.e=NaN,l.d=null;return}return Ut(l,o.toString())}if(h==="string")return(u=o.charCodeAt(0))===45?(o=o.slice(1),l.s=-1):(u===43&&(o=o.slice(1)),l.s=1),er.test(o)?Ut(l,o):bi(l,o);if(h==="bigint")return o<0?(o=-o,l.s=-1):l.s=1,Ut(l,o.toString());throw Error(Le+o)}if(c.prototype=X,c.ROUND_UP=0,c.ROUND_DOWN=1,c.ROUND_CEIL=2,c.ROUND_FLOOR=3,c.ROUND_HALF_UP=4,c.ROUND_HALF_DOWN=5,c.ROUND_HALF_EVEN=6,c.ROUND_HALF_CEIL=7,c.ROUND_HALF_FLOOR=8,c.EUCLID=9,c.config=c.set=qi,c.clone=ur,c.isDecimal=ar,c.abs=Bi,c.acos=_i,c.acosh=xi,c.add=vi,c.asin=Si,c.asinh=Ai,c.atan=Ti,c.atanh=Ni,c.atan2=Ri,c.cbrt=Oi,c.ceil=Hi,c.clamp=Ui,c.cos=Pi,c.cosh=Ci,c.div=Ii,c.exp=ki,c.floor=Mi,c.hypot=Fi,c.ln=Vi,c.log=ji,c.log10=Zi,c.log2=$i,c.max=Ki,c.min=Gi,c.mod=Wi,c.mul=zi,c.pow=Xi,c.random=Yi,c.round=Qi,c.sign=Ji,c.sin=Li,c.sinh=Di,c.sqrt=eo,c.sub=to,c.sum=no,c.tan=ro,c.tanh=io,c.trunc=oo,e===void 0&&(e={}),e&&e.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)e.hasOwnProperty(n=i[t++])||(e[n]=this[n]);return c.config(e),c}function Ii(e,t){return new this(e).div(t)}function ki(e){return new this(e).exp()}function Mi(e){return fe(e=new this(e),e.e+1,3)}function Fi(){var e,t,n=new this(0);for(me=!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 me=!0,new this(1/0);n=t}return me=!0,n.sqrt()}function ar(e){return e instanceof ct||e&&e.toStringTag===Dn||!1}function Vi(e){return new this(e).ln()}function ji(e,t){return new this(e).log(t)}function $i(e){return new this(e).log(2)}function Zi(e){return new this(e).log(10)}function Ki(){return ir(this,arguments,-1)}function Gi(){return ir(this,arguments,1)}function Wi(e,t){return new this(e).mod(t)}function zi(e,t){return new this(e).mul(t)}function Xi(e,t){return new this(e).pow(t)}function Yi(e){var t,n,i,c,o=0,a=new this(1),u=[];if(e===void 0?e=this.precision:Fe(e,1,Je),i=Math.ceil(e/he),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));o<i;)c=t[o],c>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:u[o++]=c%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);o<i;)c=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),c>=214e7?crypto.randomBytes(4).copy(t,o):(u.push(c%1e7),o+=4);o=i/4}else throw Error(Ln);else for(;o<i;)u[o++]=Math.random()*1e7|0;for(i=u[--o],e%=he,i&&e&&(c=Ue(10,he-e),u[o]=(i/c|0)*c);u[o]===0;o--)u.pop();if(o<0)n=0,u=[0];else{for(n=-1;u[0]===0;n-=he)u.shift();for(i=1,c=u[0];c>=10;c/=10)i++;i<he&&(n-=he-i)}return a.e=n,a.d=u,a}function Qi(e){return fe(e=new this(e),e.e+1,this.rounding)}function Ji(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Li(e){return new this(e).sin()}function Di(e){return new this(e).sinh()}function eo(e){return new this(e).sqrt()}function to(e,t){return new this(e).sub(t)}function no(){var e=0,t=arguments,n=new this(t[e]);for(me=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return me=!0,fe(n,this.precision,this.rounding)}function ro(e){return new this(e).tan()}function io(e){return new this(e).tanh()}function oo(e){return fe(e=new this(e),e.e+1,1)}X[Symbol.for("nodejs.util.inspect.custom")]=X.toString,X[Symbol.toStringTag]="Decimal";var ct=X.constructor=ur(nn);At=new ct(At),Tt=new ct(Tt);const so=({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}),i=e.Record({input_types:e.Vec(n),pool_address:e.Vec(e.Text),output_types:e.Vec(n)}),c=e.Variant({Ok:e.Nat64,Err:e.Text}),o=e.Record({user_id:e.Principal}),a=e.Record({canister_version:e.Opt(e.Nat64),canister_id:e.Principal}),u=e.Variant({from_user:o,from_canister:a}),h=e.Record({controllers:e.Vec(e.Principal)}),l=e.Variant({reinstall:e.Null,upgrade:e.Null,install:e.Null}),m=e.Record({mode:l,module_hash:e.Vec(e.Nat8)}),y=e.Record({canister_version:e.Nat64,taken_at_timestamp:e.Nat64,snapshot_id:e.Vec(e.Nat8)}),B=e.Variant({creation:h,code_deployment:m,load_snapshot:y,controllers_change:h,code_uninstall:e.Null}),v=e.Record({timestamp_nanos:e.Nat64,canister_version:e.Nat64,origin:u,details:B}),T=e.Record({controllers:e.Vec(e.Principal),module_hash:e.Opt(e.Vec(e.Nat8)),recent_changes:e.Vec(v),total_num_changes:e.Nat64}),N=e.Variant({Ok:T,Err:e.Text}),K=e.Record({exchange_id:e.Text,pool_address:e.Text,pool_key:e.Text}),J=e.Variant({All:e.Null,ByTxid:e.Text,ByAddress:e.Text,BySecondsPassed:e.Nat64}),F=e.Variant({Ok:e.Text,Err:e.Text}),b=e.Record({result:F,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}),P=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(b),processing_result:F,broadcasted_time:e.Opt(e.Text)}),I=e.Record({block_hash:e.Text,block_height:e.Nat32}),O=e.Record({processing_results:e.Vec(e.Text),block_basic:I,txids:e.Vec(e.Text),block_time:e.Text,received_time:e.Text}),U=e.Variant({Active:e.Null,Halted:e.Record({reason:e.Text})}),Z=e.Record({status:U,exchange_id:e.Text,canister_id:e.Principal,client_canisters:e.Vec(e.Principal)}),R=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}),j=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}),Q=e.Record({low:e.Nat64,high:e.Nat64,update_time:e.Text,medium:e.Nat64}),V=e.Variant({Enabled:e.Null,Disabled:e.Null,AllowEmpty:e.Null}),$=e.Record({last_block:e.Opt(I),pending_tx_count:e.Nat64,mempool_tx_fee_rate:Q,invoke_paused:e.Bool,utxo_proof_verification_status:V}),w=e.Variant({Confirmed:e.Nat32,Rejected:e.Text,Pending:e.Null}),H=e.Record({status:e.Opt(w),invoke_log:P,included_block:e.Opt(I),sent_tx_hex:e.Text}),x=e.Record({id:e.Text,value:e.Nat}),p=e.Record({maybe_rune:e.Opt(x),value:e.Nat64,script_pubkey_hex:e.Text,outpoint:e.Text}),_=e.Record({coin:x,from:e.Text}),k=e.Record({to:e.Text,coin:x}),g=e.Record({coins:e.Vec(x),sats:e.Nat64,txid:e.Text,vout:e.Nat32}),S=e.Record({input_coins:e.Vec(_),output_coins:e.Vec(k),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(g)}),q=e.Record({tx_fee_in_sats:e.Nat64,initiator_address:e.Text,intentions:e.Vec(S)}),G=e.Record({intention_set:q,initiator_utxo_proof:e.Vec(e.Nat8),psbt_hex:e.Text}),ee=e.Record({block_hash:e.Text,block_timestamp:e.Nat64,tx_ids:e.Vec(e.Text),block_height:e.Nat32}),ne=e.Variant({Ok:e.Vec(e.Text),Err:e.Text}),ie=e.Record({exchange_canister:e.Principal,exchange_id:e.Text,client_canisters:e.Vec(e.Principal)}),L=e.Record({txid:e.Text,timestamp:e.Nat64,block:I}),D=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([i],[c],["query"]),get_canister_info:e.Func([e.Nat64],[N],[]),get_exchange_pools:e.Func([],[e.Vec(K)],["query"]),get_failed_invoke_logs:e.Func([J],[e.Vec(e.Tuple(e.Text,P))],["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(O)],["query"]),get_registered_exchanges:e.Func([],[e.Vec(Z)],["query"]),get_rejected_txs:e.Func([e.Opt(e.Nat32)],[e.Vec(R)],["query"]),get_settings:e.Func([],[j],["query"]),get_status:e.Func([],[$],["query"]),get_tx_for_outpoint:e.Func([e.Text],[e.Opt(H)],["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(H)],["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(p)],["query"]),invoke:e.Func([G],[F],[]),new_block_detected:e.Func([ee],[t],[]),notify_exchange_for_blocks_from_height:e.Func([e.Text,e.Nat32],[ne],[]),register_exchange:e.Func([ie],[t],[]),save_included_block_for_tx:e.Func([L],[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([D],[t],[]),update_bitcoin_subnet_certificate:e.Func([e.Vec(e.Nat8)],[],[]),version:e.Func([],[e.Text],["query"])})};class fr{maestro;config;exchange;orchestrator;constructor(t){this.config=t;const n=t.network===yt.Testnet,i=n?"https://xbt-testnet.gomaestro-api.org/v0":"https://xbt-mainnet.gomaestro-api.org/v0";this.maestro=new Fr({baseUrl:i,apiKey:t.maestroApiKey});const c="https://icp0.io";this.exchange=Bt.Actor.createActor(t.exchangeIdlFactory,{agent:Bt.HttpAgent.createSync({host:c,retryTimes:50,verifyQuerySignatures:!1}),canisterId:t.exchangeCanisterId}),this.orchestrator=Bt.Actor.createActor(so,{agent:Bt.HttpAgent.createSync({host:c,retryTimes:50,verifyQuerySignatures:!1}),canisterId:n?Xr:zr})}async filterSpentUtxos(t,n){const i=await this.orchestrator.get_used_outpoints([t]);return n.filter(({txid:c,vout:o})=>i.findIndex(([a])=>`${c}:${o}`===a)<0)}async getBtcUtxos(t){let n=null;const i=[];do{const o=await this.maestro.utxosByAddress(t,n);i.push(...o.data),n=o.next_cursor}while(n!==null);const c=i.map(({txid:o,vout:a,runes:u,satoshis:h,script_pubkey:l,address:m})=>({txid:o,vout:a,address:m,runes:u.map(({rune_id:y,amount:B})=>({id:y,amount:B})),satoshis:h,scriptPk:l}));return this.filterSpentUtxos(t,c)}async getRuneUtxos(t,n){let i=null;const c=[];do{const a=await this.maestro.runeUtxosByAddress(t,n,i);c.push(...a.data),i=a.next_cursor}while(i!==null);const o=c.map(({txid:a,vout:u,runes:h,satoshis:l})=>{const m=zt(t,this.config.network);return{txid:a,vout:u,address:t,runes:h.map(({rune_id:y,amount:B})=>({id:y,amount:B})),satoshis:l,scriptPk:Gt(m)}});return this.filterSpentUtxos(t,o)}async searchRunes(t){const n=this.config.network===yt.Testnet?Qr:Yr,i=hi`
|
|
15
15
|
query GetRunes($keyword: String!, $regex: String!) {
|
|
16
16
|
runes(
|
|
17
17
|
where: {
|
|
@@ -31,4 +31,4 @@ ${String(e)}`)}catch(t){return t}},Wn=e=>{if(typeof e!="object"||e===null)throw
|
|
|
31
31
|
divisibility
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
`,c=new
|
|
34
|
+
`,c=new fi(n),o=t.split("").filter(u=>!(u==="•"||u===" ")).join("•?"),{runes:a}=await c.request(i,{keyword:t,regex:`(?i)${o}`});return a.map(({rune_id:u,spaced_rune:h,symbol:l,divisibility:m,etching:y})=>({runeId:u,spacedRune:h,symbol:l,divisibility:m,etching:y}))}async getRuneInfo(t){return(await this.searchRunes(t))[0]}async getBtcBalance(t){const i=(await this.getBtcUtxos(t)).reduce((c,o)=>c+BigInt(o.satoshis),BigInt(0));return new ct(i.toString()).div(1e8).toNumber()}async getRuneBalance(t,n){const i=await this.getRuneUtxos(t,n);if(!i)return;let c=new ct(0);for(const o of i)c=c.add(new ct(o.runes.find(a=>a.id===n)?.amount??0));return c.toNumber()}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,involvedRuneIds:i,involvedPoolAddresses:c}){const[o,a,u]=await Promise.all([this.getBtcUtxos(n),i?Promise.all(i.map(l=>this.getRuneUtxos(t,l))):Promise.resolve([]),Promise.all(c.map(l=>this.getPoolInfo(l)))]),h=Object.fromEntries(u.map(({utxos:l,address:m})=>l.map(({txid:y,vout:B,coins:v,sats:T})=>{const N=zt(m,this.config.network);return{txid:y,vout:B,address:m,runes:v.map(({id:K,value:J})=>({id:K,amount:J.toString()})),satoshis:T.toString(),scriptPk:Gt(N)}})).map((l,m)=>[c[m],l]));return new Mn({network:this.config.network,exchangeId:this.config.exchangeId,address:t,paymentAddress:n,btcUtxos:o,involvedRuneUtxos:i?.length?Object.fromEntries(i.map((l,m)=>[l,a[m]])):void 0,involvedPoolUtxos:h},this.orchestrator)}}const lr=ge.createContext(null);function co({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,i]=ge.useState({address:"",paymentAddress:"",publicKey:"",paymentPublicKey:""}),c=ge.useCallback(h=>{i(l=>({...l,...h}))},[]),o=ge.useMemo(()=>new fr(t),[t]),a=ge.useCallback(async h=>{if(!o)throw new Error("Client not available");if(!n.address||!n.paymentAddress)throw new Error("Wallet not connected");return o.createTransaction({...h,address:n.address,paymentAddress:n.paymentAddress})},[o,n]),u=ge.useMemo(()=>({client:o,...n,exchange:o.exchange,updateWallet:c,createTransaction:a}),[o,n,c,a]);return gr.jsx(lr.Provider,{value:u,children:e})}function Qe(){const e=ge.useContext(lr);if(!e)throw new Error("useRee must be used within ReeProvider");return e}function uo(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:i,paymentAddress:c}=Qe(),[o,a]=ge.useState(null),[u,h]=ge.useState(!1),[l,m]=ge.useState(null),y=ge.useCallback(async()=>{if(!c){a(null),m("Payment address not set");return}h(!0),m(null);try{const B=await i.getBtcBalance(c);a(B)}catch(B){m(B instanceof Error?B.message:"Failed to fetch BTC balance"),a(null)}finally{h(!1)}},[i,c]);return ge.useEffect(()=>{n&&y()},[c,y,n]),ge.useEffect(()=>{if(t>0){const B=setInterval(y,t);return()=>clearInterval(B)}},[t,c,y]),{balance:o,loading:u,error:l,refetch:y}}function ao(e,t={}){const{refreshInterval:n=0,autoRefresh:i=!0}=t,{client:c,address:o}=Qe(),[a,u]=ge.useState(null),[h,l]=ge.useState(!1),[m,y]=ge.useState(null),B=ge.useCallback(async()=>{if(!o){u(null),y("Address not set");return}if(!e){u(null),y("Rune ID is required");return}l(!0),y(null);try{const v=await c.getRuneBalance(o,e);u(v??null)}catch(v){y(v instanceof Error?v.message:"Failed to fetch rune balance"),u(null)}finally{l(!1)}},[c,o,e]);return ge.useEffect(()=>{i&&e&&B()},[o,e,B,i]),ge.useEffect(()=>{if(n>0&&e){const v=setInterval(B,n);return()=>clearInterval(v)}},[n,o,e,B]),{balance:a,loading:h,error:m,refetch:B}}function fo(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:i,paymentAddress:c}=Qe(),[o,a]=ge.useState([]),[u,h]=ge.useState(!1),[l,m]=ge.useState(null),y=ge.useCallback(async()=>{if(!c){a([]),m("Payment address not set");return}h(!0),m(null);try{const B=await i.getBtcUtxos(c);a(B)}catch(B){m(B instanceof Error?B.message:"Failed to fetch BTC UTXOs"),a([])}finally{h(!1)}},[i,c]);return ge.useEffect(()=>{n&&c&&y()},[c,y,n]),ge.useEffect(()=>{if(t>0&&c){const B=setInterval(y,t);return()=>clearInterval(B)}},[t,c,y]),{utxos:o,loading:u,error:l,refetch:y}}function lo(e,t={}){const{refreshInterval:n=0,autoRefresh:i=!0}=t,{client:c,address:o}=Qe(),[a,u]=ge.useState([]),[h,l]=ge.useState(!1),[m,y]=ge.useState(null),B=ge.useCallback(async()=>{if(!o){u([]),y("Address not set");return}if(!e){u([]),y("Rune ID is required");return}l(!0),y(null);try{const v=await c.getRuneUtxos(o,e);u(v)}catch(v){y(v instanceof Error?v.message:"Failed to fetch rune UTXOs"),u([])}finally{l(!1)}},[c,o,e]);return ge.useEffect(()=>{i&&o&&e&&B()},[o,e,B,i]),ge.useEffect(()=>{if(n>0&&o&&e){const v=setInterval(B,n);return()=>clearInterval(v)}},[n,o,e,B]),{utxos:a,loading:h,error:m,refetch:B}}function ho(){const{client:e}=Qe();return ge.useCallback(async n=>{const i=n;if(!i)throw new Error("Search keyword is required");return await e.searchRunes(i)},[e])}function po(e){const{client:t}=Qe(),[n,i]=ge.useState(null),[c,o]=ge.useState(!1),[a,u]=ge.useState(null),h=ge.useCallback(async()=>{if(!e){i(null),u("Rune ID is required");return}o(!0),u(null);try{const l=await t.getRuneInfo(e);i(l||null)}catch(l){u(l instanceof Error?l.message:"Failed to fetch rune info"),i(null)}finally{o(!1)}},[t,e]);return{runeInfo:n,loading:c,error:a,refetch:h}}function go(){const{client:e}=Qe(),[t,n]=ge.useState([]),[i,c]=ge.useState(!1),[o,a]=ge.useState(null),u=ge.useCallback(async()=>{c(!0),a(null);try{const h=await e.getPoolList();n(h)}catch(h){a(h instanceof Error?h.message:"Failed to fetch pool list"),n([])}finally{c(!1)}},[e]);return ge.useEffect(()=>{u()},[u]),{pools:t,loading:i,error:o,refetch:u}}function mo(e){const{client:t}=Qe(),[n,i]=ge.useState(null),[c,o]=ge.useState(!1),[a,u]=ge.useState(null),h=ge.useCallback(async()=>{if(!e){i(null),u("Pool address is required");return}o(!0),u(null);try{const l=await t.getPoolInfo(e);i(l)}catch(l){u(l instanceof Error?l.message:"Failed to fetch pool info"),i(null)}finally{o(!1)}},[t,e]);return ge.useEffect(()=>{h()},[e]),{poolInfo:n,loading:c,error:a,refetch:h}}Ae.Network=yt,Ae.ReeClient=fr,Ae.ReeProvider=co,Ae.Transaction=Mn,Ae.useBtcBalance=uo,Ae.useBtcUtxos=fo,Ae.usePoolInfo=mo,Ae.usePoolList=go,Ae.useRee=Qe,Ae.useRuneBalance=ao,Ae.useRuneInfo=po,Ae.useRuneUtxos=lo,Ae.useSearchRunes=ho,Ae.utils=Wr,Object.defineProperty(Ae,Symbol.toStringTag,{value:"Module"})}));
|