@helia/routers 5.1.1-35b081c7 → 5.1.1-73a28eda

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 CHANGED
@@ -1,27 +1,16 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaRouters = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaRouters=(()=>{var gl=Object.create;var Cn=Object.defineProperty;var bl=Object.getOwnPropertyDescriptor;var xl=Object.getOwnPropertyNames;var wl=Object.getPrototypeOf,El=Object.prototype.hasOwnProperty;var Ea=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)Cn(e,r,{get:t[r],enumerable:!0})},Sa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xl(t))!El.call(e,o)&&o!==r&&Cn(e,o,{get:()=>t[o],enumerable:!(n=bl(t,o))||n.enumerable});return e};var Go=(e,t,r)=>(r=e!=null?gl(wl(e)):{},Sa(t||!e||!e.__esModule?Cn(r,"default",{value:e,enumerable:!0}):r,e)),Sl=e=>Sa(Cn({},"__esModule",{value:!0}),e);var js=Ea((x1,Hs)=>{var b1=(function(){typeof Hs<"u"&&(Hs.exports=v);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(w){var C=w-w%1;return C==0&&(w<0||w===0&&1/w!=1/0)?-0:C},f=v.prototype,l=(v.fromDate=function(w){return new v(+w)},v.fromInt64BE=U(0,1,2,3,0,4),v.fromInt64LE=U(3,2,1,0,4,0),v.fromString=function(P){var C,N=new v,P=(P+="").replace(/^\s*[+\-]?\d+/,function(g){var g=+g,T=1970+(g-1970)%400;return N.year=g-T,T}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(d,g,T){return g<0&&(T*=-1),C=6e4*(60*+g+ +T),""}).replace(/\.\d+$/,function(d){return N.nano=+(d+c).substr(1,9),""}).split(/\D+/);if(1<P.length?P[1]--:P[1]=0,N.time=C=Date.UTC.apply(Date,P)-(C||0),isNaN(C))throw new TypeError("Invalid Date");return y(N)},v.fromTimeT=function(w){return A(w,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(w){return this.nano+=+w||0,this},f.getNano=function(){var w=y(this);return(w.time%1e3*a+ +w.nano+1e9)%1e9},f.getTimeT=function(){var C=y(this),w=Math.floor(C.time/1e3),C=C.year;return C&&(w+=C*r*e/t),w},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return S(y(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(w){var C=this,N=C.toDate(),P={H:function(){return M(N.getUTCHours())},L:function(){return L(N.getUTCMilliseconds(),3)},M:function(){return M(N.getUTCMinutes())},N:function(){return L(C.getNano(),9)},S:function(){return M(N.getUTCSeconds())},Y:function(){var d=C.getYear();return 999999<d?"+"+d:9999<d?"+"+L(d,6):0<=d?L(d,4):-999999<=d?"-"+L(-d,6):d},a:function(){return m[N.getUTCDay()]},b:function(){return h[N.getUTCMonth()]},d:function(){return M(N.getUTCDate())},e:function(){return(function(d){return(9<d?"":" ")+(0|d)})(N.getUTCDate())},m:function(){return M(N.getUTCMonth()+1)}};return(function d(g){return g.replace(/%./g,function(T){var x=T[1],b=E[x],x=P[x];return b?d(b):x?x():T})})(w||l)},f.writeInt64BE=_(0,1,2,3,0,4),f.writeInt64LE=_(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"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],E={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return v;function v(w,C,N){var P=this;if(!(P instanceof v))return new v(w,C,N);P.time=+w||0,P.nano=+C||0,P.year=+N||0,y(P)}function y(w){var C,N,P,d=w.year,g=w.time,T=w.nano,b=((T<0||a<=T)&&(T-=(N=Math.floor(T/a))*a,g+=N,N=1),d%t);return(g<-i||i<g||b)&&((C=u(g/o))&&(d+=C*t,g-=C*o),(P=S(g)).setUTCFullYear(b+P.getUTCFullYear()),P=(g=+P)+(C=u((d-=b)/t))*o,C&&-i<=P&&P<=i&&(d-=C*t,g=P),N=1),N&&(w.year=d,w.time=g,w.nano=T),w}function S(w){var C=new Date(0);return C.setTime(w),C}function A(d,P){d=+d||0;var N=u((P=(P|0)*s)/n)+u(d/n),P=P%n+d%n,d=u(P/n);return d&&(N+=d,P-=d*n),new v(1e3*P,0,N*t)}function _(w,C,N,P,d,g){return function(b,x){var R=y(this);b=b||new Array(8),F(b,x|=0);var D=Math.floor(R.time/1e3),R=R.year*(r*e/t),I=u(R/s)+u(D/s),R=R%s+D%s,D=Math.floor(R/s);return D&&(I+=D,R-=D*s),T(b,x+d,I),T(b,x+g,R),b};function T(b,x,I){b[x+w]=I>>24&255,b[x+C]=I>>16&255,b[x+N]=I>>8&255,b[x+P]=255&I}}function U(w,C,N,P,d,g){return function(b,x){F(b,x|=0);var I=T(b,x+d);return A(T(b,x+g),I)};function T(b,x){return 16777216*b[x+w]+(b[x+C]<<16|b[x+N]<<8|b[x+P])}}function F(w,C){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<C+8)throw new RangeError("Out of range")}function M(w){return(9<w?"":"0")+(0|w)}function L(w,C){return(c+(0|w)).substr(-C)}})()});var Qf=Ea((xE,oa)=>{"use strict";var J0=Object.prototype.hasOwnProperty,vt="~";function Tn(){}Object.create&&(Tn.prototype=Object.create(null),new Tn().__proto__||(vt=!1));function Q0(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Jf(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Q0(r,n||e,o),s=vt?vt+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function $o(e,t){--e._eventsCount===0?e._events=new Tn:delete e._events[t]}function wt(){this._events=new Tn,this._eventsCount=0}wt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)J0.call(r,n)&&t.push(vt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};wt.prototype.listeners=function(t){var r=vt?vt+t:t,n=this._events[r];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};wt.prototype.listenerCount=function(t){var r=vt?vt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};wt.prototype.emit=function(t,r,n,o,i,s){var a=vt?vt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,m;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,o);break;default:if(!f)for(m=1,f=new Array(u-1);m<u;m++)f[m-1]=arguments[m];c[l].fn.apply(c[l].context,f)}}return!0};wt.prototype.on=function(t,r,n){return Jf(this,t,r,n,!1)};wt.prototype.once=function(t,r,n){return Jf(this,t,r,n,!0)};wt.prototype.removeListener=function(t,r,n,o){var i=vt?vt+t:t;if(!this._events[i])return this;if(!r)return $o(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&$o(this,i);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:$o(this,i)}return this};wt.prototype.removeAllListeners=function(t){var r;return t?(r=vt?vt+t:t,this._events[r]&&$o(this,r)):(this._events=new Tn,this._eventsCount=0),this};wt.prototype.off=wt.prototype.removeListener;wt.prototype.addListener=wt.prototype.on;wt.prefixed=vt;wt.EventEmitter=wt;typeof oa<"u"&&(oa.exports=wt)});var Sm={};Et(Sm,{delegatedHTTPRouting:()=>al,delegatedHTTPRoutingDefaults:()=>Yo,httpGatewayRouting:()=>ml,libp2pRouting:()=>yl});var va=Symbol.for("@libp2p/content-routing");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},rr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var At=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var _n=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},nr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var or=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Bn=Symbol.for("@libp2p/peer-id");function Ta(e){return!!e?.[Bn]}var Aa=Symbol.for("@libp2p/peer-routing");var ti={};Et(ti,{base58btc:()=>X,base58flickr:()=>Bl});var _m=new Uint8Array(0);function Ia(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ue(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ca(e){return new TextEncoder().encode(e)}function _a(e){return new TextDecoder().decode(e)}function vl(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var v=0,y=0,S=0,A=E.length;S!==A&&E[S]===0;)S++,v++;for(var _=(A-S)*f+1>>>0,U=new Uint8Array(_);S!==A;){for(var F=E[S],M=0,L=_-1;(F!==0||M<y)&&L!==-1;L--,M++)F+=256*U[L]>>>0,U[L]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");y=M,S++}for(var w=_-y;w!==_&&U[w]===0;)w++;for(var C=c.repeat(v);w<_;++w)C+=e.charAt(U[w]);return C}function h(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var v=0;if(E[v]!==" "){for(var y=0,S=0;E[v]===c;)y++,v++;for(var A=(E.length-v)*u+1>>>0,_=new Uint8Array(A);E[v];){var U=r[E.charCodeAt(v)];if(U===255)return;for(var F=0,M=A-1;(U!==0||F<S)&&M!==-1;M--,F++)U+=a*_[M]>>>0,_[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");S=F,v++}if(E[v]!==" "){for(var L=A-S;L!==A&&_[L]===0;)L++;for(var w=new Uint8Array(y+(A-L)),C=y;L!==A;)w[C++]=_[L++];return w}}}function m(E){var v=h(E);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var Tl=vl,Al=Tl,Ra=Al;var Wo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Xo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Da(this,t)}},Jo=class{decoders;constructor(t){this.decoders=t}or(t){return Da(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Da(e,t){return new Jo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Qo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Wo(t,r,n),this.decoder=new Xo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ir({name:e,prefix:t,encode:r,decode:n}){return new Qo(e,t,r,n)}function Ee({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ra(r,e);return ir({prefix:t,name:e,encode:n,decode:i=>ue(o(i))})}function Il(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Cl(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function _l(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=_l(n);return ir({prefix:t,name:e,encode(i){return Cl(i,n,r)},decode(i){return Il(i,o,r,e)}})}var X=Ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Bl=Ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ei={};Et(ei,{base32:()=>te,base32hex:()=>Ol,base32hexpad:()=>Ll,base32hexpadupper:()=>Nl,base32hexupper:()=>Fl,base32pad:()=>Dl,base32padupper:()=>Pl,base32upper:()=>Rl,base32z:()=>Ul});var te=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Rl=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Dl=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pl=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ol=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fl=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ll=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nl=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ul=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ri={};Et(ri,{base36:()=>sr,base36upper:()=>kl});var sr=Ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),kl=Ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ee={};Et(ee,{Digest:()=>Ke,create:()=>Vt,decode:()=>Se,equals:()=>oi,hasCode:()=>nd});var Kl=Fa,Pa=128,$l=127,Ml=~$l,Vl=Math.pow(2,31);function Fa(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Vl;)t[r++]=e&255|Pa,e/=128;for(;e&Ml;)t[r++]=e&255|Pa,e>>>=7;return t[r]=e|0,Fa.bytes=r-n+1,t}var ql=ni,zl=128,Oa=127;function ni(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw ni.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Oa)<<o:(s&Oa)*Math.pow(2,o),o+=7}while(s>=zl);return ni.bytes=i-n,r}var Hl=Math.pow(2,7),jl=Math.pow(2,14),Yl=Math.pow(2,21),Zl=Math.pow(2,28),Gl=Math.pow(2,35),Wl=Math.pow(2,42),Xl=Math.pow(2,49),Jl=Math.pow(2,56),Ql=Math.pow(2,63),td=function(e){return e<Hl?1:e<jl?2:e<Yl?3:e<Zl?4:e<Gl?5:e<Wl?6:e<Xl?7:e<Jl?8:e<Ql?9:10},ed={encode:Kl,decode:ql,encodingLength:td},rd=ed,Kr=rd;function $r(e,t=0){return[Kr.decode(e,t),Kr.decode.bytes]}function ar(e,t,r=0){return Kr.encode(e,t,r),t}function cr(e){return Kr.encodingLength(e)}function Vt(e,t){let r=t.byteLength,n=cr(e),o=n+cr(r),i=new Uint8Array(o+r);return ar(e,i,0),ar(r,i,n),i.set(t,o),new Ke(e,r,t,i)}function Se(e){let t=ue(e),[r,n]=$r(t),[o,i]=$r(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,s,t)}function oi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ia(e.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function nd(e,t){return e.code===t}function La(e,t){let{bytes:r,version:n}=e;return n===0?id(r,ii(e),t??X.encoder):sd(r,ii(e),t??te.encoder)}var Na=new WeakMap;function ii(e){let t=Na.get(e);if(t==null){let r=new Map;return Na.set(e,r),r}return t}var H=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,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:t,multihash:r}=this;if(t!==Mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ad)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}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:t,digest:r}=this.multihash,n=Vt(t,r);return e.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(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&oi(t.multihash,n.multihash)}toString(t){return La(this,t)}toJSON(){return{"/":La(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??Ua(n,o,i.bytes))}else if(r[cd]===!0){let{version:n,multihash:o,code:i}=r,s=Se(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Mr)throw new Error(`Version 0 CID must use dag-pb (code: ${Mr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ua(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Mr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=ue(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ke(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=$r(t.subarray(r));return r+=h,l},o=n(),i=Mr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=od(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ii(i).set(n,t),i}};function od(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case te.prefix:{let r=t??te;return[te.prefix,r.decode(e)]}case sr.prefix:{let r=t??sr;return[sr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function id(e,t,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function sd(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Mr=112,ad=18;function Ua(e,t,r){let n=cr(e),o=n+cr(t),i=new Uint8Array(o+r.byteLength);return ar(e,i,0),ar(t,i,n),i.set(r,o),i}var cd=Symbol.for("@ipld/js-cid/CID");var si={};Et(si,{identity:()=>St});var ka=0,ud="identity",Ka=ue;function fd(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Vt(ka,Ka(e))}var St={code:ka,name:ud,encode:Ka,digest:fd};function W(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function fe(e=0){return new Uint8Array(e)}function _t(e=0){return new Uint8Array(e)}function Nt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=_t(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ma=Symbol.for("@achingbrain/uint8arraylist");function $a(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function ur(e){return!!e?.[Ma]}var Bt=class e{bufs;length;[Ma]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(ur(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(ur(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=$a(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$a(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(ur(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Nt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Nt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=n,i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===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,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(f){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!ur(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;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 l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){f=Math.max(1,h-a[m]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=_t(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=fe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=fe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=fe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=_t(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=fe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=fe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=fe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=fe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=fe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!W(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var ai={};Et(ai,{base10:()=>ld});var ld=Ee({prefix:"9",name:"base10",alphabet:"0123456789"});var ci={};Et(ci,{base16:()=>dd,base16upper:()=>hd});var dd=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hd=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ui={};Et(ui,{base2:()=>pd});var pd=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fi={};Et(fi,{base256emoji:()=>xd});var Va=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}"),md=Va.reduce((e,t,r)=>(e[r]=t,e),[]),yd=Va.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function gd(e){return e.reduce((t,r)=>(t+=md[r],t),"")}function bd(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=yd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var xd=ir({prefix:"\u{1F680}",name:"base256emoji",encode:gd,decode:bd});var hi={};Et(hi,{base64:()=>li,base64pad:()=>wd,base64url:()=>di,base64urlpad:()=>Ed});var li=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wd=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),di=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ed=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pi={};Et(pi,{base8:()=>Sd});var Sd=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mi={};Et(mi,{identity:()=>vd});var vd=ir({prefix:"\0",name:"identity",encode:e=>_a(e),decode:e=>Ca(e)});var ly=new TextEncoder,dy=new TextDecoder;var qa=85;var bi={};Et(bi,{sha256:()=>Vr,sha512:()=>Id});var Ad=20;function gi({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new yi(e,t,r,n,o)}var yi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ad,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ha(n,this.code,r?.truncate):n.then(o=>Ha(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ha(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Vt(t,e)}function Ya(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Vr=gi({name:"sha2-256",code:18,encode:Ya("SHA-256")}),Id=gi({name:"sha2-512",code:19,encode:Ya("SHA-512")});var qr={...mi,...ui,...pi,...ai,...ci,...ei,...ri,...ti,...hi,...fi},Ty={...bi,...si};function Ga(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Za=Ga("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),xi=Ga("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=_t(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Cd={utf8:Za,"utf-8":Za,hex:qr.base16,latin1:xi,ascii:xi,binary:xi,...qr},Dn=Cd;function V(e,t="utf8"){let r=Dn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Dn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var _d=parseInt("11111",2),wi=parseInt("10000000",2),Bd=parseInt("01111111",2),Wa={0:zr,1:zr,2:Rd,3:Od,4:Fd,5:Pd,6:Dd,16:zr,22:zr,48:zr};function le(e,t={offset:0}){let r=e[t.offset]&_d;if(t.offset++,Wa[r]!=null)return Wa[r](e,t);throw new Error("No decoder for tag "+r)}function Hr(e,t){let r=0;if((e[t.offset]&wi)===wi){let n=e[t.offset]&Bd,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function zr(e,t){Hr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=le(e,t);if(n===null)break;r.push(n)}return r}function Rd(e,t){let r=Hr(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Dd(e,t){let r=Hr(e,t),n=t.offset+r,o=e[t.offset];t.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(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Pd(e,t){return t.offset++,null}function Od(e,t){let r=Hr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fd(e,t){let r=Hr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Ld(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Bt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ei(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Ld(e.byteLength);return new Bt(Uint8Array.from([t.byteLength|wi]),t)}function It(e){let t=new Bt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Bt(Uint8Array.from([2]),Ei(t),t)}function Pn(e){let t=Uint8Array.from([0]),r=new Bt(t,e);return new Bt(Uint8Array.from([3]),Ei(r),r)}function ve(e,t=48){let r=new Bt;for(let n of e)r.append(n);return new Bt(Uint8Array.from([t]),Ei(r),r)}async function Xa(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var Nd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ud=Uint8Array.from([6,5,43,129,4,0,34]),kd=Uint8Array.from([6,5,43,129,4,0,35]),Kd={ext:!0,kty:"EC",crv:"P-256"},$d={ext:!0,kty:"EC",crv:"P-384"},Md={ext:!0,kty:"EC",crv:"P-521"},Si=32,vi=48,Ti=66;function Ai(e){let t=le(e);return Ja(t)}function Ja(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Si*2+1)return n=z(t.subarray(r,r+Si),"base64url"),o=z(t.subarray(r+Si),"base64url"),new fr({...Kd,key_ops:["verify"],x:n,y:o});if(t.byteLength===vi*2+1)return n=z(t.subarray(r,r+vi),"base64url"),o=z(t.subarray(r+vi),"base64url"),new fr({...$d,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ti*2+1)return n=z(t.subarray(r,r+Ti),"base64url"),o=z(t.subarray(r+Ti),"base64url"),new fr({...Md,key_ops:["verify"],x:n,y:o});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qa(e){return ve([It(Uint8Array.from([1])),ve([Vd(e.crv)],160),ve([Pn(new Bt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Vd(e){if(e==="P-256")return Nd;if(e==="P-384")return Ud;if(e==="P-521")return kd;throw new et(`Invalid curve ${e}`)}var fr=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qa(this.jwk)),this._raw}toMultihash(){return St.digest(lr(this))}toCID(){return H.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return Xa(this.jwk,r,t,n)}};function Ii(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Te(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function Rt(e,t,r=""){let n=Ii(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`,u=s+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function On(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Te(e.outputLen),Te(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function dr(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Fn(e,t){Rt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function he(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ln(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function qt(e,t){return e<<32-t|e>>>t}var ec=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",qd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Nn(e){if(Rt(e),ec)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=qd[e[r]];return t}var de={_0:48,_9:57,A:65,F:70,a:97,f:102};function tc(e){if(e>=de._0&&e<=de._9)return e-de._0;if(e>=de.A&&e<=de.F)return e-(de.A-10);if(e>=de.a&&e<=de.f)return e-(de.a-10)}function jr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ec)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=tc(e.charCodeAt(i)),a=tc(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Ci(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Rt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function _i(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function rc(e=32){Te(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Bi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function nc(e,t,r){return e&t^~e&r}function oc(e,t,r){return e&t^e&r^t&r}var Yr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ln(this.buffer)}update(t){dr(this),Rt(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Ln(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){dr(this),Fn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,he(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=Ln(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},pe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Un=BigInt(4294967295),ic=BigInt(32);function zd(e,t=!1){return t?{h:Number(e&Un),l:Number(e>>ic&Un)}:{h:Number(e>>ic&Un)|0,l:Number(e&Un)|0}}function sc(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=zd(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Ri=(e,t,r)=>e>>>r,Di=(e,t,r)=>e<<32-r|t>>>r,$e=(e,t,r)=>e>>>r|t<<32-r,Me=(e,t,r)=>e<<32-r|t>>>r,Zr=(e,t,r)=>e<<64-r|t>>>r-32,Gr=(e,t,r)=>e>>>r-32|t<<64-r;function re(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ac=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),cc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,uc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),fc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,lc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),dc=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var jd=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]),Ae=new Uint32Array(64),Pi=class extends Yr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)Ae[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=Ae[l-15],m=Ae[l-2],E=qt(h,7)^qt(h,18)^h>>>3,v=qt(m,17)^qt(m,19)^m>>>10;Ae[l]=v+Ae[l-7]+E+Ae[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=qt(a,6)^qt(a,11)^qt(a,25),m=f+h+nc(a,c,u)+jd[l]+Ae[l]|0,v=(qt(n,2)^qt(n,13)^qt(n,22))+oc(n,o,i)|0;f=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+v|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,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){he(Ae)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),he(this.buffer)}},Oi=class extends Pi{A=pe[0]|0;B=pe[1]|0;C=pe[2]|0;D=pe[3]|0;E=pe[4]|0;F=pe[5]|0;G=pe[6]|0;H=pe[7]|0;constructor(){super(32)}};var hc=sc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Yd=hc[0],Zd=hc[1],Ie=new Uint32Array(80),Ce=new Uint32Array(80),Fi=class extends Yr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:m,Gl:E,Hh:v,Hl:y}=this;return[t,r,n,o,i,s,a,c,u,f,l,h,m,E,v,y]}set(t,r,n,o,i,s,a,c,u,f,l,h,m,E,v,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=E|0,this.Hh=v|0,this.Hl=y|0}process(t,r){for(let _=0;_<16;_++,r+=4)Ie[_]=t.getUint32(r),Ce[_]=t.getUint32(r+=4);for(let _=16;_<80;_++){let U=Ie[_-15]|0,F=Ce[_-15]|0,M=$e(U,F,1)^$e(U,F,8)^Ri(U,F,7),L=Me(U,F,1)^Me(U,F,8)^Di(U,F,7),w=Ie[_-2]|0,C=Ce[_-2]|0,N=$e(w,C,19)^Zr(w,C,61)^Ri(w,C,6),P=Me(w,C,19)^Gr(w,C,61)^Di(w,C,6),d=uc(L,P,Ce[_-7],Ce[_-16]),g=fc(d,M,N,Ie[_-7],Ie[_-16]);Ie[_]=g|0,Ce[_]=d|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:m,Fl:E,Gh:v,Gl:y,Hh:S,Hl:A}=this;for(let _=0;_<80;_++){let U=$e(l,h,14)^$e(l,h,18)^Zr(l,h,41),F=Me(l,h,14)^Me(l,h,18)^Gr(l,h,41),M=l&m^~l&v,L=h&E^~h&y,w=lc(A,F,L,Zd[_],Ce[_]),C=dc(w,S,U,M,Yd[_],Ie[_]),N=w|0,P=$e(n,o,28)^Zr(n,o,34)^Zr(n,o,39),d=Me(n,o,28)^Gr(n,o,34)^Gr(n,o,39),g=n&i^n&a^i&a,T=o&s^o&c^s&c;S=v|0,A=y|0,v=m|0,y=E|0,m=l|0,E=h|0,{h:l,l:h}=re(u|0,f|0,C|0,N|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let b=ac(N,d,T);n=cc(b,C,P,g),o=b|0}({h:n,l:o}=re(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=re(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=re(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=re(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=re(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:E}=re(this.Fh|0,this.Fl|0,m|0,E|0),{h:v,l:y}=re(this.Gh|0,this.Gl|0,v|0,y|0),{h:S,l:A}=re(this.Hh|0,this.Hl|0,S|0,A|0),this.set(n,o,i,s,a,c,u,f,l,h,m,E,v,y,S,A)}roundClean(){he(Ie,Ce)}destroy(){this.destroyed=!0,he(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Li=class extends Fi{Ah=mt[0]|0;Al=mt[1]|0;Bh=mt[2]|0;Bl=mt[3]|0;Ch=mt[4]|0;Cl=mt[5]|0;Dh=mt[6]|0;Dl=mt[7]|0;Eh=mt[8]|0;El=mt[9]|0;Fh=mt[10]|0;Fl=mt[11]|0;Gh=mt[12]|0;Gl=mt[13]|0;Hh=mt[14]|0;Hl=mt[15]|0;constructor(){super(64)}};var hr=_i(()=>new Oi,Bi(1));var kn=_i(()=>new Li,Bi(3));var Y=(e,t,r)=>Rt(e,t,r),Ui=Te,pr=Nn,ct=(...e)=>Ci(...e),mr=e=>jr(e),Ve=Ii,Wr=e=>rc(e),$n=BigInt(0),Ni=BigInt(1);function zt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Mn(e){if(typeof e=="bigint"){if(!Kn(e))throw new RangeError("positive bigint expected, got "+e)}else Ui(e);return e}function Ht(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Xr(e){let t=Mn(e).toString(16);return t.length&1?"0"+t:t}function pc(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?$n:BigInt("0x"+e)}function qe(e){return pc(Nn(e))}function ne(e){return pc(Nn(Jr(Rt(e)).reverse()))}function Vn(e,t){if(Te(t),t===0)throw new RangeError("zero length");e=Mn(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return jr(r.padStart(t*2,"0"))}function ki(e,t){return Vn(e,t).reverse()}function mc(e,t){if(e=Y(e),t=Y(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Jr(e){return Uint8Array.from(Y(e))}function qn(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Kn=e=>typeof e=="bigint"&&$n<=e;function Gd(e,t,r){return Kn(e)&&Kn(t)&&Kn(r)&&t<=e&&e<r}function yr(e,t,r,n){if(!Gd(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function gr(e){if(e<$n)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>$n;e>>=Ni,t+=1);return t}var Qr=e=>(Ni<<BigInt(e))-Ni;function yc(e,t,r){if(Te(e,"hashLen"),Te(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...y)=>r(u,ct(c,...y)),m=(y=o)=>{u=h(i,y),c=h(),y.length!==0&&(u=h(s,y),c=h())},E=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,S=[];for(;y<t;){c=h();let A=c.slice();S.push(A),y+=c.length}return ct(...S)};return(y,S)=>{l(),m(y);let A;for(;(A=S(E()))===void 0;)m();return l(),A}}function jt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(i,s,a){if(!a&&s!=="function"&&!Object.hasOwn(e,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let c=e[i];if(a&&c===void 0)return;let u=typeof c;if(u!==s||c===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${u}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(t,!1),o(r,!0)}var Ki=()=>{throw new Error("not implemented")};var yt=BigInt(0),nt=BigInt(1),ze=BigInt(2),wc=BigInt(3),Ec=BigInt(4),Sc=BigInt(5),Wd=BigInt(7),vc=BigInt(8),Xd=BigInt(9),Tc=BigInt(16);function it(e,t){if(t<=yt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=yt?r:t+r}function J(e,t,r){if(t<yt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >yt;)n*=n,n%=r;return n}function gc(e,t){if(e===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=yt,i=nt,s=nt,a=yt;for(;r!==yt;){let u=n/r,f=n-r*u,l=o-s*u,h=i-a*u;n=r,r=f,o=s,i=a,s=l,a=h}if(n!==nt)throw new Error("invert: does not exist");return it(o,t)}function $i(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Ac(e,t){let r=e,n=(r.ORDER+nt)/Ec,o=r.pow(t,n);return $i(r,o,t),o}function Jd(e,t){let r=e,n=(r.ORDER-Sc)/vc,o=r.mul(t,ze),i=r.pow(o,n),s=r.mul(t,i),a=r.mul(r.mul(s,ze),i),c=r.mul(s,r.sub(a,r.ONE));return $i(r,c,t),c}function Qd(e){let t=br(e),r=Ic(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Wd)/Tc;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),h=u.mul(f,o),m=u.mul(f,i),E=u.eql(u.sqr(l),c),v=u.eql(u.sqr(h),c);f=u.cmov(f,l,E),l=u.cmov(m,h,v);let y=u.eql(u.sqr(l),c),S=u.cmov(f,l,y);return $i(u,S,c),S})}function Ic(e){if(e<wc)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ze===yt;)t/=ze,r++;let n=ze,o=br(e);for(;bc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ac;let i=o.pow(n,t),s=(t+nt)/ze;return function(c,u){let f=c;if(f.is0(u))return u;if(bc(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,i),m=f.pow(u,t),E=f.pow(u,s);for(;!f.eql(m,f.ONE);){if(f.is0(m))return f.ZERO;let v=1,y=f.sqr(m);for(;!f.eql(y,f.ONE);)if(v++,y=f.sqr(y),v===l)throw new Error("Cannot find square root");let S=nt<<BigInt(l-v-1),A=f.pow(h,S);l=v,h=f.sqr(A),m=f.mul(m,h),E=f.mul(E,A)}return E}}function th(e){return e%Ec===wc?Ac:e%vc===Sc?Jd:e%Tc===Xd?Qd(e):Ic(e)}var me=(e,t)=>(it(e,t)&nt)===nt,eh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mi(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=eh.reduce((n,o)=>(n[o]="function",n),t);if(jt(e,r),Ht(e.BYTES,"BYTES"),Ht(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=nt)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function rh(e,t,r){let n=e;if(r<yt)throw new Error("invalid exponent, negatives unsupported");if(r===yt)return n.ONE;if(r===nt)return t;let o=n.ONE,i=t;for(;r>yt;)r&nt&&(o=n.mul(o,i)),i=n.sqr(i),r>>=nt;return o}function tn(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function bc(e,t){let r=e,n=(r.ORDER-nt)/ze,o=r.pow(t,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function nh(e,t){if(t!==void 0&&Ui(t),e<=yt)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=gr(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var xc=new WeakMap,zn=class{ORDER;BITS;BYTES;isLE;ZERO=yt;ONE=nt;_lengths;_mod;constructor(t,r={}){if(t<=nt)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=nh(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(t){return it(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return yt<=t&&t<this.ORDER}is0(t){return t===yt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}neg(t){return it(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return it(t*t,this.ORDER)}add(t,r){return it(t+r,this.ORDER)}sub(t,r){return it(t-r,this.ORDER)}mul(t,r){return it(t*r,this.ORDER)}pow(t,r){return rh(this,t,r)}div(t,r){return it(t*gc(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return gc(t,this.ORDER)}sqrt(t){let r=xc.get(this);return r||xc.set(this,r=th(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?ki(t,this.BYTES):Vn(t,this.BYTES)}fromBytes(t,r=!1){Y(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?ne(t):qe(t);if(a&&(c=it(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return tn(this,t)}cmov(t,r,n){return zt(n,"condition"),n?r:t}};Object.freeze(zn.prototype);function br(e,t={}){return new zn(e,t)}function Cc(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=nt)throw new Error("field order must be greater than 1");let t=gr(e-nt);return Math.ceil(t/8)}function Vi(e){let t=Cc(e);return t+Math.ceil(t/2)}function qi(e,t,r=!1){Y(e);let n=e.length,o=Cc(t),i=Math.max(Vi(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?ne(e):qe(e),a=it(s,t-nt)+nt;return r?ki(a,o):Vn(a,o)}var xr=BigInt(0),He=BigInt(1);function en(e,t){let r=t.negate();return e?r:t}function je(e,t){let r=tn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Dc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function zi(e,t){Dc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Qr(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function _c(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=He);let u=t*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,m=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:m,offsetF:u}}var Hi=new WeakMap,Pc=new WeakMap;function ji(e){return Pc.get(e)||1}function Bc(e){if(e!==xr)throw new Error("invalid wNAF")}var wr=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>xr;)r&He&&(n=n.add(o)),o=o.double(),r>>=He;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=zi(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=zi(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:m}=_c(n,a,s);n=c,f?i=i.add(en(h,r[m])):o=o.add(en(l,r[u]))}return Bc(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=zi(t,this.bits);for(let s=0;s<i.windows&&n!==xr;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=_c(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return Bc(n),o}getPrecomputes(t,r,n){let o=Hi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Hi.set(r,o))),o}cached(t,r,n){let o=ji(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=ji(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Dc(r,this.bits),Pc.set(t,r),Hi.delete(t)}hasCache(t){return ji(t)!==1}};function Oc(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>xr||n>xr;)r&He&&(i=i.add(o)),n&He&&(s=s.add(o)),o=o.double(),r>>=He,n>>=He;return{p1:i,p2:s}}function Rc(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Mi(t),t}else return br(e,{isLE:r})}function Hn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>xr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Rc(t.p,r.Fp,n),i=Rc(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function jn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var _e=BigInt(0),lt=BigInt(1),Yi=BigInt(2),oh=BigInt(8);function ih(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function Fc(e,t={}){let r=t,n=Hn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;jt(r,{},{uvRatio:"function"});let c=Yi<<BigInt(i.BYTES*8)-lt,u=v=>o.create(v),f=r.uvRatio===void 0?(v,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,y))}}catch{return{isValid:!1,value:_e}}}:r.uvRatio;if(!ih(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(v,y,S=!1){let A=S?lt:_e;return yr("coordinate "+v,y,A,c),y}function h(v){if(!(v instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(s.Gx,s.Gy,lt,u(s.Gx*s.Gy));static ZERO=new m(_e,lt,lt,_e);static Fp=o;static Fn=i;X;Y;Z;T;constructor(y,S,A,_){this.X=l("x",y),this.Y=l("y",S),this.Z=l("z",A,!0),this.T=l("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=y||{};return l("x",S),l("y",A),new m(S,A,lt,u(S*A))}static fromBytes(y,S=!1){let A=o.BYTES,{a:_,d:U}=s;y=Jr(Y(y,A,"point")),zt(S,"zip215");let F=Jr(y),M=y[A-1];F[A-1]=M&-129;let L=ne(F),w=S?c:o.ORDER;yr("point.y",L,_e,w);let C=u(L*L),N=u(C-lt),P=u(U*C-_),{isValid:d,value:g}=f(N,P);if(!d)throw new Error("bad point: invalid y coordinate");let T=(g&lt)===lt,b=(M&128)!==0;if(!S&&g===_e&&b)throw new Error("bad point: x=0 and x_0=1");return b!==T&&(g=u(-g)),m.fromAffine({x:g,y:L})}static fromHex(y,S=!1){return m.fromBytes(mr(y),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,S=!0){return E.createCache(this,y),S||this.multiply(Yi),this}assertValidity(){let y=this,{a:S,d:A}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:_,Y:U,Z:F,T:M}=y,L=u(_*_),w=u(U*U),C=u(F*F),N=u(C*C),P=u(L*S),d=u(C*u(P+w)),g=u(N+u(A*u(L*w)));if(d!==g)throw new Error("bad point: equation left != right (1)");let T=u(_*U),b=u(F*M);if(T!==b)throw new Error("bad point: equation left != right (2)")}equals(y){h(y);let{X:S,Y:A,Z:_}=this,{X:U,Y:F,Z:M}=y,L=u(S*M),w=u(U*_),C=u(A*M),N=u(F*_);return L===w&&C===N}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:y}=s,{X:S,Y:A,Z:_}=this,U=u(S*S),F=u(A*A),M=u(Yi*u(_*_)),L=u(y*U),w=S+A,C=u(u(w*w)-U-F),N=L+F,P=N-M,d=L-F,g=u(C*P),T=u(N*d),b=u(C*d),x=u(P*N);return new m(g,T,x,b)}add(y){h(y);let{a:S,d:A}=s,{X:_,Y:U,Z:F,T:M}=this,{X:L,Y:w,Z:C,T:N}=y,P=u(_*L),d=u(U*w),g=u(M*A*N),T=u(F*C),b=u((_+U)*(L+w)-P-d),x=T-g,I=T+g,R=u(d-S*P),D=u(b*x),k=u(I*R),$=u(b*R),j=u(x*I);return new m(D,k,j,$)}subtract(y){return h(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=E.cached(this,y,_=>je(m,_));return je(m,[S,A])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===_e?m.ZERO:this.is0()||y===lt?this:E.unsafe(this,y,S=>je(m,S))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(y){let S=this,A=y,{X:_,Y:U,Z:F}=S,M=S.is0();A==null&&(A=M?oh:o.inv(F));let L=u(_*A),w=u(U*A),C=o.mul(F,A);if(M)return{x:_e,y:lt};if(C!==lt)throw new Error("invZ was invalid");return{x:L,y:w}}clearCofactor(){return a===lt?this:this.multiplyUnsafe(a)}toBytes(){let{x:y,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=y&lt?128:0,A}toHex(){return pr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new wr(m,i.BITS);return i.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var Yn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Ki()}static fromHex(t){Ki()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return pr(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Lc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;jt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Ht(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Wr:o.randomBytes,h=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,m=o.domain===void 0?(d,g,T)=>{if(zt(T,"phflag"),g.length||T)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function E(d){return c.create(ne(d))}function v(d){let g=L.secretKey;Y(d,L.secretKey,"secretKey");let T=Y(n(d),2*g,"hashedSecretKey"),b=h(T.slice(0,g)),x=T.slice(g,2*g),I=E(b);return{head:b,prefix:x,scalar:I}}function y(d){let{head:g,prefix:T,scalar:b}=v(d),x=s.multiply(b),I=x.toBytes();return{head:g,prefix:T,scalar:b,point:x,pointBytes:I}}function S(d){return y(d).pointBytes}function A(d=Uint8Array.of(),...g){let T=ct(...g);return E(n(m(T,Y(d,void 0,"context"),!!i)))}function _(d,g,T={}){d=Y(d,void 0,"message"),i&&(d=i(d));let{prefix:b,scalar:x,pointBytes:I}=y(g),R=A(T.context,b,d),D=s.multiply(R).toBytes(),k=A(T.context,D,I,d),$=c.create(R+k*x);if(!c.isValid($))throw new Error("sign failed: invalid s");let j=ct(D,c.toBytes($));return Y(j,L.signature,"result")}let U={zip215:o.zip215};function F(d,g,T,b=U){let{context:x}=b,I=b.zip215===void 0?!!U.zip215:b.zip215,R=L.signature;d=Y(d,R,"signature"),g=Y(g,void 0,"message"),T=Y(T,L.publicKey,"publicKey"),I!==void 0&&zt(I,"zip215"),i&&(g=i(g));let D=R/2,k=d.subarray(0,D),$=ne(d.subarray(D,R)),j,G,q;try{j=e.fromBytes(T,I),G=e.fromBytes(k,I),q=s.multiplyUnsafe($)}catch{return!1}if(!I&&j.isSmallOrder())return!1;let at=A(x,k,T,g);return G.add(j.multiplyUnsafe(at)).subtract(q).clearCofactor().is0()}let M=a.BYTES,L={secretKey:M,publicKey:M,signature:2*M,seed:M};function w(d){return d=d===void 0?l(L.seed):d,Y(d,L.seed,"seed")}function C(d){return Ve(d)&&d.length===L.secretKey}function N(d,g){try{return!!e.fromBytes(d,g===void 0?U.zip215:g)}catch{return!1}}let P={getExtendedPublicKey:y,randomSecretKey:w,isValidSecretKey:C,isValidPublicKey:N,toMontgomery(d){let{y:g}=e.fromBytes(d),T=L.publicKey,b=T===32;if(!b&&T!==57)throw new Error("only defined for 25519 and 448");let x=b?a.div(lt+g,lt-g):a.div(g-lt,g+lt);return a.toBytes(x)},toMontgomerySecret(d){let g=L.secretKey;Y(d,g);let T=n(d.subarray(0,g));return h(T).subarray(0,g)}};return Object.freeze(L),Object.freeze(P),Object.freeze({keygen:jn(w,S),getPublicKey:S,sign:_,verify:F,utils:P,Point:e,lengths:L})}function rn(e,t){if(Ht(e),Ht(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function sh(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function ah(e){if(!Ve(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?qn(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Zi(e,t,r,n){Y(e),Ht(r),t=ah(t),t.length>255&&(t=n(ct(qn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ct(t,rn(t.length,1)),c=new Uint8Array(i),u=rn(r,2),f=new Array(s),l=n(ct(c,e,u,rn(0,1),a));f[0]=n(ct(l,rn(1,1),a));for(let m=1;m<s;m++){let E=[sh(l,f[m-1]),rn(m+1,1),a];f[m]=n(ct(...E))}return ct(...f).slice(0,r)}var Nc="HashToScalar-";var ch=BigInt(0),ye=BigInt(1),Uc=BigInt(2);var uh=BigInt(5),fh=BigInt(8),Er=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ji={p:Er,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:fh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function lh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Er,a=e*e%i*e%i,c=J(a,Uc,i)*a%i,u=J(c,ye,i)*e%i,f=J(u,uh,i)*u%i,l=J(f,t,i)*f%i,h=J(l,r,i)*l%i,m=J(h,n,i)*h%i,E=J(m,o,i)*m%i,v=J(E,o,i)*m%i,y=J(v,t,i)*f%i;return{pow_p_5_8:J(y,Uc,i)*e%i,b2:a}}function dh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Gi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qi(e,t){let r=Er,n=it(t*t*t,r),o=it(n*n*t,r),i=lh(e*o).pow_p_5_8,s=it(e*n*i,r),a=it(t*s*s,r),c=s,u=it(s*Gi,r),f=a===e,l=a===it(-e,r),h=a===it(-e*Gi,r);return f&&(s=c),(l||h)&&(s=u),me(s,r)&&(s=it(-s,r)),{isValid:f||l,value:s}}var Re=Fc(Ji,{uvRatio:Qi}),Be=Re.Fp,$c=Re.Fn;function hh(e){return Lc(Re,kn,Object.assign({adjustScalarBytes:dh,zip215:!0},e))}var Mc=hh({});var Wi=Gi,ph=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),mh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),yh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),gh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),kc=e=>Qi(ye,e),bh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Xi=e=>Be.create(ne(e)&bh);function Kc(e){let{d:t}=Ji,r=Er,n=S=>Be.create(S),o=n(Wi*e*e),i=n((o+ye)*yh),s=BigInt(-1),a=n((s-t*o)*n(o+t)),{isValid:c,value:u}=Qi(i,a),f=n(u*e);me(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-ye)*gh-a),h=u*u,m=n((u+u)*a),E=n(l*ph),v=n(ye-h),y=n(ye+h);return new Re(n(m*y),n(v*E),n(E*y),n(m*v))}var De=class e extends Yn{static BASE=new e(Re.BASE);static ZERO=new e(Re.ZERO);static Fp=Be;static Fn=$c;constructor(t){super(t)}static fromAffine(t){return new e(Re.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){Rt(t,32);let{a:r,d:n}=Ji,o=Er,i=U=>Be.create(U),s=Xi(t);if(!mc(Be.toBytes(s),t)||me(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(ye+r*a),u=i(ye-r*a),f=i(c*c),l=i(u*u),h=i(r*n*f-l),{isValid:m,value:E}=kc(i(h*l)),v=i(E*u),y=i(E*v*h),S=i((s+s)*v);me(S,o)&&(S=i(-S));let A=i(c*y),_=i(S*A);if(!m||me(_,o)||A===ch)throw new Error("invalid ristretto255 encoding 2");return new e(new Re(S,A,ye,_))}static fromHex(t){return e.fromBytes(jr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,i=Er,s=y=>Be.create(y),a=s(s(n+r)*s(n-r)),c=s(t*r),u=s(c*c),{value:f}=kc(s(a*u)),l=s(f*a),h=s(f*c),m=s(l*h*o),E;if(me(o*m,i)){let y=s(r*Wi),S=s(t*Wi);t=y,r=S,E=s(l*mh)}else E=h;me(t*m,i)&&(r=s(-r));let v=s((n-r)*E);return me(v,i)&&(v=s(-v)),Be.toBytes(v)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:i}=t.ep,s=u=>Be.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(De.BASE);Object.freeze(De.ZERO);Object.freeze(De.prototype);Object.freeze(De);var xh=Object.freeze({Point:De,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Zi(e,r,64,kn);return xh.deriveToCurve(n)},hashToScalar(e,t={DST:Nc}){let r=Zi(e,t.DST,64,kn);return $c.create(ne(r))},deriveToCurve(e){Rt(e,64);let t=Xi(e.subarray(0,32)),r=Kc(t),n=Xi(e.subarray(32,64)),o=Kc(n);return new De(r.add(o))}});var nn=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Vc={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Zn("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 t}};var Ut=Vc;var Gn=32;var ts,wh=(async()=>{try{return await Ut.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Eh(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ut.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ut.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sh(e,t,r){return Mc.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function qc(e,t,r){return ts==null&&(ts=await wh),ts?Eh(e,t,r):Sh(e,t,r)}function Wn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Xn=class{type="Ed25519";raw;constructor(t){this.raw=es(t,Gn)}toMultihash(){return St.digest(lr(this))}toCID(){return H.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=qc(this.raw,r,t);return Wn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function rs(e){return e=es(e,Gn),new Xn(e)}function es(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Th=Math.pow(2,7),Ah=Math.pow(2,14),Ih=Math.pow(2,21),ns=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),ss=Math.pow(2,49),Q=128,bt=127;function oe(e){if(e<Th)return 1;if(e<Ah)return 2;if(e<Ih)return 3;if(e<ns)return 4;if(e<os)return 5;if(e<is)return 6;if(e<ss)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function on(e,t,r=0){switch(oe(e)){case 8:t[r++]=e&255|Q,e/=128;case 7:t[r++]=e&255|Q,e/=128;case 6:t[r++]=e&255|Q,e/=128;case 5:t[r++]=e&255|Q,e/=128;case 4:t[r++]=e&255|Q,e>>>=7;case 3:t[r++]=e&255|Q,e>>>=7;case 2:t[r++]=e&255|Q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function as(e,t){let r=e[t],n=0;if(n+=r&bt,r<Q||(r=e[t+1],n+=(r&bt)<<7,r<Q)||(r=e[t+2],n+=(r&bt)<<14,r<Q)||(r=e[t+3],n+=(r&bt)<<21,r<Q)||(r=e[t+4],n+=(r&bt)*ns,r<Q)||(r=e[t+5],n+=(r&bt)*os,r<Q)||(r=e[t+6],n+=(r&bt)*is,r<Q)||(r=e[t+7],n+=(r&bt)*ss,r<Q))return n;throw new RangeError("Could not decode varint")}function Ch(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<Q||(r=e.get(t+1),n+=(r&bt)<<7,r<Q)||(r=e.get(t+2),n+=(r&bt)<<14,r<Q)||(r=e.get(t+3),n+=(r&bt)<<21,r<Q)||(r=e.get(t+4),n+=(r&bt)*ns,r<Q)||(r=e.get(t+5),n+=(r&bt)*os,r<Q)||(r=e.get(t+6),n+=(r&bt)*is,r<Q)||(r=e.get(t+7),n+=(r&bt)*ss,r<Q))return n;throw new RangeError("Could not decode varint")}function cs(e,t=0){return e instanceof Uint8Array?as(e,t):Ch(e,t)}var us=new Float32Array([-0]),Pe=new Uint8Array(us.buffer);function Hc(e,t,r){us[0]=e,t[r]=Pe[0],t[r+1]=Pe[1],t[r+2]=Pe[2],t[r+3]=Pe[3]}function jc(e,t){return Pe[0]=e[t],Pe[1]=e[t+1],Pe[2]=e[t+2],Pe[3]=e[t+3],us[0]}var fs=new Float64Array([-0]),xt=new Uint8Array(fs.buffer);function Yc(e,t,r){fs[0]=e,t[r]=xt[0],t[r+1]=xt[1],t[r+2]=xt[2],t[r+3]=xt[3],t[r+4]=xt[4],t[r+5]=xt[5],t[r+6]=xt[6],t[r+7]=xt[7]}function Zc(e,t){return xt[0]=e[t],xt[1]=e[t+1],xt[2]=e[t+2],xt[3]=e[t+3],xt[4]=e[t+4],xt[5]=e[t+5],xt[6]=e[t+6],xt[7]=e[t+7],fs[0]}var Bh=BigInt(Number.MAX_SAFE_INTEGER),Rh=BigInt(Number.MIN_SAFE_INTEGER),Dt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ye;if(t<Bh&&t>Rh)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Gc&&(o=0n,++n>Gc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ye;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ye}},Ye=new Dt(0,0);Ye.toBigInt=function(){return 0n};Ye.zzEncode=Ye.zzDecode=function(){return this};Ye.length=function(){return 1};var Gc=4294967296n;function Wc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Xc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&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 ls(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Yt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Jn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ds=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Yt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Yt(this,4);return Jn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Yt(this,4);return Jn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Yt(this,4);let t=jc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Yt(this,4);let t=Zc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Yt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Xc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Yt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Yt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Dt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Yt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Yt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Yt(this,8);let t=Jn(this.buf,this.pos+=4),r=Jn(this.buf,this.pos+=4);return new Dt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=as(this.buf,this.pos);return this.pos+=oe(t),t}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 sn(e){return new ds(e instanceof Uint8Array?e:e.subarray())}function Sr(e,t,r){let n=sn(e);return t.decode(n,void 0,r)}function hs(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return _t(s);o+s>t&&(n=_t(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ze=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ps(){}var ys=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Dh=hs();function Ph(e){return globalThis.Buffer!=null?_t(e):Dh(e)}var cn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ze(ps,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ze(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Qn,10,Dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Dt.fromBigInt(t);return this._push(Qn,r.length(),r)}uint64Number(t){return this._push(on,oe(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Dt.fromBigInt(t).zzEncode();return this._push(Qn,r.length(),r)}sint64Number(t){let r=Dt.fromNumber(t).zzEncode();return this._push(Qn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ms,1,t?1:0)}fixed32(t){return this._push(an,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Dt.fromBigInt(t);return this._push(an,4,r.lo)._push(an,4,r.hi)}fixed64Number(t){let r=Dt.fromNumber(t);return this._push(an,4,r.lo)._push(an,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Hc,4,t)}double(t){return this._push(Yc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ms,1,0):this.uint32(r)._push(Fh,r,t)}string(t){let r=Wc(t);return r!==0?this.uint32(r)._push(ls,r,t):this._push(ms,1,0)}fork(){return this.states=new ys(this),this.head=this.tail=new Ze(ps,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 Ze(ps,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Ph(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ms(e,t,r){t[r]=e&255}function Oh(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var gs=class extends Ze{next;constructor(t,r){super(Oh,t,r),this.next=void 0}};function Qn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function an(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Fh(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(cn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Lh,t,e),this},cn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nh,t,e),this});function Lh(e,t,r){t.set(e,r)}function Nh(e,t,r){e.length<40?ls(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function bs(){return new cn}function vr(e,t){let r=bs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Tr(e,t,r){let n=sn(e);yield*t.stream(n,void 0,"$",r)}var to={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function eo(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function un(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(s,a){let c=t(s);a.int32(c)},n=function(s){let a=s.int32();return t(a)},o=function*(s){let a=s.int32();yield t(a)};return eo("enum",to.VARINT,r,n,o)}function Ar(e,t,r){return eo("message",to.LENGTH_DELIMITED,e,t,r)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var xs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(xs||(xs={}));(function(e){e.codec=()=>un(xs)})(tt||(tt={}));var ie;(function(e){let t;e.codec=()=>(t==null&&(t=Ar((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),tt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=tt.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:tt.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return vr(i,e.codec())}e.encode=r;function n(i,s){return Sr(i,e.codec(),s)}e.decode=n;function o(i,s){return Tr(i,e.codec(),s)}e.stream=o})(ie||(ie={}));var ws;(function(e){let t;e.codec=()=>(t==null&&(t=Ar((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),tt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=tt.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:tt.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return vr(i,e.codec())}e.encode=r;function n(i,s){return Sr(i,e.codec(),s)}e.decode=n;function o(i,s){return Tr(i,e.codec(),s)}e.stream=o})(ws||(ws={}));var ln={};Et(ln,{MAX_RSA_KEY_SIZE:()=>Es,generateRSAKeyPair:()=>nu,jwkToJWKKeyPair:()=>ou,jwkToPkcs1:()=>$h,jwkToPkix:()=>As,jwkToRSAPrivateKey:()=>Bs,pkcs1MessageToJwk:()=>vs,pkcs1MessageToRSAPrivateKey:()=>Is,pkcs1ToJwk:()=>Kh,pkcs1ToRSAPrivateKey:()=>ru,pkixMessageToJwk:()=>Ts,pkixMessageToRSAPublicKey:()=>_s,pkixToJwk:()=>Mh,pkixToRSAPublicKey:()=>Cs});var Ir=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=ln.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return H.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return eu(this.jwk,r,t,n)}},fn=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=ln.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return tu(this.jwk,t,r)}};var Es=8192,Ss=18,Uh=1062,kh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kh(e){let t=le(e);return vs(t)}function vs(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function $h(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new et("JWK was missing components");return ve([It(Uint8Array.from([0])),It(V(e.n,"base64url")),It(V(e.e,"base64url")),It(V(e.d,"base64url")),It(V(e.p,"base64url")),It(V(e.q,"base64url")),It(V(e.dp,"base64url")),It(V(e.dq,"base64url")),It(V(e.qi,"base64url"))]).subarray()}function Mh(e){let t=le(e,{offset:0});return Ts(t)}function Ts(e){let t=le(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function As(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return ve([kh,Pn(ve([It(V(e.n,"base64url")),It(V(e.e,"base64url"))]))]).subarray()}function ru(e){let t=le(e);return Is(t)}function Is(e){let t=vs(e);return Bs(t)}function Cs(e,t){if(e.byteLength>=Uh)throw new rr("Key size is too large");let r=le(e,{offset:0});return _s(r,e,t)}function _s(e,t,r){let n=Ts(e);if(r==null){let o=hr(ie.encode({Type:tt.RSA,Data:t}));r=Vt(Ss,o)}return new Ir(n,r)}function Bs(e){if(su(e)>Es)throw new et("Key size is too large");let t=ou(e),r=hr(ie.encode({Type:tt.RSA,Data:As(t.publicKey)})),n=Vt(Ss,r);return new fn(t.privateKey,new Ir(t.publicKey,n))}async function nu(e){if(e>Es)throw new et("Key size is too large");let t=await iu(e),r=hr(ie.encode({Type:tt.RSA,Data:As(t.publicKey)})),n=Vt(Ss,r);return new fn(t.privateKey,new Ir(t.publicKey,n))}function ou(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function iu(e,t){let r=await Ut.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Vh(r,t);return{privateKey:n[0],publicKey:n[1]}}async function tu(e,t,r){let n=await Ut.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ut.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function eu(e,t,r,n){let o=await Ut.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ut.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Vh(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([Ut.get().subtle.exportKey("jwk",e.privateKey),Ut.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function su(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return V(e.n,"base64url").length*8}var ro=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(On(t),Rt(r,void 0,"key"),this.iHash=t.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(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),he(o)}update(t){return dr(this),this.iHash.update(t),this}digestInto(t){dr(this),Fn(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},au=(()=>{let e=((t,r,n)=>new ro(t,r).update(n).digest());return e.create=(t,r)=>new ro(t,r),e})();var cu=(e,t)=>(e+(e>=0?t:-t)/uu)/t;function qh(e,t,r){yr("scalar",e,se,r);let[[n,o],[i,s]]=t,a=cu(s*e,r),c=cu(-o*e,r),u=e-a*n-c*i,f=-a*o-c*s,l=u<se,h=f<se;l&&(u=-u),h&&(f=-f);let m=Qr(Math.ceil(gr(r)/2))+Oe;if(u<se||u>=m||f<se||f>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function Ds(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Rs(e,t){jt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return zt(r.lowS,"lowS"),zt(r.prehash,"prehash"),r.format!==void 0&&Ds(r.format),r}var Ps=class extends Error{constructor(t=""){super(t)}},Zt={Err:Ps,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(Ht(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Xr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Xr(o.length/2|128):"";return Xr(e)+i+o+t},decode(e,t){let{Err:r}=Zt;t=Y(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)s=s<<8|f;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=Zt;if(Mn(e),e<se)throw new t("integer: negative integers are not allowed");let r=Xr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,o=Y(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}};Object.freeze(Zt._tlv);Object.freeze(Zt._int);Object.freeze(Zt);var se=BigInt(0),Oe=BigInt(1),uu=BigInt(2),no=BigInt(3),zh=BigInt(4);function fu(e,t={}){let r=Hn("weierstrass",e,t),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;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 f=du(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(P,d,g){if(u&&d.is0())return Uint8Array.of(0);let{x:T,y:b}=d.toAffine(),x=n.toBytes(T);if(zt(g,"isCompressed"),g){l();let I=!n.isOdd(b);return ct(lu(I),x)}else return ct(Uint8Array.of(4),x,n.toBytes(b))}function m(P){Y(P,void 0,"Point");let{publicKey:d,publicKeyUncompressed:g}=f,T=P.length,b=P[0],x=P.subarray(1);if(u&&T===1&&b===0)return{x:n.ZERO,y:n.ZERO};if(T===d&&(b===2||b===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let R=y(I),D;try{D=n.sqrt(R)}catch(j){let G=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}l();let k=n.isOdd(D);return(b&1)===1!==k&&(D=n.neg(D)),{x:I,y:D}}else if(T===g&&b===4){let I=n.BYTES,R=n.fromBytes(x.subarray(0,I)),D=n.fromBytes(x.subarray(I,I*2));if(!S(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${T}, expected compressed=${d} or uncompressed=${g}`)}let E=t.toBytes===void 0?h:t.toBytes,v=t.fromBytes===void 0?m:t.fromBytes;function y(P){let d=n.sqr(P),g=n.mul(d,P);return n.add(n.add(g,n.mul(P,i.a)),i.b)}function S(P,d){let g=n.sqr(d),T=y(P);return n.eql(g,T)}if(!S(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(i.a,no),zh),_=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(A,_)))throw new Error("bad curve params: a or b");function U(P,d,g=!1){if(!n.isValid(d)||g&&n.is0(d))throw new Error(`bad point coordinate ${P}`);return d}function F(P){if(!(P instanceof w))throw new Error("Weierstrass Point expected")}function M(P){if(!c||!c.basises)throw new Error("no endo");return qh(P,c.basises,o.ORDER)}function L(P,d,g,T,b){return g=new w(n.mul(g.X,P),g.Y,g.Z),d=en(T,d),g=en(b,g),d.add(g)}class w{static BASE=new w(i.Gx,i.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,g,T){this.X=U("x",d),this.Y=U("y",g,!0),this.Z=U("z",T),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:g,y:T}=d||{};if(!d||!n.isValid(g)||!n.isValid(T))throw new Error("invalid affine point");if(d instanceof w)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(T)?w.ZERO:new w(g,T,n.ONE)}static fromBytes(d){let g=w.fromAffine(v(Y(d,void 0,"point")));return g.assertValidity(),g}static fromHex(d){return w.fromBytes(mr(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,g=!0){return N.createCache(this,d),g||this.multiply(no),this}assertValidity(){let d=this;if(d.is0()){if(t.allowInfinityPoint&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:T}=d.toAffine();if(!n.isValid(g)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!S(g,T))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){F(d);let{X:g,Y:T,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.eql(n.mul(g,R),n.mul(x,b)),k=n.eql(n.mul(T,R),n.mul(I,b));return D&&k}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:g}=i,T=n.mul(g,no),{X:b,Y:x,Z:I}=this,R=n.ZERO,D=n.ZERO,k=n.ZERO,$=n.mul(b,b),j=n.mul(x,x),G=n.mul(I,I),q=n.mul(b,x);return q=n.add(q,q),k=n.mul(b,I),k=n.add(k,k),R=n.mul(d,k),D=n.mul(T,G),D=n.add(R,D),R=n.sub(j,D),D=n.add(j,D),D=n.mul(R,D),R=n.mul(q,R),k=n.mul(T,k),G=n.mul(d,G),q=n.sub($,G),q=n.mul(d,q),q=n.add(q,k),k=n.add($,$),$=n.add(k,$),$=n.add($,G),$=n.mul($,q),D=n.add(D,$),G=n.mul(x,I),G=n.add(G,G),$=n.mul(G,q),R=n.sub(R,$),k=n.mul(G,j),k=n.add(k,k),k=n.add(k,k),new w(R,D,k)}add(d){F(d);let{X:g,Y:T,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.ZERO,k=n.ZERO,$=n.ZERO,j=i.a,G=n.mul(i.b,no),q=n.mul(g,x),at=n.mul(T,I),ut=n.mul(b,R),ft=n.add(g,T),ot=n.add(x,I);ft=n.mul(ft,ot),ot=n.add(q,at),ft=n.sub(ft,ot),ot=n.add(g,b);let Tt=n.add(x,R);return ot=n.mul(ot,Tt),Tt=n.add(q,ut),ot=n.sub(ot,Tt),Tt=n.add(T,b),D=n.add(I,R),Tt=n.mul(Tt,D),D=n.add(at,ut),Tt=n.sub(Tt,D),$=n.mul(j,ot),D=n.mul(G,ut),$=n.add(D,$),D=n.sub(at,$),$=n.add(at,$),k=n.mul(D,$),at=n.add(q,q),at=n.add(at,q),ut=n.mul(j,ut),ot=n.mul(G,ot),at=n.add(at,ut),ut=n.sub(q,ut),ut=n.mul(j,ut),ot=n.add(ot,ut),q=n.mul(at,ot),k=n.add(k,q),q=n.mul(Tt,ot),D=n.mul(ft,D),D=n.sub(D,q),q=n.mul(ft,at),$=n.mul(Tt,$),$=n.add($,q),new w(D,k,$)}subtract(d){return F(d),this.add(d.negate())}is0(){return this.equals(w.ZERO)}multiply(d){let{endo:g}=t;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let T,b,x=I=>N.cached(this,I,R=>je(w,R));if(g){let{k1neg:I,k1:R,k2neg:D,k2:k}=M(d),{p:$,f:j}=x(R),{p:G,f:q}=x(k);b=j.add(q),T=L(g.beta,$,G,I,D)}else{let{p:I,f:R}=x(d);T=I,b=R}return je(w,[T,b])[0]}multiplyUnsafe(d){let{endo:g}=t,T=this,b=d;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===se||T.is0())return w.ZERO;if(b===Oe)return T;if(N.hasCache(this))return this.multiply(b);if(g){let{k1neg:x,k1:I,k2neg:R,k2:D}=M(b),{p1:k,p2:$}=Oc(w,T,I,D);return L(g.beta,k,$,x,R)}else return N.unsafe(T,b)}toAffine(d){let g=this,T=d,{X:b,Y:x,Z:I}=g;if(n.eql(I,n.ONE))return{x:b,y:x};let R=g.is0();T==null&&(T=R?n.ONE:n.inv(I));let D=n.mul(b,T),k=n.mul(x,T),$=n.mul(I,T);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:D,y:k}}isTorsionFree(){let{isTorsionFree:d}=t;return s===Oe?!0:d?d(w,this):N.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=t;return s===Oe?this:d?d(w,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Oe?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return zt(d,"isCompressed"),this.assertValidity(),E(w,this,d)}toHex(d=!0){return pr(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let C=o.BITS,N=new wr(w,t.endo?Math.ceil(C/2):C);return C>=8&&w.BASE.precompute(8),Object.freeze(w.prototype),Object.freeze(w),w}function lu(e){return Uint8Array.of(e?2:3)}function du(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Hh(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?Wr:t.randomBytes,o=Object.assign(du(e.Fp,r),{seed:Math.max(Vi(r.ORDER),16)});function i(m){try{let E=r.fromBytes(m);return r.isValidNot0(E)}catch{return!1}}function s(m,E){let{publicKey:v,publicKeyUncompressed:y}=o;try{let S=m.length;return E===!0&&S!==v||E===!1&&S!==y?!1:!!e.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,qi(Y(m,o.seed,"seed"),r.ORDER)}function c(m,E=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(E)}function u(m){let{secretKey:E,publicKey:v,publicKeyUncompressed:y}=o,S=r._lengths;if(!Ve(m))return;let A=Y(m,void 0,"key").length,_=A===v||A===y,U=A===E||!!S?.includes(A);if(!(_&&U))return _}function f(m,E,v=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(E)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(m);return e.fromBytes(E).multiply(y).toBytes(v)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=jn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:e,utils:l,lengths:o})}function hu(e,t,r={}){let n=t;On(n),jt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Wr:r.randomBytes,i=r.hmac===void 0?(b,x)=>au(n,b,x):r.hmac,{Fp:s,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:m,lengths:E}=Hh(e,r),v={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*uu+Oe<s.ORDER;function S(b){let x=c>>Oe;return b>x}function A(b,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return x}function _(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function U(b,x){Ds(x);let I=E.signature,R=x==="compact"?I:x==="recovered"?I+1:void 0;return Y(b,R)}class F{r;s;recovery;constructor(x,I,R){if(this.r=A("r",x),this.s=A("s",I),R!=null){if(_(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,I=v.format){U(x,I);let R;if(I==="der"){let{r:j,s:G}=Zt.toSig(Y(x));return new F(j,G)}I==="recovered"&&(R=x[0],I="compact",x=x.subarray(1));let D=E.signature/2,k=x.subarray(0,D),$=x.subarray(D,D*2);return new F(a.fromBytes(k),a.fromBytes($),R)}static fromHex(x,I){return this.fromBytes(mr(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new F(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:R}=this,D=this.assertRecovery(),k=D===2||D===3?I+c:I;if(!s.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let $=s.toBytes(k),j=e.fromBytes(ct(lu((D&1)===0),$)),G=a.inv(k),q=L(Y(x,void 0,"msgHash")),at=a.create(-q*G),ut=a.create(R*G),ft=e.BASE.multiplyUnsafe(at).add(j.multiplyUnsafe(ut));if(ft.is0())throw new Error("invalid recovery: point at infinify");return ft.assertValidity(),ft}hasHighS(){return S(this.s)}toBytes(x=v.format){if(Ds(x),x==="der")return mr(Zt.hexFromSig(this));let{r:I,s:R}=this,D=a.toBytes(I),k=a.toBytes(R);return x==="recovered"?(_(),ct(Uint8Array.of(this.assertRecovery()),D,k)):ct(D,k)}toHex(x){return pr(this.toBytes(x))}}Object.freeze(F.prototype),Object.freeze(F);let M=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=qe(x),R=x.length*8-u;return R>0?I>>BigInt(R):I}:r.bits2int,L=r.bits2int_modN===void 0?function(x){return a.create(M(x))}:r.bits2int_modN,w=Qr(u);function C(b){return yr("num < 2^"+u,b,se,w),a.toBytes(b)}function N(b,x){return Y(b,void 0,"message"),x?Y(n(b),void 0,"prehashed message"):b}function P(b,x,I){let{lowS:R,prehash:D,extraEntropy:k}=Rs(I,v);b=N(b,D);let $=L(b),j=a.fromBytes(x);if(!a.isValidNot0(j))throw new Error("invalid private key");let G=[C(j),C($)];if(k!=null&&k!==!1){let ft=k===!0?o(E.secretKey):k;G.push(Y(ft,void 0,"extraEntropy"))}let q=ct(...G),at=$;function ut(ft){let ot=M(ft);if(!a.isValidNot0(ot))return;let Tt=a.inv(ot),er=e.BASE.multiply(ot).toAffine(),kr=a.create(er.x);if(kr===se)return;let In=a.create(Tt*a.create(at+kr*j));if(In===se)return;let xa=(er.x===kr?0:2)|Number(er.y&Oe),wa=In;return R&&S(In)&&(wa=a.neg(In),xa^=1),new F(kr,wa,y?void 0:xa)}return{seed:q,k2sig:ut}}function d(b,x,I={}){let{seed:R,k2sig:D}=P(b,x,I);return yc(n.outputLen,a.BYTES,i)(R,D).toBytes(I.format)}function g(b,x,I,R={}){let{lowS:D,prehash:k,format:$}=Rs(R,v);if(I=Y(I,void 0,"publicKey"),x=N(x,k),!Ve(b)){let j=b instanceof F?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+j)}U(b,$);try{let j=F.fromBytes(b,$),G=e.fromBytes(I);if(D&&j.hasHighS())return!1;let{r:q,s:at}=j,ut=L(x),ft=a.inv(at),ot=a.create(ut*ft),Tt=a.create(q*ft),er=e.BASE.multiplyUnsafe(ot).add(G.multiplyUnsafe(Tt));return er.is0()?!1:a.create(er.x)===q}catch{return!1}}function T(b,x,I={}){let{prehash:R}=Rs(I,v);return x=N(x,R),F.fromBytes(b,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:m,lengths:E,Point:e,sign:d,verify:g,recoverPublicKey:T,Signature:F,hash:n})}var Fs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pu=BigInt(2);function Yh(e){let t=Fs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=J(f,r,t)*f%t,h=J(l,r,t)*f%t,m=J(h,pu,t)*u%t,E=J(m,o,t)*m%t,v=J(E,i,t)*E%t,y=J(v,a,t)*v%t,S=J(y,c,t)*y%t,A=J(S,a,t)*v%t,_=J(A,r,t)*f%t,U=J(_,s,t)*E%t,F=J(U,n,t)*u%t,M=J(F,pu,t);if(!Os.eql(Os.sqr(M),e))throw new Error("Cannot find square root");return M}var Os=br(Fs.p,{sqrt:Yh}),Zh=fu(Fs,{Fp:Os,endo:jh}),Cr=hu(Zh,hr);function mu(e,t,r,n){let o=Vr.digest(r instanceof Uint8Array?r:r.subarray());if(Wn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Cr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new nn(String(i))});try{return n?.signal?.throwIfAborted(),Cr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new nn(String(i))}}var oo=class{type="secp256k1";raw;_key;constructor(t){this._key=gu(t),this.raw=yu(this._key)}toMultihash(){return St.digest(lr(this))}toCID(){return H.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return mu(this._key,r,t,n)}};function Ls(e){return new oo(e)}function yu(e){return Cr.Point.fromBytes(e).toBytes()}function gu(e){try{return Cr.Point.fromBytes(e),e}catch(t){throw new rr(String(t))}}function bu(e,t){let{Type:r,Data:n}=ie.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return Cs(o,t);case tt.Ed25519:return rs(o);case tt.secp256k1:return Ls(o);case tt.ECDSA:return Ai(o);default:throw new or}}function io(e){let{Type:t,Data:r}=ie.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return rs(n);case tt.secp256k1:return Ls(n);case tt.ECDSA:return Ai(n);default:throw new or}}function lr(e){return ie.encode({Type:tt[e.type],Data:e.raw})}var xu=Symbol.for("nodejs.util.inspect.custom"),Gh=114,dn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Bn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return H.createV1(Gh,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[xu](){return`PeerId(${this.toString()})`}},so=class extends dn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ao=class extends dn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},co=class extends dn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wh=2336,hn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=St.digest(V(this.url))}[xu](){return`PeerId(${this.url})`}[Bn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return H.createV1(Wh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Xh=114,wu=2336;function Eu(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Se(X.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Ns(H.parse(e));if(t==null)throw new et('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Se(t.decode(e))}return uo(r)}function uo(e){if(Qh(e))return new so({multihash:e});if(Jh(e))try{let t=io(e);if(t.type==="Ed25519")return new ao({multihash:e,publicKey:t});if(t.type==="secp256k1")return new co({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new hn(new URL(r))}throw new nr("Supplied PeerID Multihash is invalid")}function Ns(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Xh&&e.code!==wu)throw new _n("Supplied PeerID CID is invalid");if(e.code===wu){let t=z(e.multihash.digest);return new hn(new URL(t))}return uo(e.multihash)}function Jh(e){return e.code===St.code}function Qh(e){return e.code===Vr.code}var gt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ge=class extends Error{static name="ValidationError";name="ValidationError"},fo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},lo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ho=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}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(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});if(f===void 0)break;if(i*=t,i+=f,i>u||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[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];r[o]=i>>8,r[o+1]=i&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=t(i.subarray(0,s));return r.set(i.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var tp=45,ep=15,po=new ho;function Su(e){if(!(e.length>ep))return po.new(e).parseWith(()=>po.readIPv4Addr())}function vu(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>tp))return po.new(e).parseWith(()=>po.readIPv6Addr())}function mo(e){return!!Su(e)}function Tu(e){return!!vu(e)}function ks(e){return t=>z(t,e)}function Ks(e){return t=>V(t,e)}function _r(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Ge(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Au(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ge(n);return Nt([r,o],r.length+o.length)}function Iu(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=te.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ge(n);return Nt([r,o],r.length+o.length)}function $s(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=_r(r);return`${n}:${o}`}var Ms=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new gt("Invalid byte value in IP address");t[n]=o}),t},Cu=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=mo(r[n]),s;i&&(s=Ms(r[n]),r[n]=z(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new gt("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},_u=function(e){if(e.byteLength!==4)throw new gt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Bu=function(e){if(e.byteLength!==16)throw new gt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],i=e[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;t.push(s)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${r}"`)}};function Ru(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${e}"`)}}var Us=Object.values(qr).map(e=>e.decoder),rp=(function(){let e=Us[0].or(Us[1]);return Us.slice(2).forEach(t=>e=e.or(t)),e})();function Du(e){return rp.decode(e)}function Pu(e){return t=>e.encoder.encode(t)}function np(e){if(parseInt(e).toString()!==e)throw new ge("Value must be an integer")}function op(e){if(e<0)throw new ge("Value must be a positive integer, or zero")}function ip(e){return t=>{if(t>e)throw new ge(`Value must be smaller than or equal to ${e}`)}}function sp(...e){return t=>{for(let r of e)r(t)}}var pn=sp(np,op,ip(65535));var dt=-1,Vs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new lo(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},be=new Vs,Yp=[{code:4,name:"ip4",size:32,valueToBytes:Ms,bytesToValue:_u,validate:e=>{if(!mo(e))throw new ge(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:273,name:"udp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:33,name:"dccp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:41,name:"ip6",size:128,valueToBytes:Cu,bytesToValue:Bu,stringToValue:Ru,validate:e=>{if(!Tu(e))throw new ge(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:ks("base10"),valueToBytes:Ks("base10")},{code:53,name:"dns",size:dt},{code:54,name:"dns4",size:dt},{code:55,name:"dns6",size:dt},{code:56,name:"dnsaddr",size:dt},{code:132,name:"sctp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:ks("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ks("base58btc")(e):H.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:$s,valueToBytes:Au},{code:445,name:"onion3",size:296,bytesToValue:$s,valueToBytes:Iu},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Pu(di),valueToBytes:Du},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.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:dt}];Yp.forEach(e=>{be.addProtocol(e)});function Ou(e){let t=[],r=0;for(;r<e.length;){let n=cs(e,r),o=be.getProtocol(n),i=oe(n),s=Zp(o,e,r+i),a=0;s>0&&o.size===dt&&(a=oe(s));let c=i+a+s,u={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(s>0){let f=r+i+a,l=e.subarray(f,f+s);u.value=o.bytesToValue?.(l)??z(l)}t.push(u),r+=c}return t}function Fu(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=be.getProtocol(n.code),i=oe(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??V(n.value),a=s.byteLength,o.size===dt&&(c=oe(a)));let u=new Uint8Array(i+c+a),f=0;on(n.code,u,f),f+=i,s!=null&&(o.size===dt&&(on(a,u,f),f+=c),u.set(s,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Nt(r,t)}function Lu(e){if(e.charAt(0)!=="/")throw new gt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let i=1;i<e.length;i++){let s=e.charAt(i);s!=="/"&&(r==="protocol"?o+=e.charAt(i):n+=e.charAt(i));let a=i===e.length-1;if(s==="/"||a){let c=be.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new gt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new gt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new gt("Incomplete multiaddr");return t}function Nu(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=be.getProtocol(t.code);if(r==null)throw new gt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Zp(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:cs(t,r)}var Gp=Symbol.for("nodejs.util.inspect.custom"),qs=Symbol.for("@multiformats/multiaddr");function Wp(e){if(e==null&&(e="/"),Uu(e))return e.getComponents();if(e instanceof Uint8Array)return Ou(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Lu(e);if(Array.isArray(e))return e;throw new gt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var yo=class e{[qs]=!0;#t;#n;#r;constructor(t="/",r={}){this.#t=Wp(t),r.validate!==!1&&Xp(this)}get bytes(){return this.#r==null&&(this.#r=Fu(this.#t)),this.#r}toString(){return this.#n==null&&(this.#n=Nu(this.#t)),this.#n}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new fo(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return W(this.bytes,t.bytes)}[Gp](){return`Multiaddr(${this.toString()})`}};function Xp(e){e.getComponents().forEach(t=>{let r=be.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Uu(e){return!!e?.[qs]}function go(e){return new yo(e)}function Br(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*mn(e,t={}){let r=e.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}function Jp(e,t){if(typeof e=="string")return Qp(e);if(typeof e=="number")return r0(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var bo=Jp;function Qp(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<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(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),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(e)}`)}}function t0(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function e0(e){let t=Math.abs(e);return t>=315576e5?We(e,t,315576e5,"year"):t>=26298e5?We(e,t,26298e5,"month"):t>=6048e5?We(e,t,6048e5,"week"):t>=864e5?We(e,t,864e5,"day"):t>=36e5?We(e,t,36e5,"hour"):t>=6e4?We(e,t,6e4,"minute"):t>=1e3?We(e,t,1e3,"second"):`${e} ms`}function r0(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?e0(e):t0(e)}function We(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function zs(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=bo,r.destroy=u,Object.keys(e).forEach(f=>{r[f]=e[f]}),r.names=[],r.skips=[],r.formatters={};function t(f){let l=0;for(let h=0;h<f.length;h++)l=(l<<5)-l+f.charCodeAt(h),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(f,l){let h,m=null,E,v;function y(...S){if(!y.enabled)return;let A=y,_=Number(new Date),U=_-(h||_);A.diff=U,A.prev=h,A.curr=_,h=_,S[0]=r.coerce(S[0]),typeof S[0]!="string"&&S.unshift("%O");let F=0;S[0]=S[0].replace(/%([a-zA-Z%])/g,(L,w)=>{if(L==="%%")return"%";F++;let C=r.formatters[w];if(typeof C=="function"){let N=S[F];L=C.call(A,N),S.splice(F,1),F--}return L}),r.formatArgs.call(A,S),l?.onLog!=null&&l.onLog(...S),(A.log||r.log).apply(A,S)}return y.namespace=f,y.useColors=r.useColors(),y.color=r.selectColor(f),y.extend=n,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(E!==r.namespaces&&(E=r.namespaces,v=r.enabled(f)),v),set:S=>{m=S}}),typeof r.init=="function"&&r.init(y),y}function n(f,l){let h=r(this.namespace+(typeof l>"u"?":":l)+f);return h.log=this.log,h}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,h=(typeof f=="string"?f:"").split(/[\s,]+/),m=h.length;for(l=0;l<m;l++)h[l]&&(f=h[l].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,h;for(l=0,h=r.skips.length;l<h;l++)if(r.skips[l].test(f))return!1;for(l=0,h=r.names.length;l<h;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function c(f){return f instanceof Error?f.stack??f.message:f}function u(){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 r.setupFormatters(r.formatters),r.enable(r.load()),r}var xo=u0(),n0=["#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 o0(){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 i0(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+bo(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var s0=console.debug??console.log??(()=>{});function a0(e){try{e?xo?.setItem("debug",e):xo?.removeItem("debug")}catch{}}function c0(){let e;try{e=xo?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function u0(){try{return localStorage}catch{}}function f0(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ku=zs({formatArgs:i0,save:a0,load:c0,useColors:o0,setupFormatters:f0,colors:n0,storage:xo,log:s0});var Ct=ku;Ct.formatters.b=e=>e==null?"undefined":X.baseEncode(e);Ct.formatters.t=e=>e==null?"undefined":te.baseEncode(e);Ct.formatters.m=e=>e==null?"undefined":li.baseEncode(e);Ct.formatters.p=e=>e==null?"undefined":e.toString();Ct.formatters.c=e=>e==null?"undefined":e.toString();Ct.formatters.k=e=>e==null?"undefined":e.toString();Ct.formatters.a=e=>e==null?"undefined":e.toString();function Ku(e,t=""){let r=$u(e.message),n=$u(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
- `).join(`
5
- ${t}`)}`:`${r}
6
- ${t}${n.split(`
7
- `).join(`
8
- ${t}`)}`:n!=null?`${n.split(`
9
- `).join(`
10
- ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function l0(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Mu(e,t=""){if(l0(e)){let r=Ku(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
- ${t}${e.errors.map(n=>`${Mu(n,`${t}`)}`).join(`
12
- ${t}`)}`):r+=`
13
- ${t}[Error list was empty]`,r.trim()}return Ku(e,t)}Ct.formatters.e=e=>e==null?"undefined":Mu(e);function d0(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function Xe(e,t){let r=d0(`${e}:trace`);return Ct.enabled(`${e}:trace`)&&Ct.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Ct(`${e}:trace`,t)),Object.assign(Ct(e,t),{error:Ct(`${e}:error`,t),trace:r,newScope:n=>Xe(`${e}:${n}`,t)})}function $u(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Z0=Go(js(),1);var Gt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},wo=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Rr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Eo=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},So=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},vo=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},yn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var Wt;(function(e){let t;(function(a){a.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>un(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Ar((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),e.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.pubKey!=null&&(c.uint32(58),c.bytes(a.pubKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=e.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.pubKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(h&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:e.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.pubKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return vr(a,e.codec())}e.encode=o;function i(a,c){return Sr(a,e.codec(),c)}e.decode=i;function s(a,c){return Tr(a,e.codec(),c)}e.stream=s})(Wt||(Wt={}));var h0=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function Vu(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=p0(e);return r||"Object"}function p0(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(h0.includes(t))return t}var p=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};p.uint=new p(0,"uint",!0);p.negint=new p(1,"negint",!0);p.bytes=new p(2,"bytes",!0);p.string=new p(3,"string",!0);p.array=new p(4,"array",!1);p.map=new p(5,"map",!1);p.tag=new p(6,"tag",!1);p.float=new p(7,"float",!0);p.false=new p(7,"false",!0);p.true=new p(7,"true",!0);p.null=new p(7,"null",!0);p.undefined=new p(7,"undefined",!0);p.break=new p(7,"break",!0);var O=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var gn=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",m0=new TextEncoder;function To(e){return gn&&globalThis.Buffer.isBuffer(e)}function bn(e){return e instanceof Uint8Array?To(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var y0=24,g0=200,Ys=gn?e=>e.length>=y0?globalThis.Buffer.from(e):qu(e):e=>e.length>=g0?m0.encode(e):qu(e),ae=e=>Uint8Array.from(e),zu=gn?(e,t,r)=>To(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Hu=gn?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),bn(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},ju=gn?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Ao(e,t){if(To(e)&&To(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function qu(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var b0=256,xn=class{constructor(t=b0){this.chunkSize=t,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(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=ju(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=zu(n,0,this.cursor)}else r=Hu(this.chunks,this.cursor);return t&&this.reset(),r}},Io=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var K="CBOR decode error:",Zs="CBOR encode error:",wn=[];wn[23]=1;wn[24]=2;wn[25]=3;wn[26]=5;wn[27]=9;function xe(e,t,r){if(e.length-t<r)throw new Error(`${K} not enough data for type`)}var ht=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Pt(e,t,r){xe(e,t,1);let n=e[t];if(r.strict===!0&&n<ht[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ot(e,t,r){xe(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ht[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ft(e,t,r){xe(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ht[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(e,t,r){xe(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ht[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function Yu(e,t,r,n){return new O(p.uint,Pt(e,t+1,n),2)}function Zu(e,t,r,n){return new O(p.uint,Ot(e,t+1,n),3)}function Gu(e,t,r,n){return new O(p.uint,Ft(e,t+1,n),5)}function Wu(e,t,r,n){return new O(p.uint,Lt(e,t+1,n),9)}function kt(e,t){return pt(e,0,t.value)}function pt(e,t,r){if(r<ht[0]){let n=Number(r);e.push([t|n])}else if(r<ht[1]){let n=Number(r);e.push([t|24,n])}else if(r<ht[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ht[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<ht[4]){let o=[t|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,e.push(o)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}kt.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<ht[0]?1:t<ht[1]?2:t<ht[2]?3:t<ht[3]?5:9};kt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Xu(e,t,r,n){return new O(p.negint,-1-Pt(e,t+1,n),2)}function Ju(e,t,r,n){return new O(p.negint,-1-Ot(e,t+1,n),3)}function Qu(e,t,r,n){return new O(p.negint,-1-Ft(e,t+1,n),5)}var Gs=BigInt(-1),tf=BigInt(1);function ef(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new O(p.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new O(p.negint,Gs-BigInt(o),9)}function Co(e,t){let r=t.value,n=typeof r=="bigint"?r*Gs-tf:r*-1-1;pt(e,t.type.majorEncoded,n)}Co.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Gs-tf:r*-1-1;return n<ht[0]?1:n<ht[1]?2:n<ht[2]?3:n<ht[3]?5:9};Co.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function En(e,t,r,n){xe(e,t,r+n);let o=e.slice(t+r,t+r+n);return new O(p.bytes,o,r+n)}function rf(e,t,r,n){return En(e,t,1,r)}function nf(e,t,r,n){return En(e,t,2,Pt(e,t+1,n))}function of(e,t,r,n){return En(e,t,3,Ot(e,t+1,n))}function sf(e,t,r,n){return En(e,t,5,Ft(e,t+1,n))}function af(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return En(e,t,9,o)}function _o(e){return e.encodedBytes===void 0&&(e.encodedBytes=p.equals(e.type,p.string)?Ys(e.value):e.value),e.encodedBytes}function Dr(e,t){let r=_o(t);pt(e,t.type.majorEncoded,r.length),e.push(r)}Dr.encodedSize=function(t){let r=_o(t);return pt.encodedSize(r.length)+r.length};Dr.compareTokens=function(t,r){return w0(_o(t),_o(r))};function w0(e,t){return e.length<t.length?-1:e.length>t.length?1:Ao(e,t)}var cf=new TextDecoder,S0=32;function v0(e,t,r){if(r-t<S0){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return cf.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return cf.decode(e.subarray(t,r))}function Sn(e,t,r,n,o){let i=r+n;xe(e,t,i);let s=new O(p.string,v0(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function uf(e,t,r,n){return Sn(e,t,1,r,n)}function ff(e,t,r,n){return Sn(e,t,2,Pt(e,t+1,n),n)}function lf(e,t,r,n){return Sn(e,t,3,Ot(e,t+1,n),n)}function df(e,t,r,n){return Sn(e,t,5,Ft(e,t+1,n),n)}function hf(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return Sn(e,t,9,o,n)}var pf=Dr;function Pr(e,t,r,n){return new O(p.array,n,r)}function mf(e,t,r,n){return Pr(e,t,1,r)}function yf(e,t,r,n){return Pr(e,t,2,Pt(e,t+1,n))}function gf(e,t,r,n){return Pr(e,t,3,Ot(e,t+1,n))}function bf(e,t,r,n){return Pr(e,t,5,Ft(e,t+1,n))}function xf(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return Pr(e,t,9,o)}function wf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return Pr(e,t,1,1/0)}function Bo(e,t){pt(e,p.array.majorEncoded,t.value)}Bo.compareTokens=kt.compareTokens;Bo.encodedSize=function(t){return pt.encodedSize(t.value)};function Or(e,t,r,n){return new O(p.map,n,r)}function Ef(e,t,r,n){return Or(e,t,1,r)}function Sf(e,t,r,n){return Or(e,t,2,Pt(e,t+1,n))}function vf(e,t,r,n){return Or(e,t,3,Ot(e,t+1,n))}function Tf(e,t,r,n){return Or(e,t,5,Ft(e,t+1,n))}function Af(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return Or(e,t,9,o)}function If(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return Or(e,t,1,1/0)}function Ro(e,t){pt(e,p.map.majorEncoded,t.value)}Ro.compareTokens=kt.compareTokens;Ro.encodedSize=function(t){return pt.encodedSize(t.value)};function Cf(e,t,r,n){return new O(p.tag,r,1)}function _f(e,t,r,n){return new O(p.tag,Pt(e,t+1,n),2)}function Bf(e,t,r,n){return new O(p.tag,Ot(e,t+1,n),3)}function Rf(e,t,r,n){return new O(p.tag,Ft(e,t+1,n),5)}function Df(e,t,r,n){return new O(p.tag,Lt(e,t+1,n),9)}function Do(e,t){pt(e,p.tag.majorEncoded,t.value)}Do.compareTokens=kt.compareTokens;Do.encodedSize=function(t){return pt.encodedSize(t.value)};var Ws=20,Xs=21,Js=22,Qs=23;function Pf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new O(p.null,null,1):new O(p.undefined,void 0,1)}function Of(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new O(p.break,void 0,1)}function ta(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new O(p.float,e,t)}function Ff(e,t,r,n){return ta(ea(e,t+1),3,n)}function Lf(e,t,r,n){return ta(ra(e,t+1),5,n)}function Nf(e,t,r,n){return ta($f(e,t+1),9,n)}function Po(e,t,r){let n=t.value;if(n===!1)e.push([p.float.majorEncoded|Ws]);else if(n===!0)e.push([p.float.majorEncoded|Xs]);else if(n===null)e.push([p.float.majorEncoded|Js]);else if(n===void 0)e.push([p.float.majorEncoded|Qs]);else{let o,i=!1;(!r||r.float64!==!0)&&(kf(n),o=ea(Xt,1),n===o||Number.isNaN(n)?(Xt[0]=249,e.push(Xt.slice(0,3)),i=!0):(Kf(n),o=ra(Xt,1),n===o&&(Xt[0]=250,e.push(Xt.slice(0,5)),i=!0))),i||(_0(n),o=$f(Xt,1),Xt[0]=251,e.push(Xt.slice(0,9)))}}Po.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){kf(n);let o=ea(Xt,1);if(n===o||Number.isNaN(n))return 3;if(Kf(n),o=ra(Xt,1),n===o)return 5}return 9};var Uf=new ArrayBuffer(9),Kt=new DataView(Uf,1),Xt=new Uint8Array(Uf,0);function kf(e){if(e===1/0)Kt.setUint16(0,31744,!1);else if(e===-1/0)Kt.setUint16(0,64512,!1);else if(Number.isNaN(e))Kt.setUint16(0,32256,!1);else{Kt.setFloat32(0,e);let t=Kt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Kt.setUint16(0,31744,!1);else if(r===0)Kt.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Kt.setUint16(0,0):o<-14?Kt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Kt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ea(e,t){if(e.length-t<2)throw new Error(`${K} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Kf(e){Kt.setFloat32(0,e,!1)}function ra(e,t){if(e.length-t<4)throw new Error(`${K} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function _0(e){Kt.setFloat64(0,e,!1)}function $f(e,t){if(e.length-t<8)throw new Error(`${K} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Po.compareTokens=kt.compareTokens;function Z(e,t,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Oo(e){return()=>{throw new Error(`${K} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=Yu;B[25]=Zu;B[26]=Gu;B[27]=Wu;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=Xu;B[57]=Ju;B[58]=Qu;B[59]=ef;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=rf;B[88]=nf;B[89]=of;B[90]=sf;B[91]=af;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=Oo("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=uf;B[120]=ff;B[121]=lf;B[122]=df;B[123]=hf;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=Oo("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=mf;B[152]=yf;B[153]=gf;B[154]=bf;B[155]=xf;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=wf;for(let e=160;e<=183;e++)B[e]=Ef;B[184]=Sf;B[185]=vf;B[186]=Tf;B[187]=Af;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=If;for(let e=192;e<=215;e++)B[e]=Cf;B[216]=_f;B[217]=Bf;B[218]=Rf;B[219]=Df;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=Oo("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=Pf;B[248]=Oo("simple values are not supported");B[249]=Ff;B[250]=Lf;B[251]=Nf;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=Of;var Jt=[];for(let e=0;e<24;e++)Jt[e]=new O(p.uint,e,1);for(let e=-1;e>=-24;e--)Jt[31-e]=new O(p.negint,e,1);Jt[64]=new O(p.bytes,new Uint8Array(0),1);Jt[96]=new O(p.string,"",1);Jt[128]=new O(p.array,0,1);Jt[160]=new O(p.map,0,1);Jt[244]=new O(p.false,!1,1);Jt[245]=new O(p.true,!0,1);Jt[246]=new O(p.null,null,1);function Mf(e){switch(e.type){case p.false:return ae([244]);case p.true:return ae([245]);case p.null:return ae([246]);case p.bytes:return e.value.length?void 0:ae([64]);case p.string:return e.value===""?ae([96]):void 0;case p.array:return e.value===0?ae([128]):void 0;case p.map:return e.value===0?ae([160]):void 0;case p.uint:return e.value<24?ae([Number(e.value)]):void 0;case p.negint:if(e.value>=-24)return ae([31-Number(e.value)])}}var qf=Object.freeze({float64:!0,mapSorter:F0,quickEncodeToken:Mf});function R0(){let e=[];return e[p.uint.major]=kt,e[p.negint.major]=Co,e[p.bytes.major]=Dr,e[p.string.major]=pf,e[p.array.major]=Bo,e[p.map.major]=Ro,e[p.tag.major]=Do,e[p.float.major]=Po,e}var D0=R0(),P0=new xn,Fo=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${Zs} object contains circular references`);return new e(r,t)}},Fe={null:new O(p.null,null),undefined:new O(p.undefined,void 0),true:new O(p.true,!0),false:new O(p.false,!1),emptyArray:new O(p.array,0),emptyMap:new O(p.map,0)},Le={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new O(p.float,e):e>=0?new O(p.uint,e):new O(p.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new O(p.uint,e):new O(p.negint,e)},Uint8Array(e,t,r,n){return new O(p.bytes,e)},string(e,t,r,n){return new O(p.string,e)},boolean(e,t,r,n){return e?Fe.true:Fe.false},null(e,t,r,n){return Fe.null},undefined(e,t,r,n){return Fe.undefined},ArrayBuffer(e,t,r,n){return new O(p.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new O(p.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Fe.emptyArray,new O(p.break)]:Fe.emptyArray;n=Fo.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Fr(s,r,n);return r.addBreakTokens?[new O(p.array,e.length),o,new O(p.break)]:[new O(p.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length,a;if(s){a=new Array(s),n=Fo.createCheck(n,e);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let l=o?e.get(f):e[f];c&&l===void 0||(a[u++]=[Fr(f,r,n),Fr(l,r,n)])}u<s&&(a.length=u)}return a?.length?(O0(a,r),r.addBreakTokens?[new O(p.map,a.length),a,new O(p.break)]:[new O(p.map,a.length),a]):r.addBreakTokens===!0?[Fe.emptyMap,new O(p.break)]:Fe.emptyMap},Tagged(e,t,r,n){return[new O(p.tag,e.tag),Fr(e.value,r,n)]}};Le.Map=Le.Object;Le.Buffer=Le.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Le[`${e}Array`]=Le.DataView;function Fr(e,t={},r){let n=Vu(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Le[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Le[n];if(!i)throw new Error(`${Zs} unsupported type: ${n}`);return i(e,n,t,r)}function O0(e,t){t.mapSorter&&e.sort(t.mapSorter)}function F0(e,t){if(e[0]instanceof O&&t[0]instanceof O){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Vf(r.value)),n._keyBytes||(n._keyBytes=Vf(n.value)),Ao(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Vf(e){return L0(e,D0,qf)}function zf(e,t,r,n){if(Array.isArray(t))for(let o of t)zf(e,o,r,n);else r[t.type.major](e,t,n)}var l2=p.uint.majorEncoded,d2=p.negint.majorEncoded,h2=p.bytes.majorEncoded,p2=p.string.majorEncoded,m2=p.array.majorEncoded,y2=p.float.majorEncoded|Ws,g2=p.float.majorEncoded|Xs,b2=p.float.majorEncoded|Js,x2=p.float.majorEncoded|Qs,w2=BigInt(-1),E2=BigInt(1);function L0(e,t,r,n){let o=n instanceof Uint8Array,i=o?new Io(n):P0,s=Fr(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=t[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new xn(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():bn(i.chunks[0])}}return i.reset(),zf(i,s,t,r),i.toBytes(!0)}var N0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Lo=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=Jt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${K} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Ne=Symbol.for("DONE"),Lr=Symbol.for("BREAK");function U0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ue(t,r);if(i===Lr){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Ne)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function k0(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=Ue(t,r);if(c===Lr){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(c===Ne)throw new Error(`${K} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(!n&&typeof c!="string")throw new Error(`${K} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${K} found repeat map key "${c}"`);let u=Ue(t,r);if(u===Ne)throw new Error(`${K} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*K0(e,t,r){for(let n=0;n<e.value;n++){let o=Ue(t,r);if(o===Lr){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(o===Ne)throw new Error(`${K} found map but not enough entries (got ${n} [no key], expected ${e.value})`);let i=Ue(t,r);if(i===Ne)throw new Error(`${K} found map but not enough entries (got ${n} [no value], expected ${e.value})`);yield[o,i]}}function $0(e,t){let r=!1,n=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=Ue(e,t);if(o===Ne)throw new Error(`${K} tag content missing`);if(o===Lr)throw new Error(`${K} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=e.next();if(!p.equals(o.type,p.map))throw new Error(`${K} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of K0(o,e,t))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Ue(e,t){if(e.done())return Ne;let r=e.next();if(p.equals(r.type,p.break))return Lr;if(r.type.terminal)return r.value;if(p.equals(r.type,p.array))return U0(r,e,t);if(p.equals(r.type,p.map))return k0(r,e,t);if(p.equals(r.type,p.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=$0(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${K} tag decoder must call decode() or entries()`);return o}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function Hf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);t=Object.assign({},N0,t);let r=bn(e),n=t.tokenizer||new Lo(r,t),o=Ue(n,t);if(o===Ne)throw new Error(`${K} did not find any content to decode`);if(o===Lr)throw new Error(`${K} got unexpected break`);return[o,e.subarray(n.pos())]}function na(e,t){let[r,n]=Hf(e,t);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var No=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(No.prototype,Symbol.toStringTag,{value:"Tagged"});var q0=Xe("ipns:utils"),jf=V("/ipns/");var z0=0,H0=18;function Yf(e){let t;if(e.pubKey!=null)try{t=bu(e.pubKey)}catch(r){throw q0.error(r),r}if(t!=null)return t}function Zf(e){let t=V("ipns-signature:");return Nt([t,e])}function Qe(e){return"signatureV1"in e?Wt.encode({value:V(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:V(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):Wt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function ce(e){let t=Wt.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new Gt("Missing data or signatureV2");let r=Gf(t.data),n=j0(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Y0(t),{value:n,validityType:Wt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:Wt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function vn(e){return Nt([jf,e.bytes])}function we(e){let t=Se(e.slice(jf.length));if(!Uo(t,z0)&&!Uo(t,H0))throw new nr("Multihash in IPNS key was not identity or sha2-256");return t}function Gf(e){let t=na(e);if(t.ValidityType===0)t.ValidityType=Wt.ValidityType.EOL;else throw new Rr("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function j0(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${H.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${H.parse(t).toV1().toString()}`}catch{}throw new So("Value must be a valid content path starting with /")}function Y0(e){if(e.data==null)throw new vo("Record data is missing");let t=Gf(e.data);if(!W(t.Value,e.value??new Uint8Array(0)))throw new Gt('Field "value" did not match between protobuf and CBOR');if(!W(t.Validity,e.validity??new Uint8Array(0)))throw new Gt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Gt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Gt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Gt('Field "ttl" did not match between protobuf and CBOR')}function Uo(e,t){return e.code===t}var Z2=Xe("ipns"),G2=300*1e9,G0="/ipns/",W2=G0.length;var Wf=Go(js(),1);var ko=Xe("ipns:validator"),W0=1024*10;async function X0(e,t){let r=ce(t),n;try{let o=Zf(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw ko.error("record signature verification failed"),new Gt("Record signature verification failed");if(r.validityType===Wt.ValidityType.EOL){if(Wf.default.fromString(r.validity).toDate().getTime()<Date.now())throw ko.error("record has expired"),new wo("record has expired")}else if(r.validityType!=null)throw ko.error("the validity type is unsupported"),new Rr("The validity type is unsupported");ko("ipns record for %s is valid",r.value)}async function Xf(e,t){if(t.byteLength>W0)throw new Eo("The record is too large");let r=we(e),n;Uo(r,0)&&(n=io(r));let o=ce(t),i=Yf(o)??n;if(i==null)throw new yn("Could not extract public key from IPNS record or routing key");let s=vn(i.toMultihash());if(!W(s,e))throw new yn("Embedded public key did not match routing key");await X0(i,t)}var Ko=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*Nr(e,t={}){let r=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let i of e){if(typeof i=="string"&&(i=new TextEncoder().encode(i)),ur(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new Ko("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let a=0;a<s.length;a++)yield JSON.parse(s[a])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function $t(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var ia=Go(Qf(),1);var sa=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},tl=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function aa(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){h(tl(s));return}if(s&&(c=()=>{h(tl(s))},s.addEventListener("abort",c,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let m=new sa;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(E){h(E)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?h(o):(m.message=o??`Promise timed out after ${r} milliseconds`,h(m))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}function ca(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var Ur=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=ca(this.#t,i,(a,c)=>c.priority-a.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}remove(t){let r=this.#t.findIndex(n=>typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var An=class extends ia.default{#t;#n;#r=0;#h;#m=!1;#x=!1;#c;#C=0;#w=0;#u;#f;#a;#s=[];#i=0;#e;#_;#o=0;#y;#l;#O=1n;#g=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ur,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#e=new t.queueClass,this.#_=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#M()}#S(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#F(t){this.#a?this.#s.push(t):this.#r++}#L(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#r>0&&this.#r--}#v(){return this.#s.length-this.#i}get#N(){return this.#n?!0:this.#a?this.#v()<this.#h:this.#r<this.#h}get#U(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#b(),this.emit("next")}#K(){this.#f=void 0,this.#D(),this.#R()}#$(t){if(this.#a){if(this.#S(t),this.#v()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#T(o),!0}return!1}if(this.#u===void 0){let r=this.#C-t;if(r<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#T(this.#c-n),!0}this.#r=this.#t?this.#o:0}else return this.#T(r),!0}return!1}#T(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#A(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#b(){if(this.#e.size===0){if(this.#A(),this.emit("empty"),this.#o===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#$(r);if(this.#N&&this.#U){let o=this.#e.dequeue();this.#n||(this.#F(r),this.#p()),this.emit("active"),o(),n&&this.#R(),t=!0}}return t}#R(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#C=Date.now()+this.#c)}#D(){this.#a||(this.#r===0&&this.#o===0&&this.#u&&this.#A(),this.#r=this.#t?this.#o:0),this.#I(),this.#p()}#I(){for(;this.#b(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#I()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#O++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#V(),this.#g.delete(i),h}this.#w=Date.now();let f=t({signal:r.signal});if(r.timeout&&(f=aa(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#e.size} waiting)`})),r.signal){let{signal:h}=r;f=Promise.race([f,new Promise((m,E)=>{u=()=>{E(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){o(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(i),queueMicrotask(()=>{this.#k()})}};this.#e.enqueue(a,r);let c=()=>{if(this.#e instanceof Ur){this.#e.remove(a);return}this.#e.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{s(),c(),o(u.reason),this.#b(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",f),this.#E.delete(s)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(s)}this.emit("add"),this.#b()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#e=new this.#_,this.#A(),this.#P(),this.emit("empty"),this.#o===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#d("next",()=>this.#e.size<t)}async onIdle(){this.#o===0&&this.#e.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#M(){this.#n||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#P()}))}#V(){this.#n||(this.#L(),this.#p())}#P(){let t=this.#m;if(this.#n||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#S(o),r=this.#v()}else r=this.#r;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var tr=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Mt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function tm(e){return e[Symbol.asyncIterator]!=null}function em(e){if(tm(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var Mo=em;function rm(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[r](){return this}}}var el=rm;function nm(e){return e[Symbol.asyncIterator]!=null}function om(e,t){let r=0;if(nm(e))return(async function*(){for await(let c of e)yield t(c,r++)})();let n=el(e),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=t(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield t(c,r++)})();let a=t;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var Vo=om;var rl=V("/ipns/");function nl(e){return W(e.subarray(0,rl.byteLength),rl)}var qo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*Vo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof At)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!nl(t))return;let o=we(t),i=H.createV1(114,o),s=ce(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!nl(t))throw new At("Not found");let n=we(t),o=H.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Qe(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},zo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await Mo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r={}){let n;try{n=H.decode(t)}catch{try{n=uo(ee.decode(t))}catch{n=H.createV1(qa,St.digest(t))}}for await(let o of this.client.getClosestPeers(n,r))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var Ho={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},jo=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new An({concurrency:r.concurrentRequests??Ho.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??Ho.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new qo(this),this.peerRouting=new zo(this),this.cacheName=r.cacheName??Ho.cacheName,this.cacheTTL=r.cacheTTL??Ho.cacheTTL}get[va](){return this.contentRouting}get[Aa](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Br([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t(),a=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(c,r.filterAddrs,r.filterProtocols);let u={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},f=await this.#r(c.toString(),u);if(!f.ok){if(f.status===404)return;throw f.status===422?new tr("Request does not conform to schema or semantic constraints"):new Mt(`Unexpected status code: ${f.status}`)}let l=f.headers.get("Content-Type");if(l==null)throw new Mt("No Content-Type header received");if(f.body==null){if(l!=="application/x-ndjson")throw new Mt("Routing response had no body");return}if(l.startsWith("application/json")){let m=(await f.json()).Providers??[];for(let E of m){let v=this.#t(E);v!=null&&(a++,yield v)}}else if(l.includes("application/x-ndjson"))for await(let h of Nr(mn(f.body))){let m=this.#t(h);m!=null&&(a++,yield m)}else throw new Mt(`Unsupported Content-Type: ${l}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",a,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Br([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(a,r.filterAddrs,r.filterProtocols);let c={headers:{Accept:"application/x-ndjson"},signal:o},u=await this.#r(a.toString(),c);if(u.status===404)return;if(u.status===422)throw new tr("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Mt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let h=(await u.json()).Peers??[];for(let m of h){let E=this.#t(m);E!=null&&(yield E)}}else for await(let l of Nr(mn(u.body))){let h=this.#t(l);h!=null&&(yield h)}}catch(a){this.log.error("getPeers errored - %e",a)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(Ta(t))n=t.toCID().toString();else if(H.asCID(t)===t||t instanceof H)n=t.toV1().toString();else throw new et("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=Br([this.shutDownController.signal,o,r.signal]);let s=$t(),a=$t();this.httpQueue.add(async()=>(s.resolve(),a.promise));try{await s.promise;let c=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(c,r.filterAddrs,r.filterProtocols);let u={headers:{Accept:"application/x-ndjson"},signal:i},f=await this.#r(c.toString(),u);if(f.status===404)return;if(f.status===422)throw new tr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new Mt("Routing response had no body");if(f.headers.get("Content-Type")?.startsWith("application/json")){let m=(await f.json()).Peers??[];for(let E of m){let v=this.#t(E);v!=null&&(yield v)}}else for await(let h of Nr(mn(f.body))){let m=this.#t(h);m!=null&&(yield m)}}catch(c){this.log.error("getClosestPeers errored - %e",c)}finally{i.clear(),a.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=Br([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let c={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},u=await this.#r(a,c);if(this.log("getIPNS GET %s %d",a,u.status),u.status===404)throw new At("No matching records found");if(u.status===422)throw new tr("Request does not conform to schema or semantic constraints");if(!u.ok)throw new Mt(`Unexpected status code: ${u.status}`);let f=u.headers.get("Content-Type");if(f==null||!f.includes("application/vnd.ipfs.ipns-record"))throw new At("No matching records found");if(u.body==null)throw new Mt("GET ipns response had no body");let l=await u.arrayBuffer(),h=new Uint8Array(l,0,l.byteLength);return r.validate!==!1&&await Xf(vn(t.multihash),h),ce(h)}catch(c){throw this.log.error("getIPNS GET %s error - %e",a,c),c}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=Br([this.shutDownController.signal,o,n.signal]);let s=$t(),a=$t();this.httpQueue.add(async()=>(s.resolve(),a.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let u=Qe(r),f={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:u,signal:i},l=await this.#r(c,f);if(this.log("putIPNS PUT %s %d",c,l.status),l.status!==200)throw new Mt("PUT ipns response had status other than 200")}catch(u){throw this.log.error("putIPNS PUT %s error - %e",c,u.stack),u}finally{i.clear(),a.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(go)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Eu(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#r(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let c=await this.cache?.match(t);if(c!=null){if(parseInt(c.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(c),c;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let c=await i;return this.log("deduplicating outgoing request for %s",o),c.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async c=>{if(this.log("incoming response:"),this.logResponse(c),this.cache!=null&&c.ok&&n==="GET"){let u=Date.now()+this.cacheTTL,f=new Headers(c.headers);f.set("x-cache-expires",u.toString());let l=new Response(c.clone().body,{status:c.status,statusText:c.statusText,headers:f});await this.cache.put(t,l)}return c}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function ol(e){return t=>new jo(t,e)}function Yo(e){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var il=V("/ipns/");function sl(e){return W(e.subarray(0,il.byteLength),il)}var ua=class{name="delegated-http-router";client;constructor(t,r){this.client=ol(r)(t)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*Vo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(t,r,n){if(!sl(t))return;let o=we(t),i=H.createV1(114,o),s=ce(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!sl(t))throw new At("Not found");let n=we(t),o=H.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Qe(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}async findPeer(t,r){let n=await Mo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function al(e){return t=>new ua(t,Yo(e))}var cl="[a-fA-F\\d:]",ke=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${cl})|(?<=${cl})(?=\\s|$))`:"",Qt="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",st="[a-fA-F\\d]{1,4}",Zo=`
2
+ "use strict";var HeliaRouters=(()=>{var ic=Object.create;var Sr=Object.defineProperty;var ac=Object.getOwnPropertyDescriptor;var cc=Object.getOwnPropertyNames;var fc=Object.getPrototypeOf,uc=Object.prototype.hasOwnProperty;var lc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)Sr(r,e,{get:t[e],enumerable:!0})},Cs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cc(t))!uc.call(r,o)&&o!==e&&Sr(r,o,{get:()=>t[o],enumerable:!(n=ac(t,o))||n.enumerable});return r};var hc=(r,t,e)=>(e=r!=null?ic(fc(r)):{},Cs(t||!r||!r.__esModule?Sr(e,"default",{value:r,enumerable:!0}):e,r)),dc=r=>Cs(Sr({},"__esModule",{value:!0}),r);var Ha=lc((ug,ls)=>{"use strict";var Hl=Object.prototype.hasOwnProperty,mt="~";function xr(){}Object.create&&(xr.prototype=Object.create(null),new xr().__proto__||(mt=!1));function $l(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function qa(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new $l(e,n||r,o),i=mt?mt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function xn(r,t){--r._eventsCount===0?r._events=new xr:delete r._events[t]}function dt(){this._events=new xr,this._eventsCount=0}dt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Hl.call(e,n)&&t.push(mt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};dt.prototype.listeners=function(t){var e=mt?mt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};dt.prototype.listenerCount=function(t){var e=mt?mt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};dt.prototype.emit=function(t,e,n,o,s,i){var a=mt?mt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var p=c.length,d;for(l=0;l<p;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(d=1,u=new Array(f-1);d<f;d++)u[d-1]=arguments[d];c[l].fn.apply(c[l].context,u)}}return!0};dt.prototype.on=function(t,e,n){return qa(this,t,e,n,!1)};dt.prototype.once=function(t,e,n){return qa(this,t,e,n,!0)};dt.prototype.removeListener=function(t,e,n,o){var s=mt?mt+t:t;if(!this._events[s])return this;if(!e)return xn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&xn(this,s);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:xn(this,s)}return this};dt.prototype.removeAllListeners=function(t){var e;return t?(e=mt?mt+t:t,this._events[e]&&xn(this,e)):(this._events=new xr,this._eventsCount=0),this};dt.prototype.off=dt.prototype.removeListener;dt.prototype.addListener=dt.prototype.on;dt.prefixed=mt;dt.EventEmitter=dt;typeof ls<"u"&&(ls.exports=dt)});var ph={};gt(ph,{delegatedHTTPRouting:()=>Wa,delegatedHTTPRoutingDefaults:()=>Sn,httpGatewayRouting:()=>oc,libp2pRouting:()=>sc});var St=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ar=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ft=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Ir=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Tr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Tn=Symbol.for("@libp2p/peer-id");var Ln={};gt(Ln,{base58btc:()=>W,base58flickr:()=>Ec});var bh=new Uint8Array(0);function _s(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ie(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ie(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Ds(r){return new TextEncoder().encode(r)}function Ls(r){return new TextDecoder().decode(r)}function pc(r){return r?.buffer instanceof ArrayBuffer}function ie(r){return pc(r)?r:r.slice()}function mc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var v=0,m=0,x=0,S=y.length;x!==S&&y[x]===0;)x++,v++;for(var I=(S-x)*u+1>>>0,L=new Uint8Array(I);x!==S;){for(var _=y[x],O=0,R=I-1;(_!==0||O<m)&&R!==-1;R--,O++)_+=256*L[R]>>>0,L[R]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");m=O,x++}for(var B=I-m;B!==I&&L[B]===0;)B++;for(var U=c.repeat(v);B<I;++B)U+=r.charAt(L[B]);return U}function p(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var v=0;if(y[v]!==" "){for(var m=0,x=0;y[v]===c;)m++,v++;for(var S=(y.length-v)*f+1>>>0,I=new Uint8Array(S);y[v];){var L=e[y.charCodeAt(v)];if(L===255)return;for(var _=0,O=S-1;(L!==0||_<x)&&O!==-1;O--,_++)L+=a*I[O]>>>0,I[O]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");x=_,v++}if(y[v]!==" "){for(var R=S-x;R!==S&&I[R]===0;)R++;for(var B=new Uint8Array(m+(S-R)),U=m;R!==S;)B[U++]=I[R++];return B}}}function d(y){var v=p(y);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:d}}var yc=mc,gc=yc,Ps=gc;var Bn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Cn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Os(this,t)}},_n=class{decoders;constructor(t){this.decoders=t}or(t){return Os(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Os(r,t){return new _n({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Dn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Bn(t,e,n),this.decoder=new Cn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xe({name:r,prefix:t,encode:e,decode:n}){return new Dn(r,t,e,n)}function jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ps(e,r);return xe({prefix:t,name:r,encode:n,decode:s=>kt(o(s))})}function bc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function wc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function xc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=xc(n);return xe({prefix:t,name:r,encode(s){return wc(s,n,e)},decode(s){return bc(s,o,e,r)}})}var W=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ec=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Rn={};gt(Rn,{base32:()=>Zt,base32hex:()=>Ic,base32hexpad:()=>Bc,base32hexpadupper:()=>Cc,base32hexupper:()=>Tc,base32pad:()=>Sc,base32padupper:()=>Ac,base32upper:()=>vc,base32z:()=>_c});var Zt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vc=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Sc=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ac=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ic=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Tc=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bc=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Cc=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_c=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pn={};gt(Pn,{base36:()=>$e,base36upper:()=>Dc});var $e=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Dc=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lc=Fs,Us=128,Rc=127,Pc=~Rc,Oc=Math.pow(2,31);function Fs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Oc;)t[e++]=r&255|Us,r/=128;for(;r&Pc;)t[e++]=r&255|Us,r>>>=7;return t[e]=r|0,Fs.bytes=e-n+1,t}var Uc=On,Nc=128,Ns=127;function On(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw On.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ns)<<o:(i&Ns)*Math.pow(2,o),o+=7}while(i>=Nc);return On.bytes=s-n,e}var Fc=Math.pow(2,7),kc=Math.pow(2,14),Kc=Math.pow(2,21),Vc=Math.pow(2,28),Mc=Math.pow(2,35),qc=Math.pow(2,42),Hc=Math.pow(2,49),$c=Math.pow(2,56),zc=Math.pow(2,63),jc=function(r){return r<Fc?1:r<kc?2:r<Kc?3:r<Vc?4:r<Mc?5:r<qc?6:r<Hc?7:r<$c?8:r<zc?9:10},Zc={encode:Lc,decode:Uc,encodingLength:jc},Yc=Zc,ze=Yc;function je(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function Ee(r,t,e=0){return ze.encode(r,t,e),t}function ve(r){return ze.encodingLength(r)}function Ae(r,t){let e=t.byteLength,n=ve(r),o=n+ve(e),s=new Uint8Array(o+e);return Ee(r,s,0),Ee(e,s,n),s.set(t,o),new Se(r,e,t,s)}function Yt(r){let t=kt(r),[e,n]=je(t),[o,s]=je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Se(e,o,i,t)}function ks(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&_s(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=ie(n),this.bytes=ie(o)}};function Ks(r,t){let{bytes:e,version:n}=r;return n===0?Wc(e,Un(r),t??W.encoder):Xc(e,Un(r),t??Zt.encoder)}var Vs=new WeakMap;function Un(r){let t=Vs.get(r);if(t==null){let e=new Map;return Vs.set(r,e),e}return t}var q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=ie(o),this["/"]=this.bytes}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:t,multihash:e}=this;if(t!==Ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Qc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=Ae(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ks(t.multihash,n.multihash)}toString(t){return Ks(this,t)}toJSON(){return{"/":Ks(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ms(n,o,s.bytes))}else if(e[Jc]===!0){let{version:n,multihash:o,code:s}=e,i=Yt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ze)throw new Error(`Version 0 CID must use dag-pb (code: ${Ze}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ms(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ze,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Se(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,p]=je(t.subarray(e));return e+=p,l},o=n(),s=Ze;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Gc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Un(s).set(n,t),s}};function Gc(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case Zt.prefix:{let e=t??Zt;return[Zt.prefix,e.decode(r)]}case $e.prefix:{let e=t??$e;return[$e.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Wc(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Xc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ze=112,Qc=18;function Ms(r,t,e){let n=ve(r),o=n+ve(t),s=new Uint8Array(o+e.byteLength);return Ee(r,s,0),Ee(t,s,n),s.set(e,o),s}var Jc=Symbol.for("@ipld/js-cid/CID");var Nn={};gt(Nn,{identity:()=>bt});var qs=0,tf="identity",Hs=kt;function ef(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Ae(qs,Hs(r))}var bt={code:qs,name:tf,encode:Hs,digest:ef};function nt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}async function $s(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}function J(r=0){return new Uint8Array(r)}function ot(r=0){return new Uint8Array(r)}function rf(r){return r?.buffer instanceof ArrayBuffer}function Fn(r){if(rf(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function wt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ot(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return Fn(e)}var js=Symbol.for("@achingbrain/uint8arraylist");function zs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Cr(r){return!!r?.[js]}var xt=class r{bufs;length;[js]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Cr(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Cr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=zs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=zs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Cr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return wt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:wt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Cr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ot(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=J(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=J(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ot(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=J(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=J(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=J(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!nt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var kn={};gt(kn,{base10:()=>nf});var nf=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Kn={};gt(Kn,{base16:()=>of,base16upper:()=>sf});var of=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sf=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Vn={};gt(Vn,{base2:()=>af});var af=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mn={};gt(Mn,{base256emoji:()=>hf});var Zs=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}"),cf=Zs.reduce((r,t,e)=>(r[e]=t,r),[]),ff=Zs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function uf(r){return r.reduce((t,e)=>(t+=cf[e],t),"")}function lf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=ff[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var hf=xe({prefix:"\u{1F680}",name:"base256emoji",encode:uf,decode:lf});var Hn={};gt(Hn,{base64:()=>df,base64pad:()=>pf,base64url:()=>qn,base64urlpad:()=>mf});var df=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pf=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),mf=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $n={};gt($n,{base8:()=>yf});var yf=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var zn={};gt(zn,{identity:()=>gf});var gf=xe({prefix:"\0",name:"identity",encode:r=>Ls(r),decode:r=>Ds(r)});var ed=new TextEncoder,rd=new TextDecoder;var Yn={};gt(Yn,{sha256:()=>Ye,sha512:()=>Ef});var xf=20;function Zn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new jn(r,t,e,n,o)}var jn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??xf,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ys(n,this.code,e?.truncate):n.then(o=>Ys(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ys(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Ae(t,r)}function Ws(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ye=Zn({name:"sha2-256",code:18,encode:Ws("SHA-256")}),Ef=Zn({name:"sha2-512",code:19,encode:Ws("SHA-512")});var Ge={...zn,...Vn,...$n,...kn,...Kn,...Rn,...Pn,...Ln,...Hn,...Mn},pd={...Yn,...Nn};function Qs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Xs=Qs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Gn=Qs("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ot(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),vf={utf8:Xs,"utf-8":Xs,hex:Ge.base16,latin1:Gn,ascii:Gn,binary:Gn,...Ge},_r=vf;function st(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function $(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Sf=parseInt("11111",2),Wn=parseInt("10000000",2),Af=parseInt("01111111",2),Js={0:We,1:We,2:If,3:Cf,4:_f,5:Bf,6:Tf,16:We,22:We,48:We};function Xn(r,t={offset:0}){let e=r[t.offset]&Sf;if(t.offset++,Js[e]!=null)return Js[e](r,t);throw new Error("No decoder for tag "+e)}function Xe(r,t){let e=0;if((r[t.offset]&Wn)===Wn){let n=r[t.offset]&Af,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function We(r,t){Xe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Xn(r,t);if(n===null)break;e.push(n)}return e}function If(r,t){let e=Xe(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Tf(r,t){let e=Xe(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Bf(r,t){return t.offset++,null}function Cf(r,t){let e=Xe(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function _f(r,t){let e=Xe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Df(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new xt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Qn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Df(r.byteLength);return new xt(Uint8Array.from([t.byteLength|Wn]),t)}function ti(r){let t=new xt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new xt(Uint8Array.from([2]),Qn(t),t)}function ei(r){let t=Uint8Array.from([0]),e=new xt(t,r);return new xt(Uint8Array.from([3]),Qn(e),e)}function Dr(r,t=48){let e=new xt;for(let n of r)e.append(n);return new xt(Uint8Array.from([t]),Qn(e),e)}var Lf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rf=Uint8Array.from([6,5,43,129,4,0,34]),Pf=Uint8Array.from([6,5,43,129,4,0,35]),Of={ext:!0,kty:"EC",crv:"P-256"},Uf={ext:!0,kty:"EC",crv:"P-384"},Nf={ext:!0,kty:"EC",crv:"P-521"},Jn=32,to=48,eo=66;function ri(r){let t=Xn(r);return ni(t)}function ni(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Jn*2+1)return n=$(t.subarray(e,e+Jn),"base64url"),o=$(t.subarray(e+Jn),"base64url"),new Ie({...Of,key_ops:["verify"],x:n,y:o});if(t.byteLength===to*2+1)return n=$(t.subarray(e,e+to),"base64url"),o=$(t.subarray(e+to),"base64url"),new Ie({...Uf,key_ops:["verify"],x:n,y:o});if(t.byteLength===eo*2+1)return n=$(t.subarray(e,e+eo),"base64url"),o=$(t.subarray(e+eo),"base64url"),new Ie({...Nf,key_ops:["verify"],x:n,y:o});throw new St(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function oi(r){return Dr([ti(Uint8Array.from([1])),Dr([Ff(r.crv)],160),Dr([ei(new xt(Uint8Array.from([4]),st(r.x??"","base64url"),st(r.y??"","base64url")))],161)]).subarray()}function Ff(r){if(r==="P-256")return Lf;if(r==="P-384")return Rf;if(r==="P-521")return Pf;throw new St(`Invalid curve ${r}`)}var Ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=oi(this.jwk)),this._raw}toMultihash(){return bt.digest(Te(this))}toCID(){return q.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}async verify(t,e,n){return $s(this.jwk,e,t,n)}};function ro(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Gt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function Et(r,t,e=""){let n=ro(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return r}function Lr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Gt(r.outputLen),Gt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Be(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Rr(r,t){Et(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function Vt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Pr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Tt(r,t){return r<<32-t|r>>>t}var ii=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Or(r){if(Et(r),ii)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=kf[r[e]];return t}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function si(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function Qe(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(ii)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=si(r.charCodeAt(s)),a=si(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function no(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Et(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function oo(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ai(r=32){Gt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var so=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ci(r,t,e){return r&t^~r&e}function fi(r,t,e){return r&t^r&e^t&e}var Je=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Pr(this.buffer)}update(t){Be(this),Et(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Pr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Be(this),Rr(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Pr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ur=BigInt(4294967295),ui=BigInt(32);function Kf(r,t=!1){return t?{h:Number(r&Ur),l:Number(r>>ui&Ur)}:{h:Number(r>>ui&Ur)|0,l:Number(r&Ur)|0}}function li(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Kf(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var io=(r,t,e)=>r>>>e,ao=(r,t,e)=>r<<32-e|t>>>e,ce=(r,t,e)=>r>>>e|t<<32-e,fe=(r,t,e)=>r<<32-e|t>>>e,tr=(r,t,e)=>r<<64-e|t>>>e-32,er=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var hi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),di=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,pi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),mi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,yi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),gi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Mf=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]),Wt=new Uint32Array(64),co=class extends Je{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Wt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=Wt[l-15],d=Wt[l-2],y=Tt(p,7)^Tt(p,18)^p>>>3,v=Tt(d,17)^Tt(d,19)^d>>>10;Wt[l]=v+Wt[l-7]+y+Wt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let p=Tt(a,6)^Tt(a,11)^Tt(a,25),d=u+p+ci(a,c,f)+Mf[l]+Wt[l]|0,v=(Tt(n,2)^Tt(n,13)^Tt(n,22))+fi(n,o,s)|0;u=f,f=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){Vt(Wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}},fo=class extends co{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var bi=li(["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))),qf=bi[0],Hf=bi[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),uo=class extends Je{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:p,Gh:d,Gl:y,Hh:v,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,u,l,p,d,y,v,m]}set(t,e,n,o,s,i,a,c,f,u,l,p,d,y,v,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=p|0,this.Gh=d|0,this.Gl=y|0,this.Hh=v|0,this.Hl=m|0}process(t,e){for(let I=0;I<16;I++,e+=4)Xt[I]=t.getUint32(e),Qt[I]=t.getUint32(e+=4);for(let I=16;I<80;I++){let L=Xt[I-15]|0,_=Qt[I-15]|0,O=ce(L,_,1)^ce(L,_,8)^io(L,_,7),R=fe(L,_,1)^fe(L,_,8)^ao(L,_,7),B=Xt[I-2]|0,U=Qt[I-2]|0,M=ce(B,U,19)^tr(B,U,61)^io(B,U,6),N=fe(B,U,19)^er(B,U,61)^ao(B,U,6),h=pi(R,N,Qt[I-7],Qt[I-16]),g=mi(h,O,M,Xt[I-7],Xt[I-16]);Xt[I]=g|0,Qt[I]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:p,Fh:d,Fl:y,Gh:v,Gl:m,Hh:x,Hl:S}=this;for(let I=0;I<80;I++){let L=ce(l,p,14)^ce(l,p,18)^tr(l,p,41),_=fe(l,p,14)^fe(l,p,18)^er(l,p,41),O=l&d^~l&v,R=p&y^~p&m,B=yi(S,_,R,Hf[I],Qt[I]),U=gi(B,x,L,O,qf[I],Xt[I]),M=B|0,N=ce(n,o,28)^tr(n,o,34)^tr(n,o,39),h=fe(n,o,28)^er(n,o,34)^er(n,o,39),g=n&s^n&a^s&a,E=o&i^o&c^i&c;x=v|0,S=m|0,v=d|0,m=y|0,d=l|0,y=p|0,{h:l,l:p}=Pt(f|0,u|0,U|0,M|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let w=hi(M,h,E);n=di(w,U,N,g),o=w|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Pt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Pt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=Pt(this.Eh|0,this.El|0,l|0,p|0),{h:d,l:y}=Pt(this.Fh|0,this.Fl|0,d|0,y|0),{h:v,l:m}=Pt(this.Gh|0,this.Gl|0,v|0,m|0),{h:x,l:S}=Pt(this.Hh|0,this.Hl|0,x|0,S|0),this.set(n,o,s,i,a,c,f,u,l,p,d,y,v,m,x,S)}roundClean(){Vt(Xt,Qt)}destroy(){this.destroyed=!0,Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},lo=class extends uo{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var wi=oo(()=>new fo,so(1));var Nr=oo(()=>new lo,so(3));var K=(r,t,e)=>Et(r,t,e),po=Gt,Ce=Or,tt=(...r)=>no(...r),_e=r=>Qe(r),ue=ro,rr=r=>ai(r),kr=BigInt(0),ho=BigInt(1);function Bt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function Kr(r){if(typeof r=="bigint"){if(!Fr(r))throw new RangeError("positive bigint expected, got "+r)}else po(r);return r}function Ct(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function nr(r){let t=Kr(r).toString(16);return t.length&1?"0"+t:t}function xi(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?kr:BigInt("0x"+r)}function le(r){return xi(Or(r))}function Ot(r){return xi(Or(or(Et(r)).reverse()))}function Vr(r,t){if(Gt(t),t===0)throw new RangeError("zero length");r=Kr(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return Qe(e.padStart(t*2,"0"))}function mo(r,t){return Vr(r,t).reverse()}function Ei(r,t){if(r=K(r),t=K(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function or(r){return Uint8Array.from(K(r))}function Mr(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var Fr=r=>typeof r=="bigint"&&kr<=r;function $f(r,t,e){return Fr(r)&&Fr(t)&&Fr(e)&&t<=r&&r<e}function De(r,t,e,n){if(!$f(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Le(r){if(r<kr)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>kr;r>>=ho,t+=1);return t}var sr=r=>(ho<<BigInt(r))-ho;function vi(r,t,e){if(Gt(r,"hashLen"),Gt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),u=0,l=()=>{c.fill(1),f.fill(0),u=0},p=(...m)=>e(f,tt(c,...m)),d=(m=o)=>{f=p(s,m),c=p(),m.length!==0&&(f=p(i,m),c=p())},y=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,x=[];for(;m<t;){c=p();let S=c.slice();x.push(S),m+=c.length}return tt(...x)};return(m,x)=>{l(),d(m);let S;for(;(S=x(y()))===void 0;)d();return l(),S}}function _t(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var yo=()=>{throw new Error("not implemented")};var ft=BigInt(0),Z=BigInt(1),he=BigInt(2),Ti=BigInt(3),Bi=BigInt(4),Ci=BigInt(5),zf=BigInt(7),_i=BigInt(8),jf=BigInt(9),Di=BigInt(16);function G(r,t){if(t<=ft)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=ft?e:t+e}function H(r,t,e){if(t<ft)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >ft;)n*=n,n%=e;return n}function Si(r,t){if(r===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=ft,s=Z,i=Z,a=ft;for(;e!==ft;){let f=n/e,u=n-e*f,l=o-i*f,p=s-a*f;n=e,e=u,o=i,s=a,i=l,a=p}if(n!==Z)throw new Error("invert: does not exist");return G(o,t)}function go(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Li(r,t){let e=r,n=(e.ORDER+Z)/Bi,o=e.pow(t,n);return go(e,o,t),o}function Zf(r,t){let e=r,n=(e.ORDER-Ci)/_i,o=e.mul(t,he),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,he),s),c=e.mul(i,e.sub(a,e.ONE));return go(e,c,t),c}function Yf(r){let t=Re(r),e=Ri(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+zf)/Di;return((a,c)=>{let f=a,u=f.pow(c,i),l=f.mul(u,n),p=f.mul(u,o),d=f.mul(u,s),y=f.eql(f.sqr(l),c),v=f.eql(f.sqr(p),c);u=f.cmov(u,l,y),l=f.cmov(d,p,v);let m=f.eql(f.sqr(l),c),x=f.cmov(u,l,m);return go(f,x,c),x})}function Ri(r){if(r<Ti)throw new Error("sqrt is not defined for small field");let t=r-Z,e=0;for(;t%he===ft;)t/=he,e++;let n=he,o=Re(r);for(;Ai(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Li;let s=o.pow(n,t),i=(t+Z)/he;return function(c,f){let u=c;if(u.is0(f))return f;if(Ai(u,f)!==1)throw new Error("Cannot find square root");let l=e,p=u.mul(u.ONE,s),d=u.pow(f,t),y=u.pow(f,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))return u.ZERO;let v=1,m=u.sqr(d);for(;!u.eql(m,u.ONE);)if(v++,m=u.sqr(m),v===l)throw new Error("Cannot find square root");let x=Z<<BigInt(l-v-1),S=u.pow(p,x);l=v,p=u.sqr(S),d=u.mul(d,p),y=u.mul(y,S)}return y}}function Gf(r){return r%Bi===Ti?Li:r%_i===Ci?Zf:r%Di===jf?Yf(r):Ri(r)}var qt=(r,t)=>(G(r,t)&Z)===Z,Wf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function bo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Wf.reduce((n,o)=>(n[o]="function",n),t);if(_t(r,e),Ct(r.BYTES,"BYTES"),Ct(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=Z)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Xf(r,t,e){let n=r;if(e<ft)throw new Error("invalid exponent, negatives unsupported");if(e===ft)return n.ONE;if(e===Z)return t;let o=n.ONE,s=t;for(;e>ft;)e&Z&&(o=n.mul(o,s)),s=n.sqr(s),e>>=Z;return o}function ir(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function Ai(r,t){let e=r,n=(e.ORDER-Z)/he,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Qf(r,t){if(t!==void 0&&po(t),r<=ft)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=Le(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Ii=new WeakMap,qr=class{ORDER;BITS;BYTES;isLE;ZERO=ft;ONE=Z;_lengths;_mod;constructor(t,e={}){if(t<=Z)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Qf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return G(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ft<=t&&t<this.ORDER}is0(t){return t===ft}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Z)===Z}neg(t){return G(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return G(t*t,this.ORDER)}add(t,e){return G(t+e,this.ORDER)}sub(t,e){return G(t-e,this.ORDER)}mul(t,e){return G(t*e,this.ORDER)}pow(t,e){return Xf(this,t,e)}div(t,e){return G(t*Si(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Si(t,this.ORDER)}sqrt(t){let e=Ii.get(this);return e||Ii.set(this,e=Gf(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?mo(t,this.BYTES):Vr(t,this.BYTES)}fromBytes(t,e=!1){K(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Ot(t):le(t);if(a&&(c=G(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return ir(this,t)}cmov(t,e,n){return Bt(n,"condition"),n?e:t}};Object.freeze(qr.prototype);function Re(r,t={}){return new qr(r,t)}function Pi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=Z)throw new Error("field order must be greater than 1");let t=Le(r-Z);return Math.ceil(t/8)}function wo(r){let t=Pi(r);return t+Math.ceil(t/2)}function xo(r,t,e=!1){K(r);let n=r.length,o=Pi(t),s=Math.max(wo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ot(r):le(r),a=G(i,t-Z)+Z;return e?mo(a,o):Vr(a,o)}var Pe=BigInt(0),de=BigInt(1);function ar(r,t){let e=t.negate();return r?e:t}function pe(r,t){let e=ir(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Fi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Eo(r,t){Fi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=sr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Oi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=de);let f=t*n,u=f+Math.abs(a)-1,l=a===0,p=a<0,d=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:p,isNegF:d,offsetF:f}}var vo=new WeakMap,ki=new WeakMap;function So(r){return ki.get(r)||1}function Ui(r){if(r!==Pe)throw new Error("invalid wNAF")}var Oe=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Pe;)e&de&&(n=n.add(o)),o=o.double(),e>>=de;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Eo(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Eo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:p,offsetF:d}=Oi(n,a,i);n=c,u?s=s.add(ar(p,e[d])):o=o.add(ar(l,e[f]))}return Ui(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Eo(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=Oi(n,i,s);if(n=a,!f){let l=e[c];o=o.add(u?l.negate():l)}}return Ui(n),o}getPrecomputes(t,e,n){let o=vo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),vo.set(e,o))),o}cached(t,e,n){let o=So(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=So(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Fi(e,this.bits),ki.set(t,e),vo.delete(t)}hasCache(t){return So(t)!==1}};function Ki(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Pe||n>Pe;)e&de&&(s=s.add(o)),n&de&&(i=i.add(o)),o=o.double(),e>>=de,n>>=de;return{p1:s,p2:i}}function Ni(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return bo(t),t}else return Re(r,{isLE:e})}function Hr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ni(t.p,e.Fp,n),s=Ni(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function $r(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Jt=BigInt(0),it=BigInt(1),Ao=BigInt(2),Jf=BigInt(8);function tu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Vi(r,t={}){let e=t,n=Hr("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;_t(e,{},{uvRatio:"function"});let c=Ao<<BigInt(s.BYTES*8)-it,f=v=>o.create(v),u=e.uvRatio===void 0?(v,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,m))}}catch{return{isValid:!1,value:Jt}}}:e.uvRatio;if(!tu(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(v,m,x=!1){let S=x?it:Jt;return De("coordinate "+v,m,S,c),m}function p(v){if(!(v instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,it,f(i.Gx*i.Gy));static ZERO=new d(Jt,it,it,Jt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,x,S,I){this.X=l("x",m),this.Y=l("y",x),this.Z=l("z",S,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof d)throw new Error("extended point not allowed");let{x,y:S}=m||{};return l("x",x),l("y",S),new d(x,S,it,f(x*S))}static fromBytes(m,x=!1){let S=o.BYTES,{a:I,d:L}=i;m=or(K(m,S,"point")),Bt(x,"zip215");let _=or(m),O=m[S-1];_[S-1]=O&-129;let R=Ot(_),B=x?c:o.ORDER;De("point.y",R,Jt,B);let U=f(R*R),M=f(U-it),N=f(L*U-I),{isValid:h,value:g}=u(M,N);if(!h)throw new Error("bad point: invalid y coordinate");let E=(g&it)===it,w=(O&128)!==0;if(!x&&g===Jt&&w)throw new Error("bad point: x=0 and x_0=1");return w!==E&&(g=f(-g)),d.fromAffine({x:g,y:R})}static fromHex(m,x=!1){return d.fromBytes(_e(m),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,x=!0){return y.createCache(this,m),x||this.multiply(Ao),this}assertValidity(){let m=this,{a:x,d:S}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:I,Y:L,Z:_,T:O}=m,R=f(I*I),B=f(L*L),U=f(_*_),M=f(U*U),N=f(R*x),h=f(U*f(N+B)),g=f(M+f(S*f(R*B)));if(h!==g)throw new Error("bad point: equation left != right (1)");let E=f(I*L),w=f(_*O);if(E!==w)throw new Error("bad point: equation left != right (2)")}equals(m){p(m);let{X:x,Y:S,Z:I}=this,{X:L,Y:_,Z:O}=m,R=f(x*O),B=f(L*I),U=f(S*O),M=f(_*I);return R===B&&U===M}is0(){return this.equals(d.ZERO)}negate(){return new d(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:x,Y:S,Z:I}=this,L=f(x*x),_=f(S*S),O=f(Ao*f(I*I)),R=f(m*L),B=x+S,U=f(f(B*B)-L-_),M=R+_,N=M-O,h=R-_,g=f(U*N),E=f(M*h),w=f(U*h),b=f(N*M);return new d(g,E,b,w)}add(m){p(m);let{a:x,d:S}=i,{X:I,Y:L,Z:_,T:O}=this,{X:R,Y:B,Z:U,T:M}=m,N=f(I*R),h=f(L*B),g=f(O*S*M),E=f(_*U),w=f((I+L)*(R+B)-N-h),b=E-g,A=E+g,C=f(h-x*N),T=f(w*b),D=f(A*C),P=f(w*C),k=f(b*A);return new d(T,D,k,P)}subtract(m){return p(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:S}=y.cached(this,m,I=>pe(d,I));return pe(d,[x,S])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Jt?d.ZERO:this.is0()||m===it?this:y.unsafe(this,m,x=>pe(d,x))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(m){let x=this,S=m,{X:I,Y:L,Z:_}=x,O=x.is0();S==null&&(S=O?Jf:o.inv(_));let R=f(I*S),B=f(L*S),U=o.mul(_,S);if(O)return{x:Jt,y:it};if(U!==it)throw new Error("invZ was invalid");return{x:R,y:B}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:x}=this.toAffine(),S=o.toBytes(x);return S[S.length-1]|=m&it?128:0,S}toHex(){return Ce(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new Oe(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var zr=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){yo()}static fromHex(t){yo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Ce(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.ep.precompute(t,e),this}};function Mi(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;_t(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(Ct(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?rr:o.randomBytes,p=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,d=o.domain===void 0?(h,g,E)=>{if(Bt(E,"phflag"),g.length||E)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function y(h){return c.create(Ot(h))}function v(h){let g=R.secretKey;K(h,R.secretKey,"secretKey");let E=K(n(h),2*g,"hashedSecretKey"),w=p(E.slice(0,g)),b=E.slice(g,2*g),A=y(w);return{head:w,prefix:b,scalar:A}}function m(h){let{head:g,prefix:E,scalar:w}=v(h),b=i.multiply(w),A=b.toBytes();return{head:g,prefix:E,scalar:w,point:b,pointBytes:A}}function x(h){return m(h).pointBytes}function S(h=Uint8Array.of(),...g){let E=tt(...g);return y(n(d(E,K(h,void 0,"context"),!!s)))}function I(h,g,E={}){h=K(h,void 0,"message"),s&&(h=s(h));let{prefix:w,scalar:b,pointBytes:A}=m(g),C=S(E.context,w,h),T=i.multiply(C).toBytes(),D=S(E.context,T,A,h),P=c.create(C+D*b);if(!c.isValid(P))throw new Error("sign failed: invalid s");let k=tt(T,c.toBytes(P));return K(k,R.signature,"result")}let L={zip215:o.zip215};function _(h,g,E,w=L){let{context:b}=w,A=w.zip215===void 0?!!L.zip215:w.zip215,C=R.signature;h=K(h,C,"signature"),g=K(g,void 0,"message"),E=K(E,R.publicKey,"publicKey"),A!==void 0&&Bt(A,"zip215"),s&&(g=s(g));let T=C/2,D=h.subarray(0,T),P=Ot(h.subarray(T,C)),k,V,F;try{k=r.fromBytes(E,A),V=r.fromBytes(D,A),F=i.multiplyUnsafe(P)}catch{return!1}if(!A&&k.isSmallOrder())return!1;let Q=S(b,D,E,g);return V.add(k.multiplyUnsafe(Q)).subtract(F).clearCofactor().is0()}let O=a.BYTES,R={secretKey:O,publicKey:O,signature:2*O,seed:O};function B(h){return h=h===void 0?l(R.seed):h,K(h,R.seed,"seed")}function U(h){return ue(h)&&h.length===R.secretKey}function M(h,g){try{return!!r.fromBytes(h,g===void 0?L.zip215:g)}catch{return!1}}let N={getExtendedPublicKey:m,randomSecretKey:B,isValidSecretKey:U,isValidPublicKey:M,toMontgomery(h){let{y:g}=r.fromBytes(h),E=R.publicKey,w=E===32;if(!w&&E!==57)throw new Error("only defined for 25519 and 448");let b=w?a.div(it+g,it-g):a.div(g-it,g+it);return a.toBytes(b)},toMontgomerySecret(h){let g=R.secretKey;K(h,g);let E=n(h.subarray(0,g));return p(E).subarray(0,g)}};return Object.freeze(R),Object.freeze(N),Object.freeze({keygen:$r(B,x),getPublicKey:x,sign:I,verify:_,utils:N,Point:r,lengths:R})}function cr(r,t){if(Ct(r),Ct(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function eu(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function ru(r){if(!ue(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?Mr(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Io(r,t,e,n){K(r),Ct(e),t=ru(t),t.length>255&&(t=n(tt(Mr("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=tt(t,cr(t.length,1)),c=new Uint8Array(s),f=cr(e,2),u=new Array(i),l=n(tt(c,r,f,cr(0,1),a));u[0]=n(tt(l,cr(1,1),a));for(let d=1;d<i;d++){let y=[eu(l,u[d-1]),cr(d+1,1),a];u[d]=n(tt(...y))}return tt(...u).slice(0,e)}var qi="HashToScalar-";var nu=BigInt(0),Ht=BigInt(1),Hi=BigInt(2);var ou=BigInt(5),su=BigInt(8),Ue=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),_o={p:Ue,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:su,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function iu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ue,a=r*r%s*r%s,c=H(a,Hi,s)*a%s,f=H(c,Ht,s)*r%s,u=H(f,ou,s)*f%s,l=H(u,t,s)*u%s,p=H(l,e,s)*l%s,d=H(p,n,s)*p%s,y=H(d,o,s)*d%s,v=H(y,o,s)*d%s,m=H(v,t,s)*u%s;return{pow_p_5_8:H(m,Hi,s)*r%s,b2:a}}function au(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var To=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Do(r,t){let e=Ue,n=G(t*t*t,e),o=G(n*n*t,e),s=iu(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,f=G(i*To,e),u=a===r,l=a===G(-r,e),p=a===G(-r*To,e);return u&&(i=c),(l||p)&&(i=f),qt(i,e)&&(i=G(-i,e)),{isValid:u||l,value:i}}var ee=Vi(_o,{uvRatio:Do}),te=ee.Fp,ji=ee.Fn;function cu(r){return Mi(ee,Nr,Object.assign({adjustScalarBytes:au,zip215:!0},r))}var Zi=cu({});var Bo=To,fu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),uu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),lu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),hu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),$i=r=>Do(Ht,r),du=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Co=r=>te.create(Ot(r)&du);function zi(r){let{d:t}=_o,e=Ue,n=x=>te.create(x),o=n(Bo*r*r),s=n((o+Ht)*lu),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=Do(s,a),u=n(f*r);qt(u,e)||(u=n(-u)),c||(f=u),c||(i=o);let l=n(i*(o-Ht)*hu-a),p=f*f,d=n((f+f)*a),y=n(l*fu),v=n(Ht-p),m=n(Ht+p);return new ee(n(d*m),n(v*y),n(y*m),n(d*v))}var re=class r extends zr{static BASE=new r(ee.BASE);static ZERO=new r(ee.ZERO);static Fp=te;static Fn=ji;constructor(t){super(t)}static fromAffine(t){return new r(ee.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){Et(t,32);let{a:e,d:n}=_o,o=Ue,s=L=>te.create(L),i=Co(t);if(!Ei(te.toBytes(i),t)||qt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Ht+e*a),f=s(Ht-e*a),u=s(c*c),l=s(f*f),p=s(e*n*u-l),{isValid:d,value:y}=$i(s(p*l)),v=s(y*f),m=s(y*v*p),x=s((i+i)*v);qt(x,o)&&(x=s(-x));let S=s(c*m),I=s(x*S);if(!d||qt(I,o)||S===nu)throw new Error("invalid ristretto255 encoding 2");return new r(new ee(x,S,Ht,I))}static fromHex(t){return r.fromBytes(Qe(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ue,i=m=>te.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:u}=$i(i(a*f)),l=i(u*a),p=i(u*c),d=i(l*p*o),y;if(qt(o*d,s)){let m=i(e*Bo),x=i(t*Bo);t=m,e=x,y=i(l*uu)}else y=p;qt(t*d,s)&&(e=i(-e));let v=i((n-e)*y);return qt(v,s)&&(v=i(-v)),te.toBytes(v)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>te.create(f),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(re.BASE);Object.freeze(re.ZERO);Object.freeze(re.prototype);Object.freeze(re);var pu=Object.freeze({Point:re,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Io(r,e,64,Nr);return pu.deriveToCurve(n)},hashToScalar(r,t={DST:qi}){let e=Io(r,t.DST,64,Nr);return ji.create(Ot(e))},deriveToCurve(r){Et(r,64);let t=Co(r.subarray(0,32)),e=zi(t),n=Co(r.subarray(32,64)),o=zi(n);return new re(e.add(o))}});var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},jr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Yi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new jr("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 t}};var Zr=Yi;var Yr=32;var Lo,mu=(async()=>{try{return await Zr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function yu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Zr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Zr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function gu(r,t,e){return Zi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Gi(r,t,e){return Lo==null&&(Lo=await mu),Lo?yu(r,t,e):gu(r,t,e)}function Gr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Wr=class{type="Ed25519";raw;constructor(t){this.raw=Ro(t,Yr)}toMultihash(){return bt.digest(Te(this))}toCID(){return q.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Gi(this.raw,e,t);return Gr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Xi(r){return r=Ro(r,Yr),new Wr(r)}function Ro(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new St(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var wu=Math.pow(2,7),xu=Math.pow(2,14),Eu=Math.pow(2,21),Po=Math.pow(2,28),Oo=Math.pow(2,35),Uo=Math.pow(2,42),No=Math.pow(2,49),z=128,lt=127;function Ut(r){if(r<wu)return 1;if(r<xu)return 2;if(r<Eu)return 3;if(r<Po)return 4;if(r<Oo)return 5;if(r<Uo)return 6;if(r<No)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ur(r,t,e=0){switch(Ut(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Fo(r,t){let e=r[t],n=0;if(n+=e&lt,e<z||(e=r[t+1],n+=(e&lt)<<7,e<z)||(e=r[t+2],n+=(e&lt)<<14,e<z)||(e=r[t+3],n+=(e&lt)<<21,e<z)||(e=r[t+4],n+=(e&lt)*Po,e<z)||(e=r[t+5],n+=(e&lt)*Oo,e<z)||(e=r[t+6],n+=(e&lt)*Uo,e<z)||(e=r[t+7],n+=(e&lt)*No,e<z))return n;throw new RangeError("Could not decode varint")}function vu(r,t){let e=r.get(t),n=0;if(n+=e&lt,e<z||(e=r.get(t+1),n+=(e&lt)<<7,e<z)||(e=r.get(t+2),n+=(e&lt)<<14,e<z)||(e=r.get(t+3),n+=(e&lt)<<21,e<z)||(e=r.get(t+4),n+=(e&lt)*Po,e<z)||(e=r.get(t+5),n+=(e&lt)*Oo,e<z)||(e=r.get(t+6),n+=(e&lt)*Uo,e<z)||(e=r.get(t+7),n+=(e&lt)*No,e<z))return n;throw new RangeError("Could not decode varint")}function ko(r,t=0){return r instanceof Uint8Array?Fo(r,t):vu(r,t)}var Ko=new Float32Array([-0]),ne=new Uint8Array(Ko.buffer);function Qi(r,t,e){Ko[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function Ji(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],Ko[0]}var Vo=new Float64Array([-0]),ht=new Uint8Array(Vo.buffer);function ta(r,t,e){Vo[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function ea(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],Vo[0]}var Au=BigInt(Number.MAX_SAFE_INTEGER),Iu=BigInt(Number.MIN_SAFE_INTEGER),vt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<Au&&t>Iu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ra&&(o=0n,++n>ra&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):me}},me=new vt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var ra=4294967296n;function na(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function oa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Mo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Dt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Xr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var qo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Dt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Dt(this,4);return Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Dt(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Dt(this,4);let t=Ji(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Dt(this,4);let t=ea(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Dt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return oa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Dt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Dt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Dt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Dt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Dt(this,8);let t=Xr(this.buf,this.pos+=4),e=Xr(this.buf,this.pos+=4);return new vt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Fo(this.buf,this.pos);return this.pos+=Ut(t),t}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 lr(r){return new qo(r instanceof Uint8Array?r:r.subarray())}function Qr(r,t,e){let n=lr(r);return t.decode(n,void 0,e)}function Ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ot(i);o+i>t&&(n=ot(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function $o(){}var jo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Tu=Ho();function Bu(r){return globalThis.Buffer!=null?ot(r):Tu(r)}var dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye($o,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ye(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Zo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Jr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(Jr,e.length(),e)}uint64Number(t){return this._push(ur,Ut(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(Jr,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(Jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(zo,1,t?1:0)}fixed32(t){return this._push(hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push(hr,4,e.lo)._push(hr,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push(hr,4,e.lo)._push(hr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Qi,4,t)}double(t){return this._push(ta,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(zo,1,0):this.uint32(e)._push(_u,e,t)}string(t){let e=na(t);return e!==0?this.uint32(e)._push(Mo,e,t):this._push(zo,1,0)}fork(){return this.states=new jo(this),this.head=this.tail=new ye($o,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 ye($o,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Bu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function zo(r,t,e){t[e]=r&255}function Cu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Zo=class extends ye{next;constructor(t,e){super(Cu,t,e),this.next=void 0}};function Jr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function hr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function _u(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(dr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Du,t,r),this},dr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Lu,t,r),this});function Du(r,t,e){t.set(r,e)}function Lu(r,t,e){r.length<40?Mo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(st(r),e)}function Yo(){return new dr}function tn(r,t){let e=Yo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*en(r,t,e){let n=lr(r);yield*t.stream(n,void 0,"$",e)}var rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function nn(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function Go(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return nn("enum",rn.VARINT,e,n,o)}function on(r,t,e){return nn("message",rn.LENGTH_DELIMITED,r,t,e)}var pt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(pt||(pt={}));var Wo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Wo||(Wo={}));(function(r){r.codec=()=>Go(Wo)})(pt||(pt={}));var pr;(function(r){let t;r.codec=()=>(t==null&&(t=on((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function e(s){return tn(s,r.codec())}r.encode=e;function n(s,i){return Qr(s,r.codec(),i)}r.decode=n;function o(s,i){return en(s,r.codec(),i)}r.stream=o})(pr||(pr={}));var Xo;(function(r){let t;r.codec=()=>(t==null&&(t=on((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),pt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=pt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function e(s){return tn(s,r.codec())}r.encode=e;function n(s,i){return Qr(s,r.codec(),i)}r.decode=n;function o(s,i){return en(s,r.codec(),i)}r.stream=o})(Xo||(Xo={}));var sn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Lr(t),Et(e,void 0,"key"),this.iHash=t.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(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Vt(o)}update(t){return Be(this),this.iHash.update(t),this}digestInto(t){Be(this),Rr(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ia=(()=>{let r=((t,e,n)=>new sn(t,e).update(n).digest());return r.create=(t,e)=>new sn(t,e),r})();var aa=(r,t)=>(r+(r>=0?t:-t)/ca)/t;function Pu(r,t,e){De("scalar",r,Nt,e);let[[n,o],[s,i]]=t,a=aa(i*r,e),c=aa(-o*r,e),f=r-a*n-c*s,u=-a*o-c*i,l=f<Nt,p=u<Nt;l&&(f=-f),p&&(u=-u);let d=sr(Math.ceil(Le(e)/2))+oe;if(f<Nt||f>=d||u<Nt||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:p,k2:u}}function Jo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Qo(r,t){_t(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Bt(e.lowS,"lowS"),Bt(e.prehash,"prehash"),e.format!==void 0&&Jo(e.format),e}var ts=class extends Error{constructor(t=""){super(t)}},Lt={Err:ts,_tlv:{encode:(r,t)=>{let{Err:e}=Lt;if(Ct(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(r)+s+o+t},decode(r,t){let{Err:e}=Lt;t=K(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Lt;if(Kr(r),r<Nt)throw new t("integer: negative integers are not allowed");let e=nr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Lt;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Lt,o=K(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Lt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Lt._tlv);Object.freeze(Lt._int);Object.freeze(Lt);var Nt=BigInt(0),oe=BigInt(1),ca=BigInt(2),an=BigInt(3),Ou=BigInt(4);function fa(r,t={}){let e=Hr("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;_t(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=la(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(N,h,g){if(f&&h.is0())return Uint8Array.of(0);let{x:E,y:w}=h.toAffine(),b=n.toBytes(E);if(Bt(g,"isCompressed"),g){l();let A=!n.isOdd(w);return tt(ua(A),b)}else return tt(Uint8Array.of(4),b,n.toBytes(w))}function d(N){K(N,void 0,"Point");let{publicKey:h,publicKeyUncompressed:g}=u,E=N.length,w=N[0],b=N.subarray(1);if(f&&E===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(E===h&&(w===2||w===3)){let A=n.fromBytes(b);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=m(A),T;try{T=n.sqrt(C)}catch(k){let V=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let D=n.isOdd(T);return(w&1)===1!==D&&(T=n.neg(T)),{x:A,y:T}}else if(E===g&&w===4){let A=n.BYTES,C=n.fromBytes(b.subarray(0,A)),T=n.fromBytes(b.subarray(A,A*2));if(!x(C,T))throw new Error("bad point: is not on curve");return{x:C,y:T}}else throw new Error(`bad point: got length ${E}, expected compressed=${h} or uncompressed=${g}`)}let y=t.toBytes===void 0?p:t.toBytes,v=t.fromBytes===void 0?d:t.fromBytes;function m(N){let h=n.sqr(N),g=n.mul(h,N);return n.add(n.add(g,n.mul(N,s.a)),s.b)}function x(N,h){let g=n.sqr(h),E=m(N);return n.eql(g,E)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,an),Ou),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,I)))throw new Error("bad curve params: a or b");function L(N,h,g=!1){if(!n.isValid(h)||g&&n.is0(h))throw new Error(`bad point coordinate ${N}`);return h}function _(N){if(!(N instanceof B))throw new Error("Weierstrass Point expected")}function O(N){if(!c||!c.basises)throw new Error("no endo");return Pu(N,c.basises,o.ORDER)}function R(N,h,g,E,w){return g=new B(n.mul(g.X,N),g.Y,g.Z),h=ar(E,h),g=ar(w,g),h.add(g)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,g,E){this.X=L("x",h),this.Y=L("y",g,!0),this.Z=L("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:g,y:E}=h||{};if(!h||!n.isValid(g)||!n.isValid(E))throw new Error("invalid affine point");if(h instanceof B)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(E)?B.ZERO:new B(g,E,n.ONE)}static fromBytes(h){let g=B.fromAffine(v(K(h,void 0,"point")));return g.assertValidity(),g}static fromHex(h){return B.fromBytes(_e(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,g=!0){return M.createCache(this,h),g||this.multiply(an),this}assertValidity(){let h=this;if(h.is0()){if(t.allowInfinityPoint&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:E}=h.toAffine();if(!n.isValid(g)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!x(g,E))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){_(h);let{X:g,Y:E,Z:w}=this,{X:b,Y:A,Z:C}=h,T=n.eql(n.mul(g,C),n.mul(b,w)),D=n.eql(n.mul(E,C),n.mul(A,w));return T&&D}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:g}=s,E=n.mul(g,an),{X:w,Y:b,Z:A}=this,C=n.ZERO,T=n.ZERO,D=n.ZERO,P=n.mul(w,w),k=n.mul(b,b),V=n.mul(A,A),F=n.mul(w,b);return F=n.add(F,F),D=n.mul(w,A),D=n.add(D,D),C=n.mul(h,D),T=n.mul(E,V),T=n.add(C,T),C=n.sub(k,T),T=n.add(k,T),T=n.mul(C,T),C=n.mul(F,C),D=n.mul(E,D),V=n.mul(h,V),F=n.sub(P,V),F=n.mul(h,F),F=n.add(F,D),D=n.add(P,P),P=n.add(D,P),P=n.add(P,V),P=n.mul(P,F),T=n.add(T,P),V=n.mul(b,A),V=n.add(V,V),P=n.mul(V,F),C=n.sub(C,P),D=n.mul(V,k),D=n.add(D,D),D=n.add(D,D),new B(C,T,D)}add(h){_(h);let{X:g,Y:E,Z:w}=this,{X:b,Y:A,Z:C}=h,T=n.ZERO,D=n.ZERO,P=n.ZERO,k=s.a,V=n.mul(s.b,an),F=n.mul(g,b),Q=n.mul(E,A),et=n.mul(w,C),rt=n.add(g,E),Y=n.add(b,A);rt=n.mul(rt,Y),Y=n.add(F,Q),rt=n.sub(rt,Y),Y=n.add(g,w);let yt=n.add(b,C);return Y=n.mul(Y,yt),yt=n.add(F,et),Y=n.sub(Y,yt),yt=n.add(E,w),T=n.add(A,C),yt=n.mul(yt,T),T=n.add(Q,et),yt=n.sub(yt,T),P=n.mul(k,Y),T=n.mul(V,et),P=n.add(T,P),T=n.sub(Q,P),P=n.add(Q,P),D=n.mul(T,P),Q=n.add(F,F),Q=n.add(Q,F),et=n.mul(k,et),Y=n.mul(V,Y),Q=n.add(Q,et),et=n.sub(F,et),et=n.mul(k,et),Y=n.add(Y,et),F=n.mul(Q,Y),D=n.add(D,F),F=n.mul(yt,Y),T=n.mul(rt,T),T=n.sub(T,F),F=n.mul(rt,Q),P=n.mul(yt,P),P=n.add(P,F),new B(T,D,P)}subtract(h){return _(h),this.add(h.negate())}is0(){return this.equals(B.ZERO)}multiply(h){let{endo:g}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let E,w,b=A=>M.cached(this,A,C=>pe(B,C));if(g){let{k1neg:A,k1:C,k2neg:T,k2:D}=O(h),{p:P,f:k}=b(C),{p:V,f:F}=b(D);w=k.add(F),E=R(g.beta,P,V,A,T)}else{let{p:A,f:C}=b(h);E=A,w=C}return pe(B,[E,w])[0]}multiplyUnsafe(h){let{endo:g}=t,E=this,w=h;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Nt||E.is0())return B.ZERO;if(w===oe)return E;if(M.hasCache(this))return this.multiply(w);if(g){let{k1neg:b,k1:A,k2neg:C,k2:T}=O(w),{p1:D,p2:P}=Ki(B,E,A,T);return R(g.beta,D,P,b,C)}else return M.unsafe(E,w)}toAffine(h){let g=this,E=h,{X:w,Y:b,Z:A}=g;if(n.eql(A,n.ONE))return{x:w,y:b};let C=g.is0();E==null&&(E=C?n.ONE:n.inv(A));let T=n.mul(w,E),D=n.mul(b,E),P=n.mul(A,E);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:T,y:D}}isTorsionFree(){let{isTorsionFree:h}=t;return i===oe?!0:h?h(B,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===oe?this:h?h(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===oe?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Bt(h,"isCompressed"),this.assertValidity(),y(B,this,h)}toHex(h=!0){return Ce(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=o.BITS,M=new Oe(B,t.endo?Math.ceil(U/2):U);return U>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function ua(r){return Uint8Array.of(r?2:3)}function la(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Uu(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?rr:t.randomBytes,o=Object.assign(la(r.Fp,e),{seed:Math.max(wo(e.ORDER),16)});function s(d){try{let y=e.fromBytes(d);return e.isValidNot0(y)}catch{return!1}}function i(d,y){let{publicKey:v,publicKeyUncompressed:m}=o;try{let x=d.length;return y===!0&&x!==v||y===!1&&x!==m?!1:!!r.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,xo(K(d,o.seed,"seed"),e.ORDER)}function c(d,y=!0){return r.BASE.multiply(e.fromBytes(d)).toBytes(y)}function f(d){let{secretKey:y,publicKey:v,publicKeyUncompressed:m}=o,x=e._lengths;if(!ue(d))return;let S=K(d,void 0,"key").length,I=S===v||S===m,L=S===y||!!x?.includes(S);if(!(I&&L))return I}function u(d,y,v=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(y)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(d);return r.fromBytes(y).multiply(m).toBytes(v)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=$r(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:r,utils:l,lengths:o})}function ha(r,t,e={}){let n=t;Lr(n),_t(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?rr:e.randomBytes,s=e.hmac===void 0?(w,b)=>ia(n,w,b):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:f}=a,{keygen:u,getPublicKey:l,getSharedSecret:p,utils:d,lengths:y}=Uu(r,e),v={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*ca+oe<i.ORDER;function x(w){let b=c>>oe;return w>b}function S(w,b){if(!a.isValidNot0(b))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return b}function I(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(w,b){Jo(b);let A=y.signature,C=b==="compact"?A:b==="recovered"?A+1:void 0;return K(w,C)}class _{r;s;recovery;constructor(b,A,C){if(this.r=S("r",b),this.s=S("s",A),C!=null){if(I(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(b,A=v.format){L(b,A);let C;if(A==="der"){let{r:k,s:V}=Lt.toSig(K(b));return new _(k,V)}A==="recovered"&&(C=b[0],A="compact",b=b.subarray(1));let T=y.signature/2,D=b.subarray(0,T),P=b.subarray(T,T*2);return new _(a.fromBytes(D),a.fromBytes(P),C)}static fromHex(b,A){return this.fromBytes(_e(b),A)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new _(this.r,this.s,b)}recoverPublicKey(b){let{r:A,s:C}=this,T=this.assertRecovery(),D=T===2||T===3?A+c:A;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(D),k=r.fromBytes(tt(ua((T&1)===0),P)),V=a.inv(D),F=R(K(b,void 0,"msgHash")),Q=a.create(-F*V),et=a.create(C*V),rt=r.BASE.multiplyUnsafe(Q).add(k.multiplyUnsafe(et));if(rt.is0())throw new Error("invalid recovery: point at infinify");return rt.assertValidity(),rt}hasHighS(){return x(this.s)}toBytes(b=v.format){if(Jo(b),b==="der")return _e(Lt.hexFromSig(this));let{r:A,s:C}=this,T=a.toBytes(A),D=a.toBytes(C);return b==="recovered"?(I(),tt(Uint8Array.of(this.assertRecovery()),T,D)):tt(T,D)}toHex(b){return Ce(this.toBytes(b))}}Object.freeze(_.prototype),Object.freeze(_);let O=e.bits2int===void 0?function(b){if(b.length>8192)throw new Error("input is too large");let A=le(b),C=b.length*8-f;return C>0?A>>BigInt(C):A}:e.bits2int,R=e.bits2int_modN===void 0?function(b){return a.create(O(b))}:e.bits2int_modN,B=sr(f);function U(w){return De("num < 2^"+f,w,Nt,B),a.toBytes(w)}function M(w,b){return K(w,void 0,"message"),b?K(n(w),void 0,"prehashed message"):w}function N(w,b,A){let{lowS:C,prehash:T,extraEntropy:D}=Qo(A,v);w=M(w,T);let P=R(w),k=a.fromBytes(b);if(!a.isValidNot0(k))throw new Error("invalid private key");let V=[U(k),U(P)];if(D!=null&&D!==!1){let rt=D===!0?o(y.secretKey):D;V.push(K(rt,void 0,"extraEntropy"))}let F=tt(...V),Q=P;function et(rt){let Y=O(rt);if(!a.isValidNot0(Y))return;let yt=a.inv(Y),we=r.BASE.multiply(Y).toAffine(),qe=a.create(we.x);if(qe===Nt)return;let vr=a.create(yt*a.create(Q+qe*k));if(vr===Nt)return;let Ts=(we.x===qe?0:2)|Number(we.y&oe),Bs=vr;return C&&x(vr)&&(Bs=a.neg(vr),Ts^=1),new _(qe,Bs,m?void 0:Ts)}return{seed:F,k2sig:et}}function h(w,b,A={}){let{seed:C,k2sig:T}=N(w,b,A);return vi(n.outputLen,a.BYTES,s)(C,T).toBytes(A.format)}function g(w,b,A,C={}){let{lowS:T,prehash:D,format:P}=Qo(C,v);if(A=K(A,void 0,"publicKey"),b=M(b,D),!ue(w)){let k=w instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}L(w,P);try{let k=_.fromBytes(w,P),V=r.fromBytes(A);if(T&&k.hasHighS())return!1;let{r:F,s:Q}=k,et=R(b),rt=a.inv(Q),Y=a.create(et*rt),yt=a.create(F*rt),we=r.BASE.multiplyUnsafe(Y).add(V.multiplyUnsafe(yt));return we.is0()?!1:a.create(we.x)===F}catch{return!1}}function E(w,b,A={}){let{prehash:C}=Qo(A,v);return b=M(b,C),_.fromBytes(w,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:p,utils:d,lengths:y,Point:r,sign:h,verify:g,recoverPublicKey:E,Signature:_,hash:n})}var rs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Nu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var da=BigInt(2);function Fu(r){let t=rs.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=H(u,e,t)*u%t,p=H(l,e,t)*u%t,d=H(p,da,t)*f%t,y=H(d,o,t)*d%t,v=H(y,s,t)*y%t,m=H(v,a,t)*v%t,x=H(m,c,t)*m%t,S=H(x,a,t)*v%t,I=H(S,e,t)*u%t,L=H(I,i,t)*y%t,_=H(L,n,t)*f%t,O=H(_,da,t);if(!es.eql(es.sqr(O),r))throw new Error("Cannot find square root");return O}var es=Re(rs.p,{sqrt:Fu}),ku=fa(rs,{Fp:es,endo:Nu}),Ne=ha(ku,wi);function pa(r,t,e,n){let o=Ye.digest(e instanceof Uint8Array?e:e.subarray());if(Gr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ne.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new fr(String(s))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new fr(String(s))}}var cn=class{type="secp256k1";raw;_key;constructor(t){this._key=ya(t),this.raw=ma(this._key)}toMultihash(){return bt.digest(Te(this))}toCID(){return q.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}verify(t,e,n){return pa(this._key,e,t,n)}};function ga(r){return new cn(r)}function ma(r){return Ne.Point.fromBytes(r).toBytes()}function ya(r){try{return Ne.Point.fromBytes(r),r}catch(t){throw new Ar(String(t))}}function ba(r){let{Type:t,Data:e}=pr.decode(r.digest),n=e??new Uint8Array;switch(t){case pt.Ed25519:return Xi(n);case pt.secp256k1:return ga(n);case pt.ECDSA:return ri(n);default:throw new He}}function Te(r){return pr.encode({Type:pt[r.type],Data:r.raw})}var wa=Symbol.for("nodejs.util.inspect.custom"),Ku=114,mr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return q.createV1(Ku,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return nt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return nt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[wa](){return`PeerId(${this.toString()})`}},fn=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},un=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ln=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Vu=2336,yr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=bt.digest(st(this.url))}[wa](){return`PeerId(${this.url})`}[Tn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return q.createV1(Vu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=$(t)),t.toString()===this.toString())}};var Mu=114,xa=2336;function Ea(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=Yt(W.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return ns(q.parse(r));if(t==null)throw new St('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=Yt(t.decode(r))}return va(e)}function va(r){if(Hu(r))return new fn({multihash:r});if(qu(r))try{let t=ba(r);if(t.type==="Ed25519")return new un({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ln({multihash:r,publicKey:t})}catch{let e=$(r.digest);return new yr(new URL(e))}throw new Tr("Supplied PeerID Multihash is invalid")}function ns(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Mu&&r.code!==xa)throw new Ir("Supplied PeerID CID is invalid");if(r.code===xa){let t=$(r.multihash.digest);return new yr(new URL(t))}return va(r.multihash)}function qu(r){return r.code===bt.code}function Hu(r){return r.code===Ye.code}function $u(r){return r.buffer instanceof ArrayBuffer}function gr(r){return $u(r)?r:r.slice()}var ut=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},$t=class extends Error{static name="ValidationError";name="ValidationError"},hn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},dn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var pn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,t);if(!Number.isNaN(p))return p});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var zu=45,ju=15,mn=new pn;function Sa(r){if(!(r.length>ju))return mn.new(r).parseWith(()=>mn.readIPv4Addr())}function Aa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>zu))return mn.new(r).parseWith(()=>mn.readIPv6Addr())}function yn(r){return!!Sa(r)}function Ia(r){return!!Aa(r)}function ss(r){return t=>$(t,r)}function is(r){return t=>st(t,r)}function Fe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ge(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ta(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=st(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return wt([e,o],e.length+o.length)}function Ba(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Zt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return wt([e,o],e.length+o.length)}function as(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=$(t,"base32"),o=Fe(e);return`${n}:${o}`}var cs=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new ut("Invalid byte value in IP address");t[n]=o}),t},Ca=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=yn(e[n]),i;s&&(i=cs(e[n]),e[n]=$(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,$(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new ut("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},_a=function(r){if(r.byteLength!==4)throw new ut("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Da=function(r){if(r.byteLength!==16)throw new ut("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ut(`Invalid IPv6 address "${e}"`)}};function La(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ut(`Invalid IPv6 address "${r}"`)}}var os=Object.values(Ge).map(r=>r.decoder),Zu=(function(){let r=os[0].or(os[1]);return os.slice(2).forEach(t=>r=r.or(t)),r})();function Ra(r){return Zu.decode(r)}function Pa(r){return t=>r.encoder.encode(t)}function Yu(r){if(parseInt(r).toString()!==r)throw new $t("Value must be an integer")}function Gu(r){if(r<0)throw new $t("Value must be a positive integer, or zero")}function Wu(r){return t=>{if(t>r)throw new $t(`Value must be smaller than or equal to ${r}`)}}function Xu(...r){return t=>{for(let e of r)e(t)}}var br=Xu(Yu,Gu,Wu(65535));var at=-1,fs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new dn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},zt=new fs,kl=[{code:4,name:"ip4",size:32,valueToBytes:cs,bytesToValue:_a,validate:r=>{if(!yn(r))throw new $t(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ge,bytesToValue:Fe,validate:br},{code:273,name:"udp",size:16,valueToBytes:ge,bytesToValue:Fe,validate:br},{code:33,name:"dccp",size:16,valueToBytes:ge,bytesToValue:Fe,validate:br},{code:41,name:"ip6",size:128,valueToBytes:Ca,bytesToValue:Da,stringToValue:La,validate:r=>{if(!Ia(r))throw new $t(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:ss("base10"),valueToBytes:is("base10")},{code:53,name:"dns",size:at},{code:54,name:"dns4",size:at},{code:55,name:"dns6",size:at},{code:56,name:"dnsaddr",size:at},{code:132,name:"sctp",size:16,valueToBytes:ge,bytesToValue:Fe,validate:br},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:ss("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?is("base58btc")(r):q.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:as,valueToBytes:Ta},{code:445,name:"onion3",size:296,bytesToValue:as,valueToBytes:Ba},{code:446,name:"garlic64",size:at},{code:447,name:"garlic32",size:at},{code:448,name:"tls"},{code:449,name:"sni",size:at},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:at,bytesToValue:Pa(qn),valueToBytes:Ra},{code:480,name:"http"},{code:481,name:"http-path",size:at,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:at}];kl.forEach(r=>{zt.addProtocol(r)});function Oa(r){let t=[],e=0;for(;e<r.length;){let n=ko(r,e),o=zt.getProtocol(n),s=Ut(n),i=Kl(o,r,e+s),a=0;i>0&&o.size===at&&(a=Ut(i));let c=s+a+i,f={code:n,name:o.name,bytes:gr(r.subarray(e,e+c))};if(i>0){let u=e+s+a,l=r.subarray(u,u+i);f.value=o.bytesToValue?.(l)??$(l)}t.push(f),e+=c}return t}function Ua(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=zt.getProtocol(n.code),s=Ut(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??st(n.value),a=i.byteLength,o.size===at&&(c=Ut(a)));let f=new Uint8Array(s+c+a),u=0;ur(n.code,f,u),u+=s,i!=null&&(o.size===at&&(ur(a,f,u),u+=c),f.set(i,u)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return wt(e,t)}function Na(r){if(r.charAt(0)!=="/")throw new ut('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=zt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ut(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ut(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ut("Incomplete multiaddr");return t}function Fa(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=zt.getProtocol(t.code);if(e==null)throw new ut(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Kl(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:ko(t,e)}var Vl=Symbol.for("nodejs.util.inspect.custom"),us=Symbol.for("@multiformats/multiaddr");function Ml(r){if(r==null&&(r="/"),ka(r))return r.getComponents();if(r instanceof Uint8Array)return Oa(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Na(r);if(Array.isArray(r))return r;throw new ut("Must be a string, Uint8Array, Component[], or another Multiaddr")}var gn=class r{[us]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Ml(t),e.validate!==!1&&ql(this)}get bytes(){return this.#r==null&&(this.#r=Ua(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Fa(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new hn(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return nt(this.bytes,t.bytes)}[Vl](){return`Multiaddr(${this.toString()})`}};function ql(r){r.getComponents().forEach(t=>{let e=zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function ka(r){return!!r?.[us]}function bn(r){return new gn(r)}function ke(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}async function*wr(r,t={}){let e=r.getReader();try{for(;;){let n=await e.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await e.cancel(),e.releaseLock()}}var Ma=Symbol.for("@achingbrain/uint8arraylist");function Ka(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Ke(r){return!!r?.[Ma]}var Va=class r{bufs;length;[Ma]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ke(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ke(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ka(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ka(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ke(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return wt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:wt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ke(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ot(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=J(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=J(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ot(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=J(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=J(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=J(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!nt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var wn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*Ve(r,t={}){let e=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let s of r){if(typeof s=="string"&&(s=new TextEncoder().encode(s)),Ke(s)&&(s=s.subarray()),o+=n.decode(s,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new wn("Incoming message too long");let i=o.split(e);o=i.pop()??"";for(let a=0;a<i.length;a++)yield JSON.parse(i[a])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function At(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var hs=hc(Ha(),1);var ds=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},$a=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function ps(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,u=new Promise((l,p)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){p($a(i));return}if(i&&(c=()=>{p($a(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,p),e===Number.POSITIVE_INFINITY)return;let d=new ds;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(y){p(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?p(o):(d.message=o??`Promise timed out after ${e} milliseconds`,p(d))},e)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}function ms(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var zl=100,Me=class{#t=[];#e=0;enqueue(t,e){let{priority:n=0,id:o}=e??{},{size:s}=this,i={priority:n,id:o,run:t};if(s===0){this.#t.length=0,this.#e=0,this.#t.push(i);return}if(this.#t.at(-1).priority>=n){this.#t.push(i);return}this.#r();let a=ms(this.#t,i,(c,f)=>f.priority-c.priority);this.#t.splice(a,0,i)}setPriority(t,e){let n=this.#t.findIndex((s,i)=>i>=this.#e&&s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}remove(t){let e=this.#t.findIndex((n,o)=>o<this.#e?!1:typeof t=="string"?n.id===t:n.run===t);e!==-1&&this.#t.splice(e,1)}dequeue(){if(this.#e===this.#t.length)return;let t=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>zl&&this.#e>this.#t.length/2&&this.#r(),t?.run}filter(t){let e=[];for(let n=this.#e;n<this.#t.length;n++){let o=this.#t[n];o.priority===t.priority&&e.push(o.run)}return e}get size(){return this.#t.length-this.#e}#r(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var Er=class extends hs.default{#t;#e;#r=0;#d;#m=!1;#w=!1;#c;#B=0;#x=0;#f;#u;#a;#i=[];#s=0;#n;#C;#o=0;#y;#l;#P=1n;#g=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Me,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#n=new t.queueClass,this.#C=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#M()}#v(t){for(;this.#s<this.#i.length;){let n=this.#i[this.#s];if(n!==void 0&&t-n>=this.#c)this.#s++;else break}(this.#s>100&&this.#s>this.#i.length/2||this.#s===this.#i.length)&&(this.#i=this.#i.slice(this.#s),this.#s=0)}#O(t){this.#a?this.#i.push(t):this.#r++}#U(){this.#a?this.#i.length>this.#s&&this.#i.pop():this.#r>0&&this.#r--}#S(){return this.#i.length-this.#s}get#N(){return this.#e?!0:this.#a?this.#S()<this.#d:this.#r<this.#d}get#F(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#b(),this.emit("next")}#K(){this.#u=void 0,this.#L(),this.#D()}#V(t){if(this.#a){if(this.#v(t),this.#S()>=this.#d){let n=this.#i[this.#s],o=this.#c-(t-n);return this.#A(o),!0}return!1}if(this.#f===void 0){let e=this.#B-t;if(e<0){if(this.#x>0){let n=t-this.#x;if(n<this.#c)return this.#A(this.#c-n),!0}this.#r=this.#t?this.#o:0}else return this.#A(e),!0}return!1}#A(t){this.#u===void 0&&(this.#u=setTimeout(()=>{this.#K()},t))}#I(){this.#f&&(clearInterval(this.#f),this.#f=void 0)}#_(){this.#u&&(clearTimeout(this.#u),this.#u=void 0)}#b(){if(this.#n.size===0){if(this.#I(),this.emit("empty"),this.#o===0){if(this.#_(),this.#a&&this.#s>0){let e=Date.now();this.#v(e)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let e=Date.now(),n=!this.#V(e);if(this.#N&&this.#F){let o=this.#n.dequeue();this.#e||(this.#O(e),this.#p()),this.emit("active"),o(),n&&this.#D(),t=!0}}return t}#D(){this.#e||this.#f!==void 0||this.#a||(this.#f=setInterval(()=>{this.#L()},this.#c),this.#B=Date.now()+this.#c)}#L(){this.#a||(this.#r===0&&this.#o===0&&this.#f&&this.#I(),this.#r=this.#t?this.#o:0),this.#T(),this.#p()}#T(){for(;this.#b(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#T()}setPriority(t,e){if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${e}\` (${typeof e})`);this.#n.setPriority(t,e)}async add(t,e={}){return e={timeout:this.timeout,...e,id:e.id??(this.#P++).toString()},new Promise((n,o)=>{let s=Symbol(`task-${e.id}`),i=()=>{},a=async()=>{i(),this.#o++,this.#g.set(s,{id:e.id,priority:e.priority??0,startTime:Date.now(),timeout:e.timeout});let f;try{try{e.signal?.throwIfAborted()}catch(p){throw this.#q(),this.#g.delete(s),p}this.#x=Date.now();let u=t({signal:e.signal});if(e.timeout&&(u=ps(Promise.resolve(u),{milliseconds:e.timeout,message:`Task timed out after ${e.timeout}ms (queue has ${this.#o} running, ${this.#n.size} waiting)`})),e.signal){let{signal:p}=e;u=Promise.race([u,new Promise((d,y)=>{f=()=>{y(p.reason)},p.addEventListener("abort",f,{once:!0})})])}let l=await u;n(l),this.emit("completed",l)}catch(u){o(u),this.emit("error",u)}finally{f&&e.signal?.removeEventListener("abort",f),this.#g.delete(s),queueMicrotask(()=>{this.#k()})}};this.#n.enqueue(a,e);let c=()=>{if(this.#n instanceof Me){this.#n.remove(a);return}this.#n.remove?.(e.id)};if(e.signal){let{signal:f}=e,u=()=>{i(),c(),o(f.reason),this.#b(),this.emit("next")};if(i=()=>{f.removeEventListener("abort",u),this.#E.delete(i)},f.aborted){u();return}f.addEventListener("abort",u,{once:!0}),this.#E.add(i)}this.emit("add"),this.#b()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#l?(this.#l=!1,this.#T(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#n=new this.#C,this.#I(),this.#R(),this.emit("empty"),this.#o===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#n.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#n.size<t||await this.#h("next",()=>this.#n.size<t)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#h("idle")}async onPendingZero(){this.#o!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,e)=>{let n=o=>{this.off("error",n),e(o)};this.on("error",n)})}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#n.size}sizeBy(t){return this.#n.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#M(){this.#e||(this.on("add",()=>{this.#n.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#R()}))}#q(){this.#e||(this.#U(),this.#p())}#R(){let t=this.#m;if(this.#e||this.#n.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let e;if(this.#a){let o=Date.now();this.#v(o),e=this.#S()}else e=this.#r;let n=e>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#n.size>0||this.isRateLimited&&this.#n.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t,timeoutRemaining:t.timeout?Math.max(0,t.startTime+t.timeout-Date.now()):void 0}))}};var be=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},It=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};var En={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},vn=class{url;started;httpQueue;shutDownController;timeout;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,e){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new Er({concurrency:e.concurrentRequests??En.concurrentRequests}),this.inFlightRequests=new Map,this.url=e.url instanceof URL?e.url:new URL(e.url),this.timeout=e.timeout??En.timeout,this.filterAddrs=e.filterAddrs,this.filterProtocols=e.filterProtocols,this.cacheName=e.cacheName??En.cacheName,this.cacheTTL=e.cacheTTL??En.cacheTTL}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,e={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=ke([this.shutDownController.signal,n,e.signal]);let s=At(),i=At(),a=0;this.httpQueue.add(async()=>(s.resolve(),i.promise));try{await s.promise;let c=new URL(`${this.url}routing/v1/providers/${t}`);this.#e(c,e.filterAddrs,e.filterProtocols);let f=await this.#r(c.toString(),{headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o});if(!f.ok){if(f.status===404)return;throw f.status===422?new be("Request does not conform to schema or semantic constraints"):new It(`Unexpected status code: ${f.status}`)}let u=f.headers.get("Content-Type");if(u==null)throw new It("No Content-Type header received");if(f.body==null){if(u!=="application/x-ndjson")throw new It("Routing response had no body");return}if(u.startsWith("application/json")){let p=(await f.json()).Providers??[];for(let d of p){let y=this.#t(d);y!=null&&(a++,yield y)}}else if(u.includes("application/x-ndjson"))for await(let l of Ve(wr(f.body))){let p=this.#t(l);p!=null&&(a++,yield p)}else throw new It(`Unsupported Content-Type: ${u}`)}finally{o.clear(),i.resolve(),this.log("getProviders finished found %d providers for %c",a,t)}}async*getPeers(t,e={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=ke([this.shutDownController.signal,n,e.signal]);let s=At(),i=At();this.httpQueue.add(async()=>(s.resolve(),i.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/peers/${t}`);this.#e(a,e.filterAddrs,e.filterProtocols);let c=await this.#r(a.toString(),{headers:{Accept:"application/x-ndjson"},signal:o});if(c.status===404)return;if(c.status===422)throw new be("Request does not conform to schema or semantic constraints");if(c.body==null)throw new It("Routing response had no body");if(c.headers.get("Content-Type")?.startsWith("application/json")){let l=(await c.json()).Peers??[];for(let p of l){let d=this.#t(p);d!=null&&(yield d)}}else for await(let u of Ve(wr(c.body))){let l=this.#t(u);l!=null&&(yield l)}}catch(a){this.log.error("getPeers errored - %e",a)}finally{o.clear(),i.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,e={}){let n;if(q.asCID(t)===t||t instanceof q)n=t.toV1().toString();else throw new St("Key must be CID");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),s=ke([this.shutDownController.signal,o,e.signal]);let i=At(),a=At();this.httpQueue.add(async()=>(i.resolve(),a.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#e(c,e.filterAddrs,e.filterProtocols);let f=await this.#r(c.toString(),{headers:{Accept:"application/x-ndjson"},signal:s});if(f.status===404)return;if(f.status===422)throw new be("Request does not conform to schema or semantic constraints");if(f.body==null)throw new It("Routing response had no body");if(f.headers.get("Content-Type")?.startsWith("application/json")){let p=(await f.json()).Peers??[];for(let d of p){let y=this.#t(d);y!=null&&(yield y)}}else for await(let l of Ve(wr(f.body))){let p=this.#t(l);p!=null&&(yield p)}}catch(c){this.log.error("getClosestPeers errored - %e",c)}finally{s.clear(),a.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,e={}){this.log("getIPNS starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=ke([this.shutDownController.signal,n,e.signal]);let s=At(),i=At();this.httpQueue.add(async()=>(s.resolve(),i.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let c=await this.#r(a,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o});if(this.log("getIPNS GET %s %d",a,c.status),c.status===404)throw new Ft("No matching records found");if(c.status===422)throw new be("Request does not conform to schema or semantic constraints");if(!c.ok)throw new It(`Unexpected status code: ${c.status}`);let f=c.headers.get("Content-Type");if(f==null||!f.includes("application/vnd.ipfs.ipns-record"))throw new Ft("No matching records found");if(c.body==null)throw new It("GET ipns response had no body");let u=await c.arrayBuffer();return new Uint8Array(u,0,u.byteLength)}catch(c){throw this.log.error("getIPNS GET %s error - %e",a,c),c}finally{o.clear(),i.resolve(),this.log("getIPNS finished: %c",t)}}async putIPNS(t,e,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),s=ke([this.shutDownController.signal,o,n.signal]);let i=At(),a=At();this.httpQueue.add(async()=>(i.resolve(),a.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let f=await this.#r(c,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:gr(e),signal:s});if(this.log("putIPNS PUT %s %d",c,f.status),f.status!==200)throw new It("PUT ipns response had status other than 200")}catch(f){throw this.log.error("putIPNS PUT %s error - %e",c,f.stack),f}finally{s.clear(),a.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let e=[],n=t.Addrs?.map(bn)??[];return t.Protocols!=null&&e.push(...t.Protocols),t.Protocol!=null&&(e.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Ea(t.ID),Addrs:n,Protocols:e}}catch(e){this.log.error("could not conform record to peer schema - %e",e)}}#e(t,e,n){if(e!=null||this.filterAddrs!=null){let o=e?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#r(t,e){let n=e.method??"GET",o=`${n}-${t}`;if(n==="GET"){let c=await this.cache?.match(t);if(c!=null){if(parseInt(c.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(c),c;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let s=this.inFlightRequests.get(o);if(s!=null){let c=await s;return this.log("deduplicating outgoing request for %s",o),c.clone()}this.log("outgoing request:"),this.logRequest(t,e);let i=fetch(t,e).then(async c=>{if(this.log("incoming response:"),this.logResponse(c),this.cache!=null&&c.ok&&n==="GET"){let f=Date.now()+this.cacheTTL,u=new Headers(c.headers);u.set("x-cache-expires",f.toString());let l=new Response(c.clone().body,{status:c.status,statusText:c.statusText,headers:u});await this.cache.put(t,l)}return c}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,i),await i}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,e){let n=new Headers(e.headers);this.log("%s %s HTTP/1.1",e.method??"GET",t);for(let[o,s]of n.entries())this.log("%s: %s",o,s)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[e,n]of t.headers.entries())this.log("%s: %s",e,n)}};function jl(r){return r[Symbol.asyncIterator]!=null}function Zl(r){if(jl(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var za=Zl;function Yl(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var ja=Yl;function Gl(r){return r[Symbol.asyncIterator]!=null}function Wl(r,t){let e=0;if(Gl(r))return(async function*(){for await(let c of r)yield t(c,e++)})();let n=ja(r),{value:o,done:s}=n.next();if(s===!0)return(function*(){})();let i=t(o,e++);if(typeof i.then=="function")return(async function*(){yield await i;for(let c of n)yield t(c,e++)})();let a=t;return(function*(){yield i;for(let c of n)yield a(c,e++)})()}var Za=Wl;function Ya(r){return t=>new vn(t,r)}function Sn(r){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var An=st("/ipns/");function Ga(r){return nt(r.subarray(0,An.byteLength),An)}var ys=class{name="delegated-http-router";client;constructor(t,e){this.client=Ya(e)(t)}async provide(t,e){}async cancelReprovide(t,e){}async*findProviders(t,e){yield*Za(this.client.getProviders(t,e),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(t,e,n){if(!Ga(t))return;let o=Yt(t.slice(An.length)),s=q.createV1(114,o);await this.client.putIPNS(s,e,n)}async get(t,e){if(!Ga(t))throw new Ft("Not found");let n=Yt(t.slice(An.length)),o=q.createV1(114,n);try{return await this.client.getIPNS(o,e)}catch(s){throw s.name==="BadResponseError"?new Ft("Not found"):s}}async findPeer(t,e){let n=await za(this.client.getPeers(t.toCID(),e));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Ft("Not found")}async*getClosestPeers(t,e){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function Wa(r){return t=>new ys(t,Sn(r))}var Xa="[a-fA-F\\d:]",se=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${Xa})|(?<=${Xa})(?=\\s|$))`:"",Rt="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",X="[a-fA-F\\d]{1,4}",In=`
14
3
  (?:
15
- (?:${st}:){7}(?:${st}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
16
- (?:${st}:){6}(?:${Qt}|:${st}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
17
- (?:${st}:){5}(?::${Qt}|(?::${st}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
18
- (?:${st}:){4}(?:(?::${st}){0,1}:${Qt}|(?::${st}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
19
- (?:${st}:){3}(?:(?::${st}){0,2}:${Qt}|(?::${st}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
20
- (?:${st}:){2}(?:(?::${st}){0,3}:${Qt}|(?::${st}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
21
- (?:${st}:){1}(?:(?::${st}){0,4}:${Qt}|(?::${st}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
22
- (?::(?:(?::${st}){0,5}:${Qt}|(?::${st}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
4
+ (?:${X}:){7}(?:${X}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
5
+ (?:${X}:){6}(?:${Rt}|:${X}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
6
+ (?:${X}:){5}(?::${Rt}|(?::${X}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
7
+ (?:${X}:){4}(?:(?::${X}){0,1}:${Rt}|(?::${X}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
8
+ (?:${X}:){3}(?:(?::${X}){0,2}:${Rt}|(?::${X}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
9
+ (?:${X}:){2}(?:(?::${X}){0,3}:${Rt}|(?::${X}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
10
+ (?:${X}:){1}(?:(?::${X}){0,4}:${Rt}|(?::${X}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
11
+ (?::(?:(?::${X}){0,5}:${Rt}|(?::${X}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
23
12
  )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
24
- `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),im=new RegExp(`(?:^${Qt}$)|(?:^${Zo}$)`),sm=new RegExp(`^${Qt}$`),am=new RegExp(`^${Zo}$`),fa=e=>e&&e.exact?im:new RegExp(`(?:${ke(e)}${Qt}${ke(e)})|(?:${ke(e)}${Zo}${ke(e)})`,"g");fa.v4=e=>e&&e.exact?sm:new RegExp(`${ke(e)}${Qt}${ke(e)}`,"g");fa.v6=e=>e&&e.exact?am:new RegExp(`${ke(e)}${Zo}${ke(e)}`,"g");var la=fa;function da(e){let t=(...r)=>e(...r);return Object.defineProperty(t,"name",{value:`functionTimeout(${e.name||"<anonymous>"})`,configurable:!0}),t}function ul(){return!1}var{toString:cm}=Object.prototype;function ha(e){return cm.call(e)==="[object RegExp]"}var fl={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function pa(e,t={}){if(!ha(e))throw new TypeError("Expected a RegExp instance");let r=Object.keys(fl).map(o=>(typeof t[o]=="boolean"?t[o]:e[o])?fl[o]:"").join(""),n=new RegExp(t.source||e.source,r);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:e.lastIndex,n}function ma(e,t,{timeout:r}={}){try{return da(()=>pa(e).test(t),{timeout:r})()}catch(n){if(ul(n))return!1;throw n}}var um=15,fm=45,ll={timeout:400};function ya(e){return e.length>fm?!1:ma(la.v6({exact:!0}),e,ll)}function dl(e){return e.length>um?!1:ma(la.v4({exact:!0}),e,ll)}var hl={http:"80",https:"443",ws:"80",wss:"443"},lm=["http","https","ws","wss"];function pl(e,t){t=t??{};let r=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:i,path:s}=dm(e),a=[hm(o,r),pm(i,n),mm(n)];s!=null&&a.push(ym(s));let c="/"+a.filter(u=>!!u).reduce((u,f)=>u.concat(f),[]).join("/");return go(c)}function dm(e){let[t]=e.split(":");lm.includes(t)||(e="http"+e.substring(t.length));let{protocol:r,hostname:n,port:o,pathname:i,search:s}=new URL(e);if(o==null||o===""){let c=gm(t);c!=null&&(o=c),c==null&&r==="http:"&&(o="80")}let a;return i!=null&&i!==""&&i!=="/"&&(i.startsWith("/")&&(i=i.substring(1)),a=i),s!=null&&s!==""&&(a=a??"",a+=s),{scheme:t,hostname:n,port:o,path:a}}function hm(e,t){if(!(e==null||e==="")){if(dl(e))return["ip4",e];if(ya(e))return["ip6",e];if(e[0]==="["){let r=e.substring(1,e.length-1);if(ya(r))return["ip6",r]}return[t,e]}}function pm(e,t){if(!(e==null||e===""))return t==="udp"?["udp",e]:["tcp",e]}function mm(e){if(e.match(/^tcp$|^udp$/)==null)return e==="https"?["/tls/http"]:e==="wss"?["/tls/ws"]:[e]}function ym(e){if(!(e==null||e===""))return["http-path",encodeURIComponent(e)]}function gm(e){if(!(e==null||e===""||hl[e]==null))return hl[e]}var bm=["https://trustless-gateway.link","https://4everland.io"],xm=2336;function wm(e){return e=e.toString(),{id:Ns(H.createV1(xm,St.digest(V(e)))),multiaddrs:[pl(e)]}}function Em(e){return new URL(z(e.id.toMultihash().digest))}var ga=class{name="http-gateway-router";gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??bm).map(r=>wm(r)),this.shuffle=t.shuffle??!0}async*findProviders(t,r){yield*(this.shuffle?this.gateways.toSorted(()=>Math.random()>.5?1:-1):this.gateways).map(n=>({...n,protocols:["transport-ipfs-gateway-http"],routing:"http-gateway-routing"}))}toString(){return`HTTPGatewayRouter([${this.gateways.map(t=>Em(t)).join(", ")}])`}};function ml(e={}){return new ga(e)}var ba=class{name="libp2p-router";libp2p;constructor(t){this.libp2p=t}async provide(t,r){await this.libp2p.contentRouting.provide(t,r)}async cancelReprovide(t,r){await this.libp2p.contentRouting.cancelReprovide(t,r)}async*findProviders(t,r){yield*this.libp2p.contentRouting.findProviders(t,r)}async put(t,r,n){await this.libp2p.contentRouting.put(t,r,n)}async get(t,r){return this.libp2p.contentRouting.get(t,r)}async findPeer(t,r){return this.libp2p.peerRouting.findPeer(t,r)}async*getClosestPeers(t,r){yield*this.libp2p.peerRouting.getClosestPeers(t,r)}toString(){return"Libp2pRouter()"}};function yl(e){return new ba(e)}return Sl(Sm);})();
13
+ `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),Xl=new RegExp(`(?:^${Rt}$)|(?:^${In}$)`),Ql=new RegExp(`^${Rt}$`),Jl=new RegExp(`^${In}$`),gs=r=>r&&r.exact?Xl:new RegExp(`(?:${se(r)}${Rt}${se(r)})|(?:${se(r)}${In}${se(r)})`,"g");gs.v4=r=>r&&r.exact?Ql:new RegExp(`${se(r)}${Rt}${se(r)}`,"g");gs.v6=r=>r&&r.exact?Jl:new RegExp(`${se(r)}${In}${se(r)}`,"g");var bs=gs;function ws(r){let t=(...e)=>r(...e);return Object.defineProperty(t,"name",{value:`functionTimeout(${r.name||"<anonymous>"})`,configurable:!0}),t}function Qa(){return!1}var{toString:th}=Object.prototype;function xs(r){return th.call(r)==="[object RegExp]"}var Ja={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function Es(r,t={}){if(!xs(r))throw new TypeError("Expected a RegExp instance");let e=Object.keys(Ja).map(o=>(typeof t[o]=="boolean"?t[o]:r[o])?Ja[o]:"").join(""),n=new RegExp(t.source||r.source,e);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:r.lastIndex,n}function vs(r,t,{timeout:e}={}){try{return ws(()=>Es(r).test(t),{timeout:e})()}catch(n){if(Qa(n))return!1;throw n}}var eh=15,rh=45,tc={timeout:400};function Ss(r){return r.length>rh?!1:vs(bs.v6({exact:!0}),r,tc)}function ec(r){return r.length>eh?!1:vs(bs.v4({exact:!0}),r,tc)}var rc={http:"80",https:"443",ws:"80",wss:"443"},nh=["http","https","ws","wss"];function nc(r,t){t=t??{};let e=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:s,path:i}=oh(r),a=[sh(o,e),ih(s,n),ah(n)];i!=null&&a.push(ch(i));let c="/"+a.filter(f=>!!f).reduce((f,u)=>f.concat(u),[]).join("/");return bn(c)}function oh(r){let[t]=r.split(":");nh.includes(t)||(r="http"+r.substring(t.length));let{protocol:e,hostname:n,port:o,pathname:s,search:i}=new URL(r);if(o==null||o===""){let c=fh(t);c!=null&&(o=c),c==null&&e==="http:"&&(o="80")}let a;return s!=null&&s!==""&&s!=="/"&&(s.startsWith("/")&&(s=s.substring(1)),a=s),i!=null&&i!==""&&(a=a??"",a+=i),{scheme:t,hostname:n,port:o,path:a}}function sh(r,t){if(!(r==null||r==="")){if(ec(r))return["ip4",r];if(Ss(r))return["ip6",r];if(r[0]==="["){let e=r.substring(1,r.length-1);if(Ss(e))return["ip6",e]}return[t,r]}}function ih(r,t){if(!(r==null||r===""))return t==="udp"?["udp",r]:["tcp",r]}function ah(r){if(r.match(/^tcp$|^udp$/)==null)return r==="https"?["/tls/http"]:r==="wss"?["/tls/ws"]:[r]}function ch(r){if(!(r==null||r===""))return["http-path",encodeURIComponent(r)]}function fh(r){if(!(r==null||r===""||rc[r]==null))return rc[r]}var uh=["https://trustless-gateway.link","https://4everland.io"],lh=2336;function hh(r){return r=r.toString(),{id:ns(q.createV1(lh,bt.digest(st(r)))),multiaddrs:[nc(r)]}}function dh(r){return new URL($(r.id.toMultihash().digest))}var As=class{name="http-gateway-router";gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??uh).map(e=>hh(e)),this.shuffle=t.shuffle??!0}async*findProviders(t,e){yield*(this.shuffle?this.gateways.toSorted(()=>Math.random()>.5?1:-1):this.gateways).map(n=>({...n,protocols:["transport-ipfs-gateway-http"],routing:"http-gateway-routing"}))}toString(){return`HTTPGatewayRouter([${this.gateways.map(t=>dh(t)).join(", ")}])`}};function oc(r={}){return new As(r)}var Is=class{name="libp2p-router";libp2p;constructor(t){this.libp2p=t}async provide(t,e){await this.libp2p.contentRouting.provide(t,e)}async cancelReprovide(t,e){await this.libp2p.contentRouting.cancelReprovide(t,e)}async*findProviders(t,e){yield*this.libp2p.contentRouting.findProviders(t,e)}async put(t,e,n){await this.libp2p.contentRouting.put(t,e,n)}async get(t,e){return this.libp2p.contentRouting.get(t,e)}async findPeer(t,e){return this.libp2p.peerRouting.findPeer(t,e)}async*getClosestPeers(t,e){yield*this.libp2p.peerRouting.getClosestPeers(t,e)}toString(){return"Libp2pRouter()"}};function sc(r){return new Is(r)}return dc(ph);})();
25
14
  /*! Bundled license information:
26
15
 
27
16
  @noble/curves/utils.js: