@helia/verified-fetch 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +4 -4
- package/dist/index.min.js.map +4 -4
- package/package.json +4 -4
package/dist/index.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaVerifiedFetch = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
2
|
"use strict";var HeliaVerifiedFetch=(()=>{var yF=Object.create;var K0=Object.defineProperty;var wF=Object.getOwnPropertyDescriptor;var xF=Object.getOwnPropertyNames;var bF=Object.getPrototypeOf,vF=Object.prototype.hasOwnProperty;var Rt=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Lt=(r,e)=>{for(var t in e)K0(r,t,{get:e[t],enumerable:!0})},tA=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xF(e))!vF.call(r,o)&&o!==t&&K0(r,o,{get:()=>e[o],enumerable:!(n=wF(e,o))||n.enumerable});return r};var gt=(r,e,t)=>(t=r!=null?yF(bF(r)):{},tA(e||!r||!r.__esModule?K0(t,"default",{value:r,enumerable:!0}):t,r)),EF=r=>tA(K0({},"__esModule",{value:!0}),r);var CT=Rt(hp=>{(function(){var r,e,t,n,o,i,s,a;a=function(c){var l,u,f,h;return l=(c&255<<24)>>>24,u=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[l,u,f,h].join(".")},s=function(c){var l,u,f,h,d,m;for(l=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}m=e(c),d=m[0],u=m[1],c=c.substring(u),l.push(d)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},t=function(c){return c.charCodeAt(0)},n=t("0"),i=t("a"),o=t("A"),e=function(c){var l,u,f,h,d;for(h=0,l=10,u="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,u="7")),d=f;f<c.length;){if("0"<=c[f]&&c[f]<=u)h=h*l+(t(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")h=h*l+(10+t(c[f])-i)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*l+(10+t(c[f])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===d)throw new Error("empty octet");return[h,f]},r=(function(){function c(l,u){var f,h,d,m;if(typeof l!="string")throw new Error("Missing `net' parameter");if(u||(m=l.split("/",2),l=m[0],u=m[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=s(u)}catch(y){throw f=y,new Error("Invalid mask: "+u)}for(h=d=32;d>=0;h=--d)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(s(l)&this.maskLong)>>>0}catch(y){throw f=y,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(s(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var u,f,h;for(h=s(this.first),f=s(this.last),u=0;h<=f;)l(a(h),h,u),u++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),hp.ip2long=s,hp.long2ip=a,hp.Netmask=r}).call(hp)});var dI=Rt((Kfe,Tx)=>{"use strict";var kq=Object.prototype.hasOwnProperty,mn="~";function Lp(){}Object.create&&(Lp.prototype=Object.create(null),new Lp().__proto__||(mn=!1));function Pq(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function fI(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Pq(t,n||r,o),s=mn?mn+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function E2(r,e){--r._eventsCount===0?r._events=new Lp:delete r._events[e]}function Qr(){this._events=new Lp,this._eventsCount=0}Qr.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)kq.call(t,n)&&e.push(mn?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};Qr.prototype.listeners=function(e){var t=mn?mn+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};Qr.prototype.listenerCount=function(e){var t=mn?mn+e:e,n=this._events[t];return n?n.fn?1:n.length:0};Qr.prototype.emit=function(e,t,n,o,i,s){var a=mn?mn+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,o),!0;case 5:return c.fn.call(c.context,t,n,o,i),!0;case 6:return c.fn.call(c.context,t,n,o,i,s),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var h=c.length,d;for(f=0;f<h;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,o);break;default:if(!u)for(d=1,u=new Array(l-1);d<l;d++)u[d-1]=arguments[d];c[f].fn.apply(c[f].context,u)}}return!0};Qr.prototype.on=function(e,t,n){return fI(this,e,t,n,!1)};Qr.prototype.once=function(e,t,n){return fI(this,e,t,n,!0)};Qr.prototype.removeListener=function(e,t,n,o){var i=mn?mn+e:e;if(!this._events[i])return this;if(!t)return E2(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&E2(this,i);else{for(var a=0,c=[],l=s.length;a<l;a++)(s[a].fn!==t||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:E2(this,i)}return this};Qr.prototype.removeAllListeners=function(e){var t;return e?(t=mn?mn+e:e,this._events[t]&&E2(this,t)):(this._events=new Lp,this._eventsCount=0),this};Qr.prototype.off=Qr.prototype.removeListener;Qr.prototype.addListener=Qr.prototype.on;Qr.prefixed=mn;Qr.EventEmitter=Qr;typeof Tx<"u"&&(Tx.exports=Qr)});var gI=Rt((fde,mI)=>{mI.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Ty=Rt((L1e,m9)=>{var N1e=(function(){typeof m9<"u"&&(m9.exports=y);var r=86400,e=3200,t=146097*e/400,n=r*t,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",l=Math.trunc||function(T){var k=T-T%1;return k==0&&(T<0||T===0&&1/T!=1/0)?-0:k},u=y.prototype,f=(y.fromDate=function(T){return new y(+T)},y.fromInt64BE=I(0,1,2,3,0,4),y.fromInt64LE=I(3,2,1,0,4,0),y.fromString=function(W){var k,z=new y,W=(W+="").replace(/^\s*[+\-]?\d+/,function(S){var S=+S,C=1970+(S-1970)%400;return z.year=S-C,C}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function($,S,C){return S<0&&(C*=-1),k=6e4*(60*+S+ +C),""}).replace(/\.\d+$/,function($){return z.nano=+($+c).substr(1,9),""}).split(/\D+/);if(1<W.length?W[1]--:W[1]=0,z.time=k=Date.UTC.apply(Date,W)-(k||0),isNaN(k))throw new TypeError("Invalid Date");return w(z)},y.fromTimeT=function(T){return v(T,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(T){return this.nano+=+T||0,this},u.getNano=function(){var T=w(this);return(T.time%1e3*a+ +T.nano+1e9)%1e9},u.getTimeT=function(){var k=w(this),T=Math.floor(k.time/1e3),k=k.year;return k&&(T+=k*t*r/e),T},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return x(w(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(T){var k=this,z=k.toDate(),W={H:function(){return K(z.getUTCHours())},L:function(){return M(z.getUTCMilliseconds(),3)},M:function(){return K(z.getUTCMinutes())},N:function(){return M(k.getNano(),9)},S:function(){return K(z.getUTCSeconds())},Y:function(){var $=k.getYear();return 999999<$?"+"+$:9999<$?"+"+M($,6):0<=$?M($,4):-999999<=$?"-"+M(-$,6):$},a:function(){return d[z.getUTCDay()]},b:function(){return h[z.getUTCMonth()]},d:function(){return K(z.getUTCDate())},e:function(){return(function($){return(9<$?"":" ")+(0|$)})(z.getUTCDate())},m:function(){return K(z.getUTCMonth()+1)}};return(function $(S){return S.replace(/%./g,function(C){var B=C[1],_=m[B],B=W[B];return _?$(_):B?B():C})})(T||f)},u.writeInt64BE=E(0,1,2,3,0,4),u.writeInt64LE=E(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],m={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return y;function y(T,k,z){var W=this;if(!(W instanceof y))return new y(T,k,z);W.time=+T||0,W.nano=+k||0,W.year=+z||0,w(W)}function w(T){var k,z,W,$=T.year,S=T.time,C=T.nano,_=((C<0||a<=C)&&(C-=(z=Math.floor(C/a))*a,S+=z,z=1),$%e);return(S<-i||i<S||_)&&((k=l(S/o))&&($+=k*e,S-=k*o),(W=x(S)).setUTCFullYear(_+W.getUTCFullYear()),W=(S=+W)+(k=l(($-=_)/e))*o,k&&-i<=W&&W<=i&&($-=k*e,S=W),z=1),z&&(T.year=$,T.time=S,T.nano=C),T}function x(T){var k=new Date(0);return k.setTime(T),k}function v($,W){$=+$||0;var z=l((W=(W|0)*s)/n)+l($/n),W=W%n+$%n,$=l(W/n);return $&&(z+=$,W-=$*n),new y(1e3*W,0,z*e)}function E(T,k,z,W,$,S){return function(_,B){var G=w(this);_=_||new Array(8),U(_,B|=0);var F=Math.floor(G.time/1e3),G=G.year*(t*r/e),X=l(G/s)+l(F/s),G=G%s+F%s,F=Math.floor(G/s);return F&&(X+=F,G-=F*s),C(_,B+$,X),C(_,B+S,G),_};function C(_,B,X){_[B+T]=X>>24&255,_[B+k]=X>>16&255,_[B+z]=X>>8&255,_[B+W]=255&X}}function I(T,k,z,W,$,S){return function(_,B){U(_,B|=0);var X=C(_,B+$);return v(C(_,B+S),X)};function C(_,B){return 16777216*_[B+T]+(_[B+k]<<16|_[B+z]<<8|_[B+W])}}function U(T,k){if(T=T&&T.length,T==null)throw new TypeError("Invalid Buffer");if(T<k+8)throw new RangeError("Out of range")}function K(T){return(9<T?"":"0")+(0|T)}function M(T,k){return(c+(0|T)).substr(-k)}})()});var xP=Rt((X5e,wP)=>{"use strict";function dW(r){return r>=55296&&r<=56319}function hW(r){return r>=56320&&r<=57343}wP.exports=function(e,t,n){if(typeof t!="string")throw new Error("Input must be string");for(var o=t.length,i=0,s,a,c=0;c<o;c+=1){if(s=t.charCodeAt(c),a=t[c],dW(s)&&hW(t.charCodeAt(c+1))&&(c+=1,a+=t[c]),i+=e(a),i===n)return t.slice(0,c+1);if(i>n)return t.slice(0,c-a.length+1)}return t}});var vP=Rt((Y5e,bP)=>{"use strict";function pW(r){return r>=55296&&r<=56319}function mW(r){return r>=56320&&r<=57343}bP.exports=function(e){if(typeof e!="string")throw new Error("Input must be string");for(var t=e.length,n=0,o=null,i=null,s=0;s<t;s++)o=e.charCodeAt(s),mW(o)?i!=null&&pW(i)?n+=1:n+=3:o<=127?n+=1:o>=128&&o<=2047?n+=2:o>=2048&&o<=65535&&(n+=3),i=o;return n}});var SP=Rt((Q5e,EP)=>{"use strict";var gW=xP(),yW=vP();EP.exports=gW.bind(null,yW)});var TP=Rt((Z5e,_P)=>{"use strict";var wW=SP(),xW=/[\/\?<>\\:\*\|"]/g,bW=/[\x00-\x1f\x80-\x9f]/g,vW=/^\.+$/,EW=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,SW=/[\. ]+$/;function AP(r,e){if(typeof r!="string")throw new Error("Input must be string");var t=r.replace(xW,e).replace(bW,e).replace(vW,e).replace(EW,e).replace(SW,e);return wW(t,255)}_P.exports=function(r,e){var t=e&&e.replacement||"",n=AP(r,t);return t===""?n:AP(n,"")}});var js=Rt(rd=>{"use strict";var _W="[object ArrayBuffer]",zs=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===_W}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},W9="string",TW=/^[0-9a-f\s]+$/i,CW=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,IW=/^[a-zA-Z0-9-_]+$/,R3=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=zs.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Bo=class{static toString(e,t=!1){let n=zs.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},O3=class r{static isHex(e){return typeof e===W9&&TW.test(e)}static isBase64(e){return typeof e===W9&&CW.test(e)}static isBase64Url(e){return typeof e===W9&&IW.test(e)}static ToString(e,t="utf8"){let n=zs.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Bo.toString(n,!0);case"utf16":case"utf16be":return Bo.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Bo.fromString(e,!0);case"utf16":case"utf16be":return Bo.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=zs.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return R3.fromString(e);case"utf16":case"utf16be":return Bo.fromString(e);case"utf16le":case"usc2":return Bo.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return R3.toString(e);case"utf16":case"utf16be":return Bo.toString(e);case"utf16le":case"usc2":return Bo.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=zs.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=zs.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Bo.toString(e,t)}static FromUtf16String(e,t=!1){return Bo.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};O3.DEFAULT_UTF8_ENCODING="utf8";function kW(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function PW(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function RW(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}rd.BufferSourceConverter=zs;rd.Convert=O3;rd.assign=kW;rd.combine=PW;rd.isEqual=RW});var KO=Rt(Qi=>{"use strict";Object.defineProperty(Qi,"__esModule",{value:!0});Qi.parseCookie=$O;Qi.parse=$O;Qi.stringifyCookie=cX;Qi.stringifySetCookie=F4;Qi.serialize=F4;Qi.parseSetCookie=lX;Qi.stringifySetCookie=F4;Qi.serialize=F4;var UO=/^[\u0021-\u003A\u003C\u003E-\u007E]+$/,FO=/^[\u0021-\u003A\u003C-\u007E]*$/,nX=/^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,oX=/^[\u0020-\u003A\u003D-\u007E]*$/,iX=/^-?\d+$/,sX=Object.prototype.toString,aX=(()=>{let r=function(){};return r.prototype=Object.create(null),r})();function $O(r,e){let t=new aX,n=r.length;if(n<2)return t;let o=e?.decode||HO,i=0;do{let s=Kb(r,i,n);if(s===-1)break;let a=Hb(r,i,n);if(s>a){i=r.lastIndexOf(";",s-1)+1;continue}let c=Ga(r,i,s);t[c]===void 0&&(t[c]=o(Ga(r,s+1,a))),i=a+1}while(i<n);return t}function cX(r,e){let t=e?.encode||encodeURIComponent,n=[];for(let o of Object.keys(r)){let i=r[o];if(i===void 0)continue;if(!UO.test(o))throw new TypeError(`cookie name is invalid: ${o}`);let s=t(i);if(!FO.test(s))throw new TypeError(`cookie val is invalid: ${i}`);n.push(`${o}=${s}`)}return n.join("; ")}function F4(r,e,t){let n=typeof r=="object"?r:{...t,name:r,value:String(e)},i=(typeof e=="object"?e:t)?.encode||encodeURIComponent;if(!UO.test(n.name))throw new TypeError(`argument name is invalid: ${n.name}`);let s=n.value?i(n.value):"";if(!FO.test(s))throw new TypeError(`argument val is invalid: ${n.value}`);let a=n.name+"="+s;if(n.maxAge!==void 0){if(!Number.isInteger(n.maxAge))throw new TypeError(`option maxAge is invalid: ${n.maxAge}`);a+="; Max-Age="+n.maxAge}if(n.domain){if(!nX.test(n.domain))throw new TypeError(`option domain is invalid: ${n.domain}`);a+="; Domain="+n.domain}if(n.path){if(!oX.test(n.path))throw new TypeError(`option path is invalid: ${n.path}`);a+="; Path="+n.path}if(n.expires){if(!uX(n.expires)||!Number.isFinite(n.expires.valueOf()))throw new TypeError(`option expires is invalid: ${n.expires}`);a+="; Expires="+n.expires.toUTCString()}if(n.httpOnly&&(a+="; HttpOnly"),n.secure&&(a+="; Secure"),n.partitioned&&(a+="; Partitioned"),n.priority)switch(typeof n.priority=="string"?n.priority.toLowerCase():void 0){case"low":a+="; Priority=Low";break;case"medium":a+="; Priority=Medium";break;case"high":a+="; Priority=High";break;default:throw new TypeError(`option priority is invalid: ${n.priority}`)}if(n.sameSite)switch(typeof n.sameSite=="string"?n.sameSite.toLowerCase():n.sameSite){case!0:case"strict":a+="; SameSite=Strict";break;case"lax":a+="; SameSite=Lax";break;case"none":a+="; SameSite=None";break;default:throw new TypeError(`option sameSite is invalid: ${n.sameSite}`)}return a}function lX(r,e){let t=e?.decode||HO,n=r.length,o=Hb(r,0,n),i=Kb(r,0,o),s=i===-1?{name:"",value:t(Ga(r,0,o))}:{name:Ga(r,0,i),value:t(Ga(r,i+1,o))},a=o+1;for(;a<n;){let c=Hb(r,a,n),l=Kb(r,a,c),u=l===-1?Ga(r,a,c):Ga(r,a,l),f=l===-1?void 0:Ga(r,l+1,c);switch(u.toLowerCase()){case"httponly":s.httpOnly=!0;break;case"secure":s.secure=!0;break;case"partitioned":s.partitioned=!0;break;case"domain":s.domain=f;break;case"path":s.path=f;break;case"max-age":f&&iX.test(f)&&(s.maxAge=Number(f));break;case"expires":if(!f)break;let h=new Date(f);Number.isFinite(h.valueOf())&&(s.expires=h);break;case"priority":if(!f)break;let d=f.toLowerCase();(d==="low"||d==="medium"||d==="high")&&(s.priority=d);break;case"samesite":if(!f)break;let m=f.toLowerCase();(m==="lax"||m==="strict"||m==="none")&&(s.sameSite=m);break}a=c+1}return s}function Hb(r,e,t){let n=r.indexOf(";",e);return n===-1?t:n}function Kb(r,e,t){let n=r.indexOf("=",e);return n<t?n:-1}function Ga(r,e,t){let n=e,o=t;do{let i=r.charCodeAt(n);if(i!==32&&i!==9)break}while(++n<o);for(;o>n;){let i=r.charCodeAt(o-1);if(i!==32&&i!==9)break;o--}return r.slice(n,o)}function HO(r){if(r.indexOf("%")===-1)return r;try{return decodeURIComponent(r)}catch{return r}}function uX(r){return sX.call(r)==="[object Date]"}});var hN=Rt(()=>{var dN;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,l){return function(u,f){Object.defineProperty(c,u,{configurable:!0,writable:!0,value:f}),l&&l(u,f)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,l=!a&&!c,u={create:a?function(){return G8(Object.create(null))}:c?function(){return G8({__proto__:null})}:function(){return G8({})},has:l?function(P,L){return n.call(P,L)}:function(P,L){return L in P},get:l?function(P,L){return n.call(P,L)?P[L]:void 0}:function(P,L){return P[L]}},f=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:dF(),d=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:hF(),m=typeof WeakMap=="function"?WeakMap:pF(),y=o?Symbol.for("@reflect-metadata:registry"):void 0,w=lF(),x=uF(w);function v(P,L,q,te){if(V(q)){if(!ds(P))throw new TypeError;if(!ha(L))throw new TypeError;return $(P,L)}else{if(!ds(P))throw new TypeError;if(!he(L))throw new TypeError;if(!he(te)&&!V(te)&&!Ne(te))throw new TypeError;return Ne(te)&&(te=void 0),q=at(q),S(P,L,q,te)}}e("decorate",v);function E(P,L){function q(te,Se){if(!he(te))throw new TypeError;if(!V(Se)&&!H0(Se))throw new TypeError;G(P,L,te,Se)}return q}e("metadata",E);function I(P,L,q,te){if(!he(q))throw new TypeError;return V(te)||(te=at(te)),G(P,L,q,te)}e("defineMetadata",I);function U(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),C(P,L,q)}e("hasMetadata",U);function K(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),_(P,L,q)}e("hasOwnMetadata",K);function M(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),B(P,L,q)}e("getMetadata",M);function T(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),X(P,L,q)}e("getOwnMetadata",T);function k(P,L){if(!he(P))throw new TypeError;return V(L)||(L=at(L)),F(P,L)}e("getMetadataKeys",k);function z(P,L){if(!he(P))throw new TypeError;return V(L)||(L=at(L)),Q(P,L)}e("getOwnMetadataKeys",z);function W(P,L,q){if(!he(L))throw new TypeError;if(V(q)||(q=at(q)),!he(L))throw new TypeError;V(q)||(q=at(q));var te=Th(L,q,!1);return V(te)?!1:te.OrdinaryDeleteMetadata(P,L,q)}e("deleteMetadata",W);function $(P,L){for(var q=P.length-1;q>=0;--q){var te=P[q],Se=te(L);if(!V(Se)&&!Ne(Se)){if(!ha(Se))throw new TypeError;L=Se}}return L}function S(P,L,q,te){for(var Se=P.length-1;Se>=0;--Se){var zt=P[Se],ar=zt(L,q,te);if(!V(ar)&&!Ne(ar)){if(!he(ar))throw new TypeError;te=ar}}return te}function C(P,L,q){var te=_(P,L,q);if(te)return!0;var Se=W8(L);return Ne(Se)?!1:C(P,Se,q)}function _(P,L,q){var te=Th(L,q,!1);return V(te)?!1:Pt(te.OrdinaryHasOwnMetadata(P,L,q))}function B(P,L,q){var te=_(P,L,q);if(te)return X(P,L,q);var Se=W8(L);if(!Ne(Se))return B(P,Se,q)}function X(P,L,q){var te=Th(L,q,!1);if(!V(te))return te.OrdinaryGetOwnMetadata(P,L,q)}function G(P,L,q,te){var Se=Th(q,te,!0);Se.OrdinaryDefineOwnMetadata(P,L,q,te)}function F(P,L){var q=Q(P,L),te=W8(P);if(te===null)return q;var Se=F(te,L);if(Se.length<=0)return q;if(q.length<=0)return Se;for(var zt=new d,ar=[],Fe=0,ae=q;Fe<ae.length;Fe++){var fe=ae[Fe],pe=zt.has(fe);pe||(zt.add(fe),ar.push(fe))}for(var ye=0,He=Se;ye<He.length;ye++){var fe=He[ye],pe=zt.has(fe);pe||(zt.add(fe),ar.push(fe))}return ar}function Q(P,L){var q=Th(P,L,!1);return q?q.OrdinaryOwnMetadataKeys(P,L):[]}function ne(P){if(P===null)return 1;switch(typeof P){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return P===null?1:6;default:return 6}}function V(P){return P===void 0}function Ne(P){return P===null}function Ue(P){return typeof P=="symbol"}function he(P){return typeof P=="object"?P!==null:typeof P=="function"}function Ve(P,L){switch(ne(P)){case 0:return P;case 1:return P;case 2:return P;case 3:return P;case 4:return P;case 5:return P}var q=L===3?"string":L===5?"number":"default",te=_h(P,i);if(te!==void 0){var Se=te.call(P,q);if(he(Se))throw new TypeError;return Se}return st(P,q==="default"?"number":q)}function st(P,L){if(L==="string"){var q=P.toString;if(Xo(q)){var te=q.call(P);if(!he(te))return te}var Se=P.valueOf;if(Xo(Se)){var te=Se.call(P);if(!he(te))return te}}else{var Se=P.valueOf;if(Xo(Se)){var te=Se.call(P);if(!he(te))return te}var zt=P.toString;if(Xo(zt)){var te=zt.call(P);if(!he(te))return te}}throw new TypeError}function Pt(P){return!!P}function Ge(P){return""+P}function at(P){var L=Ve(P,3);return Ue(L)?L:Ge(L)}function ds(P){return Array.isArray?Array.isArray(P):P instanceof Object?P instanceof Array:Object.prototype.toString.call(P)==="[object Array]"}function Xo(P){return typeof P=="function"}function ha(P){return typeof P=="function"}function H0(P){switch(ne(P)){case 3:return!0;case 4:return!0;default:return!1}}function Ku(P,L){return P===L||P!==P&&L!==L}function _h(P,L){var q=P[L];if(q!=null){if(!Xo(q))throw new TypeError;return q}}function YS(P){var L=_h(P,s);if(!Xo(L))throw new TypeError;var q=L.call(P);if(!he(q))throw new TypeError;return q}function QS(P){return P.value}function ZS(P){var L=P.next();return L.done?!1:L}function JS(P){var L=P.return;L&&L.call(P)}function W8(P){var L=Object.getPrototypeOf(P);if(typeof P!="function"||P===f||L!==f)return L;var q=P.prototype,te=q&&Object.getPrototypeOf(q);if(te==null||te===Object.prototype)return L;var Se=te.constructor;return typeof Se!="function"||Se===P?L:Se}function cF(){var P;!V(y)&&typeof t.Reflect<"u"&&!(y in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(P=fF(t.Reflect));var L,q,te,Se=new m,zt={registerProvider:ar,getProvider:ae,setProvider:pe};return zt;function ar(ye){if(!Object.isExtensible(zt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case P===ye:break;case V(L):L=ye;break;case L===ye:break;case V(q):q=ye;break;case q===ye:break;default:te===void 0&&(te=new d),te.add(ye);break}}function Fe(ye,He){if(!V(L)){if(L.isProviderFor(ye,He))return L;if(!V(q)){if(q.isProviderFor(ye,He))return L;if(!V(te))for(var St=YS(te);;){var jt=ZS(St);if(!jt)return;var Yo=QS(jt);if(Yo.isProviderFor(ye,He))return JS(St),Yo}}}if(!V(P)&&P.isProviderFor(ye,He))return P}function ae(ye,He){var St=Se.get(ye),jt;return V(St)||(jt=St.get(He)),V(jt)&&(jt=Fe(ye,He),V(jt)||(V(St)&&(St=new h,Se.set(ye,St)),St.set(He,jt))),jt}function fe(ye){if(V(ye))throw new TypeError;return L===ye||q===ye||!V(te)&&te.has(ye)}function pe(ye,He,St){if(!fe(St))throw new Error("Metadata provider not registered.");var jt=ae(ye,He);if(jt!==St){if(!V(jt))return!1;var Yo=Se.get(ye);V(Yo)&&(Yo=new h,Se.set(ye,Yo)),Yo.set(He,St)}return!0}}function lF(){var P;return!V(y)&&he(t.Reflect)&&Object.isExtensible(t.Reflect)&&(P=t.Reflect[y]),V(P)&&(P=cF()),!V(y)&&he(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,y,{enumerable:!1,configurable:!1,writable:!1,value:P}),P}function uF(P){var L=new m,q={isProviderFor:function(fe,pe){var ye=L.get(fe);return V(ye)?!1:ye.has(pe)},OrdinaryDefineOwnMetadata:ar,OrdinaryHasOwnMetadata:Se,OrdinaryGetOwnMetadata:zt,OrdinaryOwnMetadataKeys:Fe,OrdinaryDeleteMetadata:ae};return w.registerProvider(q),q;function te(fe,pe,ye){var He=L.get(fe),St=!1;if(V(He)){if(!ye)return;He=new h,L.set(fe,He),St=!0}var jt=He.get(pe);if(V(jt)){if(!ye)return;if(jt=new h,He.set(pe,jt),!P.setProvider(fe,pe,q))throw He.delete(pe),St&&L.delete(fe),new Error("Wrong provider for target.")}return jt}function Se(fe,pe,ye){var He=te(pe,ye,!1);return V(He)?!1:Pt(He.has(fe))}function zt(fe,pe,ye){var He=te(pe,ye,!1);if(!V(He))return He.get(fe)}function ar(fe,pe,ye,He){var St=te(ye,He,!0);St.set(fe,pe)}function Fe(fe,pe){var ye=[],He=te(fe,pe,!1);if(V(He))return ye;for(var St=He.keys(),jt=YS(St),Yo=0;;){var eA=ZS(jt);if(!eA)return ye.length=Yo,ye;var mF=QS(eA);try{ye[Yo]=mF}catch(gF){try{JS(jt)}finally{throw gF}}Yo++}}function ae(fe,pe,ye){var He=te(pe,ye,!1);if(V(He)||!He.delete(fe))return!1;if(He.size===0){var St=L.get(pe);V(St)||(St.delete(ye),St.size===0&&L.delete(St))}return!0}}function fF(P){var L=P.defineMetadata,q=P.hasOwnMetadata,te=P.getOwnMetadata,Se=P.getOwnMetadataKeys,zt=P.deleteMetadata,ar=new m,Fe={isProviderFor:function(ae,fe){var pe=ar.get(ae);return!V(pe)&&pe.has(fe)?!0:Se(ae,fe).length?(V(pe)&&(pe=new d,ar.set(ae,pe)),pe.add(fe),!0):!1},OrdinaryDefineOwnMetadata:L,OrdinaryHasOwnMetadata:q,OrdinaryGetOwnMetadata:te,OrdinaryOwnMetadataKeys:Se,OrdinaryDeleteMetadata:zt};return Fe}function Th(P,L,q){var te=w.getProvider(P,L);if(!V(te))return te;if(q){if(w.setProvider(P,L,x))return x;throw new Error("Illegal state.")}}function dF(){var P={},L=[],q=(function(){function Fe(ae,fe,pe){this._index=0,this._keys=ae,this._values=fe,this._selector=pe}return Fe.prototype["@@iterator"]=function(){return this},Fe.prototype[s]=function(){return this},Fe.prototype.next=function(){var ae=this._index;if(ae>=0&&ae<this._keys.length){var fe=this._selector(this._keys[ae],this._values[ae]);return ae+1>=this._keys.length?(this._index=-1,this._keys=L,this._values=L):this._index++,{value:fe,done:!1}}return{value:void 0,done:!0}},Fe.prototype.throw=function(ae){throw this._index>=0&&(this._index=-1,this._keys=L,this._values=L),ae},Fe.prototype.return=function(ae){return this._index>=0&&(this._index=-1,this._keys=L,this._values=L),{value:ae,done:!0}},Fe})(),te=(function(){function Fe(){this._keys=[],this._values=[],this._cacheKey=P,this._cacheIndex=-2}return Object.defineProperty(Fe.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),Fe.prototype.has=function(ae){return this._find(ae,!1)>=0},Fe.prototype.get=function(ae){var fe=this._find(ae,!1);return fe>=0?this._values[fe]:void 0},Fe.prototype.set=function(ae,fe){var pe=this._find(ae,!0);return this._values[pe]=fe,this},Fe.prototype.delete=function(ae){var fe=this._find(ae,!1);if(fe>=0){for(var pe=this._keys.length,ye=fe+1;ye<pe;ye++)this._keys[ye-1]=this._keys[ye],this._values[ye-1]=this._values[ye];return this._keys.length--,this._values.length--,Ku(ae,this._cacheKey)&&(this._cacheKey=P,this._cacheIndex=-2),!0}return!1},Fe.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=P,this._cacheIndex=-2},Fe.prototype.keys=function(){return new q(this._keys,this._values,Se)},Fe.prototype.values=function(){return new q(this._keys,this._values,zt)},Fe.prototype.entries=function(){return new q(this._keys,this._values,ar)},Fe.prototype["@@iterator"]=function(){return this.entries()},Fe.prototype[s]=function(){return this.entries()},Fe.prototype._find=function(ae,fe){if(!Ku(this._cacheKey,ae)){this._cacheIndex=-1;for(var pe=0;pe<this._keys.length;pe++)if(Ku(this._keys[pe],ae)){this._cacheIndex=pe;break}}return this._cacheIndex<0&&fe&&(this._cacheIndex=this._keys.length,this._keys.push(ae),this._values.push(void 0)),this._cacheIndex},Fe})();return te;function Se(Fe,ae){return Fe}function zt(Fe,ae){return ae}function ar(Fe,ae){return[Fe,ae]}}function hF(){var P=(function(){function L(){this._map=new h}return Object.defineProperty(L.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),L.prototype.has=function(q){return this._map.has(q)},L.prototype.add=function(q){return this._map.set(q,q),this},L.prototype.delete=function(q){return this._map.delete(q)},L.prototype.clear=function(){this._map.clear()},L.prototype.keys=function(){return this._map.keys()},L.prototype.values=function(){return this._map.keys()},L.prototype.entries=function(){return this._map.entries()},L.prototype["@@iterator"]=function(){return this.keys()},L.prototype[s]=function(){return this.keys()},L})();return P}function pF(){var P=16,L=u.create(),q=te();return(function(){function ae(){this._key=te()}return ae.prototype.has=function(fe){var pe=Se(fe,!1);return pe!==void 0?u.has(pe,this._key):!1},ae.prototype.get=function(fe){var pe=Se(fe,!1);return pe!==void 0?u.get(pe,this._key):void 0},ae.prototype.set=function(fe,pe){var ye=Se(fe,!0);return ye[this._key]=pe,this},ae.prototype.delete=function(fe){var pe=Se(fe,!1);return pe!==void 0?delete pe[this._key]:!1},ae.prototype.clear=function(){this._key=te()},ae})();function te(){var ae;do ae="@@WeakMap@@"+Fe();while(u.has(L,ae));return L[ae]=!0,ae}function Se(ae,fe){if(!n.call(ae,q)){if(!fe)return;Object.defineProperty(ae,q,{value:u.create()})}return ae[q]}function zt(ae,fe){for(var pe=0;pe<fe;++pe)ae[pe]=Math.random()*255|0;return ae}function ar(ae){if(typeof Uint8Array=="function"){var fe=new Uint8Array(ae);return typeof crypto<"u"?crypto.getRandomValues(fe):typeof msCrypto<"u"?msCrypto.getRandomValues(fe):zt(fe,ae),fe}return zt(new Array(ae),ae)}function Fe(){var ae=ar(P);ae[6]=ae[6]&79|64,ae[8]=ae[8]&191|128;for(var fe="",pe=0;pe<P;++pe){var ye=ae[pe];(pe===4||pe===6||pe===8)&&(fe+="-"),ye<16&&(fe+="0"),fe+=ye.toString(16).toLowerCase()}return fe}}function G8(P){return P.__=void 0,delete P.__,P}})})(dN||(dN={}))});var EL=Rt((FHe,w5)=>{var rL,nL,oL,iL,sL,aL,cL,lL,uL,y5,pE,fL,dL,Yd,hL,pL,mL,gL,yL,wL,xL,bL,vL;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof w5=="object"&&typeof w5.exports=="object"?r(t(e,t(w5.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};rL=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},nL=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++){n=arguments[o];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},oL=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},iL=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},sL=function(t,n){return function(o,i){n(o,i,t)}},aL=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},cL=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function l(h){try{f(i.next(h))}catch(d){c(d)}}function u(h){try{f(i.throw(h))}catch(d){c(d)}}function f(h){h.done?a(h.value):s(h.value).then(l,u)}f((i=i.apply(t,n||[])).next())})},lL=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(f){return function(h){return u([f,h])}}function u(f){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=f[0]&2?s.return:f[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,f[1])).done)return a;switch(s=0,a&&(f=[f[0]&2,a.value]),f[0]){case 0:case 1:a=f;break;case 4:return o.label++,{value:f[1],done:!1};case 5:o.label++,s=f[1],f=[0];continue;case 7:f=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(f[0]===6||f[0]===2)){o=0;continue}if(f[0]===3&&(!a||f[1]>a[0]&&f[1]<a[3])){o.label=f[1];break}if(f[0]===6&&o.label<a[1]){o.label=a[1],a=f;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(f);break}a[2]&&o.ops.pop(),o.trys.pop();continue}f=n.call(t,o)}catch(h){f=[6,h],s=0}finally{i=a=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},vL=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},uL=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},y5=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},pE=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(l){c={error:l}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},fL=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(pE(arguments[n]));return t},dL=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,l=a.length;c<l;c++,s++)i[s]=a[c];return i},Yd=function(t){return this instanceof Yd?(this.v=t,this):new Yd(t)},hL=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(m){i[m]&&(s[m]=function(y){return new Promise(function(w,x){a.push([m,y,w,x])>1||l(m,y)})})}function l(m,y){try{u(i[m](y))}catch(w){d(a[0][3],w)}}function u(m){m.value instanceof Yd?Promise.resolve(m.value.v).then(f,h):d(a[0][2],m)}function f(m){l("next",m)}function h(m){l("throw",m)}function d(m,y){m(y),a.shift(),a.length&&l(a[0][0],a[0][1])}},pL=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Yd(t[s](c)),done:s==="return"}:a?a(c):c}:a}},mL=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof y5=="function"?y5(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(l,u){c=t[a](c),s(l,u,c.done,c.value)})}}function s(a,c,l,u){Promise.resolve(u).then(function(f){a({value:f,done:l})},c)}},gL=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},yL=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},wL=function(t){return t&&t.__esModule?t:{default:t}},xL=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},bL=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",rL),r("__assign",nL),r("__rest",oL),r("__decorate",iL),r("__param",sL),r("__metadata",aL),r("__awaiter",cL),r("__generator",lL),r("__exportStar",uL),r("__createBinding",vL),r("__values",y5),r("__read",pE),r("__spread",fL),r("__spreadArrays",dL),r("__await",Yd),r("__asyncGenerator",hL),r("__asyncDelegator",pL),r("__asyncValues",mL),r("__makeTemplateObject",gL),r("__importStar",yL),r("__importDefault",wL),r("__classPrivateFieldGet",xL),r("__classPrivateFieldSet",bL)})});var wM=Rt((TYe,yM)=>{yM.exports=hS;var gM=128,MQ=127,UQ=~MQ,FQ=Math.pow(2,31);function hS(r,e,t){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw hS.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var n=t;r>=FQ;)e[t++]=r&255|gM,r/=128;for(;r&UQ;)e[t++]=r&255|gM,r>>>=7;return e[t]=r|0,hS.bytes=t-n+1,e}});var vM=Rt((CYe,bM)=>{bM.exports=pS;var $Q=128,xM=127;function pS(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a||o>49)throw pS.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&xM)<<o:(s&xM)*Math.pow(2,o),o+=7}while(s>=$Q);return pS.bytes=i-n,t}});var SM=Rt((IYe,EM)=>{var HQ=Math.pow(2,7),KQ=Math.pow(2,14),VQ=Math.pow(2,21),qQ=Math.pow(2,28),zQ=Math.pow(2,35),jQ=Math.pow(2,42),WQ=Math.pow(2,49),GQ=Math.pow(2,56),XQ=Math.pow(2,63);EM.exports=function(r){return r<HQ?1:r<KQ?2:r<VQ?3:r<qQ?4:r<zQ?5:r<jQ?6:r<WQ?7:r<GQ?8:r<XQ?9:10}});var s8=Rt((kYe,AM)=>{AM.exports={encode:wM(),decode:vM(),encodingLength:SM()}});var MM=Rt((R0,m8)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(d){if(!Array.isArray(d)&&!ArrayBuffer.isView(d))return!1;for(var m=0;m<d.length;m++)if(!Number.isInteger(d[m])||d[m]<0||d[m]>255)return!1;return!0}function o(d,m){return(d&65535)*m+(((d>>>16)*m&65535)<<16)}function i(d,m){return d<<m|d>>>32-m}function s(d){return d^=d>>>16,d=o(d,2246822507),d^=d>>>13,d=o(d,3266489909),d^=d>>>16,d}function a(d,m){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],m=[m[0]>>>16,m[0]&65535,m[1]>>>16,m[1]&65535];var y=[0,0,0,0];return y[3]+=d[3]+m[3],y[2]+=y[3]>>>16,y[3]&=65535,y[2]+=d[2]+m[2],y[1]+=y[2]>>>16,y[2]&=65535,y[1]+=d[1]+m[1],y[0]+=y[1]>>>16,y[1]&=65535,y[0]+=d[0]+m[0],y[0]&=65535,[y[0]<<16|y[1],y[2]<<16|y[3]]}function c(d,m){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],m=[m[0]>>>16,m[0]&65535,m[1]>>>16,m[1]&65535];var y=[0,0,0,0];return y[3]+=d[3]*m[3],y[2]+=y[3]>>>16,y[3]&=65535,y[2]+=d[2]*m[3],y[1]+=y[2]>>>16,y[2]&=65535,y[2]+=d[3]*m[2],y[1]+=y[2]>>>16,y[2]&=65535,y[1]+=d[1]*m[3],y[0]+=y[1]>>>16,y[1]&=65535,y[1]+=d[2]*m[2],y[0]+=y[1]>>>16,y[1]&=65535,y[1]+=d[3]*m[1],y[0]+=y[1]>>>16,y[1]&=65535,y[0]+=d[0]*m[3]+d[1]*m[2]+d[2]*m[1]+d[3]*m[0],y[0]&=65535,[y[0]<<16|y[1],y[2]<<16|y[3]]}function l(d,m){return m%=64,m===32?[d[1],d[0]]:m<32?[d[0]<<m|d[1]>>>32-m,d[1]<<m|d[0]>>>32-m]:(m-=32,[d[1]<<m|d[0]>>>32-m,d[0]<<m|d[1]>>>32-m])}function u(d,m){return m%=64,m===0?d:m<32?[d[0]<<m|d[1]>>>32-m,d[1]<<m]:[d[1]<<m-32,0]}function f(d,m){return[d[0]^m[0],d[1]^m[1]]}function h(d){return d=f(d,[0,d[0]>>>1]),d=c(d,[4283543511,3981806797]),d=f(d,[0,d[0]>>>1]),d=c(d,[3301882366,444984403]),d=f(d,[0,d[0]>>>1]),d}t.x86.hash32=function(d,m){if(t.inputValidation&&!n(d))return e;m=m||0;for(var y=d.length%4,w=d.length-y,x=m,v=0,E=3432918353,I=461845907,U=0;U<w;U=U+4)v=d[U]|d[U+1]<<8|d[U+2]<<16|d[U+3]<<24,v=o(v,E),v=i(v,15),v=o(v,I),x^=v,x=i(x,13),x=o(x,5)+3864292196;switch(v=0,y){case 3:v^=d[U+2]<<16;case 2:v^=d[U+1]<<8;case 1:v^=d[U],v=o(v,E),v=i(v,15),v=o(v,I),x^=v}return x^=d.length,x=s(x),x>>>0},t.x86.hash128=function(d,m){if(t.inputValidation&&!n(d))return e;m=m||0;for(var y=d.length%16,w=d.length-y,x=m,v=m,E=m,I=m,U=0,K=0,M=0,T=0,k=597399067,z=2869860233,W=951274213,$=2716044179,S=0;S<w;S=S+16)U=d[S]|d[S+1]<<8|d[S+2]<<16|d[S+3]<<24,K=d[S+4]|d[S+5]<<8|d[S+6]<<16|d[S+7]<<24,M=d[S+8]|d[S+9]<<8|d[S+10]<<16|d[S+11]<<24,T=d[S+12]|d[S+13]<<8|d[S+14]<<16|d[S+15]<<24,U=o(U,k),U=i(U,15),U=o(U,z),x^=U,x=i(x,19),x+=v,x=o(x,5)+1444728091,K=o(K,z),K=i(K,16),K=o(K,W),v^=K,v=i(v,17),v+=E,v=o(v,5)+197830471,M=o(M,W),M=i(M,17),M=o(M,$),E^=M,E=i(E,15),E+=I,E=o(E,5)+2530024501,T=o(T,$),T=i(T,18),T=o(T,k),I^=T,I=i(I,13),I+=x,I=o(I,5)+850148119;switch(U=0,K=0,M=0,T=0,y){case 15:T^=d[S+14]<<16;case 14:T^=d[S+13]<<8;case 13:T^=d[S+12],T=o(T,$),T=i(T,18),T=o(T,k),I^=T;case 12:M^=d[S+11]<<24;case 11:M^=d[S+10]<<16;case 10:M^=d[S+9]<<8;case 9:M^=d[S+8],M=o(M,W),M=i(M,17),M=o(M,$),E^=M;case 8:K^=d[S+7]<<24;case 7:K^=d[S+6]<<16;case 6:K^=d[S+5]<<8;case 5:K^=d[S+4],K=o(K,z),K=i(K,16),K=o(K,W),v^=K;case 4:U^=d[S+3]<<24;case 3:U^=d[S+2]<<16;case 2:U^=d[S+1]<<8;case 1:U^=d[S],U=o(U,k),U=i(U,15),U=o(U,z),x^=U}return x^=d.length,v^=d.length,E^=d.length,I^=d.length,x+=v,x+=E,x+=I,v+=x,E+=x,I+=x,x=s(x),v=s(v),E=s(E),I=s(I),x+=v,x+=E,x+=I,v+=x,E+=x,I+=x,("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(v>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)+("00000000"+(I>>>0).toString(16)).slice(-8)},t.x64.hash128=function(d,m){if(t.inputValidation&&!n(d))return e;m=m||0;for(var y=d.length%16,w=d.length-y,x=[0,m],v=[0,m],E=[0,0],I=[0,0],U=[2277735313,289559509],K=[1291169091,658871167],M=0;M<w;M=M+16)E=[d[M+4]|d[M+5]<<8|d[M+6]<<16|d[M+7]<<24,d[M]|d[M+1]<<8|d[M+2]<<16|d[M+3]<<24],I=[d[M+12]|d[M+13]<<8|d[M+14]<<16|d[M+15]<<24,d[M+8]|d[M+9]<<8|d[M+10]<<16|d[M+11]<<24],E=c(E,U),E=l(E,31),E=c(E,K),x=f(x,E),x=l(x,27),x=a(x,v),x=a(c(x,[0,5]),[0,1390208809]),I=c(I,K),I=l(I,33),I=c(I,U),v=f(v,I),v=l(v,31),v=a(v,x),v=a(c(v,[0,5]),[0,944331445]);switch(E=[0,0],I=[0,0],y){case 15:I=f(I,u([0,d[M+14]],48));case 14:I=f(I,u([0,d[M+13]],40));case 13:I=f(I,u([0,d[M+12]],32));case 12:I=f(I,u([0,d[M+11]],24));case 11:I=f(I,u([0,d[M+10]],16));case 10:I=f(I,u([0,d[M+9]],8));case 9:I=f(I,[0,d[M+8]]),I=c(I,K),I=l(I,33),I=c(I,U),v=f(v,I);case 8:E=f(E,u([0,d[M+7]],56));case 7:E=f(E,u([0,d[M+6]],48));case 6:E=f(E,u([0,d[M+5]],40));case 5:E=f(E,u([0,d[M+4]],32));case 4:E=f(E,u([0,d[M+3]],24));case 3:E=f(E,u([0,d[M+2]],16));case 2:E=f(E,u([0,d[M+1]],8));case 1:E=f(E,[0,d[M]]),E=c(E,U),E=l(E,31),E=c(E,K),x=f(x,E)}return x=f(x,[0,d.length]),v=f(v,[0,d.length]),x=a(x,v),v=a(v,x),x=h(x),v=h(v),x=a(x,v),v=a(v,x),("00000000"+(x[0]>>>0).toString(16)).slice(-8)+("00000000"+(x[1]>>>0).toString(16)).slice(-8)+("00000000"+(v[0]>>>0).toString(16)).slice(-8)+("00000000"+(v[1]>>>0).toString(16)).slice(-8)},typeof R0<"u"?(typeof m8<"u"&&m8.exports&&(R0=m8.exports=t),R0.murmurHash3=t):typeof define=="function"&&define.amd?define([],function(){return t}):(t._murmurHash3=r.murmurHash3,t.noConflict=function(){return r.murmurHash3=t._murmurHash3,t._murmurHash3=e,t.noConflict=e,t},r.murmurHash3=t)})(R0)});var FM=Rt((oZe,UM)=>{UM.exports=MM()});var VM=Rt((fZe,KM)=>{"use strict";KM.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,t,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,o=t;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let t=0,n,o;for(;t<this.length&&!n;)o=this.get(t),n=e(o),t++;return n?o:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(hZ,0),c=~(4294967295<<i+1),l=HM(o&c);return a+l-1}_bytePosFor(e,t){let n=Math.floor(e/7),o=n+1;for(;!t&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,o){let i=this._data,s=[t,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=t)i.push(s);else if(i[0][0]<=t)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(pZ),this._changedData=!1}bitField(){let e=[],t=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,t),l=~(255<<c),u=i&l;o|=u<<8-t,i=i>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(o),o=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(mZ)}};function hZ(r,e){return r+HM(e)}function HM(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function pZ(r,e){return r[0]-e[0]}function mZ(r){return r[1]}});var AU=Rt((Ztt,SU)=>{"use strict";SU.exports={RTLD_LAZY:1,RTLD_NOW:2,RTLD_GLOBAL:256,RTLD_LOCAL:0,RTLD_DEEPBIND:8,E2BIG:7,EACCES:13,EADDRINUSE:98,EADDRNOTAVAIL:99,EAFNOSUPPORT:97,EAGAIN:11,EALREADY:114,EBADF:9,EBADMSG:74,EBUSY:16,ECANCELED:125,ECHILD:10,ECONNABORTED:103,ECONNREFUSED:111,ECONNRESET:104,EDEADLK:35,EDESTADDRREQ:89,EDOM:33,EDQUOT:122,EEXIST:17,EFAULT:14,EFBIG:27,EHOSTUNREACH:113,EIDRM:43,EILSEQ:84,EINPROGRESS:115,EINTR:4,EINVAL:22,EIO:5,EISCONN:106,EISDIR:21,ELOOP:40,EMFILE:24,EMLINK:31,EMSGSIZE:90,EMULTIHOP:72,ENAMETOOLONG:36,ENETDOWN:100,ENETRESET:102,ENETUNREACH:101,ENFILE:23,ENOBUFS:105,ENODATA:61,ENODEV:19,ENOENT:2,ENOEXEC:8,ENOLCK:37,ENOLINK:67,ENOMEM:12,ENOMSG:42,ENOPROTOOPT:92,ENOSPC:28,ENOSR:63,ENOSTR:60,ENOSYS:38,ENOTCONN:107,ENOTDIR:20,ENOTEMPTY:39,ENOTSOCK:88,ENOTSUP:95,ENOTTY:25,ENXIO:6,EOPNOTSUPP:95,EOVERFLOW:75,EPERM:1,EPIPE:32,EPROTO:71,EPROTONOSUPPORT:93,EPROTOTYPE:91,ERANGE:34,EROFS:30,ESPIPE:29,ESRCH:3,ESTALE:116,ETIME:62,ETIMEDOUT:110,ETXTBSY:26,EWOULDBLOCK:11,EXDEV:18,PRIORITY_LOW:19,PRIORITY_BELOW_NORMAL:10,PRIORITY_NORMAL:0,PRIORITY_ABOVE_NORMAL:-7,PRIORITY_HIGH:-14,PRIORITY_HIGHEST:-20,SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGILL:4,SIGTRAP:5,SIGABRT:6,SIGIOT:6,SIGBUS:7,SIGFPE:8,SIGKILL:9,SIGUSR1:10,SIGSEGV:11,SIGUSR2:12,SIGPIPE:13,SIGALRM:14,SIGTERM:15,SIGCHLD:17,SIGSTKFLT:16,SIGCONT:18,SIGSTOP:19,SIGTSTP:20,SIGTTIN:21,SIGTTOU:22,SIGURG:23,SIGXCPU:24,SIGXFSZ:25,SIGVTALRM:26,SIGPROF:27,SIGWINCH:28,SIGIO:29,SIGPOLL:29,SIGPWR:30,SIGSYS:31,UV_FS_SYMLINK_DIR:1,UV_FS_SYMLINK_JUNCTION:2,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,UV_DIRENT_UNKNOWN:0,UV_DIRENT_FILE:1,UV_DIRENT_DIR:2,UV_DIRENT_LINK:3,UV_DIRENT_FIFO:4,UV_DIRENT_SOCKET:5,UV_DIRENT_CHAR:6,UV_DIRENT_BLOCK:7,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:64,O_EXCL:128,UV_FS_O_FILEMAP:0,O_NOCTTY:256,O_TRUNC:512,O_APPEND:1024,O_DIRECTORY:65536,O_NOATIME:262144,O_NOFOLLOW:131072,O_SYNC:1052672,O_DSYNC:4096,O_DIRECT:16384,O_NONBLOCK:2048,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_FS_COPYFILE_EXCL:1,COPYFILE_EXCL:1,UV_FS_COPYFILE_FICLONE:2,COPYFILE_FICLONE:2,UV_FS_COPYFILE_FICLONE_FORCE:4,COPYFILE_FICLONE_FORCE:4,OPENSSL_VERSION_NUMBER:810549312,SSL_OP_ALL:2147485776,SSL_OP_ALLOW_NO_DHE_KEX:1024,SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,SSL_OP_CISCO_ANYCONNECT:32768,SSL_OP_COOKIE_EXCHANGE:8192,SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,SSL_OP_LEGACY_SERVER_CONNECT:4,SSL_OP_NO_COMPRESSION:131072,SSL_OP_NO_ENCRYPT_THEN_MAC:524288,SSL_OP_NO_QUERY_MTU:4096,SSL_OP_NO_RENEGOTIATION:1073741824,SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,SSL_OP_NO_SSLv2:0,SSL_OP_NO_SSLv3:33554432,SSL_OP_NO_TICKET:16384,SSL_OP_NO_TLSv1:67108864,SSL_OP_NO_TLSv1_1:268435456,SSL_OP_NO_TLSv1_2:134217728,SSL_OP_NO_TLSv1_3:536870912,SSL_OP_PRIORITIZE_CHACHA:2097152,SSL_OP_TLS_ROLLBACK_BUG:8388608,ENGINE_METHOD_RSA:1,ENGINE_METHOD_DSA:2,ENGINE_METHOD_DH:4,ENGINE_METHOD_RAND:8,ENGINE_METHOD_EC:2048,ENGINE_METHOD_CIPHERS:64,ENGINE_METHOD_DIGESTS:128,ENGINE_METHOD_PKEY_METHS:512,ENGINE_METHOD_PKEY_ASN1_METHS:1024,ENGINE_METHOD_ALL:65535,ENGINE_METHOD_NONE:0,DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,RSA_PKCS1_PADDING:1,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,RSA_PSS_SALTLEN_DIGEST:-1,RSA_PSS_SALTLEN_MAX_SIGN:-2,RSA_PSS_SALTLEN_AUTO:-2,defaultCoreCipherList:"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA",TLS1_VERSION:769,TLS1_1_VERSION:770,TLS1_2_VERSION:771,TLS1_3_VERSION:772,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}});var PU=Rt(US=>{US.read=function(r,e,t,n,o){var i,s,a=o*8-n-1,c=(1<<a)-1,l=c>>1,u=-7,f=t?o-1:0,h=t?-1:1,d=r[e+f];for(f+=h,i=d&(1<<-u)-1,d>>=-u,u+=a;u>0;i=i*256+r[e+f],f+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=n;u>0;s=s*256+r[e+f],f+=h,u-=8);if(i===0)i=1-l;else{if(i===c)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-l}return(d?-1:1)*s*Math.pow(2,i-n)};US.write=function(r,e,t,n,o,i){var s,a,c,l=i*8-o-1,u=(1<<l)-1,f=u>>1,h=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:i-1,m=n?1:-1,y=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=u):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+f>=1?e+=h/c:e+=h*Math.pow(2,1-f),e*c>=2&&(s++,c/=2),s+f>=u?(a=0,s=u):s+f>=1?(a=(e*c-1)*Math.pow(2,o),s=s+f):(a=e*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;r[t+d]=a&255,d+=m,a/=256,o-=8);for(s=s<<o|a,l+=o;l>0;r[t+d]=s&255,d+=m,s/=256,l-=8);r[t+d-m]|=y*128}});var HU=Rt((Hnt,$U)=>{var Eh=1e3,Sh=Eh*60,Ah=Sh*60,$u=Ah*24,kJ=$u*7,PJ=$u*365.25;$U.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return RJ(r);if(t==="number"&&isFinite(r))return e.long?DJ(r):OJ(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function RJ(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*PJ;case"weeks":case"week":case"w":return t*kJ;case"days":case"day":case"d":return t*$u;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Ah;case"minutes":case"minute":case"mins":case"min":case"m":return t*Sh;case"seconds":case"second":case"secs":case"sec":case"s":return t*Eh;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function OJ(r){var e=Math.abs(r);return e>=$u?Math.round(r/$u)+"d":e>=Ah?Math.round(r/Ah)+"h":e>=Sh?Math.round(r/Sh)+"m":e>=Eh?Math.round(r/Eh)+"s":r+"ms"}function DJ(r){var e=Math.abs(r);return e>=$u?K8(r,e,$u,"day"):e>=Ah?K8(r,e,Ah,"hour"):e>=Sh?K8(r,e,Sh,"minute"):e>=Eh?K8(r,e,Eh,"second"):r+" ms"}function K8(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var VU=Rt((Knt,KU)=>{function NJ(r){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=o,t.enabled=a,t.humanize=HU(),t.destroy=l,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let f=0;for(let h=0;h<u.length;h++)f=(f<<5)-f+u.charCodeAt(h),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(u){let f,h=null,d,m;function y(...w){if(!y.enabled)return;let x=y,v=Number(new Date),E=v-(f||v);x.diff=E,x.prev=f,x.curr=v,f=v,w[0]=t.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let I=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(K,M)=>{if(K==="%%")return"%";I++;let T=t.formatters[M];if(typeof T=="function"){let k=w[I];K=T.call(x,k),w.splice(I,1),I--}return K}),t.formatArgs.call(x,w),(x.log||t.log).apply(x,w)}return y.namespace=u,y.useColors=t.useColors(),y.color=t.selectColor(u),y.extend=n,y.destroy=t.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(d!==t.namespaces&&(d=t.namespaces,m=t.enabled(u)),m),set:w=>{h=w}}),typeof t.init=="function"&&t.init(y),y}function n(u,f){let h=t(this.namespace+(typeof f>"u"?":":f)+u);return h.log=this.log,h}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let f=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let h of f)h[0]==="-"?t.skips.push(h.slice(1)):t.names.push(h)}function i(u,f){let h=0,d=0,m=-1,y=0;for(;h<u.length;)if(d<f.length&&(f[d]===u[h]||f[d]==="*"))f[d]==="*"?(m=d,y=h,d++):(h++,d++);else if(m!==-1)d=m+1,y++,h=y;else return!1;for(;d<f.length&&f[d]==="*";)d++;return d===f.length}function s(){let u=[...t.names,...t.skips.map(f=>"-"+f)].join(",");return t.enable(""),u}function a(u){for(let f of t.skips)if(i(u,f))return!1;for(let f of t.names)if(i(u,f))return!0;return!1}function c(u){return u instanceof Error?u.stack||u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}KU.exports=NJ});var qU=Rt((Vn,V8)=>{Vn.formatArgs=BJ;Vn.save=MJ;Vn.load=UJ;Vn.useColors=LJ;Vn.storage=FJ();Vn.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();Vn.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function LJ(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let r;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(r[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function BJ(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+V8.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}Vn.log=console.debug||console.log||(()=>{});function MJ(r){try{r?Vn.storage.setItem("debug",r):Vn.storage.removeItem("debug")}catch{}}function UJ(){let r;try{r=Vn.storage.getItem("debug")||Vn.storage.getItem("DEBUG")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function FJ(){try{return localStorage}catch{}}V8.exports=VU()(Vn);var{formatters:$J}=V8.exports;$J.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var ree={};Lt(ree,{BasePlugin:()=>on,MEDIA_TYPE_CAR:()=>Ou,MEDIA_TYPE_CBOR:()=>xo,MEDIA_TYPE_DAG_CBOR:()=>wo,MEDIA_TYPE_DAG_JSON:()=>bo,MEDIA_TYPE_DAG_PB:()=>D0,MEDIA_TYPE_IPNS_RECORD:()=>Ru,MEDIA_TYPE_JSON:()=>vo,MEDIA_TYPE_OCTET_STREAM:()=>Cr,MEDIA_TYPE_RAW:()=>Vr,MEDIA_TYPE_TAR:()=>wh,createVerifiedFetch:()=>XS,verifiedFetch:()=>j8});var rA=Symbol.for("@libp2p/connection");var hs=Symbol.for("@libp2p/content-routing");var sn=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}},V0=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},q0=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},D=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ps=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Ch=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}},Ih=class extends Error{static name="UnsupportedOperationError";constructor(e="Unsupported operation"){super(e),this.name="UnsupportedOperationError"}};var Oc=class extends Error{static name="ConnectionClosedError";constructor(e="The connection is closed"){super(e),this.name="ConnectionClosedError"}},Vu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},Qo=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},qu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Ci=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},kh=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},Ye=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}},zu=class extends Error{static name="InvalidPeerIdError";constructor(e="Invalid PeerID"){super(e),this.name="InvalidPeerIdError"}},Ii=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},z0=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},pa=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}},ju=class extends Error{static name="UnsupportedProtocolError";constructor(e="Unsupported protocol error"){super(e),this.name="UnsupportedProtocolError"}},Le=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}},Dc=class extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}},ki=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},qn=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ma=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}},Nc=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}},Ph=class extends Error{static name="LimitedConnectionError";constructor(e="Limited connection"){super(e),this.name="LimitedConnectionError"}},j0=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(e="Too many inbound protocol streams"){super(e),this.name="TooManyInboundProtocolStreamsError"}},Wu=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(e="Too many outbound protocol streams"){super(e),this.name="TooManyOutboundProtocolStreamsError"}},Zo=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var W0=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ga=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},G0=class extends ga{constructor(e,t){super(!0,e,t)}},X0=class extends ga{constructor(e,t){super(!1,e,t)}};function Y0(r){return r==null?!1:(r.type==="RSA"||r.type==="Ed25519"||r.type==="secp256k1"||r.type==="ECDSA")&&r.raw instanceof Uint8Array&&typeof r.equals=="function"&&typeof r.toMultihash=="function"&&typeof r.toCID=="function"&&typeof r.verify=="function"}var Lc=Symbol.for("@libp2p/peer-discovery");var Q0=Symbol.for("@libp2p/peer-id");function mr(r){return!!r?.[Q0]}var ms=Symbol.for("@libp2p/peer-routing");var Bc="keep-alive";function Z0(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function cr(...r){let e=[];for(let t of r)Z0(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function gr(...r){let e=[];for(let t of r)Z0(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var ya=Symbol.for("@libp2p/transport");var Rh;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Rh||(Rh={}));var _e=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(e){let t=this.#t.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#t.get(e);o==null&&(o=[],this.#t.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#t.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#t.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#t.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var qe=Symbol.for("@libp2p/service-capabilities"),zn=Symbol.for("@libp2p/service-dependencies");function Re(r){let e=new globalThis.AbortController;function t(){let i=r.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Y=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Oh=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Dh=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},J0=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var nA={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new J0("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Qt=nA;var rw={};Lt(rw,{base58btc:()=>Qe,base58flickr:()=>OF});var Mc={};Lt(Mc,{coerce:()=>_o,empty:()=>oA,equals:()=>X8,fromHex:()=>AF,fromString:()=>Y8,isBinary:()=>_F,toHex:()=>SF,toString:()=>Q8});var oA=new Uint8Array(0);function SF(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function AF(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):oA}function X8(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function _o(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function _F(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function Y8(r){return new TextEncoder().encode(r)}function Q8(r){return new TextDecoder().decode(r)}function TF(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,w=0,x=0,v=m.length;x!==v&&m[x]===0;)x++,y++;for(var E=(v-x)*u+1>>>0,I=new Uint8Array(E);x!==v;){for(var U=m[x],K=0,M=E-1;(U!==0||K<w)&&M!==-1;M--,K++)U+=256*I[M]>>>0,I[M]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");w=K,x++}for(var T=E-w;T!==E&&I[T]===0;)T++;for(var k=c.repeat(y);T<E;++T)k+=r.charAt(I[T]);return k}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var w=0,x=0;m[y]===c;)w++,y++;for(var v=(m.length-y)*l+1>>>0,E=new Uint8Array(v);m[y];){var I=t[m.charCodeAt(y)];if(I===255)return;for(var U=0,K=v-1;(I!==0||U<x)&&K!==-1;K--,U++)I+=a*E[K]>>>0,E[K]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=U,y++}if(m[y]!==" "){for(var M=v-x;M!==v&&E[M]===0;)M++;for(var T=new Uint8Array(w+(v-M)),k=w;M!==v;)T[k++]=E[M++];return T}}}function d(m){var y=h(m);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:d}}var CF=TF,IF=CF,iA=IF;var Z8=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},J8=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return sA(this,e)}},ew=class{decoders;constructor(e){this.decoders=e}or(e){return sA(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function sA(r,e){return new ew({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var tw=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Z8(e,t,n),this.decoder=new J8(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Gu({name:r,prefix:e,encode:t,decode:n}){return new tw(r,e,t,n)}function wa({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=iA(t,r);return Gu({prefix:e,name:r,encode:n,decode:i=>_o(o(i))})}function kF(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let u=e[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function PF(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function RF(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Ht({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=RF(n);return Gu({prefix:e,name:r,encode(i){return PF(i,n,t)},decode(i){return kF(i,o,t,r)}})}var Qe=wa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),OF=wa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var nw={};Lt(nw,{base32:()=>yr,base32hex:()=>BF,base32hexpad:()=>UF,base32hexpadupper:()=>FF,base32hexupper:()=>MF,base32pad:()=>NF,base32padupper:()=>LF,base32upper:()=>DF,base32z:()=>$F});var yr=Ht({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),DF=Ht({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),NF=Ht({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),LF=Ht({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),BF=Ht({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),MF=Ht({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),UF=Ht({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),FF=Ht({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$F=Ht({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ow={};Lt(ow,{base36:()=>an,base36upper:()=>HF});var an=wa({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),HF=wa({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var yt={};Lt(yt,{Digest:()=>Uc,create:()=>cn,decode:()=>ze,equals:()=>sw,hasCode:()=>s$});var KF=lA,aA=128,VF=127,qF=~VF,zF=Math.pow(2,31);function lA(r,e,t){e=e||[],t=t||0;for(var n=t;r>=zF;)e[t++]=r&255|aA,r/=128;for(;r&qF;)e[t++]=r&255|aA,r>>>=7;return e[t]=r|0,lA.bytes=t-n+1,e}var jF=iw,WF=128,cA=127;function iw(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw iw.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&cA)<<o:(s&cA)*Math.pow(2,o),o+=7}while(s>=WF);return iw.bytes=i-n,t}var GF=Math.pow(2,7),XF=Math.pow(2,14),YF=Math.pow(2,21),QF=Math.pow(2,28),ZF=Math.pow(2,35),JF=Math.pow(2,42),e$=Math.pow(2,49),t$=Math.pow(2,56),r$=Math.pow(2,63),n$=function(r){return r<GF?1:r<XF?2:r<YF?3:r<QF?4:r<ZF?5:r<JF?6:r<e$?7:r<t$?8:r<r$?9:10},o$={encode:KF,decode:jF,encodingLength:n$},i$=o$,Nh=i$;function Lh(r,e=0){return[Nh.decode(r,e),Nh.decode.bytes]}function Xu(r,e,t=0){return Nh.encode(r,e,t),e}function Yu(r){return Nh.encodingLength(r)}function cn(r,e){let t=e.byteLength,n=Yu(r),o=n+Yu(t),i=new Uint8Array(o+t);return Xu(r,i,0),Xu(t,i,n),i.set(e,o),new Uc(r,t,e,i)}function ze(r){let e=_o(r),[t,n]=Lh(e),[o,i]=Lh(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Uc(t,o,s,e)}function sw(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&X8(r.bytes,t.bytes)}}var Uc=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function s$(r,e){return r.code===e}function uA(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return c$(t,aw(r),e??Qe.encoder);default:return l$(t,aw(r),e??yr.encoder)}}var fA=new WeakMap;function aw(r){let e=fA.get(r);if(e==null){let t=new Map;return fA.set(r,t),t}return e}var Z=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Bh)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==u$)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=cn(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&sw(e.multihash,n.multihash)}toString(e){return uA(this,e)}toJSON(){return{"/":uA(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??dA(n,o,i.bytes))}else if(t[f$]===!0){let{version:n,multihash:o,code:i}=t,s=ze(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Bh)throw new Error(`Version 0 CID must use dag-pb (code: ${Bh}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=dA(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Bh,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=_o(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Uc(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,h]=Lh(e.subarray(t));return t+=h,f},o=n(),i=Bh;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),l=t+c,u=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=a$(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return aw(i).set(n,e),i}};function a$(r,e){switch(r[0]){case"Q":{let t=e??Qe;return[Qe.prefix,t.decode(`${Qe.prefix}${r}`)]}case Qe.prefix:{let t=e??Qe;return[Qe.prefix,t.decode(r)]}case yr.prefix:{let t=e??yr;return[yr.prefix,t.decode(r)]}case an.prefix:{let t=e??an;return[an.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function c$(r,e,t){let{prefix:n}=t;if(n!==Qe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function l$(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var Bh=112,u$=18;function dA(r,e,t){let n=Yu(r),o=n+Yu(e),i=new Uint8Array(o+t.byteLength);return Xu(r,i,0),Xu(e,i,n),i.set(t,o),i}var f$=Symbol.for("@ipld/js-cid/CID");var cw={};Lt(cw,{identity:()=>Ot});var hA=0,d$="identity",pA=_o;function h$(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return cn(hA,pA(r))}var Ot={code:hA,name:d$,encode:pA,digest:h$};function me(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Ie(r=0){return new Uint8Array(r)}function Bt(r=0){return new Uint8Array(r)}function dt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=Bt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var gA=Symbol.for("@achingbrain/uint8arraylist");function mA(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function To(r){return!!r?.[gA]}var se=class r{bufs;length;[gA]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(To(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(To(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=mA(this.bufs,e);return t.buf[t.index]}set(e,t){let n=mA(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(To(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return dt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:dt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,u=t>a&&t<=c;if(l&&u){if(e===a&&t===c){n.push(s);break}let f=e-a;n.push(s.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!To(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=t;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let d=this.get(f+h);if(n[h]!==d){u=Math.max(1,h-a[d]);break}}if(u===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=Ie(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=Ie(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=Ie(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=Ie(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=Ie(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=Ie(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=Ie(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=Ie(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!me(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var lw={};Lt(lw,{base10:()=>m$});var m$=wa({prefix:"9",name:"base10",alphabet:"0123456789"});var uw={};Lt(uw,{base16:()=>g$,base16upper:()=>y$});var g$=Ht({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),y$=Ht({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var fw={};Lt(fw,{base2:()=>w$});var w$=Ht({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dw={};Lt(dw,{base256emoji:()=>S$});var yA=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),x$=yA.reduce((r,e,t)=>(r[t]=e,r),[]),b$=yA.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function v$(r){return r.reduce((e,t)=>(e+=x$[t],e),"")}function E$(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=b$[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var S$=Gu({prefix:"\u{1F680}",name:"base256emoji",encode:v$,decode:E$});var hw={};Lt(hw,{base64:()=>Zt,base64pad:()=>Mh,base64url:()=>Fc,base64urlpad:()=>A$});var Zt=Ht({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mh=Ht({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fc=Ht({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),A$=Ht({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pw={};Lt(pw,{base8:()=>_$});var _$=Ht({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mw={};Lt(mw,{identity:()=>T$});var T$=Gu({prefix:"\0",name:"identity",encode:r=>Q8(r),decode:r=>Y8(r)});var Pi={};Lt(Pi,{code:()=>lr,decode:()=>xa,encode:()=>P$,name:()=>k$});var C$=new TextEncoder,I$=new TextDecoder,k$="json",lr=512;function P$(r){return C$.encode(JSON.stringify(r))}function xa(r){return JSON.parse(I$.decode(r))}var Co={};Lt(Co,{code:()=>ct,decode:()=>D$,encode:()=>O$,name:()=>R$});var R$="raw",ct=85;function O$(r){return _o(r)}function D$(r){return _o(r)}var yw={};Lt(yw,{sha256:()=>At,sha512:()=>tg});var N$=20;function gs({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new gw(r,e,t,n,o)}var gw=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??N$,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?wA(n,this.code,t?.truncate):n.then(o=>wA(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function wA(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return cn(e,r)}function bA(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var At=gs({name:"sha2-256",code:18,encode:bA("SHA-256")}),tg=gs({name:"sha2-512",code:19,encode:bA("SHA-512")});var $c={...mw,...fw,...pw,...lw,...uw,...nw,...ow,...rw,...hw,...dw},$te={...yw,...cw};function EA(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var vA=EA("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ww=EA("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Bt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),L$={utf8:vA,"utf-8":vA,hex:$c.base16,latin1:ww,ascii:ww,binary:ww,...$c},rg=L$;function O(r,e="utf8"){let t=rg[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function H(r,e="utf8"){let t=rg[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var B$=parseInt("11111",2),xw=parseInt("10000000",2),M$=parseInt("01111111",2),SA={0:Uh,1:Uh,2:U$,3:H$,4:K$,5:$$,6:F$,16:Uh,22:Uh,48:Uh};function Io(r,e={offset:0}){let t=r[e.offset]&B$;if(e.offset++,SA[t]!=null)return SA[t](r,e);throw new Error("No decoder for tag "+t)}function Fh(r,e){let t=0;if((r[e.offset]&xw)===xw){let n=r[e.offset]&M$,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function Uh(r,e){Fh(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=Io(r,e);if(n===null)break;t.push(n)}return t}function U$(r,e){let t=Fh(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function F$(r,e){let t=Fh(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function $$(r,e){return e.offset++,null}function H$(r,e){let t=Fh(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function K$(r,e){let t=Fh(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function V$(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new se;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function ng(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=V$(r.byteLength);return new se(Uint8Array.from([e.byteLength|xw]),e)}function ln(r){let e=new se,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new se(Uint8Array.from([2]),ng(e),e)}function $h(r){let e=Uint8Array.from([0]),t=new se(e,r);return new se(Uint8Array.from([3]),ng(t),t)}function AA(r){return new se(Uint8Array.from([4]),ng(r),r)}function Jo(r,e=48){let t=new se;for(let n of r)t.append(n);return new se(Uint8Array.from([e]),ng(t),t)}var _A="1.2.840.10045.3.1.7",TA="1.3.132.0.34",CA="1.3.132.0.35";async function IA(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function kA(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function PA(r,e,t,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,t.subarray());return n?.signal?.throwIfAborted(),i}var q$=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),z$=Uint8Array.from([6,5,43,129,4,0,34]),j$=Uint8Array.from([6,5,43,129,4,0,35]),RA={ext:!0,kty:"EC",crv:"P-256"},OA={ext:!0,kty:"EC",crv:"P-384"},DA={ext:!0,kty:"EC",crv:"P-521"},Qu=32,Zu=48,Ju=66;function NA(r){let e=Io(r);return bw(e)}function bw(r){let e=r[1],t=H(e,"base64url"),n=r[2][1][0],o=1,i,s;if(e.byteLength===Qu)return i=H(n.subarray(o,o+Qu),"base64url"),s=H(n.subarray(o+Qu),"base64url"),new Kc({...RA,key_ops:["sign"],d:t,x:i,y:s});if(e.byteLength===Zu)return i=H(n.subarray(o,o+Zu),"base64url"),s=H(n.subarray(o+Zu),"base64url"),new Kc({...OA,key_ops:["sign"],d:t,x:i,y:s});if(e.byteLength===Ju)return i=H(n.subarray(o,o+Ju),"base64url"),s=H(n.subarray(o+Ju),"base64url"),new Kc({...DA,key_ops:["sign"],d:t,x:i,y:s});throw new D(`Private key length was wrong length, got ${e.byteLength}, expected 32, 48 or 66`)}function vw(r){let e=Io(r);return LA(e)}function LA(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Qu*2+1)return n=H(e.subarray(t,t+Qu),"base64url"),o=H(e.subarray(t+Qu),"base64url"),new Hc({...RA,key_ops:["verify"],x:n,y:o});if(e.byteLength===Zu*2+1)return n=H(e.subarray(t,t+Zu),"base64url"),o=H(e.subarray(t+Zu),"base64url"),new Hc({...OA,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ju*2+1)return n=H(e.subarray(t,t+Ju),"base64url"),o=H(e.subarray(t+Ju),"base64url"),new Hc({...DA,key_ops:["verify"],x:n,y:o});throw new D(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function BA(r){return Jo([ln(Uint8Array.from([1])),AA(O(r.d??"","base64url")),Jo([UA(r.crv)],160),Jo([$h(new se(Uint8Array.from([4]),O(r.x??"","base64url"),O(r.y??"","base64url")))],161)]).subarray()}function MA(r){return Jo([ln(Uint8Array.from([1])),Jo([UA(r.crv)],160),Jo([$h(new se(Uint8Array.from([4]),O(r.x??"","base64url"),O(r.y??"","base64url")))],161)]).subarray()}function UA(r){if(r==="P-256")return q$;if(r==="P-384")return z$;if(r==="P-521")return j$;throw new D(`Invalid curve ${r}`)}async function FA(r="P-256"){let e=await IA(r);return new Kc(e.privateKey)}var Hc=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=MA(this.jwk)),this._raw}toMultihash(){return Ot.digest(wr(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}async verify(e,t,n){return PA(this.jwk,t,e,n)}},Kc=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Hc({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=BA(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}async sign(e,t){return kA(this.jwk,e,t)}};function Vc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function qr(r,e=""){if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new Error(`${t}expected integer >= 0, got ${r}`)}}function ke(r,e,t=""){let n=Vc(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function ws(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");qr(r.outputLen),qr(r.blockLen)}function ef(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function HA(r,e){ke(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new Error('"digestInto() output" expected to be of length >='+t)}function zr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function qc(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function ei(r,e){return r<<32-e|r>>>e}function og(r,e){return r<<e|r>>>32-e>>>0}var KA=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",W$=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function xs(r){if(ke(r),KA)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=W$[r[t]];return e}var ys={_0:48,_9:57,A:65,F:70,a:97,f:102};function $A(r){if(r>=ys._0&&r<=ys._9)return r-ys._0;if(r>=ys.A&&r<=ys.F)return r-(ys.A-10);if(r>=ys.a&&r<=ys.f)return r-(ys.a-10)}function bs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(KA)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=$A(r.charCodeAt(i)),a=$A(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}var G$=async()=>{};async function VA(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await G$(),n+=i)}}function X$(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ew(r,e=""){return typeof r=="string"?X$(r):ke(r,void 0,e)}function Sn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ke(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}function qA(r,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options must be object or undefined");return Object.assign(r,e)}function Hh(r,e={}){let t=(o,i)=>r(i).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function Ri(r=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(r))}var Sw=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ig(r,e,t){return r&e^~r&t}function sg(r,e,t){return r&e^r&t^e&t}var zc=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=qc(this.buffer)}update(e){ef(this),ke(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=qc(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ef(this),HA(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,zr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=qc(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},vs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ir=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ag=BigInt(4294967295),zA=BigInt(32);function Y$(r,e=!1){return e?{h:Number(r&ag),l:Number(r>>zA&ag)}:{h:Number(r>>zA&ag)|0,l:Number(r&ag)|0}}function jA(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let i=0;i<t;i++){let{h:s,l:a}=Y$(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Aw=(r,e,t)=>r>>>t,_w=(r,e,t)=>r<<32-t|e>>>t,jc=(r,e,t)=>r>>>t|e<<32-t,Wc=(r,e,t)=>r<<32-t|e>>>t,Kh=(r,e,t)=>r<<64-t|e>>>t-32,Vh=(r,e,t)=>r>>>t-32|e<<64-t;function Oi(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var WA=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),GA=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,XA=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),YA=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,QA=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),ZA=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var Z$=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]),ba=new Uint32Array(64),Tw=class extends zc{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)ba[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=ba[f-15],d=ba[f-2],m=ei(h,7)^ei(h,18)^h>>>3,y=ei(d,17)^ei(d,19)^d>>>10;ba[f]=y+ba[f-7]+m+ba[f-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=ei(a,6)^ei(a,11)^ei(a,25),d=u+h+ig(a,c,l)+Z$[f]+ba[f]|0,y=(ei(n,2)^ei(n,13)^ei(n,22))+sg(n,o,i)|0;u=l,l=c,c=a,a=s+d|0,s=i,i=o,o=n,n=d+y|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,l,u)}roundClean(){zr(ba)}destroy(){this.set(0,0,0,0,0,0,0,0),zr(this.buffer)}},Cw=class extends Tw{A=vs[0]|0;B=vs[1]|0;C=vs[2]|0;D=vs[3]|0;E=vs[4]|0;F=vs[5]|0;G=vs[6]|0;H=vs[7]|0;constructor(){super(32)}};var JA=jA(["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(r=>BigInt(r))),J$=JA[0],eH=JA[1],va=new Uint32Array(80),Ea=new Uint32Array(80),Iw=class extends zc{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:d,Gl:m,Hh:y,Hl:w}=this;return[e,t,n,o,i,s,a,c,l,u,f,h,d,m,y,w]}set(e,t,n,o,i,s,a,c,l,u,f,h,d,m,y,w){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=y|0,this.Hl=w|0}process(e,t){for(let E=0;E<16;E++,t+=4)va[E]=e.getUint32(t),Ea[E]=e.getUint32(t+=4);for(let E=16;E<80;E++){let I=va[E-15]|0,U=Ea[E-15]|0,K=jc(I,U,1)^jc(I,U,8)^Aw(I,U,7),M=Wc(I,U,1)^Wc(I,U,8)^_w(I,U,7),T=va[E-2]|0,k=Ea[E-2]|0,z=jc(T,k,19)^Kh(T,k,61)^Aw(T,k,6),W=Wc(T,k,19)^Vh(T,k,61)^_w(T,k,6),$=XA(M,W,Ea[E-7],Ea[E-16]),S=YA($,K,z,va[E-7],va[E-16]);va[E]=S|0,Ea[E]=$|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:d,Fl:m,Gh:y,Gl:w,Hh:x,Hl:v}=this;for(let E=0;E<80;E++){let I=jc(f,h,14)^jc(f,h,18)^Kh(f,h,41),U=Wc(f,h,14)^Wc(f,h,18)^Vh(f,h,41),K=f&d^~f&y,M=h&m^~h&w,T=QA(v,U,M,eH[E],Ea[E]),k=ZA(T,x,I,K,J$[E],va[E]),z=T|0,W=jc(n,o,28)^Kh(n,o,34)^Kh(n,o,39),$=Wc(n,o,28)^Vh(n,o,34)^Vh(n,o,39),S=n&i^n&a^i&a,C=o&s^o&c^s&c;x=y|0,v=w|0,y=d|0,w=m|0,d=f|0,m=h|0,{h:f,l:h}=Oi(l|0,u|0,k|0,z|0),l=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let _=WA(z,$,C);n=GA(_,k,W,S),o=_|0}({h:n,l:o}=Oi(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Oi(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Oi(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Oi(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=Oi(this.Eh|0,this.El|0,f|0,h|0),{h:d,l:m}=Oi(this.Fh|0,this.Fl|0,d|0,m|0),{h:y,l:w}=Oi(this.Gh|0,this.Gl|0,y|0,w|0),{h:x,l:v}=Oi(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,i,s,a,c,l,u,f,h,d,m,y,w,x,v)}roundClean(){zr(va,Ea)}destroy(){zr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},kw=class extends Iw{Ah=Ir[0]|0;Al=Ir[1]|0;Bh=Ir[2]|0;Bl=Ir[3]|0;Ch=Ir[4]|0;Cl=Ir[5]|0;Dh=Ir[6]|0;Dl=Ir[7]|0;Eh=Ir[8]|0;El=Ir[9]|0;Fh=Ir[10]|0;Fl=Ir[11]|0;Gh=Ir[12]|0;Gl=Ir[13]|0;Hh=Ir[14]|0;Hl=Ir[15]|0;constructor(){super(64)}};var ko=Hh(()=>new Cw,Sw(1));var Sa=Hh(()=>new kw,Sw(3));var Rw=BigInt(0),Pw=BigInt(1);function Es(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}" `;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function e_(r){if(typeof r=="bigint"){if(!cg(r))throw new Error("positive bigint expected, got "+r)}else qr(r);return r}function qh(r){let e=e_(r).toString(16);return e.length&1?"0"+e:e}function t_(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Rw:BigInt("0x"+r)}function tf(r){return t_(xs(r))}function Di(r){return t_(xs(Gc(ke(r)).reverse()))}function lg(r,e){qr(e),r=e_(r);let t=bs(r.toString(16).padStart(e*2,"0"));if(t.length!==e)throw new Error("number too large");return t}function zh(r,e){return lg(r,e).reverse()}function Gc(r){return Uint8Array.from(r)}var cg=r=>typeof r=="bigint"&&Rw<=r;function tH(r,e,t){return cg(r)&&cg(e)&&cg(t)&&e<=r&&r<t}function Aa(r,e,t,n){if(!tH(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Ow(r){let e;for(e=0;r>Rw;r>>=Pw,e+=1);return e}var jh=r=>(Pw<<BigInt(r))-Pw;function r_(r,e,t){if(qr(r,"hashLen"),qr(e,"qByteLen"),typeof t!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(r),l=n(r),u=0,f=()=>{c.fill(1),l.fill(0),u=0},h=(...w)=>t(l,Sn(c,...w)),d=(w=o)=>{l=h(i,w),c=h(),w.length!==0&&(l=h(s,w),c=h())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,x=[];for(;w<e;){c=h();let v=c.slice();x.push(v),w+=c.length}return Sn(...x)};return(w,x)=>{f(),d(w);let v;for(;!(v=x(m()));)d();return f(),v}}function Ni(r,e={},t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,s,a){let c=r[i];if(a&&c===void 0)return;let l=typeof c;if(l!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${l}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(t,!0)}function rf(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var un=BigInt(0),xr=BigInt(1),Xc=BigInt(2),i_=BigInt(3),s_=BigInt(4),a_=BigInt(5),rH=BigInt(7),c_=BigInt(8),nH=BigInt(9),l_=BigInt(16);function Dt(r,e){let t=r%e;return t>=un?t:e+t}function _t(r,e,t){let n=r;for(;e-- >un;)n*=n,n%=t;return n}function n_(r,e){if(r===un)throw new Error("invert: expected non-zero number");if(e<=un)throw new Error("invert: expected positive modulus, got "+e);let t=Dt(r,e),n=e,o=un,i=xr,s=xr,a=un;for(;t!==un;){let l=n/t,u=n%t,f=o-s*l,h=i-a*l;n=t,t=u,o=s,i=a,s=f,a=h}if(n!==xr)throw new Error("invert: does not exist");return Dt(o,e)}function Nw(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function u_(r,e){let t=(r.ORDER+xr)/s_,n=r.pow(e,t);return Nw(r,n,e),n}function oH(r,e){let t=(r.ORDER-a_)/c_,n=r.mul(e,Xc),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Xc),o),a=r.mul(i,r.sub(s,r.ONE));return Nw(r,a,e),a}function iH(r){let e=nf(r),t=f_(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+rH)/l_;return(a,c)=>{let l=a.pow(c,s),u=a.mul(l,n),f=a.mul(l,o),h=a.mul(l,i),d=a.eql(a.sqr(u),c),m=a.eql(a.sqr(f),c);l=a.cmov(l,u,d),u=a.cmov(h,f,m);let y=a.eql(a.sqr(u),c),w=a.cmov(l,u,y);return Nw(a,w,c),w}}function f_(r){if(r<i_)throw new Error("sqrt is not defined for small field");let e=r-xr,t=0;for(;e%Xc===un;)e/=Xc,t++;let n=Xc,o=nf(r);for(;o_(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return u_;let i=o.pow(n,e),s=(e+xr)/Xc;return function(c,l){if(c.is0(l))return l;if(o_(c,l)!==1)throw new Error("Cannot find square root");let u=t,f=c.mul(c.ONE,i),h=c.pow(l,e),d=c.pow(l,s);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let m=1,y=c.sqr(h);for(;!c.eql(y,c.ONE);)if(m++,y=c.sqr(y),m===u)throw new Error("Cannot find square root");let w=xr<<BigInt(u-m-1),x=c.pow(f,w);u=m,f=c.sqr(x),h=c.mul(h,f),d=c.mul(d,x)}return d}}function sH(r){return r%s_===i_?u_:r%c_===a_?oH:r%l_===nH?iH(r):f_(r)}var d_=(r,e)=>(Dt(r,e)&xr)===xr,aH=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Lw(r){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},t=aH.reduce((n,o)=>(n[o]="function",n),e);return Ni(r,t),r}function cH(r,e,t){if(t<un)throw new Error("invalid exponent, negatives unsupported");if(t===un)return r.ONE;if(t===xr)return e;let n=r.ONE,o=e;for(;t>un;)t&xr&&(n=r.mul(n,o)),o=r.sqr(o),t>>=xr;return n}function Wh(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function o_(r,e){let t=(r.ORDER-xr)/Xc,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function lH(r,e){e!==void 0&&qr(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}var Dw=class{ORDER;BITS;BYTES;isLE;ZERO=un;ONE=xr;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=un)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&(this.sqrt=t.sqrt),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:i}=lH(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Dt(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return un<=e&&e<this.ORDER}is0(e){return e===un}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&xr)===xr}neg(e){return Dt(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return Dt(e*e,this.ORDER)}add(e,t){return Dt(e+t,this.ORDER)}sub(e,t){return Dt(e-t,this.ORDER)}mul(e,t){return Dt(e*t,this.ORDER)}pow(e,t){return cH(this,e,t)}div(e,t){return Dt(e*n_(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return n_(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=sH(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?zh(e,this.BYTES):lg(e,this.BYTES)}fromBytes(e,t=!1){ke(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let l=new Uint8Array(o);l.set(e,i?0:l.length-e.length),e=l}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Di(e):tf(e);if(a&&(c=Dt(c,s)),!t&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Wh(this,e)}cmov(e,t,n){return n?t:e}};function nf(r,e={}){return new Dw(r,e)}function h_(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Bw(r){let e=h_(r);return e+Math.ceil(e/2)}function Mw(r,e,t=!1){ke(r);let n=r.length,o=h_(e),i=Bw(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Di(r):tf(r),a=Dt(s,e-xr)+xr;return t?zh(a,o):lg(a,o)}var of=BigInt(0),Yc=BigInt(1);function Gh(r,e){let t=e.negate();return r?t:e}function Qc(r,e){let t=Wh(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function y_(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function Uw(r,e){y_(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=jh(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function p_(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=Yc);let l=e*n,u=l+Math.abs(a)-1,f=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:d,offsetF:l}}var Fw=new WeakMap,w_=new WeakMap;function $w(r){return w_.get(r)||1}function m_(r){if(r!==of)throw new Error("invalid wNAF")}var sf=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>of;)t&Yc&&(n=n.add(o)),o=o.double(),t>>=Yc;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=Uw(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let l=1;l<o;l++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Uw(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:l,isZero:u,isNeg:f,isNegF:h,offsetF:d}=p_(n,a,s);n=c,u?i=i.add(Gh(h,t[d])):o=o.add(Gh(f,t[l]))}return m_(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=Uw(e,this.bits);for(let s=0;s<i.windows&&n!==of;s++){let{nextN:a,offset:c,isZero:l,isNeg:u}=p_(n,s,i);if(n=a,!l){let f=t[c];o=o.add(u?f.negate():f)}}return m_(n),o}getPrecomputes(e,t,n){let o=Fw.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),Fw.set(t,o))),o}cached(e,t,n){let o=$w(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=$w(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){y_(t,this.bits),w_.set(e,t),Fw.delete(e)}hasCache(e){return $w(e)!==1}};function x_(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>of||n>of;)t&Yc&&(i=i.add(o)),n&Yc&&(s=s.add(o)),o=o.double(),t>>=Yc,n>>=Yc;return{p1:i,p2:s}}function g_(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Lw(e),e}else return nf(r,{isLE:t})}function ug(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let l=e[c];if(!(typeof l=="bigint"&&l>of))throw new Error(`CURVE.${c} must be positive bigint`)}let o=g_(e.p,t.Fp,n),i=g_(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function af(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var _a=BigInt(0),br=BigInt(1),Hw=BigInt(2),uH=BigInt(8);function fH(r,e,t,n){let o=r.sqr(t),i=r.sqr(n),s=r.add(r.mul(e.a,o),i),a=r.add(r.ONE,r.mul(e.d,r.mul(o,i)));return r.eql(s,a)}function b_(r,e={}){let t=ug("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;Ni(e,{},{uvRatio:"function"});let a=Hw<<BigInt(o.BYTES*8)-br,c=w=>n.create(w),l=e.uvRatio||((w,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(w,x))}}catch{return{isValid:!1,value:_a}}});if(!fH(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(w,x,v=!1){let E=v?br:_a;return Aa("coordinate "+w,x,E,a),x}function f(w){if(!(w instanceof m))throw new Error("EdwardsPoint expected")}let h=rf((w,x)=>{let{X:v,Y:E,Z:I}=w,U=w.is0();x==null&&(x=U?uH:n.inv(I));let K=c(v*x),M=c(E*x),T=n.mul(I,x);if(U)return{x:_a,y:br};if(T!==br)throw new Error("invZ was invalid");return{x:K,y:M}}),d=rf(w=>{let{a:x,d:v}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:E,Y:I,Z:U,T:K}=w,M=c(E*E),T=c(I*I),k=c(U*U),z=c(k*k),W=c(M*x),$=c(k*c(W+T)),S=c(z+c(v*c(M*T)));if($!==S)throw new Error("bad point: equation left != right (1)");let C=c(E*I),_=c(U*K);if(C!==_)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(i.Gx,i.Gy,br,c(i.Gx*i.Gy));static ZERO=new m(_a,br,br,_a);static Fp=n;static Fn=o;X;Y;Z;T;constructor(x,v,E,I){this.X=u("x",x),this.Y=u("y",v),this.Z=u("z",E,!0),this.T=u("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(x){if(x instanceof m)throw new Error("extended point not allowed");let{x:v,y:E}=x||{};return u("x",v),u("y",E),new m(v,E,br,c(v*E))}static fromBytes(x,v=!1){let E=n.BYTES,{a:I,d:U}=i;x=Gc(ke(x,E,"point")),Es(v,"zip215");let K=Gc(x),M=x[E-1];K[E-1]=M&-129;let T=Di(K),k=v?a:n.ORDER;Aa("point.y",T,_a,k);let z=c(T*T),W=c(z-br),$=c(U*z-I),{isValid:S,value:C}=l(W,$);if(!S)throw new Error("bad point: invalid y coordinate");let _=(C&br)===br,B=(M&128)!==0;if(!v&&C===_a&&B)throw new Error("bad point: x=0 and x_0=1");return B!==_&&(C=c(-C)),m.fromAffine({x:C,y:T})}static fromHex(x,v=!1){return m.fromBytes(bs(x),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,v=!0){return y.createCache(this,x),v||this.multiply(Hw),this}assertValidity(){d(this)}equals(x){f(x);let{X:v,Y:E,Z:I}=this,{X:U,Y:K,Z:M}=x,T=c(v*M),k=c(U*I),z=c(E*M),W=c(K*I);return T===k&&z===W}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=i,{X:v,Y:E,Z:I}=this,U=c(v*v),K=c(E*E),M=c(Hw*c(I*I)),T=c(x*U),k=v+E,z=c(c(k*k)-U-K),W=T+K,$=W-M,S=T-K,C=c(z*$),_=c(W*S),B=c(z*S),X=c($*W);return new m(C,_,X,B)}add(x){f(x);let{a:v,d:E}=i,{X:I,Y:U,Z:K,T:M}=this,{X:T,Y:k,Z:z,T:W}=x,$=c(I*T),S=c(U*k),C=c(M*E*W),_=c(K*z),B=c((I+U)*(T+k)-$-S),X=_-C,G=_+C,F=c(S-v*$),Q=c(B*X),ne=c(G*F),V=c(B*F),Ne=c(X*G);return new m(Q,ne,Ne,V)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:E}=y.cached(this,x,I=>Qc(m,I));return Qc(m,[v,E])[0]}multiplyUnsafe(x,v=m.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===_a?m.ZERO:this.is0()||x===br?this:y.unsafe(this,x,E=>Qc(m,E),v)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(x){return h(this,x)}clearCofactor(){return s===br?this:this.multiplyUnsafe(s)}toBytes(){let{x,y:v}=this.toAffine(),E=n.toBytes(v);return E[E.length-1]|=x&br?128:0,E}toHex(){return xs(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new sf(m,o.BITS);return m.BASE.precompute(8),m}function v_(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');Ni(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=t.randomBytes||Ri,c=t.adjustScalarBytes||(T=>T),l=t.domain||((T,k,z)=>{if(Es(z,"phflag"),k.length||z)throw new Error("Contexts/pre-hash are not supported");return T});function u(T){return s.create(Di(T))}function f(T){let k=E.secretKey;ke(T,E.secretKey,"secretKey");let z=ke(e(T),2*k,"hashedSecretKey"),W=c(z.slice(0,k)),$=z.slice(k,2*k),S=u(W);return{head:W,prefix:$,scalar:S}}function h(T){let{head:k,prefix:z,scalar:W}=f(T),$=o.multiply(W),S=$.toBytes();return{head:k,prefix:z,scalar:W,point:$,pointBytes:S}}function d(T){return h(T).pointBytes}function m(T=Uint8Array.of(),...k){let z=Sn(...k);return u(e(l(z,ke(T,void 0,"context"),!!n)))}function y(T,k,z={}){T=ke(T,void 0,"message"),n&&(T=n(T));let{prefix:W,scalar:$,pointBytes:S}=h(k),C=m(z.context,W,T),_=o.multiply(C).toBytes(),B=m(z.context,_,S,T),X=s.create(C+B*$);if(!s.isValid(X))throw new Error("sign failed: invalid s");let G=Sn(_,s.toBytes(X));return ke(G,E.signature,"result")}let w={zip215:!0};function x(T,k,z,W=w){let{context:$,zip215:S}=W,C=E.signature;T=ke(T,C,"signature"),k=ke(k,void 0,"message"),z=ke(z,E.publicKey,"publicKey"),S!==void 0&&Es(S,"zip215"),n&&(k=n(k));let _=C/2,B=T.subarray(0,_),X=Di(T.subarray(_,C)),G,F,Q;try{G=r.fromBytes(z,S),F=r.fromBytes(B,S),Q=o.multiplyUnsafe(X)}catch{return!1}if(!S&&G.isSmallOrder())return!1;let ne=m($,F.toBytes(),G.toBytes(),k);return F.add(G.multiplyUnsafe(ne)).subtract(Q).clearCofactor().is0()}let v=i.BYTES,E={secretKey:v,publicKey:v,signature:2*v,seed:v};function I(T=a(E.seed)){return ke(T,E.seed,"seed")}function U(T){return Vc(T)&&T.length===s.BYTES}function K(T,k){try{return!!r.fromBytes(T,k)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:K,toMontgomery(T){let{y:k}=r.fromBytes(T),z=E.publicKey,W=z===32;if(!W&&z!==57)throw new Error("only defined for 25519 and 448");let $=W?i.div(br+k,br-k):i.div(k-br,k+br);return i.toBytes($)},toMontgomerySecret(T){let k=E.secretKey;ke(T,k);let z=e(T.subarray(0,k));return c(z).subarray(0,k)}};return Object.freeze({keygen:af(I,d),getPublicKey:d,sign:y,verify:x,utils:M,Point:r,lengths:E})}var Xh=BigInt(0),cf=BigInt(1),fg=BigInt(2);function dH(r){return Ni(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function E_(r){let e=dH(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i,randomBytes:s}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=s||Ri,l=a?255:448,u=a?32:56,f=BigInt(a?9:5),h=BigInt(a?121665:39081),d=a?fg**BigInt(254):fg**BigInt(447),m=a?BigInt(8)*fg**BigInt(251)-cf:BigInt(4)*fg**BigInt(445)-cf,y=d+m+cf,w=C=>Dt(C,t),x=v(f);function v(C){return zh(w(C),u)}function E(C){let _=Gc(ke(C,u,"uCoordinate"));return a&&(_[31]&=127),w(Di(_))}function I(C){return Di(o(Gc(ke(C,u,"scalar"))))}function U(C,_){let B=z(E(_),I(C));if(B===Xh)throw new Error("invalid private or public key received");return v(B)}function K(C){return U(C,x)}let M=K,T=U;function k(C,_,B){let X=w(C*(_-B));return _=w(_-X),B=w(B+X),{x_2:_,x_3:B}}function z(C,_){Aa("u",C,Xh,t),Aa("scalar",_,d,y);let B=_,X=C,G=cf,F=Xh,Q=C,ne=cf,V=Xh;for(let Ue=BigInt(l-1);Ue>=Xh;Ue--){let he=B>>Ue&cf;V^=he,{x_2:G,x_3:Q}=k(V,G,Q),{x_2:F,x_3:ne}=k(V,F,ne),V=he;let Ve=G+F,st=w(Ve*Ve),Pt=G-F,Ge=w(Pt*Pt),at=st-Ge,ds=Q+ne,Xo=Q-ne,ha=w(Xo*Ve),H0=w(ds*Pt),Ku=ha+H0,_h=ha-H0;Q=w(Ku*Ku),ne=w(X*w(_h*_h)),G=w(st*Ge),F=w(at*(st+w(h*at)))}({x_2:G,x_3:Q}=k(V,G,Q)),{x_2:F,x_3:ne}=k(V,F,ne);let Ne=i(F);return w(G*Ne)}let W={secretKey:u,publicKey:u,seed:u},$=(C=c(u))=>(ke(C,W.seed,"seed"),C),S={randomSecretKey:$};return Object.freeze({keygen:af($,M),getSharedSecret:T,getPublicKey:M,scalarMult:U,scalarMultBase:K,utils:S,GuBytes:x.slice(),lengths:W})}var hH=BigInt(1),S_=BigInt(2),pH=BigInt(3),mH=BigInt(5),gH=BigInt(8),dg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yH={p:dg,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:gH,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function __(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=dg,a=r*r%i*r%i,c=_t(a,S_,i)*a%i,l=_t(c,hH,i)*r%i,u=_t(l,mH,i)*l%i,f=_t(u,e,i)*u%i,h=_t(f,t,i)*f%i,d=_t(h,n,i)*h%i,m=_t(d,o,i)*d%i,y=_t(m,o,i)*d%i,w=_t(y,e,i)*u%i;return{pow_p_5_8:_t(w,S_,i)*r%i,b2:a}}function T_(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var A_=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wH(r,e){let t=dg,n=Dt(e*e*e,t),o=Dt(n*n*e,t),i=__(r*o).pow_p_5_8,s=Dt(r*n*i,t),a=Dt(e*s*s,t),c=s,l=Dt(s*A_,t),u=a===r,f=a===Dt(-r,t),h=a===Dt(-r*A_,t);return u&&(s=c),(f||h)&&(s=l),d_(s,t)&&(s=Dt(-s,t)),{isValid:u||f,value:s}}var xH=b_(yH,{uvRatio:wH});function bH(r){return v_(xH,Sa,Object.assign({adjustScalarBytes:T_},r))}var Yh=bH({});var Qh=(()=>{let r=dg;return E_({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=__(e);return Dt(_t(t,pH,r)*n,r)},adjustScalarBytes:T_})})();var Zc=32,jn=64,Kw=32;var lf,C_=(async()=>{try{return await Qt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function I_(){let r=Yh.utils.randomSecretKey(),e=Yh.getPublicKey(r);return{privateKey:_H(r,e),publicKey:e}}async function vH(r,e){let t;r.length===jn?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:H(r.subarray(32),"base64url"),d:H(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Qt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Qt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function EH(r,e){let t=r.subarray(0,Kw);return Yh.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function k_(r,e){return lf==null&&(lf=await C_),lf?vH(r,e):EH(r,e)}async function SH(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Qt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Qt.get().subtle.verify({name:"Ed25519"},n,e,t instanceof Uint8Array?t:t.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function AH(r,e,t){return Yh.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function P_(r,e,t){return lf==null&&(lf=await C_),lf?SH(r,e,t):AH(r,e,t)}function _H(r,e){let t=new Uint8Array(jn);for(let n=0;n<Kw;n++)t[n]=r[n],t[Kw+n]=e[n];return t}function uf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Zh=class{type="Ed25519";raw;constructor(e){this.raw=df(e,Zc)}toMultihash(){return Ot.digest(wr(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=P_(this.raw,t,e);return uf(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},ff=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=df(e,jn),this.publicKey=new Zh(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=k_(this.raw,e);return uf(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Vw(r){if(r.length>jn){r=df(r,jn+Zc);let n=r.subarray(0,jn),o=r.subarray(jn,r.length);return new ff(n,o)}r=df(r,jn);let e=r.subarray(0,jn),t=r.subarray(Zc);return new ff(e,t)}function qw(r){return r=df(r,Zc),new Zh(r)}async function O_(){let{privateKey:r,publicKey:e}=I_();return new ff(r,e)}function df(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new D(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var TH=Math.pow(2,7),CH=Math.pow(2,14),IH=Math.pow(2,21),zw=Math.pow(2,28),jw=Math.pow(2,35),Ww=Math.pow(2,42),Gw=Math.pow(2,49),lt=128,jr=127;function $e(r){if(r<TH)return 1;if(r<CH)return 2;if(r<IH)return 3;if(r<zw)return 4;if(r<jw)return 5;if(r<Ww)return 6;if(r<Gw)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function hf(r,e,t=0){switch($e(r)){case 8:e[t++]=r&255|lt,r/=128;case 7:e[t++]=r&255|lt,r/=128;case 6:e[t++]=r&255|lt,r/=128;case 5:e[t++]=r&255|lt,r/=128;case 4:e[t++]=r&255|lt,r>>>=7;case 3:e[t++]=r&255|lt,r>>>=7;case 2:e[t++]=r&255|lt,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function kH(r,e,t=0){switch($e(r)){case 8:e.set(t++,r&255|lt),r/=128;case 7:e.set(t++,r&255|lt),r/=128;case 6:e.set(t++,r&255|lt),r/=128;case 5:e.set(t++,r&255|lt),r/=128;case 4:e.set(t++,r&255|lt),r>>>=7;case 3:e.set(t++,r&255|lt),r>>>=7;case 2:e.set(t++,r&255|lt),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Xw(r,e){let t=r[e],n=0;if(n+=t&jr,t<lt||(t=r[e+1],n+=(t&jr)<<7,t<lt)||(t=r[e+2],n+=(t&jr)<<14,t<lt)||(t=r[e+3],n+=(t&jr)<<21,t<lt)||(t=r[e+4],n+=(t&jr)*zw,t<lt)||(t=r[e+5],n+=(t&jr)*jw,t<lt)||(t=r[e+6],n+=(t&jr)*Ww,t<lt)||(t=r[e+7],n+=(t&jr)*Gw,t<lt))return n;throw new RangeError("Could not decode varint")}function PH(r,e){let t=r.get(e),n=0;if(n+=t&jr,t<lt||(t=r.get(e+1),n+=(t&jr)<<7,t<lt)||(t=r.get(e+2),n+=(t&jr)<<14,t<lt)||(t=r.get(e+3),n+=(t&jr)<<21,t<lt)||(t=r.get(e+4),n+=(t&jr)*zw,t<lt)||(t=r.get(e+5),n+=(t&jr)*jw,t<lt)||(t=r.get(e+6),n+=(t&jr)*Ww,t<lt)||(t=r.get(e+7),n+=(t&jr)*Gw,t<lt))return n;throw new RangeError("Could not decode varint")}function Wr(r,e,t=0){return e==null&&(e=Bt($e(r))),e instanceof Uint8Array?hf(r,e,t):kH(r,e,t)}function Wn(r,e=0){return r instanceof Uint8Array?Xw(r,e):PH(r,e)}var Yw=new Float32Array([-0]),Ta=new Uint8Array(Yw.buffer);function D_(r,e,t){Yw[0]=r,e[t]=Ta[0],e[t+1]=Ta[1],e[t+2]=Ta[2],e[t+3]=Ta[3]}function N_(r,e){return Ta[0]=r[e],Ta[1]=r[e+1],Ta[2]=r[e+2],Ta[3]=r[e+3],Yw[0]}var Qw=new Float64Array([-0]),Gr=new Uint8Array(Qw.buffer);function L_(r,e,t){Qw[0]=r,e[t]=Gr[0],e[t+1]=Gr[1],e[t+2]=Gr[2],e[t+3]=Gr[3],e[t+4]=Gr[4],e[t+5]=Gr[5],e[t+6]=Gr[6],e[t+7]=Gr[7]}function B_(r,e){return Gr[0]=r[e],Gr[1]=r[e+1],Gr[2]=r[e+2],Gr[3]=r[e+3],Gr[4]=r[e+4],Gr[5]=r[e+5],Gr[6]=r[e+6],Gr[7]=r[e+7],Qw[0]}var RH=BigInt(Number.MAX_SAFE_INTEGER),OH=BigInt(Number.MIN_SAFE_INTEGER),Gn=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Jc;if(e<RH&&e>OH)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>M_&&(o=0n,++n>M_&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Jc;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Jc}},Jc=new Gn(0,0);Jc.toBigInt=function(){return 0n};Jc.zzEncode=Jc.zzDecode=function(){return this};Jc.length=function(){return 1};var M_=4294967296n;function U_(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function F_(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Zw(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function ti(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function hg(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Jw=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ti(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ti(this,4);return hg(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ti(this,4);return hg(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ti(this,4);let e=N_(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ti(this,4);let e=B_(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw ti(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return F_(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ti(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ti(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Gn(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw ti(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw ti(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ti(this,8);let e=hg(this.buf,this.pos+=4),t=hg(this.buf,this.pos+=4);return new Gn(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Xw(this.buf,this.pos);return this.pos+=$e(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function e7(r){return new Jw(r instanceof Uint8Array?r:r.subarray())}function xe(r,e,t){let n=e7(r);return e.decode(n,void 0,t)}function t7(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return Bt(s);o+s>e&&(n=Bt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var el=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function r7(){}var o7=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},DH=t7();function NH(r){return globalThis.Buffer!=null?Bt(r):DH(r)}var ep=class{len;head;tail;states;constructor(){this.len=0,this.head=new el(r7,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new el(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new i7((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(pg,10,Gn.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Gn.fromBigInt(e);return this._push(pg,t.length(),t)}uint64Number(e){return this._push(hf,$e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Gn.fromBigInt(e).zzEncode();return this._push(pg,t.length(),t)}sint64Number(e){let t=Gn.fromNumber(e).zzEncode();return this._push(pg,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(n7,1,e?1:0)}fixed32(e){return this._push(Jh,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Gn.fromBigInt(e);return this._push(Jh,4,t.lo)._push(Jh,4,t.hi)}fixed64Number(e){let t=Gn.fromNumber(e);return this._push(Jh,4,t.lo)._push(Jh,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(D_,4,e)}double(e){return this._push(L_,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(n7,1,0):this.uint32(t)._push(BH,t,e)}string(e){let t=U_(e);return t!==0?this.uint32(t)._push(Zw,t,e):this._push(n7,1,0)}fork(){return this.states=new o7(this),this.head=this.tail=new el(r7,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new el(r7,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=NH(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function n7(r,e,t){e[t]=r&255}function LH(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var i7=class extends el{next;constructor(e,t){super(LH,e,t),this.next=void 0}};function pg(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Jh(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function BH(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ep.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(MH,e,r),this},ep.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(UH,e,r),this});function MH(r,e,t){e.set(r,t)}function UH(r,e,t){r.length<40?Zw(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(O(r),t)}function s7(){return new ep}function be(r,e){let t=s7();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var pf;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(pf||(pf={}));function mg(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function wt(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return mg("enum",pf.VARINT,t,n)}function ve(r,e){return mg("message",pf.LENGTH_DELIMITED,r,e)}var ht=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},tp=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var xt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(xt||(xt={}));var a7;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(a7||(a7={}));(function(r){r.codec=()=>wt(a7)})(xt||(xt={}));var Li;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),xt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=xt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>be(t,r.codec()),r.decode=(t,n)=>xe(t,r.codec(),n)})(Li||(Li={}));var rp;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),xt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=xt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>be(t,r.codec()),r.decode=(t,n)=>xe(t,r.codec(),n)})(rp||(rp={}));function fn(r){if(isNaN(r)||r<=0)throw new D("random bytes length must be a Number bigger than 0");return Ri(r)}var op={};Lt(op,{MAX_RSA_KEY_SIZE:()=>c7,generateRSAKeyPair:()=>y7,jwkToJWKKeyPair:()=>q_,jwkToPkcs1:()=>KH,jwkToPkix:()=>d7,jwkToRSAPrivateKey:()=>g7,pkcs1MessageToJwk:()=>u7,pkcs1MessageToRSAPrivateKey:()=>gg,pkcs1ToJwk:()=>HH,pkcs1ToRSAPrivateKey:()=>h7,pkixMessageToJwk:()=>f7,pkixMessageToRSAPublicKey:()=>m7,pkixToJwk:()=>VH,pkixToRSAPublicKey:()=>p7});var mf=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=op.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Z.createV1(114,this._multihash)}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t,n){return V_(this.jwk,t,e,n)}},np=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=op.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,t){return K_(this.jwk,e,t)}};var c7=8192,l7=18,FH=1062,$H=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function HH(r){let e=Io(r);return u7(e)}function u7(r){return{n:H(r[1],"base64url"),e:H(r[2],"base64url"),d:H(r[3],"base64url"),p:H(r[4],"base64url"),q:H(r[5],"base64url"),dp:H(r[6],"base64url"),dq:H(r[7],"base64url"),qi:H(r[8],"base64url"),kty:"RSA"}}function KH(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new D("JWK was missing components");return Jo([ln(Uint8Array.from([0])),ln(O(r.n,"base64url")),ln(O(r.e,"base64url")),ln(O(r.d,"base64url")),ln(O(r.p,"base64url")),ln(O(r.q,"base64url")),ln(O(r.dp,"base64url")),ln(O(r.dq,"base64url")),ln(O(r.qi,"base64url"))]).subarray()}function VH(r){let e=Io(r,{offset:0});return f7(e)}function f7(r){let e=Io(r[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function d7(r){if(r.n==null||r.e==null)throw new D("JWK was missing components");return Jo([$H,$h(Jo([ln(O(r.n,"base64url")),ln(O(r.e,"base64url"))]))]).subarray()}function h7(r){let e=Io(r);return gg(e)}function gg(r){let e=u7(r);return g7(e)}function p7(r,e){if(r.byteLength>=FH)throw new ps("Key size is too large");let t=Io(r,{offset:0});return m7(t,r,e)}function m7(r,e,t){let n=f7(r);if(t==null){let o=ko(Li.encode({Type:xt.RSA,Data:e}));t=cn(l7,o)}return new mf(n,t)}function g7(r){if(j_(r)>c7)throw new D("Key size is too large");let e=q_(r),t=ko(Li.encode({Type:xt.RSA,Data:d7(e.publicKey)})),n=cn(l7,t);return new np(e.privateKey,new mf(e.publicKey,n))}async function y7(r){if(r>c7)throw new D("Key size is too large");let e=await z_(r),t=ko(Li.encode({Type:xt.RSA,Data:d7(e.publicKey)})),n=cn(l7,t);return new np(e.privateKey,new mf(e.publicKey,n))}function q_(r){if(r==null)throw new D("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function z_(r,e){let t=await Qt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await qH(t,e);return{privateKey:n[0],publicKey:n[1]}}async function K_(r,e,t){let n=await Qt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Qt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function V_(r,e,t,n){let o=await Qt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Qt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function qH(r,e){if(r.privateKey==null||r.publicKey==null)throw new D("Private and public key are required");let t=await Promise.all([Qt.get().subtle.exportKey("jwk",r.privateKey),Qt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function j_(r){if(r.kty!=="RSA")throw new D("invalid key type");if(r.n==null)throw new D("invalid key modulus");return O(r.n,"base64url").length*8}var yg=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(ws(e),ke(t,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(t.length>n?e.create().update(t).digest():t);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),zr(o)}update(e){return ef(this),this.iHash.update(e),this}digestInto(e){ef(this),ke(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ca=(r,e,t)=>new yg(r,e).update(t).digest();Ca.create=(r,e)=>new yg(r,e);var W_=(r,e)=>(r+(r>=0?e:-e)/G_)/e;function zH(r,e,t){let[[n,o],[i,s]]=e,a=W_(s*r,t),c=W_(-o*r,t),l=r-a*n-c*i,u=-a*o-c*s,f=l<As,h=u<As;f&&(l=-l),h&&(u=-u);let d=jh(Math.ceil(Ow(t)/2))+gf;if(l<As||l>=d||u<As||u>=d)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}function x7(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function w7(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return Es(t.lowS,"lowS"),Es(t.prehash,"prehash"),t.format!==void 0&&x7(t.format),t}var b7=class extends Error{constructor(e=""){super(e)}},Ia={Err:b7,_tlv:{encode:(r,e)=>{let{Err:t}=Ia;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=qh(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?qh(o.length/2|128):"";return qh(r)+i+o+e},decode(r,e){let{Err:t}=Ia,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=Ia;if(r<As)throw new e("integer: negative integers are not allowed");let t=qh(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=Ia;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return tf(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Ia,o=ke(r,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:l,l:u}=n.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=Ia,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},As=BigInt(0),gf=BigInt(1),G_=BigInt(2),wg=BigInt(3),jH=BigInt(4);function X_(r,e={}){let t=ug("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;Ni(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=Q_(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f($,S,C){let{x:_,y:B}=S.toAffine(),X=n.toBytes(_);if(Es(C,"isCompressed"),C){u();let G=!n.isOdd(B);return Sn(Y_(G),X)}else return Sn(Uint8Array.of(4),X,n.toBytes(B))}function h($){ke($,void 0,"Point");let{publicKey:S,publicKeyUncompressed:C}=l,_=$.length,B=$[0],X=$.subarray(1);if(_===S&&(B===2||B===3)){let G=n.fromBytes(X);if(!n.isValid(G))throw new Error("bad point: is not on curve, wrong x");let F=y(G),Q;try{Q=n.sqrt(F)}catch(Ne){let Ue=Ne instanceof Error?": "+Ne.message:"";throw new Error("bad point: is not on curve, sqrt error"+Ue)}u();let ne=n.isOdd(Q);return(B&1)===1!==ne&&(Q=n.neg(Q)),{x:G,y:Q}}else if(_===C&&B===4){let G=n.BYTES,F=n.fromBytes(X.subarray(0,G)),Q=n.fromBytes(X.subarray(G,G*2));if(!w(F,Q))throw new Error("bad point: is not on curve");return{x:F,y:Q}}else throw new Error(`bad point: got length ${_}, expected compressed=${S} or uncompressed=${C}`)}let d=e.toBytes||f,m=e.fromBytes||h;function y($){let S=n.sqr($),C=n.mul(S,$);return n.add(n.add(C,n.mul($,i.a)),i.b)}function w($,S){let C=n.sqr(S),_=y($);return n.eql(C,_)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(i.a,wg),jH),v=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(x,v)))throw new Error("bad curve params: a or b");function E($,S,C=!1){if(!n.isValid(S)||C&&n.is0(S))throw new Error(`bad point coordinate ${$}`);return S}function I($){if(!($ instanceof k))throw new Error("Weierstrass Point expected")}function U($){if(!c||!c.basises)throw new Error("no endo");return zH($,c.basises,o.ORDER)}let K=rf(($,S)=>{let{X:C,Y:_,Z:B}=$;if(n.eql(B,n.ONE))return{x:C,y:_};let X=$.is0();S==null&&(S=X?n.ONE:n.inv(B));let G=n.mul(C,S),F=n.mul(_,S),Q=n.mul(B,S);if(X)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Q,n.ONE))throw new Error("invZ was invalid");return{x:G,y:F}}),M=rf($=>{if($.is0()){if(e.allowInfinityPoint&&!n.is0($.Y))return;throw new Error("bad point: ZERO")}let{x:S,y:C}=$.toAffine();if(!n.isValid(S)||!n.isValid(C))throw new Error("bad point: x or y not field elements");if(!w(S,C))throw new Error("bad point: equation left != right");if(!$.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function T($,S,C,_,B){return C=new k(n.mul(C.X,$),C.Y,C.Z),S=Gh(_,S),C=Gh(B,C),S.add(C)}class k{static BASE=new k(i.Gx,i.Gy,n.ONE);static ZERO=new k(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(S,C,_){this.X=E("x",S),this.Y=E("y",C,!0),this.Z=E("z",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(S){let{x:C,y:_}=S||{};if(!S||!n.isValid(C)||!n.isValid(_))throw new Error("invalid affine point");if(S instanceof k)throw new Error("projective point not allowed");return n.is0(C)&&n.is0(_)?k.ZERO:new k(C,_,n.ONE)}static fromBytes(S){let C=k.fromAffine(m(ke(S,void 0,"point")));return C.assertValidity(),C}static fromHex(S){return k.fromBytes(bs(S))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(S=8,C=!0){return W.createCache(this,S),C||this.multiply(wg),this}assertValidity(){M(this)}hasEvenY(){let{y:S}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(S)}equals(S){I(S);let{X:C,Y:_,Z:B}=this,{X,Y:G,Z:F}=S,Q=n.eql(n.mul(C,F),n.mul(X,B)),ne=n.eql(n.mul(_,F),n.mul(G,B));return Q&&ne}negate(){return new k(this.X,n.neg(this.Y),this.Z)}double(){let{a:S,b:C}=i,_=n.mul(C,wg),{X:B,Y:X,Z:G}=this,F=n.ZERO,Q=n.ZERO,ne=n.ZERO,V=n.mul(B,B),Ne=n.mul(X,X),Ue=n.mul(G,G),he=n.mul(B,X);return he=n.add(he,he),ne=n.mul(B,G),ne=n.add(ne,ne),F=n.mul(S,ne),Q=n.mul(_,Ue),Q=n.add(F,Q),F=n.sub(Ne,Q),Q=n.add(Ne,Q),Q=n.mul(F,Q),F=n.mul(he,F),ne=n.mul(_,ne),Ue=n.mul(S,Ue),he=n.sub(V,Ue),he=n.mul(S,he),he=n.add(he,ne),ne=n.add(V,V),V=n.add(ne,V),V=n.add(V,Ue),V=n.mul(V,he),Q=n.add(Q,V),Ue=n.mul(X,G),Ue=n.add(Ue,Ue),V=n.mul(Ue,he),F=n.sub(F,V),ne=n.mul(Ue,Ne),ne=n.add(ne,ne),ne=n.add(ne,ne),new k(F,Q,ne)}add(S){I(S);let{X:C,Y:_,Z:B}=this,{X,Y:G,Z:F}=S,Q=n.ZERO,ne=n.ZERO,V=n.ZERO,Ne=i.a,Ue=n.mul(i.b,wg),he=n.mul(C,X),Ve=n.mul(_,G),st=n.mul(B,F),Pt=n.add(C,_),Ge=n.add(X,G);Pt=n.mul(Pt,Ge),Ge=n.add(he,Ve),Pt=n.sub(Pt,Ge),Ge=n.add(C,B);let at=n.add(X,F);return Ge=n.mul(Ge,at),at=n.add(he,st),Ge=n.sub(Ge,at),at=n.add(_,B),Q=n.add(G,F),at=n.mul(at,Q),Q=n.add(Ve,st),at=n.sub(at,Q),V=n.mul(Ne,Ge),Q=n.mul(Ue,st),V=n.add(Q,V),Q=n.sub(Ve,V),V=n.add(Ve,V),ne=n.mul(Q,V),Ve=n.add(he,he),Ve=n.add(Ve,he),st=n.mul(Ne,st),Ge=n.mul(Ue,Ge),Ve=n.add(Ve,st),st=n.sub(he,st),st=n.mul(Ne,st),Ge=n.add(Ge,st),he=n.mul(Ve,Ge),ne=n.add(ne,he),he=n.mul(at,Ge),Q=n.mul(Pt,Q),Q=n.sub(Q,he),he=n.mul(Pt,Ve),V=n.mul(at,V),V=n.add(V,he),new k(Q,ne,V)}subtract(S){return this.add(S.negate())}is0(){return this.equals(k.ZERO)}multiply(S){let{endo:C}=e;if(!o.isValidNot0(S))throw new Error("invalid scalar: out of range");let _,B,X=G=>W.cached(this,G,F=>Qc(k,F));if(C){let{k1neg:G,k1:F,k2neg:Q,k2:ne}=U(S),{p:V,f:Ne}=X(F),{p:Ue,f:he}=X(ne);B=Ne.add(he),_=T(C.beta,V,Ue,G,Q)}else{let{p:G,f:F}=X(S);_=G,B=F}return Qc(k,[_,B])[0]}multiplyUnsafe(S){let{endo:C}=e,_=this;if(!o.isValid(S))throw new Error("invalid scalar: out of range");if(S===As||_.is0())return k.ZERO;if(S===gf)return _;if(W.hasCache(this))return this.multiply(S);if(C){let{k1neg:B,k1:X,k2neg:G,k2:F}=U(S),{p1:Q,p2:ne}=x_(k,_,X,F);return T(C.beta,Q,ne,B,G)}else return W.unsafe(_,S)}toAffine(S){return K(this,S)}isTorsionFree(){let{isTorsionFree:S}=e;return s===gf?!0:S?S(k,this):W.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:S}=e;return s===gf?this:S?S(k,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(S=!0){return Es(S,"isCompressed"),this.assertValidity(),d(k,this,S)}toHex(S=!0){return xs(this.toBytes(S))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let z=o.BITS,W=new sf(k,e.endo?Math.ceil(z/2):z);return k.BASE.precompute(8),k}function Y_(r){return Uint8Array.of(r?2:3)}function Q_(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function WH(r,e={}){let{Fn:t}=r,n=e.randomBytes||Ri,o=Object.assign(Q_(r.Fp,t),{seed:Bw(t.ORDER)});function i(d){try{let m=t.fromBytes(d);return t.isValidNot0(m)}catch{return!1}}function s(d,m){let{publicKey:y,publicKeyUncompressed:w}=o;try{let x=d.length;return m===!0&&x!==y||m===!1&&x!==w?!1:!!r.fromBytes(d)}catch{return!1}}function a(d=n(o.seed)){return Mw(ke(d,o.seed,"seed"),t.ORDER)}function c(d,m=!0){return r.BASE.multiply(t.fromBytes(d)).toBytes(m)}function l(d){let{secretKey:m,publicKey:y,publicKeyUncompressed:w}=o;if(!Vc(d)||"_lengths"in t&&t._lengths||m===y)return;let x=ke(d,void 0,"key").length;return x===y||x===w}function u(d,m,y=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(m)===!1)throw new Error("second arg must be public key");let w=t.fromBytes(d);return r.fromBytes(m).multiply(w).toBytes(y)}let f={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=af(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:r,utils:f,lengths:o})}function Z_(r,e,t={}){ws(e),Ni(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),t=Object.assign({},t);let n=t.randomBytes||Ri,o=t.hmac||((C,_)=>Ca(e,C,_)),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:l,getPublicKey:u,getSharedSecret:f,utils:h,lengths:d}=WH(r,t),m={prehash:!0,lowS:typeof t.lowS=="boolean"?t.lowS:!0,format:"compact",extraEntropy:!1},y=a*G_<i.ORDER;function w(C){let _=a>>gf;return C>_}function x(C,_){if(!s.isValidNot0(_))throw new Error(`invalid signature ${C}: out of range 1..Point.Fn.ORDER`);return _}function v(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function E(C,_){x7(_);let B=d.signature,X=_==="compact"?B:_==="recovered"?B+1:void 0;return ke(C,X)}class I{r;s;recovery;constructor(_,B,X){if(this.r=x("r",_),this.s=x("s",B),X!=null){if(v(),![0,1,2,3].includes(X))throw new Error("invalid recovery id");this.recovery=X}Object.freeze(this)}static fromBytes(_,B=m.format){E(_,B);let X;if(B==="der"){let{r:ne,s:V}=Ia.toSig(ke(_));return new I(ne,V)}B==="recovered"&&(X=_[0],B="compact",_=_.subarray(1));let G=d.signature/2,F=_.subarray(0,G),Q=_.subarray(G,G*2);return new I(s.fromBytes(F),s.fromBytes(Q),X)}static fromHex(_,B){return this.fromBytes(bs(_),B)}assertRecovery(){let{recovery:_}=this;if(_==null)throw new Error("invalid recovery id: must be present");return _}addRecoveryBit(_){return new I(this.r,this.s,_)}recoverPublicKey(_){let{r:B,s:X}=this,G=this.assertRecovery(),F=G===2||G===3?B+a:B;if(!i.isValid(F))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let Q=i.toBytes(F),ne=r.fromBytes(Sn(Y_((G&1)===0),Q)),V=s.inv(F),Ne=K(ke(_,void 0,"msgHash")),Ue=s.create(-Ne*V),he=s.create(X*V),Ve=r.BASE.multiplyUnsafe(Ue).add(ne.multiplyUnsafe(he));if(Ve.is0())throw new Error("invalid recovery: point at infinify");return Ve.assertValidity(),Ve}hasHighS(){return w(this.s)}toBytes(_=m.format){if(x7(_),_==="der")return bs(Ia.hexFromSig(this));let{r:B,s:X}=this,G=s.toBytes(B),F=s.toBytes(X);return _==="recovered"?(v(),Sn(Uint8Array.of(this.assertRecovery()),G,F)):Sn(G,F)}toHex(_){return xs(this.toBytes(_))}}let U=t.bits2int||function(_){if(_.length>8192)throw new Error("input is too large");let B=tf(_),X=_.length*8-c;return X>0?B>>BigInt(X):B},K=t.bits2int_modN||function(_){return s.create(U(_))},M=jh(c);function T(C){return Aa("num < 2^"+c,C,As,M),s.toBytes(C)}function k(C,_){return ke(C,void 0,"message"),_?ke(e(C),void 0,"prehashed message"):C}function z(C,_,B){let{lowS:X,prehash:G,extraEntropy:F}=w7(B,m);C=k(C,G);let Q=K(C),ne=s.fromBytes(_);if(!s.isValidNot0(ne))throw new Error("invalid private key");let V=[T(ne),T(Q)];if(F!=null&&F!==!1){let Ve=F===!0?n(d.secretKey):F;V.push(ke(Ve,void 0,"extraEntropy"))}let Ne=Sn(...V),Ue=Q;function he(Ve){let st=U(Ve);if(!s.isValidNot0(st))return;let Pt=s.inv(st),Ge=r.BASE.multiply(st).toAffine(),at=s.create(Ge.x);if(at===As)return;let ds=s.create(Pt*s.create(Ue+at*ne));if(ds===As)return;let Xo=(Ge.x===at?0:2)|Number(Ge.y&gf),ha=ds;return X&&w(ds)&&(ha=s.neg(ds),Xo^=1),new I(at,ha,y?void 0:Xo)}return{seed:Ne,k2sig:he}}function W(C,_,B={}){let{seed:X,k2sig:G}=z(C,_,B);return r_(e.outputLen,s.BYTES,o)(X,G).toBytes(B.format)}function $(C,_,B,X={}){let{lowS:G,prehash:F,format:Q}=w7(X,m);if(B=ke(B,void 0,"publicKey"),_=k(_,F),!Vc(C)){let ne=C instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+ne)}E(C,Q);try{let ne=I.fromBytes(C,Q),V=r.fromBytes(B);if(G&&ne.hasHighS())return!1;let{r:Ne,s:Ue}=ne,he=K(_),Ve=s.inv(Ue),st=s.create(he*Ve),Pt=s.create(Ne*Ve),Ge=r.BASE.multiplyUnsafe(st).add(V.multiplyUnsafe(Pt));return Ge.is0()?!1:s.create(Ge.x)===Ne}catch{return!1}}function S(C,_,B={}){let{prehash:X}=w7(B,m);return _=k(_,X),I.fromBytes(C,"recovered").recoverPublicKey(_).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:f,utils:h,lengths:d,Point:r,sign:W,verify:$,recoverPublicKey:S,Signature:I,hash:e})}var E7={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},GH={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var J_=BigInt(2);function XH(r){let e=E7.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%e,u=l*l*r%e,f=_t(u,t,e)*u%e,h=_t(f,t,e)*u%e,d=_t(h,J_,e)*l%e,m=_t(d,o,e)*d%e,y=_t(m,i,e)*m%e,w=_t(y,a,e)*y%e,x=_t(w,c,e)*w%e,v=_t(x,a,e)*y%e,E=_t(v,t,e)*u%e,I=_t(E,s,e)*m%e,U=_t(I,n,e)*l%e,K=_t(U,J_,e);if(!v7.eql(v7.sqr(K),r))throw new Error("Cannot find square root");return K}var v7=nf(E7.p,{sqrt:XH}),YH=X_(E7,{Fp:v7,endo:GH}),ri=Z_(YH,ko);var eT=32;function tT(r,e,t){let n=At.digest(e instanceof Uint8Array?e:e.subarray());if(uf(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),ri.sign(o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Oh(String(o))});try{return ri.sign(n.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Oh(String(o))}}function rT(r,e,t,n){let o=At.digest(t instanceof Uint8Array?t:t.subarray());if(uf(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),ri.verify(e,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Dh(String(i))});try{return n?.signal?.throwIfAborted(),ri.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Dh(String(i))}}var ip=class{type="secp256k1";raw;_key;constructor(e){this._key=iT(e),this.raw=nT(this._key)}toMultihash(){return Ot.digest(wr(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t,n){return rT(this._key,t,e,n)}},sp=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=oT(e),this.publicKey=new ip(t??sT(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,t){return tT(this.raw,e,t)}};function S7(r){return new sp(r)}function A7(r){return new ip(r)}async function aT(){let r=QH();return new sp(r)}function nT(r){return ri.Point.fromBytes(r).toBytes()}function oT(r){try{return ri.getPublicKey(r,!0),r}catch(e){throw new Ch(String(e))}}function iT(r){try{return ri.Point.fromBytes(r),r}catch(e){throw new ps(String(e))}}function sT(r){try{return ri.getPublicKey(r,!0)}catch(e){throw new Ch(String(e))}}function QH(){return ri.utils.randomSecretKey()}async function yf(r,e){if(r==="Ed25519")return O_();if(r==="secp256k1")return aT();if(r==="RSA")return y7(ZH(e));if(r==="ECDSA")return FA(JH(e));throw new Zo}function Wt(r,e){let{Type:t,Data:n}=Li.decode(r),o=n??new Uint8Array;switch(t){case xt.RSA:return p7(o,e);case xt.Ed25519:return qw(o);case xt.secp256k1:return A7(o);case xt.ECDSA:return vw(o);default:throw new Zo}}function xg(r){let{Type:e,Data:t}=Li.decode(r.digest),n=t??new Uint8Array;switch(e){case xt.Ed25519:return qw(n);case xt.secp256k1:return A7(n);case xt.ECDSA:return vw(n);default:throw new Zo}}function wr(r){return Li.encode({Type:xt[r.type],Data:r.raw})}function cT(r){let e=rp.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case xt.RSA:return h7(t);case xt.Ed25519:return Vw(t);case xt.secp256k1:return S7(t);case xt.ECDSA:return NA(t);default:throw new Zo}}function lT(r){if(r.byteLength===jn)return Vw(r);if(r.byteLength===eT)return S7(r);let e=Io(r),t=e[2]?.[0];if(t===_A||t===TA||t===CA)return bw(e);if(e.length>8)return gg(e);throw new D("Could not extract private key from raw bytes")}function tl(r){return rp.encode({Type:xt[r.type],Data:r.raw})}function ZH(r){return r==null?2048:parseInt(r,10)}function JH(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new D("Unsupported curve, should be P-256, P-384 or P-521")}async function bg(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new D("Only RSA and ECDSA keys are supported")}var ap=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ka=new Uint32Array(80),_7=class extends zc{A=ap[0]|0;B=ap[1]|0;C=ap[2]|0;D=ap[3]|0;E=ap[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:e,B:t,C:n,D:o,E:i}=this;return[e,t,n,o,i]}set(e,t,n,o,i){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0}process(e,t){for(let c=0;c<16;c++,t+=4)ka[c]=e.getUint32(t,!1);for(let c=16;c<80;c++)ka[c]=og(ka[c-3]^ka[c-8]^ka[c-14]^ka[c-16],1);let{A:n,B:o,C:i,D:s,E:a}=this;for(let c=0;c<80;c++){let l,u;c<20?(l=ig(o,i,s),u=1518500249):c<40?(l=o^i^s,u=1859775393):c<60?(l=sg(o,i,s),u=2400959708):(l=o^i^s,u=3395469782);let f=og(n,5)+l+a+u+ka[c]|0;a=s,s=i,i=og(o,30),o=n,n=f}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,this.set(n,o,i,s,a)}roundClean(){zr(ka)}destroy(){this.set(0,0,0,0,0),zr(this.buffer)}},uT=Hh(()=>new _7);function fT(r,e,t,n){ws(r);let o=qA({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(qr(i,"c"),qr(s,"dkLen"),qr(a,"asyncTick"),i<1)throw new Error("iterations (c) must be >= 1");let c=Ew(e,"password"),l=Ew(t,"salt"),u=new Uint8Array(s),f=Ca.create(r,c),h=f._cloneInto().update(l);return{c:i,dkLen:s,asyncTick:a,DK:u,PRF:f,PRFSalt:h}}function dT(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),zr(o),t}function hT(r,e,t,n){let{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=fT(r,e,t,n),l,u=new Uint8Array(4),f=qc(u),h=new Uint8Array(a.outputLen);for(let d=1,m=0;m<i;d++,m+=a.outputLen){let y=s.subarray(m,m+a.outputLen);f.setInt32(0,d,!1),(l=c._cloneInto(l)).update(u).digestInto(h),y.set(h.subarray(0,y.length));for(let w=1;w<o;w++){a._cloneInto(l).update(h).digestInto(h);for(let x=0;x<y.length;x++)y[x]^=h[x]}}return dT(a,c,s,l,h)}async function vg(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:l}=fT(r,e,t,n),u,f=new Uint8Array(4),h=qc(f),d=new Uint8Array(c.outputLen);for(let m=1,y=0;y<i;m++,y+=c.outputLen){let w=a.subarray(y,y+c.outputLen);h.setInt32(0,m,!1),(u=l._cloneInto(u)).update(f).digestInto(d),w.set(d.subarray(0,w.length)),await VA(o-1,s,()=>{c._cloneInto(u).update(d).digestInto(d);for(let x=0;x<w.length;x++)w[x]^=d[x]})}return dT(c,l,a,u,d)}var pT={sha1:uT,"sha2-256":ko,"sha2-512":Sa};function cp(r,e,t,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(pT).join(" / ");throw new D(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let i=pT[o],s=hT(i,r,e,{c:t,dkLen:n});return Zt.encode(s).substring(1)}var T7={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},mT={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},gT=new globalThis.TextEncoder;function eK(r,e){let t=T7[e],n=mT[e];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(e,n*t);return n}function tK(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=T7[e],o=mT[e],i=r;for(;i.length>0;){let s=gT.encodeInto(i,t);i=i.slice(s.read);for(let a=0;a<s.written;a++)o^=BigInt(t[a]),o=BigInt.asUintN(e,o*n)}return o}function C7(r,{size:e=32,utf8Buffer:t}={}){if(!T7[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return tK(r,e,t);r=gT.encode(r)}return eK(r,e)}var lp={hash:r=>Number(C7(r,{size:32})),hashV:(r,e)=>rK(lp.hash(r,e))};function rK(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),O(e,"base16")}var I7=64,ni=class{fp;h;seed;constructor(e,t,n,o=2){if(o>I7)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),s=Ie(o);for(let a=0;a<s.length;a++)s[a]=i[a];s.length===0&&(s[0]=7),this.fp=s,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?me(this.fp,e.fp):!1}};function rl(r,e){return Math.floor(Math.random()*(e-r))+r}var nl=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");let t=rl(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var nK=500,up=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??lp,this.seed=e.seed??rl(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=O(e));let t=new ni(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new nl(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new nl(this.bucketSize)),this.buckets[n].add(t)||this.buckets[o].add(t))return this.count++,!0;let i=[n,o],s=i[rl(0,i.length-1)];this.buckets[s]==null&&(this.buckets[s]=new nl(this.bucketSize));for(let a=0;a<nK;a++){let c=this.buckets[s].swap(t);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new nl(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=O(e));let t=new ni(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(t)??!1;if(o)return o;let i=(n^t.hash())%this.filterSize;return this.buckets[i]?.has(t)??!1}remove(e){typeof e=="string"&&(e=O(e));let t=new ni(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(t)??!1;if(o)return this.count--,o;let i=(n^t.hash())%this.filterSize,s=this.buckets[i]?.remove(t)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},oK={1:.5,2:.84,4:.95,8:.98};function iK(r=.001){return r>.002?2:r>1e-5?4:8}function yT(r,e=.001){let t=iK(e),n=oK[t],o=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),I7);return{filterSize:o,bucketSize:t,fingerprintSize:i}}var Eg=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??lp,this.seed=e.seed??rl(0,Math.pow(2,10)),this.filterSeries=[new up({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=O(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new up({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=O(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=O(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function vr(r,e=.001,t){return new Eg({...yT(r,e),...t??{}})}function Te(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new D(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}var Sg=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=e,i+=u,i>l||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var wT=45,sK=15,wf=new Sg;function Ag(r){if(!(r.length>sK))return wf.new(r).parseWith(()=>wf.readIPv4Addr())}function _g(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wT))return wf.new(r).parseWith(()=>wf.readIPv6Addr())}function xf(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>wT)return;let t=wf.new(r).parseWith(()=>wf.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}function xT(r,e,t){let n=0;for(let o of r)if(!(n<e)){if(n>t)break;if(o!==255)return!1;n++}return!0}function bT(r,e,t,n){let o=0;for(let i of r)if(!(o<t)){if(o>n)break;if(i!==e[o])return!1;o++}return!0}function k7(r){switch(r.length){case ol:return r.join(".");case il:{let e=[];for(let t=0;t<r.length;t++)t%2===0&&e.push(r[t].toString(16).padStart(2,"0")+r[t+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function vT(r){let e=0;for(let[t,n]of r.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=t+1;o<r.length;o++)if(r[o]!=0)return-1;break}return e}function ET(r){let e="0x";for(let t of r)e+=(t>>4).toString(16)+(t&15).toString(16);return e}var ol=4,il=16,qie=parseInt("0xFFFF",16),aK=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function fp(r,e){e.length===il&&r.length===ol&&xT(e,0,11)&&(e=e.slice(12)),e.length===ol&&r.length===il&&bT(r,aK,0,11)&&(r=r.slice(12));let t=r.length;if(t!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=r[o]&e[o];return n}function ST(r,e){if(typeof e=="string"&&(e=xf(e)),e==null)throw new Error("Invalid ip");if(e.length!==r.network.length)return!1;for(let t=0;t<e.length;t++)if((r.network[t]&r.mask[t])!==(e[t]&r.mask[t]))return!1;return!0}function P7(r){let[e,t]=r.split("/");if(!e||!t)throw new Error("Failed to parse given CIDR: "+r);let n=ol,o=Ag(e);if(o==null&&(n=il,o=_g(e),o==null))throw new Error("Failed to parse given CIDR: "+r);let i=parseInt(t,10);if(Number.isNaN(i)||String(i).length!==t.length||i<0||i>n*8)throw new Error("Failed to parse given CIDR: "+r);let s=R7(i,8*n);return{network:fp(o,s),mask:s}}function R7(r,e){if(e!==8*ol&&e!==8*il)throw new Error("Invalid CIDR mask");if(r<0||r>e)throw new Error("Invalid CIDR mask");let t=e/8,n=new Uint8Array(t);for(let o=0;o<t;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var sl=class{constructor(e,t){if(t==null)({network:this.network,mask:this.mask}=P7(e));else{let n=xf(e);if(n==null)throw new Error("Failed to parse network");t=String(t);let o=parseInt(t,10);if(Number.isNaN(o)||String(o).length!==t.length||o<0||o>n.length*8){let i=xf(t);if(i==null)throw new Error("Failed to parse mask");this.mask=i}else this.mask=R7(o,8*n.length);this.network=fp(n,this.mask)}}contains(e){return ST({network:this.network,mask:this.mask},e)}toString(){let e=vT(this.mask),t=e!==-1?String(e):ET(this.mask);return k7(this.network)+"/"+t}};function AT(r,e){return new sl(r).contains(e)}function Tg(r){try{let e=Te(r);switch(e.type){case"ip6":return AT("2000::/3",e.host);default:return!1}}catch{return!1}}function _T(r){try{let e=Te(r);switch(e.type){case"ip4":return e.host.startsWith("169.254.");case"ip6":return e.host.toLowerCase().startsWith("fe80");default:return!1}}catch{return!1}}function TT(r){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(r)||/^::1$/.test(r)}function dp(r){try{let e=Te(r);switch(e.type){case"ip4":case"ip6":return TT(e.host);default:return!1}}catch{return!1}}function kr(r){try{return Te(r),!0}catch{return!1}}function oi(r){return!!Ag(r)}function Cg(r){return!!_g(r)}var IT=gt(CT(),1),cK=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],lK=cK.map(r=>new IT.Netmask(r));function O7(r){for(let e of lK)if(e.contains(r))return!0;return!1}function uK(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function fK(r){let e=r.split(":");if(e.length<2)return!1;let t=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(t.substring(0,2),16)}.${parseInt(t.substring(2),16)}`;return O7(o)}function dK(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function hK(r){let e=r.split(":"),t=e[e.length-1];return O7(t)}function pK(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function bf(r){if(oi(r))return O7(r);if(uK(r))return fK(r);if(dK(r))return hK(r);if(Cg(r))return pK(r)}function Kt(r){try{let e=Te(r);switch(e.type){case"ip4":case"ip6":return bf(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function Ke(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ig=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},vf=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ig(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Ig(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var D7=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ur(r={}){return mK(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function mK(r,e){e=e??{};let t=e.onEnd,n=new vf,o,i,s,a=Ke(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,x)=>{i=v=>{i=null,n.push(v);try{w(r(n))}catch(E){x(E)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ke()})}},l=w=>i!=null?i(w):(n.push(w),o),u=w=>(n=new vf,i!=null?i({error:w}):(n.push({error:w}),o)),f=w=>{if(s)return o;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:w})},h=w=>s?o:(s=!0,w!=null?u(w):l({done:!0})),d=()=>(n=new vf,h(),{done:!0}),m=w=>(h(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:m,push:f,end:h,get readableLength(){return n.size},onEmpty:async w=>{let x=w?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let v,E;x!=null&&(v=new Promise((I,U)=>{E=()=>{U(new D7)},x.addEventListener("abort",E)}));try{await Promise.race([a.promise,v])}finally{E!=null&&x!=null&&x?.removeEventListener("abort",E)}}},t==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(w){return y.throw(w),t!=null&&(t(w),t=void 0),{done:!0}},return(){return y.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(w){return y.end(w),t!=null&&(t(w),t=void 0),o},get readableLength(){return y.readableLength},onEmpty:w=>y.onEmpty(w)},o}var N7=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},L7=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},kT=r=>globalThis.DOMException===void 0?new L7(r):new DOMException(r),PT=r=>{let e=r.reason===void 0?kT("This operation was aborted."):r.reason;return e instanceof Error?e:kT(e)};function B7(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((u,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&f(PT(d)),a=()=>{f(PT(d))},d.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(u,f);return}let h=new N7;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(d){f(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(h.message=o??`Promise timed out after ${t} milliseconds`,f(h))},t),(async()=>{try{u(await r)}catch(d){f(d)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var gK=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function yK(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:u}=gK(r),f=async(...d)=>{let m=t.multiArgs?d:d[0];if(t.filter)try{if(!await t.filter(m))return}catch(y){n(),s(y);return}c.push(m),t.count===c.length&&(n(),i(c))},h=(...d)=>{n(),s(t.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,f);for(let d of t.rejectionEvents)a.includes(d)||u(d,h)};for(let d of a)l(d,f);for(let d of t.rejectionEvents)a.includes(d)||l(d,h);t.signal&&t.signal.addEventListener("abort",()=>{h(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=B7(o,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Ze(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=yK(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function _s(r,e){let t,n=function(){let o=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var kg=class extends Error{remainingPoints;msBeforeNext;consumedPoints;isFirstInDuration;constructor(e="Rate limit exceeded",t){super(e),this.name="RateLimitError",this.remainingPoints=t.remainingPoints,this.msBeforeNext=t.msBeforeNext,this.consumedPoints=t.consumedPoints,this.isFirstInDuration=t.isFirstInDuration}},Pg=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},al=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Rg=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Og=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function wK(r){return r.reason}async function rt(r,e,t){if(e==null)return r;let n=t?.translateError??wK;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Dg=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Ke(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new sn)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function xK(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ng=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=xK(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new sn),this.cleanup())}async join(e={}){let t=new Dg(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await rt(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Gt=class extends _e{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=_s(this.emitEmpty.bind(this),1),this.emitIdle=_s(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Pg;let n=new Ng(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new sn)}),this.clear()}async onEmpty(e){this.size!==0&&await Ze(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Ze(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ze(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=ur({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},o=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new sn("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var bK=Math.pow(2,20)*4,Pa=class extends _e{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??bK,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new se,this.writeBuffer=new se,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new Og)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),rt(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ur(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let n=i=>{e.end(i.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Ci(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new G0(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new qu;this.dispatchEvent(new X0(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ga))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let i=this.writeBuffer.sublist(0,o),s=new se(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new W0(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new kh(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new kh(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Ra=class extends Pa{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ze(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ze(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Ef(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Oa=class extends _e{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let n=s=>{try{this.onData(s.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await rt(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new Qo;let t=this.onCreateStream({...this.streamOptions,...e});return Ef(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new Rg(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=n=>{let o=this.streams.findIndex(i=>i===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var Da=class extends Pa{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ze(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Ze(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var Sf=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,t){return 1-Math.exp(-(e-t)/this.timeSpan)}push(e,t=Date.now()){if(this.previousTime!=null){let n=this.alpha(t,this.previousTime),o=e-this.movingAverage,i=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*i),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=t}};var vK=1.2,EK=2,SK=5e3,AK=6e4,_K=5e3,ii=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let t=e.interval??_K;this.success=new Sf(t),this.failure=new Sf(t),this.next=new Sf(t),this.failureMultiplier=e.failureMultiplier??EK,this.timeoutMultiplier=e.timeoutMultiplier??vK,this.minTimeout=e.minTimeout??SK,this.maxTimeout=e.maxTimeout??AK,e.metricName!=null&&(this.metric=e.metrics?.registerMetricGroup(e.metricName))}getTimeoutSignal(e={}){let t=Math.round(this.next.movingAverage*(e.timeoutFactor??this.timeoutMultiplier));t<this.minTimeout&&(t=this.minTimeout),t>this.maxTimeout&&(t=this.maxTimeout);let n=AbortSignal.timeout(t),o=Re([e.signal,n]);return o.start=Date.now(),o.timeout=t,o}cleanUp(e){let t=Date.now()-e.start;e.aborted?(this.failure.push(t),this.next.push(t*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:t})):(this.success.push(t),this.next.push(t),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:t}))}};var Pr=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ts=class extends Error{static name="ValidationError";name="ValidationError"},Lg=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Bg=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function U7(r){return e=>H(e,r)}function F7(r){return e=>O(e,r)}function Af(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function cl(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function RT(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=O(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=cl(n);return dt([t,o],t.length+o.length)}function OT(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=yr.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=cl(n);return dt([t,o],t.length+o.length)}function $7(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=H(e,"base32"),o=Af(t);return`${n}:${o}`}var H7=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new Pr("Invalid byte value in IP address");e[n]=o}),e},DT=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=oi(t[n]),s;i&&(s=H7(t[n]),t[n]=H(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,H(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new Pr("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},NT=function(r){if(r.byteLength!==4)throw new Pr("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},LT=function(r){if(r.byteLength!==16)throw new Pr("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Pr(`Invalid IPv6 address "${t}"`)}};function BT(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Pr(`Invalid IPv6 address "${r}"`)}}var M7=Object.values($c).map(r=>r.decoder),TK=(function(){let r=M7[0].or(M7[1]);return M7.slice(2).forEach(e=>r=r.or(e)),r})();function MT(r){return TK.decode(r)}function UT(r){return e=>r.encoder.encode(e)}function CK(r){if(parseInt(r).toString()!==r)throw new Ts("Value must be an integer")}function IK(r){if(r<0)throw new Ts("Value must be a positive integer, or zero")}function kK(r){return e=>{if(e>r)throw new Ts(`Value must be smaller than or equal to ${r}`)}}function PK(...r){return e=>{for(let t of r)t(e)}}var pp=PK(CK,IK,kK(65535));var Er=-1,K7=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Bg(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ks=new K7,zK=[{code:4,name:"ip4",size:32,valueToBytes:H7,bytesToValue:NT,validate:r=>{if(!oi(r))throw new Ts(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:273,name:"udp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:33,name:"dccp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:41,name:"ip6",size:128,valueToBytes:DT,bytesToValue:LT,stringToValue:BT,validate:r=>{if(!Cg(r))throw new Ts(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:Er},{code:43,name:"ipcidr",size:8,bytesToValue:U7("base10"),valueToBytes:F7("base10")},{code:53,name:"dns",size:Er},{code:54,name:"dns4",size:Er},{code:55,name:"dns6",size:Er},{code:56,name:"dnsaddr",size:Er},{code:132,name:"sctp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:Er,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:Er,bytesToValue:U7("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?F7("base58btc")(r):Z.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:$7,valueToBytes:RT},{code:445,name:"onion3",size:296,bytesToValue:$7,valueToBytes:OT},{code:446,name:"garlic64",size:Er},{code:447,name:"garlic32",size:Er},{code:448,name:"tls"},{code:449,name:"sni",size:Er},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:Er,bytesToValue:UT(Fc),valueToBytes:MT},{code:480,name:"http"},{code:481,name:"http-path",size:Er,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:Er}];zK.forEach(r=>{ks.addProtocol(r)});function FT(r){let e=[],t=0;for(;t<r.length;){let n=Wn(r,t),o=ks.getProtocol(n),i=$e(n),s=jK(o,r,t+i),a=0;s>0&&o.size===Er&&(a=$e(s));let c=i+a+s,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let u=t+i+a,f=r.subarray(u,u+s);l.value=o.bytesToValue?.(f)??H(f)}e.push(l),t+=c}return e}function $T(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=ks.getProtocol(n.code),i=$e(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??O(n.value),a=s.byteLength,o.size===Er&&(c=$e(a)));let l=new Uint8Array(i+c+a),u=0;hf(n.code,l,u),u+=i,s!=null&&(o.size===Er&&(hf(a,l,u),u+=c),l.set(s,u)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return dt(t,e)}function HT(r){if(r.charAt(0)!=="/")throw new Pr('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=ks.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new Pr(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Pr(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new Pr("Incomplete multiaddr");return e}function KT(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=ks.getProtocol(e.code);if(t==null)throw new Pr(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function jK(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Wn(e,t)}var WK=Symbol.for("nodejs.util.inspect.custom"),Q7=Symbol.for("@multiformats/multiaddr");function GK(r){if(r==null&&(r="/"),Mi(r))return r.getComponents();if(r instanceof Uint8Array)return FT(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),HT(r);if(Array.isArray(r))return r;throw new Pr("Must be a string, Uint8Array, Component[], or another Multiaddr")}var $g=class r{[Q7]=!0;#t;#e;#r;constructor(e="/",t={}){this.#t=GK(e),t.validate!==!1&&XK(this)}get bytes(){return this.#r==null&&(this.#r=$T(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=KT(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#t,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Lg(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===e){t=n;break}return new r(this.#t.slice(0,t),{validate:!1})}equals(e){return me(this.bytes,e.bytes)}[WK](){return`Multiaddr(${this.toString()})`}};function XK(r){r.getComponents().forEach(e=>{let t=ks.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Mi(r){return!!r?.[Q7]}function ie(r){return new $g(r)}var Z7=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ke(),this.haveNext=Ke()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ke(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ke(),await rt(this.readNext.promise,t?.signal,t)}};function VT(){return new Z7}function YK(r){return r[Symbol.asyncIterator]!=null}async function QK(r,e,t){try{await Promise.all(r.map(async n=>{for await(let o of n)await e.push(o,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*ZK(r){let e=new AbortController,t=VT();QK(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*JK(r){for(let e of r)yield*e}function eV(...r){let e=[];for(let t of r)YK(t)||e.push(t);return e.length===r.length?JK(e):ZK(r)}var dn=eV;function Xn(r,...e){if(r==null)throw new Error("Empty pipeline");if(J7(r)){let n=r;r=()=>n.source}else if(zT(r)||qT(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&J7(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)J7(t[n])&&(t[n]=rV(t[n]));return tV(...t)}var tV=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},qT=r=>r?.[Symbol.asyncIterator]!=null,zT=r=>r?.[Symbol.iterator]!=null,J7=r=>r==null?!1:r.sink!=null&&r.source!=null,rV=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=ur({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(qT(i))o=async function*(){yield*i,n.end()};else if(zT(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return dn(n,o())}return r.source};var nV=4194304,Hg=class extends Error{static name="UnwrappedError";name="UnwrappedError"},bp=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},tx=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},rx=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function oV(r){return typeof r?.closeRead=="function"}function iV(r){return typeof r?.close=="function"}function ex(r){return oV(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:iV(r)?r.status!=="open":!1}function sV(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Kg(r,e){let t=e?.maxBufferSize??nV,n=new se,o,i=!1;if(!sV(r))throw new D("Argument should be a Stream or a Multiaddr");let s=u=>{if(n.append(u.data),n.byteLength>t){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${t}`))}o?.resolve()};r.addEventListener("message",s);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(u){if(i===!0)throw new Hg("Stream was unwrapped");if(ex(r)){if(u?.bytes==null)return null;if(n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new al(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let f=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await rt(o.promise,u?.signal),ex(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(ex(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,h),new al(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return l.read(u)}let d=n.sublist(0,h);return n.consume(h),d},async write(u,f){if(i===!0)throw new Hg("Stream was unwrapped");r.send(u)||await Ze(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return l}function La(r,e={}){let t=Kg(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=$e(e.maxDataLength));let n=e?.lengthDecoder??Wn,o=e?.lengthEncoder??Wr;return{async read(s){let a=-1,c=new se;for(;;){let u=await t.read({...s,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new bp("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new rx(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new tx(`Message length too long - ${a} > ${e.maxDataLength}`);let l=await t.read({...s,bytes:a});if(l==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new al(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(l.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",l.byteLength,a),new al(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(s,a){await t.write(new se(o(s.byteLength),s),a)},async writeV(s,a){let c=new se(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function bt(r,e){let t=La(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var aV=1024*1024*4,cV=1024*1024*4,Vg=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new se,this.maxBufferSize=e.maxBufferSize??aV,this.maxDataLength=e.maxDataLength??cV,this.lengthDecoder=e.lengthDecoder??Wn,this.encodingLength=e.encodingLength??$e}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new D(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let t;try{t=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(t<0||t>this.maxDataLength)throw new bp("Invalid message length");let n=this.encodingLength(t),o=n+t;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};var lV=["string","number","bigint","symbol"],uV=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function jT(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(lV.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(fV(r))return"Buffer";let t=dV(r);return t||"Object"}function fV(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function dV(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(uV.includes(e))return e}var A=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};A.uint=new A(0,"uint",!0);A.negint=new A(1,"negint",!0);A.bytes=new A(2,"bytes",!0);A.string=new A(3,"string",!0);A.array=new A(4,"array",!1);A.map=new A(5,"map",!1);A.tag=new A(6,"tag",!1);A.float=new A(7,"float",!0);A.false=new A(7,"false",!0);A.true=new A(7,"true",!0);A.null=new A(7,"null",!0);A.undefined=new A(7,"undefined",!0);A.break=new A(7,"break",!0);var j=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var If=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",hV=new TextDecoder,pV=new TextEncoder;function qg(r){return If&&globalThis.Buffer.isBuffer(r)}function vp(r){return r instanceof Uint8Array?qg(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var YT=If?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):GT(r,e,t):(r,e,t)=>t-e>64?hV.decode(r.subarray(e,t)):GT(r,e,t),zg=If?r=>r.length>64?globalThis.Buffer.from(r):WT(r):r=>r.length>64?pV.encode(r):WT(r),Ui=r=>Uint8Array.from(r),kf=If?(r,e,t)=>qg(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),QT=If?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),vp(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},ZT=If?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function jg(r,e){if(qg(r)&&qg(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function WT(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function GT(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],l=r[e+3],(a&192)===128&&(c&192)===128&&(l&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|l&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return nx(n)}var XT=4096;function nx(r){let e=r.length;if(e<=XT)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=XT));return t}var mV=256,Ep=class{constructor(e=mV){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=ZT(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=kf(n,0,this.cursor)}else t=QT(this.chunks,this.cursor);return e&&this.reset(),t}};var ge="CBOR decode error:",Ps="CBOR encode error:",Sp=[];Sp[23]=1;Sp[24]=2;Sp[25]=3;Sp[26]=5;Sp[27]=9;function Rs(r,e,t){if(r.length-e<t)throw new Error(`${ge} not enough data for type`)}var Sr=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Yn(r,e,t){Rs(r,e,1);let n=r[e];if(t.strict===!0&&n<Sr[0])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);return n}function Qn(r,e,t){Rs(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Sr[1])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);return n}function Zn(r,e,t){Rs(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Sr[2])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);return n}function Jn(r,e,t){Rs(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<Sr[3])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${ge} integers outside of the safe integer range are not supported`)}function JT(r,e,t,n){return new j(A.uint,Yn(r,e+1,n),2)}function eC(r,e,t,n){return new j(A.uint,Qn(r,e+1,n),3)}function tC(r,e,t,n){return new j(A.uint,Zn(r,e+1,n),5)}function rC(r,e,t,n){return new j(A.uint,Jn(r,e+1,n),9)}function Po(r,e){return Rr(r,0,e.value)}function Rr(r,e,t){if(t<Sr[0]){let n=Number(t);r.push([e|n])}else if(t<Sr[1]){let n=Number(t);r.push([e|24,n])}else if(t<Sr[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Sr[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<Sr[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${ge} encountered BigInt larger than allowable range`)}}Po.encodedSize=function(e){return Rr.encodedSize(e.value)};Rr.encodedSize=function(e){return e<Sr[0]?1:e<Sr[1]?2:e<Sr[2]?3:e<Sr[3]?5:9};Po.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function nC(r,e,t,n){return new j(A.negint,-1-Yn(r,e+1,n),2)}function oC(r,e,t,n){return new j(A.negint,-1-Qn(r,e+1,n),3)}function iC(r,e,t,n){return new j(A.negint,-1-Zn(r,e+1,n),5)}var ox=BigInt(-1),sC=BigInt(1);function aC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new j(A.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${ge} integers outside of the safe integer range are not supported`);return new j(A.negint,ox-BigInt(o),9)}function Wg(r,e){let t=e.value,n=typeof t=="bigint"?t*ox-sC:t*-1-1;Rr(r,e.type.majorEncoded,n)}Wg.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*ox-sC:t*-1-1;return n<Sr[0]?1:n<Sr[1]?2:n<Sr[2]?3:n<Sr[3]?5:9};Wg.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Ap(r,e,t,n){Rs(r,e,t+n);let o=kf(r,e+t,e+t+n);return new j(A.bytes,o,t+n)}function cC(r,e,t,n){return Ap(r,e,1,t)}function lC(r,e,t,n){return Ap(r,e,2,Yn(r,e+1,n))}function uC(r,e,t,n){return Ap(r,e,3,Qn(r,e+1,n))}function fC(r,e,t,n){return Ap(r,e,5,Zn(r,e+1,n))}function dC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer bytes lengths not supported`);return Ap(r,e,9,o)}function Gg(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===A.string?zg(r.value):r.value),r.encodedBytes}function Pf(r,e){let t=Gg(e);Rr(r,e.type.majorEncoded,t.length),r.push(t)}Pf.encodedSize=function(e){let t=Gg(e);return Rr.encodedSize(t.length)+t.length};Pf.compareTokens=function(e,t){return yV(Gg(e),Gg(t))};function yV(r,e){return r.length<e.length?-1:r.length>e.length?1:jg(r,e)}function _p(r,e,t,n,o){let i=t+n;Rs(r,e,i);let s=new j(A.string,YT(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=kf(r,e+t,e+i)),s}function hC(r,e,t,n){return _p(r,e,1,t,n)}function pC(r,e,t,n){return _p(r,e,2,Yn(r,e+1,n),n)}function mC(r,e,t,n){return _p(r,e,3,Qn(r,e+1,n),n)}function gC(r,e,t,n){return _p(r,e,5,Zn(r,e+1,n),n)}function yC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer string lengths not supported`);return _p(r,e,9,o,n)}var wC=Pf;function Rf(r,e,t,n){return new j(A.array,n,t)}function xC(r,e,t,n){return Rf(r,e,1,t)}function bC(r,e,t,n){return Rf(r,e,2,Yn(r,e+1,n))}function vC(r,e,t,n){return Rf(r,e,3,Qn(r,e+1,n))}function EC(r,e,t,n){return Rf(r,e,5,Zn(r,e+1,n))}function SC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer array lengths not supported`);return Rf(r,e,9,o)}function AC(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${ge} indefinite length items not allowed`);return Rf(r,e,1,1/0)}function Xg(r,e){Rr(r,A.array.majorEncoded,e.value)}Xg.compareTokens=Po.compareTokens;Xg.encodedSize=function(e){return Rr.encodedSize(e.value)};function Of(r,e,t,n){return new j(A.map,n,t)}function _C(r,e,t,n){return Of(r,e,1,t)}function TC(r,e,t,n){return Of(r,e,2,Yn(r,e+1,n))}function CC(r,e,t,n){return Of(r,e,3,Qn(r,e+1,n))}function IC(r,e,t,n){return Of(r,e,5,Zn(r,e+1,n))}function kC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer map lengths not supported`);return Of(r,e,9,o)}function PC(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${ge} indefinite length items not allowed`);return Of(r,e,1,1/0)}function Yg(r,e){Rr(r,A.map.majorEncoded,e.value)}Yg.compareTokens=Po.compareTokens;Yg.encodedSize=function(e){return Rr.encodedSize(e.value)};function RC(r,e,t,n){return new j(A.tag,t,1)}function OC(r,e,t,n){return new j(A.tag,Yn(r,e+1,n),2)}function DC(r,e,t,n){return new j(A.tag,Qn(r,e+1,n),3)}function NC(r,e,t,n){return new j(A.tag,Zn(r,e+1,n),5)}function LC(r,e,t,n){return new j(A.tag,Jn(r,e+1,n),9)}function Qg(r,e){Rr(r,A.tag.majorEncoded,e.value)}Qg.compareTokens=Po.compareTokens;Qg.encodedSize=function(e){return Rr.encodedSize(e.value)};var SV=20,AV=21,_V=22,TV=23;function BC(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${ge} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new j(A.null,null,1):new j(A.undefined,void 0,1)}function MC(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${ge} indefinite length items not allowed`);return new j(A.break,void 0,1)}function ix(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${ge} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${ge} Infinity values are not supported`)}return new j(A.float,r,e)}function UC(r,e,t,n){return ix(sx(r,e+1),3,n)}function FC(r,e,t,n){return ix(ax(r,e+1),5,n)}function $C(r,e,t,n){return ix(qC(r,e+1),9,n)}function Zg(r,e,t){let n=e.value;if(n===!1)r.push([A.float.majorEncoded|SV]);else if(n===!0)r.push([A.float.majorEncoded|AV]);else if(n===null)r.push([A.float.majorEncoded|_V]);else if(n===void 0)r.push([A.float.majorEncoded|TV]);else{let o,i=!1;(!t||t.float64!==!0)&&(KC(n),o=sx(ai,1),n===o||Number.isNaN(n)?(ai[0]=249,r.push(ai.slice(0,3)),i=!0):(VC(n),o=ax(ai,1),n===o&&(ai[0]=250,r.push(ai.slice(0,5)),i=!0))),i||(CV(n),o=qC(ai,1),ai[0]=251,r.push(ai.slice(0,9)))}}Zg.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){KC(n);let o=sx(ai,1);if(n===o||Number.isNaN(n))return 3;if(VC(n),o=ax(ai,1),n===o)return 5}return 9};var HC=new ArrayBuffer(9),Ro=new DataView(HC,1),ai=new Uint8Array(HC,0);function KC(r){if(r===1/0)Ro.setUint16(0,31744,!1);else if(r===-1/0)Ro.setUint16(0,64512,!1);else if(Number.isNaN(r))Ro.setUint16(0,32256,!1);else{Ro.setFloat32(0,r);let e=Ro.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Ro.setUint16(0,31744,!1);else if(t===0)Ro.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Ro.setUint16(0,0):o<-14?Ro.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Ro.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function sx(r,e){if(r.length-e<2)throw new Error(`${ge} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function VC(r){Ro.setFloat32(0,r,!1)}function ax(r,e){if(r.length-e<4)throw new Error(`${ge} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function CV(r){Ro.setFloat64(0,r,!1)}function qC(r,e){if(r.length-e<8)throw new Error(`${ge} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Zg.compareTokens=Po.compareTokens;function Je(r,e,t){throw new Error(`${ge} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Jg(r){return()=>{throw new Error(`${ge} ${r}`)}}var oe=[];for(let r=0;r<=23;r++)oe[r]=Je;oe[24]=JT;oe[25]=eC;oe[26]=tC;oe[27]=rC;oe[28]=Je;oe[29]=Je;oe[30]=Je;oe[31]=Je;for(let r=32;r<=55;r++)oe[r]=Je;oe[56]=nC;oe[57]=oC;oe[58]=iC;oe[59]=aC;oe[60]=Je;oe[61]=Je;oe[62]=Je;oe[63]=Je;for(let r=64;r<=87;r++)oe[r]=cC;oe[88]=lC;oe[89]=uC;oe[90]=fC;oe[91]=dC;oe[92]=Je;oe[93]=Je;oe[94]=Je;oe[95]=Jg("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)oe[r]=hC;oe[120]=pC;oe[121]=mC;oe[122]=gC;oe[123]=yC;oe[124]=Je;oe[125]=Je;oe[126]=Je;oe[127]=Jg("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)oe[r]=xC;oe[152]=bC;oe[153]=vC;oe[154]=EC;oe[155]=SC;oe[156]=Je;oe[157]=Je;oe[158]=Je;oe[159]=AC;for(let r=160;r<=183;r++)oe[r]=_C;oe[184]=TC;oe[185]=CC;oe[186]=IC;oe[187]=kC;oe[188]=Je;oe[189]=Je;oe[190]=Je;oe[191]=PC;for(let r=192;r<=215;r++)oe[r]=RC;oe[216]=OC;oe[217]=DC;oe[218]=NC;oe[219]=LC;oe[220]=Je;oe[221]=Je;oe[222]=Je;oe[223]=Je;for(let r=224;r<=243;r++)oe[r]=Jg("simple values are not supported");oe[244]=Je;oe[245]=Je;oe[246]=Je;oe[247]=BC;oe[248]=Jg("simple values are not supported");oe[249]=UC;oe[250]=FC;oe[251]=$C;oe[252]=Je;oe[253]=Je;oe[254]=Je;oe[255]=MC;var ci=[];for(let r=0;r<24;r++)ci[r]=new j(A.uint,r,1);for(let r=-1;r>=-24;r--)ci[31-r]=new j(A.negint,r,1);ci[64]=new j(A.bytes,new Uint8Array(0),1);ci[96]=new j(A.string,"",1);ci[128]=new j(A.array,0,1);ci[160]=new j(A.map,0,1);ci[244]=new j(A.false,!1,1);ci[245]=new j(A.true,!0,1);ci[246]=new j(A.null,null,1);function e2(r){switch(r.type){case A.false:return Ui([244]);case A.true:return Ui([245]);case A.null:return Ui([246]);case A.bytes:return r.value.length?void 0:Ui([64]);case A.string:return r.value===""?Ui([96]):void 0;case A.array:return r.value===0?Ui([128]):void 0;case A.map:return r.value===0?Ui([160]):void 0;case A.uint:return r.value<24?Ui([Number(r.value)]):void 0;case A.negint:if(r.value>=-24)return Ui([31-Number(r.value)])}}var kV={float64:!1,mapSorter:RV,quickEncodeToken:e2},jC=Object.freeze({float64:!0,mapSorter:OV,quickEncodeToken:e2});function lx(){let r=[];return r[A.uint.major]=Po,r[A.negint.major]=Wg,r[A.bytes.major]=Pf,r[A.string.major]=wC,r[A.array.major]=Xg,r[A.map.major]=Yg,r[A.tag.major]=Qg,r[A.float.major]=Zg,r}var ux=lx(),cx=new Ep,t2=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Ps} object contains circular references`);return new r(t,e)}},Ba={null:new j(A.null,null),undefined:new j(A.undefined,void 0),true:new j(A.true,!0),false:new j(A.false,!1),emptyArray:new j(A.array,0),emptyMap:new j(A.map,0)},Ma={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new j(A.float,r):r>=0?new j(A.uint,r):new j(A.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new j(A.uint,r):new j(A.negint,r)},Uint8Array(r,e,t,n){return new j(A.bytes,r)},string(r,e,t,n){return new j(A.string,r)},boolean(r,e,t,n){return r?Ba.true:Ba.false},null(r,e,t,n){return Ba.null},undefined(r,e,t,n){return Ba.undefined},ArrayBuffer(r,e,t,n){return new j(A.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new j(A.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Ba.emptyArray,new j(A.break)]:Ba.emptyArray;n=t2.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Tp(s,t,n);return t.addBreakTokens?[new j(A.array,r.length),o,new j(A.break)]:[new j(A.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[Ba.emptyMap,new j(A.break)]:Ba.emptyMap;n=t2.createCheck(n,r);let a=[],c=0;for(let l of i)a[c++]=[Tp(l,t,n),Tp(o?r.get(l):r[l],t,n)];return PV(a,t),t.addBreakTokens?[new j(A.map,s),a,new j(A.break)]:[new j(A.map,s),a]}};Ma.Map=Ma.Object;Ma.Buffer=Ma.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ma[`${r}Array`]=Ma.DataView;function Tp(r,e={},t){let n=jT(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||Ma[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=Ma[n];if(!i)throw new Error(`${Ps} unsupported type: ${n}`);return i(r,n,e,t)}function PV(r,e){e.mapSorter&&r.sort(e.mapSorter)}function RV(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=ux[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function OV(r,e){if(r[0]instanceof j&&e[0]instanceof j){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=zC(t.value)),n._keyBytes||(n._keyBytes=zC(n.value)),jg(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function zC(r){return r2(r,ux,jC)}function WC(r,e,t,n){if(Array.isArray(e))for(let o of e)WC(r,o,t,n);else t[e.type.major](r,e,n)}function r2(r,e,t){let n=Tp(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),a=new Ep(s);if(i(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return vp(a.chunks[0])}}return cx.reset(),WC(cx,n,e,t),cx.toBytes(!0)}function Ua(r,e){return e=Object.assign({},kV,e),r2(r,ux,e)}var DV={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},n2=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=ci[e];if(t===void 0){let n=oe[e];if(!n)throw new Error(`${ge} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Cp=Symbol.for("DONE"),o2=Symbol.for("BREAK");function NV(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Df(e,t);if(i===o2){if(r.value===1/0)break;throw new Error(`${ge} got unexpected break to lengthed array`)}if(i===Cp)throw new Error(`${ge} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function LV(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Df(e,t);if(a===o2){if(r.value===1/0)break;throw new Error(`${ge} got unexpected break to lengthed map`)}if(a===Cp)throw new Error(`${ge} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${ge} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${ge} found repeat map key "${a}"`);let c=Df(e,t);if(c===Cp)throw new Error(`${ge} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Df(r,e){if(r.done())return Cp;let t=r.next();if(t.type===A.break)return o2;if(t.type.terminal)return t.value;if(t.type===A.array)return NV(t,r,e);if(t.type===A.map)return LV(t,r,e);if(t.type===A.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Df(r,e);return e.tags[t.value](n)}throw new Error(`${ge} tag not supported (${t.value})`)}throw new Error("unsupported")}function fx(r,e){if(!(r instanceof Uint8Array))throw new Error(`${ge} data to decode must be a Uint8Array`);e=Object.assign({},DV,e);let t=e.tokenizer||new n2(r,e),n=Df(t,e);if(n===Cp)throw new Error(`${ge} did not find any content to decode`);if(n===o2)throw new Error(`${ge} got unexpected break`);return[n,r.subarray(t.pos())]}function eo(r,e){let[t,n]=fx(r,e);if(n.length>0)throw new Error(`${ge} too many terminals, data makes no sense`);return t}var i2=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nf=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},s2=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ip=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function a2(r){return r[Symbol.asyncIterator]!=null}function GC(r,e){if(r.byteLength>e)throw new Nf("Message length too long")}var l2=r=>{let e=$e(r),t=Bt(e);return Wr(r,t),l2.bytes=e,t};l2.bytes=0;function Os(r,e){e=e??{};let t=e.lengthEncoder??l2,n=e?.maxDataLength??4194304;function*o(i){GC(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return a2(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}Os.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??l2,n=e?.maxDataLength??4194304;return GC(r,n),new se(t(r.byteLength),r)};var fl;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(fl||(fl={}));var hx=r=>{let e=Wn(r);return hx.bytes=$e(e),e};hx.bytes=0;function dl(r,e){let t=new se,n=fl.LENGTH,o=-1,i=e?.lengthDecoder??hx,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===fl.LENGTH)try{if(o=i(t),o<0)throw new i2("Invalid message length");if(o>a)throw new Nf("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=fl.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new s2("Message length length too long");break}throw l}if(n===fl.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=fl.LENGTH}}}return a2(r)?(async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new Ip("Unexpected end of input")})():(function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new Ip("Unexpected end of input")})()}dl.fromReader=(r,e)=>{let t=1,n=(async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}})();return dl(n,{...e??{},onLength:i=>{t=i}})};function MV(r,e){if(typeof r=="string")return UV(r);if(typeof r=="number")return HV(r,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}var u2=MV;function UV(r){if(typeof r!="string"||r.length===0||r.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,o=parseFloat(t),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function FV(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function $V(r){let e=Math.abs(r);return e>=315576e5?hl(r,e,315576e5,"year"):e>=26298e5?hl(r,e,26298e5,"month"):e>=6048e5?hl(r,e,6048e5,"week"):e>=864e5?hl(r,e,864e5,"day"):e>=36e5?hl(r,e,36e5,"hour"):e>=6e4?hl(r,e,6e4,"minute"):e>=1e3?hl(r,e,1e3,"second"):`${r} ms`}function HV(r,e){if(typeof r!="number"||!Number.isFinite(r))throw Error("Value provided to ms.format() must be of type number.");return e?.long?$V(r):FV(r)}function hl(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function px(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=u2,t.destroy=l,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let f=0;for(let h=0;h<u.length;h++)f=(f<<5)-f+u.charCodeAt(h),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(u,f){let h,d=null,m,y;function w(...x){if(!w.enabled)return;let v=w,E=Number(new Date),I=E-(h||E);v.diff=I,v.prev=h,v.curr=E,h=E,x[0]=t.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let U=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,(M,T)=>{if(M==="%%")return"%";U++;let k=t.formatters[T];if(typeof k=="function"){let z=x[U];M=k.call(v,z),x.splice(U,1),U--}return M}),t.formatArgs.call(v,x),f?.onLog!=null&&f.onLog(...x),(v.log||t.log).apply(v,x)}return w.namespace=u,w.useColors=t.useColors(),w.color=t.selectColor(u),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(m!==t.namespaces&&(m=t.namespaces,y=t.enabled(u)),y),set:x=>{d=x}}),typeof t.init=="function"&&t.init(w),w}function n(u,f){let h=t(this.namespace+(typeof f>"u"?":":f)+u);return h.log=this.log,h}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let f,h=(typeof u=="string"?u:"").split(/[\s,]+/),d=h.length;for(f=0;f<d;f++)h[f]&&(u=h[f].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.substr(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,h;for(f=0,h=t.skips.length;f<h;f++)if(t.skips[f].test(u))return!1;for(f=0,h=t.names.length;f<h;f++)if(t.names[f].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var f2=GV(),KV=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function VV(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function qV(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+u2(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var zV=console.debug??console.log??(()=>{});function jV(r){try{r?f2?.setItem("debug",r):f2?.removeItem("debug")}catch{}}function WV(){let r;try{r=f2?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function GV(){try{return localStorage}catch{}}function XV(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var YC=px({formatArgs:qV,save:jV,load:WV,useColors:VV,setupFormatters:XV,colors:KV,storage:f2,log:zV});var An=YC;An.formatters.b=r=>r==null?"undefined":Qe.baseEncode(r);An.formatters.t=r=>r==null?"undefined":yr.baseEncode(r);An.formatters.m=r=>r==null?"undefined":Zt.baseEncode(r);An.formatters.p=r=>r==null?"undefined":r.toString();An.formatters.c=r=>r==null?"undefined":r.toString();An.formatters.k=r=>r==null?"undefined":r.toString();An.formatters.a=r=>r==null?"undefined":r.toString();function QC(r,e=""){let t=ZC(r.message),n=ZC(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return y;function y(T,k,z){var W=this;if(!(W instanceof y))return new y(T,k,z);W.time=+T||0,W.nano=+k||0,W.year=+z||0,w(W)}function w(T){var k,z,W,$=T.year,S=T.time,C=T.nano,_=((C<0||a<=C)&&(C-=(z=Math.floor(C/a))*a,S+=z,z=1),$%e);return(S<-i||i<S||_)&&((k=l(S/o))&&($+=k*e,S-=k*o),(W=x(S)).setUTCFullYear(_+W.getUTCFullYear()),W=(S=+W)+(k=l(($-=_)/e))*o,k&&-i<=W&&W<=i&&($-=k*e,S=W),z=1),z&&(T.year=$,T.time=S,T.nano=C),T}function x(T){var k=new Date(0);return k.setTime(T),k}function v($,W){$=+$||0;var z=l((W=(W|0)*s)/n)+l($/n),W=W%n+$%n,$=l(W/n);return $&&(z+=$,W-=$*n),new y(1e3*W,0,z*e)}function E(T,k,z,W,$,S){return function(_,B){var G=w(this);_=_||new Array(8),U(_,B|=0);var F=Math.floor(G.time/1e3),G=G.year*(t*r/e),X=l(G/s)+l(F/s),G=G%s+F%s,F=Math.floor(G/s);return F&&(X+=F,G-=F*s),C(_,B+$,X),C(_,B+S,G),_};function C(_,B,X){_[B+T]=X>>24&255,_[B+k]=X>>16&255,_[B+z]=X>>8&255,_[B+W]=255&X}}function I(T,k,z,W,$,S){return function(_,B){U(_,B|=0);var X=C(_,B+$);return v(C(_,B+S),X)};function C(_,B){return 16777216*_[B+T]+(_[B+k]<<16|_[B+z]<<8|_[B+W])}}function U(T,k){if(T=T&&T.length,T==null)throw new TypeError("Invalid Buffer");if(T<k+8)throw new RangeError("Out of range")}function K(T){return(9<T?"":"0")+(0|T)}function M(T,k){return(c+(0|T)).substr(-k)}})()});var xP=Rt((X5e,wP)=>{"use strict";function dW(r){return r>=55296&&r<=56319}function hW(r){return r>=56320&&r<=57343}wP.exports=function(e,t,n){if(typeof t!="string")throw new Error("Input must be string");for(var o=t.length,i=0,s,a,c=0;c<o;c+=1){if(s=t.charCodeAt(c),a=t[c],dW(s)&&hW(t.charCodeAt(c+1))&&(c+=1,a+=t[c]),i+=e(a),i===n)return t.slice(0,c+1);if(i>n)return t.slice(0,c-a.length+1)}return t}});var vP=Rt((Y5e,bP)=>{"use strict";function pW(r){return r>=55296&&r<=56319}function mW(r){return r>=56320&&r<=57343}bP.exports=function(e){if(typeof e!="string")throw new Error("Input must be string");for(var t=e.length,n=0,o=null,i=null,s=0;s<t;s++)o=e.charCodeAt(s),mW(o)?i!=null&&pW(i)?n+=1:n+=3:o<=127?n+=1:o>=128&&o<=2047?n+=2:o>=2048&&o<=65535&&(n+=3),i=o;return n}});var SP=Rt((Q5e,EP)=>{"use strict";var gW=xP(),yW=vP();EP.exports=gW.bind(null,yW)});var TP=Rt((Z5e,_P)=>{"use strict";var wW=SP(),xW=/[\/\?<>\\:\*\|"]/g,bW=/[\x00-\x1f\x80-\x9f]/g,vW=/^\.+$/,EW=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,SW=/[\. ]+$/;function AP(r,e){if(typeof r!="string")throw new Error("Input must be string");var t=r.replace(xW,e).replace(bW,e).replace(vW,e).replace(EW,e).replace(SW,e);return wW(t,255)}_P.exports=function(r,e){var t=e&&e.replacement||"",n=AP(r,t);return t===""?n:AP(n,"")}});var js=Rt(rd=>{"use strict";var _W="[object ArrayBuffer]",zs=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===_W}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},W9="string",TW=/^[0-9a-f\s]+$/i,CW=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,IW=/^[a-zA-Z0-9-_]+$/,R3=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=zs.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Bo=class{static toString(e,t=!1){let n=zs.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},O3=class r{static isHex(e){return typeof e===W9&&TW.test(e)}static isBase64(e){return typeof e===W9&&CW.test(e)}static isBase64Url(e){return typeof e===W9&&IW.test(e)}static ToString(e,t="utf8"){let n=zs.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Bo.toString(n,!0);case"utf16":case"utf16be":return Bo.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Bo.fromString(e,!0);case"utf16":case"utf16be":return Bo.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=zs.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return R3.fromString(e);case"utf16":case"utf16be":return Bo.fromString(e);case"utf16le":case"usc2":return Bo.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return R3.toString(e);case"utf16":case"utf16be":return Bo.toString(e);case"utf16le":case"usc2":return Bo.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=zs.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=zs.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Bo.toString(e,t)}static FromUtf16String(e,t=!1){return Bo.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};O3.DEFAULT_UTF8_ENCODING="utf8";function kW(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function PW(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function RW(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}rd.BufferSourceConverter=zs;rd.Convert=O3;rd.assign=kW;rd.combine=PW;rd.isEqual=RW});var KO=Rt(Qi=>{"use strict";Object.defineProperty(Qi,"__esModule",{value:!0});Qi.parseCookie=$O;Qi.parse=$O;Qi.stringifyCookie=cX;Qi.stringifySetCookie=F4;Qi.serialize=F4;Qi.parseSetCookie=lX;Qi.stringifySetCookie=F4;Qi.serialize=F4;var UO=/^[\u0021-\u003A\u003C\u003E-\u007E]+$/,FO=/^[\u0021-\u003A\u003C-\u007E]*$/,nX=/^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,oX=/^[\u0020-\u003A\u003D-\u007E]*$/,iX=/^-?\d+$/,sX=Object.prototype.toString,aX=(()=>{let r=function(){};return r.prototype=Object.create(null),r})();function $O(r,e){let t=new aX,n=r.length;if(n<2)return t;let o=e?.decode||HO,i=0;do{let s=Kb(r,i,n);if(s===-1)break;let a=Hb(r,i,n);if(s>a){i=r.lastIndexOf(";",s-1)+1;continue}let c=Ga(r,i,s);t[c]===void 0&&(t[c]=o(Ga(r,s+1,a))),i=a+1}while(i<n);return t}function cX(r,e){let t=e?.encode||encodeURIComponent,n=[];for(let o of Object.keys(r)){let i=r[o];if(i===void 0)continue;if(!UO.test(o))throw new TypeError(`cookie name is invalid: ${o}`);let s=t(i);if(!FO.test(s))throw new TypeError(`cookie val is invalid: ${i}`);n.push(`${o}=${s}`)}return n.join("; ")}function F4(r,e,t){let n=typeof r=="object"?r:{...t,name:r,value:String(e)},i=(typeof e=="object"?e:t)?.encode||encodeURIComponent;if(!UO.test(n.name))throw new TypeError(`argument name is invalid: ${n.name}`);let s=n.value?i(n.value):"";if(!FO.test(s))throw new TypeError(`argument val is invalid: ${n.value}`);let a=n.name+"="+s;if(n.maxAge!==void 0){if(!Number.isInteger(n.maxAge))throw new TypeError(`option maxAge is invalid: ${n.maxAge}`);a+="; Max-Age="+n.maxAge}if(n.domain){if(!nX.test(n.domain))throw new TypeError(`option domain is invalid: ${n.domain}`);a+="; Domain="+n.domain}if(n.path){if(!oX.test(n.path))throw new TypeError(`option path is invalid: ${n.path}`);a+="; Path="+n.path}if(n.expires){if(!uX(n.expires)||!Number.isFinite(n.expires.valueOf()))throw new TypeError(`option expires is invalid: ${n.expires}`);a+="; Expires="+n.expires.toUTCString()}if(n.httpOnly&&(a+="; HttpOnly"),n.secure&&(a+="; Secure"),n.partitioned&&(a+="; Partitioned"),n.priority)switch(typeof n.priority=="string"?n.priority.toLowerCase():void 0){case"low":a+="; Priority=Low";break;case"medium":a+="; Priority=Medium";break;case"high":a+="; Priority=High";break;default:throw new TypeError(`option priority is invalid: ${n.priority}`)}if(n.sameSite)switch(typeof n.sameSite=="string"?n.sameSite.toLowerCase():n.sameSite){case!0:case"strict":a+="; SameSite=Strict";break;case"lax":a+="; SameSite=Lax";break;case"none":a+="; SameSite=None";break;default:throw new TypeError(`option sameSite is invalid: ${n.sameSite}`)}return a}function lX(r,e){let t=e?.decode||HO,n=r.length,o=Hb(r,0,n),i=Kb(r,0,o),s=i===-1?{name:"",value:t(Ga(r,0,o))}:{name:Ga(r,0,i),value:t(Ga(r,i+1,o))},a=o+1;for(;a<n;){let c=Hb(r,a,n),l=Kb(r,a,c),u=l===-1?Ga(r,a,c):Ga(r,a,l),f=l===-1?void 0:Ga(r,l+1,c);switch(u.toLowerCase()){case"httponly":s.httpOnly=!0;break;case"secure":s.secure=!0;break;case"partitioned":s.partitioned=!0;break;case"domain":s.domain=f;break;case"path":s.path=f;break;case"max-age":f&&iX.test(f)&&(s.maxAge=Number(f));break;case"expires":if(!f)break;let h=new Date(f);Number.isFinite(h.valueOf())&&(s.expires=h);break;case"priority":if(!f)break;let d=f.toLowerCase();(d==="low"||d==="medium"||d==="high")&&(s.priority=d);break;case"samesite":if(!f)break;let m=f.toLowerCase();(m==="lax"||m==="strict"||m==="none")&&(s.sameSite=m);break}a=c+1}return s}function Hb(r,e,t){let n=r.indexOf(";",e);return n===-1?t:n}function Kb(r,e,t){let n=r.indexOf("=",e);return n<t?n:-1}function Ga(r,e,t){let n=e,o=t;do{let i=r.charCodeAt(n);if(i!==32&&i!==9)break}while(++n<o);for(;o>n;){let i=r.charCodeAt(o-1);if(i!==32&&i!==9)break;o--}return r.slice(n,o)}function HO(r){if(r.indexOf("%")===-1)return r;try{return decodeURIComponent(r)}catch{return r}}function uX(r){return sX.call(r)==="[object Date]"}});var hN=Rt(()=>{var dN;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,l){return function(u,f){Object.defineProperty(c,u,{configurable:!0,writable:!0,value:f}),l&&l(u,f)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,l=!a&&!c,u={create:a?function(){return G8(Object.create(null))}:c?function(){return G8({__proto__:null})}:function(){return G8({})},has:l?function(P,L){return n.call(P,L)}:function(P,L){return L in P},get:l?function(P,L){return n.call(P,L)?P[L]:void 0}:function(P,L){return P[L]}},f=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:dF(),d=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:hF(),m=typeof WeakMap=="function"?WeakMap:pF(),y=o?Symbol.for("@reflect-metadata:registry"):void 0,w=lF(),x=uF(w);function v(P,L,q,te){if(V(q)){if(!ds(P))throw new TypeError;if(!ha(L))throw new TypeError;return $(P,L)}else{if(!ds(P))throw new TypeError;if(!he(L))throw new TypeError;if(!he(te)&&!V(te)&&!Ne(te))throw new TypeError;return Ne(te)&&(te=void 0),q=at(q),S(P,L,q,te)}}e("decorate",v);function E(P,L){function q(te,Se){if(!he(te))throw new TypeError;if(!V(Se)&&!H0(Se))throw new TypeError;G(P,L,te,Se)}return q}e("metadata",E);function I(P,L,q,te){if(!he(q))throw new TypeError;return V(te)||(te=at(te)),G(P,L,q,te)}e("defineMetadata",I);function U(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),C(P,L,q)}e("hasMetadata",U);function K(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),_(P,L,q)}e("hasOwnMetadata",K);function M(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),B(P,L,q)}e("getMetadata",M);function T(P,L,q){if(!he(L))throw new TypeError;return V(q)||(q=at(q)),X(P,L,q)}e("getOwnMetadata",T);function k(P,L){if(!he(P))throw new TypeError;return V(L)||(L=at(L)),F(P,L)}e("getMetadataKeys",k);function z(P,L){if(!he(P))throw new TypeError;return V(L)||(L=at(L)),Q(P,L)}e("getOwnMetadataKeys",z);function W(P,L,q){if(!he(L))throw new TypeError;if(V(q)||(q=at(q)),!he(L))throw new TypeError;V(q)||(q=at(q));var te=Th(L,q,!1);return V(te)?!1:te.OrdinaryDeleteMetadata(P,L,q)}e("deleteMetadata",W);function $(P,L){for(var q=P.length-1;q>=0;--q){var te=P[q],Se=te(L);if(!V(Se)&&!Ne(Se)){if(!ha(Se))throw new TypeError;L=Se}}return L}function S(P,L,q,te){for(var Se=P.length-1;Se>=0;--Se){var zt=P[Se],ar=zt(L,q,te);if(!V(ar)&&!Ne(ar)){if(!he(ar))throw new TypeError;te=ar}}return te}function C(P,L,q){var te=_(P,L,q);if(te)return!0;var Se=W8(L);return Ne(Se)?!1:C(P,Se,q)}function _(P,L,q){var te=Th(L,q,!1);return V(te)?!1:Pt(te.OrdinaryHasOwnMetadata(P,L,q))}function B(P,L,q){var te=_(P,L,q);if(te)return X(P,L,q);var Se=W8(L);if(!Ne(Se))return B(P,Se,q)}function X(P,L,q){var te=Th(L,q,!1);if(!V(te))return te.OrdinaryGetOwnMetadata(P,L,q)}function G(P,L,q,te){var Se=Th(q,te,!0);Se.OrdinaryDefineOwnMetadata(P,L,q,te)}function F(P,L){var q=Q(P,L),te=W8(P);if(te===null)return q;var Se=F(te,L);if(Se.length<=0)return q;if(q.length<=0)return Se;for(var zt=new d,ar=[],Fe=0,ae=q;Fe<ae.length;Fe++){var fe=ae[Fe],pe=zt.has(fe);pe||(zt.add(fe),ar.push(fe))}for(var ye=0,He=Se;ye<He.length;ye++){var fe=He[ye],pe=zt.has(fe);pe||(zt.add(fe),ar.push(fe))}return ar}function Q(P,L){var q=Th(P,L,!1);return q?q.OrdinaryOwnMetadataKeys(P,L):[]}function ne(P){if(P===null)return 1;switch(typeof P){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return P===null?1:6;default:return 6}}function V(P){return P===void 0}function Ne(P){return P===null}function Ue(P){return typeof P=="symbol"}function he(P){return typeof P=="object"?P!==null:typeof P=="function"}function Ve(P,L){switch(ne(P)){case 0:return P;case 1:return P;case 2:return P;case 3:return P;case 4:return P;case 5:return P}var q=L===3?"string":L===5?"number":"default",te=_h(P,i);if(te!==void 0){var Se=te.call(P,q);if(he(Se))throw new TypeError;return Se}return st(P,q==="default"?"number":q)}function st(P,L){if(L==="string"){var q=P.toString;if(Xo(q)){var te=q.call(P);if(!he(te))return te}var Se=P.valueOf;if(Xo(Se)){var te=Se.call(P);if(!he(te))return te}}else{var Se=P.valueOf;if(Xo(Se)){var te=Se.call(P);if(!he(te))return te}var zt=P.toString;if(Xo(zt)){var te=zt.call(P);if(!he(te))return te}}throw new TypeError}function Pt(P){return!!P}function Ge(P){return""+P}function at(P){var L=Ve(P,3);return Ue(L)?L:Ge(L)}function ds(P){return Array.isArray?Array.isArray(P):P instanceof Object?P instanceof Array:Object.prototype.toString.call(P)==="[object Array]"}function Xo(P){return typeof P=="function"}function ha(P){return typeof P=="function"}function H0(P){switch(ne(P)){case 3:return!0;case 4:return!0;default:return!1}}function Ku(P,L){return P===L||P!==P&&L!==L}function _h(P,L){var q=P[L];if(q!=null){if(!Xo(q))throw new TypeError;return q}}function YS(P){var L=_h(P,s);if(!Xo(L))throw new TypeError;var q=L.call(P);if(!he(q))throw new TypeError;return q}function QS(P){return P.value}function ZS(P){var L=P.next();return L.done?!1:L}function JS(P){var L=P.return;L&&L.call(P)}function W8(P){var L=Object.getPrototypeOf(P);if(typeof P!="function"||P===f||L!==f)return L;var q=P.prototype,te=q&&Object.getPrototypeOf(q);if(te==null||te===Object.prototype)return L;var Se=te.constructor;return typeof Se!="function"||Se===P?L:Se}function cF(){var P;!V(y)&&typeof t.Reflect<"u"&&!(y in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(P=fF(t.Reflect));var L,q,te,Se=new m,zt={registerProvider:ar,getProvider:ae,setProvider:pe};return zt;function ar(ye){if(!Object.isExtensible(zt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case P===ye:break;case V(L):L=ye;break;case L===ye:break;case V(q):q=ye;break;case q===ye:break;default:te===void 0&&(te=new d),te.add(ye);break}}function Fe(ye,He){if(!V(L)){if(L.isProviderFor(ye,He))return L;if(!V(q)){if(q.isProviderFor(ye,He))return L;if(!V(te))for(var St=YS(te);;){var jt=ZS(St);if(!jt)return;var Yo=QS(jt);if(Yo.isProviderFor(ye,He))return JS(St),Yo}}}if(!V(P)&&P.isProviderFor(ye,He))return P}function ae(ye,He){var St=Se.get(ye),jt;return V(St)||(jt=St.get(He)),V(jt)&&(jt=Fe(ye,He),V(jt)||(V(St)&&(St=new h,Se.set(ye,St)),St.set(He,jt))),jt}function fe(ye){if(V(ye))throw new TypeError;return L===ye||q===ye||!V(te)&&te.has(ye)}function pe(ye,He,St){if(!fe(St))throw new Error("Metadata provider not registered.");var jt=ae(ye,He);if(jt!==St){if(!V(jt))return!1;var Yo=Se.get(ye);V(Yo)&&(Yo=new h,Se.set(ye,Yo)),Yo.set(He,St)}return!0}}function lF(){var P;return!V(y)&&he(t.Reflect)&&Object.isExtensible(t.Reflect)&&(P=t.Reflect[y]),V(P)&&(P=cF()),!V(y)&&he(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,y,{enumerable:!1,configurable:!1,writable:!1,value:P}),P}function uF(P){var L=new m,q={isProviderFor:function(fe,pe){var ye=L.get(fe);return V(ye)?!1:ye.has(pe)},OrdinaryDefineOwnMetadata:ar,OrdinaryHasOwnMetadata:Se,OrdinaryGetOwnMetadata:zt,OrdinaryOwnMetadataKeys:Fe,OrdinaryDeleteMetadata:ae};return w.registerProvider(q),q;function te(fe,pe,ye){var He=L.get(fe),St=!1;if(V(He)){if(!ye)return;He=new h,L.set(fe,He),St=!0}var jt=He.get(pe);if(V(jt)){if(!ye)return;if(jt=new h,He.set(pe,jt),!P.setProvider(fe,pe,q))throw He.delete(pe),St&&L.delete(fe),new Error("Wrong provider for target.")}return jt}function Se(fe,pe,ye){var He=te(pe,ye,!1);return V(He)?!1:Pt(He.has(fe))}function zt(fe,pe,ye){var He=te(pe,ye,!1);if(!V(He))return He.get(fe)}function ar(fe,pe,ye,He){var St=te(ye,He,!0);St.set(fe,pe)}function Fe(fe,pe){var ye=[],He=te(fe,pe,!1);if(V(He))return ye;for(var St=He.keys(),jt=YS(St),Yo=0;;){var eA=ZS(jt);if(!eA)return ye.length=Yo,ye;var mF=QS(eA);try{ye[Yo]=mF}catch(gF){try{JS(jt)}finally{throw gF}}Yo++}}function ae(fe,pe,ye){var He=te(pe,ye,!1);if(V(He)||!He.delete(fe))return!1;if(He.size===0){var St=L.get(pe);V(St)||(St.delete(ye),St.size===0&&L.delete(St))}return!0}}function fF(P){var L=P.defineMetadata,q=P.hasOwnMetadata,te=P.getOwnMetadata,Se=P.getOwnMetadataKeys,zt=P.deleteMetadata,ar=new m,Fe={isProviderFor:function(ae,fe){var pe=ar.get(ae);return!V(pe)&&pe.has(fe)?!0:Se(ae,fe).length?(V(pe)&&(pe=new d,ar.set(ae,pe)),pe.add(fe),!0):!1},OrdinaryDefineOwnMetadata:L,OrdinaryHasOwnMetadata:q,OrdinaryGetOwnMetadata:te,OrdinaryOwnMetadataKeys:Se,OrdinaryDeleteMetadata:zt};return Fe}function Th(P,L,q){var te=w.getProvider(P,L);if(!V(te))return te;if(q){if(w.setProvider(P,L,x))return x;throw new Error("Illegal state.")}}function dF(){var P={},L=[],q=(function(){function Fe(ae,fe,pe){this._index=0,this._keys=ae,this._values=fe,this._selector=pe}return Fe.prototype["@@iterator"]=function(){return this},Fe.prototype[s]=function(){return this},Fe.prototype.next=function(){var ae=this._index;if(ae>=0&&ae<this._keys.length){var fe=this._selector(this._keys[ae],this._values[ae]);return ae+1>=this._keys.length?(this._index=-1,this._keys=L,this._values=L):this._index++,{value:fe,done:!1}}return{value:void 0,done:!0}},Fe.prototype.throw=function(ae){throw this._index>=0&&(this._index=-1,this._keys=L,this._values=L),ae},Fe.prototype.return=function(ae){return this._index>=0&&(this._index=-1,this._keys=L,this._values=L),{value:ae,done:!0}},Fe})(),te=(function(){function Fe(){this._keys=[],this._values=[],this._cacheKey=P,this._cacheIndex=-2}return Object.defineProperty(Fe.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),Fe.prototype.has=function(ae){return this._find(ae,!1)>=0},Fe.prototype.get=function(ae){var fe=this._find(ae,!1);return fe>=0?this._values[fe]:void 0},Fe.prototype.set=function(ae,fe){var pe=this._find(ae,!0);return this._values[pe]=fe,this},Fe.prototype.delete=function(ae){var fe=this._find(ae,!1);if(fe>=0){for(var pe=this._keys.length,ye=fe+1;ye<pe;ye++)this._keys[ye-1]=this._keys[ye],this._values[ye-1]=this._values[ye];return this._keys.length--,this._values.length--,Ku(ae,this._cacheKey)&&(this._cacheKey=P,this._cacheIndex=-2),!0}return!1},Fe.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=P,this._cacheIndex=-2},Fe.prototype.keys=function(){return new q(this._keys,this._values,Se)},Fe.prototype.values=function(){return new q(this._keys,this._values,zt)},Fe.prototype.entries=function(){return new q(this._keys,this._values,ar)},Fe.prototype["@@iterator"]=function(){return this.entries()},Fe.prototype[s]=function(){return this.entries()},Fe.prototype._find=function(ae,fe){if(!Ku(this._cacheKey,ae)){this._cacheIndex=-1;for(var pe=0;pe<this._keys.length;pe++)if(Ku(this._keys[pe],ae)){this._cacheIndex=pe;break}}return this._cacheIndex<0&&fe&&(this._cacheIndex=this._keys.length,this._keys.push(ae),this._values.push(void 0)),this._cacheIndex},Fe})();return te;function Se(Fe,ae){return Fe}function zt(Fe,ae){return ae}function ar(Fe,ae){return[Fe,ae]}}function hF(){var P=(function(){function L(){this._map=new h}return Object.defineProperty(L.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),L.prototype.has=function(q){return this._map.has(q)},L.prototype.add=function(q){return this._map.set(q,q),this},L.prototype.delete=function(q){return this._map.delete(q)},L.prototype.clear=function(){this._map.clear()},L.prototype.keys=function(){return this._map.keys()},L.prototype.values=function(){return this._map.keys()},L.prototype.entries=function(){return this._map.entries()},L.prototype["@@iterator"]=function(){return this.keys()},L.prototype[s]=function(){return this.keys()},L})();return P}function pF(){var P=16,L=u.create(),q=te();return(function(){function ae(){this._key=te()}return ae.prototype.has=function(fe){var pe=Se(fe,!1);return pe!==void 0?u.has(pe,this._key):!1},ae.prototype.get=function(fe){var pe=Se(fe,!1);return pe!==void 0?u.get(pe,this._key):void 0},ae.prototype.set=function(fe,pe){var ye=Se(fe,!0);return ye[this._key]=pe,this},ae.prototype.delete=function(fe){var pe=Se(fe,!1);return pe!==void 0?delete pe[this._key]:!1},ae.prototype.clear=function(){this._key=te()},ae})();function te(){var ae;do ae="@@WeakMap@@"+Fe();while(u.has(L,ae));return L[ae]=!0,ae}function Se(ae,fe){if(!n.call(ae,q)){if(!fe)return;Object.defineProperty(ae,q,{value:u.create()})}return ae[q]}function zt(ae,fe){for(var pe=0;pe<fe;++pe)ae[pe]=Math.random()*255|0;return ae}function ar(ae){if(typeof Uint8Array=="function"){var fe=new Uint8Array(ae);return typeof crypto<"u"?crypto.getRandomValues(fe):typeof msCrypto<"u"?msCrypto.getRandomValues(fe):zt(fe,ae),fe}return zt(new Array(ae),ae)}function Fe(){var ae=ar(P);ae[6]=ae[6]&79|64,ae[8]=ae[8]&191|128;for(var fe="",pe=0;pe<P;++pe){var ye=ae[pe];(pe===4||pe===6||pe===8)&&(fe+="-"),ye<16&&(fe+="0"),fe+=ye.toString(16).toLowerCase()}return fe}}function G8(P){return P.__=void 0,delete P.__,P}})})(dN||(dN={}))});var EL=Rt((FHe,w5)=>{var rL,nL,oL,iL,sL,aL,cL,lL,uL,y5,pE,fL,dL,Yd,hL,pL,mL,gL,yL,wL,xL,bL,vL;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof w5=="object"&&typeof w5.exports=="object"?r(t(e,t(w5.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};rL=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},nL=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++){n=arguments[o];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},oL=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},iL=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},sL=function(t,n){return function(o,i){n(o,i,t)}},aL=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},cL=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function l(h){try{f(i.next(h))}catch(d){c(d)}}function u(h){try{f(i.throw(h))}catch(d){c(d)}}function f(h){h.done?a(h.value):s(h.value).then(l,u)}f((i=i.apply(t,n||[])).next())})},lL=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(f){return function(h){return u([f,h])}}function u(f){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=f[0]&2?s.return:f[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,f[1])).done)return a;switch(s=0,a&&(f=[f[0]&2,a.value]),f[0]){case 0:case 1:a=f;break;case 4:return o.label++,{value:f[1],done:!1};case 5:o.label++,s=f[1],f=[0];continue;case 7:f=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(f[0]===6||f[0]===2)){o=0;continue}if(f[0]===3&&(!a||f[1]>a[0]&&f[1]<a[3])){o.label=f[1];break}if(f[0]===6&&o.label<a[1]){o.label=a[1],a=f;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(f);break}a[2]&&o.ops.pop(),o.trys.pop();continue}f=n.call(t,o)}catch(h){f=[6,h],s=0}finally{i=a=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},vL=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},uL=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},y5=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},pE=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(l){c={error:l}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},fL=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(pE(arguments[n]));return t},dL=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,l=a.length;c<l;c++,s++)i[s]=a[c];return i},Yd=function(t){return this instanceof Yd?(this.v=t,this):new Yd(t)},hL=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(m){i[m]&&(s[m]=function(y){return new Promise(function(w,x){a.push([m,y,w,x])>1||l(m,y)})})}function l(m,y){try{u(i[m](y))}catch(w){d(a[0][3],w)}}function u(m){m.value instanceof Yd?Promise.resolve(m.value.v).then(f,h):d(a[0][2],m)}function f(m){l("next",m)}function h(m){l("throw",m)}function d(m,y){m(y),a.shift(),a.length&&l(a[0][0],a[0][1])}},pL=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Yd(t[s](c)),done:s==="return"}:a?a(c):c}:a}},mL=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof y5=="function"?y5(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(l,u){c=t[a](c),s(l,u,c.done,c.value)})}}function s(a,c,l,u){Promise.resolve(u).then(function(f){a({value:f,done:l})},c)}},gL=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},yL=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},wL=function(t){return t&&t.__esModule?t:{default:t}},xL=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},bL=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",rL),r("__assign",nL),r("__rest",oL),r("__decorate",iL),r("__param",sL),r("__metadata",aL),r("__awaiter",cL),r("__generator",lL),r("__exportStar",uL),r("__createBinding",vL),r("__values",y5),r("__read",pE),r("__spread",fL),r("__spreadArrays",dL),r("__await",Yd),r("__asyncGenerator",hL),r("__asyncDelegator",pL),r("__asyncValues",mL),r("__makeTemplateObject",gL),r("__importStar",yL),r("__importDefault",wL),r("__classPrivateFieldGet",xL),r("__classPrivateFieldSet",bL)})});var wM=Rt((TYe,yM)=>{yM.exports=hS;var gM=128,MQ=127,UQ=~MQ,FQ=Math.pow(2,31);function hS(r,e,t){if(Number.MAX_SAFE_INTEGER&&r>Number.MAX_SAFE_INTEGER)throw hS.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var n=t;r>=FQ;)e[t++]=r&255|gM,r/=128;for(;r&UQ;)e[t++]=r&255|gM,r>>>=7;return e[t]=r|0,hS.bytes=t-n+1,e}});var vM=Rt((CYe,bM)=>{bM.exports=pS;var $Q=128,xM=127;function pS(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a||o>49)throw pS.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&xM)<<o:(s&xM)*Math.pow(2,o),o+=7}while(s>=$Q);return pS.bytes=i-n,t}});var SM=Rt((IYe,EM)=>{var HQ=Math.pow(2,7),KQ=Math.pow(2,14),VQ=Math.pow(2,21),qQ=Math.pow(2,28),zQ=Math.pow(2,35),jQ=Math.pow(2,42),WQ=Math.pow(2,49),GQ=Math.pow(2,56),XQ=Math.pow(2,63);EM.exports=function(r){return r<HQ?1:r<KQ?2:r<VQ?3:r<qQ?4:r<zQ?5:r<jQ?6:r<WQ?7:r<GQ?8:r<XQ?9:10}});var s8=Rt((kYe,AM)=>{AM.exports={encode:wM(),decode:vM(),encodingLength:SM()}});var UM=Rt((R0,y8)=>{(function(r,e){"use strict";var t={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function n(d){if(!Array.isArray(d)&&!ArrayBuffer.isView(d))return!1;for(var m=0;m<d.length;m++)if(!Number.isInteger(d[m])||d[m]<0||d[m]>255)return!1;return!0}function o(d,m){return(d&65535)*m+(((d>>>16)*m&65535)<<16)}function i(d,m){return d<<m|d>>>32-m}function s(d){return d^=d>>>16,d=o(d,2246822507),d^=d>>>13,d=o(d,3266489909),d^=d>>>16,d}function a(d,m){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],m=[m[0]>>>16,m[0]&65535,m[1]>>>16,m[1]&65535];var y=[0,0,0,0];return y[3]+=d[3]+m[3],y[2]+=y[3]>>>16,y[3]&=65535,y[2]+=d[2]+m[2],y[1]+=y[2]>>>16,y[2]&=65535,y[1]+=d[1]+m[1],y[0]+=y[1]>>>16,y[1]&=65535,y[0]+=d[0]+m[0],y[0]&=65535,[y[0]<<16|y[1],y[2]<<16|y[3]]}function c(d,m){d=[d[0]>>>16,d[0]&65535,d[1]>>>16,d[1]&65535],m=[m[0]>>>16,m[0]&65535,m[1]>>>16,m[1]&65535];var y=[0,0,0,0];return y[3]+=d[3]*m[3],y[2]+=y[3]>>>16,y[3]&=65535,y[2]+=d[2]*m[3],y[1]+=y[2]>>>16,y[2]&=65535,y[2]+=d[3]*m[2],y[1]+=y[2]>>>16,y[2]&=65535,y[1]+=d[1]*m[3],y[0]+=y[1]>>>16,y[1]&=65535,y[1]+=d[2]*m[2],y[0]+=y[1]>>>16,y[1]&=65535,y[1]+=d[3]*m[1],y[0]+=y[1]>>>16,y[1]&=65535,y[0]+=d[0]*m[3]+d[1]*m[2]+d[2]*m[1]+d[3]*m[0],y[0]&=65535,[y[0]<<16|y[1],y[2]<<16|y[3]]}function l(d,m){return m%=64,m===32?[d[1],d[0]]:m<32?[d[0]<<m|d[1]>>>32-m,d[1]<<m|d[0]>>>32-m]:(m-=32,[d[1]<<m|d[0]>>>32-m,d[0]<<m|d[1]>>>32-m])}function u(d,m){return m%=64,m===0?d:m<32?[d[0]<<m|d[1]>>>32-m,d[1]<<m]:[d[1]<<m-32,0]}function f(d,m){return[d[0]^m[0],d[1]^m[1]]}function h(d){return d=f(d,[0,d[0]>>>1]),d=c(d,[4283543511,3981806797]),d=f(d,[0,d[0]>>>1]),d=c(d,[3301882366,444984403]),d=f(d,[0,d[0]>>>1]),d}t.x86.hash32=function(d,m){if(t.inputValidation&&!n(d))return e;m=m||0;for(var y=d.length%4,w=d.length-y,x=m,v=0,E=3432918353,I=461845907,U=0;U<w;U=U+4)v=d[U]|d[U+1]<<8|d[U+2]<<16|d[U+3]<<24,v=o(v,E),v=i(v,15),v=o(v,I),x^=v,x=i(x,13),x=o(x,5)+3864292196;switch(v=0,y){case 3:v^=d[U+2]<<16;case 2:v^=d[U+1]<<8;case 1:v^=d[U],v=o(v,E),v=i(v,15),v=o(v,I),x^=v}return x^=d.length,x=s(x),x>>>0},t.x86.hash128=function(d,m){if(t.inputValidation&&!n(d))return e;m=m||0;for(var y=d.length%16,w=d.length-y,x=m,v=m,E=m,I=m,U=0,K=0,M=0,T=0,k=597399067,z=2869860233,W=951274213,$=2716044179,S=0;S<w;S=S+16)U=d[S]|d[S+1]<<8|d[S+2]<<16|d[S+3]<<24,K=d[S+4]|d[S+5]<<8|d[S+6]<<16|d[S+7]<<24,M=d[S+8]|d[S+9]<<8|d[S+10]<<16|d[S+11]<<24,T=d[S+12]|d[S+13]<<8|d[S+14]<<16|d[S+15]<<24,U=o(U,k),U=i(U,15),U=o(U,z),x^=U,x=i(x,19),x+=v,x=o(x,5)+1444728091,K=o(K,z),K=i(K,16),K=o(K,W),v^=K,v=i(v,17),v+=E,v=o(v,5)+197830471,M=o(M,W),M=i(M,17),M=o(M,$),E^=M,E=i(E,15),E+=I,E=o(E,5)+2530024501,T=o(T,$),T=i(T,18),T=o(T,k),I^=T,I=i(I,13),I+=x,I=o(I,5)+850148119;switch(U=0,K=0,M=0,T=0,y){case 15:T^=d[S+14]<<16;case 14:T^=d[S+13]<<8;case 13:T^=d[S+12],T=o(T,$),T=i(T,18),T=o(T,k),I^=T;case 12:M^=d[S+11]<<24;case 11:M^=d[S+10]<<16;case 10:M^=d[S+9]<<8;case 9:M^=d[S+8],M=o(M,W),M=i(M,17),M=o(M,$),E^=M;case 8:K^=d[S+7]<<24;case 7:K^=d[S+6]<<16;case 6:K^=d[S+5]<<8;case 5:K^=d[S+4],K=o(K,z),K=i(K,16),K=o(K,W),v^=K;case 4:U^=d[S+3]<<24;case 3:U^=d[S+2]<<16;case 2:U^=d[S+1]<<8;case 1:U^=d[S],U=o(U,k),U=i(U,15),U=o(U,z),x^=U}return x^=d.length,v^=d.length,E^=d.length,I^=d.length,x+=v,x+=E,x+=I,v+=x,E+=x,I+=x,x=s(x),v=s(v),E=s(E),I=s(I),x+=v,x+=E,x+=I,v+=x,E+=x,I+=x,("00000000"+(x>>>0).toString(16)).slice(-8)+("00000000"+(v>>>0).toString(16)).slice(-8)+("00000000"+(E>>>0).toString(16)).slice(-8)+("00000000"+(I>>>0).toString(16)).slice(-8)},t.x64.hash128=function(d,m){if(t.inputValidation&&!n(d))return e;m=m||0;for(var y=d.length%16,w=d.length-y,x=[0,m],v=[0,m],E=[0,0],I=[0,0],U=[2277735313,289559509],K=[1291169091,658871167],M=0;M<w;M=M+16)E=[d[M+4]|d[M+5]<<8|d[M+6]<<16|d[M+7]<<24,d[M]|d[M+1]<<8|d[M+2]<<16|d[M+3]<<24],I=[d[M+12]|d[M+13]<<8|d[M+14]<<16|d[M+15]<<24,d[M+8]|d[M+9]<<8|d[M+10]<<16|d[M+11]<<24],E=c(E,U),E=l(E,31),E=c(E,K),x=f(x,E),x=l(x,27),x=a(x,v),x=a(c(x,[0,5]),[0,1390208809]),I=c(I,K),I=l(I,33),I=c(I,U),v=f(v,I),v=l(v,31),v=a(v,x),v=a(c(v,[0,5]),[0,944331445]);switch(E=[0,0],I=[0,0],y){case 15:I=f(I,u([0,d[M+14]],48));case 14:I=f(I,u([0,d[M+13]],40));case 13:I=f(I,u([0,d[M+12]],32));case 12:I=f(I,u([0,d[M+11]],24));case 11:I=f(I,u([0,d[M+10]],16));case 10:I=f(I,u([0,d[M+9]],8));case 9:I=f(I,[0,d[M+8]]),I=c(I,K),I=l(I,33),I=c(I,U),v=f(v,I);case 8:E=f(E,u([0,d[M+7]],56));case 7:E=f(E,u([0,d[M+6]],48));case 6:E=f(E,u([0,d[M+5]],40));case 5:E=f(E,u([0,d[M+4]],32));case 4:E=f(E,u([0,d[M+3]],24));case 3:E=f(E,u([0,d[M+2]],16));case 2:E=f(E,u([0,d[M+1]],8));case 1:E=f(E,[0,d[M]]),E=c(E,U),E=l(E,31),E=c(E,K),x=f(x,E)}return x=f(x,[0,d.length]),v=f(v,[0,d.length]),x=a(x,v),v=a(v,x),x=h(x),v=h(v),x=a(x,v),v=a(v,x),("00000000"+(x[0]>>>0).toString(16)).slice(-8)+("00000000"+(x[1]>>>0).toString(16)).slice(-8)+("00000000"+(v[0]>>>0).toString(16)).slice(-8)+("00000000"+(v[1]>>>0).toString(16)).slice(-8)},typeof R0<"u"?(typeof y8<"u"&&y8.exports&&(R0=y8.exports=t),R0.murmurHash3=t):typeof define=="function"&&define.amd?define([],function(){return t}):(t._murmurHash3=r.murmurHash3,t.noConflict=function(){return r.murmurHash3=t._murmurHash3,t._murmurHash3=e,t.noConflict=e,t},r.murmurHash3=t)})(R0)});var $M=Rt((vZe,FM)=>{FM.exports=UM()});var qM=Rt((IZe,VM)=>{"use strict";VM.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let n=this._internalPositionFor(e,!1);if(t===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let o=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):o=!0,this._setInternalPos(n,e,t,o),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let t=this._internalPositionFor(e,!0);if(t!==-1)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t<this.length;)e(this.get(t),t,this),t++}map(e){let t=0,n=new Array(this.length);for(;t<this.length;)n[t]=e(this.get(t),t,this),t++;return n}reduce(e,t){let n=0,o=t;for(;n<this.length;){let i=this.get(n);o=e(o,i,n),n++}return o}find(e){let t=0,n,o;for(;t<this.length&&!n;)o=this.get(t),n=e(o),t++;return n?o:void 0}_internalPositionFor(e,t){let n=this._bytePosFor(e,t);if(n>=this._bitArrays.length)return-1;let o=this._bitArrays[n],i=e-n*7;if(!((o&1<<i)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(fZ,0),c=~(4294967295<<i+1),l=KM(o&c);return a+l-1}_bytePosFor(e,t){let n=Math.floor(e/7),o=n+1;for(;!t&&this._bitArrays.length<o;)this._bitArrays.push(0);return n}_setBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]|=1<<e-t*7}_unsetBit(e){let t=this._bytePosFor(e,!1);this._bitArrays[t]&=~(1<<e-t*7)}_setInternalPos(e,t,n,o){let i=this._data,s=[t,n];if(o)this._sortData(),i[e]=s;else{if(i.length)if(i[i.length-1][0]>=t)i.push(s);else if(i[0][0]<=t)i.unshift(s);else{let a=Math.round(i.length/2);this._data=i.slice(0,a).concat(s).concat(i.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(dZ),this._changedData=!1}bitField(){let e=[],t=8,n=0,o=0,i,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(i=s.shift(),n=7);let c=Math.min(n,t),l=~(255<<c),u=i&l;o|=u<<8-t,i=i>>>c,n-=c,t-=c,(!t||!n&&!s.length)&&(e.push(o),o=0,t=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(hZ)}};function fZ(r,e){return r+KM(e)}function KM(r){let e=r;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function dZ(r,e){return r[0]-e[0]}function hZ(r){return r[1]}});var AU=Rt((Ztt,SU)=>{"use strict";SU.exports={RTLD_LAZY:1,RTLD_NOW:2,RTLD_GLOBAL:256,RTLD_LOCAL:0,RTLD_DEEPBIND:8,E2BIG:7,EACCES:13,EADDRINUSE:98,EADDRNOTAVAIL:99,EAFNOSUPPORT:97,EAGAIN:11,EALREADY:114,EBADF:9,EBADMSG:74,EBUSY:16,ECANCELED:125,ECHILD:10,ECONNABORTED:103,ECONNREFUSED:111,ECONNRESET:104,EDEADLK:35,EDESTADDRREQ:89,EDOM:33,EDQUOT:122,EEXIST:17,EFAULT:14,EFBIG:27,EHOSTUNREACH:113,EIDRM:43,EILSEQ:84,EINPROGRESS:115,EINTR:4,EINVAL:22,EIO:5,EISCONN:106,EISDIR:21,ELOOP:40,EMFILE:24,EMLINK:31,EMSGSIZE:90,EMULTIHOP:72,ENAMETOOLONG:36,ENETDOWN:100,ENETRESET:102,ENETUNREACH:101,ENFILE:23,ENOBUFS:105,ENODATA:61,ENODEV:19,ENOENT:2,ENOEXEC:8,ENOLCK:37,ENOLINK:67,ENOMEM:12,ENOMSG:42,ENOPROTOOPT:92,ENOSPC:28,ENOSR:63,ENOSTR:60,ENOSYS:38,ENOTCONN:107,ENOTDIR:20,ENOTEMPTY:39,ENOTSOCK:88,ENOTSUP:95,ENOTTY:25,ENXIO:6,EOPNOTSUPP:95,EOVERFLOW:75,EPERM:1,EPIPE:32,EPROTO:71,EPROTONOSUPPORT:93,EPROTOTYPE:91,ERANGE:34,EROFS:30,ESPIPE:29,ESRCH:3,ESTALE:116,ETIME:62,ETIMEDOUT:110,ETXTBSY:26,EWOULDBLOCK:11,EXDEV:18,PRIORITY_LOW:19,PRIORITY_BELOW_NORMAL:10,PRIORITY_NORMAL:0,PRIORITY_ABOVE_NORMAL:-7,PRIORITY_HIGH:-14,PRIORITY_HIGHEST:-20,SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGILL:4,SIGTRAP:5,SIGABRT:6,SIGIOT:6,SIGBUS:7,SIGFPE:8,SIGKILL:9,SIGUSR1:10,SIGSEGV:11,SIGUSR2:12,SIGPIPE:13,SIGALRM:14,SIGTERM:15,SIGCHLD:17,SIGSTKFLT:16,SIGCONT:18,SIGSTOP:19,SIGTSTP:20,SIGTTIN:21,SIGTTOU:22,SIGURG:23,SIGXCPU:24,SIGXFSZ:25,SIGVTALRM:26,SIGPROF:27,SIGWINCH:28,SIGIO:29,SIGPOLL:29,SIGPWR:30,SIGSYS:31,UV_FS_SYMLINK_DIR:1,UV_FS_SYMLINK_JUNCTION:2,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,UV_DIRENT_UNKNOWN:0,UV_DIRENT_FILE:1,UV_DIRENT_DIR:2,UV_DIRENT_LINK:3,UV_DIRENT_FIFO:4,UV_DIRENT_SOCKET:5,UV_DIRENT_CHAR:6,UV_DIRENT_BLOCK:7,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:64,O_EXCL:128,UV_FS_O_FILEMAP:0,O_NOCTTY:256,O_TRUNC:512,O_APPEND:1024,O_DIRECTORY:65536,O_NOATIME:262144,O_NOFOLLOW:131072,O_SYNC:1052672,O_DSYNC:4096,O_DIRECT:16384,O_NONBLOCK:2048,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_FS_COPYFILE_EXCL:1,COPYFILE_EXCL:1,UV_FS_COPYFILE_FICLONE:2,COPYFILE_FICLONE:2,UV_FS_COPYFILE_FICLONE_FORCE:4,COPYFILE_FICLONE_FORCE:4,OPENSSL_VERSION_NUMBER:810549312,SSL_OP_ALL:2147485776,SSL_OP_ALLOW_NO_DHE_KEX:1024,SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,SSL_OP_CISCO_ANYCONNECT:32768,SSL_OP_COOKIE_EXCHANGE:8192,SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,SSL_OP_LEGACY_SERVER_CONNECT:4,SSL_OP_NO_COMPRESSION:131072,SSL_OP_NO_ENCRYPT_THEN_MAC:524288,SSL_OP_NO_QUERY_MTU:4096,SSL_OP_NO_RENEGOTIATION:1073741824,SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,SSL_OP_NO_SSLv2:0,SSL_OP_NO_SSLv3:33554432,SSL_OP_NO_TICKET:16384,SSL_OP_NO_TLSv1:67108864,SSL_OP_NO_TLSv1_1:268435456,SSL_OP_NO_TLSv1_2:134217728,SSL_OP_NO_TLSv1_3:536870912,SSL_OP_PRIORITIZE_CHACHA:2097152,SSL_OP_TLS_ROLLBACK_BUG:8388608,ENGINE_METHOD_RSA:1,ENGINE_METHOD_DSA:2,ENGINE_METHOD_DH:4,ENGINE_METHOD_RAND:8,ENGINE_METHOD_EC:2048,ENGINE_METHOD_CIPHERS:64,ENGINE_METHOD_DIGESTS:128,ENGINE_METHOD_PKEY_METHS:512,ENGINE_METHOD_PKEY_ASN1_METHS:1024,ENGINE_METHOD_ALL:65535,ENGINE_METHOD_NONE:0,DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,RSA_PKCS1_PADDING:1,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,RSA_PSS_SALTLEN_DIGEST:-1,RSA_PSS_SALTLEN_MAX_SIGN:-2,RSA_PSS_SALTLEN_AUTO:-2,defaultCoreCipherList:"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA",TLS1_VERSION:769,TLS1_1_VERSION:770,TLS1_2_VERSION:771,TLS1_3_VERSION:772,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}});var PU=Rt(US=>{US.read=function(r,e,t,n,o){var i,s,a=o*8-n-1,c=(1<<a)-1,l=c>>1,u=-7,f=t?o-1:0,h=t?-1:1,d=r[e+f];for(f+=h,i=d&(1<<-u)-1,d>>=-u,u+=a;u>0;i=i*256+r[e+f],f+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=n;u>0;s=s*256+r[e+f],f+=h,u-=8);if(i===0)i=1-l;else{if(i===c)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-l}return(d?-1:1)*s*Math.pow(2,i-n)};US.write=function(r,e,t,n,o,i){var s,a,c,l=i*8-o-1,u=(1<<l)-1,f=u>>1,h=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:i-1,m=n?1:-1,y=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=u):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+f>=1?e+=h/c:e+=h*Math.pow(2,1-f),e*c>=2&&(s++,c/=2),s+f>=u?(a=0,s=u):s+f>=1?(a=(e*c-1)*Math.pow(2,o),s=s+f):(a=e*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;r[t+d]=a&255,d+=m,a/=256,o-=8);for(s=s<<o|a,l+=o;l>0;r[t+d]=s&255,d+=m,s/=256,l-=8);r[t+d-m]|=y*128}});var HU=Rt((Hnt,$U)=>{var Eh=1e3,Sh=Eh*60,Ah=Sh*60,$u=Ah*24,kJ=$u*7,PJ=$u*365.25;$U.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return RJ(r);if(t==="number"&&isFinite(r))return e.long?DJ(r):OJ(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function RJ(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*PJ;case"weeks":case"week":case"w":return t*kJ;case"days":case"day":case"d":return t*$u;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Ah;case"minutes":case"minute":case"mins":case"min":case"m":return t*Sh;case"seconds":case"second":case"secs":case"sec":case"s":return t*Eh;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function OJ(r){var e=Math.abs(r);return e>=$u?Math.round(r/$u)+"d":e>=Ah?Math.round(r/Ah)+"h":e>=Sh?Math.round(r/Sh)+"m":e>=Eh?Math.round(r/Eh)+"s":r+"ms"}function DJ(r){var e=Math.abs(r);return e>=$u?K8(r,e,$u,"day"):e>=Ah?K8(r,e,Ah,"hour"):e>=Sh?K8(r,e,Sh,"minute"):e>=Eh?K8(r,e,Eh,"second"):r+" ms"}function K8(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var VU=Rt((Knt,KU)=>{function NJ(r){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=o,t.enabled=a,t.humanize=HU(),t.destroy=l,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let f=0;for(let h=0;h<u.length;h++)f=(f<<5)-f+u.charCodeAt(h),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(u){let f,h=null,d,m;function y(...w){if(!y.enabled)return;let x=y,v=Number(new Date),E=v-(f||v);x.diff=E,x.prev=f,x.curr=v,f=v,w[0]=t.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let I=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(K,M)=>{if(K==="%%")return"%";I++;let T=t.formatters[M];if(typeof T=="function"){let k=w[I];K=T.call(x,k),w.splice(I,1),I--}return K}),t.formatArgs.call(x,w),(x.log||t.log).apply(x,w)}return y.namespace=u,y.useColors=t.useColors(),y.color=t.selectColor(u),y.extend=n,y.destroy=t.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(d!==t.namespaces&&(d=t.namespaces,m=t.enabled(u)),m),set:w=>{h=w}}),typeof t.init=="function"&&t.init(y),y}function n(u,f){let h=t(this.namespace+(typeof f>"u"?":":f)+u);return h.log=this.log,h}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let f=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let h of f)h[0]==="-"?t.skips.push(h.slice(1)):t.names.push(h)}function i(u,f){let h=0,d=0,m=-1,y=0;for(;h<u.length;)if(d<f.length&&(f[d]===u[h]||f[d]==="*"))f[d]==="*"?(m=d,y=h,d++):(h++,d++);else if(m!==-1)d=m+1,y++,h=y;else return!1;for(;d<f.length&&f[d]==="*";)d++;return d===f.length}function s(){let u=[...t.names,...t.skips.map(f=>"-"+f)].join(",");return t.enable(""),u}function a(u){for(let f of t.skips)if(i(u,f))return!1;for(let f of t.names)if(i(u,f))return!0;return!1}function c(u){return u instanceof Error?u.stack||u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}KU.exports=NJ});var qU=Rt((Vn,V8)=>{Vn.formatArgs=BJ;Vn.save=MJ;Vn.load=UJ;Vn.useColors=LJ;Vn.storage=FJ();Vn.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();Vn.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function LJ(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let r;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(r[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function BJ(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+V8.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}Vn.log=console.debug||console.log||(()=>{});function MJ(r){try{r?Vn.storage.setItem("debug",r):Vn.storage.removeItem("debug")}catch{}}function UJ(){let r;try{r=Vn.storage.getItem("debug")||Vn.storage.getItem("DEBUG")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function FJ(){try{return localStorage}catch{}}V8.exports=VU()(Vn);var{formatters:$J}=V8.exports;$J.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var ree={};Lt(ree,{BasePlugin:()=>on,MEDIA_TYPE_CAR:()=>Ou,MEDIA_TYPE_CBOR:()=>xo,MEDIA_TYPE_DAG_CBOR:()=>wo,MEDIA_TYPE_DAG_JSON:()=>bo,MEDIA_TYPE_DAG_PB:()=>D0,MEDIA_TYPE_IPNS_RECORD:()=>Ru,MEDIA_TYPE_JSON:()=>vo,MEDIA_TYPE_OCTET_STREAM:()=>Cr,MEDIA_TYPE_RAW:()=>Vr,MEDIA_TYPE_TAR:()=>wh,createVerifiedFetch:()=>XS,verifiedFetch:()=>j8});var rA=Symbol.for("@libp2p/connection");var hs=Symbol.for("@libp2p/content-routing");var sn=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}},V0=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},q0=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},D=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ps=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Ch=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}},Ih=class extends Error{static name="UnsupportedOperationError";constructor(e="Unsupported operation"){super(e),this.name="UnsupportedOperationError"}};var Oc=class extends Error{static name="ConnectionClosedError";constructor(e="The connection is closed"){super(e),this.name="ConnectionClosedError"}},Vu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},Qo=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},qu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Ci=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},kh=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},Ye=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}},zu=class extends Error{static name="InvalidPeerIdError";constructor(e="Invalid PeerID"){super(e),this.name="InvalidPeerIdError"}},Ii=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},z0=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},pa=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}},ju=class extends Error{static name="UnsupportedProtocolError";constructor(e="Unsupported protocol error"){super(e),this.name="UnsupportedProtocolError"}},Le=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}},Dc=class extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}},ki=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},qn=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ma=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}},Nc=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}},Ph=class extends Error{static name="LimitedConnectionError";constructor(e="Limited connection"){super(e),this.name="LimitedConnectionError"}},j0=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(e="Too many inbound protocol streams"){super(e),this.name="TooManyInboundProtocolStreamsError"}},Wu=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(e="Too many outbound protocol streams"){super(e),this.name="TooManyOutboundProtocolStreamsError"}},Zo=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var W0=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ga=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},G0=class extends ga{constructor(e,t){super(!0,e,t)}},X0=class extends ga{constructor(e,t){super(!1,e,t)}};function Y0(r){return r==null?!1:(r.type==="RSA"||r.type==="Ed25519"||r.type==="secp256k1"||r.type==="ECDSA")&&r.raw instanceof Uint8Array&&typeof r.equals=="function"&&typeof r.toMultihash=="function"&&typeof r.toCID=="function"&&typeof r.verify=="function"}var Lc=Symbol.for("@libp2p/peer-discovery");var Q0=Symbol.for("@libp2p/peer-id");function mr(r){return!!r?.[Q0]}var ms=Symbol.for("@libp2p/peer-routing");var Bc="keep-alive";function Z0(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function cr(...r){let e=[];for(let t of r)Z0(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function gr(...r){let e=[];for(let t of r)Z0(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var ya=Symbol.for("@libp2p/transport");var Rh;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Rh||(Rh={}));var _e=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(e){let t=this.#t.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#t.get(e);o==null&&(o=[],this.#t.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#t.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#t.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#t.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var qe=Symbol.for("@libp2p/service-capabilities"),zn=Symbol.for("@libp2p/service-dependencies");function Re(r){let e=new globalThis.AbortController;function t(){let i=r.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Y=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Oh=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Dh=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},J0=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var nA={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new J0("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Qt=nA;var rw={};Lt(rw,{base58btc:()=>Qe,base58flickr:()=>OF});var Mc={};Lt(Mc,{coerce:()=>_o,empty:()=>oA,equals:()=>X8,fromHex:()=>AF,fromString:()=>Y8,isBinary:()=>_F,toHex:()=>SF,toString:()=>Q8});var oA=new Uint8Array(0);function SF(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function AF(r){let e=r.match(/../g);return e!=null?new Uint8Array(e.map(t=>parseInt(t,16))):oA}function X8(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function _o(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function _F(r){return r instanceof ArrayBuffer||ArrayBuffer.isView(r)}function Y8(r){return new TextEncoder().encode(r)}function Q8(r){return new TextDecoder().decode(r)}function TF(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,w=0,x=0,v=m.length;x!==v&&m[x]===0;)x++,y++;for(var E=(v-x)*u+1>>>0,I=new Uint8Array(E);x!==v;){for(var U=m[x],K=0,M=E-1;(U!==0||K<w)&&M!==-1;M--,K++)U+=256*I[M]>>>0,I[M]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");w=K,x++}for(var T=E-w;T!==E&&I[T]===0;)T++;for(var k=c.repeat(y);T<E;++T)k+=r.charAt(I[T]);return k}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var w=0,x=0;m[y]===c;)w++,y++;for(var v=(m.length-y)*l+1>>>0,E=new Uint8Array(v);m[y];){var I=t[m.charCodeAt(y)];if(I===255)return;for(var U=0,K=v-1;(I!==0||U<x)&&K!==-1;K--,U++)I+=a*E[K]>>>0,E[K]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=U,y++}if(m[y]!==" "){for(var M=v-x;M!==v&&E[M]===0;)M++;for(var T=new Uint8Array(w+(v-M)),k=w;M!==v;)T[k++]=E[M++];return T}}}function d(m){var y=h(m);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:d}}var CF=TF,IF=CF,iA=IF;var Z8=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},J8=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return sA(this,e)}},ew=class{decoders;constructor(e){this.decoders=e}or(e){return sA(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function sA(r,e){return new ew({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var tw=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Z8(e,t,n),this.decoder=new J8(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Gu({name:r,prefix:e,encode:t,decode:n}){return new tw(r,e,t,n)}function wa({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=iA(t,r);return Gu({prefix:e,name:r,encode:n,decode:i=>_o(o(i))})}function kF(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let u=e[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function PF(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function RF(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Ht({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=RF(n);return Gu({prefix:e,name:r,encode(i){return PF(i,n,t)},decode(i){return kF(i,o,t,r)}})}var Qe=wa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),OF=wa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var nw={};Lt(nw,{base32:()=>yr,base32hex:()=>BF,base32hexpad:()=>UF,base32hexpadupper:()=>FF,base32hexupper:()=>MF,base32pad:()=>NF,base32padupper:()=>LF,base32upper:()=>DF,base32z:()=>$F});var yr=Ht({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),DF=Ht({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),NF=Ht({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),LF=Ht({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),BF=Ht({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),MF=Ht({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),UF=Ht({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),FF=Ht({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$F=Ht({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ow={};Lt(ow,{base36:()=>an,base36upper:()=>HF});var an=wa({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),HF=wa({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var yt={};Lt(yt,{Digest:()=>Uc,create:()=>cn,decode:()=>ze,equals:()=>sw,hasCode:()=>s$});var KF=lA,aA=128,VF=127,qF=~VF,zF=Math.pow(2,31);function lA(r,e,t){e=e||[],t=t||0;for(var n=t;r>=zF;)e[t++]=r&255|aA,r/=128;for(;r&qF;)e[t++]=r&255|aA,r>>>=7;return e[t]=r|0,lA.bytes=t-n+1,e}var jF=iw,WF=128,cA=127;function iw(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw iw.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&cA)<<o:(s&cA)*Math.pow(2,o),o+=7}while(s>=WF);return iw.bytes=i-n,t}var GF=Math.pow(2,7),XF=Math.pow(2,14),YF=Math.pow(2,21),QF=Math.pow(2,28),ZF=Math.pow(2,35),JF=Math.pow(2,42),e$=Math.pow(2,49),t$=Math.pow(2,56),r$=Math.pow(2,63),n$=function(r){return r<GF?1:r<XF?2:r<YF?3:r<QF?4:r<ZF?5:r<JF?6:r<e$?7:r<t$?8:r<r$?9:10},o$={encode:KF,decode:jF,encodingLength:n$},i$=o$,Nh=i$;function Lh(r,e=0){return[Nh.decode(r,e),Nh.decode.bytes]}function Xu(r,e,t=0){return Nh.encode(r,e,t),e}function Yu(r){return Nh.encodingLength(r)}function cn(r,e){let t=e.byteLength,n=Yu(r),o=n+Yu(t),i=new Uint8Array(o+t);return Xu(r,i,0),Xu(t,i,n),i.set(e,o),new Uc(r,t,e,i)}function ze(r){let e=_o(r),[t,n]=Lh(e),[o,i]=Lh(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Uc(t,o,s,e)}function sw(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&X8(r.bytes,t.bytes)}}var Uc=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function s$(r,e){return r.code===e}function uA(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return c$(t,aw(r),e??Qe.encoder);default:return l$(t,aw(r),e??yr.encoder)}}var fA=new WeakMap;function aw(r){let e=fA.get(r);if(e==null){let t=new Map;return fA.set(r,t),t}return e}var Z=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Bh)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==u$)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=cn(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&sw(e.multihash,n.multihash)}toString(e){return uA(this,e)}toJSON(){return{"/":uA(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??dA(n,o,i.bytes))}else if(t[f$]===!0){let{version:n,multihash:o,code:i}=t,s=ze(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Bh)throw new Error(`Version 0 CID must use dag-pb (code: ${Bh}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=dA(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Bh,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=_o(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Uc(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,h]=Lh(e.subarray(t));return t+=h,f},o=n(),i=Bh;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),l=t+c,u=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=a$(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return aw(i).set(n,e),i}};function a$(r,e){switch(r[0]){case"Q":{let t=e??Qe;return[Qe.prefix,t.decode(`${Qe.prefix}${r}`)]}case Qe.prefix:{let t=e??Qe;return[Qe.prefix,t.decode(r)]}case yr.prefix:{let t=e??yr;return[yr.prefix,t.decode(r)]}case an.prefix:{let t=e??an;return[an.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function c$(r,e,t){let{prefix:n}=t;if(n!==Qe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function l$(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var Bh=112,u$=18;function dA(r,e,t){let n=Yu(r),o=n+Yu(e),i=new Uint8Array(o+t.byteLength);return Xu(r,i,0),Xu(e,i,n),i.set(t,o),i}var f$=Symbol.for("@ipld/js-cid/CID");var cw={};Lt(cw,{identity:()=>Ot});var hA=0,d$="identity",pA=_o;function h$(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return cn(hA,pA(r))}var Ot={code:hA,name:d$,encode:pA,digest:h$};function me(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Ie(r=0){return new Uint8Array(r)}function Bt(r=0){return new Uint8Array(r)}function dt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=Bt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var gA=Symbol.for("@achingbrain/uint8arraylist");function mA(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function To(r){return!!r?.[gA]}var se=class r{bufs;length;[gA]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(To(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(To(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=mA(this.bufs,e);return t.buf[t.index]}set(e,t){let n=mA(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(To(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return dt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:dt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,u=t>a&&t<=c;if(l&&u){if(e===a&&t===c){n.push(s);break}let f=e-a;n.push(s.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!To(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=t;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let d=this.get(f+h);if(n[h]!==d){u=Math.max(1,h-a[d]);break}}if(u===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=Ie(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=Ie(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=Ie(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=Ie(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=Ie(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=Ie(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=Ie(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=Ie(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!me(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var lw={};Lt(lw,{base10:()=>m$});var m$=wa({prefix:"9",name:"base10",alphabet:"0123456789"});var uw={};Lt(uw,{base16:()=>g$,base16upper:()=>y$});var g$=Ht({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),y$=Ht({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var fw={};Lt(fw,{base2:()=>w$});var w$=Ht({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dw={};Lt(dw,{base256emoji:()=>S$});var yA=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),x$=yA.reduce((r,e,t)=>(r[t]=e,r),[]),b$=yA.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function v$(r){return r.reduce((e,t)=>(e+=x$[t],e),"")}function E$(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=b$[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var S$=Gu({prefix:"\u{1F680}",name:"base256emoji",encode:v$,decode:E$});var hw={};Lt(hw,{base64:()=>Zt,base64pad:()=>Mh,base64url:()=>Fc,base64urlpad:()=>A$});var Zt=Ht({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mh=Ht({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fc=Ht({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),A$=Ht({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pw={};Lt(pw,{base8:()=>_$});var _$=Ht({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mw={};Lt(mw,{identity:()=>T$});var T$=Gu({prefix:"\0",name:"identity",encode:r=>Q8(r),decode:r=>Y8(r)});var Pi={};Lt(Pi,{code:()=>lr,decode:()=>xa,encode:()=>P$,name:()=>k$});var C$=new TextEncoder,I$=new TextDecoder,k$="json",lr=512;function P$(r){return C$.encode(JSON.stringify(r))}function xa(r){return JSON.parse(I$.decode(r))}var Co={};Lt(Co,{code:()=>ct,decode:()=>D$,encode:()=>O$,name:()=>R$});var R$="raw",ct=85;function O$(r){return _o(r)}function D$(r){return _o(r)}var yw={};Lt(yw,{sha256:()=>At,sha512:()=>tg});var N$=20;function gs({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new gw(r,e,t,n,o)}var gw=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??N$,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?wA(n,this.code,t?.truncate):n.then(o=>wA(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function wA(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return cn(e,r)}function bA(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var At=gs({name:"sha2-256",code:18,encode:bA("SHA-256")}),tg=gs({name:"sha2-512",code:19,encode:bA("SHA-512")});var $c={...mw,...fw,...pw,...lw,...uw,...nw,...ow,...rw,...hw,...dw},$te={...yw,...cw};function EA(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var vA=EA("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ww=EA("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Bt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),L$={utf8:vA,"utf-8":vA,hex:$c.base16,latin1:ww,ascii:ww,binary:ww,...$c},rg=L$;function O(r,e="utf8"){let t=rg[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function H(r,e="utf8"){let t=rg[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var B$=parseInt("11111",2),xw=parseInt("10000000",2),M$=parseInt("01111111",2),SA={0:Uh,1:Uh,2:U$,3:H$,4:K$,5:$$,6:F$,16:Uh,22:Uh,48:Uh};function Io(r,e={offset:0}){let t=r[e.offset]&B$;if(e.offset++,SA[t]!=null)return SA[t](r,e);throw new Error("No decoder for tag "+t)}function Fh(r,e){let t=0;if((r[e.offset]&xw)===xw){let n=r[e.offset]&M$,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function Uh(r,e){Fh(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=Io(r,e);if(n===null)break;t.push(n)}return t}function U$(r,e){let t=Fh(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function F$(r,e){let t=Fh(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function $$(r,e){return e.offset++,null}function H$(r,e){let t=Fh(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function K$(r,e){let t=Fh(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function V$(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new se;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function ng(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=V$(r.byteLength);return new se(Uint8Array.from([e.byteLength|xw]),e)}function ln(r){let e=new se,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new se(Uint8Array.from([2]),ng(e),e)}function $h(r){let e=Uint8Array.from([0]),t=new se(e,r);return new se(Uint8Array.from([3]),ng(t),t)}function AA(r){return new se(Uint8Array.from([4]),ng(r),r)}function Jo(r,e=48){let t=new se;for(let n of r)t.append(n);return new se(Uint8Array.from([e]),ng(t),t)}var _A="1.2.840.10045.3.1.7",TA="1.3.132.0.34",CA="1.3.132.0.35";async function IA(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function kA(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function PA(r,e,t,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,t.subarray());return n?.signal?.throwIfAborted(),i}var q$=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),z$=Uint8Array.from([6,5,43,129,4,0,34]),j$=Uint8Array.from([6,5,43,129,4,0,35]),RA={ext:!0,kty:"EC",crv:"P-256"},OA={ext:!0,kty:"EC",crv:"P-384"},DA={ext:!0,kty:"EC",crv:"P-521"},Qu=32,Zu=48,Ju=66;function NA(r){let e=Io(r);return bw(e)}function bw(r){let e=r[1],t=H(e,"base64url"),n=r[2][1][0],o=1,i,s;if(e.byteLength===Qu)return i=H(n.subarray(o,o+Qu),"base64url"),s=H(n.subarray(o+Qu),"base64url"),new Kc({...RA,key_ops:["sign"],d:t,x:i,y:s});if(e.byteLength===Zu)return i=H(n.subarray(o,o+Zu),"base64url"),s=H(n.subarray(o+Zu),"base64url"),new Kc({...OA,key_ops:["sign"],d:t,x:i,y:s});if(e.byteLength===Ju)return i=H(n.subarray(o,o+Ju),"base64url"),s=H(n.subarray(o+Ju),"base64url"),new Kc({...DA,key_ops:["sign"],d:t,x:i,y:s});throw new D(`Private key length was wrong length, got ${e.byteLength}, expected 32, 48 or 66`)}function vw(r){let e=Io(r);return LA(e)}function LA(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Qu*2+1)return n=H(e.subarray(t,t+Qu),"base64url"),o=H(e.subarray(t+Qu),"base64url"),new Hc({...RA,key_ops:["verify"],x:n,y:o});if(e.byteLength===Zu*2+1)return n=H(e.subarray(t,t+Zu),"base64url"),o=H(e.subarray(t+Zu),"base64url"),new Hc({...OA,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ju*2+1)return n=H(e.subarray(t,t+Ju),"base64url"),o=H(e.subarray(t+Ju),"base64url"),new Hc({...DA,key_ops:["verify"],x:n,y:o});throw new D(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function BA(r){return Jo([ln(Uint8Array.from([1])),AA(O(r.d??"","base64url")),Jo([UA(r.crv)],160),Jo([$h(new se(Uint8Array.from([4]),O(r.x??"","base64url"),O(r.y??"","base64url")))],161)]).subarray()}function MA(r){return Jo([ln(Uint8Array.from([1])),Jo([UA(r.crv)],160),Jo([$h(new se(Uint8Array.from([4]),O(r.x??"","base64url"),O(r.y??"","base64url")))],161)]).subarray()}function UA(r){if(r==="P-256")return q$;if(r==="P-384")return z$;if(r==="P-521")return j$;throw new D(`Invalid curve ${r}`)}async function FA(r="P-256"){let e=await IA(r);return new Kc(e.privateKey)}var Hc=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=MA(this.jwk)),this._raw}toMultihash(){return Ot.digest(wr(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}async verify(e,t,n){return PA(this.jwk,t,e,n)}},Kc=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Hc({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=BA(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}async sign(e,t){return kA(this.jwk,e,t)}};function Vc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function qr(r,e=""){if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new Error(`${t}expected integer >= 0, got ${r}`)}}function ke(r,e,t=""){let n=Vc(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function ws(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");qr(r.outputLen),qr(r.blockLen)}function ef(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function HA(r,e){ke(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new Error('"digestInto() output" expected to be of length >='+t)}function zr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function qc(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function ei(r,e){return r<<32-e|r>>>e}function og(r,e){return r<<e|r>>>32-e>>>0}var KA=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",W$=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function xs(r){if(ke(r),KA)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=W$[r[t]];return e}var ys={_0:48,_9:57,A:65,F:70,a:97,f:102};function $A(r){if(r>=ys._0&&r<=ys._9)return r-ys._0;if(r>=ys.A&&r<=ys.F)return r-(ys.A-10);if(r>=ys.a&&r<=ys.f)return r-(ys.a-10)}function bs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(KA)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=$A(r.charCodeAt(i)),a=$A(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}var G$=async()=>{};async function VA(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await G$(),n+=i)}}function X$(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ew(r,e=""){return typeof r=="string"?X$(r):ke(r,void 0,e)}function Sn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ke(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}function qA(r,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options must be object or undefined");return Object.assign(r,e)}function Hh(r,e={}){let t=(o,i)=>r(i).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function Ri(r=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(r))}var Sw=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ig(r,e,t){return r&e^~r&t}function sg(r,e,t){return r&e^r&t^e&t}var zc=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=qc(this.buffer)}update(e){ef(this),ke(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=qc(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ef(this),HA(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,zr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=qc(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},vs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ir=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ag=BigInt(4294967295),zA=BigInt(32);function Y$(r,e=!1){return e?{h:Number(r&ag),l:Number(r>>zA&ag)}:{h:Number(r>>zA&ag)|0,l:Number(r&ag)|0}}function jA(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let i=0;i<t;i++){let{h:s,l:a}=Y$(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Aw=(r,e,t)=>r>>>t,_w=(r,e,t)=>r<<32-t|e>>>t,jc=(r,e,t)=>r>>>t|e<<32-t,Wc=(r,e,t)=>r<<32-t|e>>>t,Kh=(r,e,t)=>r<<64-t|e>>>t-32,Vh=(r,e,t)=>r>>>t-32|e<<64-t;function Oi(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var WA=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),GA=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,XA=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),YA=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,QA=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),ZA=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var Z$=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]),ba=new Uint32Array(64),Tw=class extends zc{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)ba[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=ba[f-15],d=ba[f-2],m=ei(h,7)^ei(h,18)^h>>>3,y=ei(d,17)^ei(d,19)^d>>>10;ba[f]=y+ba[f-7]+m+ba[f-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=ei(a,6)^ei(a,11)^ei(a,25),d=u+h+ig(a,c,l)+Z$[f]+ba[f]|0,y=(ei(n,2)^ei(n,13)^ei(n,22))+sg(n,o,i)|0;u=l,l=c,c=a,a=s+d|0,s=i,i=o,o=n,n=d+y|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,l,u)}roundClean(){zr(ba)}destroy(){this.set(0,0,0,0,0,0,0,0),zr(this.buffer)}},Cw=class extends Tw{A=vs[0]|0;B=vs[1]|0;C=vs[2]|0;D=vs[3]|0;E=vs[4]|0;F=vs[5]|0;G=vs[6]|0;H=vs[7]|0;constructor(){super(32)}};var JA=jA(["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(r=>BigInt(r))),J$=JA[0],eH=JA[1],va=new Uint32Array(80),Ea=new Uint32Array(80),Iw=class extends zc{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:d,Gl:m,Hh:y,Hl:w}=this;return[e,t,n,o,i,s,a,c,l,u,f,h,d,m,y,w]}set(e,t,n,o,i,s,a,c,l,u,f,h,d,m,y,w){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=y|0,this.Hl=w|0}process(e,t){for(let E=0;E<16;E++,t+=4)va[E]=e.getUint32(t),Ea[E]=e.getUint32(t+=4);for(let E=16;E<80;E++){let I=va[E-15]|0,U=Ea[E-15]|0,K=jc(I,U,1)^jc(I,U,8)^Aw(I,U,7),M=Wc(I,U,1)^Wc(I,U,8)^_w(I,U,7),T=va[E-2]|0,k=Ea[E-2]|0,z=jc(T,k,19)^Kh(T,k,61)^Aw(T,k,6),W=Wc(T,k,19)^Vh(T,k,61)^_w(T,k,6),$=XA(M,W,Ea[E-7],Ea[E-16]),S=YA($,K,z,va[E-7],va[E-16]);va[E]=S|0,Ea[E]=$|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:d,Fl:m,Gh:y,Gl:w,Hh:x,Hl:v}=this;for(let E=0;E<80;E++){let I=jc(f,h,14)^jc(f,h,18)^Kh(f,h,41),U=Wc(f,h,14)^Wc(f,h,18)^Vh(f,h,41),K=f&d^~f&y,M=h&m^~h&w,T=QA(v,U,M,eH[E],Ea[E]),k=ZA(T,x,I,K,J$[E],va[E]),z=T|0,W=jc(n,o,28)^Kh(n,o,34)^Kh(n,o,39),$=Wc(n,o,28)^Vh(n,o,34)^Vh(n,o,39),S=n&i^n&a^i&a,C=o&s^o&c^s&c;x=y|0,v=w|0,y=d|0,w=m|0,d=f|0,m=h|0,{h:f,l:h}=Oi(l|0,u|0,k|0,z|0),l=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let _=WA(z,$,C);n=GA(_,k,W,S),o=_|0}({h:n,l:o}=Oi(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Oi(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Oi(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Oi(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=Oi(this.Eh|0,this.El|0,f|0,h|0),{h:d,l:m}=Oi(this.Fh|0,this.Fl|0,d|0,m|0),{h:y,l:w}=Oi(this.Gh|0,this.Gl|0,y|0,w|0),{h:x,l:v}=Oi(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,i,s,a,c,l,u,f,h,d,m,y,w,x,v)}roundClean(){zr(va,Ea)}destroy(){zr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},kw=class extends Iw{Ah=Ir[0]|0;Al=Ir[1]|0;Bh=Ir[2]|0;Bl=Ir[3]|0;Ch=Ir[4]|0;Cl=Ir[5]|0;Dh=Ir[6]|0;Dl=Ir[7]|0;Eh=Ir[8]|0;El=Ir[9]|0;Fh=Ir[10]|0;Fl=Ir[11]|0;Gh=Ir[12]|0;Gl=Ir[13]|0;Hh=Ir[14]|0;Hl=Ir[15]|0;constructor(){super(64)}};var ko=Hh(()=>new Cw,Sw(1));var Sa=Hh(()=>new kw,Sw(3));var Rw=BigInt(0),Pw=BigInt(1);function Es(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}" `;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function e_(r){if(typeof r=="bigint"){if(!cg(r))throw new Error("positive bigint expected, got "+r)}else qr(r);return r}function qh(r){let e=e_(r).toString(16);return e.length&1?"0"+e:e}function t_(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Rw:BigInt("0x"+r)}function tf(r){return t_(xs(r))}function Di(r){return t_(xs(Gc(ke(r)).reverse()))}function lg(r,e){qr(e),r=e_(r);let t=bs(r.toString(16).padStart(e*2,"0"));if(t.length!==e)throw new Error("number too large");return t}function zh(r,e){return lg(r,e).reverse()}function Gc(r){return Uint8Array.from(r)}var cg=r=>typeof r=="bigint"&&Rw<=r;function tH(r,e,t){return cg(r)&&cg(e)&&cg(t)&&e<=r&&r<t}function Aa(r,e,t,n){if(!tH(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Ow(r){let e;for(e=0;r>Rw;r>>=Pw,e+=1);return e}var jh=r=>(Pw<<BigInt(r))-Pw;function r_(r,e,t){if(qr(r,"hashLen"),qr(e,"qByteLen"),typeof t!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(r),l=n(r),u=0,f=()=>{c.fill(1),l.fill(0),u=0},h=(...w)=>t(l,Sn(c,...w)),d=(w=o)=>{l=h(i,w),c=h(),w.length!==0&&(l=h(s,w),c=h())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,x=[];for(;w<e;){c=h();let v=c.slice();x.push(v),w+=c.length}return Sn(...x)};return(w,x)=>{f(),d(w);let v;for(;!(v=x(m()));)d();return f(),v}}function Ni(r,e={},t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,s,a){let c=r[i];if(a&&c===void 0)return;let l=typeof c;if(l!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${l}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(t,!0)}function rf(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var un=BigInt(0),xr=BigInt(1),Xc=BigInt(2),i_=BigInt(3),s_=BigInt(4),a_=BigInt(5),rH=BigInt(7),c_=BigInt(8),nH=BigInt(9),l_=BigInt(16);function Dt(r,e){let t=r%e;return t>=un?t:e+t}function _t(r,e,t){let n=r;for(;e-- >un;)n*=n,n%=t;return n}function n_(r,e){if(r===un)throw new Error("invert: expected non-zero number");if(e<=un)throw new Error("invert: expected positive modulus, got "+e);let t=Dt(r,e),n=e,o=un,i=xr,s=xr,a=un;for(;t!==un;){let l=n/t,u=n%t,f=o-s*l,h=i-a*l;n=t,t=u,o=s,i=a,s=f,a=h}if(n!==xr)throw new Error("invert: does not exist");return Dt(o,e)}function Nw(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function u_(r,e){let t=(r.ORDER+xr)/s_,n=r.pow(e,t);return Nw(r,n,e),n}function oH(r,e){let t=(r.ORDER-a_)/c_,n=r.mul(e,Xc),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Xc),o),a=r.mul(i,r.sub(s,r.ONE));return Nw(r,a,e),a}function iH(r){let e=nf(r),t=f_(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+rH)/l_;return(a,c)=>{let l=a.pow(c,s),u=a.mul(l,n),f=a.mul(l,o),h=a.mul(l,i),d=a.eql(a.sqr(u),c),m=a.eql(a.sqr(f),c);l=a.cmov(l,u,d),u=a.cmov(h,f,m);let y=a.eql(a.sqr(u),c),w=a.cmov(l,u,y);return Nw(a,w,c),w}}function f_(r){if(r<i_)throw new Error("sqrt is not defined for small field");let e=r-xr,t=0;for(;e%Xc===un;)e/=Xc,t++;let n=Xc,o=nf(r);for(;o_(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return u_;let i=o.pow(n,e),s=(e+xr)/Xc;return function(c,l){if(c.is0(l))return l;if(o_(c,l)!==1)throw new Error("Cannot find square root");let u=t,f=c.mul(c.ONE,i),h=c.pow(l,e),d=c.pow(l,s);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let m=1,y=c.sqr(h);for(;!c.eql(y,c.ONE);)if(m++,y=c.sqr(y),m===u)throw new Error("Cannot find square root");let w=xr<<BigInt(u-m-1),x=c.pow(f,w);u=m,f=c.sqr(x),h=c.mul(h,f),d=c.mul(d,x)}return d}}function sH(r){return r%s_===i_?u_:r%c_===a_?oH:r%l_===nH?iH(r):f_(r)}var d_=(r,e)=>(Dt(r,e)&xr)===xr,aH=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Lw(r){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},t=aH.reduce((n,o)=>(n[o]="function",n),e);return Ni(r,t),r}function cH(r,e,t){if(t<un)throw new Error("invalid exponent, negatives unsupported");if(t===un)return r.ONE;if(t===xr)return e;let n=r.ONE,o=e;for(;t>un;)t&xr&&(n=r.mul(n,o)),o=r.sqr(o),t>>=xr;return n}function Wh(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function o_(r,e){let t=(r.ORDER-xr)/Xc,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function lH(r,e){e!==void 0&&qr(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}var Dw=class{ORDER;BITS;BYTES;isLE;ZERO=un;ONE=xr;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=un)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&(this.sqrt=t.sqrt),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:i}=lH(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Dt(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return un<=e&&e<this.ORDER}is0(e){return e===un}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&xr)===xr}neg(e){return Dt(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return Dt(e*e,this.ORDER)}add(e,t){return Dt(e+t,this.ORDER)}sub(e,t){return Dt(e-t,this.ORDER)}mul(e,t){return Dt(e*t,this.ORDER)}pow(e,t){return cH(this,e,t)}div(e,t){return Dt(e*n_(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return n_(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=sH(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?zh(e,this.BYTES):lg(e,this.BYTES)}fromBytes(e,t=!1){ke(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let l=new Uint8Array(o);l.set(e,i?0:l.length-e.length),e=l}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Di(e):tf(e);if(a&&(c=Dt(c,s)),!t&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Wh(this,e)}cmov(e,t,n){return n?t:e}};function nf(r,e={}){return new Dw(r,e)}function h_(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Bw(r){let e=h_(r);return e+Math.ceil(e/2)}function Mw(r,e,t=!1){ke(r);let n=r.length,o=h_(e),i=Bw(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Di(r):tf(r),a=Dt(s,e-xr)+xr;return t?zh(a,o):lg(a,o)}var of=BigInt(0),Yc=BigInt(1);function Gh(r,e){let t=e.negate();return r?t:e}function Qc(r,e){let t=Wh(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function y_(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function Uw(r,e){y_(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=jh(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function p_(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=Yc);let l=e*n,u=l+Math.abs(a)-1,f=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:d,offsetF:l}}var Fw=new WeakMap,w_=new WeakMap;function $w(r){return w_.get(r)||1}function m_(r){if(r!==of)throw new Error("invalid wNAF")}var sf=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>of;)t&Yc&&(n=n.add(o)),o=o.double(),t>>=Yc;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=Uw(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let l=1;l<o;l++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Uw(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:l,isZero:u,isNeg:f,isNegF:h,offsetF:d}=p_(n,a,s);n=c,u?i=i.add(Gh(h,t[d])):o=o.add(Gh(f,t[l]))}return m_(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=Uw(e,this.bits);for(let s=0;s<i.windows&&n!==of;s++){let{nextN:a,offset:c,isZero:l,isNeg:u}=p_(n,s,i);if(n=a,!l){let f=t[c];o=o.add(u?f.negate():f)}}return m_(n),o}getPrecomputes(e,t,n){let o=Fw.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),Fw.set(t,o))),o}cached(e,t,n){let o=$w(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=$w(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){y_(t,this.bits),w_.set(e,t),Fw.delete(e)}hasCache(e){return $w(e)!==1}};function x_(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>of||n>of;)t&Yc&&(i=i.add(o)),n&Yc&&(s=s.add(o)),o=o.double(),t>>=Yc,n>>=Yc;return{p1:i,p2:s}}function g_(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Lw(e),e}else return nf(r,{isLE:t})}function ug(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let l=e[c];if(!(typeof l=="bigint"&&l>of))throw new Error(`CURVE.${c} must be positive bigint`)}let o=g_(e.p,t.Fp,n),i=g_(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function af(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var _a=BigInt(0),br=BigInt(1),Hw=BigInt(2),uH=BigInt(8);function fH(r,e,t,n){let o=r.sqr(t),i=r.sqr(n),s=r.add(r.mul(e.a,o),i),a=r.add(r.ONE,r.mul(e.d,r.mul(o,i)));return r.eql(s,a)}function b_(r,e={}){let t=ug("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;Ni(e,{},{uvRatio:"function"});let a=Hw<<BigInt(o.BYTES*8)-br,c=w=>n.create(w),l=e.uvRatio||((w,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(w,x))}}catch{return{isValid:!1,value:_a}}});if(!fH(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(w,x,v=!1){let E=v?br:_a;return Aa("coordinate "+w,x,E,a),x}function f(w){if(!(w instanceof m))throw new Error("EdwardsPoint expected")}let h=rf((w,x)=>{let{X:v,Y:E,Z:I}=w,U=w.is0();x==null&&(x=U?uH:n.inv(I));let K=c(v*x),M=c(E*x),T=n.mul(I,x);if(U)return{x:_a,y:br};if(T!==br)throw new Error("invZ was invalid");return{x:K,y:M}}),d=rf(w=>{let{a:x,d:v}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:E,Y:I,Z:U,T:K}=w,M=c(E*E),T=c(I*I),k=c(U*U),z=c(k*k),W=c(M*x),$=c(k*c(W+T)),S=c(z+c(v*c(M*T)));if($!==S)throw new Error("bad point: equation left != right (1)");let C=c(E*I),_=c(U*K);if(C!==_)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(i.Gx,i.Gy,br,c(i.Gx*i.Gy));static ZERO=new m(_a,br,br,_a);static Fp=n;static Fn=o;X;Y;Z;T;constructor(x,v,E,I){this.X=u("x",x),this.Y=u("y",v),this.Z=u("z",E,!0),this.T=u("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(x){if(x instanceof m)throw new Error("extended point not allowed");let{x:v,y:E}=x||{};return u("x",v),u("y",E),new m(v,E,br,c(v*E))}static fromBytes(x,v=!1){let E=n.BYTES,{a:I,d:U}=i;x=Gc(ke(x,E,"point")),Es(v,"zip215");let K=Gc(x),M=x[E-1];K[E-1]=M&-129;let T=Di(K),k=v?a:n.ORDER;Aa("point.y",T,_a,k);let z=c(T*T),W=c(z-br),$=c(U*z-I),{isValid:S,value:C}=l(W,$);if(!S)throw new Error("bad point: invalid y coordinate");let _=(C&br)===br,B=(M&128)!==0;if(!v&&C===_a&&B)throw new Error("bad point: x=0 and x_0=1");return B!==_&&(C=c(-C)),m.fromAffine({x:C,y:T})}static fromHex(x,v=!1){return m.fromBytes(bs(x),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,v=!0){return y.createCache(this,x),v||this.multiply(Hw),this}assertValidity(){d(this)}equals(x){f(x);let{X:v,Y:E,Z:I}=this,{X:U,Y:K,Z:M}=x,T=c(v*M),k=c(U*I),z=c(E*M),W=c(K*I);return T===k&&z===W}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=i,{X:v,Y:E,Z:I}=this,U=c(v*v),K=c(E*E),M=c(Hw*c(I*I)),T=c(x*U),k=v+E,z=c(c(k*k)-U-K),W=T+K,$=W-M,S=T-K,C=c(z*$),_=c(W*S),B=c(z*S),X=c($*W);return new m(C,_,X,B)}add(x){f(x);let{a:v,d:E}=i,{X:I,Y:U,Z:K,T:M}=this,{X:T,Y:k,Z:z,T:W}=x,$=c(I*T),S=c(U*k),C=c(M*E*W),_=c(K*z),B=c((I+U)*(T+k)-$-S),X=_-C,G=_+C,F=c(S-v*$),Q=c(B*X),ne=c(G*F),V=c(B*F),Ne=c(X*G);return new m(Q,ne,Ne,V)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:E}=y.cached(this,x,I=>Qc(m,I));return Qc(m,[v,E])[0]}multiplyUnsafe(x,v=m.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===_a?m.ZERO:this.is0()||x===br?this:y.unsafe(this,x,E=>Qc(m,E),v)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(x){return h(this,x)}clearCofactor(){return s===br?this:this.multiplyUnsafe(s)}toBytes(){let{x,y:v}=this.toAffine(),E=n.toBytes(v);return E[E.length-1]|=x&br?128:0,E}toHex(){return xs(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new sf(m,o.BITS);return m.BASE.precompute(8),m}function v_(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');Ni(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=t.randomBytes||Ri,c=t.adjustScalarBytes||(T=>T),l=t.domain||((T,k,z)=>{if(Es(z,"phflag"),k.length||z)throw new Error("Contexts/pre-hash are not supported");return T});function u(T){return s.create(Di(T))}function f(T){let k=E.secretKey;ke(T,E.secretKey,"secretKey");let z=ke(e(T),2*k,"hashedSecretKey"),W=c(z.slice(0,k)),$=z.slice(k,2*k),S=u(W);return{head:W,prefix:$,scalar:S}}function h(T){let{head:k,prefix:z,scalar:W}=f(T),$=o.multiply(W),S=$.toBytes();return{head:k,prefix:z,scalar:W,point:$,pointBytes:S}}function d(T){return h(T).pointBytes}function m(T=Uint8Array.of(),...k){let z=Sn(...k);return u(e(l(z,ke(T,void 0,"context"),!!n)))}function y(T,k,z={}){T=ke(T,void 0,"message"),n&&(T=n(T));let{prefix:W,scalar:$,pointBytes:S}=h(k),C=m(z.context,W,T),_=o.multiply(C).toBytes(),B=m(z.context,_,S,T),X=s.create(C+B*$);if(!s.isValid(X))throw new Error("sign failed: invalid s");let G=Sn(_,s.toBytes(X));return ke(G,E.signature,"result")}let w={zip215:!0};function x(T,k,z,W=w){let{context:$,zip215:S}=W,C=E.signature;T=ke(T,C,"signature"),k=ke(k,void 0,"message"),z=ke(z,E.publicKey,"publicKey"),S!==void 0&&Es(S,"zip215"),n&&(k=n(k));let _=C/2,B=T.subarray(0,_),X=Di(T.subarray(_,C)),G,F,Q;try{G=r.fromBytes(z,S),F=r.fromBytes(B,S),Q=o.multiplyUnsafe(X)}catch{return!1}if(!S&&G.isSmallOrder())return!1;let ne=m($,F.toBytes(),G.toBytes(),k);return F.add(G.multiplyUnsafe(ne)).subtract(Q).clearCofactor().is0()}let v=i.BYTES,E={secretKey:v,publicKey:v,signature:2*v,seed:v};function I(T=a(E.seed)){return ke(T,E.seed,"seed")}function U(T){return Vc(T)&&T.length===s.BYTES}function K(T,k){try{return!!r.fromBytes(T,k)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:K,toMontgomery(T){let{y:k}=r.fromBytes(T),z=E.publicKey,W=z===32;if(!W&&z!==57)throw new Error("only defined for 25519 and 448");let $=W?i.div(br+k,br-k):i.div(k-br,k+br);return i.toBytes($)},toMontgomerySecret(T){let k=E.secretKey;ke(T,k);let z=e(T.subarray(0,k));return c(z).subarray(0,k)}};return Object.freeze({keygen:af(I,d),getPublicKey:d,sign:y,verify:x,utils:M,Point:r,lengths:E})}var Xh=BigInt(0),cf=BigInt(1),fg=BigInt(2);function dH(r){return Ni(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function E_(r){let e=dH(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i,randomBytes:s}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=s||Ri,l=a?255:448,u=a?32:56,f=BigInt(a?9:5),h=BigInt(a?121665:39081),d=a?fg**BigInt(254):fg**BigInt(447),m=a?BigInt(8)*fg**BigInt(251)-cf:BigInt(4)*fg**BigInt(445)-cf,y=d+m+cf,w=C=>Dt(C,t),x=v(f);function v(C){return zh(w(C),u)}function E(C){let _=Gc(ke(C,u,"uCoordinate"));return a&&(_[31]&=127),w(Di(_))}function I(C){return Di(o(Gc(ke(C,u,"scalar"))))}function U(C,_){let B=z(E(_),I(C));if(B===Xh)throw new Error("invalid private or public key received");return v(B)}function K(C){return U(C,x)}let M=K,T=U;function k(C,_,B){let X=w(C*(_-B));return _=w(_-X),B=w(B+X),{x_2:_,x_3:B}}function z(C,_){Aa("u",C,Xh,t),Aa("scalar",_,d,y);let B=_,X=C,G=cf,F=Xh,Q=C,ne=cf,V=Xh;for(let Ue=BigInt(l-1);Ue>=Xh;Ue--){let he=B>>Ue&cf;V^=he,{x_2:G,x_3:Q}=k(V,G,Q),{x_2:F,x_3:ne}=k(V,F,ne),V=he;let Ve=G+F,st=w(Ve*Ve),Pt=G-F,Ge=w(Pt*Pt),at=st-Ge,ds=Q+ne,Xo=Q-ne,ha=w(Xo*Ve),H0=w(ds*Pt),Ku=ha+H0,_h=ha-H0;Q=w(Ku*Ku),ne=w(X*w(_h*_h)),G=w(st*Ge),F=w(at*(st+w(h*at)))}({x_2:G,x_3:Q}=k(V,G,Q)),{x_2:F,x_3:ne}=k(V,F,ne);let Ne=i(F);return w(G*Ne)}let W={secretKey:u,publicKey:u,seed:u},$=(C=c(u))=>(ke(C,W.seed,"seed"),C),S={randomSecretKey:$};return Object.freeze({keygen:af($,M),getSharedSecret:T,getPublicKey:M,scalarMult:U,scalarMultBase:K,utils:S,GuBytes:x.slice(),lengths:W})}var hH=BigInt(1),S_=BigInt(2),pH=BigInt(3),mH=BigInt(5),gH=BigInt(8),dg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yH={p:dg,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:gH,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function __(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=dg,a=r*r%i*r%i,c=_t(a,S_,i)*a%i,l=_t(c,hH,i)*r%i,u=_t(l,mH,i)*l%i,f=_t(u,e,i)*u%i,h=_t(f,t,i)*f%i,d=_t(h,n,i)*h%i,m=_t(d,o,i)*d%i,y=_t(m,o,i)*d%i,w=_t(y,e,i)*u%i;return{pow_p_5_8:_t(w,S_,i)*r%i,b2:a}}function T_(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var A_=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wH(r,e){let t=dg,n=Dt(e*e*e,t),o=Dt(n*n*e,t),i=__(r*o).pow_p_5_8,s=Dt(r*n*i,t),a=Dt(e*s*s,t),c=s,l=Dt(s*A_,t),u=a===r,f=a===Dt(-r,t),h=a===Dt(-r*A_,t);return u&&(s=c),(f||h)&&(s=l),d_(s,t)&&(s=Dt(-s,t)),{isValid:u||f,value:s}}var xH=b_(yH,{uvRatio:wH});function bH(r){return v_(xH,Sa,Object.assign({adjustScalarBytes:T_},r))}var Yh=bH({});var Qh=(()=>{let r=dg;return E_({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=__(e);return Dt(_t(t,pH,r)*n,r)},adjustScalarBytes:T_})})();var Zc=32,jn=64,Kw=32;var lf,C_=(async()=>{try{return await Qt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function I_(){let r=Yh.utils.randomSecretKey(),e=Yh.getPublicKey(r);return{privateKey:_H(r,e),publicKey:e}}async function vH(r,e){let t;r.length===jn?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:H(r.subarray(32),"base64url"),d:H(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Qt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Qt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function EH(r,e){let t=r.subarray(0,Kw);return Yh.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function k_(r,e){return lf==null&&(lf=await C_),lf?vH(r,e):EH(r,e)}async function SH(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Qt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Qt.get().subtle.verify({name:"Ed25519"},n,e,t instanceof Uint8Array?t:t.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function AH(r,e,t){return Yh.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function P_(r,e,t){return lf==null&&(lf=await C_),lf?SH(r,e,t):AH(r,e,t)}function _H(r,e){let t=new Uint8Array(jn);for(let n=0;n<Kw;n++)t[n]=r[n],t[Kw+n]=e[n];return t}function uf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Zh=class{type="Ed25519";raw;constructor(e){this.raw=df(e,Zc)}toMultihash(){return Ot.digest(wr(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=P_(this.raw,t,e);return uf(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},ff=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=df(e,jn),this.publicKey=new Zh(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=k_(this.raw,e);return uf(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Vw(r){if(r.length>jn){r=df(r,jn+Zc);let n=r.subarray(0,jn),o=r.subarray(jn,r.length);return new ff(n,o)}r=df(r,jn);let e=r.subarray(0,jn),t=r.subarray(Zc);return new ff(e,t)}function qw(r){return r=df(r,Zc),new Zh(r)}async function O_(){let{privateKey:r,publicKey:e}=I_();return new ff(r,e)}function df(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new D(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var TH=Math.pow(2,7),CH=Math.pow(2,14),IH=Math.pow(2,21),zw=Math.pow(2,28),jw=Math.pow(2,35),Ww=Math.pow(2,42),Gw=Math.pow(2,49),lt=128,jr=127;function $e(r){if(r<TH)return 1;if(r<CH)return 2;if(r<IH)return 3;if(r<zw)return 4;if(r<jw)return 5;if(r<Ww)return 6;if(r<Gw)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function hf(r,e,t=0){switch($e(r)){case 8:e[t++]=r&255|lt,r/=128;case 7:e[t++]=r&255|lt,r/=128;case 6:e[t++]=r&255|lt,r/=128;case 5:e[t++]=r&255|lt,r/=128;case 4:e[t++]=r&255|lt,r>>>=7;case 3:e[t++]=r&255|lt,r>>>=7;case 2:e[t++]=r&255|lt,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function kH(r,e,t=0){switch($e(r)){case 8:e.set(t++,r&255|lt),r/=128;case 7:e.set(t++,r&255|lt),r/=128;case 6:e.set(t++,r&255|lt),r/=128;case 5:e.set(t++,r&255|lt),r/=128;case 4:e.set(t++,r&255|lt),r>>>=7;case 3:e.set(t++,r&255|lt),r>>>=7;case 2:e.set(t++,r&255|lt),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Xw(r,e){let t=r[e],n=0;if(n+=t&jr,t<lt||(t=r[e+1],n+=(t&jr)<<7,t<lt)||(t=r[e+2],n+=(t&jr)<<14,t<lt)||(t=r[e+3],n+=(t&jr)<<21,t<lt)||(t=r[e+4],n+=(t&jr)*zw,t<lt)||(t=r[e+5],n+=(t&jr)*jw,t<lt)||(t=r[e+6],n+=(t&jr)*Ww,t<lt)||(t=r[e+7],n+=(t&jr)*Gw,t<lt))return n;throw new RangeError("Could not decode varint")}function PH(r,e){let t=r.get(e),n=0;if(n+=t&jr,t<lt||(t=r.get(e+1),n+=(t&jr)<<7,t<lt)||(t=r.get(e+2),n+=(t&jr)<<14,t<lt)||(t=r.get(e+3),n+=(t&jr)<<21,t<lt)||(t=r.get(e+4),n+=(t&jr)*zw,t<lt)||(t=r.get(e+5),n+=(t&jr)*jw,t<lt)||(t=r.get(e+6),n+=(t&jr)*Ww,t<lt)||(t=r.get(e+7),n+=(t&jr)*Gw,t<lt))return n;throw new RangeError("Could not decode varint")}function Wr(r,e,t=0){return e==null&&(e=Bt($e(r))),e instanceof Uint8Array?hf(r,e,t):kH(r,e,t)}function Wn(r,e=0){return r instanceof Uint8Array?Xw(r,e):PH(r,e)}var Yw=new Float32Array([-0]),Ta=new Uint8Array(Yw.buffer);function D_(r,e,t){Yw[0]=r,e[t]=Ta[0],e[t+1]=Ta[1],e[t+2]=Ta[2],e[t+3]=Ta[3]}function N_(r,e){return Ta[0]=r[e],Ta[1]=r[e+1],Ta[2]=r[e+2],Ta[3]=r[e+3],Yw[0]}var Qw=new Float64Array([-0]),Gr=new Uint8Array(Qw.buffer);function L_(r,e,t){Qw[0]=r,e[t]=Gr[0],e[t+1]=Gr[1],e[t+2]=Gr[2],e[t+3]=Gr[3],e[t+4]=Gr[4],e[t+5]=Gr[5],e[t+6]=Gr[6],e[t+7]=Gr[7]}function B_(r,e){return Gr[0]=r[e],Gr[1]=r[e+1],Gr[2]=r[e+2],Gr[3]=r[e+3],Gr[4]=r[e+4],Gr[5]=r[e+5],Gr[6]=r[e+6],Gr[7]=r[e+7],Qw[0]}var RH=BigInt(Number.MAX_SAFE_INTEGER),OH=BigInt(Number.MIN_SAFE_INTEGER),Gn=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Jc;if(e<RH&&e>OH)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>M_&&(o=0n,++n>M_&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Jc;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Jc}},Jc=new Gn(0,0);Jc.toBigInt=function(){return 0n};Jc.zzEncode=Jc.zzDecode=function(){return this};Jc.length=function(){return 1};var M_=4294967296n;function U_(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function F_(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Zw(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function ti(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function hg(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Jw=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ti(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ti(this,4);return hg(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ti(this,4);return hg(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ti(this,4);let e=N_(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ti(this,4);let e=B_(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw ti(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return F_(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ti(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ti(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Gn(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw ti(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw ti(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ti(this,8);let e=hg(this.buf,this.pos+=4),t=hg(this.buf,this.pos+=4);return new Gn(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Xw(this.buf,this.pos);return this.pos+=$e(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function e7(r){return new Jw(r instanceof Uint8Array?r:r.subarray())}function xe(r,e,t){let n=e7(r);return e.decode(n,void 0,t)}function t7(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return Bt(s);o+s>e&&(n=Bt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var el=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function r7(){}var o7=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},DH=t7();function NH(r){return globalThis.Buffer!=null?Bt(r):DH(r)}var ep=class{len;head;tail;states;constructor(){this.len=0,this.head=new el(r7,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new el(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new i7((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(pg,10,Gn.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Gn.fromBigInt(e);return this._push(pg,t.length(),t)}uint64Number(e){return this._push(hf,$e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Gn.fromBigInt(e).zzEncode();return this._push(pg,t.length(),t)}sint64Number(e){let t=Gn.fromNumber(e).zzEncode();return this._push(pg,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(n7,1,e?1:0)}fixed32(e){return this._push(Jh,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Gn.fromBigInt(e);return this._push(Jh,4,t.lo)._push(Jh,4,t.hi)}fixed64Number(e){let t=Gn.fromNumber(e);return this._push(Jh,4,t.lo)._push(Jh,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(D_,4,e)}double(e){return this._push(L_,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(n7,1,0):this.uint32(t)._push(BH,t,e)}string(e){let t=U_(e);return t!==0?this.uint32(t)._push(Zw,t,e):this._push(n7,1,0)}fork(){return this.states=new o7(this),this.head=this.tail=new el(r7,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new el(r7,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=NH(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function n7(r,e,t){e[t]=r&255}function LH(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var i7=class extends el{next;constructor(e,t){super(LH,e,t),this.next=void 0}};function pg(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Jh(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function BH(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ep.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(MH,e,r),this},ep.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(UH,e,r),this});function MH(r,e,t){e.set(r,t)}function UH(r,e,t){r.length<40?Zw(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(O(r),t)}function s7(){return new ep}function be(r,e){let t=s7();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var pf;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(pf||(pf={}));function mg(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function wt(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return mg("enum",pf.VARINT,t,n)}function ve(r,e){return mg("message",pf.LENGTH_DELIMITED,r,e)}var ht=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},tp=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var xt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(xt||(xt={}));var a7;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(a7||(a7={}));(function(r){r.codec=()=>wt(a7)})(xt||(xt={}));var Li;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),xt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=xt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>be(t,r.codec()),r.decode=(t,n)=>xe(t,r.codec(),n)})(Li||(Li={}));var rp;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),xt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=xt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>be(t,r.codec()),r.decode=(t,n)=>xe(t,r.codec(),n)})(rp||(rp={}));function fn(r){if(isNaN(r)||r<=0)throw new D("random bytes length must be a Number bigger than 0");return Ri(r)}var op={};Lt(op,{MAX_RSA_KEY_SIZE:()=>c7,generateRSAKeyPair:()=>y7,jwkToJWKKeyPair:()=>q_,jwkToPkcs1:()=>KH,jwkToPkix:()=>d7,jwkToRSAPrivateKey:()=>g7,pkcs1MessageToJwk:()=>u7,pkcs1MessageToRSAPrivateKey:()=>gg,pkcs1ToJwk:()=>HH,pkcs1ToRSAPrivateKey:()=>h7,pkixMessageToJwk:()=>f7,pkixMessageToRSAPublicKey:()=>m7,pkixToJwk:()=>VH,pkixToRSAPublicKey:()=>p7});var mf=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=op.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Z.createV1(114,this._multihash)}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t,n){return V_(this.jwk,t,e,n)}},np=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=op.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,t){return K_(this.jwk,e,t)}};var c7=8192,l7=18,FH=1062,$H=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function HH(r){let e=Io(r);return u7(e)}function u7(r){return{n:H(r[1],"base64url"),e:H(r[2],"base64url"),d:H(r[3],"base64url"),p:H(r[4],"base64url"),q:H(r[5],"base64url"),dp:H(r[6],"base64url"),dq:H(r[7],"base64url"),qi:H(r[8],"base64url"),kty:"RSA"}}function KH(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new D("JWK was missing components");return Jo([ln(Uint8Array.from([0])),ln(O(r.n,"base64url")),ln(O(r.e,"base64url")),ln(O(r.d,"base64url")),ln(O(r.p,"base64url")),ln(O(r.q,"base64url")),ln(O(r.dp,"base64url")),ln(O(r.dq,"base64url")),ln(O(r.qi,"base64url"))]).subarray()}function VH(r){let e=Io(r,{offset:0});return f7(e)}function f7(r){let e=Io(r[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function d7(r){if(r.n==null||r.e==null)throw new D("JWK was missing components");return Jo([$H,$h(Jo([ln(O(r.n,"base64url")),ln(O(r.e,"base64url"))]))]).subarray()}function h7(r){let e=Io(r);return gg(e)}function gg(r){let e=u7(r);return g7(e)}function p7(r,e){if(r.byteLength>=FH)throw new ps("Key size is too large");let t=Io(r,{offset:0});return m7(t,r,e)}function m7(r,e,t){let n=f7(r);if(t==null){let o=ko(Li.encode({Type:xt.RSA,Data:e}));t=cn(l7,o)}return new mf(n,t)}function g7(r){if(j_(r)>c7)throw new D("Key size is too large");let e=q_(r),t=ko(Li.encode({Type:xt.RSA,Data:d7(e.publicKey)})),n=cn(l7,t);return new np(e.privateKey,new mf(e.publicKey,n))}async function y7(r){if(r>c7)throw new D("Key size is too large");let e=await z_(r),t=ko(Li.encode({Type:xt.RSA,Data:d7(e.publicKey)})),n=cn(l7,t);return new np(e.privateKey,new mf(e.publicKey,n))}function q_(r){if(r==null)throw new D("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function z_(r,e){let t=await Qt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await qH(t,e);return{privateKey:n[0],publicKey:n[1]}}async function K_(r,e,t){let n=await Qt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Qt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function V_(r,e,t,n){let o=await Qt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Qt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function qH(r,e){if(r.privateKey==null||r.publicKey==null)throw new D("Private and public key are required");let t=await Promise.all([Qt.get().subtle.exportKey("jwk",r.privateKey),Qt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function j_(r){if(r.kty!=="RSA")throw new D("invalid key type");if(r.n==null)throw new D("invalid key modulus");return O(r.n,"base64url").length*8}var yg=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(ws(e),ke(t,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(t.length>n?e.create().update(t).digest():t);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),zr(o)}update(e){return ef(this),this.iHash.update(e),this}digestInto(e){ef(this),ke(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ca=(r,e,t)=>new yg(r,e).update(t).digest();Ca.create=(r,e)=>new yg(r,e);var W_=(r,e)=>(r+(r>=0?e:-e)/G_)/e;function zH(r,e,t){let[[n,o],[i,s]]=e,a=W_(s*r,t),c=W_(-o*r,t),l=r-a*n-c*i,u=-a*o-c*s,f=l<As,h=u<As;f&&(l=-l),h&&(u=-u);let d=jh(Math.ceil(Ow(t)/2))+gf;if(l<As||l>=d||u<As||u>=d)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}function x7(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function w7(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return Es(t.lowS,"lowS"),Es(t.prehash,"prehash"),t.format!==void 0&&x7(t.format),t}var b7=class extends Error{constructor(e=""){super(e)}},Ia={Err:b7,_tlv:{encode:(r,e)=>{let{Err:t}=Ia;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=qh(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?qh(o.length/2|128):"";return qh(r)+i+o+e},decode(r,e){let{Err:t}=Ia,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=Ia;if(r<As)throw new e("integer: negative integers are not allowed");let t=qh(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=Ia;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return tf(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Ia,o=ke(r,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:l,l:u}=n.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=Ia,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},As=BigInt(0),gf=BigInt(1),G_=BigInt(2),wg=BigInt(3),jH=BigInt(4);function X_(r,e={}){let t=ug("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;Ni(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=Q_(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f($,S,C){let{x:_,y:B}=S.toAffine(),X=n.toBytes(_);if(Es(C,"isCompressed"),C){u();let G=!n.isOdd(B);return Sn(Y_(G),X)}else return Sn(Uint8Array.of(4),X,n.toBytes(B))}function h($){ke($,void 0,"Point");let{publicKey:S,publicKeyUncompressed:C}=l,_=$.length,B=$[0],X=$.subarray(1);if(_===S&&(B===2||B===3)){let G=n.fromBytes(X);if(!n.isValid(G))throw new Error("bad point: is not on curve, wrong x");let F=y(G),Q;try{Q=n.sqrt(F)}catch(Ne){let Ue=Ne instanceof Error?": "+Ne.message:"";throw new Error("bad point: is not on curve, sqrt error"+Ue)}u();let ne=n.isOdd(Q);return(B&1)===1!==ne&&(Q=n.neg(Q)),{x:G,y:Q}}else if(_===C&&B===4){let G=n.BYTES,F=n.fromBytes(X.subarray(0,G)),Q=n.fromBytes(X.subarray(G,G*2));if(!w(F,Q))throw new Error("bad point: is not on curve");return{x:F,y:Q}}else throw new Error(`bad point: got length ${_}, expected compressed=${S} or uncompressed=${C}`)}let d=e.toBytes||f,m=e.fromBytes||h;function y($){let S=n.sqr($),C=n.mul(S,$);return n.add(n.add(C,n.mul($,i.a)),i.b)}function w($,S){let C=n.sqr(S),_=y($);return n.eql(C,_)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(i.a,wg),jH),v=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(x,v)))throw new Error("bad curve params: a or b");function E($,S,C=!1){if(!n.isValid(S)||C&&n.is0(S))throw new Error(`bad point coordinate ${$}`);return S}function I($){if(!($ instanceof k))throw new Error("Weierstrass Point expected")}function U($){if(!c||!c.basises)throw new Error("no endo");return zH($,c.basises,o.ORDER)}let K=rf(($,S)=>{let{X:C,Y:_,Z:B}=$;if(n.eql(B,n.ONE))return{x:C,y:_};let X=$.is0();S==null&&(S=X?n.ONE:n.inv(B));let G=n.mul(C,S),F=n.mul(_,S),Q=n.mul(B,S);if(X)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Q,n.ONE))throw new Error("invZ was invalid");return{x:G,y:F}}),M=rf($=>{if($.is0()){if(e.allowInfinityPoint&&!n.is0($.Y))return;throw new Error("bad point: ZERO")}let{x:S,y:C}=$.toAffine();if(!n.isValid(S)||!n.isValid(C))throw new Error("bad point: x or y not field elements");if(!w(S,C))throw new Error("bad point: equation left != right");if(!$.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function T($,S,C,_,B){return C=new k(n.mul(C.X,$),C.Y,C.Z),S=Gh(_,S),C=Gh(B,C),S.add(C)}class k{static BASE=new k(i.Gx,i.Gy,n.ONE);static ZERO=new k(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(S,C,_){this.X=E("x",S),this.Y=E("y",C,!0),this.Z=E("z",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(S){let{x:C,y:_}=S||{};if(!S||!n.isValid(C)||!n.isValid(_))throw new Error("invalid affine point");if(S instanceof k)throw new Error("projective point not allowed");return n.is0(C)&&n.is0(_)?k.ZERO:new k(C,_,n.ONE)}static fromBytes(S){let C=k.fromAffine(m(ke(S,void 0,"point")));return C.assertValidity(),C}static fromHex(S){return k.fromBytes(bs(S))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(S=8,C=!0){return W.createCache(this,S),C||this.multiply(wg),this}assertValidity(){M(this)}hasEvenY(){let{y:S}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(S)}equals(S){I(S);let{X:C,Y:_,Z:B}=this,{X,Y:G,Z:F}=S,Q=n.eql(n.mul(C,F),n.mul(X,B)),ne=n.eql(n.mul(_,F),n.mul(G,B));return Q&&ne}negate(){return new k(this.X,n.neg(this.Y),this.Z)}double(){let{a:S,b:C}=i,_=n.mul(C,wg),{X:B,Y:X,Z:G}=this,F=n.ZERO,Q=n.ZERO,ne=n.ZERO,V=n.mul(B,B),Ne=n.mul(X,X),Ue=n.mul(G,G),he=n.mul(B,X);return he=n.add(he,he),ne=n.mul(B,G),ne=n.add(ne,ne),F=n.mul(S,ne),Q=n.mul(_,Ue),Q=n.add(F,Q),F=n.sub(Ne,Q),Q=n.add(Ne,Q),Q=n.mul(F,Q),F=n.mul(he,F),ne=n.mul(_,ne),Ue=n.mul(S,Ue),he=n.sub(V,Ue),he=n.mul(S,he),he=n.add(he,ne),ne=n.add(V,V),V=n.add(ne,V),V=n.add(V,Ue),V=n.mul(V,he),Q=n.add(Q,V),Ue=n.mul(X,G),Ue=n.add(Ue,Ue),V=n.mul(Ue,he),F=n.sub(F,V),ne=n.mul(Ue,Ne),ne=n.add(ne,ne),ne=n.add(ne,ne),new k(F,Q,ne)}add(S){I(S);let{X:C,Y:_,Z:B}=this,{X,Y:G,Z:F}=S,Q=n.ZERO,ne=n.ZERO,V=n.ZERO,Ne=i.a,Ue=n.mul(i.b,wg),he=n.mul(C,X),Ve=n.mul(_,G),st=n.mul(B,F),Pt=n.add(C,_),Ge=n.add(X,G);Pt=n.mul(Pt,Ge),Ge=n.add(he,Ve),Pt=n.sub(Pt,Ge),Ge=n.add(C,B);let at=n.add(X,F);return Ge=n.mul(Ge,at),at=n.add(he,st),Ge=n.sub(Ge,at),at=n.add(_,B),Q=n.add(G,F),at=n.mul(at,Q),Q=n.add(Ve,st),at=n.sub(at,Q),V=n.mul(Ne,Ge),Q=n.mul(Ue,st),V=n.add(Q,V),Q=n.sub(Ve,V),V=n.add(Ve,V),ne=n.mul(Q,V),Ve=n.add(he,he),Ve=n.add(Ve,he),st=n.mul(Ne,st),Ge=n.mul(Ue,Ge),Ve=n.add(Ve,st),st=n.sub(he,st),st=n.mul(Ne,st),Ge=n.add(Ge,st),he=n.mul(Ve,Ge),ne=n.add(ne,he),he=n.mul(at,Ge),Q=n.mul(Pt,Q),Q=n.sub(Q,he),he=n.mul(Pt,Ve),V=n.mul(at,V),V=n.add(V,he),new k(Q,ne,V)}subtract(S){return this.add(S.negate())}is0(){return this.equals(k.ZERO)}multiply(S){let{endo:C}=e;if(!o.isValidNot0(S))throw new Error("invalid scalar: out of range");let _,B,X=G=>W.cached(this,G,F=>Qc(k,F));if(C){let{k1neg:G,k1:F,k2neg:Q,k2:ne}=U(S),{p:V,f:Ne}=X(F),{p:Ue,f:he}=X(ne);B=Ne.add(he),_=T(C.beta,V,Ue,G,Q)}else{let{p:G,f:F}=X(S);_=G,B=F}return Qc(k,[_,B])[0]}multiplyUnsafe(S){let{endo:C}=e,_=this;if(!o.isValid(S))throw new Error("invalid scalar: out of range");if(S===As||_.is0())return k.ZERO;if(S===gf)return _;if(W.hasCache(this))return this.multiply(S);if(C){let{k1neg:B,k1:X,k2neg:G,k2:F}=U(S),{p1:Q,p2:ne}=x_(k,_,X,F);return T(C.beta,Q,ne,B,G)}else return W.unsafe(_,S)}toAffine(S){return K(this,S)}isTorsionFree(){let{isTorsionFree:S}=e;return s===gf?!0:S?S(k,this):W.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:S}=e;return s===gf?this:S?S(k,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(S=!0){return Es(S,"isCompressed"),this.assertValidity(),d(k,this,S)}toHex(S=!0){return xs(this.toBytes(S))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let z=o.BITS,W=new sf(k,e.endo?Math.ceil(z/2):z);return k.BASE.precompute(8),k}function Y_(r){return Uint8Array.of(r?2:3)}function Q_(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function WH(r,e={}){let{Fn:t}=r,n=e.randomBytes||Ri,o=Object.assign(Q_(r.Fp,t),{seed:Bw(t.ORDER)});function i(d){try{let m=t.fromBytes(d);return t.isValidNot0(m)}catch{return!1}}function s(d,m){let{publicKey:y,publicKeyUncompressed:w}=o;try{let x=d.length;return m===!0&&x!==y||m===!1&&x!==w?!1:!!r.fromBytes(d)}catch{return!1}}function a(d=n(o.seed)){return Mw(ke(d,o.seed,"seed"),t.ORDER)}function c(d,m=!0){return r.BASE.multiply(t.fromBytes(d)).toBytes(m)}function l(d){let{secretKey:m,publicKey:y,publicKeyUncompressed:w}=o;if(!Vc(d)||"_lengths"in t&&t._lengths||m===y)return;let x=ke(d,void 0,"key").length;return x===y||x===w}function u(d,m,y=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(m)===!1)throw new Error("second arg must be public key");let w=t.fromBytes(d);return r.fromBytes(m).multiply(w).toBytes(y)}let f={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=af(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:r,utils:f,lengths:o})}function Z_(r,e,t={}){ws(e),Ni(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),t=Object.assign({},t);let n=t.randomBytes||Ri,o=t.hmac||((C,_)=>Ca(e,C,_)),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:l,getPublicKey:u,getSharedSecret:f,utils:h,lengths:d}=WH(r,t),m={prehash:!0,lowS:typeof t.lowS=="boolean"?t.lowS:!0,format:"compact",extraEntropy:!1},y=a*G_<i.ORDER;function w(C){let _=a>>gf;return C>_}function x(C,_){if(!s.isValidNot0(_))throw new Error(`invalid signature ${C}: out of range 1..Point.Fn.ORDER`);return _}function v(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function E(C,_){x7(_);let B=d.signature,X=_==="compact"?B:_==="recovered"?B+1:void 0;return ke(C,X)}class I{r;s;recovery;constructor(_,B,X){if(this.r=x("r",_),this.s=x("s",B),X!=null){if(v(),![0,1,2,3].includes(X))throw new Error("invalid recovery id");this.recovery=X}Object.freeze(this)}static fromBytes(_,B=m.format){E(_,B);let X;if(B==="der"){let{r:ne,s:V}=Ia.toSig(ke(_));return new I(ne,V)}B==="recovered"&&(X=_[0],B="compact",_=_.subarray(1));let G=d.signature/2,F=_.subarray(0,G),Q=_.subarray(G,G*2);return new I(s.fromBytes(F),s.fromBytes(Q),X)}static fromHex(_,B){return this.fromBytes(bs(_),B)}assertRecovery(){let{recovery:_}=this;if(_==null)throw new Error("invalid recovery id: must be present");return _}addRecoveryBit(_){return new I(this.r,this.s,_)}recoverPublicKey(_){let{r:B,s:X}=this,G=this.assertRecovery(),F=G===2||G===3?B+a:B;if(!i.isValid(F))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let Q=i.toBytes(F),ne=r.fromBytes(Sn(Y_((G&1)===0),Q)),V=s.inv(F),Ne=K(ke(_,void 0,"msgHash")),Ue=s.create(-Ne*V),he=s.create(X*V),Ve=r.BASE.multiplyUnsafe(Ue).add(ne.multiplyUnsafe(he));if(Ve.is0())throw new Error("invalid recovery: point at infinify");return Ve.assertValidity(),Ve}hasHighS(){return w(this.s)}toBytes(_=m.format){if(x7(_),_==="der")return bs(Ia.hexFromSig(this));let{r:B,s:X}=this,G=s.toBytes(B),F=s.toBytes(X);return _==="recovered"?(v(),Sn(Uint8Array.of(this.assertRecovery()),G,F)):Sn(G,F)}toHex(_){return xs(this.toBytes(_))}}let U=t.bits2int||function(_){if(_.length>8192)throw new Error("input is too large");let B=tf(_),X=_.length*8-c;return X>0?B>>BigInt(X):B},K=t.bits2int_modN||function(_){return s.create(U(_))},M=jh(c);function T(C){return Aa("num < 2^"+c,C,As,M),s.toBytes(C)}function k(C,_){return ke(C,void 0,"message"),_?ke(e(C),void 0,"prehashed message"):C}function z(C,_,B){let{lowS:X,prehash:G,extraEntropy:F}=w7(B,m);C=k(C,G);let Q=K(C),ne=s.fromBytes(_);if(!s.isValidNot0(ne))throw new Error("invalid private key");let V=[T(ne),T(Q)];if(F!=null&&F!==!1){let Ve=F===!0?n(d.secretKey):F;V.push(ke(Ve,void 0,"extraEntropy"))}let Ne=Sn(...V),Ue=Q;function he(Ve){let st=U(Ve);if(!s.isValidNot0(st))return;let Pt=s.inv(st),Ge=r.BASE.multiply(st).toAffine(),at=s.create(Ge.x);if(at===As)return;let ds=s.create(Pt*s.create(Ue+at*ne));if(ds===As)return;let Xo=(Ge.x===at?0:2)|Number(Ge.y&gf),ha=ds;return X&&w(ds)&&(ha=s.neg(ds),Xo^=1),new I(at,ha,y?void 0:Xo)}return{seed:Ne,k2sig:he}}function W(C,_,B={}){let{seed:X,k2sig:G}=z(C,_,B);return r_(e.outputLen,s.BYTES,o)(X,G).toBytes(B.format)}function $(C,_,B,X={}){let{lowS:G,prehash:F,format:Q}=w7(X,m);if(B=ke(B,void 0,"publicKey"),_=k(_,F),!Vc(C)){let ne=C instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+ne)}E(C,Q);try{let ne=I.fromBytes(C,Q),V=r.fromBytes(B);if(G&&ne.hasHighS())return!1;let{r:Ne,s:Ue}=ne,he=K(_),Ve=s.inv(Ue),st=s.create(he*Ve),Pt=s.create(Ne*Ve),Ge=r.BASE.multiplyUnsafe(st).add(V.multiplyUnsafe(Pt));return Ge.is0()?!1:s.create(Ge.x)===Ne}catch{return!1}}function S(C,_,B={}){let{prehash:X}=w7(B,m);return _=k(_,X),I.fromBytes(C,"recovered").recoverPublicKey(_).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:f,utils:h,lengths:d,Point:r,sign:W,verify:$,recoverPublicKey:S,Signature:I,hash:e})}var E7={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},GH={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var J_=BigInt(2);function XH(r){let e=E7.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%e,u=l*l*r%e,f=_t(u,t,e)*u%e,h=_t(f,t,e)*u%e,d=_t(h,J_,e)*l%e,m=_t(d,o,e)*d%e,y=_t(m,i,e)*m%e,w=_t(y,a,e)*y%e,x=_t(w,c,e)*w%e,v=_t(x,a,e)*y%e,E=_t(v,t,e)*u%e,I=_t(E,s,e)*m%e,U=_t(I,n,e)*l%e,K=_t(U,J_,e);if(!v7.eql(v7.sqr(K),r))throw new Error("Cannot find square root");return K}var v7=nf(E7.p,{sqrt:XH}),YH=X_(E7,{Fp:v7,endo:GH}),ri=Z_(YH,ko);var eT=32;function tT(r,e,t){let n=At.digest(e instanceof Uint8Array?e:e.subarray());if(uf(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),ri.sign(o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Oh(String(o))});try{return ri.sign(n.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Oh(String(o))}}function rT(r,e,t,n){let o=At.digest(t instanceof Uint8Array?t:t.subarray());if(uf(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),ri.verify(e,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Dh(String(i))});try{return n?.signal?.throwIfAborted(),ri.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Dh(String(i))}}var ip=class{type="secp256k1";raw;_key;constructor(e){this._key=iT(e),this.raw=nT(this._key)}toMultihash(){return Ot.digest(wr(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return Qe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t,n){return rT(this._key,t,e,n)}},sp=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=oT(e),this.publicKey=new ip(t??sT(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,t){return tT(this.raw,e,t)}};function S7(r){return new sp(r)}function A7(r){return new ip(r)}async function aT(){let r=QH();return new sp(r)}function nT(r){return ri.Point.fromBytes(r).toBytes()}function oT(r){try{return ri.getPublicKey(r,!0),r}catch(e){throw new Ch(String(e))}}function iT(r){try{return ri.Point.fromBytes(r),r}catch(e){throw new ps(String(e))}}function sT(r){try{return ri.getPublicKey(r,!0)}catch(e){throw new Ch(String(e))}}function QH(){return ri.utils.randomSecretKey()}async function yf(r,e){if(r==="Ed25519")return O_();if(r==="secp256k1")return aT();if(r==="RSA")return y7(ZH(e));if(r==="ECDSA")return FA(JH(e));throw new Zo}function Wt(r,e){let{Type:t,Data:n}=Li.decode(r),o=n??new Uint8Array;switch(t){case xt.RSA:return p7(o,e);case xt.Ed25519:return qw(o);case xt.secp256k1:return A7(o);case xt.ECDSA:return vw(o);default:throw new Zo}}function xg(r){let{Type:e,Data:t}=Li.decode(r.digest),n=t??new Uint8Array;switch(e){case xt.Ed25519:return qw(n);case xt.secp256k1:return A7(n);case xt.ECDSA:return vw(n);default:throw new Zo}}function wr(r){return Li.encode({Type:xt[r.type],Data:r.raw})}function cT(r){let e=rp.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case xt.RSA:return h7(t);case xt.Ed25519:return Vw(t);case xt.secp256k1:return S7(t);case xt.ECDSA:return NA(t);default:throw new Zo}}function lT(r){if(r.byteLength===jn)return Vw(r);if(r.byteLength===eT)return S7(r);let e=Io(r),t=e[2]?.[0];if(t===_A||t===TA||t===CA)return bw(e);if(e.length>8)return gg(e);throw new D("Could not extract private key from raw bytes")}function tl(r){return rp.encode({Type:xt[r.type],Data:r.raw})}function ZH(r){return r==null?2048:parseInt(r,10)}function JH(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new D("Unsupported curve, should be P-256, P-384 or P-521")}async function bg(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new D("Only RSA and ECDSA keys are supported")}var ap=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ka=new Uint32Array(80),_7=class extends zc{A=ap[0]|0;B=ap[1]|0;C=ap[2]|0;D=ap[3]|0;E=ap[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:e,B:t,C:n,D:o,E:i}=this;return[e,t,n,o,i]}set(e,t,n,o,i){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0}process(e,t){for(let c=0;c<16;c++,t+=4)ka[c]=e.getUint32(t,!1);for(let c=16;c<80;c++)ka[c]=og(ka[c-3]^ka[c-8]^ka[c-14]^ka[c-16],1);let{A:n,B:o,C:i,D:s,E:a}=this;for(let c=0;c<80;c++){let l,u;c<20?(l=ig(o,i,s),u=1518500249):c<40?(l=o^i^s,u=1859775393):c<60?(l=sg(o,i,s),u=2400959708):(l=o^i^s,u=3395469782);let f=og(n,5)+l+a+u+ka[c]|0;a=s,s=i,i=og(o,30),o=n,n=f}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,this.set(n,o,i,s,a)}roundClean(){zr(ka)}destroy(){this.set(0,0,0,0,0),zr(this.buffer)}},uT=Hh(()=>new _7);function fT(r,e,t,n){ws(r);let o=qA({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(qr(i,"c"),qr(s,"dkLen"),qr(a,"asyncTick"),i<1)throw new Error("iterations (c) must be >= 1");let c=Ew(e,"password"),l=Ew(t,"salt"),u=new Uint8Array(s),f=Ca.create(r,c),h=f._cloneInto().update(l);return{c:i,dkLen:s,asyncTick:a,DK:u,PRF:f,PRFSalt:h}}function dT(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),zr(o),t}function hT(r,e,t,n){let{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=fT(r,e,t,n),l,u=new Uint8Array(4),f=qc(u),h=new Uint8Array(a.outputLen);for(let d=1,m=0;m<i;d++,m+=a.outputLen){let y=s.subarray(m,m+a.outputLen);f.setInt32(0,d,!1),(l=c._cloneInto(l)).update(u).digestInto(h),y.set(h.subarray(0,y.length));for(let w=1;w<o;w++){a._cloneInto(l).update(h).digestInto(h);for(let x=0;x<y.length;x++)y[x]^=h[x]}}return dT(a,c,s,l,h)}async function vg(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:l}=fT(r,e,t,n),u,f=new Uint8Array(4),h=qc(f),d=new Uint8Array(c.outputLen);for(let m=1,y=0;y<i;m++,y+=c.outputLen){let w=a.subarray(y,y+c.outputLen);h.setInt32(0,m,!1),(u=l._cloneInto(u)).update(f).digestInto(d),w.set(d.subarray(0,w.length)),await VA(o-1,s,()=>{c._cloneInto(u).update(d).digestInto(d);for(let x=0;x<w.length;x++)w[x]^=d[x]})}return dT(c,l,a,u,d)}var pT={sha1:uT,"sha2-256":ko,"sha2-512":Sa};function cp(r,e,t,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(pT).join(" / ");throw new D(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let i=pT[o],s=hT(i,r,e,{c:t,dkLen:n});return Zt.encode(s).substring(1)}var T7={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},mT={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},gT=new globalThis.TextEncoder;function eK(r,e){let t=T7[e],n=mT[e];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(e,n*t);return n}function tK(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=T7[e],o=mT[e],i=r;for(;i.length>0;){let s=gT.encodeInto(i,t);i=i.slice(s.read);for(let a=0;a<s.written;a++)o^=BigInt(t[a]),o=BigInt.asUintN(e,o*n)}return o}function C7(r,{size:e=32,utf8Buffer:t}={}){if(!T7[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return tK(r,e,t);r=gT.encode(r)}return eK(r,e)}var lp={hash:r=>Number(C7(r,{size:32})),hashV:(r,e)=>rK(lp.hash(r,e))};function rK(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),O(e,"base16")}var I7=64,ni=class{fp;h;seed;constructor(e,t,n,o=2){if(o>I7)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),s=Ie(o);for(let a=0;a<s.length;a++)s[a]=i[a];s.length===0&&(s[0]=7),this.fp=s,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?me(this.fp,e.fp):!1}};function rl(r,e){return Math.floor(Math.random()*(e-r))+r}var nl=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");let t=rl(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof ni))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var nK=500,up=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??lp,this.seed=e.seed??rl(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=O(e));let t=new ni(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new nl(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new nl(this.bucketSize)),this.buckets[n].add(t)||this.buckets[o].add(t))return this.count++,!0;let i=[n,o],s=i[rl(0,i.length-1)];this.buckets[s]==null&&(this.buckets[s]=new nl(this.bucketSize));for(let a=0;a<nK;a++){let c=this.buckets[s].swap(t);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new nl(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=O(e));let t=new ni(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.has(t)??!1;if(o)return o;let i=(n^t.hash())%this.filterSize;return this.buckets[i]?.has(t)??!1}remove(e){typeof e=="string"&&(e=O(e));let t=new ni(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,o=this.buckets[n]?.remove(t)??!1;if(o)return this.count--,o;let i=(n^t.hash())%this.filterSize,s=this.buckets[i]?.remove(t)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},oK={1:.5,2:.84,4:.95,8:.98};function iK(r=.001){return r>.002?2:r>1e-5?4:8}function yT(r,e=.001){let t=iK(e),n=oK[t],o=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),I7);return{filterSize:o,bucketSize:t,fingerprintSize:i}}var Eg=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??lp,this.seed=e.seed??rl(0,Math.pow(2,10)),this.filterSeries=[new up({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=O(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new up({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=O(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=O(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function vr(r,e=.001,t){return new Eg({...yT(r,e),...t??{}})}function Te(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new D(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}var Sg=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=e,i+=u,i>l||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var wT=45,sK=15,wf=new Sg;function Ag(r){if(!(r.length>sK))return wf.new(r).parseWith(()=>wf.readIPv4Addr())}function _g(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wT))return wf.new(r).parseWith(()=>wf.readIPv6Addr())}function xf(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>wT)return;let t=wf.new(r).parseWith(()=>wf.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}function xT(r,e,t){let n=0;for(let o of r)if(!(n<e)){if(n>t)break;if(o!==255)return!1;n++}return!0}function bT(r,e,t,n){let o=0;for(let i of r)if(!(o<t)){if(o>n)break;if(i!==e[o])return!1;o++}return!0}function k7(r){switch(r.length){case ol:return r.join(".");case il:{let e=[];for(let t=0;t<r.length;t++)t%2===0&&e.push(r[t].toString(16).padStart(2,"0")+r[t+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function vT(r){let e=0;for(let[t,n]of r.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=t+1;o<r.length;o++)if(r[o]!=0)return-1;break}return e}function ET(r){let e="0x";for(let t of r)e+=(t>>4).toString(16)+(t&15).toString(16);return e}var ol=4,il=16,qie=parseInt("0xFFFF",16),aK=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function fp(r,e){e.length===il&&r.length===ol&&xT(e,0,11)&&(e=e.slice(12)),e.length===ol&&r.length===il&&bT(r,aK,0,11)&&(r=r.slice(12));let t=r.length;if(t!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=r[o]&e[o];return n}function ST(r,e){if(typeof e=="string"&&(e=xf(e)),e==null)throw new Error("Invalid ip");if(e.length!==r.network.length)return!1;for(let t=0;t<e.length;t++)if((r.network[t]&r.mask[t])!==(e[t]&r.mask[t]))return!1;return!0}function P7(r){let[e,t]=r.split("/");if(!e||!t)throw new Error("Failed to parse given CIDR: "+r);let n=ol,o=Ag(e);if(o==null&&(n=il,o=_g(e),o==null))throw new Error("Failed to parse given CIDR: "+r);let i=parseInt(t,10);if(Number.isNaN(i)||String(i).length!==t.length||i<0||i>n*8)throw new Error("Failed to parse given CIDR: "+r);let s=R7(i,8*n);return{network:fp(o,s),mask:s}}function R7(r,e){if(e!==8*ol&&e!==8*il)throw new Error("Invalid CIDR mask");if(r<0||r>e)throw new Error("Invalid CIDR mask");let t=e/8,n=new Uint8Array(t);for(let o=0;o<t;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var sl=class{constructor(e,t){if(t==null)({network:this.network,mask:this.mask}=P7(e));else{let n=xf(e);if(n==null)throw new Error("Failed to parse network");t=String(t);let o=parseInt(t,10);if(Number.isNaN(o)||String(o).length!==t.length||o<0||o>n.length*8){let i=xf(t);if(i==null)throw new Error("Failed to parse mask");this.mask=i}else this.mask=R7(o,8*n.length);this.network=fp(n,this.mask)}}contains(e){return ST({network:this.network,mask:this.mask},e)}toString(){let e=vT(this.mask),t=e!==-1?String(e):ET(this.mask);return k7(this.network)+"/"+t}};function AT(r,e){return new sl(r).contains(e)}function Tg(r){try{let e=Te(r);switch(e.type){case"ip6":return AT("2000::/3",e.host);default:return!1}}catch{return!1}}function _T(r){try{let e=Te(r);switch(e.type){case"ip4":return e.host.startsWith("169.254.");case"ip6":return e.host.toLowerCase().startsWith("fe80");default:return!1}}catch{return!1}}function TT(r){return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(r)||/^::1$/.test(r)}function dp(r){try{let e=Te(r);switch(e.type){case"ip4":case"ip6":return TT(e.host);default:return!1}}catch{return!1}}function kr(r){try{return Te(r),!0}catch{return!1}}function oi(r){return!!Ag(r)}function Cg(r){return!!_g(r)}var IT=gt(CT(),1),cK=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],lK=cK.map(r=>new IT.Netmask(r));function O7(r){for(let e of lK)if(e.contains(r))return!0;return!1}function uK(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function fK(r){let e=r.split(":");if(e.length<2)return!1;let t=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(t.substring(0,2),16)}.${parseInt(t.substring(2),16)}`;return O7(o)}function dK(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function hK(r){let e=r.split(":"),t=e[e.length-1];return O7(t)}function pK(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function bf(r){if(oi(r))return O7(r);if(uK(r))return fK(r);if(dK(r))return hK(r);if(Cg(r))return pK(r)}function Kt(r){try{let e=Te(r);switch(e.type){case"ip4":case"ip6":return bf(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function Ke(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ig=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},vf=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ig(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Ig(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var D7=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ur(r={}){return mK(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function mK(r,e){e=e??{};let t=e.onEnd,n=new vf,o,i,s,a=Ke(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,x)=>{i=v=>{i=null,n.push(v);try{w(r(n))}catch(E){x(E)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ke()})}},l=w=>i!=null?i(w):(n.push(w),o),u=w=>(n=new vf,i!=null?i({error:w}):(n.push({error:w}),o)),f=w=>{if(s)return o;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:w})},h=w=>s?o:(s=!0,w!=null?u(w):l({done:!0})),d=()=>(n=new vf,h(),{done:!0}),m=w=>(h(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:m,push:f,end:h,get readableLength(){return n.size},onEmpty:async w=>{let x=w?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let v,E;x!=null&&(v=new Promise((I,U)=>{E=()=>{U(new D7)},x.addEventListener("abort",E)}));try{await Promise.race([a.promise,v])}finally{E!=null&&x!=null&&x?.removeEventListener("abort",E)}}},t==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(w){return y.throw(w),t!=null&&(t(w),t=void 0),{done:!0}},return(){return y.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(w){return y.end(w),t!=null&&(t(w),t=void 0),o},get readableLength(){return y.readableLength},onEmpty:w=>y.onEmpty(w)},o}var N7=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},L7=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},kT=r=>globalThis.DOMException===void 0?new L7(r):new DOMException(r),PT=r=>{let e=r.reason===void 0?kT("This operation was aborted."):r.reason;return e instanceof Error?e:kT(e)};function B7(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((u,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&f(PT(d)),a=()=>{f(PT(d))},d.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(u,f);return}let h=new N7;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(d){f(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(h.message=o??`Promise timed out after ${t} milliseconds`,f(h))},t),(async()=>{try{u(await r)}catch(d){f(d)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var gK=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function yK(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:u}=gK(r),f=async(...d)=>{let m=t.multiArgs?d:d[0];if(t.filter)try{if(!await t.filter(m))return}catch(y){n(),s(y);return}c.push(m),t.count===c.length&&(n(),i(c))},h=(...d)=>{n(),s(t.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,f);for(let d of t.rejectionEvents)a.includes(d)||u(d,h)};for(let d of a)l(d,f);for(let d of t.rejectionEvents)a.includes(d)||l(d,h);t.signal&&t.signal.addEventListener("abort",()=>{h(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=B7(o,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Ze(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=yK(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function _s(r,e){let t,n=function(){let o=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var kg=class extends Error{remainingPoints;msBeforeNext;consumedPoints;isFirstInDuration;constructor(e="Rate limit exceeded",t){super(e),this.name="RateLimitError",this.remainingPoints=t.remainingPoints,this.msBeforeNext=t.msBeforeNext,this.consumedPoints=t.consumedPoints,this.isFirstInDuration=t.isFirstInDuration}},Pg=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}},al=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Rg=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Og=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function wK(r){return r.reason}async function rt(r,e,t){if(e==null)return r;let n=t?.translateError??wK;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Dg=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Ke(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new sn)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function xK(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ng=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=xK(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new sn),this.cleanup())}async join(e={}){let t=new Dg(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await rt(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Gt=class extends _e{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=_s(this.emitEmpty.bind(this),1),this.emitIdle=_s(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Pg;let n=new Ng(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new sn)}),this.clear()}async onEmpty(e){this.size!==0&&await Ze(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Ze(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ze(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=ur({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},o=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new sn("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var bK=Math.pow(2,20)*4,Pa=class extends _e{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??bK,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new se,this.writeBuffer=new se,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new Og)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),rt(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ur(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let n=i=>{e.end(i.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Ci(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new G0(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Ci(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new qu;this.dispatchEvent(new X0(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ga))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let i=this.writeBuffer.sublist(0,o),s=new se(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new W0(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new kh(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new kh(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Ra=class extends Pa{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ze(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ze(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Ef(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Oa=class extends _e{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let n=s=>{try{this.onData(s.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await rt(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new Qo;let t=this.onCreateStream({...this.streamOptions,...e});return Ef(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new Rg(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=n=>{let o=this.streams.findIndex(i=>i===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var Da=class extends Pa{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ze(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Ze(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var Sf=class{movingAverage;variance;deviation;forecast;timeSpan;previousTime;constructor(e){this.timeSpan=e,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}alpha(e,t){return 1-Math.exp(-(e-t)/this.timeSpan)}push(e,t=Date.now()){if(this.previousTime!=null){let n=this.alpha(t,this.previousTime),o=e-this.movingAverage,i=n*o;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+o*i),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*o}else this.movingAverage=e;this.previousTime=t}};var vK=1.2,EK=2,SK=5e3,AK=6e4,_K=5e3,ii=class{success;failure;next;metric;timeoutMultiplier;failureMultiplier;minTimeout;maxTimeout;constructor(e={}){let t=e.interval??_K;this.success=new Sf(t),this.failure=new Sf(t),this.next=new Sf(t),this.failureMultiplier=e.failureMultiplier??EK,this.timeoutMultiplier=e.timeoutMultiplier??vK,this.minTimeout=e.minTimeout??SK,this.maxTimeout=e.maxTimeout??AK,e.metricName!=null&&(this.metric=e.metrics?.registerMetricGroup(e.metricName))}getTimeoutSignal(e={}){let t=Math.round(this.next.movingAverage*(e.timeoutFactor??this.timeoutMultiplier));t<this.minTimeout&&(t=this.minTimeout),t>this.maxTimeout&&(t=this.maxTimeout);let n=AbortSignal.timeout(t),o=Re([e.signal,n]);return o.start=Date.now(),o.timeout=t,o}cleanUp(e){let t=Date.now()-e.start;e.aborted?(this.failure.push(t),this.next.push(t*this.failureMultiplier),this.metric?.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:t})):(this.success.push(t),this.next.push(t),this.metric?.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:t}))}};var Pr=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ts=class extends Error{static name="ValidationError";name="ValidationError"},Lg=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Bg=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function U7(r){return e=>H(e,r)}function F7(r){return e=>O(e,r)}function Af(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function cl(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function RT(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=O(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=cl(n);return dt([t,o],t.length+o.length)}function OT(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=yr.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=cl(n);return dt([t,o],t.length+o.length)}function $7(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=H(e,"base32"),o=Af(t);return`${n}:${o}`}var H7=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new Pr("Invalid byte value in IP address");e[n]=o}),e},DT=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=oi(t[n]),s;i&&(s=H7(t[n]),t[n]=H(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,H(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new Pr("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},NT=function(r){if(r.byteLength!==4)throw new Pr("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},LT=function(r){if(r.byteLength!==16)throw new Pr("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Pr(`Invalid IPv6 address "${t}"`)}};function BT(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Pr(`Invalid IPv6 address "${r}"`)}}var M7=Object.values($c).map(r=>r.decoder),TK=(function(){let r=M7[0].or(M7[1]);return M7.slice(2).forEach(e=>r=r.or(e)),r})();function MT(r){return TK.decode(r)}function UT(r){return e=>r.encoder.encode(e)}function CK(r){if(parseInt(r).toString()!==r)throw new Ts("Value must be an integer")}function IK(r){if(r<0)throw new Ts("Value must be a positive integer, or zero")}function kK(r){return e=>{if(e>r)throw new Ts(`Value must be smaller than or equal to ${r}`)}}function PK(...r){return e=>{for(let t of r)t(e)}}var pp=PK(CK,IK,kK(65535));var Er=-1,K7=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Bg(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ks=new K7,zK=[{code:4,name:"ip4",size:32,valueToBytes:H7,bytesToValue:NT,validate:r=>{if(!oi(r))throw new Ts(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:273,name:"udp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:33,name:"dccp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:41,name:"ip6",size:128,valueToBytes:DT,bytesToValue:LT,stringToValue:BT,validate:r=>{if(!Cg(r))throw new Ts(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:Er},{code:43,name:"ipcidr",size:8,bytesToValue:U7("base10"),valueToBytes:F7("base10")},{code:53,name:"dns",size:Er},{code:54,name:"dns4",size:Er},{code:55,name:"dns6",size:Er},{code:56,name:"dnsaddr",size:Er},{code:132,name:"sctp",size:16,valueToBytes:cl,bytesToValue:Af,validate:pp},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:Er,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:Er,bytesToValue:U7("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?F7("base58btc")(r):Z.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:$7,valueToBytes:RT},{code:445,name:"onion3",size:296,bytesToValue:$7,valueToBytes:OT},{code:446,name:"garlic64",size:Er},{code:447,name:"garlic32",size:Er},{code:448,name:"tls"},{code:449,name:"sni",size:Er},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:Er,bytesToValue:UT(Fc),valueToBytes:MT},{code:480,name:"http"},{code:481,name:"http-path",size:Er,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:Er}];zK.forEach(r=>{ks.addProtocol(r)});function FT(r){let e=[],t=0;for(;t<r.length;){let n=Wn(r,t),o=ks.getProtocol(n),i=$e(n),s=jK(o,r,t+i),a=0;s>0&&o.size===Er&&(a=$e(s));let c=i+a+s,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let u=t+i+a,f=r.subarray(u,u+s);l.value=o.bytesToValue?.(f)??H(f)}e.push(l),t+=c}return e}function $T(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=ks.getProtocol(n.code),i=$e(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??O(n.value),a=s.byteLength,o.size===Er&&(c=$e(a)));let l=new Uint8Array(i+c+a),u=0;hf(n.code,l,u),u+=i,s!=null&&(o.size===Er&&(hf(a,l,u),u+=c),l.set(s,u)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return dt(t,e)}function HT(r){if(r.charAt(0)!=="/")throw new Pr('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=ks.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new Pr(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Pr(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new Pr("Incomplete multiaddr");return e}function KT(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=ks.getProtocol(e.code);if(t==null)throw new Pr(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function jK(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Wn(e,t)}var WK=Symbol.for("nodejs.util.inspect.custom"),Q7=Symbol.for("@multiformats/multiaddr");function GK(r){if(r==null&&(r="/"),Mi(r))return r.getComponents();if(r instanceof Uint8Array)return FT(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),HT(r);if(Array.isArray(r))return r;throw new Pr("Must be a string, Uint8Array, Component[], or another Multiaddr")}var $g=class r{[Q7]=!0;#t;#e;#r;constructor(e="/",t={}){this.#t=GK(e),t.validate!==!1&&XK(this)}get bytes(){return this.#r==null&&(this.#r=$T(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=KT(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#t,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Lg(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===e){t=n;break}return new r(this.#t.slice(0,t),{validate:!1})}equals(e){return me(this.bytes,e.bytes)}[WK](){return`Multiaddr(${this.toString()})`}};function XK(r){r.getComponents().forEach(e=>{let t=ks.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Mi(r){return!!r?.[Q7]}function ie(r){return new $g(r)}var Z7=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ke(),this.haveNext=Ke()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ke(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ke(),await rt(this.readNext.promise,t?.signal,t)}};function VT(){return new Z7}function YK(r){return r[Symbol.asyncIterator]!=null}async function QK(r,e,t){try{await Promise.all(r.map(async n=>{for await(let o of n)await e.push(o,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*ZK(r){let e=new AbortController,t=VT();QK(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*JK(r){for(let e of r)yield*e}function eV(...r){let e=[];for(let t of r)YK(t)||e.push(t);return e.length===r.length?JK(e):ZK(r)}var dn=eV;function Xn(r,...e){if(r==null)throw new Error("Empty pipeline");if(J7(r)){let n=r;r=()=>n.source}else if(zT(r)||qT(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&J7(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)J7(t[n])&&(t[n]=rV(t[n]));return tV(...t)}var tV=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},qT=r=>r?.[Symbol.asyncIterator]!=null,zT=r=>r?.[Symbol.iterator]!=null,J7=r=>r==null?!1:r.sink!=null&&r.source!=null,rV=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=ur({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(qT(i))o=async function*(){yield*i,n.end()};else if(zT(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return dn(n,o())}return r.source};var nV=4194304,Hg=class extends Error{static name="UnwrappedError";name="UnwrappedError"},bp=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},tx=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},rx=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function oV(r){return typeof r?.closeRead=="function"}function iV(r){return typeof r?.close=="function"}function ex(r){return oV(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:iV(r)?r.status!=="open":!1}function sV(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Kg(r,e){let t=e?.maxBufferSize??nV,n=new se,o,i=!1;if(!sV(r))throw new D("Argument should be a Stream or a Multiaddr");let s=u=>{if(n.append(u.data),n.byteLength>t){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${t}`))}o?.resolve()};r.addEventListener("message",s);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(u){if(i===!0)throw new Hg("Stream was unwrapped");if(ex(r)){if(u?.bytes==null)return null;if(n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new al(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let f=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await rt(o.promise,u?.signal),ex(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(ex(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,h),new al(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return l.read(u)}let d=n.sublist(0,h);return n.consume(h),d},async write(u,f){if(i===!0)throw new Hg("Stream was unwrapped");r.send(u)||await Ze(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return l}function La(r,e={}){let t=Kg(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=$e(e.maxDataLength));let n=e?.lengthDecoder??Wn,o=e?.lengthEncoder??Wr;return{async read(s){let a=-1,c=new se;for(;;){let u=await t.read({...s,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new bp("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new rx(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new tx(`Message length too long - ${a} > ${e.maxDataLength}`);let l=await t.read({...s,bytes:a});if(l==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new al(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(l.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",l.byteLength,a),new al(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(s,a){await t.write(new se(o(s.byteLength),s),a)},async writeV(s,a){let c=new se(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function bt(r,e){let t=La(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var aV=1024*1024*4,cV=1024*1024*4,Vg=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new se,this.maxBufferSize=e.maxBufferSize??aV,this.maxDataLength=e.maxDataLength??cV,this.lengthDecoder=e.lengthDecoder??Wn,this.encodingLength=e.encodingLength??$e}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new D(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let t;try{t=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(t<0||t>this.maxDataLength)throw new bp("Invalid message length");let n=this.encodingLength(t),o=n+t;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};var lV=["string","number","bigint","symbol"],uV=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function jT(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(lV.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(fV(r))return"Buffer";let t=dV(r);return t||"Object"}function fV(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function dV(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(uV.includes(e))return e}var A=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};A.uint=new A(0,"uint",!0);A.negint=new A(1,"negint",!0);A.bytes=new A(2,"bytes",!0);A.string=new A(3,"string",!0);A.array=new A(4,"array",!1);A.map=new A(5,"map",!1);A.tag=new A(6,"tag",!1);A.float=new A(7,"float",!0);A.false=new A(7,"false",!0);A.true=new A(7,"true",!0);A.null=new A(7,"null",!0);A.undefined=new A(7,"undefined",!0);A.break=new A(7,"break",!0);var j=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var If=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",hV=new TextDecoder,pV=new TextEncoder;function qg(r){return If&&globalThis.Buffer.isBuffer(r)}function vp(r){return r instanceof Uint8Array?qg(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var YT=If?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):GT(r,e,t):(r,e,t)=>t-e>64?hV.decode(r.subarray(e,t)):GT(r,e,t),zg=If?r=>r.length>64?globalThis.Buffer.from(r):WT(r):r=>r.length>64?pV.encode(r):WT(r),Ui=r=>Uint8Array.from(r),kf=If?(r,e,t)=>qg(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),QT=If?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),vp(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},ZT=If?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function jg(r,e){if(qg(r)&&qg(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function WT(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function GT(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],l=r[e+3],(a&192)===128&&(c&192)===128&&(l&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|l&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return nx(n)}var XT=4096;function nx(r){let e=r.length;if(e<=XT)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=XT));return t}var mV=256,Ep=class{constructor(e=mV){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=ZT(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=kf(n,0,this.cursor)}else t=QT(this.chunks,this.cursor);return e&&this.reset(),t}};var ge="CBOR decode error:",Ps="CBOR encode error:",Sp=[];Sp[23]=1;Sp[24]=2;Sp[25]=3;Sp[26]=5;Sp[27]=9;function Rs(r,e,t){if(r.length-e<t)throw new Error(`${ge} not enough data for type`)}var Sr=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Yn(r,e,t){Rs(r,e,1);let n=r[e];if(t.strict===!0&&n<Sr[0])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);return n}function Qn(r,e,t){Rs(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Sr[1])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);return n}function Zn(r,e,t){Rs(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Sr[2])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);return n}function Jn(r,e,t){Rs(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<Sr[3])throw new Error(`${ge} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${ge} integers outside of the safe integer range are not supported`)}function JT(r,e,t,n){return new j(A.uint,Yn(r,e+1,n),2)}function eC(r,e,t,n){return new j(A.uint,Qn(r,e+1,n),3)}function tC(r,e,t,n){return new j(A.uint,Zn(r,e+1,n),5)}function rC(r,e,t,n){return new j(A.uint,Jn(r,e+1,n),9)}function Po(r,e){return Rr(r,0,e.value)}function Rr(r,e,t){if(t<Sr[0]){let n=Number(t);r.push([e|n])}else if(t<Sr[1]){let n=Number(t);r.push([e|24,n])}else if(t<Sr[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Sr[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<Sr[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${ge} encountered BigInt larger than allowable range`)}}Po.encodedSize=function(e){return Rr.encodedSize(e.value)};Rr.encodedSize=function(e){return e<Sr[0]?1:e<Sr[1]?2:e<Sr[2]?3:e<Sr[3]?5:9};Po.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function nC(r,e,t,n){return new j(A.negint,-1-Yn(r,e+1,n),2)}function oC(r,e,t,n){return new j(A.negint,-1-Qn(r,e+1,n),3)}function iC(r,e,t,n){return new j(A.negint,-1-Zn(r,e+1,n),5)}var ox=BigInt(-1),sC=BigInt(1);function aC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new j(A.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${ge} integers outside of the safe integer range are not supported`);return new j(A.negint,ox-BigInt(o),9)}function Wg(r,e){let t=e.value,n=typeof t=="bigint"?t*ox-sC:t*-1-1;Rr(r,e.type.majorEncoded,n)}Wg.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*ox-sC:t*-1-1;return n<Sr[0]?1:n<Sr[1]?2:n<Sr[2]?3:n<Sr[3]?5:9};Wg.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Ap(r,e,t,n){Rs(r,e,t+n);let o=kf(r,e+t,e+t+n);return new j(A.bytes,o,t+n)}function cC(r,e,t,n){return Ap(r,e,1,t)}function lC(r,e,t,n){return Ap(r,e,2,Yn(r,e+1,n))}function uC(r,e,t,n){return Ap(r,e,3,Qn(r,e+1,n))}function fC(r,e,t,n){return Ap(r,e,5,Zn(r,e+1,n))}function dC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer bytes lengths not supported`);return Ap(r,e,9,o)}function Gg(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===A.string?zg(r.value):r.value),r.encodedBytes}function Pf(r,e){let t=Gg(e);Rr(r,e.type.majorEncoded,t.length),r.push(t)}Pf.encodedSize=function(e){let t=Gg(e);return Rr.encodedSize(t.length)+t.length};Pf.compareTokens=function(e,t){return yV(Gg(e),Gg(t))};function yV(r,e){return r.length<e.length?-1:r.length>e.length?1:jg(r,e)}function _p(r,e,t,n,o){let i=t+n;Rs(r,e,i);let s=new j(A.string,YT(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=kf(r,e+t,e+i)),s}function hC(r,e,t,n){return _p(r,e,1,t,n)}function pC(r,e,t,n){return _p(r,e,2,Yn(r,e+1,n),n)}function mC(r,e,t,n){return _p(r,e,3,Qn(r,e+1,n),n)}function gC(r,e,t,n){return _p(r,e,5,Zn(r,e+1,n),n)}function yC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer string lengths not supported`);return _p(r,e,9,o,n)}var wC=Pf;function Rf(r,e,t,n){return new j(A.array,n,t)}function xC(r,e,t,n){return Rf(r,e,1,t)}function bC(r,e,t,n){return Rf(r,e,2,Yn(r,e+1,n))}function vC(r,e,t,n){return Rf(r,e,3,Qn(r,e+1,n))}function EC(r,e,t,n){return Rf(r,e,5,Zn(r,e+1,n))}function SC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer array lengths not supported`);return Rf(r,e,9,o)}function AC(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${ge} indefinite length items not allowed`);return Rf(r,e,1,1/0)}function Xg(r,e){Rr(r,A.array.majorEncoded,e.value)}Xg.compareTokens=Po.compareTokens;Xg.encodedSize=function(e){return Rr.encodedSize(e.value)};function Of(r,e,t,n){return new j(A.map,n,t)}function _C(r,e,t,n){return Of(r,e,1,t)}function TC(r,e,t,n){return Of(r,e,2,Yn(r,e+1,n))}function CC(r,e,t,n){return Of(r,e,3,Qn(r,e+1,n))}function IC(r,e,t,n){return Of(r,e,5,Zn(r,e+1,n))}function kC(r,e,t,n){let o=Jn(r,e+1,n);if(typeof o=="bigint")throw new Error(`${ge} 64-bit integer map lengths not supported`);return Of(r,e,9,o)}function PC(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${ge} indefinite length items not allowed`);return Of(r,e,1,1/0)}function Yg(r,e){Rr(r,A.map.majorEncoded,e.value)}Yg.compareTokens=Po.compareTokens;Yg.encodedSize=function(e){return Rr.encodedSize(e.value)};function RC(r,e,t,n){return new j(A.tag,t,1)}function OC(r,e,t,n){return new j(A.tag,Yn(r,e+1,n),2)}function DC(r,e,t,n){return new j(A.tag,Qn(r,e+1,n),3)}function NC(r,e,t,n){return new j(A.tag,Zn(r,e+1,n),5)}function LC(r,e,t,n){return new j(A.tag,Jn(r,e+1,n),9)}function Qg(r,e){Rr(r,A.tag.majorEncoded,e.value)}Qg.compareTokens=Po.compareTokens;Qg.encodedSize=function(e){return Rr.encodedSize(e.value)};var SV=20,AV=21,_V=22,TV=23;function BC(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${ge} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new j(A.null,null,1):new j(A.undefined,void 0,1)}function MC(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${ge} indefinite length items not allowed`);return new j(A.break,void 0,1)}function ix(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${ge} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${ge} Infinity values are not supported`)}return new j(A.float,r,e)}function UC(r,e,t,n){return ix(sx(r,e+1),3,n)}function FC(r,e,t,n){return ix(ax(r,e+1),5,n)}function $C(r,e,t,n){return ix(qC(r,e+1),9,n)}function Zg(r,e,t){let n=e.value;if(n===!1)r.push([A.float.majorEncoded|SV]);else if(n===!0)r.push([A.float.majorEncoded|AV]);else if(n===null)r.push([A.float.majorEncoded|_V]);else if(n===void 0)r.push([A.float.majorEncoded|TV]);else{let o,i=!1;(!t||t.float64!==!0)&&(KC(n),o=sx(ai,1),n===o||Number.isNaN(n)?(ai[0]=249,r.push(ai.slice(0,3)),i=!0):(VC(n),o=ax(ai,1),n===o&&(ai[0]=250,r.push(ai.slice(0,5)),i=!0))),i||(CV(n),o=qC(ai,1),ai[0]=251,r.push(ai.slice(0,9)))}}Zg.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){KC(n);let o=sx(ai,1);if(n===o||Number.isNaN(n))return 3;if(VC(n),o=ax(ai,1),n===o)return 5}return 9};var HC=new ArrayBuffer(9),Ro=new DataView(HC,1),ai=new Uint8Array(HC,0);function KC(r){if(r===1/0)Ro.setUint16(0,31744,!1);else if(r===-1/0)Ro.setUint16(0,64512,!1);else if(Number.isNaN(r))Ro.setUint16(0,32256,!1);else{Ro.setFloat32(0,r);let e=Ro.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Ro.setUint16(0,31744,!1);else if(t===0)Ro.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Ro.setUint16(0,0):o<-14?Ro.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Ro.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function sx(r,e){if(r.length-e<2)throw new Error(`${ge} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function VC(r){Ro.setFloat32(0,r,!1)}function ax(r,e){if(r.length-e<4)throw new Error(`${ge} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function CV(r){Ro.setFloat64(0,r,!1)}function qC(r,e){if(r.length-e<8)throw new Error(`${ge} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Zg.compareTokens=Po.compareTokens;function Je(r,e,t){throw new Error(`${ge} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Jg(r){return()=>{throw new Error(`${ge} ${r}`)}}var oe=[];for(let r=0;r<=23;r++)oe[r]=Je;oe[24]=JT;oe[25]=eC;oe[26]=tC;oe[27]=rC;oe[28]=Je;oe[29]=Je;oe[30]=Je;oe[31]=Je;for(let r=32;r<=55;r++)oe[r]=Je;oe[56]=nC;oe[57]=oC;oe[58]=iC;oe[59]=aC;oe[60]=Je;oe[61]=Je;oe[62]=Je;oe[63]=Je;for(let r=64;r<=87;r++)oe[r]=cC;oe[88]=lC;oe[89]=uC;oe[90]=fC;oe[91]=dC;oe[92]=Je;oe[93]=Je;oe[94]=Je;oe[95]=Jg("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)oe[r]=hC;oe[120]=pC;oe[121]=mC;oe[122]=gC;oe[123]=yC;oe[124]=Je;oe[125]=Je;oe[126]=Je;oe[127]=Jg("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)oe[r]=xC;oe[152]=bC;oe[153]=vC;oe[154]=EC;oe[155]=SC;oe[156]=Je;oe[157]=Je;oe[158]=Je;oe[159]=AC;for(let r=160;r<=183;r++)oe[r]=_C;oe[184]=TC;oe[185]=CC;oe[186]=IC;oe[187]=kC;oe[188]=Je;oe[189]=Je;oe[190]=Je;oe[191]=PC;for(let r=192;r<=215;r++)oe[r]=RC;oe[216]=OC;oe[217]=DC;oe[218]=NC;oe[219]=LC;oe[220]=Je;oe[221]=Je;oe[222]=Je;oe[223]=Je;for(let r=224;r<=243;r++)oe[r]=Jg("simple values are not supported");oe[244]=Je;oe[245]=Je;oe[246]=Je;oe[247]=BC;oe[248]=Jg("simple values are not supported");oe[249]=UC;oe[250]=FC;oe[251]=$C;oe[252]=Je;oe[253]=Je;oe[254]=Je;oe[255]=MC;var ci=[];for(let r=0;r<24;r++)ci[r]=new j(A.uint,r,1);for(let r=-1;r>=-24;r--)ci[31-r]=new j(A.negint,r,1);ci[64]=new j(A.bytes,new Uint8Array(0),1);ci[96]=new j(A.string,"",1);ci[128]=new j(A.array,0,1);ci[160]=new j(A.map,0,1);ci[244]=new j(A.false,!1,1);ci[245]=new j(A.true,!0,1);ci[246]=new j(A.null,null,1);function e2(r){switch(r.type){case A.false:return Ui([244]);case A.true:return Ui([245]);case A.null:return Ui([246]);case A.bytes:return r.value.length?void 0:Ui([64]);case A.string:return r.value===""?Ui([96]):void 0;case A.array:return r.value===0?Ui([128]):void 0;case A.map:return r.value===0?Ui([160]):void 0;case A.uint:return r.value<24?Ui([Number(r.value)]):void 0;case A.negint:if(r.value>=-24)return Ui([31-Number(r.value)])}}var kV={float64:!1,mapSorter:RV,quickEncodeToken:e2},jC=Object.freeze({float64:!0,mapSorter:OV,quickEncodeToken:e2});function lx(){let r=[];return r[A.uint.major]=Po,r[A.negint.major]=Wg,r[A.bytes.major]=Pf,r[A.string.major]=wC,r[A.array.major]=Xg,r[A.map.major]=Yg,r[A.tag.major]=Qg,r[A.float.major]=Zg,r}var ux=lx(),cx=new Ep,t2=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Ps} object contains circular references`);return new r(t,e)}},Ba={null:new j(A.null,null),undefined:new j(A.undefined,void 0),true:new j(A.true,!0),false:new j(A.false,!1),emptyArray:new j(A.array,0),emptyMap:new j(A.map,0)},Ma={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new j(A.float,r):r>=0?new j(A.uint,r):new j(A.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new j(A.uint,r):new j(A.negint,r)},Uint8Array(r,e,t,n){return new j(A.bytes,r)},string(r,e,t,n){return new j(A.string,r)},boolean(r,e,t,n){return r?Ba.true:Ba.false},null(r,e,t,n){return Ba.null},undefined(r,e,t,n){return Ba.undefined},ArrayBuffer(r,e,t,n){return new j(A.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new j(A.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Ba.emptyArray,new j(A.break)]:Ba.emptyArray;n=t2.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Tp(s,t,n);return t.addBreakTokens?[new j(A.array,r.length),o,new j(A.break)]:[new j(A.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[Ba.emptyMap,new j(A.break)]:Ba.emptyMap;n=t2.createCheck(n,r);let a=[],c=0;for(let l of i)a[c++]=[Tp(l,t,n),Tp(o?r.get(l):r[l],t,n)];return PV(a,t),t.addBreakTokens?[new j(A.map,s),a,new j(A.break)]:[new j(A.map,s),a]}};Ma.Map=Ma.Object;Ma.Buffer=Ma.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ma[`${r}Array`]=Ma.DataView;function Tp(r,e={},t){let n=jT(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||Ma[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=Ma[n];if(!i)throw new Error(`${Ps} unsupported type: ${n}`);return i(r,n,e,t)}function PV(r,e){e.mapSorter&&r.sort(e.mapSorter)}function RV(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=ux[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function OV(r,e){if(r[0]instanceof j&&e[0]instanceof j){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=zC(t.value)),n._keyBytes||(n._keyBytes=zC(n.value)),jg(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function zC(r){return r2(r,ux,jC)}function WC(r,e,t,n){if(Array.isArray(e))for(let o of e)WC(r,o,t,n);else t[e.type.major](r,e,n)}function r2(r,e,t){let n=Tp(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),a=new Ep(s);if(i(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return vp(a.chunks[0])}}return cx.reset(),WC(cx,n,e,t),cx.toBytes(!0)}function Ua(r,e){return e=Object.assign({},kV,e),r2(r,ux,e)}var DV={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},n2=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=ci[e];if(t===void 0){let n=oe[e];if(!n)throw new Error(`${ge} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Cp=Symbol.for("DONE"),o2=Symbol.for("BREAK");function NV(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Df(e,t);if(i===o2){if(r.value===1/0)break;throw new Error(`${ge} got unexpected break to lengthed array`)}if(i===Cp)throw new Error(`${ge} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function LV(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Df(e,t);if(a===o2){if(r.value===1/0)break;throw new Error(`${ge} got unexpected break to lengthed map`)}if(a===Cp)throw new Error(`${ge} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${ge} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${ge} found repeat map key "${a}"`);let c=Df(e,t);if(c===Cp)throw new Error(`${ge} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Df(r,e){if(r.done())return Cp;let t=r.next();if(t.type===A.break)return o2;if(t.type.terminal)return t.value;if(t.type===A.array)return NV(t,r,e);if(t.type===A.map)return LV(t,r,e);if(t.type===A.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Df(r,e);return e.tags[t.value](n)}throw new Error(`${ge} tag not supported (${t.value})`)}throw new Error("unsupported")}function fx(r,e){if(!(r instanceof Uint8Array))throw new Error(`${ge} data to decode must be a Uint8Array`);e=Object.assign({},DV,e);let t=e.tokenizer||new n2(r,e),n=Df(t,e);if(n===Cp)throw new Error(`${ge} did not find any content to decode`);if(n===o2)throw new Error(`${ge} got unexpected break`);return[n,r.subarray(t.pos())]}function eo(r,e){let[t,n]=fx(r,e);if(n.length>0)throw new Error(`${ge} too many terminals, data makes no sense`);return t}var i2=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nf=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},s2=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ip=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function a2(r){return r[Symbol.asyncIterator]!=null}function GC(r,e){if(r.byteLength>e)throw new Nf("Message length too long")}var l2=r=>{let e=$e(r),t=Bt(e);return Wr(r,t),l2.bytes=e,t};l2.bytes=0;function Os(r,e){e=e??{};let t=e.lengthEncoder??l2,n=e?.maxDataLength??4194304;function*o(i){GC(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return a2(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}Os.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??l2,n=e?.maxDataLength??4194304;return GC(r,n),new se(t(r.byteLength),r)};var fl;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(fl||(fl={}));var hx=r=>{let e=Wn(r);return hx.bytes=$e(e),e};hx.bytes=0;function dl(r,e){let t=new se,n=fl.LENGTH,o=-1,i=e?.lengthDecoder??hx,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===fl.LENGTH)try{if(o=i(t),o<0)throw new i2("Invalid message length");if(o>a)throw new Nf("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=fl.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new s2("Message length length too long");break}throw l}if(n===fl.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=fl.LENGTH}}}return a2(r)?(async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new Ip("Unexpected end of input")})():(function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new Ip("Unexpected end of input")})()}dl.fromReader=(r,e)=>{let t=1,n=(async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}})();return dl(n,{...e??{},onLength:i=>{t=i}})};function MV(r,e){if(typeof r=="string")return UV(r);if(typeof r=="number")return HV(r,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}var u2=MV;function UV(r){if(typeof r!="string"||r.length===0||r.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,o=parseFloat(t),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function FV(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function $V(r){let e=Math.abs(r);return e>=315576e5?hl(r,e,315576e5,"year"):e>=26298e5?hl(r,e,26298e5,"month"):e>=6048e5?hl(r,e,6048e5,"week"):e>=864e5?hl(r,e,864e5,"day"):e>=36e5?hl(r,e,36e5,"hour"):e>=6e4?hl(r,e,6e4,"minute"):e>=1e3?hl(r,e,1e3,"second"):`${r} ms`}function HV(r,e){if(typeof r!="number"||!Number.isFinite(r))throw Error("Value provided to ms.format() must be of type number.");return e?.long?$V(r):FV(r)}function hl(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function px(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=u2,t.destroy=l,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let f=0;for(let h=0;h<u.length;h++)f=(f<<5)-f+u.charCodeAt(h),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(u,f){let h,d=null,m,y;function w(...x){if(!w.enabled)return;let v=w,E=Number(new Date),I=E-(h||E);v.diff=I,v.prev=h,v.curr=E,h=E,x[0]=t.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let U=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,(M,T)=>{if(M==="%%")return"%";U++;let k=t.formatters[T];if(typeof k=="function"){let z=x[U];M=k.call(v,z),x.splice(U,1),U--}return M}),t.formatArgs.call(v,x),f?.onLog!=null&&f.onLog(...x),(v.log||t.log).apply(v,x)}return w.namespace=u,w.useColors=t.useColors(),w.color=t.selectColor(u),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(m!==t.namespaces&&(m=t.namespaces,y=t.enabled(u)),y),set:x=>{d=x}}),typeof t.init=="function"&&t.init(w),w}function n(u,f){let h=t(this.namespace+(typeof f>"u"?":":f)+u);return h.log=this.log,h}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let f,h=(typeof u=="string"?u:"").split(/[\s,]+/),d=h.length;for(f=0;f<d;f++)h[f]&&(u=h[f].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.substr(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,h;for(f=0,h=t.skips.length;f<h;f++)if(t.skips[f].test(u))return!1;for(f=0,h=t.names.length;f<h;f++)if(t.names[f].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var f2=GV(),KV=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function VV(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function qV(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+u2(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var zV=console.debug??console.log??(()=>{});function jV(r){try{r?f2?.setItem("debug",r):f2?.removeItem("debug")}catch{}}function WV(){let r;try{r=f2?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function GV(){try{return localStorage}catch{}}function XV(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var YC=px({formatArgs:qV,save:jV,load:WV,useColors:VV,setupFormatters:XV,colors:KV,storage:f2,log:zV});var An=YC;An.formatters.b=r=>r==null?"undefined":Qe.baseEncode(r);An.formatters.t=r=>r==null?"undefined":yr.baseEncode(r);An.formatters.m=r=>r==null?"undefined":Zt.baseEncode(r);An.formatters.p=r=>r==null?"undefined":r.toString();An.formatters.c=r=>r==null?"undefined":r.toString();An.formatters.k=r=>r==null?"undefined":r.toString();An.formatters.a=r=>r==null?"undefined":r.toString();function QC(r,e=""){let t=ZC(r.message),n=ZC(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
|
|
4
4
|
`).join(`
|
|
5
5
|
${e}`)}`:`${t}
|
|
6
6
|
${e}${n.split(`
|
|
@@ -107,13 +107,13 @@ a=end-of-candidates
|
|
|
107
107
|
`;try{r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
|
|
108
108
|
a=ice-ufrag:`+e+t).replace(/\na=ice-pwd:[^\n]*\n/,`
|
|
109
109
|
a=ice-pwd:`+e+t)}catch{}return r}var nS=O("libp2p-webrtc-noise:");function WB(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=O(n,"hex"),i=cn(At.code,o),s=eS.decode(tS(e)),a=nS.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?dt([nS,s,i.bytes],a):dt([nS,i.bytes,s],a)}var kQ=O6?"iceconnectionstatechange":"connectionstatechange";function PQ(r,e){return r.role==="server"}async function GB(r,e,t,n){let o=r.createDataChannel("",{negotiated:!0,id:0});try{if(n.role==="client"){n.log.trace("client creating local offer");let f=await r.createOffer();n.log.trace("client created local offer %s",f.sdp);let h=rS(f,t);n.log.trace("client setting local offer %s",h.sdp),await r.setLocalDescription(h);let d=qB(n.remoteAddr,t);n.log.trace("client setting server description %s",d.sdp),await r.setRemoteDescription(d)}else{let f=zB(n.remoteAddr,t);n.log.trace("server setting client %s %s",f.type,f.sdp),await r.setRemoteDescription(f),n.log.trace("server creating local answer");let h=await r.createAnswer();n.log.trace("server created local answer");let d=rS(h,t);n.log.trace("server setting local description %s",h.sdp),await r.setLocalDescription(d)}if(o.readyState!=="open"&&(n.log.trace("%s wait for handshake channel to open, starting status %s",n.role,o.readyState),await Ze(o,"open",n)),n.log.trace("%s handshake channel opened",n.role),PQ(n,r)){let f=r.remoteFingerprint()?.value??"";n.remoteAddr=n.remoteAddr.encapsulate(VB(f))}let i=KB(r.localDescription?.sdp);if(i==null)throw new nc("Could not get fingerprint from local description sdp");n.log.trace("%s performing noise handshake",n.role);let s=WB(i,n.remoteAddr,n.role),a=i4({prologueBytes:s})(n),c=e1({channel:o,direction:"outbound",isHandshake:!0,log:n.log,...n.dataChannel??{}}),l=t1({peerConnection:r,remoteAddr:n.remoteAddr,metrics:n.events,direction:n.role==="client"?"outbound":"inbound",log:n.logger.forComponent("libp2p:webrtc-direct:connection")});if(r.addEventListener(kQ,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":l.close().catch(f=>{n.log.error("error closing connection - %e",f),l.abort(f)});break;default:break}}),n.events?.increment({peer_connection:!0}),n.role==="client"){n.log.trace("%s secure inbound",n.role);let f=await a.secureInbound(c,{remotePeer:n.remotePeer,signal:n.signal,skipStreamMuxerNegotiation:!0});return n.log.trace("%s upgrade outbound",n.role),await n.upgrader.upgradeOutbound(l,{skipProtection:!0,skipEncryption:!0,remotePeer:f.remotePeer,muxerFactory:e,signal:n.signal})}n.log.trace("%s secure outbound",n.role);let u=await a.secureOutbound(c,{remotePeer:n.remotePeer,signal:n.signal,skipStreamMuxerNegotiation:!0});l.remoteAddr=l.remoteAddr.encapsulate(`/p2p/${u.remotePeer}`),n.log.trace("%s upgrade inbound",n.role),await n.upgrader.upgradeInbound(l,{skipProtection:!0,skipEncryption:!0,remotePeer:u.remotePeer,muxerFactory:e,signal:n.signal})}catch(i){throw o.close(),r.close(),i}}async function XB(r,e,t={}){let n=t.certificate;n==null&&(n=await RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"}));let o=typeof t.rtcConfiguration=="function"?await t.rtcConfiguration():t.rtcConfiguration,i=new RTCPeerConnection({...o??{},certificates:[n]}),s=new rc({peerConnection:i,metrics:t.events,dataChannelOptions:t.dataChannel});return{peerConnection:i,muxerFactory:s}}async function YB(r){let e=await bg(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...H(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
|
|
110
|
-
`)}var W5=class{log;metrics;components;init;certificate;privateKey;emitter;renewCertificateTask;constructor(e,t={}){if(this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,this.emitter=new _e,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new D("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[ya]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[qe]=["@libp2p/transport"];async start(){this.certificate=await this.getCertificate()}async stop(){this.renewCertificateTask!=null&&clearTimeout(this.renewCertificateTask),this.certificate=void 0}async dial(e,t){this.log("dial %a",e),t.signal.throwIfAborted();let n,o=e.getComponents().findLast(c=>c.code===421)?.value;o!=null&&(n=je(o));let i=sN(),{peerConnection:s,muxerFactory:a}=await XB("client",i,{rtcConfiguration:typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{},dataChannel:this.init.dataChannel});try{return await GB(s,a,i,{role:"client",log:this.log,logger:this.components.logger,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeer:n,privateKey:this.components.privateKey})}catch(c){throw s.close(),c}}createListener(e){if(this.certificate==null)throw new qn;return new j5(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(jp.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(RQ(this.init.certificate))return this.log("using provided TLS certificate"),this.init.certificate;let t=await this.loadOrCreatePrivateKey(),{pem:n,certhash:o}=await this.loadOrCreateCertificate(t,e);return{privateKey:await YB(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??ZD,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Ye;this.log.trace("checking for stored private key"),this.privateKey=await t.exportKey(e)}catch(n){if(n.name!=="NotFoundError")throw n;this.log.trace("generating private key"),this.privateKey=await yf("ECDSA","P-256"),t!=null?(this.log.trace("storing private key"),await t.importKey(e,this.privateKey)):this.log("no keychain configured - not storing private key")}return this.privateKey}async loadOrCreateCertificate(e,t){if(this.certificate!=null&&t!==!0)return this.certificate;let n,o=new nt(this.init.certificateDatastoreKey??QD),i=await bg(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Ye;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??av)-Date.now();return s<0&&(s=100),this.log("will renew TLS certificate after %d ms",s),this.renewCertificateTask=setTimeout(()=>{this.log("renewing TLS certificate"),this.getCertificate(!0).then(a=>{this.certificate=a,this.emitter.safeDispatchEvent("certificate:renew",{detail:a})}).catch(a=>{this.log.error("could not renew certificate - %e",a)})},s),{pem:n.toString("pem"),certhash:Fc.encode((await At.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ch(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??av);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Ye;this.log("loaded certificate, expires in %d ms",i);let s=await o.publicKey.export(crypto),a=await crypto.subtle.exportKey("raw",s),c=await crypto.subtle.exportKey("raw",t.publicKey);if(!me(new Uint8Array(a,0,a.byteLength),new Uint8Array(c,0,c.byteLength)))throw this.log("stored TLS certificate public key did not match public key from private key"),new Ye;return this.log("loaded certificate, expiry time is %o",i),o}async createCertificate(e,t){let n=new Date,o=new Date(Date.now()+(this.init.certificateLifespan??JD));n.setMilliseconds(0),o.setMilliseconds(0);let i=await z5.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new ih(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,O(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function RQ(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function G5(r){return e=>new W5(e,r)}function QB(r){return e=>new H6(e,r)}function ZB(){throw new Error("WebSocket Servers can not be created in the browser!")}var OQ=1024*1024*4,DQ=10,oS=class extends Ra{websocket;maxBufferedAmount;checkBufferedAmountTask;constructor(e){super(e),this.websocket=e.websocket,this.maxBufferedAmount=e.maxBufferedAmount??OQ,this.checkBufferedAmountTask=Bf(this.checkBufferedAmount.bind(this),e.bufferedAmountPollInterval??DQ),this.websocket.addEventListener("close",t=>{if(this.log('closed - code %d, reason "%s", wasClean %s',t.code,t.reason,t.wasClean),this.checkBufferedAmountTask.stop(),!t.wasClean){this.onRemoteReset();return}this.onTransportClosed()},{once:!0}),this.websocket.addEventListener("message",t=>{try{let n;if(typeof t.data=="string")n=O(t.data);else if(t.data instanceof ArrayBuffer)n=new Uint8Array(t.data,0,t.data.byteLength);else{this.abort(new Error("Incorrect binary type"));return}this.onData(n)}catch(n){this.log.error("error receiving data - %e",n)}})}sendData(e){for(let n of e)this.websocket.send(n);let t=this.websocket.bufferedAmount<this.maxBufferedAmount;return t||this.checkBufferedAmountTask.start(),{sentBytes:e.byteLength,canSendMore:t}}sendReset(){this.websocket.close(1006)}async sendClose(e){this.websocket.close(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}checkBufferedAmount(){this.log("buffered amount now %d",this.websocket.bufferedAmount),this.websocket.bufferedAmount===0&&(this.checkBufferedAmountTask.stop(),this.safeDispatchEvent("drain"))}};function JB(r){return new oS(r)}var iS=class{log;init;logger;metrics;components;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:websockets"),this.logger=e.logger,this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_websockets_dialer_events_total",{label:"event",help:"Total count of WebSockets dialer events by type"})})}[ya]=!0;[Symbol.toStringTag]="@libp2p/websockets";[qe]=["@libp2p/transport"];async dial(e,t){this.log("dialing %s",e),t=t??{};let n=JB({websocket:await this._connect(e,t),remoteAddr:e,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:websockets:connection"),maxBufferedAmount:this.init.maxBufferedAmount,bufferedAmountPollInterval:this.init.bufferedAmountPollInterval});this.log("new outbound connection %s",n.remoteAddr);let o=await t.upgrader.upgradeOutbound(n,t);return this.log("outbound connection %s upgraded",n.remoteAddr),o}async _connect(e,t){t?.signal?.throwIfAborted();let n=Ha(e);this.log("create websocket connection to %s",n);let o=new WebSocket(n);o.binaryType="arraybuffer";try{t.onProgress?.(new Y("websockets:open-connection")),await Ze(o,"open",t)}catch(i){if(t.signal?.aborted)throw this.metrics?.dialerEvents.increment({abort:!0}),new Vu(`Could not connect to ${n}`);this.metrics?.dialerEvents.increment({error:!0});try{o.close()}catch{}throw i}return this.log("connected %s",e),this.metrics?.dialerEvents.increment({connect:!0}),o}createListener(e){return ZB({logger:this.logger,events:this.components.events,metrics:this.components.metrics},{...this.init,...e})}listenFilter(e){return e.filter(t=>Hs.exactMatch(t)||Sl.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function X5(r={}){return e=>new iS(e,r)}var sS=gt(Ty(),1);function Y5(r,e){let t=e.map((n,o)=>({record:io(n),index:o}));return t.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===_n.ValidityType.EOL&&o.record.validityType===_n.ValidityType.EOL){let a=sS.default.fromString(n.record.validity).toDate(),c=sS.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var eM="6.0.14",tM="helia";var rM={list:["/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN","/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb","/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt","/dnsaddr/va1.bootstrap.libp2p.io/p2p/12D3KooWKnDdG3iXw9eTFijk3EWSunZcFi54Zka4wmtqtt6rPxc8","/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"]};function b0(r={}){let e=`${tM}/${eM} ${I3()}`;return{privateKey:r.privateKey,dns:r.dns,nodeInfo:{userAgent:e},addresses:{listen:["/p2p-circuit","/webrtc"]},transports:[cO(),QB(),G5(),X5()],connectionEncrypters:[i4()],streamMuxers:[jR(),$D()],peerDiscovery:[QR(rM)],services:{autoNAT:YR(),dcutr:fO(),delegatedRouting:()=>_k("https://delegated-ipfs.dev",g9()),dht:LD({clientMode:!0,validators:{ipns:Tl},selectors:{ipns:Y5}}),identify:rD(),identifyPush:nD(),keychain:Z3(r.keychain),ping:zD(),http:YO()}}}async function nM(r){let e=r.libp2p??{};e.privateKey==null&&r.datastore!=null&&(e.privateKey=await rb(r.datastore,r.keychain));let t=b0(e);return t.datastore=t.datastore??r.datastore,await k3({...t,...e,start:!1})}async function oM(r={}){let e=r.datastore??new Cl,t=r.blockstore??new em,n;return yP(r.libp2p)?n=r.libp2p:n=await nM({...r,libp2p:{dns:r.dns,...r.libp2p,start:void 0},datastore:e}),{...r,libp2p:n,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[Gp(),qp()],routers:r.routers??[Jp(n),Zp()],metrics:n.metrics}}async function iM(r={}){let e=await oM(r),t=new fy(e);return e.start!==!1&&await t.start(),t}function sM(){let r=b0();r.start=!1,r.addresses={listen:[]},r.transports=[G5(),X5()],r.peerDiscovery=[];let e={dcutr:r.services.dcutr,identify:r.services.identify,keychain:r.services.keychain,ping:r.services.ping};return{...r,start:!1,services:e}}var lh=class extends Map{#t=0;#e=new Map;#r=new Map;#o;#s;#a;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=e.maxSize,this.#s=e.maxAge||Number.POSITIVE_INFINITY,this.#a=e.onEviction}get __oldCache(){return this.#r}#l(e){if(typeof this.#a=="function")for(let[t,n]of e)this.#a(t,n.value)}#n(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#a=="function"&&this.#a(e,t.value),this.delete(e)):!1}#m(e,t){if(this.#n(e,t)===!1)return t.value}#h(e,t){return t.expiry?this.#m(e,t):t.value}#p(e,t){let n=t.get(e);return this.#h(e,n)}#u(e,t){this.#e.set(e,t),this.#t++,this.#t>=this.#o&&(this.#t=0,this.#l(this.#r),this.#r=this.#e,this.#e=new Map)}#f(e,t){this.#r.delete(e),this.#u(e,t)}*#i(){for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield e)}for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#h(e,t)}if(this.#r.has(e)){let t=this.#r.get(e);if(this.#n(e,t)===!1)return this.#f(e,t),t.value}}set(e,t,{maxAge:n=this.#s}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#u(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#n(e,this.#e.get(e)):this.#r.has(e)?!this.#n(e,this.#r.get(e)):!1}peek(e){if(this.#e.has(e))return this.#p(e,this.#e);if(this.#r.has(e))return this.#p(e,this.#r)}expiresIn(e){let t=this.#e.get(e)??this.#r.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){let t=this.#e.delete(e);return t&&this.#t--,this.#r.delete(e)||t}clear(){this.#e.clear(),this.#r.clear(),this.#t=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#i()],n=t.length-e;n<0?(this.#e=new Map(t),this.#r=new Map,this.#t=t.length):(n>0&&this.#l(t.slice(0,n)),this.#r=new Map(t.slice(n)),this.#e=new Map,this.#t=0),this.#o=e}evict(e=1){let t=Number(e);if(!t||t<=0)return;let n=[...this.#i()],o=Math.trunc(Math.min(t,Math.max(n.length-1,0)));o<=0||(this.#l(n.slice(0,o)),this.#r=new Map(n.slice(o)),this.#e=new Map,this.#t=0)}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield[t,n.value])}for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield[t,n.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#n(o,i)===!1&&(yield[o,i.value])}e=[...this.#r];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#e.has(o)||this.#n(o,i)===!1&&(yield[o,i.value])}}*entriesAscending(){for(let[e,t]of this.#i())yield[e,t.value]}get size(){if(!this.#t)return this.#r.size;let e=0;for(let t of this.#r.keys())this.#e.has(t)||e++;return Math.min(this.#t+e,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#s}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[n,o]of this.entriesAscending())e.call(t,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var Q5=class extends Error{static name="DNSLinkNotFoundError";constructor(e="DNSLink not found"){super(e),this.name="DNSLinkNotFoundError"}},uh=class extends Error{static name="InvalidNamespaceError";constructor(e="Invalid namespace"){super(e),this.name="InvalidNamespaceError"}};var aM=(r,e)=>{let[,t,n,...o]=r.split("/");if(t!=="ipfs")throw new uh(`Namespace ${t} was not "ipfs"`);return{namespace:"ipfs",cid:Z.parse(n),path:o.length>0?`/${o.join("/")}`:"",answer:e}};var cM=(r,e)=>{let[,t,n,...o]=r.split("/");if(t!=="ipns")throw new uh(`Namespace ${t} was not "ipns"`);try{return{namespace:"ipns",peerId:je(n),path:o.length>0?`/${o.join("/")}`:"",answer:e}}catch{return{namespace:"dnslink",value:n,path:o.length>0?`/${o.join("/")}`:"",answer:e}}};var Z5=class{dns;log;namespaces;cache;cacheMaxAnswers;constructor(e,t={}){this.dns=e.dns,this.log=e.logger.forComponent("helia:dnslink"),this.namespaces={ipfs:aM,ipns:cM,...t.namespaces},this.cache=new lh({maxSize:t.cacheSize??1e3,maxAge:t.cacheMaxAge??3e4}),this.cacheMaxAnswers=t.cacheMaxAnswers??10}async resolve(e,t={}){if(t.nocache!==!0){let s=this.cache.get(e);if(s!=null){let a=[...s.values()];if(a.length>0)return a}}let n=await this.recursiveResolveDomain(e,t.maxRecursiveDepth??xI,t),o=new lh({maxSize:this.cacheMaxAnswers});n.forEach((s,a)=>{o.set(a,s,{maxAge:s.answer.TTL*1e3})});let i=n.reduce((s,a)=>{let c=a.answer.TTL*1e3;return c>s?c:s},0);return this.cache.maxAge<i&&(i=this.cache.maxAge),this.cache.set(e,o,{maxAge:i}),n}async recursiveResolveDomain(e,t,n={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await this.recursiveResolveDnslink(e,t,n)}catch(o){if(o.code!=="ENOTFOUND"&&o.code!=="ENODATA"&&o.name!=="DNSLinkNotFoundError"&&o.name!=="NotFoundError")throw o;return e.startsWith("_dnslink.")?e=e.replace("_dnslink.",""):e=`_dnslink.${e}`,this.recursiveResolveDnslink(e,t,n)}}async recursiveResolveDnslink(e,t,n={}){if(t===0)throw new Error("recursion limit exceeded");this.log("query %s for TXT and CNAME records",e);let i=((await this.dns.query(e,{...n,types:[Zr.TXT]}))?.Answer??[]).sort((l,u)=>l.data.localeCompare(u.data));this.log("found %d TXT records for %s",i.length,e);let s=[];for(let l of i)try{let u=l.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;this.log("%s TXT %s",l.name,u),u=u.replace("dnslink=","");let[,f,h]=u.split("/");if(f==="dnslink"){s.push(...await this.recursiveResolveDomain(h,t-1,n));continue}let d=this.namespaces[f];if(d==null){this.log('unknown protocol "%s" in DNSLink record for domain: %s',f,e);continue}let m=d(u,l);if(m.namespace==="dnslink"){s.push(...await this.recursiveResolveDomain(m.value,t-1,n));continue}s.push(d(u,l))}catch(u){this.log.error("could not parse DNS link record for domain %s, %s - %e",e,l.data,u)}if(s.length>0)return s;this.log("no DNSLink records found for %s, falling back to CNAME",e);let c=((await this.dns.query(e,{...n,types:[Zr.CNAME]}))?.Answer??[]).sort((l,u)=>l.data.localeCompare(u.data));this.log("found %d CNAME records for %s",c.length,e);for(let l of c)try{return await this.recursiveResolveDomain(l.data,t-1,n)}catch(u){this.log.error("domain %s cname %s had no DNSLink records - %e",e,l.data,u)}throw new Q5(`No DNSLink records found for domain: ${e}`)}};function lM(r,e={}){return new Z5(r,e)}var uM=BigInt(6e4)*5000000n;var J5=class extends Error{static name="RecordsFailedValidationError";constructor(e="Records failed validation"){super(e),this.name="RecordsFailedValidationError"}},e8=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(e="Unsupported multibase prefix"){super(e),this.name="UnsupportedMultibasePrefixError"}},t8=class extends Error{static name="UnsupportedMultihashCodecError";constructor(e="Unsupported multihash codec"){super(e),this.name="UnsupportedMultihashCodecError"}},r8=class extends Error{static name="InvalidValueError";constructor(e="Invalid value"){super(e),this.name="InvalidValueError"}};var v0=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"};var NQ=114,aS=0,cS=18;function lS(r,e){return r.code===e}var n8="/dht/record/",LQ="/ipns/metadata/";function E0(r){return new nt(n8+H(r,"base32"),!1)}function o8(r){return new nt(LQ+H(r,"base32"),!1)}function BQ(r){return r?.asCID===r}function fM(r){if(!BQ(r))return!1;if(r.code!==NQ)throw new D(`CID codec ${r.code} was not libp2p-key`);if(r.multihash.code!==aS&&r.multihash.code!==cS)throw new D(`Multihash algorithm codec ${r.multihash.code} was not Identity or SHA256 hash`);return!0}var dM={[an.prefix]:an,[Qe.prefix]:Qe},i8=class{routers;localStore;log;constructor(e,t){this.log=e.logger.forComponent("helia:ipns"),this.localStore=t.localStore,this.routers=t.routers}async resolve(e,t={}){let n=Y0(e)||mr(e)?e.toMultihash():fM(e)?e.multihash:e,o=_l(n),i=await this.#e(o,t);return{...await this.#t(i.value,t),record:i}}async#t(e,t={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=Qe.decode(`z${i}`);else if(dM[s]!=null)a=dM[s].decode(i);else throw new e8(`Unsupported multibase prefix "${s}"`);let c;try{c=ze(a)}catch{c=Z.decode(a).multihash}if(!lS(c,aS)&&!lS(c,cS))throw new t8(`Unsupported multihash codec "${c.code}"`);let{cid:l}=await this.resolve(c,t),u=n.slice(3).join("/");return{cid:l,path:u===""?void 0:u}}else if(o==="ipfs"){let i=Z.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s===""?void 0:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",e),new r8("Invalid value")}async#e(e,t={}){let n=[];if(await this.localStore.has(e,t))if(this.log("record is present in the cache"),t.nocache!==!0)try{let{record:c,created:l}=await this.localStore.get(e,t);this.log("record retrieved from cache"),await Tl(e,c),this.log("record was valid");let u=io(c),f=Number((u.ttl??uM)/1000000n);if(l.getTime()+f>Date.now())return this.log("record TTL was valid"),u;if(t.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),u;this.log("record TTL has been reached, searching routing for updates"),n.push(c)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,t)}else this.log("ignoring local cache due to nocache=true option");if(t.offline===!0)throw new v0("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async c=>{let l;try{l=await c.get(e,{...t,validate:!1})}catch(u){this.log.error("error finding IPNS record using router %s - %e",c.toString(),u),s.push(u);return}try{await Tl(e,l),n.push(l)}catch(u){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),u)}})),n.length===0)throw i>0?new J5(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new v0("Could not find record for routing key");let a=n[Y5(e,n)];return await this.localStore.put(e,a,t),io(a)}};var S0;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.keyName!=null&&t.keyName!==""&&(n.uint32(10),n.string(t.keyName)),t.lifetime!=null&&t.lifetime!==0&&(n.uint32(16),n.uint32(t.lifetime)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={keyName:"",lifetime:0},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.keyName=t.string();break}case 2:{i.lifetime=t.uint32();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>be(t,r.codec()),r.decode=(t,n)=>xe(t,r.codec(),n)})(S0||(S0={}));function hM(r,e){return{async put(t,n,o={}){try{let i=E0(t);try{let c=await r.get(i),l=Ut.deserialize(c);if(me(l.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Ut(t,n,new Date);o.onProgress?.(new Y("ipns:routing:datastore:put"));let a=r.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(o8(t),S0.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new Y("ipns:routing:datastore:error",i)),i}},async get(t,n={}){try{let o=E0(t);n.onProgress?.(new Y("ipns:routing:datastore:get"));let i=await r.get(o,n),s=Ut.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new Y("ipns:routing:datastore:error",o)),o}},async has(t,n={}){let o=E0(t);return r.has(o,n)},async delete(t,n){let o=E0(t),i=r.batch();i.delete(o),i.delete(o8(t)),await i.commit(n)},async*list(t={}){try{t.onProgress?.(new Y("ipns:routing:datastore:list"));for await(let{key:n,value:o}of r.query({prefix:n8},t))try{let i=Ut.deserialize(o),a=n.toString().substring(n8.length),c=O(a,"base32"),l=o8(c),u;try{let f=await r.get(l,t);u=S0.decode(f)}catch(f){e.error("Error deserializing metadata for %s - %e",a,f)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw t.onProgress?.(new Y("ipns:routing:datastore:error",n)),n}}}}var uS=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(o){throw n.onProgress?.(new Y("ipns:routing:helia:error",o)),o}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){throw t.onProgress?.(new Y("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function fS(r){return new uS(r)}var dS=class{localStore;constructor(e){this.localStore=e}async put(e,t,n){await this.localStore.put(e,t,n)}async get(e,t){let{record:n}=await this.localStore.get(e,t);return n}toString(){return"LocalStoreRouting()"}};function pM(r){return new dS(r)}function mM(r,e={}){let t=hM(r.datastore,r.logger.forComponent("helia:ipns:local-store")),n=[pM(t),fS(r.routing),...e.routers??[]];return new i8(r,{routers:n,localStore:t})}var mS=gt(s8(),1);var gS=40;function yS(r,e){if(!r.length)throw new Error("Unexpected end of data");let t=mS.default.decode(r);return e.seek(mS.default.decode.bytes),t}function wS(r){let e=new DataView(r.buffer,r.byteOffset,r.byteLength),t=0;return{version:2,characteristics:[e.getBigUint64(t,!0),e.getBigUint64(t+=8,!0)],dataOffset:Number(e.getBigUint64(t+=8,!0)),dataSize:Number(e.getBigUint64(t+=8,!0)),indexOffset:Number(e.getBigUint64(t+=8,!0))}}var Cc={Null:r=>r===null?r:void 0,Int:r=>Number.isInteger(r)?r:void 0,Float:r=>typeof r=="number"&&Number.isFinite(r)?r:void 0,String:r=>typeof r=="string"?r:void 0,Bool:r=>typeof r=="boolean"?r:void 0,Bytes:r=>r instanceof Uint8Array?r:void 0,Link:r=>r!==null&&typeof r=="object"&&r.asCID===r?r:void 0,List:r=>Array.isArray(r)?r:void 0,Map:r=>r!==null&&typeof r=="object"&&r.asCID!==r&&!Array.isArray(r)&&!(r instanceof Uint8Array)?r:void 0},A0={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Cc.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Cc.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=A0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=A0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:Cc.Int,CarV1HeaderOrV2Pragma:r=>{if(Cc.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=A0["CarV1HeaderOrV2Pragma > roots (anon)"](r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=A0.Int(r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},_0={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Cc.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Cc.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=_0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=_0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:Cc.Int,CarV1HeaderOrV2Pragma:r=>{if(Cc.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=_0["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=_0.Int(s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},xS={toTyped:A0.CarV1HeaderOrV2Pragma,toRepresentation:_0.CarV1HeaderOrV2Pragma};var $Ye=lx();var JQ=gt(s8(),1);var zYe=[new j(A.map,2),new j(A.string,"version"),new j(A.uint,1),new j(A.string,"roots")],jYe=new j(A.tag,42);async function bS(r,e){let t=yS(await r.upTo(8),r);if(t===0)throw new Error("Invalid CAR header (zero length)");let n=await r.exactly(t,!0),o=no(n);if(xS.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=wS(await r.exactly(gS,!0));r.seek(i.dataOffset-r.pos);let s=await bS(r,1);return Object.assign(s,i)}function T0(r){let e=0;return{async upTo(t){return r.subarray(e,e+Math.min(t,r.length-e))},async exactly(t,n=!1){if(t>r.length-e)throw new Error("Unexpected end of data");let o=r.subarray(e,e+t);return n&&(e+=t),o},seek(t){e+=t},get pos(){return e}}}var vS=gt(s8(),1),CM=1;function ES(r){let e=gn({version:CM,roots:r}),t=vS.default.encode(e.length),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function IM(r){return{async setRoots(e){let t=ES(e);await r.write(t)},async writeBlock(e){let{cid:t,bytes:n}=e;await r.write(new Uint8Array(vS.default.encode(t.bytes.length+n.length))),await r.write(t.bytes),n.length&&await r.write(n)},async close(){await r.end()},version(){return CM}}}function a8(){}function kM(){let r=[],e=null,t=a8,n=!1,o=null,i=a8,s=()=>(e||(e=new Promise(l=>{t=()=>{e=null,t=a8,l()}})),e),a={write(l){r.push(l);let u=s();return i(),u},async end(){n=!0;let l=s();i(),await l}},c={async next(){let l=r.shift();return l?(r.length===0&&t(),{done:!1,value:l}):n?(t(),{done:!0,value:void 0}):(o||(o=new Promise(u=>{i=()=>(o=null,i=a8,u(c.next()))})),o)}};return{writer:a,iterator:c}}var C0=class r{constructor(e,t){this._encoder=t,this._mutex=t.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let t=Z.asCID(e.cid);if(!t)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:t,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=nZ(e);let{encoder:t,iterator:n}=PM(),o=new r(e,t),i=new c8(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:t}=PM();e.setRoots=()=>Promise.resolve();let n=new r([],e),o=new c8(t);return{writer:n,out:o}}static async updateRootsInBytes(e,t){let n=T0(e);await bS(n);let o=ES(t);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},c8=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function PM(){let r=kM(),{writer:e,iterator:t}=r;return{encoder:IM(e),iterator:t}}function nZ(r){if(r===void 0)return[];if(!Array.isArray(r)){let t=Z.asCID(r);if(!t)throw new TypeError("roots must be a single CID or an array of CIDs");return[t]}let e=[];for(let t of r){let n=Z.asCID(t);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var fh=class{walker;constructor(e){this.walker=e?.walker}async*export(e,t,n,o){let i,s={blockstore:t,getCodec:n};this.walker!=null?i=this.walker(s):i=ly()(s);for await(let a of i.walk(e,o))yield a.block}};var l8=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,t){await Xr(this.components.blockstore.putMany(er(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),t))}async*export(e,t){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=C0.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,t).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:l}=await rt(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(l!=null&&(yield l),c===!0)break}}async _export(e,t,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new dh:new fh),a=i,c=!1;if(o!=null){for await(let{cid:l,bytes:u}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,l),a=l,i.equals(l)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(l.multihash.bytes)===!0)continue;n?.blockFilter?.add(l.multihash.bytes),await t.put({cid:l,bytes:u})}}for await(let{cid:l,bytes:u}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(l.multihash.bytes)!==!0&&l.multihash.code!==0&&(c&&l.equals(a)||(n?.blockFilter?.add(l.multihash.bytes),await t.put({cid:l,bytes:u})))}await t.close()}};var I0=class{async*export(e,t,n,o){let i=await De(t.get(e,o));yield $a({cid:e,bytes:i,codec:await n(e.code)})}};var k0=class r extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=r.name;code=r.code;constructor(e="Invalid type"){super(e)}},u8=class r extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=r.name;code=r.code;constructor(e="Invalid message"){super(e)}};var _i;(function(r){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(t||(t={})),(function(o){o.codec=()=>wt(t)})(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=ve((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),r.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),f8.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=f8.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>be(o,r.codec()),r.decode=o=>xe(o,r.codec())})(_i||(_i={}));var f8;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Seconds=t.int64();break;case 2:o.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>be(t,r.codec()),r.decode=t=>xe(t,r.codec())})(f8||(f8={}));var OM;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.MimeType=t.string();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>be(t,r.codec()),r.decode=t=>xe(t,r.codec())})(OM||(OM={}));var DM={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},iZ=["directory","hamt-sharded-directory"],NM=parseInt("0644",8),LM=parseInt("0755",8),BM=BigInt(1024),nn=class r{static unmarshal(e){let t=_i.decode(e);if(t.fanout!=null&&t.fanout>BM)throw new u8(`Fanout size was too large - ${t.fanout} > ${BM}`);let n=new r({type:DM[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(DM).includes(t))throw new k0("Type: "+t+" is not valid");this.type=t??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?LM:NM:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return iZ.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(t=>{e+=t}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=_i.DataType.Raw;break;case"directory":e=_i.DataType.Directory;break;case"file":e=_i.DataType.File;break;case"metadata":e=_i.DataType.Metadata;break;case"symlink":e=_i.DataType.Symlink;break;case"hamt-sharded-directory":e=_i.DataType.HAMTShard;break;default:throw new k0(`Type: ${e} is not valid`)}let t=this.data;(this.data==null||this.data.length===0)&&(t=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===NM&&!this.isDirectory()&&(n=void 0),n===LM&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),_i.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var P0=class extends Error{static code="ERR_NOT_UNIXFS";static message="Not a UnixFS node";static name="NotUnixFSError";code="ERR_NOT_UNIXFS";message="Not a UnixFS node";name="NotUnixFSError"},d8=class extends Error{static name="NotDescendantError";name="NotDescendantError"},h8=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function aZ(r){return r.cid.code===85}function cZ(r){return r.cid.code===112}function lZ(r){if(aZ(r))return!0;if(cZ(r)&&r.value.Data!=null){let e=nn.unmarshal(r.value.Data);return e.type==="file"||e.type==="raw"}else throw new P0("Encountered non raw/dag-pb CID in UnixFS DAG")}var dh=class{options;constructor(e){this.options=e}async*export(e,t,n,o){if(e.code!==112&&e.code!==85)throw new P0("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=zf()({blockstore:t,getCodec:n}),s=this.options?.offset??0,a=this.options?.length??1/0,c=this.options?.listingOnly??!1;if(s<0)throw new D("Offset cannot be negative");if(a<0)throw new D("Length cannot be negative");let l,u=new AbortController,f=Re([u.signal,o?.signal]);u.signal;function h(d,m){if(l==null&&(l=lZ(m)),!l){let U=m.value.Links.find(M=>M.Hash.equals(d)),K=nn.unmarshal(m.value.Data??new Uint8Array);return K.type==="directory"?!c:K.type==="hamt-sharded-directory"&&c?U?.Name?.length===2:!0}let y=m.value.Links.findIndex(U=>U.Hash.equals(d)),w=nn.unmarshal(m.value.Data??new Uint8Array),x=s,v=x+a,E=Number([...w.blockSizes].slice(0,y).reduce((U,K)=>U+K,0n)),I=E+Number(w.blockSizes[y]);return x>=E&&x<I||v>=E&&v<I||x<=E&&v>=I}try{for await(let d of i.walk(e,{...o,includeChild:h,signal:f}))yield d.block}finally{u.abort(),f.clear()}}};var p8=class{path;constructor(e){this.path=e}async*traverse(e,t,n,o){if(!this.path.some(s=>s.equals(e)))throw new h8(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let l=!1;for(let[,u]of i.links())if(u.equals(s)){l=!0;break}if(!l)throw new d8(`${s} is not a child of ${i.cid}`)}let a=await De(t.get(s,o)),c=$a({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};function uZ(r){return r[Symbol.asyncIterator]!=null}function fZ(r){if(uZ(r))return(async()=>{let t;for await(let n of r)t=n;return t})();let e;for(let t of r)e=t;return e}var hh=fZ;var g8=gt(FM(),1);function dZ(r){let e=new Array(4);for(let t=0;t<4;t++)e[t]=r&255,r=r>>8;return new Uint8Array(e)}var aZe=gs({name:"murmur3-32",code:35,encode:r=>dZ(g8.default.x86.hash32(r))}),$M=gs({name:"murmur3-128",code:34,encode:r=>Mc.fromHex(g8.default.x64.hash128(r))}),cZe=gs({name:"murmur3-x64-64",code:34,encode:r=>Mc.fromHex(g8.default.x64.hash128(r)).subarray(0,8)});var qM=gt(VM(),1);var Pu=class r{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,t,n=0){this._options=e,this._popCount=0,this._parent=t,this._posAtParent=n,this._children=new qM.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof r?o.push(i.serialize(e,t)):o.push(e(i,s))),o),n))}async asyncTransform(e,t){return zM(this,e,t)}toJSON(){return this.serialize(yZ,wZ)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);if(!(n instanceof r)&&n!=null&&n.key===e)return n}async _findPlace(e){let t=this._options.hash(typeof e=="string"?O(e):e),n=await t.take(this._options.bits),o=this._children.get(n);return o instanceof r?o._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:o}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let o=await n._findPlace(t.existingChild.hash);return o.bucket._putAt(o,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(gZ);if(e!=null&&!(e instanceof r)){let t=e.hash;t.untake(this._options.bits);let n={pos:this._posAtParent,hash:t,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function gZ(r){return!!r}function yZ(r,e){return r.key}function wZ(r){return r}async function zM(r,e,t){let n=[];for(let o of r._children.compactArray())if(o instanceof Pu)await zM(o,e,t);else{let i=await e(o);n.push({bitField:r._children.bitField(),children:i})}return t(n)}var xZ=[255,254,252,248,240,224,192,128],bZ=[1,3,7,15,31,63,127,255],y8=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,t),a=vZ(o,i-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function vZ(r,e,t){let n=EZ(e,t);return(r&n)>>>e}function EZ(r,e){return xZ[r]&bZ[Math.min(e+r-1,7)]}function jM(r){function e(t){return t instanceof w8?t:new w8(t,r)}return e}var w8=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),t),s=o.take(i);n=(n<<i)+s,t-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),t);n.untake(o),t-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?dt([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new y8(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function WM(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:jM(r.hashFn)};return new Pu(e)}function GM(r){return new l8(r)}var ph=class r extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=r.name;code=r.code;constructor(e="Bad path"){super(e)}},yo=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not found"){super(e)}},mh=class r extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=r.name;code=r.code;constructor(e="No resolver"){super(e)}},Nt=class r extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=r.name;code=r.code;constructor(e="Not UnixFS"){super(e)}},x8=class r extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=r.name;code=r.code;constructor(e="Over read"){super(e)}},b8=class r extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=r.name;code=r.code;constructor(e="Under read"){super(e)}},Ti=class r extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=r.name;code=r.code;constructor(e="Invalid parameters"){super(e)}};function gh(r){return r==null?!1:Z.asCID(r)===r}function yh(r,e){let t,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(r,i))throw new ph(`Object did not have key "${i}"`);if(o+=`/${i}`,t=r[i],r=t,gh(t))break}return{value:t,rest:e.slice(n),path:o.substring(1)}}async function*SS(r,e,t,n){let o=await De(t.get(r,n)),i=no(o),s=yh(i,e);yield{cid:gh(s.value)?s.value:r,name:s.path,rest:s.rest}}async function*XM(r,e,t,n){let o=await De(t.get(r,n)),i=Ms(o),s=yh(i,e);yield{cid:gh(s.value)?s.value:r,name:s.path,rest:s.rest}}var SZ=async function(r){return(await $M.encode(r)).slice(0,8).reverse()},AZ=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new Pu({hash:t._options.hash,bits:t._options.bits},e,i));return}await t.put(o.Name.substring(2),!0)}))},YM=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),_Z=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()};async function*AS(r,e,t,n,o,i){if(o==null){if(r.Data==null)throw new Nt("No data in PBNode");let h;try{h=nn.unmarshal(r.Data)}catch(m){throw new Nt(m.message)}if(h.type!=="hamt-sharded-directory")throw new Nt("Not a HAMT");if(h.fanout==null)throw new Nt("Missing fanout");let d=WM({hashFn:SZ,bits:Math.log2(Number(h.fanout))});o={rootBucket:d,hamtDepth:1,lastBucket:d}}let s=(o.lastBucket.tableSize()-1).toString(16).length;await AZ(r.Links,o.lastBucket,o.rootBucket);let a=await o.rootBucket._findNewBucketAndPos(e),c=YM(a.pos,s),l=_Z(a);l.length>o.hamtDepth&&(o.lastBucket=l[o.hamtDepth],c=YM(o.lastBucket._posAtParent,s));let u=r.Links.find(h=>{if(h.Name==null)return!1;let d=h.Name.substring(0,s),m=h.Name.substring(s);return!(d!==c||m!==""&&m!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(s)===e){yield{cid:u.Hash,name:u.Name.substring(s),rest:t};return}o.hamtDepth++;let f=await De(n.get(u.Hash,i));r=Jr(f),i?.yieldSubShards===!0&&(yield{cid:u.Hash,name:u.Name??"",rest:[e,...t]}),yield*AS(r,e,t,n,o,i)}async function*QM(r,e,t,n){let o=await De(t.get(r,n)),i;try{i=Jr(o)}catch(a){throw new Nt(a.message)}if(i.Data==null)throw new Nt("no data in PBNode");let s;try{s=nn.unmarshal(i.Data)}catch(a){throw new Nt(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHamtPath===!1){let a=i.Links.find(c=>c.Name===e[0]);if(a==null)throw new yo(`No link "${e[0]}" found under ${r}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let c of AS(i,e[0],e.slice(1),t,void 0,n))c.name===e[0]&&(a=!0),yield c;if(!a)throw new yo(`No link "${e[0]}" found under ${r}`)}}async function*ZM(r,e,t,n){if(e.length!==0)throw new ph(`Cannot load path /${e.join("/")} from identity block`)}async function*JM(r,e,t,n){let o=await De(t.get(r,n)),i=xa(o),s=yh(i,e);yield{cid:r,name:s.path,rest:s.rest}}async function*eU(r,e,t,n){if(e.length!==0)throw new yo(`Cannot load path /${e.join("/")} from raw block`)}var CZ={[pt]:QM,[ct]:eU,[fr]:SS,81:SS,[dr]:XM,[Ot.code]:ZM,[lr]:JM};async function*Ic(r,e,t={}){for(r=r.toString(),r.startsWith("/ipfs/")&&(r=r.substring(6));r.endsWith("/");)r=r.substring(0,r.length-1);let[n,...o]=r.split(/(?<!\\)\//g).filter(Boolean),i=Z.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let c=CZ[i.code];if(c==null)throw new mh(`No resolver for code ${i.code}`);let l=!1;for await(let u of c(i,o,e,t)){if(i=u.cid,l=!s[s.length-1].equals(i),o=u.rest,!l)break;s=[...s,u.cid],a=`${a}/${u.name}`,yield{cid:u.cid,name:u.name,path:a,roots:s,remainder:u.rest}}if(!l)break}if(t?.signal?.throwIfAborted(),o.length!==0)throw new yo(`Could not resolve path /${o.join("/")} under ${r}`)}async function _S(r,e,t,n,o){let i=await De(n.get(r,o)),s=no(i);return{type:"object",cid:r,name:e,path:t,object:s,node:i}}async function tU(r,e,t,n,o){let i=await De(n.get(r,o)),s=Ms(i);return{type:"object",cid:r,name:e,path:t,object:s,node:i}}function O0(r,e,t,n){let o=BigInt(r.length),i=BigInt(e+o);return t>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(r=r.subarray(0,Number(n-e))),t>=e&&t<i&&(r=r.subarray(Number(t-e))),r)}var v8=(r,e=0,t=r)=>{let n=BigInt(r),o=BigInt(e??0),i=BigInt(t);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new Ti("Offset must be greater than or equal to 0");if(o>n)throw new Ti("Offset must be less than the file size");if(i<0n)throw new Ti("Length must be greater than or equal to 0");if(i>n)throw new Ti("Length must be less than the file size");return{start:o,end:i}};function E8(r,e){async function*t(n={}){let{start:o,end:i}=v8(r.length,n.offset,n.length),s=O0(r,0n,o,i);n.onProgress?.(new Y(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(r.byteLength)})),yield s}return t}async function rU(r,e,t,n,o){let i=ze(r.multihash.bytes);return{type:"identity",cid:r,name:e,path:t,content:E8(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.length),node:i.bytes}}async function nU(r,e,t,n,o){let i=await De(n.get(r,o)),s=xa(i);return{type:"object",cid:r,name:e,path:t,object:s,node:i}}async function oU(r,e,t,n,o){let i=await De(n.get(r,o));return{type:"raw",cid:r,name:e,path:t,content:E8(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function iU(r,e,t,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,c=e.Links.slice(s,a);i.onProgress?.(new Y("unixfs:exporter:walk:directory",{cid:r})),yield*c.map(l=>({cid:l.Hash,name:l.Name??"",path:`${n}/${l.Name??""}`}))}return o}async function sU(r,e,t,n,o,i,s){if(e instanceof Uint8Array){let l=O0(e,n,o,i);t.push(l);return}if(e.Data==null)throw new Nt("no data in PBNode");let a;try{a=nn.unmarshal(e.Data)}catch(l){throw new Nt(l.message)}if(a.data!=null){let l=a.data,u=O0(l,n,o,i);t.push(u),n+=BigInt(u.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new Nt("Inconsistent block sizes and dag links");for(let l=0;l<e.Links.length;l++){let u=e.Links[l],f=n,h=f+a.blockSizes[l];if((o>=f&&o<h||i>=f&&i<=h||o<f&&i>h)&&c.push({link:u,blockStart:n}),n=h,n>i)break}await Xn(c,l=>er(l,u=>async()=>{let f=await De(r.get(u.link.Hash,s));return{...u,block:f}}),l=>ao(l,{ordered:!0,concurrency:s.blockReadConcurrency}),async l=>{for await(let{link:u,block:f,blockStart:h}of l){let d;switch(u.Hash.code){case pt:d=Jr(f);break;case ct:d=f;break;default:t.end(new Nt(`Unsupported codec: ${u.Hash.code}`));return}let m=new Ls({concurrency:1});m.on("error",y=>{t.end(y)}),m.add(async()=>{s.onProgress?.(new Y("unixfs:exporter:walk:file",{cid:u.Hash})),await sU(r,d,t,h,o,i,s)}),await m.onIdle()}}),n>=i&&t.end()}function TS(r,e,t,n,o){async function*i(s={}){let a=t.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:l}=v8(a,s.offset,s.length);if(l===0n)return;let u=0n,f=l-c,h=ur();s.onProgress?.(new Y("unixfs:exporter:walk:file",{cid:r})),sU(o,e,h,0n,c,l,s).catch(d=>{h.end(d)});for await(let d of h)if(d!=null){if(u+=BigInt(d.byteLength),u>f)throw h.end(),new x8("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");u===f&&h.end(),s.onProgress?.(new Y("unixfs:exporter:progress:unixfs:file",{bytesRead:u,totalBytes:f,fileSize:a})),yield d}if(u<f)throw new b8("Traversed entire DAG but did not read enough bytes")}return i}async function*aU(r,e,t,n){let o=r.Links;if(r.Data==null)throw new Nt("no data in PBNode");let i;try{i=nn.unmarshal(r.Data)}catch(c){throw new Nt(c.message)}if(i.fanout==null)throw new Nt("missing fanout");let s=(i.fanout-1n).toString(16).length,a=Xn(o,c=>er(c,l=>async()=>{let u=l.Name!=null?l.Name.substring(s):null;if(u!=null&&u!=="")return{entries:[{cid:l.Hash,name:u,path:`${e}/${u}`}]};{let f=await De(t.get(l.Hash,n));return r=Jr(f),n.onProgress?.(new Y("unixfs:exporter:walk:hamt-sharded-directory",{cid:l.Hash})),{entries:aU(r,e,t,n)}}}),c=>ao(c,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:c}of a)yield*c}function cU(r,e,t,n,o){function i(s={}){return s.onProgress?.(new Y("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),aU(e,n,o,s)}return i}var IZ={raw:TS,file:TS,directory:iU,"hamt-sharded-directory":cU,metadata:(r,e,t,n)=>()=>[],symlink:(r,e,t,n)=>()=>[]};async function lU(r,e,t,n,o){let i=await De(n.get(r,o)),s;try{s=Jr(i)}catch(l){throw new Nt(l.message)}if(s.Data==null)throw new Nt("no data in PBNode");let a;try{a=nn.unmarshal(s.Data)}catch(l){throw new Nt(l.message)}let c=IZ[a.type](r,s,a,t,n);if(c==null)throw new yo("could not find content exporter");return a.isDirectory()?{type:"directory",cid:r,name:e,path:t,entries:c,unixfs:a,node:s}:{type:"file",cid:r,name:e,path:t,content:c,unixfs:a,node:s,size:a.fileSize()}}var kZ={[pt]:lU,[ct]:oU,[fr]:_S,81:_S,[dr]:tU,[Ot.code]:rU,[lr]:nU};async function ls(r,e,t={}){let n,o;if(r instanceof String||typeof r=="string"){let s=await hh(Ic(r,e,t));if(s==null)throw new yo(`Could not walk path to ${r}`);n=s.cid,o=s.name,r=s.path}else if(Z.asCID(r)===r||r instanceof Z)n=r,o=r=n.toString();else throw new Ti("Path must be string or CID");let i=kZ[n.code];if(i==null)throw new mh(`No resolver for code ${n.code}`);return i(n,o,r,e,t)}async function*uU(r,e,t={}){let n=await ls(r,e,t);if(n==null)return;if(yield{cid:n.cid,name:n.name,path:n.path,depth:0},n.type==="directory")for await(let i of o(n,0,`${r}`,t))yield i;async function*o(i,s,a,c){s++;for await(let l of i.entries(c)){let u=`${a}/${l.name}`;yield{...l,depth:s,path:u};let f=await ls(l.cid,e,c);f.type==="directory"&&(yield*o(f,s,u,c))}}}var wo="application/vnd.ipld.dag-cbor",xo="application/cbor",bo="application/vnd.ipld.dag-json",vo="application/json",Vr="application/vnd.ipld.raw",Cr="application/octet-stream",Ru="application/vnd.ipfs.ipns-record",Ou="application/vnd.ipld.car",wh="application/x-tar",D0="application/vnd.ipld.dag-pb",S8={mediaType:Cr,codecs:[ct,lr,dr,81,fr,pt],immutable:!0,extension:".bin",etag:"",disposition:"attachment"},PZ={mediaType:wo,codecs:[fr,81,dr,lr,pt,ct],immutable:!0,extension:".cbor",etag:".dag-cbor",disposition:"attachment"},RZ={mediaType:xo,codecs:[81,fr,dr,lr,pt,ct],immutable:!0,extension:".cbor",etag:".cbor",disposition:"attachment"},OZ={mediaType:bo,codecs:[dr,lr,fr,81,pt,ct],immutable:!0,extension:".json",etag:".dag-json",disposition:"inline"},DZ={mediaType:vo,codecs:[lr,dr,fr,81,pt,ct],immutable:!0,extension:".json",etag:".json",disposition:"inline"},fU={mediaType:Vr,codecs:[ct,lr,dr,81,fr,pt],immutable:!0,extension:".raw",etag:".raw",disposition:"attachment"},Du={mediaType:Ru,codecs:[],immutable:!1,extension:".bin",etag:".bin",disposition:"attachment"},CS={mediaType:Ou,codecs:[ct,lr,dr,81,fr,pt],immutable:!1,extension:".car",etag:".car",disposition:"attachment"},NZ={mediaType:wh,codecs:[ct,pt],immutable:!1,extension:".x-tar",etag:".x-tar",disposition:"attachment"},dU=[PZ,RZ,OZ,DZ,fU,Du,CS,NZ,S8];function hU(r){return dU.find(e=>e.mediaType===r)}function N0(r){return r==null?[]:dU.filter(e=>e.codecs.includes(r.code)).sort((e,t)=>{let n=e.codecs.indexOf(r.code),o=t.codecs.indexOf(r.code);return n<o?-1:o<n?1:0})}function pU(r="ipfs:",e){let t=N0(e);return r==="ipfs:"&&t.length===0&&(t=[fU,S8]),r==="ipns:"&&t.push(Du),t}function Fn(r){if(r==null)throw new D("Cannot get filename for Content-Disposition header - filename argument was missing");let e=LZ(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function LZ(r){return r.replace(/[^\x00-\x7F]/g,"_")}var $n=class extends Error{static name="InvalidRangeError";constructor(e="Invalid range request"){super(e),this.name="InvalidRangeError"}};function mU({offset:r,length:e}){return{offset:Number(r),length:Number(e)}}function IS(r,e,t){if(r=BigInt(r),e!=null){if(e=BigInt(e),e<0n)throw new $n("Range start cannot be negative");if(e>=r)throw new $n("Range start cannot be larger than total bytes")}if(t!=null){if(t=BigInt(t),(t>0n?t:-t)>=r)throw new $n("Range end cannot be larger than total bytes");if(t<0n)if(e==null)e=r+t,t=r-1n;else throw new $n("Range end cannot be negative");t+=1n}return mU(yU(r,e,t))}function gU(r,e){r=BigInt(r);let t=(e??"0:*").split(":"),n=BigInt(t[0]),o=t[1]==="*"?r:BigInt(t[1]);return mU(yU(r,n,o))}function yU(r,e=0n,t=r){if(e>=0n)return t>=0n?{offset:e,length:t-e}:{offset:e,length:r-e+t};let n=r+e;return Math.abs(Number(e))>Number(r)&&(n=0n),t>=0n?{offset:n,length:t-n}:{offset:n,length:r-n+t}}function BZ(r){return r instanceof AggregateError||r?.name==="AggregateError"&&Array.isArray(r?.errors)}function L0(r){let e;return BZ(r)&&(e=r.errors.map(t=>L0(t))),{name:r.name,message:r.message,stack:r.stack,errors:e}}function wU({ttl:r,protocol:e,response:t}){if(t.headers.has("cache-control"))return;let n;e==="ipfs:"?n="public, max-age=29030400, immutable":r==null?n="public, max-age=300":n=`public, max-age=${r}`,t.headers.set("cache-control",n)}function kS(r,e,t){e!=null&&(e=BigInt(e)),t!=null&&(t=BigInt(t));let n=BigInt(r);if((t??0n)>=n)throw new $n("Invalid range: Range-end index is greater than or equal to the size of the file.");if((e??0n)>=n)throw new $n("Invalid range: Range-start index is greater than or equal to the size of the file.");let o="*";if(e==null)t!=null&&(t<0n?o=`${n+t}-${n-1n}`:o=`0-${t}`);else if(t==null){let i="*";r!=null&&(i=`${n-1n}`),o=`${e}-${i}`}else o=`${e}-${t}`;return`bytes ${o}/${n}`}function PS(r,e,t){Object.defineProperty(r,e,{enumerable:!0,configurable:!1,set:()=>{},get:()=>t})}function Eo(r,e){r.type!==e&&PS(r,"type",e)}function So(r,e){e=e.toString();let t=e.indexOf("#");t>-1&&(e=e.substring(0,t)),r.url!==e&&PS(r,"url",e)}function xU(r){PS(r,"redirected",!0)}function Ao(r,e,t){let n=new Response(e,{...t??{},status:200,statusText:"OK"});return t?.redirected===!0&&xU(n),Eo(n,"basic"),So(n,r),n}function RS(r,e,t){let n=new Response(JSON.stringify({error:L0(e)}),{...t??{},status:500,statusText:"Internal Server Error"});return n.headers.set("X-Content-Type-Options","nosniff"),n.headers.set("content-type","application/json"),n.headers.set("x-error-message",btoa(e.message)),Eo(n,"basic"),So(n,r),n}function A8(r,e,t){let n=new Response(e,{...t??{},status:504,statusText:"Gateway Timeout"});return Eo(n,"basic"),So(n,r),n}function Nu(r,e,t){let n=new Response(e,{...t??{},status:502,statusText:"Bad Gateway"});return Eo(n,"basic"),So(n,r),n}function OS(r,e,t){let n=new Response(e,{...t??{},status:501,statusText:"Not Implemented"});return n.headers.set("X-Content-Type-Options","nosniff"),Eo(n,"basic"),So(n,r),n}function Pc(r,e,t,n){let o=new Headers(n?.headers);o.set("content-type","application/json");let i=new Response(JSON.stringify({requested:e.map(s=>s.mediaType),acceptable:t.map(s=>s.mediaType)}),{...n??{},status:406,statusText:"Not Acceptable",headers:o});return Eo(i,"basic"),So(i,r),i}function DS(r,e,t){let n=new Response(e,{...t??{},status:404,statusText:"Not Found"});return Eo(n,"basic"),So(n,r),n}function MZ(r){return Array.isArray(r)&&r.every(e=>e instanceof Error)}function Go(r,e,t){let n,o;MZ(e)?(n=e[e.length-1].stack,o=e.map(a=>({message:a.message,stack:a.stack??""}))):e instanceof Error&&(n=e.stack,o=[{message:e.message,stack:e.stack??""}]);let i=JSON.stringify({stack:n,errors:o}),s=new Response(i,{status:400,statusText:"Bad Request",...t??{},headers:{...t?.headers??{},"Content-Type":"application/json"}});return Eo(s,"basic"),So(s,r),s}function bU(r,e,t){let n=new Response(null,{...t??{},status:301,statusText:"Moved Permanently",headers:{...t?.headers??{},location:e}});return Eo(n,"basic"),So(n,r),n}function NS(r,e,t){let n=new Response(null,{...t??{},status:304,statusText:"Not Modified"});return["cache-control","content-location","date","etag","expires","vary"].forEach(i=>{let s=e.get(i);s!=null&&n.headers.set(i,s)}),Eo(n,"basic"),So(n,r),n}function xh(r,e,t,n,o){let i;if(t.ranges.length===1)i=UZ(r,e,t.ranges[0],n,o);else if(t.ranges.length>1)i=FZ(r,e,t,n,o);else return _8(r,n);return o?.redirected===!0&&xU(i),Eo(i,"basic"),So(i,r),i}function UZ(r,e,t,n,o){try{let i=new Headers(o?.headers),{offset:s,length:a}=IS(n,t.start,t.end);i.set("content-length",`${a}`),i.set("content-range",kS(n,t.start,t.end));let c=Fo(e(s,a));return new Response(c,{...o??{},status:206,statusText:"Partial Content",headers:i})}catch(i){return i.name==="InvalidRangeError"?_8(r,n,o):RS(r,i,o)}}function FZ(r,e,t,n,o){let i=new Headers(o?.headers),s=i.get("content-type");if(s==null)throw new Error("Content-Type header must be set");i.delete("content-type");let a=0n,c=t.ranges.map(({start:f,end:h})=>{let d=O([`--${t.multipartBoundary}`,`Content-Type: ${s}`,`Content-Range: ${kS(n,f,h)}`,"",""].join(`\r
|
|
110
|
+
`)}var W5=class{log;metrics;components;init;certificate;privateKey;emitter;renewCertificateTask;constructor(e,t={}){if(this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,this.emitter=new _e,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new D("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[ya]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[qe]=["@libp2p/transport"];async start(){this.certificate=await this.getCertificate()}async stop(){this.renewCertificateTask!=null&&clearTimeout(this.renewCertificateTask),this.certificate=void 0}async dial(e,t){this.log("dial %a",e),t.signal.throwIfAborted();let n,o=e.getComponents().findLast(c=>c.code===421)?.value;o!=null&&(n=je(o));let i=sN(),{peerConnection:s,muxerFactory:a}=await XB("client",i,{rtcConfiguration:typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{},dataChannel:this.init.dataChannel});try{return await GB(s,a,i,{role:"client",log:this.log,logger:this.components.logger,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeer:n,privateKey:this.components.privateKey})}catch(c){throw s.close(),c}}createListener(e){if(this.certificate==null)throw new qn;return new j5(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(jp.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(RQ(this.init.certificate))return this.log("using provided TLS certificate"),this.init.certificate;let t=await this.loadOrCreatePrivateKey(),{pem:n,certhash:o}=await this.loadOrCreateCertificate(t,e);return{privateKey:await YB(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??ZD,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Ye;this.log.trace("checking for stored private key"),this.privateKey=await t.exportKey(e)}catch(n){if(n.name!=="NotFoundError")throw n;this.log.trace("generating private key"),this.privateKey=await yf("ECDSA","P-256"),t!=null?(this.log.trace("storing private key"),await t.importKey(e,this.privateKey)):this.log("no keychain configured - not storing private key")}return this.privateKey}async loadOrCreateCertificate(e,t){if(this.certificate!=null&&t!==!0)return this.certificate;let n,o=new nt(this.init.certificateDatastoreKey??QD),i=await bg(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Ye;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??av)-Date.now();return s<0&&(s=100),this.log("will renew TLS certificate after %d ms",s),this.renewCertificateTask=setTimeout(()=>{this.log("renewing TLS certificate"),this.getCertificate(!0).then(a=>{this.certificate=a,this.emitter.safeDispatchEvent("certificate:renew",{detail:a})}).catch(a=>{this.log.error("could not renew certificate - %e",a)})},s),{pem:n.toString("pem"),certhash:Fc.encode((await At.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ch(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??av);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Ye;this.log("loaded certificate, expires in %d ms",i);let s=await o.publicKey.export(crypto),a=await crypto.subtle.exportKey("raw",s),c=await crypto.subtle.exportKey("raw",t.publicKey);if(!me(new Uint8Array(a,0,a.byteLength),new Uint8Array(c,0,c.byteLength)))throw this.log("stored TLS certificate public key did not match public key from private key"),new Ye;return this.log("loaded certificate, expiry time is %o",i),o}async createCertificate(e,t){let n=new Date,o=new Date(Date.now()+(this.init.certificateLifespan??JD));n.setMilliseconds(0),o.setMilliseconds(0);let i=await z5.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new ih(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,O(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function RQ(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function G5(r){return e=>new W5(e,r)}function QB(r){return e=>new H6(e,r)}function ZB(){throw new Error("WebSocket Servers can not be created in the browser!")}var OQ=1024*1024*4,DQ=10,oS=class extends Ra{websocket;maxBufferedAmount;checkBufferedAmountTask;constructor(e){super(e),this.websocket=e.websocket,this.maxBufferedAmount=e.maxBufferedAmount??OQ,this.checkBufferedAmountTask=Bf(this.checkBufferedAmount.bind(this),e.bufferedAmountPollInterval??DQ),this.websocket.addEventListener("close",t=>{if(this.log('closed - code %d, reason "%s", wasClean %s',t.code,t.reason,t.wasClean),this.checkBufferedAmountTask.stop(),!t.wasClean){this.onRemoteReset();return}this.onTransportClosed()},{once:!0}),this.websocket.addEventListener("message",t=>{try{let n;if(typeof t.data=="string")n=O(t.data);else if(t.data instanceof ArrayBuffer)n=new Uint8Array(t.data,0,t.data.byteLength);else{this.abort(new Error("Incorrect binary type"));return}this.onData(n)}catch(n){this.log.error("error receiving data - %e",n)}})}sendData(e){for(let n of e)this.websocket.send(n);let t=this.websocket.bufferedAmount<this.maxBufferedAmount;return t||this.checkBufferedAmountTask.start(),{sentBytes:e.byteLength,canSendMore:t}}sendReset(){this.websocket.close(1006)}async sendClose(e){this.websocket.close(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}checkBufferedAmount(){this.log("buffered amount now %d",this.websocket.bufferedAmount),this.websocket.bufferedAmount===0&&(this.checkBufferedAmountTask.stop(),this.safeDispatchEvent("drain"))}};function JB(r){return new oS(r)}var iS=class{log;init;logger;metrics;components;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:websockets"),this.logger=e.logger,this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_websockets_dialer_events_total",{label:"event",help:"Total count of WebSockets dialer events by type"})})}[ya]=!0;[Symbol.toStringTag]="@libp2p/websockets";[qe]=["@libp2p/transport"];async dial(e,t){this.log("dialing %s",e),t=t??{};let n=JB({websocket:await this._connect(e,t),remoteAddr:e,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:websockets:connection"),maxBufferedAmount:this.init.maxBufferedAmount,bufferedAmountPollInterval:this.init.bufferedAmountPollInterval});this.log("new outbound connection %s",n.remoteAddr);let o=await t.upgrader.upgradeOutbound(n,t);return this.log("outbound connection %s upgraded",n.remoteAddr),o}async _connect(e,t){t?.signal?.throwIfAborted();let n=Ha(e);this.log("create websocket connection to %s",n);let o=new WebSocket(n);o.binaryType="arraybuffer";try{t.onProgress?.(new Y("websockets:open-connection")),await Ze(o,"open",t)}catch(i){if(t.signal?.aborted)throw this.metrics?.dialerEvents.increment({abort:!0}),new Vu(`Could not connect to ${n}`);this.metrics?.dialerEvents.increment({error:!0});try{o.close()}catch{}throw i}return this.log("connected %s",e),this.metrics?.dialerEvents.increment({connect:!0}),o}createListener(e){return ZB({logger:this.logger,events:this.components.events,metrics:this.components.metrics},{...this.init,...e})}listenFilter(e){return e.filter(t=>Hs.exactMatch(t)||Sl.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function X5(r={}){return e=>new iS(e,r)}var sS=gt(Ty(),1);function Y5(r,e){let t=e.map((n,o)=>({record:io(n),index:o}));return t.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===_n.ValidityType.EOL&&o.record.validityType===_n.ValidityType.EOL){let a=sS.default.fromString(n.record.validity).toDate(),c=sS.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var eM="6.0.14",tM="helia";var rM={list:["/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN","/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb","/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt","/dnsaddr/va1.bootstrap.libp2p.io/p2p/12D3KooWKnDdG3iXw9eTFijk3EWSunZcFi54Zka4wmtqtt6rPxc8","/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"]};function b0(r={}){let e=`${tM}/${eM} ${I3()}`;return{privateKey:r.privateKey,dns:r.dns,nodeInfo:{userAgent:e},addresses:{listen:["/p2p-circuit","/webrtc"]},transports:[cO(),QB(),G5(),X5()],connectionEncrypters:[i4()],streamMuxers:[jR(),$D()],peerDiscovery:[QR(rM)],services:{autoNAT:YR(),dcutr:fO(),delegatedRouting:()=>_k("https://delegated-ipfs.dev",g9()),dht:LD({clientMode:!0,validators:{ipns:Tl},selectors:{ipns:Y5}}),identify:rD(),identifyPush:nD(),keychain:Z3(r.keychain),ping:zD(),http:YO()}}}async function nM(r){let e=r.libp2p??{};e.privateKey==null&&r.datastore!=null&&(e.privateKey=await rb(r.datastore,r.keychain));let t=b0(e);return t.datastore=t.datastore??r.datastore,await k3({...t,...e,start:!1})}async function oM(r={}){let e=r.datastore??new Cl,t=r.blockstore??new em,n;return yP(r.libp2p)?n=r.libp2p:n=await nM({...r,libp2p:{dns:r.dns,...r.libp2p,start:void 0},datastore:e}),{...r,libp2p:n,datastore:e,blockstore:t,blockBrokers:r.blockBrokers??[Gp(),qp()],routers:r.routers??[Jp(n),Zp()],metrics:n.metrics}}async function iM(r={}){let e=await oM(r),t=new fy(e);return e.start!==!1&&await t.start(),t}function sM(){let r=b0();r.start=!1,r.addresses={listen:[]},r.transports=[G5(),X5()],r.peerDiscovery=[];let e={dcutr:r.services.dcutr,identify:r.services.identify,keychain:r.services.keychain,ping:r.services.ping};return{...r,start:!1,services:e}}var lh=class extends Map{#t=0;#e=new Map;#r=new Map;#o;#s;#a;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=e.maxSize,this.#s=e.maxAge||Number.POSITIVE_INFINITY,this.#a=e.onEviction}get __oldCache(){return this.#r}#l(e){if(typeof this.#a=="function")for(let[t,n]of e)this.#a(t,n.value)}#n(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#a=="function"&&this.#a(e,t.value),this.delete(e)):!1}#m(e,t){if(this.#n(e,t)===!1)return t.value}#h(e,t){return t.expiry?this.#m(e,t):t.value}#p(e,t){let n=t.get(e);return this.#h(e,n)}#u(e,t){this.#e.set(e,t),this.#t++,this.#t>=this.#o&&(this.#t=0,this.#l(this.#r),this.#r=this.#e,this.#e=new Map)}#f(e,t){this.#r.delete(e),this.#u(e,t)}*#i(){for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield e)}for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#h(e,t)}if(this.#r.has(e)){let t=this.#r.get(e);if(this.#n(e,t)===!1)return this.#f(e,t),t.value}}set(e,t,{maxAge:n=this.#s}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#u(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#n(e,this.#e.get(e)):this.#r.has(e)?!this.#n(e,this.#r.get(e)):!1}peek(e){if(this.#e.has(e))return this.#p(e,this.#e);if(this.#r.has(e))return this.#p(e,this.#r)}expiresIn(e){let t=this.#e.get(e)??this.#r.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){let t=this.#e.delete(e);return t&&this.#t--,this.#r.delete(e)||t}clear(){this.#e.clear(),this.#r.clear(),this.#t=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#i()],n=t.length-e;n<0?(this.#e=new Map(t),this.#r=new Map,this.#t=t.length):(n>0&&this.#l(t.slice(0,n)),this.#r=new Map(t.slice(n)),this.#e=new Map,this.#t=0),this.#o=e}evict(e=1){let t=Number(e);if(!t||t<=0)return;let n=[...this.#i()],o=Math.trunc(Math.min(t,Math.max(n.length-1,0)));o<=0||(this.#l(n.slice(0,o)),this.#r=new Map(n.slice(o)),this.#e=new Map,this.#t=0)}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield[t,n.value])}for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield[t,n.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#n(o,i)===!1&&(yield[o,i.value])}e=[...this.#r];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#e.has(o)||this.#n(o,i)===!1&&(yield[o,i.value])}}*entriesAscending(){for(let[e,t]of this.#i())yield[e,t.value]}get size(){if(!this.#t)return this.#r.size;let e=0;for(let t of this.#r.keys())this.#e.has(t)||e++;return Math.min(this.#t+e,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#s}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[n,o]of this.entriesAscending())e.call(t,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var Q5=class extends Error{static name="DNSLinkNotFoundError";constructor(e="DNSLink not found"){super(e),this.name="DNSLinkNotFoundError"}},uh=class extends Error{static name="InvalidNamespaceError";constructor(e="Invalid namespace"){super(e),this.name="InvalidNamespaceError"}};var aM=(r,e)=>{let[,t,n,...o]=r.split("/");if(t!=="ipfs")throw new uh(`Namespace ${t} was not "ipfs"`);return{namespace:"ipfs",cid:Z.parse(n),path:o.length>0?`/${o.join("/")}`:"",answer:e}};var cM=(r,e)=>{let[,t,n,...o]=r.split("/");if(t!=="ipns")throw new uh(`Namespace ${t} was not "ipns"`);try{return{namespace:"ipns",peerId:je(n),path:o.length>0?`/${o.join("/")}`:"",answer:e}}catch{return{namespace:"dnslink",value:n,path:o.length>0?`/${o.join("/")}`:"",answer:e}}};var Z5=class{dns;log;namespaces;cache;cacheMaxAnswers;constructor(e,t={}){this.dns=e.dns,this.log=e.logger.forComponent("helia:dnslink"),this.namespaces={ipfs:aM,ipns:cM,...t.namespaces},this.cache=new lh({maxSize:t.cacheSize??1e3,maxAge:t.cacheMaxAge??3e4}),this.cacheMaxAnswers=t.cacheMaxAnswers??10}async resolve(e,t={}){if(t.nocache!==!0){let s=this.cache.get(e);if(s!=null){let a=[...s.values()];if(a.length>0)return a}}let n=await this.recursiveResolveDomain(e,t.maxRecursiveDepth??xI,t),o=new lh({maxSize:this.cacheMaxAnswers});n.forEach((s,a)=>{o.set(a,s,{maxAge:s.answer.TTL*1e3})});let i=n.reduce((s,a)=>{let c=a.answer.TTL*1e3;return c>s?c:s},0);return this.cache.maxAge<i&&(i=this.cache.maxAge),this.cache.set(e,o,{maxAge:i}),n}async recursiveResolveDomain(e,t,n={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await this.recursiveResolveDnslink(e,t,n)}catch(o){if(o.code!=="ENOTFOUND"&&o.code!=="ENODATA"&&o.name!=="DNSLinkNotFoundError"&&o.name!=="NotFoundError")throw o;return e.startsWith("_dnslink.")?e=e.replace("_dnslink.",""):e=`_dnslink.${e}`,this.recursiveResolveDnslink(e,t,n)}}async recursiveResolveDnslink(e,t,n={}){if(t===0)throw new Error("recursion limit exceeded");this.log("query %s for TXT and CNAME records",e);let i=((await this.dns.query(e,{...n,types:[Zr.TXT]}))?.Answer??[]).sort((l,u)=>l.data.localeCompare(u.data));this.log("found %d TXT records for %s",i.length,e);let s=[];for(let l of i)try{let u=l.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;this.log("%s TXT %s",l.name,u),u=u.replace("dnslink=","");let[,f,h]=u.split("/");if(f==="dnslink"){s.push(...await this.recursiveResolveDomain(h,t-1,n));continue}let d=this.namespaces[f];if(d==null){this.log('unknown protocol "%s" in DNSLink record for domain: %s',f,e);continue}let m=d(u,l);if(m.namespace==="dnslink"){s.push(...await this.recursiveResolveDomain(m.value,t-1,n));continue}s.push(d(u,l))}catch(u){this.log.error("could not parse DNS link record for domain %s, %s - %e",e,l.data,u)}if(s.length>0)return s;this.log("no DNSLink records found for %s, falling back to CNAME",e);let c=((await this.dns.query(e,{...n,types:[Zr.CNAME]}))?.Answer??[]).sort((l,u)=>l.data.localeCompare(u.data));this.log("found %d CNAME records for %s",c.length,e);for(let l of c)try{return await this.recursiveResolveDomain(l.data,t-1,n)}catch(u){this.log.error("domain %s cname %s had no DNSLink records - %e",e,l.data,u)}throw new Q5(`No DNSLink records found for domain: ${e}`)}};function lM(r,e={}){return new Z5(r,e)}var uM=BigInt(6e4)*5000000n;var J5=class extends Error{static name="RecordsFailedValidationError";constructor(e="Records failed validation"){super(e),this.name="RecordsFailedValidationError"}},e8=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(e="Unsupported multibase prefix"){super(e),this.name="UnsupportedMultibasePrefixError"}},t8=class extends Error{static name="UnsupportedMultihashCodecError";constructor(e="Unsupported multihash codec"){super(e),this.name="UnsupportedMultihashCodecError"}},r8=class extends Error{static name="InvalidValueError";constructor(e="Invalid value"){super(e),this.name="InvalidValueError"}};var v0=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"};var NQ=114,aS=0,cS=18;function lS(r,e){return r.code===e}var n8="/dht/record/",LQ="/ipns/metadata/";function E0(r){return new nt(n8+H(r,"base32"),!1)}function o8(r){return new nt(LQ+H(r,"base32"),!1)}function BQ(r){return r?.asCID===r}function fM(r){if(!BQ(r))return!1;if(r.code!==NQ)throw new D(`CID codec ${r.code} was not libp2p-key`);if(r.multihash.code!==aS&&r.multihash.code!==cS)throw new D(`Multihash algorithm codec ${r.multihash.code} was not Identity or SHA256 hash`);return!0}var dM={[an.prefix]:an,[Qe.prefix]:Qe},i8=class{routers;localStore;log;constructor(e,t){this.log=e.logger.forComponent("helia:ipns"),this.localStore=t.localStore,this.routers=t.routers}async resolve(e,t={}){let n=Y0(e)||mr(e)?e.toMultihash():fM(e)?e.multihash:e,o=_l(n),i=await this.#e(o,t);return{...await this.#t(i.value,t),record:i}}async#t(e,t={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=Qe.decode(`z${i}`);else if(dM[s]!=null)a=dM[s].decode(i);else throw new e8(`Unsupported multibase prefix "${s}"`);let c;try{c=ze(a)}catch{c=Z.decode(a).multihash}if(!lS(c,aS)&&!lS(c,cS))throw new t8(`Unsupported multihash codec "${c.code}"`);let{cid:l}=await this.resolve(c,t),u=n.slice(3).join("/");return{cid:l,path:u===""?void 0:u}}else if(o==="ipfs"){let i=Z.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s===""?void 0:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",e),new r8("Invalid value")}async#e(e,t={}){let n=[];if(await this.localStore.has(e,t))if(this.log("record is present in the cache"),t.nocache!==!0)try{let{record:c,created:l}=await this.localStore.get(e,t);this.log("record retrieved from cache"),await Tl(e,c),this.log("record was valid");let u=io(c),f=Number((u.ttl??uM)/1000000n);if(l.getTime()+f>Date.now())return this.log("record TTL was valid"),u;if(t.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),u;this.log("record TTL has been reached, searching routing for updates"),n.push(c)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,t)}else this.log("ignoring local cache due to nocache=true option");if(t.offline===!0)throw new v0("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async c=>{let l;try{l=await c.get(e,{...t,validate:!1})}catch(u){this.log.error("error finding IPNS record using router %s - %e",c.toString(),u),s.push(u);return}try{await Tl(e,l),n.push(l)}catch(u){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),u)}})),n.length===0)throw i>0?new J5(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new v0("Could not find record for routing key");let a=n[Y5(e,n)];return await this.localStore.put(e,a,t),io(a)}};var S0;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.keyName!=null&&t.keyName!==""&&(n.uint32(10),n.string(t.keyName)),t.lifetime!=null&&t.lifetime!==0&&(n.uint32(16),n.uint32(t.lifetime)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={keyName:"",lifetime:0},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.keyName=t.string();break}case 2:{i.lifetime=t.uint32();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>be(t,r.codec()),r.decode=(t,n)=>xe(t,r.codec(),n)})(S0||(S0={}));function hM(r,e){return{async put(t,n,o={}){try{let i=E0(t);try{let c=await r.get(i),l=Ut.deserialize(c);if(me(l.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Ut(t,n,new Date);o.onProgress?.(new Y("ipns:routing:datastore:put"));let a=r.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(o8(t),S0.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new Y("ipns:routing:datastore:error",i)),i}},async get(t,n={}){try{let o=E0(t);n.onProgress?.(new Y("ipns:routing:datastore:get"));let i=await r.get(o,n),s=Ut.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new Y("ipns:routing:datastore:error",o)),o}},async has(t,n={}){let o=E0(t);return r.has(o,n)},async delete(t,n){let o=E0(t),i=r.batch();i.delete(o),i.delete(o8(t)),await i.commit(n)},async*list(t={}){try{t.onProgress?.(new Y("ipns:routing:datastore:list"));for await(let{key:n,value:o}of r.query({prefix:n8},t))try{let i=Ut.deserialize(o),a=n.toString().substring(n8.length),c=O(a,"base32"),l=o8(c),u;try{let f=await r.get(l,t);u=S0.decode(f)}catch(f){e.error("Error deserializing metadata for %s - %e",a,f)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw t.onProgress?.(new Y("ipns:routing:datastore:error",n)),n}}}}var uS=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(o){throw n.onProgress?.(new Y("ipns:routing:helia:error",o)),o}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){throw t.onProgress?.(new Y("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function fS(r){return new uS(r)}var dS=class{localStore;constructor(e){this.localStore=e}async put(e,t,n){await this.localStore.put(e,t,n)}async get(e,t){let{record:n}=await this.localStore.get(e,t);return n}toString(){return"LocalStoreRouting()"}};function pM(r){return new dS(r)}function mM(r,e={}){let t=hM(r.datastore,r.logger.forComponent("helia:ipns:local-store")),n=[pM(t),fS(r.routing),...e.routers??[]];return new i8(r,{routers:n,localStore:t})}var mS=gt(s8(),1);var gS=40;function yS(r,e){if(!r.length)throw new Error("Unexpected end of data");let t=mS.default.decode(r);return e.seek(mS.default.decode.bytes),t}function wS(r){let e=new DataView(r.buffer,r.byteOffset,r.byteLength),t=0;return{version:2,characteristics:[e.getBigUint64(t,!0),e.getBigUint64(t+=8,!0)],dataOffset:Number(e.getBigUint64(t+=8,!0)),dataSize:Number(e.getBigUint64(t+=8,!0)),indexOffset:Number(e.getBigUint64(t+=8,!0))}}var Cc={Null:r=>r===null?r:void 0,Int:r=>Number.isInteger(r)?r:void 0,Float:r=>typeof r=="number"&&Number.isFinite(r)?r:void 0,String:r=>typeof r=="string"?r:void 0,Bool:r=>typeof r=="boolean"?r:void 0,Bytes:r=>r instanceof Uint8Array?r:void 0,Link:r=>r!==null&&typeof r=="object"&&r.asCID===r?r:void 0,List:r=>Array.isArray(r)?r:void 0,Map:r=>r!==null&&typeof r=="object"&&r.asCID!==r&&!Array.isArray(r)&&!(r instanceof Uint8Array)?r:void 0},A0={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Cc.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Cc.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=A0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=A0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:Cc.Int,CarV1HeaderOrV2Pragma:r=>{if(Cc.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=A0["CarV1HeaderOrV2Pragma > roots (anon)"](r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=A0.Int(r[i]);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},_0={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Cc.Link,"CarV1HeaderOrV2Pragma > roots (anon)":r=>{if(Cc.List(r)!==void 0){for(let e=0;e<r.length;e++){let t=r[e];if(t=_0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](t),t===void 0)return;if(t!==r[e]){let n=r.slice(0,e);for(let o=e;o<r.length;o++){let i=r[o];if(i=_0["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return r}},Int:Cc.Int,CarV1HeaderOrV2Pragma:r=>{if(Cc.Map(r)===void 0)return;let e=Object.entries(r),t=r,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let a=_0["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.roots=a}}break;case"version":{n--;let a=_0.Int(s);if(a===void 0)return;if(a!==s||t!==r){if(t===r){t={};for(let c=0;c<o;c++)t[e[c][0]]=e[c][1]}t.version=a}}break;default:return}}if(!(n>0))return t}},xS={toTyped:A0.CarV1HeaderOrV2Pragma,toRepresentation:_0.CarV1HeaderOrV2Pragma};var $Ye=lx();var JQ=gt(s8(),1);var zYe=[new j(A.map,2),new j(A.string,"version"),new j(A.uint,1),new j(A.string,"roots")],jYe=new j(A.tag,42);async function bS(r,e){let t=yS(await r.upTo(8),r);if(t===0)throw new Error("Invalid CAR header (zero length)");let n=await r.exactly(t,!0),o=no(n);if(xS.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=wS(await r.exactly(gS,!0));r.seek(i.dataOffset-r.pos);let s=await bS(r,1);return Object.assign(s,i)}function T0(r){let e=0;return{async upTo(t){return r.subarray(e,e+Math.min(t,r.length-e))},async exactly(t,n=!1){if(t>r.length-e)throw new Error("Unexpected end of data");let o=r.subarray(e,e+t);return n&&(e+=t),o},seek(t){e+=t},get pos(){return e}}}var vS=gt(s8(),1),CM=1;function ES(r){let e=gn({version:CM,roots:r}),t=vS.default.encode(e.length),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function IM(r){return{async setRoots(e){let t=ES(e);await r.write(t)},async writeBlock(e){let{cid:t,bytes:n}=e;await r.write(new Uint8Array(vS.default.encode(t.bytes.length+n.length))),await r.write(t.bytes),n.length&&await r.write(n)},async close(){await r.end()},version(){return CM}}}function a8(){}function kM(){let r=[],e=null,t=a8,n=!1,o=null,i=a8,s=()=>(e||(e=new Promise(l=>{t=()=>{e=null,t=a8,l()}})),e),a={write(l){r.push(l);let u=s();return i(),u},async end(){n=!0;let l=s();i(),await l}},c={async next(){let l=r.shift();return l?(r.length===0&&t(),{done:!1,value:l}):n?(t(),{done:!0,value:void 0}):(o||(o=new Promise(u=>{i=()=>(o=null,i=a8,u(c.next()))})),o)}};return{writer:a,iterator:c}}var C0=class r{constructor(e,t){this._encoder=t,this._mutex=t.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let t=Z.asCID(e.cid);if(!t)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:t,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=nZ(e);let{encoder:t,iterator:n}=PM(),o=new r(e,t),i=new c8(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:t}=PM();e.setRoots=()=>Promise.resolve();let n=new r([],e),o=new c8(t);return{writer:n,out:o}}static async updateRootsInBytes(e,t){let n=T0(e);await bS(n);let o=ES(t);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},c8=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function PM(){let r=kM(),{writer:e,iterator:t}=r;return{encoder:IM(e),iterator:t}}function nZ(r){if(r===void 0)return[];if(!Array.isArray(r)){let t=Z.asCID(r);if(!t)throw new TypeError("roots must be a single CID or an array of CIDs");return[t]}let e=[];for(let t of r){let n=Z.asCID(t);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var fh=class{walker;constructor(e){this.walker=e?.walker}async*export(e,t,n,o){let i,s={blockstore:t,getCodec:n};this.walker!=null?i=this.walker(s):i=ly()(s);for await(let a of i.walk(e,o))yield a.block}};var l8=class{components;log;constructor(e){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,t){await Xr(this.components.blockstore.putMany(er(e.blocks(),({cid:n,bytes:o})=>({cid:n,bytes:o})),t))}async*export(e,t){let n=Array.isArray(e)?e:[e],{writer:o,out:i}=C0.create(n),s=i[Symbol.asyncIterator](),a=new AbortController;for(this._export(n,o,t).catch(c=>{this.log.error("error during streaming export - %e",c),a.abort(c)});;){let{done:c,value:l}=await rt(s.next(),a.signal);if(a.signal.aborted)throw a.signal.reason;if(l!=null&&(yield l),c===!0)break}}async _export(e,t,n){let o=n?.traversal;for(let i of e){if(i.multihash.code===0)continue;let s=n?.exporter??(i.code===112?new dh:new fh),a=i,c=!1;if(o!=null){for await(let{cid:l,bytes:u}of o.traverse(a,this.components.blockstore,this.components.getCodec,n))if(this.log.trace("next CID on path to %c is %c",i,l),a=l,i.equals(l)&&(c=!0),c||n?.includeTraversalBlocks===!0){if(n?.blockFilter?.has(l.multihash.bytes)===!0)continue;n?.blockFilter?.add(l.multihash.bytes),await t.put({cid:l,bytes:u})}}for await(let{cid:l,bytes:u}of s.export(a,this.components.blockstore,this.components.getCodec,n))n?.blockFilter?.has(l.multihash.bytes)!==!0&&l.multihash.code!==0&&(c&&l.equals(a)||(n?.blockFilter?.add(l.multihash.bytes),await t.put({cid:l,bytes:u})))}await t.close()}};var I0=class{async*export(e,t,n,o){let i=await De(t.get(e,o));yield $a({cid:e,bytes:i,codec:await n(e.code)})}};var k0=class r extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=r.name;code=r.code;constructor(e="Invalid type"){super(e)}},u8=class r extends Error{static name="InvalidUnixFSMessageError";static code="ERR_INVALID_MESSAGE";name=r.name;code=r.code;constructor(e="Invalid message"){super(e)}};var _i;(function(r){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=r.DataType||(r.DataType={}));let t;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(t||(t={})),(function(o){o.codec=()=>wt(t)})(e=r.DataType||(r.DataType={}));let n;r.codec=()=>(n==null&&(n=ve((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),r.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let a of o.blocksizes)i.uint32(32),i.uint64(a);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),f8.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.Type=r.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=f8.codec().decode(o,o.uint32());break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>be(o,r.codec()),r.decode=o=>xe(o,r.codec())})(_i||(_i={}));var f8;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Seconds!=null&&(n.uint32(8),n.int64(t.Seconds)),t.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(t.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Seconds=t.int64();break;case 2:o.FractionalNanoseconds=t.fixed32();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>be(t,r.codec()),r.decode=t=>xe(t,r.codec())})(f8||(f8={}));var OM;(function(r){let e;r.codec=()=>(e==null&&(e=ve((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.MimeType!=null&&(n.uint32(10),n.string(t.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.MimeType=t.string();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>be(t,r.codec()),r.decode=t=>xe(t,r.codec())})(OM||(OM={}));var DM={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},iZ=["directory","hamt-sharded-directory"],NM=parseInt("0644",8),LM=parseInt("0755",8),BM=BigInt(1024),nn=class r{static unmarshal(e){let t=_i.decode(e);if(t.fanout!=null&&t.fanout>BM)throw new u8(`Fanout size was too large - ${t.fanout} > ${BM}`);let n=new r({type:DM[t.Type!=null?t.Type.toString():"File"],data:t.Data,blockSizes:t.blocksizes,mode:t.mode,mtime:t.mtime!=null?{secs:t.mtime.Seconds??0n,nsecs:t.mtime.FractionalNanoseconds}:void 0,fanout:t.fanout});return n._originalMode=t.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:t,data:n,blockSizes:o,hashType:i,fanout:s,mtime:a,mode:c}=e;if(t!=null&&!Object.values(DM).includes(t))throw new k0("Type: "+t+" is not valid");this.type=t??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?LM:NM:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return iZ.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(t=>{e+=t}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=_i.DataType.Raw;break;case"directory":e=_i.DataType.Directory;break;case"file":e=_i.DataType.File;break;case"metadata":e=_i.DataType.Metadata;break;case"symlink":e=_i.DataType.Symlink;break;case"hamt-sharded-directory":e=_i.DataType.HAMTShard;break;default:throw new k0(`Type: ${e} is not valid`)}let t=this.data;(this.data==null||this.data.length===0)&&(t=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===NM&&!this.isDirectory()&&(n=void 0),n===LM&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),_i.encode({Type:e,Data:t,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var P0=class extends Error{static code="ERR_NOT_UNIXFS";static message="Not a UnixFS node";static name="NotUnixFSError";code="ERR_NOT_UNIXFS";message="Not a UnixFS node";name="NotUnixFSError"},d8=class extends Error{static name="NotDescendantError";name="NotDescendantError"},h8=class extends Error{static name="InvalidTraversalError";name="InvalidTraversalError"};function aZ(r){return r.cid.code===85}function cZ(r){return r.cid.code===112}function lZ(r){if(aZ(r))return!0;if(cZ(r)&&r.value.Data!=null){let e=nn.unmarshal(r.value.Data);return e.type==="file"||e.type==="raw"}else throw new P0("Encountered non raw/dag-pb CID in UnixFS DAG")}var dh=class{options;constructor(e){this.options=e}async*export(e,t,n,o){if(e.code!==112&&e.code!==85)throw new P0("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");let i=zf()({blockstore:t,getCodec:n}),s=this.options?.offset??0,a=this.options?.length??1/0,c=this.options?.listingOnly??!1;if(s<0)throw new D("Offset cannot be negative");if(a<0)throw new D("Length cannot be negative");let l,u=new AbortController,f=Re([u.signal,o?.signal]);u.signal;function h(d,m){if(l==null&&(l=lZ(m)),!l){let U=m.value.Links.find(M=>M.Hash.equals(d)),K=nn.unmarshal(m.value.Data??new Uint8Array);return K.type==="directory"?!c:K.type==="hamt-sharded-directory"&&c?U?.Name?.length===2:!0}let y=m.value.Links.findIndex(U=>U.Hash.equals(d)),w=nn.unmarshal(m.value.Data??new Uint8Array),x=s,v=x+a,E=Number([...w.blockSizes].slice(0,y).reduce((U,K)=>U+K,0n)),I=E+Number(w.blockSizes[y]);return x>=E&&x<I||v>=E&&v<I||x<=E&&v>=I}try{for await(let d of i.walk(e,{...o,includeChild:h,signal:f}))yield d.block}finally{u.abort(),f.clear()}}};var p8=class{path;constructor(e){this.path=e}async*traverse(e,t,n,o){if(!this.path.some(s=>s.equals(e)))throw new h8(`CIDPath traversal must include ${e}`);let i;for(let s of this.path){if(i!=null){let l=!1;for(let[,u]of i.links())if(u.equals(s)){l=!0;break}if(!l)throw new d8(`${s} is not a child of ${i.cid}`)}let a=await De(t.get(s,o)),c=$a({cid:s,bytes:a,codec:await n(s.code)});i=c,yield c}}};var hh=class r extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=r.name;code=r.code;constructor(e="Bad path"){super(e)}},yo=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not found"){super(e)}},ph=class r extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=r.name;code=r.code;constructor(e="No resolver"){super(e)}},Nt=class r extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=r.name;code=r.code;constructor(e="Not UnixFS"){super(e)}},m8=class r extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=r.name;code=r.code;constructor(e="Over read"){super(e)}},g8=class r extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=r.name;code=r.code;constructor(e="Under read"){super(e)}},Ti=class r extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=r.name;code=r.code;constructor(e="Invalid parameters"){super(e)}};function mh(r){return r==null?!1:Z.asCID(r)===r}function gh(r,e){let t,n=0,o="";for(;n<e.length;){let i=e[n];if(n++,!Object.hasOwnProperty.call(r,i))throw new hh(`Object did not have key "${i}"`);if(o+=`/${i}`,t=r[i],r=t,mh(t))break}return{value:t,rest:e.slice(n),path:o.substring(1)}}async function*SS(r,e,t,n){let o=await De(t.get(r,n)),i=no(o),s=gh(i,e);yield{cid:mh(s.value)?s.value:r,name:s.path,rest:s.rest}}async function*MM(r,e,t,n){let o=await De(t.get(r,n)),i=Ms(o),s=gh(i,e);yield{cid:mh(s.value)?s.value:r,name:s.path,rest:s.rest}}var w8=gt($M(),1);function uZ(r){let e=new Array(4);for(let t=0;t<4;t++)e[t]=r&255,r=r>>8;return new Uint8Array(e)}var AZe=gs({name:"murmur3-32",code:35,encode:r=>uZ(w8.default.x86.hash32(r))}),HM=gs({name:"murmur3-128",code:34,encode:r=>Mc.fromHex(w8.default.x64.hash128(r))}),_Ze=gs({name:"murmur3-x64-64",code:34,encode:r=>Mc.fromHex(w8.default.x64.hash128(r)).subarray(0,8)});var zM=gt(qM(),1);var Pu=class r{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,t,n=0){this._options=e,this._popCount=0,this._parent=t,this._posAtParent=n,this._children=new zM.default,this.key=null}async put(e,t){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,t)}async get(e){let t=await this._findChild(e);if(t!=null)return t.value}async del(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);n!=null&&n.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce((t,n)=>n instanceof r?t+n.leafCount():t+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let t of e)t instanceof r?yield*t.eachLeafSeries():yield t}serialize(e,t){let n=[];return t(this._children.reduce((o,i,s)=>(i!=null&&(i instanceof r?o.push(i.serialize(e,t)):o.push(e(i,s))),o),n))}async asyncTransform(e,t){return jM(this,e,t)}toJSON(){return this.serialize(mZ,gZ)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let t=await this._findPlace(e),n=t.bucket._at(t.pos);if(!(n instanceof r)&&n!=null&&n.key===e)return n}async _findPlace(e){let t=this._options.hash(typeof e=="string"?O(e):e),n=await t.take(this._options.bits),o=this._children.get(n);return o instanceof r?o._findPlace(t):{bucket:this,pos:n,hash:t,existingChild:o}}async _findNewBucketAndPos(e){let t=await this._findPlace(e);if(t.existingChild!=null&&t.existingChild.key!==e){let n=new r(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,n);let o=await n._findPlace(t.existingChild.hash);return o.bucket._putAt(o,t.existingChild.key,t.existingChild.value),n._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,n){this._putObjectAt(e.pos,{key:t,value:n,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)==null&&this._popCount++,this._children.set(e,t)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(pZ);if(e!=null&&!(e instanceof r)){let t=e.hash;t.untake(this._options.bits);let n={pos:this._posAtParent,hash:t,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function pZ(r){return!!r}function mZ(r,e){return r.key}function gZ(r){return r}async function jM(r,e,t){let n=[];for(let o of r._children.compactArray())if(o instanceof Pu)await jM(o,e,t);else{let i=await e(o);n.push({bitField:r._children.bitField(),children:i})}return t(n)}var yZ=[255,254,252,248,240,224,192,128],wZ=[1,3,7,15,31,63,127,255],x8=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let t=e,n=0;for(;t>0&&this._haveBits();){let o=this._value[this._currentBytePos],i=this._currentBitPos+1,s=Math.min(i,t),a=xZ(o,i-s,s);n=(n<<s)+a,t-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function xZ(r,e,t){let n=bZ(e,t);return(r&n)>>>e}function bZ(r,e){return yZ[r]&wZ[Math.min(e+r-1,7)]}function WM(r){function e(t){return t instanceof b8?t:new b8(t,r)}return e}var b8=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits<t;)await this._produceMoreBits();let n=0;for(;t>0;){let o=this._buffers[this._currentBufferIndex],i=Math.min(o.availableBits(),t),s=o.take(i);n=(n<<i)+s,t-=i,this._availableBits-=i,o.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let t=e;for(;t>0;){let n=this._buffers[this._currentBufferIndex],o=Math.min(n.totalBits()-n.availableBits(),t);n.untake(o),t-=o,this._availableBits+=o,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?dt([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),n=new x8(t);this._buffers.push(n),this._availableBits+=n.availableBits()}};function GM(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:r.bits??8,hash:WM(r.hashFn)};return new Pu(e)}var vZ=async function(r){return(await HM.encode(r)).slice(0,8).reverse()},EZ=async(r,e,t)=>{let n=(e.tableSize()-1).toString(16).length;await Promise.all(r.map(async o=>{if(o.Name==null)throw new Error("Unexpected Link without a Name");if(o.Name.length===n){let i=parseInt(o.Name,16);e._putObjectAt(i,new Pu({hash:t._options.hash,bits:t._options.bits},e,i));return}await t.put(o.Name.substring(2),!0)}))},XM=(r,e)=>r.toString(16).toUpperCase().padStart(e,"0").substring(0,e),SZ=r=>{let e=r.bucket,t=[];for(;e._parent!=null;)t.push(e),e=e._parent;return t.push(e),t.reverse()};async function*AS(r,e,t,n,o,i){if(o==null){if(r.Data==null)throw new Nt("No data in PBNode");let h;try{h=nn.unmarshal(r.Data)}catch(m){throw new Nt(m.message)}if(h.type!=="hamt-sharded-directory")throw new Nt("Not a HAMT");if(h.fanout==null)throw new Nt("Missing fanout");let d=GM({hashFn:vZ,bits:Math.log2(Number(h.fanout))});o={rootBucket:d,hamtDepth:1,lastBucket:d}}let s=(o.lastBucket.tableSize()-1).toString(16).length;await EZ(r.Links,o.lastBucket,o.rootBucket);let a=await o.rootBucket._findNewBucketAndPos(e),c=XM(a.pos,s),l=SZ(a);l.length>o.hamtDepth&&(o.lastBucket=l[o.hamtDepth],c=XM(o.lastBucket._posAtParent,s));let u=r.Links.find(h=>{if(h.Name==null)return!1;let d=h.Name.substring(0,s),m=h.Name.substring(s);return!(d!==c||m!==""&&m!==e)});if(u==null)return;if(u.Name!=null&&u.Name.substring(s)===e){yield{cid:u.Hash,name:u.Name.substring(s),rest:t};return}o.hamtDepth++;let f=await De(n.get(u.Hash,i));r=Jr(f),i?.yieldSubShards===!0&&(yield{cid:u.Hash,name:u.Name??"",rest:[e,...t]}),yield*AS(r,e,t,n,o,i)}async function*YM(r,e,t,n){let o=await De(t.get(r,n)),i;try{i=Jr(o)}catch(a){throw new Nt(a.message)}if(i.Data==null)throw new Nt("no data in PBNode");let s;try{s=nn.unmarshal(i.Data)}catch(a){throw new Nt(a.message)}if(s.type==="directory"||s.type==="hamt-sharded-directory"&&n?.translateHamtPath===!1){let a=i.Links.find(c=>c.Name===e[0]);if(a==null)throw new yo(`No link "${e[0]}" found under ${r}`);yield{cid:a.Hash,name:e[0],rest:e.slice(1)}}else if(s.type==="hamt-sharded-directory"){let a=!1;for await(let c of AS(i,e[0],e.slice(1),t,void 0,n))c.name===e[0]&&(a=!0),yield c;if(!a)throw new yo(`No link "${e[0]}" found under ${r}`)}}async function*QM(r,e,t,n){if(e.length!==0)throw new hh(`Cannot load path /${e.join("/")} from identity block`)}async function*ZM(r,e,t,n){let o=await De(t.get(r,n)),i=xa(o),s=gh(i,e);yield{cid:r,name:s.path,rest:s.rest}}async function*JM(r,e,t,n){if(e.length!==0)throw new yo(`Cannot load path /${e.join("/")} from raw block`)}var _Z={[pt]:YM,[ct]:JM,[fr]:SS,81:SS,[dr]:MM,[Ot.code]:QM,[lr]:ZM};async function*Ic(r,e,t={}){for(r=r.toString(),r.startsWith("/ipfs/")&&(r=r.substring(6));r.endsWith("/");)r=r.substring(0,r.length-1);let[n,...o]=r.split(/(?<!\\)\//g).filter(Boolean),i=Z.parse(n),s=[i],a=`${i}`;for(yield{cid:i,name:a,path:a,roots:s,remainder:o};o.length>0;){let c=_Z[i.code];if(c==null)throw new ph(`No resolver for code ${i.code}`);let l=!1;for await(let u of c(i,o,e,t)){if(i=u.cid,l=!s[s.length-1].equals(i),o=u.rest,!l)break;s=[...s,u.cid],a=`${a}/${u.name}`,yield{cid:u.cid,name:u.name,path:a,roots:s,remainder:u.rest}}if(!l)break}if(t?.signal?.throwIfAborted(),o.length!==0)throw new yo(`Could not resolve path /${o.join("/")} under ${r}`)}function TZ(r){return r[Symbol.asyncIterator]!=null}function CZ(r){if(TZ(r))return(async()=>{let t;for await(let n of r)t=n;return t})();let e;for(let t of r)e=t;return e}var yh=CZ;async function _S(r,e,t,n,o){let i=await De(n.get(r,o)),s=no(i);return{type:"object",cid:r,name:e,path:t,object:s,node:i}}async function eU(r,e,t,n,o){let i=await De(n.get(r,o)),s=Ms(i);return{type:"object",cid:r,name:e,path:t,object:s,node:i}}function O0(r,e,t,n){let o=BigInt(r.length),i=BigInt(e+o);return t>=i||n<e?new Uint8Array(0):(n>=e&&n<i&&(r=r.subarray(0,Number(n-e))),t>=e&&t<i&&(r=r.subarray(Number(t-e))),r)}var v8=(r,e=0,t=r)=>{let n=BigInt(r),o=BigInt(e??0),i=BigInt(t);if(i!==n&&(i=o+i),i>n&&(i=n),o<0n)throw new Ti("Offset must be greater than or equal to 0");if(o>n)throw new Ti("Offset must be less than the file size");if(i<0n)throw new Ti("Length must be greater than or equal to 0");if(i>n)throw new Ti("Length must be less than the file size");return{start:o,end:i}};function E8(r,e){async function*t(n={}){let{start:o,end:i}=v8(r.length,n.offset,n.length),s=O0(r,0n,o,i);n.onProgress?.(new Y(e,{bytesRead:BigInt(s.byteLength),totalBytes:i-o,fileSize:BigInt(r.byteLength)})),yield s}return t}async function tU(r,e,t,n,o){let i=ze(r.multihash.bytes);return{type:"identity",cid:r,name:e,path:t,content:E8(i.digest,"unixfs:exporter:progress:identity"),size:BigInt(i.bytes.length),node:i.bytes}}async function rU(r,e,t,n,o){let i=await De(n.get(r,o)),s=xa(i);return{type:"object",cid:r,name:e,path:t,object:s,node:i}}async function nU(r,e,t,n,o){let i=await De(n.get(r,o));return{type:"raw",cid:r,name:e,path:t,content:E8(i,"unixfs:exporter:progress:raw"),size:BigInt(i.length),node:i}}function oU(r,e,t,n){async function*o(i={}){let s=i.offset??0,a=i.length??e.Links.length,c=e.Links.slice(s,a);i.onProgress?.(new Y("unixfs:exporter:walk:directory",{cid:r})),yield*c.map(l=>({cid:l.Hash,name:l.Name??"",path:`${n}/${l.Name??""}`}))}return o}async function iU(r,e,t,n,o,i,s){if(e instanceof Uint8Array){let l=O0(e,n,o,i);t.push(l);return}if(e.Data==null)throw new Nt("no data in PBNode");let a;try{a=nn.unmarshal(e.Data)}catch(l){throw new Nt(l.message)}if(a.data!=null){let l=a.data,u=O0(l,n,o,i);t.push(u),n+=BigInt(u.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new Nt("Inconsistent block sizes and dag links");for(let l=0;l<e.Links.length;l++){let u=e.Links[l],f=n,h=f+a.blockSizes[l];if((o>=f&&o<h||i>=f&&i<=h||o<f&&i>h)&&c.push({link:u,blockStart:n}),n=h,n>i)break}await Xn(c,l=>er(l,u=>async()=>{let f=await De(r.get(u.link.Hash,s));return{...u,block:f}}),l=>ao(l,{ordered:!0,concurrency:s.blockReadConcurrency}),async l=>{for await(let{link:u,block:f,blockStart:h}of l){let d;switch(u.Hash.code){case pt:d=Jr(f);break;case ct:d=f;break;default:t.end(new Nt(`Unsupported codec: ${u.Hash.code}`));return}let m=new Ls({concurrency:1});m.on("error",y=>{t.end(y)}),m.add(async()=>{s.onProgress?.(new Y("unixfs:exporter:walk:file",{cid:u.Hash})),await iU(r,d,t,h,o,i,s)}),await m.onIdle()}}),n>=i&&t.end()}function TS(r,e,t,n,o){async function*i(s={}){let a=t.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:l}=v8(a,s.offset,s.length);if(l===0n)return;let u=0n,f=l-c,h=ur();s.onProgress?.(new Y("unixfs:exporter:walk:file",{cid:r})),iU(o,e,h,0n,c,l,s).catch(d=>{h.end(d)});for await(let d of h)if(d!=null){if(u+=BigInt(d.byteLength),u>f)throw h.end(),new m8("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");u===f&&h.end(),s.onProgress?.(new Y("unixfs:exporter:progress:unixfs:file",{bytesRead:u,totalBytes:f,fileSize:a})),yield d}if(u<f)throw new g8("Traversed entire DAG but did not read enough bytes")}return i}async function*sU(r,e,t,n){let o=r.Links;if(r.Data==null)throw new Nt("no data in PBNode");let i;try{i=nn.unmarshal(r.Data)}catch(c){throw new Nt(c.message)}if(i.fanout==null)throw new Nt("missing fanout");let s=(i.fanout-1n).toString(16).length,a=Xn(o,c=>er(c,l=>async()=>{let u=l.Name!=null?l.Name.substring(s):null;if(u!=null&&u!=="")return{entries:[{cid:l.Hash,name:u,path:`${e}/${u}`}]};{let f=await De(t.get(l.Hash,n));return r=Jr(f),n.onProgress?.(new Y("unixfs:exporter:walk:hamt-sharded-directory",{cid:l.Hash})),{entries:sU(r,e,t,n)}}}),c=>ao(c,{ordered:!0,concurrency:n.blockReadConcurrency}));for await(let{entries:c}of a)yield*c}function aU(r,e,t,n,o){function i(s={}){return s.onProgress?.(new Y("unixfs:exporter:walk:hamt-sharded-directory",{cid:r})),sU(e,n,o,s)}return i}var IZ={raw:TS,file:TS,directory:oU,"hamt-sharded-directory":aU,metadata:(r,e,t,n)=>()=>[],symlink:(r,e,t,n)=>()=>[]};async function cU(r,e,t,n,o){let i=await De(n.get(r,o)),s;try{s=Jr(i)}catch(l){throw new Nt(l.message)}if(s.Data==null)throw new Nt("no data in PBNode");let a;try{a=nn.unmarshal(s.Data)}catch(l){throw new Nt(l.message)}let c=IZ[a.type](r,s,a,t,n);if(c==null)throw new yo("could not find content exporter");return a.isDirectory()?{type:"directory",cid:r,name:e,path:t,entries:c,unixfs:a,node:s}:{type:"file",cid:r,name:e,path:t,content:c,unixfs:a,node:s,size:a.fileSize()}}var kZ={[pt]:cU,[ct]:nU,[fr]:_S,81:_S,[dr]:eU,[Ot.code]:tU,[lr]:rU};async function ls(r,e,t={}){let n,o;if(r instanceof String||typeof r=="string"){let s=await yh(Ic(r,e,t));if(s==null)throw new yo(`Could not walk path to ${r}`);n=s.cid,o=s.name,r=s.path}else if(Z.asCID(r)===r||r instanceof Z)n=r,o=r=n.toString();else throw new Ti("Path must be string or CID");let i=kZ[n.code];if(i==null)throw new ph(`No resolver for code ${n.code}`);return i(n,o,r,e,t)}async function*lU(r,e,t={}){let n=await ls(r,e,t);if(n==null)return;if(yield{cid:n.cid,name:n.name,path:n.path,depth:0},n.type==="directory")for await(let i of o(n,0,`${r}`,t))yield i;async function*o(i,s,a,c){s++;for await(let l of i.entries(c)){let u=`${a}/${l.name}`;yield{...l,depth:s,path:u};let f=await ls(l.cid,e,c);f.type==="directory"&&(yield*o(f,s,u,c))}}}function uU(r){return new l8(r)}var wo="application/vnd.ipld.dag-cbor",xo="application/cbor",bo="application/vnd.ipld.dag-json",vo="application/json",Vr="application/vnd.ipld.raw",Cr="application/octet-stream",Ru="application/vnd.ipfs.ipns-record",Ou="application/vnd.ipld.car",wh="application/x-tar",D0="application/vnd.ipld.dag-pb",S8={mediaType:Cr,codecs:[ct,lr,dr,81,fr,pt],immutable:!0,extension:".bin",etag:"",disposition:"attachment"},PZ={mediaType:wo,codecs:[fr,81,dr,lr,pt,ct],immutable:!0,extension:".cbor",etag:".dag-cbor",disposition:"attachment"},RZ={mediaType:xo,codecs:[81,fr,dr,lr,pt,ct],immutable:!0,extension:".cbor",etag:".cbor",disposition:"attachment"},OZ={mediaType:bo,codecs:[dr,lr,fr,81,pt,ct],immutable:!0,extension:".json",etag:".dag-json",disposition:"inline"},DZ={mediaType:vo,codecs:[lr,dr,fr,81,pt,ct],immutable:!0,extension:".json",etag:".json",disposition:"inline"},fU={mediaType:Vr,codecs:[ct,lr,dr,81,fr,pt],immutable:!0,extension:".raw",etag:".raw",disposition:"attachment"},Du={mediaType:Ru,codecs:[],immutable:!1,extension:".bin",etag:".bin",disposition:"attachment"},CS={mediaType:Ou,codecs:[ct,lr,dr,81,fr,pt],immutable:!1,extension:".car",etag:".car",disposition:"attachment"},NZ={mediaType:wh,codecs:[ct,pt],immutable:!1,extension:".x-tar",etag:".x-tar",disposition:"attachment"},dU=[PZ,RZ,OZ,DZ,fU,Du,CS,NZ,S8];function hU(r){return dU.find(e=>e.mediaType===r)}function N0(r){return r==null?[]:dU.filter(e=>e.codecs.includes(r.code)).sort((e,t)=>{let n=e.codecs.indexOf(r.code),o=t.codecs.indexOf(r.code);return n<o?-1:o<n?1:0})}function pU(r="ipfs:",e){let t=N0(e);return r==="ipfs:"&&t.length===0&&(t=[fU,S8]),r==="ipns:"&&t.push(Du),t}function Fn(r){if(r==null)throw new D("Cannot get filename for Content-Disposition header - filename argument was missing");let e=LZ(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function LZ(r){return r.replace(/[^\x00-\x7F]/g,"_")}var $n=class extends Error{static name="InvalidRangeError";constructor(e="Invalid range request"){super(e),this.name="InvalidRangeError"}};function mU({offset:r,length:e}){return{offset:Number(r),length:Number(e)}}function IS(r,e,t){if(r=BigInt(r),e!=null){if(e=BigInt(e),e<0n)throw new $n("Range start cannot be negative");if(e>=r)throw new $n("Range start cannot be larger than total bytes")}if(t!=null){if(t=BigInt(t),(t>0n?t:-t)>=r)throw new $n("Range end cannot be larger than total bytes");if(t<0n)if(e==null)e=r+t,t=r-1n;else throw new $n("Range end cannot be negative");t+=1n}return mU(yU(r,e,t))}function gU(r,e){r=BigInt(r);let t=(e??"0:*").split(":"),n=BigInt(t[0]),o=t[1]==="*"?r:BigInt(t[1]);return mU(yU(r,n,o))}function yU(r,e=0n,t=r){if(e>=0n)return t>=0n?{offset:e,length:t-e}:{offset:e,length:r-e+t};let n=r+e;return Math.abs(Number(e))>Number(r)&&(n=0n),t>=0n?{offset:n,length:t-n}:{offset:n,length:r-n+t}}function BZ(r){return r instanceof AggregateError||r?.name==="AggregateError"&&Array.isArray(r?.errors)}function L0(r){let e;return BZ(r)&&(e=r.errors.map(t=>L0(t))),{name:r.name,message:r.message,stack:r.stack,errors:e}}function wU({ttl:r,protocol:e,response:t}){if(t.headers.has("cache-control"))return;let n;e==="ipfs:"?n="public, max-age=29030400, immutable":r==null?n="public, max-age=300":n=`public, max-age=${r}`,t.headers.set("cache-control",n)}function kS(r,e,t){e!=null&&(e=BigInt(e)),t!=null&&(t=BigInt(t));let n=BigInt(r);if((t??0n)>=n)throw new $n("Invalid range: Range-end index is greater than or equal to the size of the file.");if((e??0n)>=n)throw new $n("Invalid range: Range-start index is greater than or equal to the size of the file.");let o="*";if(e==null)t!=null&&(t<0n?o=`${n+t}-${n-1n}`:o=`0-${t}`);else if(t==null){let i="*";r!=null&&(i=`${n-1n}`),o=`${e}-${i}`}else o=`${e}-${t}`;return`bytes ${o}/${n}`}function PS(r,e,t){Object.defineProperty(r,e,{enumerable:!0,configurable:!1,set:()=>{},get:()=>t})}function Eo(r,e){r.type!==e&&PS(r,"type",e)}function So(r,e){e=e.toString();let t=e.indexOf("#");t>-1&&(e=e.substring(0,t)),r.url!==e&&PS(r,"url",e)}function xU(r){PS(r,"redirected",!0)}function Ao(r,e,t){let n=new Response(e,{...t??{},status:200,statusText:"OK"});return t?.redirected===!0&&xU(n),Eo(n,"basic"),So(n,r),n}function RS(r,e,t){let n=new Response(JSON.stringify({error:L0(e)}),{...t??{},status:500,statusText:"Internal Server Error"});return n.headers.set("X-Content-Type-Options","nosniff"),n.headers.set("content-type","application/json"),n.headers.set("x-error-message",btoa(e.message)),Eo(n,"basic"),So(n,r),n}function A8(r,e,t){let n=new Response(e,{...t??{},status:504,statusText:"Gateway Timeout"});return Eo(n,"basic"),So(n,r),n}function Nu(r,e,t){let n=new Response(e,{...t??{},status:502,statusText:"Bad Gateway"});return Eo(n,"basic"),So(n,r),n}function OS(r,e,t){let n=new Response(e,{...t??{},status:501,statusText:"Not Implemented"});return n.headers.set("X-Content-Type-Options","nosniff"),Eo(n,"basic"),So(n,r),n}function Pc(r,e,t,n){let o=new Headers(n?.headers);o.set("content-type","application/json");let i=new Response(JSON.stringify({requested:e.map(s=>s.mediaType),acceptable:t.map(s=>s.mediaType)}),{...n??{},status:406,statusText:"Not Acceptable",headers:o});return Eo(i,"basic"),So(i,r),i}function DS(r,e,t){let n=new Response(e,{...t??{},status:404,statusText:"Not Found"});return Eo(n,"basic"),So(n,r),n}function MZ(r){return Array.isArray(r)&&r.every(e=>e instanceof Error)}function Go(r,e,t){let n,o;MZ(e)?(n=e[e.length-1].stack,o=e.map(a=>({message:a.message,stack:a.stack??""}))):e instanceof Error&&(n=e.stack,o=[{message:e.message,stack:e.stack??""}]);let i=JSON.stringify({stack:n,errors:o}),s=new Response(i,{status:400,statusText:"Bad Request",...t??{},headers:{...t?.headers??{},"Content-Type":"application/json"}});return Eo(s,"basic"),So(s,r),s}function bU(r,e,t){let n=new Response(null,{...t??{},status:301,statusText:"Moved Permanently",headers:{...t?.headers??{},location:e}});return Eo(n,"basic"),So(n,r),n}function NS(r,e,t){let n=new Response(null,{...t??{},status:304,statusText:"Not Modified"});return["cache-control","content-location","date","etag","expires","vary"].forEach(i=>{let s=e.get(i);s!=null&&n.headers.set(i,s)}),Eo(n,"basic"),So(n,r),n}function xh(r,e,t,n,o){let i;if(t.ranges.length===1)i=UZ(r,e,t.ranges[0],n,o);else if(t.ranges.length>1)i=FZ(r,e,t,n,o);else return _8(r,n);return o?.redirected===!0&&xU(i),Eo(i,"basic"),So(i,r),i}function UZ(r,e,t,n,o){try{let i=new Headers(o?.headers),{offset:s,length:a}=IS(n,t.start,t.end);i.set("content-length",`${a}`),i.set("content-range",kS(n,t.start,t.end));let c=Fo(e(s,a));return new Response(c,{...o??{},status:206,statusText:"Partial Content",headers:i})}catch(i){return i.name==="InvalidRangeError"?_8(r,n,o):RS(r,i,o)}}function FZ(r,e,t,n,o){let i=new Headers(o?.headers),s=i.get("content-type");if(s==null)throw new Error("Content-Type header must be set");i.delete("content-type");let a=0n,c=t.ranges.map(({start:f,end:h})=>{let d=O([`--${t.multipartBoundary}`,`Content-Type: ${s}`,`Content-Range: ${kS(n,f,h)}`,"",""].join(`\r
|
|
111
111
|
`));return a+=BigInt(d.byteLength)+(BigInt(h??n)-BigInt(f??0)),d}),l=O([`--${t.multipartBoundary}--`,""].join(`\r
|
|
112
112
|
`));a+=BigInt(l.byteLength),i.set("content-length",`${a}`),i.set("content-type",`multipart/byteranges; boundary=${t.multipartBoundary}`);let u=Fo((async function*(){for(let f=0;f<c.length;f++){yield c[f];let{offset:h,length:d}=IS(n,t.ranges[f].start,t.ranges[f].end);yield*e(h,d),yield O(`\r
|
|
113
|
-
`)}yield l})());return new Response(u,{...o??{},status:206,statusText:"Partial Content",headers:i})}function _8(r,e,t){let n=new Headers(t?.headers);e!=null&&n.set("content-range",`bytes */${e}`);let o=new Response("Range Not Satisfiable",{...t,headers:n,status:416,statusText:"Range Not Satisfiable"});return Eo(o,"basic"),So(o,r),o}function vU(r,e){let t=new Headers(e?.headers),n=new Response("Precondition Failed",{...e,headers:t,status:412,statusText:"Precondition Failed"});return Eo(n,"basic"),So(n,r),n}var on=class{pluginOptions;_log;get log(){return this._log==null&&(this._log=this.pluginOptions.logger.newScope(this.id)),this._log}constructor(e){this.pluginOptions=e}};function $Z(r){return`${r.replace(/\/ipfs\//,"").replace(/\/ipns\//,"").replace(/\/+$/g,"").replace(/\//g,"_")}.car`}function HZ({url:r}){let e=r.searchParams.get("dag-scope");return e==="all"||e==="entity"||e==="block"?e:r.searchParams.has("entity-bytes")?"entity":"all"}var T8=class extends on{id="car-plugin";canHandle({accept:e}){return e.some(t=>t.contentType.mediaType===Ou)}async handle(e){let{options:t,url:n,accept:o,resource:i,blockstore:s,range:a,ipfsRoots:c,terminalElement:l,requestedMimeTypes:u}=e;if(a!=null)return Go(i,new Error("Range requests are not supported for CAR files"));let f=o.filter(I=>I.contentType.mediaType===Ou).pop();if(f==null)return Go(i,new Error("Could not find CAR media type in accept header"));let h=f.options.order==="dfs"?"dfs":"unk",d=f.options.dups!=="n";if(f.options.version==="2"||n.searchParams.get("car-version")==="2")return Pc(i,u,[CS]);let m=this.pluginOptions.helia,y=
|
|
113
|
+
`)}yield l})());return new Response(u,{...o??{},status:206,statusText:"Partial Content",headers:i})}function _8(r,e,t){let n=new Headers(t?.headers);e!=null&&n.set("content-range",`bytes */${e}`);let o=new Response("Range Not Satisfiable",{...t,headers:n,status:416,statusText:"Range Not Satisfiable"});return Eo(o,"basic"),So(o,r),o}function vU(r,e){let t=new Headers(e?.headers),n=new Response("Precondition Failed",{...e,headers:t,status:412,statusText:"Precondition Failed"});return Eo(n,"basic"),So(n,r),n}var on=class{pluginOptions;_log;get log(){return this._log==null&&(this._log=this.pluginOptions.logger.newScope(this.id)),this._log}constructor(e){this.pluginOptions=e}};function $Z(r){return`${r.replace(/\/ipfs\//,"").replace(/\/ipns\//,"").replace(/\/+$/g,"").replace(/\//g,"_")}.car`}function HZ({url:r}){let e=r.searchParams.get("dag-scope");return e==="all"||e==="entity"||e==="block"?e:r.searchParams.has("entity-bytes")?"entity":"all"}var T8=class extends on{id="car-plugin";canHandle({accept:e}){return e.some(t=>t.contentType.mediaType===Ou)}async handle(e){let{options:t,url:n,accept:o,resource:i,blockstore:s,range:a,ipfsRoots:c,terminalElement:l,requestedMimeTypes:u}=e;if(a!=null)return Go(i,new Error("Range requests are not supported for CAR files"));let f=o.filter(I=>I.contentType.mediaType===Ou).pop();if(f==null)return Go(i,new Error("Could not find CAR media type in accept header"));let h=f.options.order==="dfs"?"dfs":"unk",d=f.options.dups!=="n";if(f.options.version==="2"||n.searchParams.get("car-version")==="2")return Pc(i,u,[CS]);let m=this.pluginOptions.helia,y=uU({blockstore:s,getCodec:m.getCodec,logger:m.logger}),w={...t,includeTraversalBlocks:!0};d||(w.blockFilter=vr(1024)),c.length>1&&(w.traversal=new p8(c));let x=HZ(e),v=l.cid;if(x==="block")w.exporter=new I0;else if(x==="entity")if(v.code===pt){let I={listingOnly:!0},U=await ls(l.cid,s,e.options);if(U.type==="file"){let K=gU(U.size,n.searchParams.get("entity-bytes"));I.offset=K.offset,I.length=K.length}w.exporter=new dh(I)}else w.exporter=new I0;else w.exporter=new fh({walker:h==="dfs"?zf():uy()});let E=Fo(y.export(v,w));return Ao(i,E,{headers:{"content-type":`${Ou}; version=1; order=${h}; dups=${d?"y":"n"}`,"content-disposition":`attachment; ${Fn(n.searchParams.get("filename")??$Z(`/ipfs/${n.hostname}${n.pathname}`))}`,"x-content-type-options":"nosniff","accept-ranges":"none"}})}};var KZ={[fr]:{[vo]:r=>No(no(r)),[bo]:r=>No(no(r)),[wo]:r=>r,[xo]:r=>r,[Vr]:r=>r,[Cr]:r=>r},81:{[vo]:r=>No(no(r)),[bo]:r=>No(no(r)),[wo]:r=>r,[xo]:r=>r,[Vr]:r=>r,[Cr]:r=>r},[dr]:{[xo]:r=>gn(Ms(r)),[wo]:r=>gn(Ms(r)),[bo]:r=>r,[vo]:r=>r,[Vr]:r=>r,[Cr]:r=>r},[lr]:{[xo]:r=>gn(xa(r)),[wo]:r=>gn(xa(r)),[bo]:r=>r,[vo]:r=>r,[Vr]:r=>r,[Cr]:r=>r},[pt]:{[xo]:r=>gn(Jr(r)),[wo]:r=>gn(Jr(r)),[vo]:r=>No(Jr(r)),[bo]:r=>No(Jr(r)),[Vr]:r=>r,[Cr]:r=>r},[ct]:{[xo]:r=>gn(r),[wo]:r=>gn(r),[vo]:r=>r,[bo]:r=>No(r),[Vr]:r=>r,[Cr]:r=>r},[Ot.code]:{[xo]:r=>gn(r),[wo]:r=>gn(r),[vo]:r=>No(r),[bo]:r=>No(r),[Vr]:r=>r,[Cr]:r=>r}};function EU(r,e,t){if(t.length===0)return{contentType:N0(r)[0],output:e};for(let n of t){let o=KZ[r.code]?.[n.contentType.mediaType];if(o!=null)return{contentType:n.contentType,output:o(e)}}throw new Error(`Could not convert ${r} to any of ${t.map(n=>n.contentType.mediaType).join(", ")}`)}var C8=class extends on{id="ipld-plugin";codes=[81,fr,dr,lr,ct,pt,Ot.code];canHandle({terminalElement:e,accept:t}){let n=this.codes.includes(e.cid.code),o=t.length===0||t.some(i=>i.contentType.mediaType===xo||i.contentType.mediaType===wo||i.contentType.mediaType===vo||i.contentType.mediaType===bo);return n&&o}async handle(e){let{url:t,resource:n,accept:o,ipfsRoots:i,terminalElement:s,blockstore:a,options:c,requestedMimeTypes:l}=e;this.log.trace("fetching %c%s",s.cid,t.pathname);let u=await De(a.get(s.cid,c)),f;try{let d=EU(s.cid,u,o);u=d.output,f=d.contentType}catch(d){return this.log.error("could not decode object from block - %e",d),Pc(n,l,N0(s.cid))}let h={"content-length":`${u.byteLength}`,"content-type":f.mediaType,"content-disposition":`${t.searchParams.get("download")==="true"?"attachment":f.disposition}; ${Fn(t.searchParams.get("filename")??`${s.cid}${f.extension}`)}`,"x-ipfs-roots":i.map(d=>d.toV1()).join(","),"x-content-type-options":"nosniff","accept-ranges":"bytes"};return e.range!=null?xh(n,async function*(d,m){yield u.subarray(d,d+m)},e.range,u.byteLength,{headers:h}):Ao(n,u,{headers:h})}};var I8=class extends on{id="ipns-record-plugin";codes=[];canHandle({accept:e}){return e.some(t=>t.contentType.mediaType===Ru)}async handle(e){let{resource:t,url:n,options:o,range:i}=e,{ipnsResolver:s}=this.pluginOptions;if(n.pathname!==""&&n.pathname!=="/"||n.protocol!=="ipns:")return this.log.error('invalid request for IPNS name "%s" and path "%s"',n,n.pathname),Go(t,new Error("Invalid IPNS name"));if(i!=null)return Go(t,new Error("Range requests are not supported for IPNS records"));let a;try{this.log.trace('trying to parse peer id from "%s"',n.hostname),a=je(n.hostname)}catch(u){return this.log.error("could not parse peer id from IPNS url %s",t,u),Go(t,u)}let c=await s.resolve(a,o),l=Al(c.record);return Ao(t,l,{headers:{"content-length":`${l.byteLength}`,"content-type":Du.mediaType,"content-disposition":`attachment; ${Fn(n.searchParams.get("filename")??`${a}${Du.extension}`)}`,"x-ipfs-roots":c.cid.toV1().toString(),"cache-control":`public, max-age=${Number((c.record.ttl??0n)/BigInt(1e9))}`,"accept-ranges":"none"}})}};var k8=class extends on{id="raw-plugin";canHandle({accept:e}){return e.length===0||e.some(n=>n.contentType.mediaType===Vr||n.contentType.mediaType===Cr)}async handle(e){let{url:t,resource:n,accept:o,ipfsRoots:i,terminalElement:s,blockstore:a,options:c}=e;this.log.trace("fetching %c%s",s.cid,t.pathname);let l=await De(a.get(s.cid,c)),u={"content-length":`${l.byteLength}`,"content-type":o.some(f=>f.contentType.mediaType===Vr)?Vr:Cr,"content-disposition":`${t.searchParams.get("download")==="false"?"inline":"attachment"}; ${Fn(t.searchParams.get("filename")??`${s.cid}.raw`)}`,"x-ipfs-roots":i.map(f=>f.toV1()).join(","),"x-content-type-options":"nosniff","accept-ranges":"bytes"};return e.range!=null?xh(n,async function*(f,h){yield l.subarray(f,f+h)},e.range,l.byteLength,{headers:u}):Ao(n,l,{headers:u})}};var P8=class extends Error{name;code;constructor(e,t,n){super(e),this.name=t,this.code=n}},Lu=class extends P8{constructor(e="not a Unixfs node"){super(e,"NotUnixFSError","ERR_NOT_UNIXFS")}};var R8=class extends P8{constructor(e="path does not exist"){super(e,"DoesNotExistError","ERR_DOES_NOT_EXIST")}};var Mtt=O("ustar\0","binary"),Utt=O("ustar ","binary"),Ftt=O(" \0","binary");var TU=gt(AU(),1);var qZ="0000000000000000000",zZ="7777777777777777777",jZ=48,WZ=O("ustar\0","binary"),GZ=O("00","binary"),XZ=parseInt("7777",8),YZ=257,QZ=263,ZZ=function(r){switch(r){case"file":return 0;case"link":return 1;case"symlink":return 2;case"character-device":return 3;case"block-device":return 4;case"directory":return 5;case"fifo":return 6;case"contiguous-file":return 7;case"pax-header":return 72;default:return 0}},JZ=function(r){let e=256;for(let t=0;t<148;t++)e+=r[t];for(let t=156;t<512;t++)e+=r[t];return e},Rc=function(r,e){let t=r.toString(8);return t.length>e?O(zZ.slice(0,e)+" "):O(qZ.slice(0,e-t.length)+t+" ")},LS=function(r){let e=O(r).byteLength,t=Math.floor(Math.log(e)/Math.log(10))+1;return e+t>=Math.pow(10,t)&&t++,`${e+t}${r}`};function _U(r){let e="";r.name!=null&&(e+=LS(" path="+r.name+`
|
|
114
114
|
`)),r.linkname!=null&&(e+=LS(" linkpath="+r.linkname+`
|
|
115
115
|
`));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=LS(" "+n+"="+t[n]+`
|
|
116
|
-
`));return O(e)}function O8(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),O(t).byteLength!==t.length)return null;for(;O(t).byteLength>100;){let o=t.indexOf("/");if(o===-1)return null;n+=n!==""?"/"+t.slice(0,o):t.slice(0,o),t=t.slice(o+1)}return O(t).byteLength>100||O(n).byteLength>155||r.linkname!=null&&O(r.linkname).byteLength>100?null:(e.set(O(t),0),e.set(Rc(r.mode&XZ,6),100),e.set(Rc(r.uid,6),108),e.set(Rc(r.gid,6),116),e.set(Rc(r.size,11),124),e.set(Rc(r.mtime.getTime()/1e3|0,11),136),e[156]=jZ+ZZ(r.type),r.linkname!=null&&e.set(O(r.linkname),157),e.set(WZ,YZ),e.set(GZ,QZ),r.uname!=null&&e.set(O(r.uname),265),r.gname!=null&&e.set(O(r.gname),297),e.set(Rc(r.devmajor??0,6),329),e.set(Rc(r.devminor??0,6),337),n!=null&&e.set(O(n),345),e.set(Rc(JZ(e),6),148),e)}var{S_IFMT:tJ,S_IFBLK:rJ,S_IFCHR:nJ,S_IFDIR:oJ,S_IFIFO:iJ,S_IFLNK:sJ}=TU.default,aJ=parseInt("755",8),cJ=parseInt("644",8),CU=new Uint8Array(1024);function lJ(r=0){switch(r&tJ){case rJ:return"block-device";case nJ:return"character-device";case oJ:return"directory";case iJ:return"fifo";case sJ:return"symlink";default:return"file"}}function MS(r){return r&=511,r!==0?CU.subarray(0,512-r):new Uint8Array(0)}function BS(r){if(r.pax==null){let e=O8(r);if(e!=null)return e}return uJ(r)}function uJ(r){let e=_U(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new se(O8(t)??new Uint8Array(0),e,MS(e.length),O8({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function D8(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??lJ(e.mode),mode:e.mode??(e.type==="directory"?aJ:cJ),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=O(t)),t instanceof Uint8Array||To(t)){n.size=t.length,yield BS(n),yield To(t)?t.subarray():t,yield MS(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=H(await De(t)),yield BS(n);continue}if(yield BS(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let o=0;for await(let i of t??[])o+=i.length,yield To(i)?i.subarray():i;if(o!==n.size)throw new Error(`size mismatch, wrote ${o} of ${n.size} bytes`);yield MS(n.size)}yield CU}}var fJ=["file","raw","directory"];function dJ(r,e){let t,n,o=0n;return(r.type==="file"||r.type==="raw"||r.type==="identity")&&(o=r.size),(r.type==="file"||r.type==="directory")&&(t=r.unixfs.mode,n=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:e,mode:t,mtime:n,size:Number(o),type:r.type==="directory"?"directory":"file"}}function IU(r,e){if(!fJ.includes(r.type))throw new Lu(`${r.type} is not a UnixFS node`);let t={header:dJ(r,e)};return(r.type==="file"||r.type==="raw")&&(t.body=r.content()),t}async function*kU(r,e,t){let n=await hh(Ic(r,e,t));if(n==null)throw new D(`Could not walk path "${r}"`);let o=await ls(n.cid,e,t);if(o.type==="file"||o.type==="raw"){yield*Xn([IU(o,n.path)],D8());return}if(o.type==="directory"){yield*Xn(uU(o.cid,e,t),i=>er(i,async s=>{let a=await ls(s.cid,e,t);return IU(a,s.path)}),D8());return}throw new Lu("Not a UnixFS node")}var N8=class extends on{id="tar-plugin";codes=[];canHandle({accept:e}){return e.some(t=>t.contentType.mediaType===wh)}async handle(e){let{terminalElement:t,url:n,resource:o,options:i,blockstore:s,range:a}=e;if(t.cid.code!==pt&&t.cid.code!==ct)return Go(o,new Lu("Only UnixFS data can be returned in a TAR file"));if(a!=null)return Go(o,new Error("Range requests are not supported for TAR files"));let c=Fo(kU(`/ipfs/${t.cid}${n.pathname}`,s,i));return Ao(o,c,{headers:{"content-type":wh,"content-disposition":`attachment; ${Fn(n.searchParams.get("filename")??`${t.cid.toString()}.tar`)}`,"accept-ranges":"none"}})}};function hJ(r,e){let t;try{t=new URL(r.toString())}catch{t=e}if(!t.pathname.endsWith("/"))return t.pathname+="/",t.toString()}var L8=class extends on{id="unixfs-plugin";codes=[pt,ct];canHandle({terminalElement:e,accept:t}){let n=this.codes.includes(e.cid.code),o=t.length===0||t.some(i=>i.contentType.mediaType===Cr||i.contentType.mediaType===D0);return n&&o}async handle(e){let{url:t,resource:n,terminalElement:o,ipfsRoots:i,blockstore:s}=e,a=t.searchParams.get("filename")??o.name,c,l;try{l=await ls(o.cid,s,e.options)}catch(u){if(e?.options?.signal?.throwIfAborted(),u.name==="BlockNotFoundWhileOfflineError")throw u;return this.log.error("could not export %c - $e",o.cid,u),Nu(n,"Unable to stream content")}if(l.type==="directory"){let u=hJ(n,t);if(u!=null){if(this.log.trace("directory url normalization spec requires redirect"),e.options?.redirect==="error")throw this.log('could not redirect to %s as redirect option was set to "error"',u),new TypeError("Failed to fetch");if(e.options?.redirect==="manual")return this.log("returning 301 permanent redirect to %s",u),bU(e.resource,u);this.log("following redirect to %s",u),n=u,c=!0}let f=o.cid;if(e.options?.supportDirectoryIndexes!==!1){let d="index.html";try{this.log.trace("found directory at %c%s, looking for index.html",f,t.pathname);let m=await e.serverTiming.time("exporter-dir","",hh(Ic(`/ipfs/${f}/${d}`,e.blockstore,e.options)));if(m==null)return Nu(n,"Unable to stream content");let y=await e.serverTiming.time("exporter-dir","",ls(m.cid,e.blockstore,e.options));return y.type!=="file"&&y.type!=="raw"&&y.type!=="identity"?Nu(n,"Unable to stream content"):(a=d,this.log.trace("found directory index at %c%s with cid %c",f,d,l.cid),await this.streamFile(n,y,a,i,c,e.range,e.options))}catch(m){if(m.name!=="NotFoundError")throw this.log.error("error loading path %c/%s - %e",f,d,m),m}}let h=await De(e.blockstore.get(f,e.options));return Ao(n,h,{headers:{"content-type":D0,"content-length":`${h.byteLength}`,"content-disposition":`${t.searchParams.get("download")==="true"?"attachment":"inline"}; ${Fn(`${f}.dir`)}`,"x-ipfs-roots":i.map(d=>d.toV1()).join(","),"accept-ranges":"bytes"},redirected:c})}else return l.type==="file"||l.type==="raw"||l.type==="identity"?(this.log("streaming file"),this.streamFile(n,l,a,i,c,e.range,e.options)):(this.log.error("cannot stream terminal element type %s",l.type),Nu(n,"Unable to stream content"))}async streamFile(e,t,n,o,i,s,a){let c=Cr;return s==null&&(c=await this.detectContentType(t,n,a)),s!=null?xh(e,(l,u)=>t.content({...a??{},offset:l,length:u}),s,t.size,{headers:{"content-type":c,"content-disposition":`inline; ${Fn(n)}`,"x-ipfs-roots":o.map(l=>l.toV1()).join(","),"accept-ranges":"bytes"},redirected:i}):Ao(e,Fo(t.content(a)),{headers:{"content-type":c,"content-length":`${t.size}`,"content-disposition":`inline; ${Fn(n)}`,"x-ipfs-roots":o.map(l=>l.toV1()).join(","),"accept-ranges":"bytes"},redirected:i})}async detectContentType(e,t,n){let o;if(e.type==="raw"||e.type==="identity"?o=e.node:o=await Ny(e.content(n)),o==null)throw new Error("stream ended before first block was read");let i;if(this.pluginOptions.contentTypeParser!=null)try{let s=this.pluginOptions.contentTypeParser(o,t);if(Ef(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s);this.log.trace("contentTypeParser returned %s for file with name %s",i,t)}catch(s){this.log.error("error parsing content type - %e",s)}return i??Cr}};var B0=class extends Map{#t=0;#e=new Map;#r=new Map;#o;#s;#a;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=e.maxSize,this.#s=e.maxAge||Number.POSITIVE_INFINITY,this.#a=e.onEviction}get __oldCache(){return this.#r}#l(e){if(typeof this.#a=="function")for(let[t,n]of e)this.#a(t,n.value)}#n(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#a=="function"&&this.#a(e,t.value),this.delete(e)):!1}#m(e,t){if(this.#n(e,t)===!1)return t.value}#h(e,t){return t.expiry?this.#m(e,t):t.value}#p(e,t){let n=t.get(e);return this.#h(e,n)}#u(e,t){this.#e.set(e,t),this.#t++,this.#t>=this.#o&&(this.#t=0,this.#l(this.#r),this.#r=this.#e,this.#e=new Map)}#f(e,t){this.#r.delete(e),this.#u(e,t)}*#i(){for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield e)}for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#h(e,t)}if(this.#r.has(e)){let t=this.#r.get(e);if(this.#n(e,t)===!1)return this.#f(e,t),t.value}}set(e,t,{maxAge:n=this.#s}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#u(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#n(e,this.#e.get(e)):this.#r.has(e)?!this.#n(e,this.#r.get(e)):!1}peek(e){if(this.#e.has(e))return this.#p(e,this.#e);if(this.#r.has(e))return this.#p(e,this.#r)}expiresIn(e){let t=this.#e.get(e)??this.#r.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){let t=this.#e.delete(e);return t&&this.#t--,this.#r.delete(e)||t}clear(){this.#e.clear(),this.#r.clear(),this.#t=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#i()],n=t.length-e;n<0?(this.#e=new Map(t),this.#r=new Map,this.#t=t.length):(n>0&&this.#l(t.slice(0,n)),this.#r=new Map(t.slice(n)),this.#e=new Map,this.#t=0),this.#o=e}evict(e=1){let t=Number(e);if(!t||t<=0)return;let n=[...this.#i()],o=Math.trunc(Math.min(t,Math.max(n.length-1,0)));o<=0||(this.#l(n.slice(0,o)),this.#r=new Map(n.slice(o)),this.#e=new Map,this.#t=0)}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield[t,n.value])}for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield[t,n.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#n(o,i)===!1&&(yield[o,i.value])}e=[...this.#r];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#e.has(o)||this.#n(o,i)===!1&&(yield[o,i.value])}}*entriesAscending(){for(let[e,t]of this.#i())yield[e,t.value]}get size(){if(!this.#t)return this.#r.size;let e=0;for(let t of this.#r.keys())this.#e.has(t)||e++;return Math.min(this.#t+e,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#s}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[n,o]of this.entriesAscending())e.call(t,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var bh=class{headers;constructor(){this.headers=[]}getHeader(){return this.headers.join(",")}async time(e,t,n){let o=performance.now();try{return await n}finally{let s=(performance.now()-o).toFixed(1);this.headers.push(`${e};dur=${s};desc="${t}"`)}}};var pJ=29030400;function mJ(r){return{cid:r,name:r.toString(),path:r.toString(),roots:[r],remainder:[]}}var B8=class{components;blockstoreSessions;constructor(e,t={}){this.components=e,this.blockstoreSessions=new B0({maxSize:t.sessionCacheSize??100,maxAge:t.sessionTTLms??6e4,onEviction:(n,o)=>{o.close()}})}async resolve(e,t=new bh,n={}){if(e.protocol==="ipfs:")return this.resolveIPFSPath(e,t,n);if(e.protocol==="ipns:")return this.resolveIPNSName(e,t,n);if(e.protocol==="dnslink:")return this.resolveDNSLink(e,t,n);throw new Ti(`Invalid resource. Unsupported protocol in URL, must be ipfs:, ipns:, or dnslink: ${e}`)}getBlockstore(e,t={}){if(t.session===!1)return this.components.helia.blockstore;let n=`ipfs:${e}`,o=this.blockstoreSessions.get(n);return o==null&&(o=this.components.helia.blockstore.createSession(e,t),this.blockstoreSessions.set(n,o)),o}async resolveDNSLink(e,t,n){let i=(await t.time("dnsLink.resolve",`Resolve DNSLink ${e.hostname}`,this.components.dnsLink.resolve(e.hostname,n)))?.[0];if(i==null)throw new TypeError(`Invalid resource. Cannot resolve DNSLink from domain: ${e.hostname}`);if(i.namespace==="ipns")return this.resolveIPNSName(e,t,n);if(i.namespace!=="ipfs")throw new TypeError(`Invalid resource. Unexpected DNSLink namespace ${i.namespace} from domain: ${domain}`);i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`);return{...await this.resolveIPFSPath(s,t,n),url:e,ttl:i.answer.TTL}}async resolveIPNSName(e,t,n){let o=je(e.hostname),i=await t.time("ipns.resolve",`Resolve IPNS name ${o}`,this.components.ipnsResolver.resolve(o,n));i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`);return{...await this.resolveIPFSPath(s,t,n),url:e,ttl:Number((i.record.ttl??0n)/BigInt(1e9))}}async resolveIPFSPath(e,t,n){let o=await t.time("ipfs.resolve","",this.walkPath(e,n));return{...o,url:e,ttl:pJ,blockstore:o.blockstore}}async walkPath(e,t={}){let n=Z.parse(e.hostname),o=this.getBlockstore(n,t);try{let i=[],s,a=gJ(e);for await(let c of Ic(a,o,{...t,yieldSubShards:!0}))i.push(c.cid),s=c;if(s==null)throw new R8("No terminal element found");return{ipfsRoots:i,terminalElement:s,blockstore:o}}catch(i){if(i.name==="NoResolverError")return{ipfsRoots:[n],terminalElement:mJ(n),blockstore:o};throw i}}};function gJ(r){return`/ipfs/${r.hostname}${decodeURI(r.pathname)}`}var DU=gt(PU(),1);var RU={128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"},yJ={};for(let[r,e]of Object.entries(RU))yJ[e]=Number.parseInt(r,10);var M8;function wJ(){if(!(typeof globalThis.TextDecoder>"u"))return M8??(M8=new globalThis.TextDecoder("utf-8"))}var Bu=32*1024;function OU(r,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":{let t=wJ();return t?t.decode(r):xJ(r)}case"utf-16le":return bJ(r);case"us-ascii":case"ascii":return vJ(r);case"latin1":case"iso-8859-1":return EJ(r);case"windows-1252":return SJ(r);default:throw new RangeError(`Encoding '${e}' not supported`)}}function xJ(r){let e=[],t="",n=0;for(;n<r.length;){let o=r[n++];if(o<128)t+=String.fromCharCode(o);else if(o<224){let i=r[n++]&63;t+=String.fromCharCode((o&31)<<6|i)}else if(o<240){let i=r[n++]&63,s=r[n++]&63;t+=String.fromCharCode((o&15)<<12|i<<6|s)}else{let i=r[n++]&63,s=r[n++]&63,a=r[n++]&63,c=(o&7)<<18|i<<12|s<<6|a;c-=65536,t+=String.fromCharCode(55296+(c>>10&1023),56320+(c&1023))}t.length>=Bu&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function bJ(r){let e=r.length&-2;if(e===0)return"";let t=[],n=Bu;for(let o=0;o<e;){let i=Math.min(n,e-o>>1),s=new Array(i);for(let a=0;a<i;a++,o+=2)s[a]=r[o]|r[o+1]<<8;t.push(String.fromCharCode.apply(null,s))}return t.join("")}function vJ(r){let e=[];for(let t=0;t<r.length;t+=Bu){let n=Math.min(r.length,t+Bu),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i]&127;e.push(String.fromCharCode.apply(null,o))}return e.join("")}function EJ(r){let e=[];for(let t=0;t<r.length;t+=Bu){let n=Math.min(r.length,t+Bu),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i];e.push(String.fromCharCode.apply(null,o))}return e.join("")}function SJ(r){let e=[],t="";for(let n=0;n<r.length;n++){let o=r[n],i=o>=128&&o<=159?RU[o]:void 0;t+=i??String.fromCharCode(o),t.length>=Bu&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function Hn(r){return new DataView(r.buffer,r.byteOffset)}var NU={len:1,get(r,e){return Hn(r).getUint8(e)},put(r,e,t){return Hn(r).setUint8(e,t),e+1}},$t={len:2,get(r,e){return Hn(r).getUint16(e,!0)},put(r,e,t){return Hn(r).setUint16(e,t,!0),e+2}},Mu={len:2,get(r,e){return Hn(r).getUint16(e)},put(r,e,t){return Hn(r).setUint16(e,t),e+2}};var Yt={len:4,get(r,e){return Hn(r).getUint32(e,!0)},put(r,e,t){return Hn(r).setUint32(e,t,!0),e+4}},FS={len:4,get(r,e){return Hn(r).getUint32(e)},put(r,e,t){return Hn(r).setUint32(e,t),e+4}};var LU={len:4,get(r,e){return Hn(r).getInt32(e)},put(r,e,t){return Hn(r).setInt32(e,t),e+4}};var BU={len:8,get(r,e){return Hn(r).getBigUint64(e,!0)},put(r,e,t){return Hn(r).setBigUint64(e,t,!0),e+8}};var Kn=class{constructor(e,t){this.len=e,this.encoding=t}get(e,t=0){let n=e.subarray(t,t+this.len);return OU(n,this.encoding)}};var _J="End-Of-Stream",kt=class extends Error{constructor(){super(_J),this.name="EndOfStreamError"}},Uu=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Fu=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,t=!1){let n=await this.read(e,t);return this.peekQueue.push(e.subarray(0,n)),n}async read(e,t=!1){if(e.length===0)return 0;let n=this.readFromPeekBuffer(e);if(this.endOfStream||(n+=await this.readRemainderFromStream(e.subarray(n),t)),n===0&&!t)throw new kt;return n}readFromPeekBuffer(e){let t=e.length,n=0;for(;this.peekQueue.length>0&&t>0;){let o=this.peekQueue.pop();if(!o)throw new Error("peekData should be defined");let i=Math.min(o.length,t);e.set(o.subarray(0,i),n),n+=i,t-=i,i<o.length&&this.peekQueue.push(o.subarray(i))}return n}async readRemainderFromStream(e,t){let n=0;for(;n<e.length&&!this.endOfStream;){if(this.interrupted)throw new Uu;let o=await this.readFromStream(e.subarray(n),t);if(o===0)break;n+=o}if(!t&&n<e.length)throw new kt;return n}};var U8=class extends Fu{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}};var M0=class extends U8{async readFromStream(e,t){if(e.length===0)return 0;let n=await this.reader.read(new Uint8Array(e.length),{min:t?void 0:e.length});return n.done&&(this.endOfStream=n.done),n.value?(e.set(n.value),n.value.length):0}};var vh=class extends Fu{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,t){let n=Math.min(t.length,e.length);return e.set(t.subarray(0,n)),n<t.length?this.buffer=t.subarray(n):this.buffer=null,n}async readFromStream(e,t){if(e.length===0)return 0;let n=0;for(this.buffer&&(n+=this.writeChunk(e,this.buffer));n<e.length&&!this.endOfStream;){let o=await this.reader.read();if(o.done){this.endOfStream=!0;break}o.value&&(n+=this.writeChunk(e.subarray(n),o.value))}if(!t&&n===0&&this.endOfStream)throw new kt;return n}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}};function $S(r){try{let e=r.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new vh(e):new M0(e)}catch(e){if(e instanceof TypeError)return new vh(r.getReader());throw e}}var da=class{constructor(e){this.numBuffer=new Uint8Array(8),this.position=0,this.onClose=e?.onClose,e?.abortSignal&&e.abortSignal.addEventListener("abort",()=>{this.abort()})}async readToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.readBuffer(n,{position:t})<e.len)throw new kt;return e.get(n,0)}async peekToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.peekBuffer(n,{position:t})<e.len)throw new kt;return e.get(n,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new kt;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new kt;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let t=this.fileInfo.size-this.position;if(e>t)return this.position+=t,t}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,t){if(!this.supportsRandomAccess()&&t&&t.position!==void 0&&t.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");return{mayBeLess:!1,offset:0,length:e.length,position:this.position,...t}}abort(){return Promise.resolve()}};var CJ=256e3,F8=class extends da{constructor(e,t){super(t),this.streamReader=e,this.fileInfo=t?.fileInfo??{}}async readBuffer(e,t){let n=this.normalizeOptions(e,t),o=n.position-this.position;if(o>0)return await this.ignore(o),this.readBuffer(e,t);if(o<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(n.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,n.length),n.mayBeLess);if(this.position+=i,(!t||!t.mayBeLess)&&i<n.length)throw new kt;return i}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=0;if(n.position){let i=n.position-this.position;if(i>0){let s=new Uint8Array(n.length+i);return o=await this.peekBuffer(s,{mayBeLess:n.mayBeLess}),e.set(s.subarray(i)),o-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(n.length>0){try{o=await this.streamReader.peek(e.subarray(0,n.length),n.mayBeLess)}catch(i){if(t?.mayBeLess&&i instanceof kt)return 0;throw i}if(!n.mayBeLess&&o<n.length)throw new kt}return o}async ignore(e){let t=Math.min(CJ,e),n=new Uint8Array(t),o=0;for(;o<e;){let i=e-o,s=await this.readBuffer(n,{length:Math.min(t,i)});if(s<0)return s;o+=s}return o}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}};var $8=class extends da{constructor(e,t){super(t),this.uint8Array=e,this.fileInfo={...t?.fileInfo??{},size:e.length}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.uint8Array.length-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new kt;return e.set(this.uint8Array.subarray(n.position,n.position+o)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};var H8=class extends da{constructor(e,t){super(t),this.blob=e,this.fileInfo={...t?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.blob.size-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new kt;let i=await this.blob.slice(n.position,n.position+o).arrayBuffer();return e.set(new Uint8Array(i)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};function MU(r,e){let t=$S(r),n=e??{},o=n.onClose;return n.onClose=async()=>{if(await t.close(),o)return o()},new F8(t,n)}function UU(r,e){return new $8(r,e)}function FU(r,e){return new H8(r,e)}var GU=gt(qU(),1);var Hu={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},HS={get(r){return{signature:Yt.get(r,0),compressedSize:Yt.get(r,8),uncompressedSize:Yt.get(r,12)}},len:16},zU={get(r){let e=$t.get(r,6);return{signature:Yt.get(r,0),minVersion:$t.get(r,4),dataDescriptor:!!(e&8),compressedMethod:$t.get(r,8),compressedSize:Yt.get(r,18),uncompressedSize:Yt.get(r,22),filenameLength:$t.get(r,26),extraFieldLength:$t.get(r,28),filename:null}},len:30},jU={get(r){return{signature:Yt.get(r,0),nrOfThisDisk:$t.get(r,4),nrOfThisDiskWithTheStart:$t.get(r,6),nrOfEntriesOnThisDisk:$t.get(r,8),nrOfEntriesOfSize:$t.get(r,10),sizeOfCd:Yt.get(r,12),offsetOfStartOfCd:Yt.get(r,16),zipFileCommentLength:$t.get(r,20)}},len:22},WU={get(r){let e=$t.get(r,8);return{signature:Yt.get(r,0),minVersion:$t.get(r,6),dataDescriptor:!!(e&8),compressedMethod:$t.get(r,10),compressedSize:Yt.get(r,20),uncompressedSize:Yt.get(r,24),filenameLength:$t.get(r,28),extraFieldLength:$t.get(r,30),fileCommentLength:$t.get(r,32),relativeOffsetOfLocalHeader:Yt.get(r,42),filename:null}},len:46};function XU(r){let e=new Uint8Array(Yt.len);return Yt.put(e,0,r),e}var us=(0,GU.default)("tokenizer:inflate"),KS=256*1024,HJ=XU(Hu.DataDescriptor),q8=XU(Hu.EndOfCentralDirectory),U0=class r{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(KS)}async isZip(){return await this.peekSignature()===Hu.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(Yt)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,t=Math.min(16*1024,e.fileInfo.size),n=this.syncBuffer.subarray(0,t);await this.tokenizer.readBuffer(n,{position:e.fileInfo.size-t});for(let o=n.length-4;o>=0;o--)if(n[o]===q8[0]&&n[o+1]===q8[1]&&n[o+2]===q8[2]&&n[o+3]===q8[3])return e.fileInfo.size-t+o;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){us("Cannot reading central-directory without random-read support");return}us("Reading central-directory...");let e=this.tokenizer.position,t=await this.findEndOfCentralDirectoryLocator();if(t>0){us("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(jU,t),o=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let s=await this.tokenizer.readToken(WU);if(s.signature!==Hu.CentralFileHeader)throw new Error("Expected Central-File-Header signature");s.filename=await this.tokenizer.readToken(new Kn(s.filenameLength,"utf-8")),await this.tokenizer.ignore(s.extraFieldLength),await this.tokenizer.ignore(s.fileCommentLength),o.push(s),us(`Add central-directory file-entry: n=${i+1}/${o.length}: filename=${o[i].filename}`)}return this.tokenizer.setPosition(e),o}this.tokenizer.setPosition(e)}async unzip(e){let t=await this.readCentralDirectory();if(t)return this.iterateOverCentralDirectory(t,e);let n=!1;do{let o=await this.readLocalFileHeader();if(!o)break;let i=e(o);n=!!i.stop;let s;if(await this.tokenizer.ignore(o.extraFieldLength),o.dataDescriptor&&o.compressedSize===0){let a=[],c=KS;us("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let l=-1;for(;l<0&&c===KS;){c=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),l=KJ(this.syncBuffer.subarray(0,c),HJ);let u=l>=0?l:c;if(i.handler){let f=new Uint8Array(u);await this.tokenizer.readBuffer(f),a.push(f)}else await this.tokenizer.ignore(u)}us(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(o,VJ(a),i.handler)}else i.handler?(us(`Reading compressed-file-data: ${o.compressedSize} bytes`),s=new Uint8Array(o.compressedSize),await this.tokenizer.readBuffer(s),await this.inflate(o,s,i.handler)):(us(`Ignoring compressed-file-data: ${o.compressedSize} bytes`),await this.tokenizer.ignore(o.compressedSize));if(us(`Reading data-descriptor at pos=${this.tokenizer.position}`),o.dataDescriptor&&(await this.tokenizer.readToken(HS)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-HS.len}`)}while(!n)}async iterateOverCentralDirectory(e,t){for(let n of e){let o=t(n);if(o.handler){this.tokenizer.setPosition(n.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let s=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(s),await this.inflate(i,s,o.handler)}}if(o.stop)break}}async inflate(e,t,n){if(e.compressedMethod===0)return n(t);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);us(`Decompress filename=${e.filename}, compressed-size=${t.length}`);let o=await r.decompressDeflateRaw(t);return n(o)}static async decompressDeflateRaw(e){let t=new ReadableStream({start(i){i.enqueue(e),i.close()}}),n=new DecompressionStream("deflate-raw"),o=t.pipeThrough(n);try{let s=await new Response(o).arrayBuffer();return new Uint8Array(s)}catch(i){let s=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(s)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(Yt);if(e===Hu.LocalFileHeader){let t=await this.tokenizer.readToken(zU);return t.filename=await this.tokenizer.readToken(new Kn(t.filenameLength,"utf-8")),t}if(e===Hu.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}};function KJ(r,e){let t=r.length,n=e.length;if(n>t)return-1;for(let o=0;o<=t-n;o++){let i=!0;for(let s=0;s<n;s++)if(r[o+s]!==e[s]){i=!1;break}if(i)return o}return-1}function VJ(r){let e=r.reduce((o,i)=>o+i.length,0),t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var F0=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(t){let n=new Uint8Array(1024),o=await e.readBuffer(n,{mayBeLess:!0});if(o===0){t.close();return}t.enqueue(n.subarray(0,o))}}).pipeThrough(new DecompressionStream("gzip"))}};var Znt={utf8:new globalThis.TextDecoder("utf8")};var Jnt=new globalThis.TextEncoder;var eot=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function VS(r){let{byteLength:e}=r;if(e===6)return r.getUint16(0)*2**32+r.getUint32(2);if(e===5)return r.getUint8(0)*2**32+r.getUint32(1);if(e===4)return r.getUint32(0);if(e===3)return r.getUint8(0)*2**16+r.getUint16(1);if(e===2)return r.getUint16(0);if(e===1)return r.getUint8(0)}function YU(r,e){if(e==="utf-16le"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o&255,o>>8&255)}return t}if(e==="utf-16be"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o>>8&255,o&255)}return t}return[...r].map(t=>t.charCodeAt(0))}function QU(r,e=0){let t=Number.parseInt(new Kn(6).get(r,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(t))return!1;let n=256;for(let o=e;o<e+148;o++)n+=r[o];for(let o=e+156;o<e+512;o++)n+=r[o];return t===n}var ZU={get:(r,e)=>r[e+3]&127|r[e+2]<<7|r[e+1]<<14|r[e]<<21,len:4};var JU=["jpg","png","apng","gif","webp","flif","xcf","cr2","cr3","orf","arw","dng","nef","rw2","raf","tif","bmp","icns","jxr","psd","indd","zip","tar","rar","gz","bz2","7z","dmg","mp4","mid","mkv","webm","mov","avi","mpg","mp2","mp3","m4a","oga","ogg","ogv","opus","flac","wav","spx","amr","pdf","epub","elf","macho","exe","swf","rtf","wasm","woff","woff2","eot","ttf","otf","ttc","ico","flv","ps","xz","sqlite","nes","crx","xpi","cab","deb","ar","rpm","Z","lz","cfb","mxf","mts","blend","bpg","docx","pptx","xlsx","3gp","3g2","j2c","jp2","jpm","jpx","mj2","aif","qcp","odt","ods","odp","xml","mobi","heic","cur","ktx","ape","wv","dcm","ics","glb","pcap","dsf","lnk","alias","voc","ac3","m4v","m4p","m4b","f4v","f4p","f4b","f4a","mie","asf","ogm","ogx","mpc","arrow","shp","aac","mp1","it","s3m","xm","skp","avif","eps","lzh","pgp","asar","stl","chm","3mf","zst","jxl","vcf","jls","pst","dwg","parquet","class","arj","cpio","ace","avro","icc","fbx","vsdx","vtt","apk","drc","lz4","potx","xltx","dotx","xltm","ott","ots","otp","odg","otg","xlsm","docm","dotm","potm","pptm","jar","jmp","rm","sav","ppsm","ppsx","tar.gz","reg","dat"],eF=["image/jpeg","image/png","image/gif","image/webp","image/flif","image/x-xcf","image/x-canon-cr2","image/x-canon-cr3","image/tiff","image/bmp","image/vnd.ms-photo","image/vnd.adobe.photoshop","application/x-indesign","application/epub+zip","application/x-xpinstall","application/vnd.ms-powerpoint.slideshow.macroenabled.12","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.slideshow","application/zip","application/x-tar","application/x-rar-compressed","application/gzip","application/x-bzip2","application/x-7z-compressed","application/x-apple-diskimage","application/vnd.apache.arrow.file","video/mp4","audio/midi","video/matroska","video/webm","video/quicktime","video/vnd.avi","audio/wav","audio/qcelp","audio/x-ms-asf","video/x-ms-asf","application/vnd.ms-asf","video/mpeg","video/3gpp","audio/mpeg","audio/mp4","video/ogg","audio/ogg","audio/ogg; codecs=opus","application/ogg","audio/flac","audio/ape","audio/wavpack","audio/amr","application/pdf","application/x-elf","application/x-mach-binary","application/x-msdownload","application/x-shockwave-flash","application/rtf","application/wasm","font/woff","font/woff2","application/vnd.ms-fontobject","font/ttf","font/otf","font/collection","image/x-icon","video/x-flv","application/postscript","application/eps","application/x-xz","application/x-sqlite3","application/x-nintendo-nes-rom","application/x-google-chrome-extension","application/vnd.ms-cab-compressed","application/x-deb","application/x-unix-archive","application/x-rpm","application/x-compress","application/x-lzip","application/x-cfb","application/x-mie","application/mxf","video/mp2t","application/x-blender","image/bpg","image/j2c","image/jp2","image/jpx","image/jpm","image/mj2","audio/aiff","application/xml","application/x-mobipocket-ebook","image/heif","image/heif-sequence","image/heic","image/heic-sequence","image/icns","image/ktx","application/dicom","audio/x-musepack","text/calendar","text/vcard","text/vtt","model/gltf-binary","application/vnd.tcpdump.pcap","audio/x-dsf","application/x.ms.shortcut","application/x.apple.alias","audio/x-voc","audio/vnd.dolby.dd-raw","audio/x-m4a","image/apng","image/x-olympus-orf","image/x-sony-arw","image/x-adobe-dng","image/x-nikon-nef","image/x-panasonic-rw2","image/x-fujifilm-raf","video/x-m4v","video/3gpp2","application/x-esri-shape","audio/aac","audio/x-it","audio/x-s3m","audio/x-xm","video/MP1S","video/MP2P","application/vnd.sketchup.skp","image/avif","application/x-lzh-compressed","application/pgp-encrypted","application/x-asar","model/stl","application/vnd.ms-htmlhelp","model/3mf","image/jxl","application/zstd","image/jls","application/vnd.ms-outlook","image/vnd.dwg","application/vnd.apache.parquet","application/java-vm","application/x-arj","application/x-cpio","application/x-ace-compressed","application/avro","application/vnd.iccprofile","application/x.autodesk.fbx","application/vnd.visio","application/vnd.android.package-archive","application/vnd.google.draco","application/x-lz4","application/vnd.openxmlformats-officedocument.presentationml.template","application/vnd.openxmlformats-officedocument.spreadsheetml.template","application/vnd.openxmlformats-officedocument.wordprocessingml.template","application/vnd.ms-excel.template.macroenabled.12","application/vnd.oasis.opendocument.text-template","application/vnd.oasis.opendocument.spreadsheet-template","application/vnd.oasis.opendocument.presentation-template","application/vnd.oasis.opendocument.graphics","application/vnd.oasis.opendocument.graphics-template","application/vnd.ms-excel.sheet.macroenabled.12","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-word.template.macroenabled.12","application/vnd.ms-powerpoint.template.macroenabled.12","application/vnd.ms-powerpoint.presentation.macroenabled.12","application/java-archive","application/vnd.rn-realmedia","application/x-spss-sav","application/x-ms-regedit","application/x-ft-windows-registry-hive","application/x-jmp-data"];var qS=4100;async function tF(r,e){return new jS(e).fromBuffer(r)}function zS(r){switch(r=r.toLowerCase(),r){case"application/epub+zip":return{ext:"epub",mime:r};case"application/vnd.oasis.opendocument.text":return{ext:"odt",mime:r};case"application/vnd.oasis.opendocument.text-template":return{ext:"ott",mime:r};case"application/vnd.oasis.opendocument.spreadsheet":return{ext:"ods",mime:r};case"application/vnd.oasis.opendocument.spreadsheet-template":return{ext:"ots",mime:r};case"application/vnd.oasis.opendocument.presentation":return{ext:"odp",mime:r};case"application/vnd.oasis.opendocument.presentation-template":return{ext:"otp",mime:r};case"application/vnd.oasis.opendocument.graphics":return{ext:"odg",mime:r};case"application/vnd.oasis.opendocument.graphics-template":return{ext:"otg",mime:r};case"application/vnd.openxmlformats-officedocument.presentationml.slideshow":return{ext:"ppsx",mime:r};case"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return{ext:"xlsx",mime:r};case"application/vnd.ms-excel.sheet.macroenabled":return{ext:"xlsm",mime:"application/vnd.ms-excel.sheet.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.spreadsheetml.template":return{ext:"xltx",mime:r};case"application/vnd.ms-excel.template.macroenabled":return{ext:"xltm",mime:"application/vnd.ms-excel.template.macroenabled.12"};case"application/vnd.ms-powerpoint.slideshow.macroenabled":return{ext:"ppsm",mime:"application/vnd.ms-powerpoint.slideshow.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return{ext:"docx",mime:r};case"application/vnd.ms-word.document.macroenabled":return{ext:"docm",mime:"application/vnd.ms-word.document.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.template":return{ext:"dotx",mime:r};case"application/vnd.ms-word.template.macroenabledtemplate":return{ext:"dotm",mime:"application/vnd.ms-word.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.template":return{ext:"potx",mime:r};case"application/vnd.ms-powerpoint.template.macroenabled":return{ext:"potm",mime:"application/vnd.ms-powerpoint.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.presentation":return{ext:"pptx",mime:r};case"application/vnd.ms-powerpoint.presentation.macroenabled":return{ext:"pptm",mime:"application/vnd.ms-powerpoint.presentation.macroenabled.12"};case"application/vnd.ms-visio.drawing":return{ext:"vsdx",mime:"application/vnd.visio"};case"application/vnd.ms-package.3dmanufacturing-3dmodel+xml":return{ext:"3mf",mime:"model/3mf"};default:}}function fs(r,e,t){t={offset:0,...t};for(let[n,o]of e.entries())if(t.mask){if(o!==(t.mask[n]&r[n+t.offset]))return!1}else if(o!==r[n+t.offset])return!1;return!0}var jS=class{constructor(e){this.options={mpegOffsetTolerance:0,...e},this.detectors=[...e?.customDetectors??[],{id:"core",detect:this.detectConfident},{id:"core.imprecise",detect:this.detectImprecise}],this.tokenizerOptions={abortSignal:e?.signal}}async fromTokenizer(e){let t=e.position;for(let n of this.detectors){let o=await n.detect(e);if(o)return o;if(t!==e.position)return}}async fromBuffer(e){if(!(e instanceof Uint8Array||e instanceof ArrayBuffer))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof e}\``);let t=e instanceof Uint8Array?e:new Uint8Array(e);if(t?.length>1)return this.fromTokenizer(UU(t,this.tokenizerOptions))}async fromBlob(e){let t=FU(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async fromStream(e){let t=MU(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async toDetectionStream(e,t){let{sampleSize:n=qS}=t,o,i,s=e.getReader({mode:"byob"});try{let{value:l,done:u}=await s.read(new Uint8Array(n));if(i=l,!u&&l)try{o=await this.fromBuffer(l.subarray(0,n))}catch(f){if(!(f instanceof kt))throw f;o=void 0}i=l}finally{s.releaseLock()}let a=new TransformStream({async start(l){l.enqueue(i)},transform(l,u){u.enqueue(l)}}),c=e.pipeThrough(a);return c.fileType=o,c}check(e,t){return fs(this.buffer,e,t)}checkString(e,t){return this.check(YU(e,t?.encoding),t)}detectConfident=async e=>{if(this.buffer=new Uint8Array(qS),e.fileInfo.size===void 0&&(e.fileInfo.size=Number.MAX_SAFE_INTEGER),this.tokenizer=e,await e.peekBuffer(this.buffer,{length:32,mayBeLess:!0}),this.check([66,77]))return{ext:"bmp",mime:"image/bmp"};if(this.check([11,119]))return{ext:"ac3",mime:"audio/vnd.dolby.dd-raw"};if(this.check([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(this.check([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if(this.check([37,33]))return await e.peekBuffer(this.buffer,{length:24,mayBeLess:!0}),this.checkString("PS-Adobe-",{offset:2})&&this.checkString(" EPSF-",{offset:14})?{ext:"eps",mime:"application/eps"}:{ext:"ps",mime:"application/postscript"};if(this.check([31,160])||this.check([31,157]))return{ext:"Z",mime:"application/x-compress"};if(this.check([199,113]))return{ext:"cpio",mime:"application/x-cpio"};if(this.check([96,234]))return{ext:"arj",mime:"application/x-arj"};if(this.check([239,187,191]))return this.tokenizer.ignore(3),this.detectConfident(e);if(this.check([71,73,70]))return{ext:"gif",mime:"image/gif"};if(this.check([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(this.check([31,139,8])){let n=new F0(e).inflate(),o=!0;try{let i;try{i=await this.fromStream(n)}catch{o=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{o&&await n.cancel()}return{ext:"gz",mime:"application/gzip"}}if(this.check([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(this.checkString("ID3")){await e.ignore(6);let t=await e.readToken(ZU);return e.position+t>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(t),this.fromTokenizer(e))}if(this.checkString("MP+"))return{ext:"mpc",mime:"audio/x-musepack"};if((this.buffer[0]===67||this.buffer[0]===70)&&this.check([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(this.check([255,216,255]))return this.check([247],{offset:3})?{ext:"jls",mime:"image/jls"}:{ext:"jpg",mime:"image/jpeg"};if(this.check([79,98,106,1]))return{ext:"avro",mime:"application/avro"};if(this.checkString("FLIF"))return{ext:"flif",mime:"image/flif"};if(this.checkString("8BPS"))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(this.checkString("MPCK"))return{ext:"mpc",mime:"audio/x-musepack"};if(this.checkString("FORM"))return{ext:"aif",mime:"audio/aiff"};if(this.checkString("icns",{offset:0}))return{ext:"icns",mime:"image/icns"};if(this.check([80,75,3,4])){let t;return await new U0(e).unzip(n=>{switch(n.filename){case"META-INF/mozilla.rsa":return t={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return t={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(o){let i=new TextDecoder("utf-8").decode(o).trim();t=zS(i)},stop:!0};case"[Content_Types].xml":return{async handler(o){let i=new TextDecoder("utf-8").decode(o),s=i.indexOf('.main+xml"');if(s===-1){let a="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${a}"`)&&(t=zS(a))}else{i=i.slice(0,Math.max(0,s));let a=i.lastIndexOf('"'),c=i.slice(Math.max(0,a+1));t=zS(c)}},stop:!0};default:return/classes\d*\.dex/.test(n.filename)?(t={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(n=>{if(!(n instanceof kt))throw n}),t??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let t=new Uint8Array(8);return await e.readBuffer(t),fs(t,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:fs(t,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:fs(t,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:fs(t,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:fs(t,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:fs(t,[1,118,111,114,98,105,115])?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"}}if(this.check([80,75])&&(this.buffer[2]===3||this.buffer[2]===5||this.buffer[2]===7)&&(this.buffer[3]===4||this.buffer[3]===6||this.buffer[3]===8))return{ext:"zip",mime:"application/zip"};if(this.checkString("MThd"))return{ext:"mid",mime:"audio/midi"};if(this.checkString("wOFF")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff",mime:"font/woff"};if(this.checkString("wOF2")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(this.check([212,195,178,161])||this.check([161,178,195,212]))return{ext:"pcap",mime:"application/vnd.tcpdump.pcap"};if(this.checkString("DSD "))return{ext:"dsf",mime:"audio/x-dsf"};if(this.checkString("LZIP"))return{ext:"lz",mime:"application/x-lzip"};if(this.checkString("fLaC"))return{ext:"flac",mime:"audio/flac"};if(this.check([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(this.checkString("wvpk"))return{ext:"wv",mime:"audio/wavpack"};if(this.checkString("%PDF"))return{ext:"pdf",mime:"application/pdf"};if(this.check([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(this.check([73,73])){let t=await this.readTiffHeader(!1);if(t)return t}if(this.check([77,77])){let t=await this.readTiffHeader(!0);if(t)return t}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function t(){let a=await e.peekNumber(NU),c=128,l=0;for(;(a&c)===0&&c!==0;)++l,c>>=1;let u=new Uint8Array(l+1);return await e.readBuffer(u),u}async function n(){let a=await t(),c=await t();c[0]^=128>>c.length-1;let l=Math.min(6,c.length),u=new DataView(a.buffer),f=new DataView(c.buffer,c.length-l,l);return{id:VS(u),len:VS(f)}}async function o(a){for(;a>0;){let c=await n();if(c.id===17026)return(await e.readToken(new Kn(c.len))).replaceAll(/\00.*$/g,"");await e.ignore(c.len),--a}}let i=await n();switch(await o(i.len)){case"webm":return{ext:"webm",mime:"video/webm"};case"matroska":return{ext:"mkv",mime:"video/matroska"};default:return}}if(this.checkString("SQLi"))return{ext:"sqlite",mime:"application/x-sqlite3"};if(this.check([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(this.checkString("Cr24"))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(this.checkString("MSCF")||this.checkString("ISc("))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(this.check([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(this.check([197,208,211,198]))return{ext:"eps",mime:"application/eps"};if(this.check([40,181,47,253]))return{ext:"zst",mime:"application/zstd"};if(this.check([127,69,76,70]))return{ext:"elf",mime:"application/x-elf"};if(this.check([33,66,68,78]))return{ext:"pst",mime:"application/vnd.ms-outlook"};if(this.checkString("PAR1")||this.checkString("PARE"))return{ext:"parquet",mime:"application/vnd.apache.parquet"};if(this.checkString("ttcf"))return{ext:"ttc",mime:"font/collection"};if(this.check([254,237,250,206])||this.check([254,237,250,207])||this.check([206,250,237,254])||this.check([207,250,237,254]))return{ext:"macho",mime:"application/x-mach-binary"};if(this.check([4,34,77,24]))return{ext:"lz4",mime:"application/x-lz4"};if(this.checkString("regf"))return{ext:"dat",mime:"application/x-ft-windows-registry-hive"};if(this.checkString("$FL2")||this.checkString("$FL3"))return{ext:"sav",mime:"application/x-spss-sav"};if(this.check([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(this.checkString("#!AMR"))return{ext:"amr",mime:"audio/amr"};if(this.checkString("{\\rtf"))return{ext:"rtf",mime:"application/rtf"};if(this.check([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(this.checkString("IMPM"))return{ext:"it",mime:"audio/x-it"};if(this.checkString("-lh0-",{offset:2})||this.checkString("-lh1-",{offset:2})||this.checkString("-lh2-",{offset:2})||this.checkString("-lh3-",{offset:2})||this.checkString("-lh4-",{offset:2})||this.checkString("-lh5-",{offset:2})||this.checkString("-lh6-",{offset:2})||this.checkString("-lh7-",{offset:2})||this.checkString("-lzs-",{offset:2})||this.checkString("-lz4-",{offset:2})||this.checkString("-lz5-",{offset:2})||this.checkString("-lhd-",{offset:2}))return{ext:"lzh",mime:"application/x-lzh-compressed"};if(this.check([0,0,1,186])){if(this.check([33],{offset:4,mask:[241]}))return{ext:"mpg",mime:"video/MP1S"};if(this.check([68],{offset:4,mask:[196]}))return{ext:"mpg",mime:"video/MP2P"}}if(this.checkString("ITSF"))return{ext:"chm",mime:"application/vnd.ms-htmlhelp"};if(this.check([202,254,186,190])){let t=FS.get(this.buffer,4),n=Mu.get(this.buffer,6);if(t>0&&t<=30)return{ext:"macho",mime:"application/x-mach-binary"};if(n>30)return{ext:"class",mime:"application/java-vm"}}if(this.checkString(".RMF"))return{ext:"rm",mime:"application/vnd.rn-realmedia"};if(this.checkString("DRACO"))return{ext:"drc",mime:"application/vnd.google.draco"};if(this.check([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(this.checkString("<?xml "))return{ext:"xml",mime:"application/xml"};if(this.check([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(this.check([82,97,114,33,26,7])&&(this.buffer[6]===0||this.buffer[6]===1))return{ext:"rar",mime:"application/x-rar-compressed"};if(this.checkString("solid "))return{ext:"stl",mime:"model/stl"};if(this.checkString("AC")){let t=new Kn(4,"latin1").get(this.buffer,2);if(t.match("^d*")&&t>=1e3&&t<=1050)return{ext:"dwg",mime:"image/vnd.dwg"}}if(this.checkString("070707"))return{ext:"cpio",mime:"application/x-cpio"};if(this.checkString("BLENDER"))return{ext:"blend",mime:"application/x-blender"};if(this.checkString("!<arch>"))return await e.ignore(8),await e.readToken(new Kn(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
116
|
+
`));return O(e)}function O8(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),O(t).byteLength!==t.length)return null;for(;O(t).byteLength>100;){let o=t.indexOf("/");if(o===-1)return null;n+=n!==""?"/"+t.slice(0,o):t.slice(0,o),t=t.slice(o+1)}return O(t).byteLength>100||O(n).byteLength>155||r.linkname!=null&&O(r.linkname).byteLength>100?null:(e.set(O(t),0),e.set(Rc(r.mode&XZ,6),100),e.set(Rc(r.uid,6),108),e.set(Rc(r.gid,6),116),e.set(Rc(r.size,11),124),e.set(Rc(r.mtime.getTime()/1e3|0,11),136),e[156]=jZ+ZZ(r.type),r.linkname!=null&&e.set(O(r.linkname),157),e.set(WZ,YZ),e.set(GZ,QZ),r.uname!=null&&e.set(O(r.uname),265),r.gname!=null&&e.set(O(r.gname),297),e.set(Rc(r.devmajor??0,6),329),e.set(Rc(r.devminor??0,6),337),n!=null&&e.set(O(n),345),e.set(Rc(JZ(e),6),148),e)}var{S_IFMT:tJ,S_IFBLK:rJ,S_IFCHR:nJ,S_IFDIR:oJ,S_IFIFO:iJ,S_IFLNK:sJ}=TU.default,aJ=parseInt("755",8),cJ=parseInt("644",8),CU=new Uint8Array(1024);function lJ(r=0){switch(r&tJ){case rJ:return"block-device";case nJ:return"character-device";case oJ:return"directory";case iJ:return"fifo";case sJ:return"symlink";default:return"file"}}function MS(r){return r&=511,r!==0?CU.subarray(0,512-r):new Uint8Array(0)}function BS(r){if(r.pax==null){let e=O8(r);if(e!=null)return e}return uJ(r)}function uJ(r){let e=_U(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new se(O8(t)??new Uint8Array(0),e,MS(e.length),O8({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function D8(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??lJ(e.mode),mode:e.mode??(e.type==="directory"?aJ:cJ),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=O(t)),t instanceof Uint8Array||To(t)){n.size=t.length,yield BS(n),yield To(t)?t.subarray():t,yield MS(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=H(await De(t)),yield BS(n);continue}if(yield BS(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let o=0;for await(let i of t??[])o+=i.length,yield To(i)?i.subarray():i;if(o!==n.size)throw new Error(`size mismatch, wrote ${o} of ${n.size} bytes`);yield MS(n.size)}yield CU}}var fJ=["file","raw","directory"];function dJ(r,e){let t,n,o=0n;return(r.type==="file"||r.type==="raw"||r.type==="identity")&&(o=r.size),(r.type==="file"||r.type==="directory")&&(t=r.unixfs.mode,n=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:e,mode:t,mtime:n,size:Number(o),type:r.type==="directory"?"directory":"file"}}function IU(r,e){if(!fJ.includes(r.type))throw new Lu(`${r.type} is not a UnixFS node`);let t={header:dJ(r,e)};return(r.type==="file"||r.type==="raw")&&(t.body=r.content()),t}async function*kU(r,e,t){let n=await yh(Ic(r,e,t));if(n==null)throw new D(`Could not walk path "${r}"`);let o=await ls(n.cid,e,t);if(o.type==="file"||o.type==="raw"){yield*Xn([IU(o,n.path)],D8());return}if(o.type==="directory"){yield*Xn(lU(o.cid,e,t),i=>er(i,async s=>{let a=await ls(s.cid,e,t);return IU(a,s.path)}),D8());return}throw new Lu("Not a UnixFS node")}var N8=class extends on{id="tar-plugin";codes=[];canHandle({accept:e}){return e.some(t=>t.contentType.mediaType===wh)}async handle(e){let{terminalElement:t,url:n,resource:o,options:i,blockstore:s,range:a}=e;if(t.cid.code!==pt&&t.cid.code!==ct)return Go(o,new Lu("Only UnixFS data can be returned in a TAR file"));if(a!=null)return Go(o,new Error("Range requests are not supported for TAR files"));let c=Fo(kU(`/ipfs/${t.cid}${n.pathname}`,s,i));return Ao(o,c,{headers:{"content-type":wh,"content-disposition":`attachment; ${Fn(n.searchParams.get("filename")??`${t.cid.toString()}.tar`)}`,"accept-ranges":"none"}})}};function hJ(r,e){let t;try{t=new URL(r.toString())}catch{t=e}if(!t.pathname.endsWith("/"))return t.pathname+="/",t.toString()}var L8=class extends on{id="unixfs-plugin";codes=[pt,ct];canHandle({terminalElement:e,accept:t}){let n=this.codes.includes(e.cid.code),o=t.length===0||t.some(i=>i.contentType.mediaType===Cr||i.contentType.mediaType===D0);return n&&o}async handle(e){let{url:t,resource:n,terminalElement:o,ipfsRoots:i,blockstore:s}=e,a=t.searchParams.get("filename")??o.name,c,l;try{l=await ls(o.cid,s,e.options)}catch(u){if(e?.options?.signal?.throwIfAborted(),u.name==="BlockNotFoundWhileOfflineError")throw u;return this.log.error("could not export %c - $e",o.cid,u),Nu(n,"Unable to stream content")}if(l.type==="directory"){let u=hJ(n,t);if(u!=null){if(this.log.trace("directory url normalization spec requires redirect"),e.options?.redirect==="error")throw this.log('could not redirect to %s as redirect option was set to "error"',u),new TypeError("Failed to fetch");if(e.options?.redirect==="manual")return this.log("returning 301 permanent redirect to %s",u),bU(e.resource,u);this.log("following redirect to %s",u),n=u,c=!0}let f=o.cid;if(e.options?.supportDirectoryIndexes!==!1){let d="index.html";try{this.log.trace("found directory at %c%s, looking for index.html",f,t.pathname);let m=await e.serverTiming.time("exporter-dir","",yh(Ic(`/ipfs/${f}/${d}`,e.blockstore,e.options)));if(m==null)return Nu(n,"Unable to stream content");let y=await e.serverTiming.time("exporter-dir","",ls(m.cid,e.blockstore,e.options));return y.type!=="file"&&y.type!=="raw"&&y.type!=="identity"?Nu(n,"Unable to stream content"):(a=d,this.log.trace("found directory index at %c%s with cid %c",f,d,l.cid),await this.streamFile(n,y,a,i,c,e.range,e.options))}catch(m){if(m.name!=="NotFoundError")throw this.log.error("error loading path %c/%s - %e",f,d,m),m}}let h=await De(e.blockstore.get(f,e.options));return Ao(n,h,{headers:{"content-type":D0,"content-length":`${h.byteLength}`,"content-disposition":`${t.searchParams.get("download")==="true"?"attachment":"inline"}; ${Fn(`${f}.dir`)}`,"x-ipfs-roots":i.map(d=>d.toV1()).join(","),"accept-ranges":"bytes"},redirected:c})}else return l.type==="file"||l.type==="raw"||l.type==="identity"?(this.log("streaming file"),this.streamFile(n,l,a,i,c,e.range,e.options)):(this.log.error("cannot stream terminal element type %s",l.type),Nu(n,"Unable to stream content"))}async streamFile(e,t,n,o,i,s,a){let c=Cr;return s==null&&(c=await this.detectContentType(t,n,a)),s!=null?xh(e,(l,u)=>t.content({...a??{},offset:l,length:u}),s,t.size,{headers:{"content-type":c,"content-disposition":`inline; ${Fn(n)}`,"x-ipfs-roots":o.map(l=>l.toV1()).join(","),"accept-ranges":"bytes"},redirected:i}):Ao(e,Fo(t.content(a)),{headers:{"content-type":c,"content-length":`${t.size}`,"content-disposition":`inline; ${Fn(n)}`,"x-ipfs-roots":o.map(l=>l.toV1()).join(","),"accept-ranges":"bytes"},redirected:i})}async detectContentType(e,t,n){let o;if(e.type==="raw"||e.type==="identity"?o=e.node:o=await Ny(e.content(n)),o==null)throw new Error("stream ended before first block was read");let i;if(this.pluginOptions.contentTypeParser!=null)try{let s=this.pluginOptions.contentTypeParser(o,t);if(Ef(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s);this.log.trace("contentTypeParser returned %s for file with name %s",i,t)}catch(s){this.log.error("error parsing content type - %e",s)}return i??Cr}};var B0=class extends Map{#t=0;#e=new Map;#r=new Map;#o;#s;#a;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=e.maxSize,this.#s=e.maxAge||Number.POSITIVE_INFINITY,this.#a=e.onEviction}get __oldCache(){return this.#r}#l(e){if(typeof this.#a=="function")for(let[t,n]of e)this.#a(t,n.value)}#n(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#a=="function"&&this.#a(e,t.value),this.delete(e)):!1}#m(e,t){if(this.#n(e,t)===!1)return t.value}#h(e,t){return t.expiry?this.#m(e,t):t.value}#p(e,t){let n=t.get(e);return this.#h(e,n)}#u(e,t){this.#e.set(e,t),this.#t++,this.#t>=this.#o&&(this.#t=0,this.#l(this.#r),this.#r=this.#e,this.#e=new Map)}#f(e,t){this.#r.delete(e),this.#u(e,t)}*#i(){for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield e)}for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#h(e,t)}if(this.#r.has(e)){let t=this.#r.get(e);if(this.#n(e,t)===!1)return this.#f(e,t),t.value}}set(e,t,{maxAge:n=this.#s}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#u(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#n(e,this.#e.get(e)):this.#r.has(e)?!this.#n(e,this.#r.get(e)):!1}peek(e){if(this.#e.has(e))return this.#p(e,this.#e);if(this.#r.has(e))return this.#p(e,this.#r)}expiresIn(e){let t=this.#e.get(e)??this.#r.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){let t=this.#e.delete(e);return t&&this.#t--,this.#r.delete(e)||t}clear(){this.#e.clear(),this.#r.clear(),this.#t=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#i()],n=t.length-e;n<0?(this.#e=new Map(t),this.#r=new Map,this.#t=t.length):(n>0&&this.#l(t.slice(0,n)),this.#r=new Map(t.slice(n)),this.#e=new Map,this.#t=0),this.#o=e}evict(e=1){let t=Number(e);if(!t||t<=0)return;let n=[...this.#i()],o=Math.trunc(Math.min(t,Math.max(n.length-1,0)));o<=0||(this.#l(n.slice(0,o)),this.#r=new Map(n.slice(o)),this.#e=new Map,this.#t=0)}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield[t,n.value])}for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield[t,n.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#n(o,i)===!1&&(yield[o,i.value])}e=[...this.#r];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#e.has(o)||this.#n(o,i)===!1&&(yield[o,i.value])}}*entriesAscending(){for(let[e,t]of this.#i())yield[e,t.value]}get size(){if(!this.#t)return this.#r.size;let e=0;for(let t of this.#r.keys())this.#e.has(t)||e++;return Math.min(this.#t+e,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#s}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[n,o]of this.entriesAscending())e.call(t,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var bh=class{headers;constructor(){this.headers=[]}getHeader(){return this.headers.join(",")}async time(e,t,n){let o=performance.now();try{return await n}finally{let s=(performance.now()-o).toFixed(1);this.headers.push(`${e};dur=${s};desc="${t}"`)}}};var pJ=29030400;function mJ(r){return{cid:r,name:r.toString(),path:r.toString(),roots:[r],remainder:[]}}var B8=class{components;blockstoreSessions;constructor(e,t={}){this.components=e,this.blockstoreSessions=new B0({maxSize:t.sessionCacheSize??100,maxAge:t.sessionTTLms??6e4,onEviction:(n,o)=>{o.close()}})}async resolve(e,t=new bh,n={}){if(e.protocol==="ipfs:")return this.resolveIPFSPath(e,t,n);if(e.protocol==="ipns:")return this.resolveIPNSName(e,t,n);if(e.protocol==="dnslink:")return this.resolveDNSLink(e,t,n);throw new Ti(`Invalid resource. Unsupported protocol in URL, must be ipfs:, ipns:, or dnslink: ${e}`)}getBlockstore(e,t={}){if(t.session===!1)return this.components.helia.blockstore;let n=`ipfs:${e}`,o=this.blockstoreSessions.get(n);return o==null&&(o=this.components.helia.blockstore.createSession(e,t),this.blockstoreSessions.set(n,o)),o}async resolveDNSLink(e,t,n){let i=(await t.time("dnsLink.resolve",`Resolve DNSLink ${e.hostname}`,this.components.dnsLink.resolve(e.hostname,n)))?.[0];if(i==null)throw new TypeError(`Invalid resource. Cannot resolve DNSLink from domain: ${e.hostname}`);if(i.namespace==="ipns")return this.resolveIPNSName(e,t,n);if(i.namespace!=="ipfs")throw new TypeError(`Invalid resource. Unexpected DNSLink namespace ${i.namespace} from domain: ${domain}`);i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`);return{...await this.resolveIPFSPath(s,t,n),url:e,ttl:i.answer.TTL}}async resolveIPNSName(e,t,n){let o=je(e.hostname),i=await t.time("ipns.resolve",`Resolve IPNS name ${o}`,this.components.ipnsResolver.resolve(o,n));i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`);return{...await this.resolveIPFSPath(s,t,n),url:e,ttl:Number((i.record.ttl??0n)/BigInt(1e9))}}async resolveIPFSPath(e,t,n){let o=await t.time("ipfs.resolve","",this.walkPath(e,n));return{...o,url:e,ttl:pJ,blockstore:o.blockstore}}async walkPath(e,t={}){let n=Z.parse(e.hostname),o=this.getBlockstore(n,t);try{let i=[],s,a=gJ(e);for await(let c of Ic(a,o,{...t,yieldSubShards:!0}))i.push(c.cid),s=c;if(s==null)throw new R8("No terminal element found");return{ipfsRoots:i,terminalElement:s,blockstore:o}}catch(i){if(i.name==="NoResolverError")return{ipfsRoots:[n],terminalElement:mJ(n),blockstore:o};throw i}}};function gJ(r){return`/ipfs/${r.hostname}${decodeURI(r.pathname)}`}var DU=gt(PU(),1);var RU={128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"},yJ={};for(let[r,e]of Object.entries(RU))yJ[e]=Number.parseInt(r,10);var M8;function wJ(){if(!(typeof globalThis.TextDecoder>"u"))return M8??(M8=new globalThis.TextDecoder("utf-8"))}var Bu=32*1024;function OU(r,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":{let t=wJ();return t?t.decode(r):xJ(r)}case"utf-16le":return bJ(r);case"us-ascii":case"ascii":return vJ(r);case"latin1":case"iso-8859-1":return EJ(r);case"windows-1252":return SJ(r);default:throw new RangeError(`Encoding '${e}' not supported`)}}function xJ(r){let e=[],t="",n=0;for(;n<r.length;){let o=r[n++];if(o<128)t+=String.fromCharCode(o);else if(o<224){let i=r[n++]&63;t+=String.fromCharCode((o&31)<<6|i)}else if(o<240){let i=r[n++]&63,s=r[n++]&63;t+=String.fromCharCode((o&15)<<12|i<<6|s)}else{let i=r[n++]&63,s=r[n++]&63,a=r[n++]&63,c=(o&7)<<18|i<<12|s<<6|a;c-=65536,t+=String.fromCharCode(55296+(c>>10&1023),56320+(c&1023))}t.length>=Bu&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function bJ(r){let e=r.length&-2;if(e===0)return"";let t=[],n=Bu;for(let o=0;o<e;){let i=Math.min(n,e-o>>1),s=new Array(i);for(let a=0;a<i;a++,o+=2)s[a]=r[o]|r[o+1]<<8;t.push(String.fromCharCode.apply(null,s))}return t.join("")}function vJ(r){let e=[];for(let t=0;t<r.length;t+=Bu){let n=Math.min(r.length,t+Bu),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i]&127;e.push(String.fromCharCode.apply(null,o))}return e.join("")}function EJ(r){let e=[];for(let t=0;t<r.length;t+=Bu){let n=Math.min(r.length,t+Bu),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i];e.push(String.fromCharCode.apply(null,o))}return e.join("")}function SJ(r){let e=[],t="";for(let n=0;n<r.length;n++){let o=r[n],i=o>=128&&o<=159?RU[o]:void 0;t+=i??String.fromCharCode(o),t.length>=Bu&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function Hn(r){return new DataView(r.buffer,r.byteOffset)}var NU={len:1,get(r,e){return Hn(r).getUint8(e)},put(r,e,t){return Hn(r).setUint8(e,t),e+1}},$t={len:2,get(r,e){return Hn(r).getUint16(e,!0)},put(r,e,t){return Hn(r).setUint16(e,t,!0),e+2}},Mu={len:2,get(r,e){return Hn(r).getUint16(e)},put(r,e,t){return Hn(r).setUint16(e,t),e+2}};var Yt={len:4,get(r,e){return Hn(r).getUint32(e,!0)},put(r,e,t){return Hn(r).setUint32(e,t,!0),e+4}},FS={len:4,get(r,e){return Hn(r).getUint32(e)},put(r,e,t){return Hn(r).setUint32(e,t),e+4}};var LU={len:4,get(r,e){return Hn(r).getInt32(e)},put(r,e,t){return Hn(r).setInt32(e,t),e+4}};var BU={len:8,get(r,e){return Hn(r).getBigUint64(e,!0)},put(r,e,t){return Hn(r).setBigUint64(e,t,!0),e+8}};var Kn=class{constructor(e,t){this.len=e,this.encoding=t}get(e,t=0){let n=e.subarray(t,t+this.len);return OU(n,this.encoding)}};var _J="End-Of-Stream",kt=class extends Error{constructor(){super(_J),this.name="EndOfStreamError"}},Uu=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Fu=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,t=!1){let n=await this.read(e,t);return this.peekQueue.push(e.subarray(0,n)),n}async read(e,t=!1){if(e.length===0)return 0;let n=this.readFromPeekBuffer(e);if(this.endOfStream||(n+=await this.readRemainderFromStream(e.subarray(n),t)),n===0&&!t)throw new kt;return n}readFromPeekBuffer(e){let t=e.length,n=0;for(;this.peekQueue.length>0&&t>0;){let o=this.peekQueue.pop();if(!o)throw new Error("peekData should be defined");let i=Math.min(o.length,t);e.set(o.subarray(0,i),n),n+=i,t-=i,i<o.length&&this.peekQueue.push(o.subarray(i))}return n}async readRemainderFromStream(e,t){let n=0;for(;n<e.length&&!this.endOfStream;){if(this.interrupted)throw new Uu;let o=await this.readFromStream(e.subarray(n),t);if(o===0)break;n+=o}if(!t&&n<e.length)throw new kt;return n}};var U8=class extends Fu{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}};var M0=class extends U8{async readFromStream(e,t){if(e.length===0)return 0;let n=await this.reader.read(new Uint8Array(e.length),{min:t?void 0:e.length});return n.done&&(this.endOfStream=n.done),n.value?(e.set(n.value),n.value.length):0}};var vh=class extends Fu{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,t){let n=Math.min(t.length,e.length);return e.set(t.subarray(0,n)),n<t.length?this.buffer=t.subarray(n):this.buffer=null,n}async readFromStream(e,t){if(e.length===0)return 0;let n=0;for(this.buffer&&(n+=this.writeChunk(e,this.buffer));n<e.length&&!this.endOfStream;){let o=await this.reader.read();if(o.done){this.endOfStream=!0;break}o.value&&(n+=this.writeChunk(e.subarray(n),o.value))}if(!t&&n===0&&this.endOfStream)throw new kt;return n}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}};function $S(r){try{let e=r.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new vh(e):new M0(e)}catch(e){if(e instanceof TypeError)return new vh(r.getReader());throw e}}var da=class{constructor(e){this.numBuffer=new Uint8Array(8),this.position=0,this.onClose=e?.onClose,e?.abortSignal&&e.abortSignal.addEventListener("abort",()=>{this.abort()})}async readToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.readBuffer(n,{position:t})<e.len)throw new kt;return e.get(n,0)}async peekToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.peekBuffer(n,{position:t})<e.len)throw new kt;return e.get(n,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new kt;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new kt;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let t=this.fileInfo.size-this.position;if(e>t)return this.position+=t,t}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,t){if(!this.supportsRandomAccess()&&t&&t.position!==void 0&&t.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");return{mayBeLess:!1,offset:0,length:e.length,position:this.position,...t}}abort(){return Promise.resolve()}};var CJ=256e3,F8=class extends da{constructor(e,t){super(t),this.streamReader=e,this.fileInfo=t?.fileInfo??{}}async readBuffer(e,t){let n=this.normalizeOptions(e,t),o=n.position-this.position;if(o>0)return await this.ignore(o),this.readBuffer(e,t);if(o<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(n.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,n.length),n.mayBeLess);if(this.position+=i,(!t||!t.mayBeLess)&&i<n.length)throw new kt;return i}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=0;if(n.position){let i=n.position-this.position;if(i>0){let s=new Uint8Array(n.length+i);return o=await this.peekBuffer(s,{mayBeLess:n.mayBeLess}),e.set(s.subarray(i)),o-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(n.length>0){try{o=await this.streamReader.peek(e.subarray(0,n.length),n.mayBeLess)}catch(i){if(t?.mayBeLess&&i instanceof kt)return 0;throw i}if(!n.mayBeLess&&o<n.length)throw new kt}return o}async ignore(e){let t=Math.min(CJ,e),n=new Uint8Array(t),o=0;for(;o<e;){let i=e-o,s=await this.readBuffer(n,{length:Math.min(t,i)});if(s<0)return s;o+=s}return o}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}};var $8=class extends da{constructor(e,t){super(t),this.uint8Array=e,this.fileInfo={...t?.fileInfo??{},size:e.length}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.uint8Array.length-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new kt;return e.set(this.uint8Array.subarray(n.position,n.position+o)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};var H8=class extends da{constructor(e,t){super(t),this.blob=e,this.fileInfo={...t?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.blob.size-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new kt;let i=await this.blob.slice(n.position,n.position+o).arrayBuffer();return e.set(new Uint8Array(i)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};function MU(r,e){let t=$S(r),n=e??{},o=n.onClose;return n.onClose=async()=>{if(await t.close(),o)return o()},new F8(t,n)}function UU(r,e){return new $8(r,e)}function FU(r,e){return new H8(r,e)}var GU=gt(qU(),1);var Hu={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},HS={get(r){return{signature:Yt.get(r,0),compressedSize:Yt.get(r,8),uncompressedSize:Yt.get(r,12)}},len:16},zU={get(r){let e=$t.get(r,6);return{signature:Yt.get(r,0),minVersion:$t.get(r,4),dataDescriptor:!!(e&8),compressedMethod:$t.get(r,8),compressedSize:Yt.get(r,18),uncompressedSize:Yt.get(r,22),filenameLength:$t.get(r,26),extraFieldLength:$t.get(r,28),filename:null}},len:30},jU={get(r){return{signature:Yt.get(r,0),nrOfThisDisk:$t.get(r,4),nrOfThisDiskWithTheStart:$t.get(r,6),nrOfEntriesOnThisDisk:$t.get(r,8),nrOfEntriesOfSize:$t.get(r,10),sizeOfCd:Yt.get(r,12),offsetOfStartOfCd:Yt.get(r,16),zipFileCommentLength:$t.get(r,20)}},len:22},WU={get(r){let e=$t.get(r,8);return{signature:Yt.get(r,0),minVersion:$t.get(r,6),dataDescriptor:!!(e&8),compressedMethod:$t.get(r,10),compressedSize:Yt.get(r,20),uncompressedSize:Yt.get(r,24),filenameLength:$t.get(r,28),extraFieldLength:$t.get(r,30),fileCommentLength:$t.get(r,32),relativeOffsetOfLocalHeader:Yt.get(r,42),filename:null}},len:46};function XU(r){let e=new Uint8Array(Yt.len);return Yt.put(e,0,r),e}var us=(0,GU.default)("tokenizer:inflate"),KS=256*1024,HJ=XU(Hu.DataDescriptor),q8=XU(Hu.EndOfCentralDirectory),U0=class r{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(KS)}async isZip(){return await this.peekSignature()===Hu.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(Yt)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,t=Math.min(16*1024,e.fileInfo.size),n=this.syncBuffer.subarray(0,t);await this.tokenizer.readBuffer(n,{position:e.fileInfo.size-t});for(let o=n.length-4;o>=0;o--)if(n[o]===q8[0]&&n[o+1]===q8[1]&&n[o+2]===q8[2]&&n[o+3]===q8[3])return e.fileInfo.size-t+o;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){us("Cannot reading central-directory without random-read support");return}us("Reading central-directory...");let e=this.tokenizer.position,t=await this.findEndOfCentralDirectoryLocator();if(t>0){us("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(jU,t),o=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let s=await this.tokenizer.readToken(WU);if(s.signature!==Hu.CentralFileHeader)throw new Error("Expected Central-File-Header signature");s.filename=await this.tokenizer.readToken(new Kn(s.filenameLength,"utf-8")),await this.tokenizer.ignore(s.extraFieldLength),await this.tokenizer.ignore(s.fileCommentLength),o.push(s),us(`Add central-directory file-entry: n=${i+1}/${o.length}: filename=${o[i].filename}`)}return this.tokenizer.setPosition(e),o}this.tokenizer.setPosition(e)}async unzip(e){let t=await this.readCentralDirectory();if(t)return this.iterateOverCentralDirectory(t,e);let n=!1;do{let o=await this.readLocalFileHeader();if(!o)break;let i=e(o);n=!!i.stop;let s;if(await this.tokenizer.ignore(o.extraFieldLength),o.dataDescriptor&&o.compressedSize===0){let a=[],c=KS;us("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let l=-1;for(;l<0&&c===KS;){c=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),l=KJ(this.syncBuffer.subarray(0,c),HJ);let u=l>=0?l:c;if(i.handler){let f=new Uint8Array(u);await this.tokenizer.readBuffer(f),a.push(f)}else await this.tokenizer.ignore(u)}us(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(o,VJ(a),i.handler)}else i.handler?(us(`Reading compressed-file-data: ${o.compressedSize} bytes`),s=new Uint8Array(o.compressedSize),await this.tokenizer.readBuffer(s),await this.inflate(o,s,i.handler)):(us(`Ignoring compressed-file-data: ${o.compressedSize} bytes`),await this.tokenizer.ignore(o.compressedSize));if(us(`Reading data-descriptor at pos=${this.tokenizer.position}`),o.dataDescriptor&&(await this.tokenizer.readToken(HS)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-HS.len}`)}while(!n)}async iterateOverCentralDirectory(e,t){for(let n of e){let o=t(n);if(o.handler){this.tokenizer.setPosition(n.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let s=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(s),await this.inflate(i,s,o.handler)}}if(o.stop)break}}async inflate(e,t,n){if(e.compressedMethod===0)return n(t);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);us(`Decompress filename=${e.filename}, compressed-size=${t.length}`);let o=await r.decompressDeflateRaw(t);return n(o)}static async decompressDeflateRaw(e){let t=new ReadableStream({start(i){i.enqueue(e),i.close()}}),n=new DecompressionStream("deflate-raw"),o=t.pipeThrough(n);try{let s=await new Response(o).arrayBuffer();return new Uint8Array(s)}catch(i){let s=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(s)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(Yt);if(e===Hu.LocalFileHeader){let t=await this.tokenizer.readToken(zU);return t.filename=await this.tokenizer.readToken(new Kn(t.filenameLength,"utf-8")),t}if(e===Hu.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}};function KJ(r,e){let t=r.length,n=e.length;if(n>t)return-1;for(let o=0;o<=t-n;o++){let i=!0;for(let s=0;s<n;s++)if(r[o+s]!==e[s]){i=!1;break}if(i)return o}return-1}function VJ(r){let e=r.reduce((o,i)=>o+i.length,0),t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var F0=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(t){let n=new Uint8Array(1024),o=await e.readBuffer(n,{mayBeLess:!0});if(o===0){t.close();return}t.enqueue(n.subarray(0,o))}}).pipeThrough(new DecompressionStream("gzip"))}};var Znt={utf8:new globalThis.TextDecoder("utf8")};var Jnt=new globalThis.TextEncoder;var eot=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function VS(r){let{byteLength:e}=r;if(e===6)return r.getUint16(0)*2**32+r.getUint32(2);if(e===5)return r.getUint8(0)*2**32+r.getUint32(1);if(e===4)return r.getUint32(0);if(e===3)return r.getUint8(0)*2**16+r.getUint16(1);if(e===2)return r.getUint16(0);if(e===1)return r.getUint8(0)}function YU(r,e){if(e==="utf-16le"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o&255,o>>8&255)}return t}if(e==="utf-16be"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o>>8&255,o&255)}return t}return[...r].map(t=>t.charCodeAt(0))}function QU(r,e=0){let t=Number.parseInt(new Kn(6).get(r,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(t))return!1;let n=256;for(let o=e;o<e+148;o++)n+=r[o];for(let o=e+156;o<e+512;o++)n+=r[o];return t===n}var ZU={get:(r,e)=>r[e+3]&127|r[e+2]<<7|r[e+1]<<14|r[e]<<21,len:4};var JU=["jpg","png","apng","gif","webp","flif","xcf","cr2","cr3","orf","arw","dng","nef","rw2","raf","tif","bmp","icns","jxr","psd","indd","zip","tar","rar","gz","bz2","7z","dmg","mp4","mid","mkv","webm","mov","avi","mpg","mp2","mp3","m4a","oga","ogg","ogv","opus","flac","wav","spx","amr","pdf","epub","elf","macho","exe","swf","rtf","wasm","woff","woff2","eot","ttf","otf","ttc","ico","flv","ps","xz","sqlite","nes","crx","xpi","cab","deb","ar","rpm","Z","lz","cfb","mxf","mts","blend","bpg","docx","pptx","xlsx","3gp","3g2","j2c","jp2","jpm","jpx","mj2","aif","qcp","odt","ods","odp","xml","mobi","heic","cur","ktx","ape","wv","dcm","ics","glb","pcap","dsf","lnk","alias","voc","ac3","m4v","m4p","m4b","f4v","f4p","f4b","f4a","mie","asf","ogm","ogx","mpc","arrow","shp","aac","mp1","it","s3m","xm","skp","avif","eps","lzh","pgp","asar","stl","chm","3mf","zst","jxl","vcf","jls","pst","dwg","parquet","class","arj","cpio","ace","avro","icc","fbx","vsdx","vtt","apk","drc","lz4","potx","xltx","dotx","xltm","ott","ots","otp","odg","otg","xlsm","docm","dotm","potm","pptm","jar","jmp","rm","sav","ppsm","ppsx","tar.gz","reg","dat"],eF=["image/jpeg","image/png","image/gif","image/webp","image/flif","image/x-xcf","image/x-canon-cr2","image/x-canon-cr3","image/tiff","image/bmp","image/vnd.ms-photo","image/vnd.adobe.photoshop","application/x-indesign","application/epub+zip","application/x-xpinstall","application/vnd.ms-powerpoint.slideshow.macroenabled.12","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.slideshow","application/zip","application/x-tar","application/x-rar-compressed","application/gzip","application/x-bzip2","application/x-7z-compressed","application/x-apple-diskimage","application/vnd.apache.arrow.file","video/mp4","audio/midi","video/matroska","video/webm","video/quicktime","video/vnd.avi","audio/wav","audio/qcelp","audio/x-ms-asf","video/x-ms-asf","application/vnd.ms-asf","video/mpeg","video/3gpp","audio/mpeg","audio/mp4","video/ogg","audio/ogg","audio/ogg; codecs=opus","application/ogg","audio/flac","audio/ape","audio/wavpack","audio/amr","application/pdf","application/x-elf","application/x-mach-binary","application/x-msdownload","application/x-shockwave-flash","application/rtf","application/wasm","font/woff","font/woff2","application/vnd.ms-fontobject","font/ttf","font/otf","font/collection","image/x-icon","video/x-flv","application/postscript","application/eps","application/x-xz","application/x-sqlite3","application/x-nintendo-nes-rom","application/x-google-chrome-extension","application/vnd.ms-cab-compressed","application/x-deb","application/x-unix-archive","application/x-rpm","application/x-compress","application/x-lzip","application/x-cfb","application/x-mie","application/mxf","video/mp2t","application/x-blender","image/bpg","image/j2c","image/jp2","image/jpx","image/jpm","image/mj2","audio/aiff","application/xml","application/x-mobipocket-ebook","image/heif","image/heif-sequence","image/heic","image/heic-sequence","image/icns","image/ktx","application/dicom","audio/x-musepack","text/calendar","text/vcard","text/vtt","model/gltf-binary","application/vnd.tcpdump.pcap","audio/x-dsf","application/x.ms.shortcut","application/x.apple.alias","audio/x-voc","audio/vnd.dolby.dd-raw","audio/x-m4a","image/apng","image/x-olympus-orf","image/x-sony-arw","image/x-adobe-dng","image/x-nikon-nef","image/x-panasonic-rw2","image/x-fujifilm-raf","video/x-m4v","video/3gpp2","application/x-esri-shape","audio/aac","audio/x-it","audio/x-s3m","audio/x-xm","video/MP1S","video/MP2P","application/vnd.sketchup.skp","image/avif","application/x-lzh-compressed","application/pgp-encrypted","application/x-asar","model/stl","application/vnd.ms-htmlhelp","model/3mf","image/jxl","application/zstd","image/jls","application/vnd.ms-outlook","image/vnd.dwg","application/vnd.apache.parquet","application/java-vm","application/x-arj","application/x-cpio","application/x-ace-compressed","application/avro","application/vnd.iccprofile","application/x.autodesk.fbx","application/vnd.visio","application/vnd.android.package-archive","application/vnd.google.draco","application/x-lz4","application/vnd.openxmlformats-officedocument.presentationml.template","application/vnd.openxmlformats-officedocument.spreadsheetml.template","application/vnd.openxmlformats-officedocument.wordprocessingml.template","application/vnd.ms-excel.template.macroenabled.12","application/vnd.oasis.opendocument.text-template","application/vnd.oasis.opendocument.spreadsheet-template","application/vnd.oasis.opendocument.presentation-template","application/vnd.oasis.opendocument.graphics","application/vnd.oasis.opendocument.graphics-template","application/vnd.ms-excel.sheet.macroenabled.12","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-word.template.macroenabled.12","application/vnd.ms-powerpoint.template.macroenabled.12","application/vnd.ms-powerpoint.presentation.macroenabled.12","application/java-archive","application/vnd.rn-realmedia","application/x-spss-sav","application/x-ms-regedit","application/x-ft-windows-registry-hive","application/x-jmp-data"];var qS=4100;async function tF(r,e){return new jS(e).fromBuffer(r)}function zS(r){switch(r=r.toLowerCase(),r){case"application/epub+zip":return{ext:"epub",mime:r};case"application/vnd.oasis.opendocument.text":return{ext:"odt",mime:r};case"application/vnd.oasis.opendocument.text-template":return{ext:"ott",mime:r};case"application/vnd.oasis.opendocument.spreadsheet":return{ext:"ods",mime:r};case"application/vnd.oasis.opendocument.spreadsheet-template":return{ext:"ots",mime:r};case"application/vnd.oasis.opendocument.presentation":return{ext:"odp",mime:r};case"application/vnd.oasis.opendocument.presentation-template":return{ext:"otp",mime:r};case"application/vnd.oasis.opendocument.graphics":return{ext:"odg",mime:r};case"application/vnd.oasis.opendocument.graphics-template":return{ext:"otg",mime:r};case"application/vnd.openxmlformats-officedocument.presentationml.slideshow":return{ext:"ppsx",mime:r};case"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return{ext:"xlsx",mime:r};case"application/vnd.ms-excel.sheet.macroenabled":return{ext:"xlsm",mime:"application/vnd.ms-excel.sheet.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.spreadsheetml.template":return{ext:"xltx",mime:r};case"application/vnd.ms-excel.template.macroenabled":return{ext:"xltm",mime:"application/vnd.ms-excel.template.macroenabled.12"};case"application/vnd.ms-powerpoint.slideshow.macroenabled":return{ext:"ppsm",mime:"application/vnd.ms-powerpoint.slideshow.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return{ext:"docx",mime:r};case"application/vnd.ms-word.document.macroenabled":return{ext:"docm",mime:"application/vnd.ms-word.document.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.template":return{ext:"dotx",mime:r};case"application/vnd.ms-word.template.macroenabledtemplate":return{ext:"dotm",mime:"application/vnd.ms-word.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.template":return{ext:"potx",mime:r};case"application/vnd.ms-powerpoint.template.macroenabled":return{ext:"potm",mime:"application/vnd.ms-powerpoint.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.presentation":return{ext:"pptx",mime:r};case"application/vnd.ms-powerpoint.presentation.macroenabled":return{ext:"pptm",mime:"application/vnd.ms-powerpoint.presentation.macroenabled.12"};case"application/vnd.ms-visio.drawing":return{ext:"vsdx",mime:"application/vnd.visio"};case"application/vnd.ms-package.3dmanufacturing-3dmodel+xml":return{ext:"3mf",mime:"model/3mf"};default:}}function fs(r,e,t){t={offset:0,...t};for(let[n,o]of e.entries())if(t.mask){if(o!==(t.mask[n]&r[n+t.offset]))return!1}else if(o!==r[n+t.offset])return!1;return!0}var jS=class{constructor(e){this.options={mpegOffsetTolerance:0,...e},this.detectors=[...e?.customDetectors??[],{id:"core",detect:this.detectConfident},{id:"core.imprecise",detect:this.detectImprecise}],this.tokenizerOptions={abortSignal:e?.signal}}async fromTokenizer(e){let t=e.position;for(let n of this.detectors){let o=await n.detect(e);if(o)return o;if(t!==e.position)return}}async fromBuffer(e){if(!(e instanceof Uint8Array||e instanceof ArrayBuffer))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof e}\``);let t=e instanceof Uint8Array?e:new Uint8Array(e);if(t?.length>1)return this.fromTokenizer(UU(t,this.tokenizerOptions))}async fromBlob(e){let t=FU(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async fromStream(e){let t=MU(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async toDetectionStream(e,t){let{sampleSize:n=qS}=t,o,i,s=e.getReader({mode:"byob"});try{let{value:l,done:u}=await s.read(new Uint8Array(n));if(i=l,!u&&l)try{o=await this.fromBuffer(l.subarray(0,n))}catch(f){if(!(f instanceof kt))throw f;o=void 0}i=l}finally{s.releaseLock()}let a=new TransformStream({async start(l){l.enqueue(i)},transform(l,u){u.enqueue(l)}}),c=e.pipeThrough(a);return c.fileType=o,c}check(e,t){return fs(this.buffer,e,t)}checkString(e,t){return this.check(YU(e,t?.encoding),t)}detectConfident=async e=>{if(this.buffer=new Uint8Array(qS),e.fileInfo.size===void 0&&(e.fileInfo.size=Number.MAX_SAFE_INTEGER),this.tokenizer=e,await e.peekBuffer(this.buffer,{length:32,mayBeLess:!0}),this.check([66,77]))return{ext:"bmp",mime:"image/bmp"};if(this.check([11,119]))return{ext:"ac3",mime:"audio/vnd.dolby.dd-raw"};if(this.check([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(this.check([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if(this.check([37,33]))return await e.peekBuffer(this.buffer,{length:24,mayBeLess:!0}),this.checkString("PS-Adobe-",{offset:2})&&this.checkString(" EPSF-",{offset:14})?{ext:"eps",mime:"application/eps"}:{ext:"ps",mime:"application/postscript"};if(this.check([31,160])||this.check([31,157]))return{ext:"Z",mime:"application/x-compress"};if(this.check([199,113]))return{ext:"cpio",mime:"application/x-cpio"};if(this.check([96,234]))return{ext:"arj",mime:"application/x-arj"};if(this.check([239,187,191]))return this.tokenizer.ignore(3),this.detectConfident(e);if(this.check([71,73,70]))return{ext:"gif",mime:"image/gif"};if(this.check([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(this.check([31,139,8])){let n=new F0(e).inflate(),o=!0;try{let i;try{i=await this.fromStream(n)}catch{o=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{o&&await n.cancel()}return{ext:"gz",mime:"application/gzip"}}if(this.check([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(this.checkString("ID3")){await e.ignore(6);let t=await e.readToken(ZU);return e.position+t>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(t),this.fromTokenizer(e))}if(this.checkString("MP+"))return{ext:"mpc",mime:"audio/x-musepack"};if((this.buffer[0]===67||this.buffer[0]===70)&&this.check([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(this.check([255,216,255]))return this.check([247],{offset:3})?{ext:"jls",mime:"image/jls"}:{ext:"jpg",mime:"image/jpeg"};if(this.check([79,98,106,1]))return{ext:"avro",mime:"application/avro"};if(this.checkString("FLIF"))return{ext:"flif",mime:"image/flif"};if(this.checkString("8BPS"))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(this.checkString("MPCK"))return{ext:"mpc",mime:"audio/x-musepack"};if(this.checkString("FORM"))return{ext:"aif",mime:"audio/aiff"};if(this.checkString("icns",{offset:0}))return{ext:"icns",mime:"image/icns"};if(this.check([80,75,3,4])){let t;return await new U0(e).unzip(n=>{switch(n.filename){case"META-INF/mozilla.rsa":return t={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return t={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(o){let i=new TextDecoder("utf-8").decode(o).trim();t=zS(i)},stop:!0};case"[Content_Types].xml":return{async handler(o){let i=new TextDecoder("utf-8").decode(o),s=i.indexOf('.main+xml"');if(s===-1){let a="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${a}"`)&&(t=zS(a))}else{i=i.slice(0,Math.max(0,s));let a=i.lastIndexOf('"'),c=i.slice(Math.max(0,a+1));t=zS(c)}},stop:!0};default:return/classes\d*\.dex/.test(n.filename)?(t={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(n=>{if(!(n instanceof kt))throw n}),t??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let t=new Uint8Array(8);return await e.readBuffer(t),fs(t,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:fs(t,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:fs(t,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:fs(t,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:fs(t,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:fs(t,[1,118,111,114,98,105,115])?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"}}if(this.check([80,75])&&(this.buffer[2]===3||this.buffer[2]===5||this.buffer[2]===7)&&(this.buffer[3]===4||this.buffer[3]===6||this.buffer[3]===8))return{ext:"zip",mime:"application/zip"};if(this.checkString("MThd"))return{ext:"mid",mime:"audio/midi"};if(this.checkString("wOFF")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff",mime:"font/woff"};if(this.checkString("wOF2")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(this.check([212,195,178,161])||this.check([161,178,195,212]))return{ext:"pcap",mime:"application/vnd.tcpdump.pcap"};if(this.checkString("DSD "))return{ext:"dsf",mime:"audio/x-dsf"};if(this.checkString("LZIP"))return{ext:"lz",mime:"application/x-lzip"};if(this.checkString("fLaC"))return{ext:"flac",mime:"audio/flac"};if(this.check([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(this.checkString("wvpk"))return{ext:"wv",mime:"audio/wavpack"};if(this.checkString("%PDF"))return{ext:"pdf",mime:"application/pdf"};if(this.check([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(this.check([73,73])){let t=await this.readTiffHeader(!1);if(t)return t}if(this.check([77,77])){let t=await this.readTiffHeader(!0);if(t)return t}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function t(){let a=await e.peekNumber(NU),c=128,l=0;for(;(a&c)===0&&c!==0;)++l,c>>=1;let u=new Uint8Array(l+1);return await e.readBuffer(u),u}async function n(){let a=await t(),c=await t();c[0]^=128>>c.length-1;let l=Math.min(6,c.length),u=new DataView(a.buffer),f=new DataView(c.buffer,c.length-l,l);return{id:VS(u),len:VS(f)}}async function o(a){for(;a>0;){let c=await n();if(c.id===17026)return(await e.readToken(new Kn(c.len))).replaceAll(/\00.*$/g,"");await e.ignore(c.len),--a}}let i=await n();switch(await o(i.len)){case"webm":return{ext:"webm",mime:"video/webm"};case"matroska":return{ext:"mkv",mime:"video/matroska"};default:return}}if(this.checkString("SQLi"))return{ext:"sqlite",mime:"application/x-sqlite3"};if(this.check([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(this.checkString("Cr24"))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(this.checkString("MSCF")||this.checkString("ISc("))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(this.check([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(this.check([197,208,211,198]))return{ext:"eps",mime:"application/eps"};if(this.check([40,181,47,253]))return{ext:"zst",mime:"application/zstd"};if(this.check([127,69,76,70]))return{ext:"elf",mime:"application/x-elf"};if(this.check([33,66,68,78]))return{ext:"pst",mime:"application/vnd.ms-outlook"};if(this.checkString("PAR1")||this.checkString("PARE"))return{ext:"parquet",mime:"application/vnd.apache.parquet"};if(this.checkString("ttcf"))return{ext:"ttc",mime:"font/collection"};if(this.check([254,237,250,206])||this.check([254,237,250,207])||this.check([206,250,237,254])||this.check([207,250,237,254]))return{ext:"macho",mime:"application/x-mach-binary"};if(this.check([4,34,77,24]))return{ext:"lz4",mime:"application/x-lz4"};if(this.checkString("regf"))return{ext:"dat",mime:"application/x-ft-windows-registry-hive"};if(this.checkString("$FL2")||this.checkString("$FL3"))return{ext:"sav",mime:"application/x-spss-sav"};if(this.check([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(this.checkString("#!AMR"))return{ext:"amr",mime:"audio/amr"};if(this.checkString("{\\rtf"))return{ext:"rtf",mime:"application/rtf"};if(this.check([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(this.checkString("IMPM"))return{ext:"it",mime:"audio/x-it"};if(this.checkString("-lh0-",{offset:2})||this.checkString("-lh1-",{offset:2})||this.checkString("-lh2-",{offset:2})||this.checkString("-lh3-",{offset:2})||this.checkString("-lh4-",{offset:2})||this.checkString("-lh5-",{offset:2})||this.checkString("-lh6-",{offset:2})||this.checkString("-lh7-",{offset:2})||this.checkString("-lzs-",{offset:2})||this.checkString("-lz4-",{offset:2})||this.checkString("-lz5-",{offset:2})||this.checkString("-lhd-",{offset:2}))return{ext:"lzh",mime:"application/x-lzh-compressed"};if(this.check([0,0,1,186])){if(this.check([33],{offset:4,mask:[241]}))return{ext:"mpg",mime:"video/MP1S"};if(this.check([68],{offset:4,mask:[196]}))return{ext:"mpg",mime:"video/MP2P"}}if(this.checkString("ITSF"))return{ext:"chm",mime:"application/vnd.ms-htmlhelp"};if(this.check([202,254,186,190])){let t=FS.get(this.buffer,4),n=Mu.get(this.buffer,6);if(t>0&&t<=30)return{ext:"macho",mime:"application/x-mach-binary"};if(n>30)return{ext:"class",mime:"application/java-vm"}}if(this.checkString(".RMF"))return{ext:"rm",mime:"application/vnd.rn-realmedia"};if(this.checkString("DRACO"))return{ext:"drc",mime:"application/vnd.google.draco"};if(this.check([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(this.checkString("<?xml "))return{ext:"xml",mime:"application/xml"};if(this.check([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(this.check([82,97,114,33,26,7])&&(this.buffer[6]===0||this.buffer[6]===1))return{ext:"rar",mime:"application/x-rar-compressed"};if(this.checkString("solid "))return{ext:"stl",mime:"model/stl"};if(this.checkString("AC")){let t=new Kn(4,"latin1").get(this.buffer,2);if(t.match("^d*")&&t>=1e3&&t<=1050)return{ext:"dwg",mime:"image/vnd.dwg"}}if(this.checkString("070707"))return{ext:"cpio",mime:"application/x-cpio"};if(this.checkString("BLENDER"))return{ext:"blend",mime:"application/x-blender"};if(this.checkString("!<arch>"))return await e.ignore(8),await e.readToken(new Kn(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
117
117
|
`,"\r"," "," ","\0"].some(t=>this.checkString(t,{offset:6})))return{ext:"vtt",mime:"text/vtt"};if(this.check([137,80,78,71,13,10,26,10])){await e.ignore(8);async function t(){return{length:await e.readToken(LU),type:await e.readToken(new Kn(4,"latin1"))}}do{let n=await t();if(n.length<0)return;switch(n.type){case"IDAT":return{ext:"png",mime:"image/png"};case"acTL":return{ext:"apng",mime:"image/apng"};default:await e.ignore(n.length+4)}}while(e.position+8<e.fileInfo.size);return{ext:"png",mime:"image/png"}}if(this.check([65,82,82,79,87,49,0,0]))return{ext:"arrow",mime:"application/vnd.apache.arrow.file"};if(this.check([103,108,84,70,2,0,0,0]))return{ext:"glb",mime:"model/gltf-binary"};if(this.check([102,114,101,101],{offset:4})||this.check([109,100,97,116],{offset:4})||this.check([109,111,111,118],{offset:4})||this.check([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(this.check([73,73,82,79,8,0,0,0,24]))return{ext:"orf",mime:"image/x-olympus-orf"};if(this.checkString("gimp xcf "))return{ext:"xcf",mime:"image/x-xcf"};if(this.checkString("ftyp",{offset:4})&&(this.buffer[8]&96)!==0){let t=new Kn(4,"latin1").get(this.buffer,8).replace("\0"," ").trim();switch(t){case"avif":case"avis":return{ext:"avif",mime:"image/avif"};case"mif1":return{ext:"heic",mime:"image/heif"};case"msf1":return{ext:"heic",mime:"image/heif-sequence"};case"heic":case"heix":return{ext:"heic",mime:"image/heic"};case"hevc":case"hevx":return{ext:"heic",mime:"image/heic-sequence"};case"qt":return{ext:"mov",mime:"video/quicktime"};case"M4V":case"M4VH":case"M4VP":return{ext:"m4v",mime:"video/x-m4v"};case"M4P":return{ext:"m4p",mime:"video/mp4"};case"M4B":return{ext:"m4b",mime:"audio/mp4"};case"M4A":return{ext:"m4a",mime:"audio/x-m4a"};case"F4V":return{ext:"f4v",mime:"video/mp4"};case"F4P":return{ext:"f4p",mime:"video/mp4"};case"F4A":return{ext:"f4a",mime:"audio/mp4"};case"F4B":return{ext:"f4b",mime:"audio/mp4"};case"crx":return{ext:"cr3",mime:"image/x-canon-cr3"};default:return t.startsWith("3g")?t.startsWith("3g2")?{ext:"3g2",mime:"video/3gpp2"}:{ext:"3gp",mime:"video/3gpp"}:{ext:"mp4",mime:"video/mp4"}}}if(this.checkString(`REGEDIT4\r
|
|
118
118
|
`))return{ext:"reg",mime:"application/x-ms-regedit"};if(this.check([82,73,70,70])){if(this.checkString("WEBP",{offset:8}))return{ext:"webp",mime:"image/webp"};if(this.check([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(this.check([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/wav"};if(this.check([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(this.check([73,73,85,0,24,0,0,0,136,231,116,216]))return{ext:"rw2",mime:"image/x-panasonic-rw2"};if(this.check([48,38,178,117,142,102,207,17,166,217])){async function t(){let n=new Uint8Array(16);return await e.readBuffer(n),{id:n,size:Number(await e.readToken(BU))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let n=await t(),o=n.size-24;if(fs(n.id,[145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101])){let i=new Uint8Array(16);if(o-=await e.readBuffer(i),fs(i,[64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"audio/x-ms-asf"};if(fs(i,[192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"video/x-ms-asf"};break}await e.ignore(o)}return{ext:"asf",mime:"application/vnd.ms-asf"}}if(this.check([171,75,84,88,32,49,49,187,13,10,26,10]))return{ext:"ktx",mime:"image/ktx"};if((this.check([126,16,4])||this.check([126,24,4]))&&this.check([48,77,73,69],{offset:4}))return{ext:"mie",mime:"application/x-mie"};if(this.check([39,10,0,0,0,0,0,0,0,0,0,0],{offset:2}))return{ext:"shp",mime:"application/x-esri-shape"};if(this.check([255,79,255,81]))return{ext:"j2c",mime:"image/j2c"};if(this.check([0,0,0,12,106,80,32,32,13,10,135,10]))switch(await e.ignore(20),await e.readToken(new Kn(4,"ascii"))){case"jp2 ":return{ext:"jp2",mime:"image/jp2"};case"jpx ":return{ext:"jpx",mime:"image/jpx"};case"jpm ":return{ext:"jpm",mime:"image/jpm"};case"mjp2":return{ext:"mj2",mime:"image/mj2"};default:return}if(this.check([255,10])||this.check([0,0,0,12,74,88,76,32,13,10,135,10]))return{ext:"jxl",mime:"image/jxl"};if(this.check([254,255]))return this.checkString("<?xml ",{offset:2,encoding:"utf-16be"})?{ext:"xml",mime:"application/xml"}:void 0;if(this.check([208,207,17,224,161,177,26,225]))return{ext:"cfb",mime:"application/x-cfb"};if(await e.peekBuffer(this.buffer,{length:Math.min(256,e.fileInfo.size),mayBeLess:!0}),this.check([97,99,115,112],{offset:36}))return{ext:"icc",mime:"application/vnd.iccprofile"};if(this.checkString("**ACE",{offset:7})&&this.checkString("**",{offset:12}))return{ext:"ace",mime:"application/x-ace-compressed"};if(this.checkString("BEGIN:")){if(this.checkString("VCARD",{offset:6}))return{ext:"vcf",mime:"text/vcard"};if(this.checkString("VCALENDAR",{offset:6}))return{ext:"ics",mime:"text/calendar"}}if(this.checkString("FUJIFILMCCD-RAW"))return{ext:"raf",mime:"image/x-fujifilm-raf"};if(this.checkString("Extended Module:"))return{ext:"xm",mime:"audio/x-xm"};if(this.checkString("Creative Voice File"))return{ext:"voc",mime:"audio/x-voc"};if(this.check([4,0,0,0])&&this.buffer.length>=16){let t=new DataView(this.buffer.buffer).getUint32(12,!0);if(t>12&&this.buffer.length>=t+16)try{let n=new TextDecoder().decode(this.buffer.subarray(16,t+16));if(JSON.parse(n).files)return{ext:"asar",mime:"application/x-asar"}}catch{}}if(this.check([6,14,43,52,2,5,1,1,13,1,2,1,1,2]))return{ext:"mxf",mime:"application/mxf"};if(this.checkString("SCRM",{offset:44}))return{ext:"s3m",mime:"audio/x-s3m"};if(this.check([71])&&this.check([71],{offset:188}))return{ext:"mts",mime:"video/mp2t"};if(this.check([71],{offset:4})&&this.check([71],{offset:196}))return{ext:"mts",mime:"video/mp2t"};if(this.check([66,79,79,75,77,79,66,73],{offset:60}))return{ext:"mobi",mime:"application/x-mobipocket-ebook"};if(this.check([68,73,67,77],{offset:128}))return{ext:"dcm",mime:"application/dicom"};if(this.check([76,0,0,0,1,20,2,0,0,0,0,0,192,0,0,0,0,0,0,70]))return{ext:"lnk",mime:"application/x.ms.shortcut"};if(this.check([98,111,111,107,0,0,0,0,109,97,114,107,0,0,0,0]))return{ext:"alias",mime:"application/x.apple.alias"};if(this.checkString("Kaydara FBX Binary \0"))return{ext:"fbx",mime:"application/x.autodesk.fbx"};if(this.check([76,80],{offset:34})&&(this.check([0,0,1],{offset:8})||this.check([1,0,2],{offset:8})||this.check([2,0,2],{offset:8})))return{ext:"eot",mime:"application/vnd.ms-fontobject"};if(this.check([6,6,237,245,216,29,70,229,189,49,239,231,254,116,183,29]))return{ext:"indd",mime:"application/x-indesign"};if(this.check([255,255,0,0,7,0,0,0,4,0,0,0,1,0,1,0])||this.check([0,0,255,255,0,0,0,7,0,0,0,4,0,1,0,1]))return{ext:"jmp",mime:"application/x-jmp-data"};if(await e.peekBuffer(this.buffer,{length:Math.min(512,e.fileInfo.size),mayBeLess:!0}),this.checkString("ustar",{offset:257})&&(this.checkString("\0",{offset:262})||this.checkString(" ",{offset:262}))||this.check([0,0,0,0,0,0],{offset:257})&&QU(this.buffer))return{ext:"tar",mime:"application/x-tar"};if(this.check([255,254])){let t="utf-16le";return this.checkString("<?xml ",{offset:2,encoding:t})?{ext:"xml",mime:"application/xml"}:this.check([255,14],{offset:2})&&this.checkString("SketchUp Model",{offset:4,encoding:t})?{ext:"skp",mime:"application/vnd.sketchup.skp"}:this.checkString(`Windows Registry Editor Version 5.00\r
|
|
119
119
|
`,{offset:2,encoding:t})?{ext:"reg",mime:"application/x-ms-regedit"}:void 0}if(this.checkString("-----BEGIN PGP MESSAGE-----"))return{ext:"pgp",mime:"application/pgp-encrypted"}};detectImprecise=async e=>{if(this.buffer=new Uint8Array(qS),await e.peekBuffer(this.buffer,{length:Math.min(8,e.fileInfo.size),mayBeLess:!0}),this.check([0,0,1,186])||this.check([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(this.check([0,1,0,0,0]))return{ext:"ttf",mime:"font/ttf"};if(this.check([0,0,1,0]))return{ext:"ico",mime:"image/x-icon"};if(this.check([0,0,2,0]))return{ext:"cur",mime:"image/x-icon"};if(await e.peekBuffer(this.buffer,{length:Math.min(2+this.options.mpegOffsetTolerance,e.fileInfo.size),mayBeLess:!0}),this.buffer.length>=2+this.options.mpegOffsetTolerance)for(let t=0;t<=this.options.mpegOffsetTolerance;++t){let n=this.scanMpeg(t);if(n)return n}};async readTiffTag(e){let t=await this.tokenizer.readToken(e?Mu:$t);switch(this.tokenizer.ignore(10),t){case 50341:return{ext:"arw",mime:"image/x-sony-arw"};case 50706:return{ext:"dng",mime:"image/x-adobe-dng"};default:}}async readTiffIFD(e){let t=await this.tokenizer.readToken(e?Mu:$t);for(let n=0;n<t;++n){let o=await this.readTiffTag(e);if(o)return o}}async readTiffHeader(e){let t=(e?Mu:$t).get(this.buffer,2),n=(e?FS:Yt).get(this.buffer,4);if(t===42){if(n>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(n>=8){let i=(e?Mu:$t).get(this.buffer,8),s=(e?Mu:$t).get(this.buffer,10);if(i===28&&s===254||i===31&&s===11)return{ext:"nef",mime:"image/x-nikon-nef"}}}return await this.tokenizer.ignore(n),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(t===43)return{ext:"tif",mime:"image/tiff"}}scanMpeg(e){if(this.check([255,224],{offset:e,mask:[255,224]})){if(this.check([16],{offset:e+1,mask:[22]}))return this.check([8],{offset:e+1,mask:[8]})?{ext:"aac",mime:"audio/aac"}:{ext:"aac",mime:"audio/aac"};if(this.check([2],{offset:e+1,mask:[6]}))return{ext:"mp3",mime:"audio/mpeg"};if(this.check([4],{offset:e+1,mask:[6]}))return{ext:"mp2",mime:"audio/mpeg"};if(this.check([6],{offset:e+1,mask:[6]}))return{ext:"mp1",mime:"audio/mpeg"}}}},lot=new Set(JU),uot=new Set(eF);var rF="application/octet-stream";function qJ(r){return/^(<\?xml[^>]+>)?[^<^\w]+<svg/ig.test(r)}async function zJ(r){try{return JSON.parse(r),!0}catch{return!1}}function jJ(r){let e=new TextDecoder("utf-8",{fatal:!0});try{return e.decode(r)}catch{return null}}async function WJ(r){return/^\s*<(?:!doctype\s+html|html|head|body)\b/i.test(r)}async function nF(r,e){let t=(await tF(r))?.mime;if(t!=null)return t==="application/xml"&&e?.toLowerCase().endsWith(".svg")?"image/svg+xml":t;if(e==null||e.includes(".")===!1){let n=jJ(r);return n!=null?qJ(n)?"image/svg+xml":await zJ(n)?"application/json":await WJ(n)?"text/html; charset=utf-8":"text/plain; charset=utf-8":rF}switch(e.split(".").pop()){case"css":return"text/css";case"html":return"text/html; charset=utf-8";case"js":return"application/javascript";case"json":return"application/json";case"txt":return"text/plain";case"woff2":return"font/woff2";case"svg":return"image/svg+xml";case"csv":return"text/csv";case"doc":return"application/msword";case"xls":return"application/vnd.ms-excel";case"ppt":return"application/vnd.ms-powerpoint";case"msi":return"application/x-msdownload";default:return rF}}function oF(r,e,t){if(t?.signal?.throwIfAborted(),["AbortError","InvalidParametersError"].includes(e.name))throw e;return e.code==="ECONNREFUSED"||e.code==="ECANCELLED"||e.name==="DNSQueryFailedError"?A8(r,e):["NotUnixFSError"].includes(e.name)?Nu(r,e):e.code==="ETIMEOUT"||e.name==="TimeoutError"?A8(r,e):["ERR_BAD_PATH","ERR_NO_TERMINAL_ELEMENT","ERR_NOT_FOUND"].includes(e.code)?DS(r):["DoesNotExistError"].includes(e.name)?DS(r):["BlockNotFoundWhileOfflineError"].includes(e.name)?vU(r):["RecordNotFoundError","LoadBlockFailedError"].includes(e.name)?A8(r,e):RS(r,e)}function iF({cid:r,contentType:e,ranges:t,contentPrefix:n}){let o=e.immutable?"":"W/",i=e.etag;if(t?.length!=null&&t?.length>0){let s=t.filter(a=>a.start!=null||a.end!=null);s.length>0&&(i+="."+s.map(a=>`${a.start??0}-${a.end??"N"}`).join(","))}return`${o}"${n??""}${r.toString()}${i}"`}function WS(r,e){let t=(e?.get("if-none-match")??"").split(",").map(n=>(n=n.trim(),n.startsWith("W/")&&(n=n.substring(2)),n));return r.startsWith("W/")&&(r=r.substring(2)),t.includes("*")||t.includes(r)}function GS(r){if(r==null||r==="")return;let e=Number(r);if(isNaN(e))throw new $n(`Invalid range specification: could not parse "${e}" as number`);return e}function GJ(r){if(r==null||r==="")return[];if(!r.startsWith("bytes="))throw new $n("Invalid range request");let t=r.substring(6).split(",").map(o=>o.trim()),n=[];for(let o of t){let i=o.match(/^(?<start>\d+)?-(?<end>\d+)?$/);if(i?.groups==null)throw new $n(`Invalid range specification: ${o}`);if(o.startsWith("-"))n.push({end:GS(o)});else{let{start:s,end:a}=i.groups;n.push({start:GS(s),end:GS(a)})}}return n}function sF(r,e){let t=e.get("range");if(t!=null)try{let n=GJ(t);return n.length===0?void 0:{multipartBoundary:`multipart_byteranges_${Math.floor(Math.random()*1e9)}`,ranges:n}}catch(n){return n.name==="InvalidRangeError"?_8(r):Go(r,n)}}function XJ(r){if(!r.startsWith("/ipfs/")&&!r.startsWith("/ipns/"))throw new D(`Path ${r} did not start with /ipfs/ or /ipns/`);let e=new URL(`not-http://example.com${r}`),[,t,n,...o]=e.pathname.split("/");return`${t}://${n}${o.length>0?`/${o.join("/")}`:""}${e.search}${e.hash}`}function aF(r){if((r.startsWith("/ipfs/")||r.startsWith("/ipns/"))&&(r=XJ(r)),r.startsWith("ipfs://")||r.startsWith("ipns://")||r.startsWith("dnslink://")){let e=new URL(r);if(e.protocol==="ipns:")try{Z.parse(e.hostname)}catch{try{je(e.hostname)}catch{e.protocol="dnslink"}}return e}throw new D(`URL did not start with ipfs:// or ipns:// - ${r}`)}function YJ(r){if(r!=null)return{...r,signal:r?.signal==null?void 0:r?.signal}}function QJ(r){let e=r.get("accept")?.split(",")??[];return e.length!==1?!1:e[0].split(";")[0]===Ru}function ZJ(r){let e=r.get("accept")?.split(",")??[];return e.length!==1?!1:e[0].split(";")[0]===Vr}var z8=class{helia;ipnsResolver;dnsLink;log;contentTypeParser;withServerTiming;plugins=[];urlResolver;constructor(e,t={}){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipnsResolver=t.ipnsResolver??mM(e),this.dnsLink=t.dnsLink??lM(e),this.contentTypeParser=t.contentTypeParser??nF,this.withServerTiming=t?.withServerTiming??!1,this.urlResolver=new B8({ipnsResolver:this.ipnsResolver,dnsLink:this.dnsLink,helia:this.helia},t);let n={...t,logger:e.logger.forComponent("verified-fetch"),helia:e,contentTypeParser:this.contentTypeParser,ipnsResolver:this.ipnsResolver},o=[new L8(n),new C8(n),new T8(n),new N8(n),new I8(n),new k8(n)],i=t.plugins?.map(s=>s(n))??[];if(i.length>0){let s=new Map(o.map(c=>[c.id,c])),a=new Map(i.map(c=>[c.id,c]));this.plugins=o.map(c=>a.get(c.id)??c),this.plugins.unshift(...i.filter(c=>!s.has(c.id)))}else this.plugins=o}async fetch(e,t){this.log("fetch %s %s",t?.method??"GET",e);try{if(t?.method==="OPTIONS")return this.handleFinalResponse(new Response(null,{status:200}));let n=YJ(t),o=new Headers(n?.headers),i=new bh;n!=null&&(n.offline??=o.get("cache-control")==="only-if-cached"),n?.onProgress?.(new Y("verified-fetch:request:start",{resource:e}));let s=sF(e,o);if(s instanceof Response)return this.handleFinalResponse(s);let a=this.parseResource(e);if(a.protocol==="ipfs:"&&a.pathname===""&&WS(`"${a.hostname}"`,o))return NS(e,new Headers({etag:`"${a.hostname}"`,"cache-control":"public, max-age=29030400, immutable"}));let c=JJ(a,o.get("accept"));if(QJ(o)){if(a.protocol!=="ipns:")return Pc(a,c,[Du]);let d=this.plugins.find(m=>m.id==="ipns-record-plugin");return d==null?Pc(e,c,[]):this.handleFinalResponse(await d.handle({range:s,url:a,resource:e,options:n}))}let l=await this.urlResolver.resolve(a,i,{...n,isRawBlockRequest:ZJ(o)});n?.onProgress?.(new Y("verified-fetch:request:resolve",{cid:l.terminalElement.cid,path:l.url.pathname}));let u=this.getAcceptHeader(l.url,c,l.terminalElement.cid);if(u instanceof Response)return this.log("allowed media types for requested CID did not contain anything the client can understand"),this.handleFinalResponse(u);let f={...l,resource:e,accept:u,range:s,options:n,onProgress:n?.onProgress,serverTiming:i,headers:o,requestedMimeTypes:c};this.log.trace('finding handler for cid code "0x%s" and response content types %s',l.terminalElement.cid.code.toString(16),u.map(d=>d.contentType.mediaType).join(", "));let h=await this.runPluginPipeline(f);return n?.onProgress?.(new Y("verified-fetch:request:end",{cid:l.terminalElement.cid,path:l.url.pathname})),h==null&&this.log.error("no plugin could handle request for %s",e),this.handleFinalResponse(h,!!n?.withServerTiming||!!this.withServerTiming,f)}catch(n){return this.log.error("error fetching resource %s - %e",e,n),this.handleFinalResponse(oF(e,n,t))}}getAcceptHeader(e,t,n){let o=pU(e.protocol,n),i=[];for(let s of t){let[a,c]=s.mediaType.split("/");for(let l of o){let[u,f]=l.mediaType.split("/");s.mediaType.includes(l.mediaType)&&i.push({contentType:l,options:s.options}),s.mediaType==="*/*"&&i.push({contentType:l,options:s.options}),s.mediaType.startsWith("*/")&&f===c&&i.push({contentType:l,options:s.options}),s.mediaType.endsWith("/*")&&u===a&&i.push({contentType:l,options:s.options})}}return i.length===0?(this.log("requested %o",t.map(({mediaType:s})=>s)),this.log("supported %o",o.map(({mediaType:s})=>s)),Pc(e,t,o)):i}parseResource(e){return(mr(e)||Y0(e))&&(e=`/ipns/${e}`),(Z.asCID(e)===e||e instanceof Z)&&(e=`/ipfs/${e}`),new URL(aF(e.toString()))}handleFinalResponse(e,t,n){let o=hU(e.headers.get("content-type"))??S8;if(t===!0&&n?.serverTiming!=null){let i=n?.serverTiming.getHeader();i!==""&&e.headers.set("server-timing",i)}if(n?.url?.protocol!=null&&n.ttl!=null&&wU({response:e,ttl:n.ttl,protocol:n.url.protocol}),n?.terminalElement.cid!=null){let i=decodeURI(n?.url.pathname),s=H(O(i),"ascii");e.headers.set("x-ipfs-path",`/${n.url.protocol==="ipfs:"?"ipfs":"ipns"}/${n?.url.hostname}${s==="/"?"":s}`)}if(e.headers.set("access-control-allow-origin","*"),e.headers.set("access-control-allow-methods","GET, HEAD, OPTIONS"),e.headers.set("access-control-allow-headers","Range, X-Requested-With"),e.headers.set("access-control-expose-headers","Content-Range, Content-Length, X-Ipfs-Path, X-Ipfs-Roots, X-Stream-Output"),n?.terminalElement.cid!=null&&e.headers.get("etag")==null){let i=iF({cid:n.terminalElement.cid,contentType:o,ranges:n?.range?.ranges});if(e.headers.set("etag",i),WS(i,n?.headers))return NS(e.url,e.headers)}return n?.options?.method==="HEAD"?new Response(null,{status:200,headers:e.headers}):(e.status>399&&e.headers.delete("content-disposition"),e)}async runPluginPipeline(e){let t,n=new Set;this.log.trace("checking which plugins can handle %c%s with accept %s",e.terminalElement.cid,e.url.pathname,e.accept.map(a=>a.contentType.mediaType).join(", "));let o=this.plugins.filter(a=>!n.has(a.id)).filter(a=>a.canHandle(e));if(o.length===0)return this.log.trace("no plugins found that can handle request; exiting pipeline"),OS(e.resource);this.log.trace("plugins ready to handle request: %s",o.map(a=>a.id).join(", "));let i=!1,s=!1;for(let a of o){this.log("invoking plugin: %s",a.id),n.add(a.id);let c=await a.handle(e);if(this.log("plugin response %s %o",a.id,c),c!=null){t=c,s=!0;break}if(t!=null){this.log.trace("plugin %s produced final response",a.id);break}if(s&&t!=null)break;if(!i){this.log.trace("no context changes and no final response; exiting pipeline.");break}}return t??OS(e.resource,JSON.stringify({error:L0(new Error("No verified fetch plugin could handle the request"))}),{headers:{"content-type":"application/json"}})}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function JJ(r,e){return(e==null||e==="")&&(e="*/*"),e.split(",").map(t=>{let n=t.trim().split(";"),o={q:"1"};for(let i=1;i<n.length;i++){let[s,a]=n[i].split("=").map(c=>c.trim());o[s]=a}return{mediaType:`${n[0]}`.trim(),options:o}}).sort((t,n)=>t.options.q===n.options.q?0:t.options.q>n.options.q?-1:1)}var $0,j8=async function(e,t){return $0==null&&($0=await XS()),$0(e,t)};j8.start=async function(){await $0?.start()};j8.stop=async function(){await $0?.stop()};async function XS(r,e){let t;if(!eee(r)){let i=tee(r?.dnsResolvers),s=sM();s.dns=i;let a=r?.routers??["https://delegated-ipfs.dev"];for(let u=0;u<a.length;u++)s.services[`delegatedRouting${u}`]=Tk({url:a[u]});r?.libp2pConfig!=null&&Object.assign(s,r.libp2pConfig),t=await k3(s);let c=[qp()],l=[Jp(t)];(r?.gateways==null||r.gateways.length>0)&&(c.push(Gp({allowInsecure:r?.allowInsecure,allowLocal:r?.allowLocal})),l.push(Zp({gateways:r?.gateways??["https://trustless-gateway.link"]}))),r=await iM({libp2p:t,blockBrokers:c,dns:i,routers:l,hashers:r?.hashers}),r.logger.forComponent("helia:verified-fetch").trace("created verified-fetch with libp2p config: %j",s)}let n=new z8(r,e);async function o(i,s){return n.fetch(i,s)}return o.start=n.start.bind(n),o.stop=n.stop.bind(n),o}function eee(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}function tee(r){if(r!=null)return Array.isArray(r)?gl({resolvers:{".":r}}):gl({resolvers:r})}return EF(ree);})();
|