@helia/routers 0.0.0 → 1.0.0-e554493
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/README.md +4 -0
- package/dist/index.min.js +4 -4
- package/dist/src/delegated-http-routing.d.ts.map +1 -1
- package/dist/src/delegated-http-routing.js +1 -5
- package/dist/src/delegated-http-routing.js.map +1 -1
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +9 -5
- package/src/delegated-http-routing.ts +1 -6
- package/src/index.ts +5 -0
package/dist/index.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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 ch=Object.create;var $n=Object.defineProperty;var uh=Object.getOwnPropertyDescriptor;var lh=Object.getOwnPropertyNames;var fh=Object.getPrototypeOf,hh=Object.prototype.hasOwnProperty;var nr=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),me=(r,e)=>{for(var t in e)$n(r,t,{get:e[t],enumerable:!0})},Pa=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of lh(e))!hh.call(r,o)&&o!==t&&$n(r,o,{get:()=>e[o],enumerable:!(n=uh(e,o))||n.enumerable});return r};var Vt=(r,e,t)=>(t=r!=null?ch(fh(r)):{},Pa(e||!r||!r.__esModule?$n(t,"default",{value:r,enumerable:!0}):t,r)),dh=r=>Pa($n({},"__esModule",{value:!0}),r);var qa=nr((pm,$a)=>{var br=1e3,xr=br*60,Er=xr*60,or=Er*24,ph=or*7,gh=or*365.25;$a.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return mh(r);if(t==="number"&&isFinite(r))return e.long?wh(r):yh(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function mh(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*gh;case"weeks":case"week":case"w":return t*ph;case"days":case"day":case"d":return t*or;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Er;case"minutes":case"minute":case"mins":case"min":case"m":return t*xr;case"seconds":case"second":case"secs":case"sec":case"s":return t*br;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function yh(r){var e=Math.abs(r);return e>=or?Math.round(r/or)+"d":e>=Er?Math.round(r/Er)+"h":e>=xr?Math.round(r/xr)+"m":e>=br?Math.round(r/br)+"s":r+"ms"}function wh(r){var e=Math.abs(r);return e>=or?qn(r,e,or,"day"):e>=Er?qn(r,e,Er,"hour"):e>=xr?qn(r,e,xr,"minute"):e>=br?qn(r,e,br,"second"):r+" ms"}function qn(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var Ga=nr((gm,za)=>{function bh(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=qa(),t.destroy=f,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let l=0;for(let d=0;d<u.length;d++)l=(l<<5)-l+u.charCodeAt(d),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(u){let l,d=null,E,g;function h(...p){if(!h.enabled)return;let b=h,R=Number(new Date),v=R-(l||R);b.diff=v,b.prev=l,b.curr=R,l=R,p[0]=t.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let L=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(k,N)=>{if(k==="%%")return"%";L++;let y=t.formatters[N];if(typeof y=="function"){let C=p[L];k=y.call(b,C),p.splice(L,1),L--}return k}),t.formatArgs.call(b,p),(b.log||t.log).apply(b,p)}return h.namespace=u,h.useColors=t.useColors(),h.color=t.selectColor(u),h.extend=n,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(E!==t.namespaces&&(E=t.namespaces,g=t.enabled(u)),g),set:p=>{d=p}}),typeof t.init=="function"&&t.init(h),h}function n(u,l){let d=t(this.namespace+(typeof l>"u"?":":l)+u);return d.log=this.log,d}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let l,d=(typeof u=="string"?u:"").split(/[\s,]+/),E=d.length;for(l=0;l<E;l++)d[l]&&(u=d[l].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.slice(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...t.names.map(a),...t.skips.map(a).map(l=>"-"+l)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,d;for(l=0,d=t.skips.length;l<d;l++)if(t.skips[l].test(u))return!1;for(l=0,d=t.names.length;l<d;l++)if(t.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack||u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}za.exports=bh});var ja=nr((Oe,zn)=>{Oe.formatArgs=Eh;Oe.save=vh;Oe.load=Bh;Oe.useColors=xh;Oe.storage=Ah();Oe.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();Oe.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function xh(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Eh(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+zn.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}Oe.log=console.debug||console.log||(()=>{});function vh(r){try{r?Oe.storage.setItem("debug",r):Oe.storage.removeItem("debug")}catch{}}function Bh(){let r;try{r=Oe.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Ah(){try{return localStorage}catch{}}zn.exports=Ga()(Oe);var{formatters:Sh}=zn.exports;Sh.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var mu=nr(jr=>{"use strict";var Ip="[object ArrayBuffer]",Rt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ip}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},js="string",Rp=/^[0-9a-f]+$/i,kp=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Tp=/^[a-zA-Z0-9-_]+$/,wo=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=Rt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},ze=class{static toString(e,t=!1){let n=Rt.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},bo=class r{static isHex(e){return typeof e===js&&Rp.test(e)}static isBase64(e){return typeof e===js&&kp.test(e)}static isBase64Url(e){return typeof e===js&&Tp.test(e)}static ToString(e,t="utf8"){let n=Rt.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return ze.toString(n,!0);case"utf16":case"utf16be":return ze.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return ze.fromString(e,!0);case"utf16":case"utf16be":return ze.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Rt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return wo.fromString(e);case"utf16":case"utf16be":return ze.fromString(e);case"utf16le":case"usc2":return ze.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return wo.toString(e);case"utf16":case"utf16be":return ze.toString(e);case"utf16le":case"usc2":return ze.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Rt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Rt.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return ze.toString(e,t)}static FromUtf16String(e,t=!1){return ze.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};bo.DEFAULT_UTF8_ENCODING="utf8";function Cp(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function Np(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function _p(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}jr.BufferSourceConverter=Rt;jr.Convert=bo;jr.assign=Cp;jr.combine=Np;jr.isEqual=_p});var ci=nr((O1,vl)=>{"use strict";function El(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function pg(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return El(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),El(new o,t)}}vl.exports=pg});var ua=nr(($1,ca)=>{var K1=function(){typeof ca<"u"&&(ca.exports=h);var r=86400,e=3200,t=146097*e/400,n=r*t,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(y){var C=y-y%1;return C==0&&(y<0||y===0&&1/y!=1/0)?-0:C},u=h.prototype,l=(h.fromDate=function(y){return new h(+y)},h.fromInt64BE=L(0,1,2,3,0,4),h.fromInt64LE=L(3,2,1,0,4,0),h.fromString=function(T){var C,V=new h,T=(T+="").replace(/^\s*[+\-]?\d+/,function(H){var H=+H,J=1970+(H-1970)%400;return V.year=H-J,J}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(P,H,J){return H<0&&(J*=-1),C=6e4*(60*+H+ +J),""}).replace(/\.\d+$/,function(P){return V.nano=+(P+c).substr(1,9),""}).split(/\D+/);if(1<T.length?T[1]--:T[1]=0,V.time=C=Date.UTC.apply(Date,T)-(C||0),isNaN(C))throw new TypeError("Invalid Date");return p(V)},h.fromTimeT=function(y){return R(y,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(y){return this.nano+=+y||0,this},u.getNano=function(){var y=p(this);return(y.time%1e3*a+ +y.nano+1e9)%1e9},u.getTimeT=function(){var C=p(this),y=Math.floor(C.time/1e3),C=C.year;return C&&(y+=C*t*r/e),y},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return b(p(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(y){var C=this,V=C.toDate(),T={H:function(){return k(V.getUTCHours())},L:function(){return N(V.getUTCMilliseconds(),3)},M:function(){return k(V.getUTCMinutes())},N:function(){return N(C.getNano(),9)},S:function(){return k(V.getUTCSeconds())},Y:function(){var P=C.getYear();return 999999<P?"+"+P:9999<P?"+"+N(P,6):0<=P?N(P,4):-999999<=P?"-"+N(-P,6):P},a:function(){return E[V.getUTCDay()]},b:function(){return d[V.getUTCMonth()]},d:function(){return k(V.getUTCDate())},e:function(){return function(P){return(9<P?"":" ")+(0|P)}(V.getUTCDate())},m:function(){return k(V.getUTCMonth()+1)}};return function P(H){return H.replace(/%./g,function(J){var A=J[1],x=g[A],A=T[A];return x?P(x):A?A():J})}(y||l)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],E=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],g={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return h;function h(y,C,V){var T=this;if(!(T instanceof h))return new h(y,C,V);T.time=+y||0,T.nano=+C||0,T.year=+V||0,p(T)}function p(y){var C,V,T,P=y.year,H=y.time,J=y.nano,x=((J<0||a<=J)&&(J-=(V=Math.floor(J/a))*a,H+=V,V=1),P%e);return(H<-i||i<H||x)&&((C=f(H/o))&&(P+=C*e,H-=C*o),(T=b(H)).setUTCFullYear(x+T.getUTCFullYear()),T=(H=+T)+(C=f((P-=x)/e))*o,C&&-i<=T&&T<=i&&(P-=C*e,H=T),V=1),V&&(y.year=P,y.time=H,y.nano=J),y}function b(y){var C=new Date(0);return C.setTime(y),C}function R(P,T){P=+P||0;var V=f((T=(T|0)*s)/n)+f(P/n),T=T%n+P%n,P=f(T/n);return P&&(V+=P,T-=P*n),new h(1e3*T,0,V*e)}function v(y,C,V,T,P,H){return function(x,A){var B=p(this);x=x||new Array(8),S(x,A|=0);var w=Math.floor(B.time/1e3),B=B.year*(t*r/e),M=f(B/s)+f(w/s),B=B%s+w%s,w=Math.floor(B/s);return w&&(M+=w,B-=w*s),J(x,A+P,M),J(x,A+H,B),x};function J(x,A,M){x[A+y]=M>>24&255,x[A+C]=M>>16&255,x[A+V]=M>>8&255,x[A+T]=255&M}}function L(y,C,V,T,P,H){return function(x,A){S(x,A|=0);var M=J(x,A+P);return R(J(x,A+H),M)};function J(x,A){return 16777216*x[A+y]+(x[A+C]<<16|x[A+V]<<8|x[A+T])}}function S(y,C){if(y=y&&y.length,y==null)throw new TypeError("Invalid Buffer");if(y<C+8)throw new RangeError("Out of range")}function k(y){return(9<y?"":"0")+(0|y)}function N(y,C){return(c+(0|y)).substr(-C)}}()});var Kf=nr((C2,Ea)=>{"use strict";var em=Object.prototype.hasOwnProperty,Ue="~";function Fn(){}Object.create&&(Fn.prototype=Object.create(null),new Fn().__proto__||(Ue=!1));function tm(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Hf(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new tm(t,n||r,o),s=Ue?Ue+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function vi(r,e){--r._eventsCount===0?r._events=new Fn:delete r._events[e]}function ke(){this._events=new Fn,this._eventsCount=0}ke.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)em.call(t,n)&&e.push(Ue?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ke.prototype.listeners=function(e){var t=Ue?Ue+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};ke.prototype.listenerCount=function(e){var t=Ue?Ue+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ke.prototype.emit=function(e,t,n,o,i,s){var a=Ue?Ue+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,o),!0;case 5:return c.fn.call(c.context,t,n,o,i),!0;case 6:return c.fn.call(c.context,t,n,o,i,s),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,E;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(e,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,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,o);break;default:if(!u)for(E=1,u=new Array(f-1);E<f;E++)u[E-1]=arguments[E];c[l].fn.apply(c[l].context,u)}}return!0};ke.prototype.on=function(e,t,n){return Hf(this,e,t,n,!1)};ke.prototype.once=function(e,t,n){return Hf(this,e,t,n,!0)};ke.prototype.removeListener=function(e,t,n,o){var i=Ue?Ue+e:e;if(!this._events[i])return this;if(!t)return vi(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&vi(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==t||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:vi(this,i)}return this};ke.prototype.removeAllListeners=function(e){var t;return e?(t=Ue?Ue+e:e,this._events[t]&&vi(this,t)):(this._events=new Fn,this._eventsCount=0),this};ke.prototype.off=ke.prototype.removeListener;ke.prototype.addListener=ke.prototype.on;ke.prefixed=Ue;ke.EventEmitter=ke;typeof Ea<"u"&&(Ea.exports=ke)});var am={};me(am,{delegatedHTTPRouting:()=>Xf,libp2pRouting:()=>Qf});var Fa=Symbol.for("@libp2p/content-routing");var Ti=Symbol.for("@libp2p/peer-id");function Ma(r){return r!=null&&!!r[Ti]}var Ha=Symbol.for("@libp2p/peer-routing");var O=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Ka=(r,...e)=>{try{[...e]}catch{}};var Pe=Vt(ja(),1);var Li={};me(Li,{base32:()=>Ze,base32hex:()=>Uh,base32hexpad:()=>Dh,base32hexpadupper:()=>Vh,base32hexupper:()=>Lh,base32pad:()=>Nh,base32padupper:()=>_h,base32upper:()=>ec,base32z:()=>Oh});var mm=new Uint8Array(0);function Ya(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function bt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Za(r){return new TextEncoder().encode(r)}function Wa(r){return new TextDecoder().decode(r)}function Ih(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var h=0,p=0,b=0,R=g.length;b!==R&&g[b]===0;)b++,h++;for(var v=(R-b)*u+1>>>0,L=new Uint8Array(v);b!==R;){for(var S=g[b],k=0,N=v-1;(S!==0||k<p)&&N!==-1;N--,k++)S+=256*L[N]>>>0,L[N]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");p=k,b++}for(var y=v-p;y!==v&&L[y]===0;)y++;for(var C=c.repeat(h);y<v;++y)C+=r.charAt(L[y]);return C}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var h=0;if(g[h]!==" "){for(var p=0,b=0;g[h]===c;)p++,h++;for(var R=(g.length-h)*f+1>>>0,v=new Uint8Array(R);g[h];){var L=t[g.charCodeAt(h)];if(L===255)return;for(var S=0,k=R-1;(L!==0||S<b)&&k!==-1;k--,S++)L+=a*v[k]>>>0,v[k]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=S,h++}if(g[h]!==" "){for(var N=R-b;N!==R&&v[N]===0;)N++;for(var y=new Uint8Array(p+(R-N)),C=p;N!==R;)y[C++]=v[N++];return y}}}function E(g){var h=d(g);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:E}}var Rh=Ih,kh=Rh,Xa=kh;var Ci=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ni=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Qa(this,e)}},_i=class{decoders;constructor(e){this.decoders=e}or(e){return Qa(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Qa(r,e){return new _i({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ui=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ci(e,t,n),this.decoder=new Ni(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function vr({name:r,prefix:e,encode:t,decode:n}){return new Ui(r,e,t,n)}function Ot({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Xa(t,r);return vr({prefix:e,name:r,encode:n,decode:i=>bt(o(i))})}function Th(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Ch(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function ae({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return vr({prefix:e,name:r,encode(o){return Ch(o,n,t)},decode(o){return Th(o,n,t,r)}})}var Ze=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ec=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nh=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_h=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uh=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lh=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Dh=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vh=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oh=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Di={};me(Di,{base58btc:()=>le,base58flickr:()=>Ph});var le=Ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ph=Ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vi={};me(Vi,{base64:()=>on,base64pad:()=>Fh,base64url:()=>Mh,base64urlpad:()=>Hh});var on=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fh=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mh=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hh=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});Pe.default.formatters.b=r=>r==null?"undefined":le.baseEncode(r);Pe.default.formatters.t=r=>r==null?"undefined":Ze.baseEncode(r);Pe.default.formatters.m=r=>r==null?"undefined":on.baseEncode(r);Pe.default.formatters.p=r=>r==null?"undefined":r.toString();Pe.default.formatters.c=r=>r==null?"undefined":r.toString();Pe.default.formatters.k=r=>r==null?"undefined":r.toString();Pe.default.formatters.a=r=>r==null?"undefined":r.toString();function Kh(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function Pt(r){let e=Kh(`${r}:trace`);return Pe.default.enabled(`${r}:trace`)&&Pe.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,Pe.default)(`${r}:trace`)),Object.assign((0,Pe.default)(r),{error:(0,Pe.default)(`${r}:error`),trace:e})}var Oi={};me(Oi,{base10:()=>$h});var $h=Ot({prefix:"9",name:"base10",alphabet:"0123456789"});var Pi={};me(Pi,{base16:()=>qh,base16upper:()=>zh});var qh=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zh=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Fi={};me(Fi,{base2:()=>Gh});var Gh=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mi={};me(Mi,{base256emoji:()=>Jh});var tc=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}"),jh=tc.reduce((r,e,t)=>(r[t]=e,r),[]),Yh=tc.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Zh(r){return r.reduce((e,t)=>(e+=jh[t],e),"")}function Wh(r){let e=[];for(let t of r){let n=Yh[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Jh=vr({prefix:"\u{1F680}",name:"base256emoji",encode:Zh,decode:Wh});var Hi={};me(Hi,{base36:()=>Gn,base36upper:()=>Xh});var Gn=Ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xh=Ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ki={};me(Ki,{base8:()=>Qh});var Qh=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $i={};me($i,{identity:()=>ed});var ed=vr({prefix:"\0",name:"identity",encode:r=>Wa(r),decode:r=>Za(r)});var Vm=new TextEncoder,Om=new TextDecoder;var zi={};me(zi,{identity:()=>ct});var nd=oc,rc=128,od=127,id=~od,sd=Math.pow(2,31);function oc(r,e,t){e=e||[],t=t||0;for(var n=t;r>=sd;)e[t++]=r&255|rc,r/=128;for(;r&id;)e[t++]=r&255|rc,r>>>=7;return e[t]=r|0,oc.bytes=t-n+1,e}var ad=qi,cd=128,nc=127;function qi(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw qi.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&nc)<<o:(s&nc)*Math.pow(2,o),o+=7}while(s>=cd);return qi.bytes=i-n,t}var ud=Math.pow(2,7),ld=Math.pow(2,14),fd=Math.pow(2,21),hd=Math.pow(2,28),dd=Math.pow(2,35),pd=Math.pow(2,42),gd=Math.pow(2,49),md=Math.pow(2,56),yd=Math.pow(2,63),wd=function(r){return r<ud?1:r<ld?2:r<fd?3:r<hd?4:r<dd?5:r<pd?6:r<gd?7:r<md?8:r<yd?9:10},bd={encode:nd,decode:ad,encodingLength:wd},xd=bd,sn=xd;function an(r,e=0){return[sn.decode(r,e),sn.decode.bytes]}function Br(r,e,t=0){return sn.encode(r,e,t),e}function Ar(r){return sn.encodingLength(r)}function at(r,e){let t=e.byteLength,n=Ar(r),o=n+Ar(t),i=new Uint8Array(o+t);return Br(r,i,0),Br(t,i,n),i.set(e,o),new Sr(r,t,e,i)}function Ft(r){let e=bt(r),[t,n]=an(e),[o,i]=an(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Sr(t,o,s,e)}function ic(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ya(r.bytes,t.bytes)}}var Sr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var sc=0,Ed="identity",ac=bt;function vd(r){return at(sc,ac(r))}var ct={code:sc,name:Ed,encode:ac,digest:vd};var Yi={};me(Yi,{sha256:()=>Ee,sha512:()=>Bd});function ji({name:r,code:e,encode:t}){return new Gi(r,e,t)}var Gi=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?at(this.code,t):t.then(n=>at(this.code,n))}else throw Error("Unknown type, must be binary type")}};function uc(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ee=ji({name:"sha2-256",code:18,encode:uc("SHA-256")}),Bd=ji({name:"sha2-512",code:19,encode:uc("SHA-512")});function lc(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Sd(t,Zi(r),e??le.encoder);default:return Id(t,Zi(r),e??Ze.encoder)}}var fc=new WeakMap;function Zi(r){let e=fc.get(r);if(e==null){let t=new Map;return fc.set(r,t),t}return e}var Te=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==cn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Rd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=at(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ic(e.multihash,n.multihash)}toString(e){return lc(this,e)}toJSON(){return{"/":lc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??hc(n,o,i.bytes))}else if(t[kd]===!0){let{version:n,multihash:o,code:i}=t,s=Ft(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==cn)throw new Error(`Version 0 CID must use dag-pb (code: ${cn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=hc(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,cn,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=bt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Sr(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,d]=an(e.subarray(t));return t+=d,l},o=n(),i=cn;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,o]=Ad(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Zi(i).set(n,e),i}};function Ad(r,e){switch(r[0]){case"Q":{let t=e??le;return[le.prefix,t.decode(`${le.prefix}${r}`)]}case le.prefix:{let t=e??le;return[le.prefix,t.decode(r)]}case Ze.prefix:{let t=e??Ze;return[Ze.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Sd(r,e,t){let{prefix:n}=t;if(n!==le.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Id(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var cn=112,Rd=18;function hc(r,e,t){let n=Ar(r),o=n+Ar(e),i=new Uint8Array(o+t.byteLength);return Br(r,i,0),Br(e,i,n),i.set(t,o),i}var kd=Symbol.for("@ipld/js-cid/CID");var Ht={...$i,...Fi,...Ki,...Oi,...Pi,...Li,...Hi,...Di,...Vi,...Mi},oy={...Yi,...zi};function ce(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Td=Symbol.for("nodejs.util.inspect.custom"),dc=Object.values(Ht).map(r=>r.decoder).reduce((r,e)=>r.or(e),Ht.identity.decoder),pc=114,Wi=36,Ji=37,un=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ti]=!0;toString(){return this.string==null&&(this.string=le.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Te.createV1(pc,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return Xi(e).equals(this);if(e?.multihash?.bytes!=null)return ce(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Td](){return`PeerId(${this.toString()})`}},Ir=class extends un{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Rr=class extends un{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},kr=class extends un{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Xi(r,e){if(e=e??dc,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Ft(le.decode(`z${r}`));return r.startsWith("12D")?new Rr({multihash:t}):r.startsWith("16U")?new kr({multihash:t}):new Ir({multihash:t})}return ir(dc.decode(r))}function ir(r){try{let e=Ft(r);if(e.code===ct.code){if(e.digest.length===Wi)return new Rr({multihash:e});if(e.digest.length===Ji)return new kr({multihash:e})}if(e.code===Ee.code)return new Ir({multihash:e})}catch{return Cd(Te.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Cd(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==pc)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Ee.code)return new Ir({multihash:r.multihash});if(e.code===ct.code){if(e.digest.length===Wi)return new Rr({multihash:r.multihash});if(e.digest.length===Ji)return new kr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function gc(r,e){return r.length===Wi?new Rr({multihash:at(ct.code,r),privateKey:e}):r.length===Ji?new kr({multihash:at(ct.code,r),privateKey:e}):new Ir({multihash:await Ee.digest(r),publicKey:r,privateKey:e})}function sr(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function We(r=0){return globalThis.Buffer?.allocUnsafe!=null?sr(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function yc(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var mc=yc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qi=yc("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=We(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Nd={utf8:mc,"utf-8":mc,hex:Ht.base16,latin1:Qi,ascii:Qi,binary:Qi,...Ht},Yn=Nd;function W(r,e="utf8"){let t=Yn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var _d=Math.pow(2,7),Ud=Math.pow(2,14),Ld=Math.pow(2,21),es=Math.pow(2,28),ts=Math.pow(2,35),rs=Math.pow(2,42),ns=Math.pow(2,49),ee=128,Se=127;function ut(r){if(r<_d)return 1;if(r<Ud)return 2;if(r<Ld)return 3;if(r<es)return 4;if(r<ts)return 5;if(r<rs)return 6;if(r<ns)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Dd(r,e,t=0){switch(ut(r)){case 8:e[t++]=r&255|ee,r/=128;case 7:e[t++]=r&255|ee,r/=128;case 6:e[t++]=r&255|ee,r/=128;case 5:e[t++]=r&255|ee,r/=128;case 4:e[t++]=r&255|ee,r>>>=7;case 3:e[t++]=r&255|ee,r>>>=7;case 2:e[t++]=r&255|ee,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Vd(r,e,t=0){switch(ut(r)){case 8:e.set(t++,r&255|ee),r/=128;case 7:e.set(t++,r&255|ee),r/=128;case 6:e.set(t++,r&255|ee),r/=128;case 5:e.set(t++,r&255|ee),r/=128;case 4:e.set(t++,r&255|ee),r>>>=7;case 3:e.set(t++,r&255|ee),r>>>=7;case 2:e.set(t++,r&255|ee),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Od(r,e){let t=r[e],n=0;if(n+=t&Se,t<ee||(t=r[e+1],n+=(t&Se)<<7,t<ee)||(t=r[e+2],n+=(t&Se)<<14,t<ee)||(t=r[e+3],n+=(t&Se)<<21,t<ee)||(t=r[e+4],n+=(t&Se)*es,t<ee)||(t=r[e+5],n+=(t&Se)*ts,t<ee)||(t=r[e+6],n+=(t&Se)*rs,t<ee)||(t=r[e+7],n+=(t&Se)*ns,t<ee))return n;throw new RangeError("Could not decode varint")}function Pd(r,e){let t=r.get(e),n=0;if(n+=t&Se,t<ee||(t=r.get(e+1),n+=(t&Se)<<7,t<ee)||(t=r.get(e+2),n+=(t&Se)<<14,t<ee)||(t=r.get(e+3),n+=(t&Se)<<21,t<ee)||(t=r.get(e+4),n+=(t&Se)*es,t<ee)||(t=r.get(e+5),n+=(t&Se)*ts,t<ee)||(t=r.get(e+6),n+=(t&Se)*rs,t<ee)||(t=r.get(e+7),n+=(t&Se)*ns,t<ee))return n;throw new RangeError("Could not decode varint")}function Tr(r,e,t=0){return e==null&&(e=We(ut(r))),e instanceof Uint8Array?Dd(r,e,t):Vd(r,e,t)}function ar(r,e=0){return r instanceof Uint8Array?Od(r,e):Pd(r,e)}function Ce(r,e){if(globalThis.Buffer!=null)return sr(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=We(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return sr(t)}var Zn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=e,i+=u,i>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var bc=45,Fd=15,Cr=new Zn;function os(r){if(!(r.length>Fd))return Cr.new(r).parseWith(()=>Cr.readIPv4Addr())}function is(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>bc))return Cr.new(r).parseWith(()=>Cr.readIPv6Addr())}function Wn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>bc))return Cr.new(r).parseWith(()=>Cr.readIPAddr())}var Vy=parseInt("0xFFFF",16),Oy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function j(r,e="utf8"){let t=Yn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?sr(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function vc(r){return!!os(r)}function Bc(r){return!!is(r)}function Jn(r){return!!Wn(r)}var Ac=vc,qd=Bc,ss=function(r){let e=0;if(r=r.toString().trim(),Ac(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(qd(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Ac(t[n]),s;i&&(s=ss(t[n]),t[n]=W(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,W(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},Sc=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Nr={},as={},Gd=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];Gd.forEach(r=>{let e=jd(...r);as[e.code]=e,Nr[e.name]=e});function jd(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function ne(r){if(typeof r=="number"){if(as[r]!=null)return as[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Nr[r]!=null)return Nr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Bw=ne("ip4"),Aw=ne("ip6"),Sw=ne("ipcidr");function us(r,e){switch(ne(r).code){case 4:case 41:return Zd(e);case 42:return kc(e);case 6:case 273:case 33:case 132:return Cc(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return kc(e);case 421:return Qd(e);case 444:return Tc(e);case 445:return Tc(e);case 466:return Xd(e);default:return W(e,"base16")}}function ls(r,e){switch(ne(r).code){case 4:return Ic(e);case 41:return Ic(e);case 42:return Rc(e);case 6:case 273:case 33:case 132:return fs(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Rc(e);case 421:return Wd(e);case 444:return e0(e);case 445:return t0(e);case 466:return Jd(e);default:return j(e,"base16")}}var cs=Object.values(Ht).map(r=>r.decoder),Yd=function(){let r=cs[0].or(cs[1]);return cs.slice(2).forEach(e=>r=r.or(e)),r}();function Ic(r){if(!Jn(r))throw new Error("invalid ip address");return ss(r)}function Zd(r){let e=Sc(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Jn(e))throw new Error("invalid ip address");return e}function fs(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Cc(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Rc(r){let e=j(r),t=Uint8Array.from(Tr(e.length));return Ce([t,e],t.length+e.length)}function kc(r){let e=ar(r);if(r=r.slice(ut(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function Wd(r){let e;r[0]==="Q"||r[0]==="1"?e=Ft(le.decode(`z${r}`)).bytes:e=Te.parse(r).multihash.bytes;let t=Uint8Array.from(Tr(e.length));return Ce([t,e],t.length+e.length)}function Jd(r){let e=Yd.decode(r),t=Uint8Array.from(Tr(e.length));return Ce([t,e],t.length+e.length)}function Xd(r){let e=ar(r),t=r.slice(ut(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function Qd(r){let e=ar(r),t=r.slice(ut(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function e0(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=Ze.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=fs(n);return Ce([t,o],t.length+o.length)}function t0(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=Ze.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=fs(n);return Ce([t,o],t.length+o.length)}function Tc(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=Cc(t);return`${n}:${o}`}function Nc(r){r=hs(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=ne(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw Uc("invalid address: "+r);if(a.path===!0){n=hs(o.slice(i).join("/")),e.push([a.code,ls(a.code,n)]),t.push([a.code,n]);break}let c=ls(a.code,o[i]);e.push([a.code,c]),t.push([a.code,us(a.code,c)])}return{string:_c(t),bytes:ps(e),tuples:e,stringTuples:t,path:n}}function ds(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=ar(r,o),s=ut(i),a=ne(i),c=r0(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw Uc("Invalid address Uint8Array: "+W(r,"base16"));e.push([i,f]);let u=us(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:_c(t),tuples:e,stringTuples:t,path:n}}function _c(r){let e=[];return r.map(t=>{let n=ne(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),hs(e.join("/"))}function ps(r){return Ce(r.map(e=>{let t=ne(e[0]),n=Uint8Array.from(Tr(t.code));return e.length>1&&e[1]!=null&&(n=Ce([n,e[1]])),n}))}function r0(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=ar(e instanceof Uint8Array?e:Uint8Array.from(e));return t+ut(t)}}function hs(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Uc(r){return new Error("Error parsing address: "+r)}var n0=Symbol.for("nodejs.util.inspect.custom"),gs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),o0=[ne("dns").code,ne("dns4").code,ne("dns6").code,ne("dnsaddr").code],Xn=class r{bytes;#e;#r;#i;#a;[gs]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ds(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Nc(e)}else if(Dc(e))t=ds(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#r=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=ne("tcp"),a=ne("udp"),c=ne("ip4"),f=ne("ip6"),u=ne("dns6"),l=ne("ip6zone");for(let[E,g]of this.stringTuples())E===l.code&&(i=`%${g??""}`),o0.includes(E)&&(t=s.name,o=443,n=`${g??""}${i}`,e=E===u.code?6:4),(E===s.code||E===a.code)&&(t=ne(E).name,o=parseInt(g??"")),(E===c.code||E===f.code)&&(t=ne(E).name,n=`${g??""}${i}`,e=E===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#r.map(([e])=>Object.assign({},ne(e)))}protoCodes(){return this.#r.map(([e])=>e)}protoNames(){return this.#r.map(([e])=>ne(e).name)}tuples(){return this.#r}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ps(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Nr.p2p.code&&e.push([n,o]),n===Nr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(le.decode(`z${n}`),"base58btc"):W(Te.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return ce(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Lc.get(t.name);if(n==null)throw new O(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>new r(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[n0](){return`Multiaddr(${this.#e})`}};var Lc=new Map;function Dc(r){return!!r?.[gs]}function ms(r){return new Xn(r)}function ln(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}async function*Qn(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var zs={};me(zs,{Ed25519PrivateKey:()=>dr,Ed25519PublicKey:()=>yn,generateKeyPair:()=>Bp,generateKeyPairFromSeed:()=>gu,unmarshalEd25519PrivateKey:()=>Ep,unmarshalEd25519PublicKey:()=>vp});function qe(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function _r(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function i0(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ys(r,...e){if(!i0(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function eo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");_r(r.outputLen),_r(r.blockLen)}function Ur(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Vc(r,e){ys(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var to=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Oc(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Dr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Je=(r,e)=>r<<32-e|r>>>e,s0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!s0)throw new Error("Non little-endian hardware is not supported");var a0=async()=>{};async function Pc(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await a0(),n+=i)}}function ws(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Kt(r){if(typeof r=="string"&&(r=ws(r)),!Oc(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function ro(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];if(!Oc(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Lr=class{clone(){return this._cloneInto()}},c0={}.toString;function Fc(r,e){if(e!==void 0&&c0.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function no(r){let e=n=>r().update(Kt(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Vr(r=32){if(to&&typeof to.getRandomValues=="function")return to.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function u0(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}var Or=class extends Lr{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Dr(this.buffer)}update(e){Ur(this);let{view:t,buffer:n,blockLen:o}=this;e=Kt(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Dr(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ur(this),Vc(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)t[l]=0;u0(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Dr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should 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],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var oo=BigInt(4294967295),bs=BigInt(32);function Mc(r,e=!1){return e?{h:Number(r&oo),l:Number(r>>bs&oo)}:{h:Number(r>>bs&oo)|0,l:Number(r&oo)|0}}function l0(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Mc(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var f0=(r,e)=>BigInt(r>>>0)<<bs|BigInt(e>>>0),h0=(r,e,t)=>r>>>t,d0=(r,e,t)=>r<<32-t|e>>>t,p0=(r,e,t)=>r>>>t|e<<32-t,g0=(r,e,t)=>r<<32-t|e>>>t,m0=(r,e,t)=>r<<64-t|e>>>t-32,y0=(r,e,t)=>r>>>t-32|e<<64-t,w0=(r,e)=>e,b0=(r,e)=>r,x0=(r,e,t)=>r<<t|e>>>32-t,E0=(r,e,t)=>e<<t|r>>>32-t,v0=(r,e,t)=>e<<t-32|r>>>64-t,B0=(r,e,t)=>r<<t-32|e>>>64-t;function A0(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var S0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),I0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,R0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),k0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,T0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),C0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var N0={fromBig:Mc,split:l0,toBig:f0,shrSH:h0,shrSL:d0,rotrSH:p0,rotrSL:g0,rotrBH:m0,rotrBL:y0,rotr32H:w0,rotr32L:b0,rotlSH:x0,rotlSL:E0,rotlBH:v0,rotlBL:B0,add:A0,add3L:S0,add3H:I0,add4L:R0,add4H:k0,add5H:C0,add5L:T0},q=N0;var[_0,U0]=q.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),$t=new Uint32Array(80),qt=new Uint32Array(80),xs=class extends Or{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:E,Gl:g,Hh:h,Hl:p}=this;return[e,t,n,o,i,s,a,c,f,u,l,d,E,g,h,p]}set(e,t,n,o,i,s,a,c,f,u,l,d,E,g,h,p){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=h|0,this.Hl=p|0}process(e,t){for(let v=0;v<16;v++,t+=4)$t[v]=e.getUint32(t),qt[v]=e.getUint32(t+=4);for(let v=16;v<80;v++){let L=$t[v-15]|0,S=qt[v-15]|0,k=q.rotrSH(L,S,1)^q.rotrSH(L,S,8)^q.shrSH(L,S,7),N=q.rotrSL(L,S,1)^q.rotrSL(L,S,8)^q.shrSL(L,S,7),y=$t[v-2]|0,C=qt[v-2]|0,V=q.rotrSH(y,C,19)^q.rotrBH(y,C,61)^q.shrSH(y,C,6),T=q.rotrSL(y,C,19)^q.rotrBL(y,C,61)^q.shrSL(y,C,6),P=q.add4L(N,T,qt[v-7],qt[v-16]),H=q.add4H(P,k,V,$t[v-7],$t[v-16]);$t[v]=H|0,qt[v]=P|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:E,Fl:g,Gh:h,Gl:p,Hh:b,Hl:R}=this;for(let v=0;v<80;v++){let L=q.rotrSH(l,d,14)^q.rotrSH(l,d,18)^q.rotrBH(l,d,41),S=q.rotrSL(l,d,14)^q.rotrSL(l,d,18)^q.rotrBL(l,d,41),k=l&E^~l&h,N=d&g^~d&p,y=q.add5L(R,S,N,U0[v],qt[v]),C=q.add5H(y,b,L,k,_0[v],$t[v]),V=y|0,T=q.rotrSH(n,o,28)^q.rotrBH(n,o,34)^q.rotrBH(n,o,39),P=q.rotrSL(n,o,28)^q.rotrBL(n,o,34)^q.rotrBL(n,o,39),H=n&i^n&a^i&a,J=o&s^o&c^s&c;b=h|0,R=p|0,h=E|0,p=g|0,E=l|0,g=d|0,{h:l,l:d}=q.add(f|0,u|0,C|0,V|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let x=q.add3L(V,P,J);n=q.add3H(x,C,T,H),o=x|0}({h:n,l:o}=q.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=q.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=q.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=q.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=q.add(this.Eh|0,this.El|0,l|0,d|0),{h:E,l:g}=q.add(this.Fh|0,this.Fl|0,E|0,g|0),{h,l:p}=q.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:b,l:R}=q.add(this.Hh|0,this.Hl|0,b|0,R|0),this.set(n,o,i,s,a,c,f,u,l,d,E,g,h,p,b,R)}roundClean(){$t.fill(0),qt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Pr=no(()=>new xs);var so={};me(so,{bitGet:()=>M0,bitLen:()=>F0,bitMask:()=>fn,bitSet:()=>H0,bytesToHex:()=>Et,bytesToNumberBE:()=>vt,bytesToNumberLE:()=>zt,concatBytes:()=>Bt,createHmacDrbg:()=>Bs,ensureBytes:()=>ue,equalBytes:()=>O0,hexToBytes:()=>cr,hexToNumber:()=>vs,isBytes:()=>Xe,numberToBytesBE:()=>Gt,numberToBytesLE:()=>ur,numberToHexUnpadded:()=>qc,numberToVarBytesBE:()=>V0,utf8ToBytes:()=>P0,validateObject:()=>lt});var $c=BigInt(0),io=BigInt(1),L0=BigInt(2);function Xe(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var D0=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Et(r){if(!Xe(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=D0[r[t]];return e}function qc(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function vs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var xt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Hc(r){if(r>=xt._0&&r<=xt._9)return r-xt._0;if(r>=xt._A&&r<=xt._F)return r-(xt._A-10);if(r>=xt._a&&r<=xt._f)return r-(xt._a-10)}function cr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=Hc(r.charCodeAt(i)),a=Hc(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function vt(r){return vs(Et(r))}function zt(r){if(!Xe(r))throw new Error("Uint8Array expected");return vs(Et(Uint8Array.from(r).reverse()))}function Gt(r,e){return cr(r.toString(16).padStart(e*2,"0"))}function ur(r,e){return Gt(r,e).reverse()}function V0(r){return cr(qc(r))}function ue(r,e,t){let n;if(typeof e=="string")try{n=cr(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Xe(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function Bt(...r){let e=0;for(let o=0;o<r.length;o++){let i=r[o];if(!Xe(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e),n=0;for(let o=0;o<r.length;o++){let i=r[o];t.set(i,n),n+=i.length}return t}function O0(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function P0(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function F0(r){let e;for(e=0;r>$c;r>>=io,e+=1);return e}function M0(r,e){return r>>BigInt(e)&io}var H0=(r,e,t)=>r|(t?io:$c)<<BigInt(e),fn=r=>(L0<<BigInt(r-1))-io,Es=r=>new Uint8Array(r),Kc=r=>Uint8Array.from(r);function Bs(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=Es(r),o=Es(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>t(o,n,...l),c=(l=Es())=>{o=a(Kc([0]),l),n=a(),l.length!==0&&(o=a(Kc([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<e;){n=a();let E=n.slice();d.push(E),l+=n.length}return Bt(...d)};return(l,d)=>{s(),c(l);let E;for(;!(E=d(f()));)c();return s(),E}}var K0={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Xe(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function lt(r,e,t={}){let n=(o,i,s)=>{let a=K0[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${i}`)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}var ge=BigInt(0),oe=BigInt(1),lr=BigInt(2),$0=BigInt(3),As=BigInt(4),zc=BigInt(5),Gc=BigInt(8),q0=BigInt(9),z0=BigInt(16);function re(r,e){let t=r%e;return t>=ge?t:e+t}function G0(r,e,t){if(t<=ge||e<ge)throw new Error("Expected power/modulo > 0");if(t===oe)return ge;let n=oe;for(;e>ge;)e&oe&&(n=n*r%t),r=r*r%t,e>>=oe;return n}function ie(r,e,t){let n=r;for(;e-- >ge;)n*=n,n%=t;return n}function ao(r,e){if(r===ge||e<=ge)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=re(r,e),n=e,o=ge,i=oe,s=oe,a=ge;for(;t!==ge;){let f=n/t,u=n%t,l=o-s*f,d=i-a*f;n=t,t=u,o=s,i=a,s=l,a=d}if(n!==oe)throw new Error("invert: does not exist");return re(o,e)}function j0(r){let e=(r-oe)/lr,t,n,o;for(t=r-oe,n=0;t%lr===ge;t/=lr,n++);for(o=lr;o<r&&G0(o,e,r)!==r-oe;o++);if(n===1){let s=(r+oe)/As;return function(c,f){let u=c.pow(f,s);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+oe)/lr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),t),l=a.pow(c,i),d=a.pow(c,t);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let E=1;for(let h=a.sqr(d);E<f&&!a.eql(h,a.ONE);E++)h=a.sqr(h);let g=a.pow(u,oe<<BigInt(f-E-1));u=a.sqr(g),l=a.mul(l,g),d=a.mul(d,u),f=E}return l}}function Y0(r){if(r%As===$0){let e=(r+oe)/As;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%Gc===zc){let e=(r-zc)/Gc;return function(n,o){let i=n.mul(o,lr),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,lr),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%z0,j0(r)}var jc=(r,e)=>(re(r,e)&oe)===oe,Z0=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ss(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Z0.reduce((n,o)=>(n[o]="function",n),e);return lt(r,t)}function W0(r,e,t){if(t<ge)throw new Error("Expected power > 0");if(t===ge)return r.ONE;if(t===oe)return e;let n=r.ONE,o=e;for(;t>ge;)t&oe&&(n=r.mul(n,o)),o=r.sqr(o),t>>=oe;return n}function J0(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function Is(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function co(r,e,t=!1,n={}){if(r<=ge)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Is(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Y0(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:fn(o),ZERO:ge,ONE:oe,create:c=>re(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ge<=c&&c<r},is0:c=>c===ge,isOdd:c=>(c&oe)===oe,neg:c=>re(-c,r),eql:(c,f)=>c===f,sqr:c=>re(c*c,r),add:(c,f)=>re(c+f,r),sub:(c,f)=>re(c-f,r),mul:(c,f)=>re(c*f,r),pow:(c,f)=>W0(a,c,f),div:(c,f)=>re(c*ao(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>ao(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>J0(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?ur(c,i):Gt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?zt(c):vt(c)}});return Object.freeze(a)}function Yc(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function Zc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Rs(r){let e=Zc(r);return e+Math.ceil(e/2)}function Wc(r,e,t=!1){let n=r.length,o=Zc(e),i=Rs(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=t?vt(r):zt(r),a=re(s,e-oe)+oe;return t?ur(a,o):Gt(a,o)}var Q0=BigInt(0),ks=BigInt(1);function uo(r,e){let t=(o,i)=>{let s=i.negate();return o?s:i},n=o=>{let i=Math.ceil(e/o)+1,s=2**(o-1);return{windows:i,windowSize:s}};return{constTimeNegate:t,unsafeLadder(o,i){let s=r.ZERO,a=o;for(;i>Q0;)i&ks&&(s=s.add(a)),a=a.double(),i>>=ks;return s},precomputeWindow(o,i){let{windows:s,windowSize:a}=n(i),c=[],f=o,u=f;for(let l=0;l<s;l++){u=f,c.push(u);for(let d=1;d<a;d++)u=u.add(f),c.push(u);f=u.double()}return c},wNAF(o,i,s){let{windows:a,windowSize:c}=n(o),f=r.ZERO,u=r.BASE,l=BigInt(2**o-1),d=2**o,E=BigInt(o);for(let g=0;g<a;g++){let h=g*c,p=Number(s&l);s>>=E,p>c&&(p-=d,s+=ks);let b=h,R=h+Math.abs(p)-1,v=g%2!==0,L=p<0;p===0?u=u.add(t(v,i[b])):f=f.add(t(L,i[R]))}return{p:f,f:u}},wNAFCached(o,i,s,a){let c=o._WINDOW_SIZE||1,f=i.get(o);return f||(f=this.precomputeWindow(o,c),c!==1&&i.set(o,a(f))),this.wNAF(c,f,s)}}}function hn(r){return Ss(r.Fp),lt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Is(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Qe=BigInt(0),Fe=BigInt(1),lo=BigInt(2),ep=BigInt(8),tp={zip215:!0};function rp(r){let e=hn(r);return lt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function fo(r){let e=rp(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=lo<<BigInt(a*8)-Fe,u=t.create,l=e.uvRatio||((B,w)=>{try{return{isValid:!0,value:t.sqrt(B*t.inv(w))}}catch{return{isValid:!1,value:Qe}}}),d=e.adjustScalarBytes||(B=>B),E=e.domain||((B,w,D)=>{if(w.length||D)throw new Error("Contexts/pre-hash are not supported");return B}),g=B=>typeof B=="bigint"&&Qe<B,h=(B,w)=>g(B)&&g(w)&&B<w,p=B=>B===Qe||h(B,f);function b(B,w){if(h(B,w))return B;throw new Error(`Expected valid scalar < ${w}, got ${typeof B} ${B}`)}function R(B){return B===Qe?B:b(B,n)}let v=new Map;function L(B){if(!(B instanceof S))throw new Error("ExtendedPoint expected")}class S{constructor(w,D,F,$){if(this.ex=w,this.ey=D,this.ez=F,this.et=$,!p(w))throw new Error("x required");if(!p(D))throw new Error("y required");if(!p(F))throw new Error("z required");if(!p($))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof S)throw new Error("extended point not allowed");let{x:D,y:F}=w||{};if(!p(D)||!p(F))throw new Error("invalid affine point");return new S(D,F,Fe,u(D*F))}static normalizeZ(w){let D=t.invertBatch(w.map(F=>F.ez));return w.map((F,$)=>F.toAffine(D[$])).map(S.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,v.delete(this)}assertValidity(){let{a:w,d:D}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:F,ey:$,ez:z,et:G}=this,te=u(F*F),Z=u($*$),X=u(z*z),he=u(X*X),se=u(te*w),be=u(X*u(se+Z)),xe=u(he+u(D*u(te*Z)));if(be!==xe)throw new Error("bad point: equation left != right (1)");let pe=u(F*$),Ae=u(z*G);if(pe!==Ae)throw new Error("bad point: equation left != right (2)")}equals(w){L(w);let{ex:D,ey:F,ez:$}=this,{ex:z,ey:G,ez:te}=w,Z=u(D*te),X=u(z*$),he=u(F*te),se=u(G*$);return Z===X&&he===se}is0(){return this.equals(S.ZERO)}negate(){return new S(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:w}=e,{ex:D,ey:F,ez:$}=this,z=u(D*D),G=u(F*F),te=u(lo*u($*$)),Z=u(w*z),X=D+F,he=u(u(X*X)-z-G),se=Z+G,be=se-te,xe=Z-G,pe=u(he*be),Ae=u(se*xe),wt=u(he*xe),rr=u(be*se);return new S(pe,Ae,rr,wt)}add(w){L(w);let{a:D,d:F}=e,{ex:$,ey:z,ez:G,et:te}=this,{ex:Z,ey:X,ez:he,et:se}=w;if(D===BigInt(-1)){let Na=u((z-$)*(X+Z)),_a=u((z+$)*(X-Z)),ki=u(_a-Na);if(ki===Qe)return this.double();let Ua=u(G*lo*se),La=u(te*lo*he),Da=La+Ua,Va=_a+Na,Oa=La-Ua,oh=u(Da*ki),ih=u(Va*Oa),sh=u(Da*Oa),ah=u(ki*Va);return new S(oh,ih,ah,sh)}let be=u($*Z),xe=u(z*X),pe=u(te*F*se),Ae=u(G*he),wt=u(($+z)*(Z+X)-be-xe),rr=Ae-pe,nn=Ae+pe,Ca=u(xe-D*be),eh=u(wt*rr),th=u(nn*Ca),rh=u(wt*Ca),nh=u(rr*nn);return new S(eh,th,nh,rh)}subtract(w){return this.add(w.negate())}wNAF(w){return y.wNAFCached(this,v,w,S.normalizeZ)}multiply(w){let{p:D,f:F}=this.wNAF(b(w,n));return S.normalizeZ([D,F])[0]}multiplyUnsafe(w){let D=R(w);return D===Qe?N:this.equals(N)||D===Fe?this:this.equals(k)?this.wNAF(D).p:y.unsafeLadder(this,D)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return y.unsafeLadder(this,n).is0()}toAffine(w){let{ex:D,ey:F,ez:$}=this,z=this.is0();w==null&&(w=z?ep:t.inv($));let G=u(D*w),te=u(F*w),Z=u($*w);if(z)return{x:Qe,y:Fe};if(Z!==Fe)throw new Error("invZ was invalid");return{x:G,y:te}}clearCofactor(){let{h:w}=e;return w===Fe?this:this.multiplyUnsafe(w)}static fromHex(w,D=!1){let{d:F,a:$}=e,z=t.BYTES;w=ue("pointHex",w,z);let G=w.slice(),te=w[z-1];G[z-1]=te&-129;let Z=zt(G);Z===Qe||(D?b(Z,f):b(Z,t.ORDER));let X=u(Z*Z),he=u(X-Fe),se=u(F*X-$),{isValid:be,value:xe}=l(he,se);if(!be)throw new Error("Point.fromHex: invalid y coordinate");let pe=(xe&Fe)===Fe,Ae=(te&128)!==0;if(!D&&xe===Qe&&Ae)throw new Error("Point.fromHex: x=0 and x_0=1");return Ae!==pe&&(xe=u(-xe)),S.fromAffine({x:xe,y:Z})}static fromPrivateKey(w){return T(w).point}toRawBytes(){let{x:w,y:D}=this.toAffine(),F=ur(D,t.BYTES);return F[F.length-1]|=w&Fe?128:0,F}toHex(){return Et(this.toRawBytes())}}S.BASE=new S(e.Gx,e.Gy,Fe,u(e.Gx*e.Gy)),S.ZERO=new S(Qe,Fe,Fe,Qe);let{BASE:k,ZERO:N}=S,y=uo(S,a*8);function C(B){return re(B,n)}function V(B){return C(zt(B))}function T(B){let w=a;B=ue("private key",B,w);let D=ue("hashed private key",i(B),2*w),F=d(D.slice(0,w)),$=D.slice(w,2*w),z=V(F),G=k.multiply(z),te=G.toRawBytes();return{head:F,prefix:$,scalar:z,point:G,pointBytes:te}}function P(B){return T(B).pointBytes}function H(B=new Uint8Array,...w){let D=Bt(...w);return V(i(E(D,ue("context",B),!!o)))}function J(B,w,D={}){B=ue("message",B),o&&(B=o(B));let{prefix:F,scalar:$,pointBytes:z}=T(w),G=H(D.context,F,B),te=k.multiply(G).toRawBytes(),Z=H(D.context,te,z,B),X=C(G+Z*$);R(X);let he=Bt(te,ur(X,t.BYTES));return ue("result",he,a*2)}let x=tp;function A(B,w,D,F=x){let{context:$,zip215:z}=F,G=t.BYTES;B=ue("signature",B,2*G),w=ue("message",w),o&&(w=o(w));let te=zt(B.slice(G,2*G)),Z,X,he;try{Z=S.fromHex(D,z),X=S.fromHex(B.slice(0,G),z),he=k.multiplyUnsafe(te)}catch{return!1}if(!z&&Z.isSmallOrder())return!1;let se=H($,X.toRawBytes(),Z.toRawBytes(),w);return X.add(Z.multiplyUnsafe(se)).subtract(he).clearCofactor().equals(S.ZERO)}return k._setWindowSize(8),{CURVE:e,getPublicKey:P,sign:J,verify:A,ExtendedPoint:S,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>s(t.BYTES),precompute(B=8,w=S.BASE){return w._setWindowSize(B),w.multiply(BigInt(3)),w}}}}var Cs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Jc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Sb=BigInt(0),np=BigInt(1),Ts=BigInt(2),op=BigInt(5),Xc=BigInt(10),ip=BigInt(20),sp=BigInt(40),Qc=BigInt(80);function ap(r){let e=Cs,n=r*r%e*r%e,o=ie(n,Ts,e)*n%e,i=ie(o,np,e)*r%e,s=ie(i,op,e)*i%e,a=ie(s,Xc,e)*s%e,c=ie(a,ip,e)*a%e,f=ie(c,sp,e)*c%e,u=ie(f,Qc,e)*f%e,l=ie(u,Qc,e)*f%e,d=ie(l,Xc,e)*s%e;return{pow_p_5_8:ie(d,Ts,e)*r%e,b2:n}}function cp(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function up(r,e){let t=Cs,n=re(e*e*e,t),o=re(n*n*e,t),i=ap(r*o).pow_p_5_8,s=re(r*n*i,t),a=re(e*s*s,t),c=s,f=re(s*Jc,t),u=a===r,l=a===re(-r,t),d=a===re(-r*Jc,t);return u&&(s=c),(l||d)&&(s=f),jc(s,t)&&(s=re(-s,t)),{isValid:u||l,value:s}}var At=co(Cs,void 0,!0),Ns={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:At,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Pr,randomBytes:Vr,adjustScalarBytes:cp,uvRatio:up},Fr=fo(Ns);function eu(r,e,t){if(e.length>255)throw new Error("Context is too big");return ro(ws("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var Ib=fo({...Ns,domain:eu}),Rb=fo({...Ns,domain:eu,prehash:Pr});var lp=(At.ORDER+BigInt(3))/BigInt(8),kb=At.pow(Ts,lp),Tb=At.sqrt(At.neg(At.ONE)),Cb=(At.ORDER-BigInt(5))/BigInt(8),Nb=BigInt(486662);var _b=Yc(At,At.neg(BigInt(486664)));var Ub=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Lb=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Db=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vb=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Ob=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Mr=32,St=64,ho=32;function tu(){let r=Fr.utils.randomPrivateKey(),e=Fr.getPublicKey(r);return{privateKey:iu(r,e),publicKey:e}}function ru(r){if(r.length!==ho)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=Fr.getPublicKey(e);return{privateKey:iu(e,t),publicKey:t}}function nu(r,e){let t=r.subarray(0,ho);return Fr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function ou(r,e,t){return Fr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function iu(r,e){let t=new Uint8Array(St);for(let n=0;n<ho;n++)t[n]=r[n],t[ho+n]=e[n];return t}var Ne={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var _s={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function su(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",i=r?.saltLength??16,s=r?.iterations??32767,a=Ne.get();t*=8;async function c(l,d){let E=a.getRandomValues(new Uint8Array(i)),g=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:g};typeof d=="string"&&(d=j(d));let p;if(d.length===0){p=await a.subtle.importKey("jwk",_s,{name:"AES-GCM"},!0,["encrypt"]);try{let R={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},v=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(R,v,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",_s,{name:"AES-GCM"},!0,["encrypt"])}}else{let R={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},v=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(R,v,{name:e,length:t},!0,["encrypt"])}let b=await a.subtle.encrypt(h,p,l);return Ce([E,h.iv,new Uint8Array(b)])}async function f(l,d){let E=l.subarray(0,i),g=l.subarray(i,i+n),h=l.subarray(i+n),p={name:e,iv:g};typeof d=="string"&&(d=j(d));let b;if(d.length===0)try{let v={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},L=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(v,L,{name:e,length:t},!0,["decrypt"])}catch{b=await a.subtle.importKey("jwk",_s,{name:"AES-GCM"},!0,["decrypt"])}else{let v={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},L=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(v,L,{name:e,length:t},!0,["decrypt"])}let R=await a.subtle.decrypt(p,b,h);return new Uint8Array(R)}return{encrypt:c,decrypt:f}}async function Hr(r,e){let n=await su().encrypt(r,e);return on.encode(n)}var Us=new Float32Array([-0]),jt=new Uint8Array(Us.buffer);function au(r,e,t){Us[0]=r,e[t]=jt[0],e[t+1]=jt[1],e[t+2]=jt[2],e[t+3]=jt[3]}function cu(r,e){return jt[0]=r[e],jt[1]=r[e+1],jt[2]=r[e+2],jt[3]=r[e+3],Us[0]}var Ls=new Float64Array([-0]),Ie=new Uint8Array(Ls.buffer);function uu(r,e,t){Ls[0]=r,e[t]=Ie[0],e[t+1]=Ie[1],e[t+2]=Ie[2],e[t+3]=Ie[3],e[t+4]=Ie[4],e[t+5]=Ie[5],e[t+6]=Ie[6],e[t+7]=Ie[7]}function lu(r,e){return Ie[0]=r[e],Ie[1]=r[e+1],Ie[2]=r[e+2],Ie[3]=r[e+3],Ie[4]=r[e+4],Ie[5]=r[e+5],Ie[6]=r[e+6],Ie[7]=r[e+7],Ls[0]}var dp=BigInt(Number.MAX_SAFE_INTEGER),pp=BigInt(Number.MIN_SAFE_INTEGER),Le=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return fr;if(e<dp&&e>pp)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>fu&&(o=0n,++n>fu&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return fr;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):fr}},fr=new Le(0,0);fr.toBigInt=function(){return 0n};fr.zzEncode=fr.zzDecode=function(){return this};fr.length=function(){return 1};var fu=4294967296n;function hu(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function du(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ds(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function et(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function po(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Vs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,et(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw et(this,4);return po(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw et(this,4);return po(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw et(this,4);let e=cu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw et(this,4);let e=lu(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw et(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return du(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw et(this,e);this.pos+=e}else do if(this.pos>=this.len)throw et(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw et(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw et(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw et(this,8);let e=po(this.buf,this.pos+=4),t=po(this.buf,this.pos+=4);return new Le(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 Os(r){return new Vs(r instanceof Uint8Array?r:r.subarray())}function Kr(r,e){let t=Os(r);return e.decode(t)}function Ps(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return We(s);o+s>e&&(n=We(e),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var hr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Fs(){}var Hs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},gp=Ps();function mp(r){return globalThis.Buffer!=null?We(r):gp(r)}var gn=class{len;head;tail;states;constructor(){this.len=0,this.head=new hr(Fs,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new hr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ks((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(dn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Le.fromBigInt(e);return this._push(dn,t.length(),t)}uint64Number(e){let t=Le.fromNumber(e);return this._push(dn,t.length(),t)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Le.fromBigInt(e).zzEncode();return this._push(dn,t.length(),t)}sint64Number(e){let t=Le.fromNumber(e).zzEncode();return this._push(dn,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ms,1,e?1:0)}fixed32(e){return this._push(pn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Le.fromBigInt(e);return this._push(pn,4,t.lo)._push(pn,4,t.hi)}fixed64Number(e){let t=Le.fromNumber(e);return this._push(pn,4,t.lo)._push(pn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(au,4,e)}double(e){return this._push(uu,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ms,1,0):this.uint32(t)._push(wp,t,e)}string(e){let t=hu(e);return t!==0?this.uint32(t)._push(Ds,t,e):this._push(Ms,1,0)}fork(){return this.states=new Hs(this),this.head=this.tail=new hr(Fs,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 hr(Fs,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=mp(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ms(r,e,t){e[t]=r&255}function yp(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Ks=class extends hr{next;constructor(e,t){super(yp,e,t),this.next=void 0}};function dn(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function pn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function wp(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(gn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(bp,e,r),this},gn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(xp,e,r),this});function bp(r,e,t){e.set(r,t)}function xp(r,e,t){r.length<40?Ds(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(j(r),t)}function $s(){return new gn}function $r(r,e){let t=$s();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var qr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(qr||(qr={}));function go(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function mn(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return go("enum",qr.VARINT,t,n)}function zr(r,e){return go("message",qr.LENGTH_DELIMITED,r,e)}var fe;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(fe||(fe={}));var qs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(qs||(qs={}));(function(r){r.codec=()=>mn(qs)})(fe||(fe={}));var ft;(function(r){let e;r.codec=()=>(e==null&&(e=zr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),fe.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=fe.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>$r(t,r.codec()),r.decode=t=>Kr(t,r.codec())})(ft||(ft={}));var It;(function(r){let e;r.codec=()=>(e==null&&(e=zr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),fe.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=fe.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>$r(t,r.codec()),r.decode=t=>Kr(t,r.codec())})(It||(It={}));var yn=class{_key;constructor(e){this._key=Gr(e,Mr)}verify(e,t){return ou(this._key,t,e)}marshal(){return this._key}get bytes(){return ft.encode({Type:fe.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return qe(e)?e.then(({bytes:t})=>t):e.bytes}},dr=class{_key;_publicKey;constructor(e,t){this._key=Gr(e,St),this._publicKey=Gr(t,Mr)}sign(e){return nu(this._key,e)}get public(){return new yn(this._publicKey)}marshal(){return this._key}get bytes(){return It.encode({Type:fe.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=Ee.digest(this.bytes),t;return qe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=ct.digest(this.public.bytes);return le.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Hr(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ep(r){if(r.length>St){r=Gr(r,St+Mr);let n=r.subarray(0,St),o=r.subarray(St,r.length);return new dr(n,o)}r=Gr(r,St);let e=r.subarray(0,St),t=r.subarray(Mr);return new dr(e,t)}function vp(r){return r=Gr(r,Mr),new yn(r)}async function Bp(){let{privateKey:r,publicKey:e}=tu();return new dr(r,e)}async function gu(r){let{privateKey:e,publicKey:t}=ru(r);return new dr(e,t)}function Gr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new O(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var ta={};me(ta,{MAX_RSA_KEY_SIZE:()=>Tn,RsaPrivateKey:()=>Jr,RsaPublicKey:()=>kn,fromJwk:()=>Wp,generateKeyPair:()=>Jp,unmarshalRsaPrivateKey:()=>Qs,unmarshalRsaPublicKey:()=>Zp});function pr(r){if(isNaN(r)||r<=0)throw new O("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Vr(r)}var Jt={};me(Jt,{exportToPem:()=>qp,importFromPem:()=>zp,jwkToPkcs1:()=>Mp,jwkToPkix:()=>Kp,pkcs1ToJwk:()=>Fp,pkixToJwk:()=>Hp});var yo=class extends Lr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,eo(e);let n=Kt(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return Ur(this),this.iHash.update(e),this}digestInto(e){Ur(this),ys(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},wn=(r,e,t)=>new yo(r,e).update(t).digest();wn.create=(r,e)=>new yo(r,e);function Ap(r,e,t,n){eo(r);let o=Fc({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(_r(i),_r(s),_r(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Kt(e),f=Kt(t),u=new Uint8Array(s),l=wn.create(r,c),d=l._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:a,DK:u,PRF:l,PRFSalt:d}}function Sp(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Gs(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:f}=Ap(r,e,t,n),u,l=new Uint8Array(4),d=Dr(l),E=new Uint8Array(c.outputLen);for(let g=1,h=0;h<i;g++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);d.setInt32(0,g,!1),(u=f._cloneInto(u)).update(l).digestInto(E),p.set(E.subarray(0,p.length)),await Pc(o-1,s,()=>{c._cloneInto(u).update(E).digestInto(E);for(let b=0;b<p.length;b++)p[b]^=E[b]})}return Sp(c,f,a,u,E)}var Y=Vt(mu());function gr(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Yt(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(o/l),o-=f[i-u-1]*l}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function xo(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Ys(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=gr(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,gr(i,8)-n}function yu(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=Yt(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=Yt(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function wu(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function De(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var Mx=Math.log(2);function Eo(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Zs(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function Nt(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var xn=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Zs(this.items)}},bn=[new Uint8Array([1])],bu="0123456789";var Zr="",rt=new ArrayBuffer(0),Ws=new Uint8Array(0),En="EndOfContent",Eu="OCTET STRING",vu="BIT STRING";function _t(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?Y.BufferSourceConverter.toUint8Array(i.valueHex):Ws}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Nt(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",rt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:Y.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var kt=class{constructor({blockLength:e=0,error:t=Zr,warnings:n=[],valueBeforeDecode:o=Ws}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=Y.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:Y.Convert.ToHex(this.valueBeforeDecodeView)}}};kt.NAME="baseBlock";var Re=class extends kt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Re.NAME="valueBlock";var vo=class extends _t(kt){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?Y.BufferSourceConverter.toUint8Array(e.valueHex):Ws,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",rt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=Yt(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);if(!Nt(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let d=new Uint8Array(u);for(let E=0;E<f.length;E++)d[E]=f[E];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let d=0;d<c;d++)l[d]=f[d];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=gr(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};vo.NAME="identificationBlock";var Bo=class extends kt{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);if(!Nt(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=gr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=Yt(this.length,8);if(o.byteLength>127)return this.error="Too big length",rt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Bo.NAME="lengthBlock";var _={},ve=class extends kt{constructor({name:e=Zr,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new vo(o),this.lenBlock=new Bo(o),this.valueBlock=i?new i(o):new Re(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new xn;t||Bu(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?rt:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():Y.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${Y.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return wu(t,n)}};ve.NAME="BaseBlock";function Bu(r){if(r instanceof _.Constructed)for(let e of r.valueBlock.value)Bu(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Ao=class extends ve{constructor({value:e=Zr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Ao.NAME="BaseStringBlock";var So=class extends _t(Re){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};So.NAME="PrimitiveValueBlock";var Au,Io=class extends ve{constructor(e={}){super(e,So),this.idBlock.isConstructed=!1}};Au=Io;_.Primitive=Au;Io.NAME="PRIMITIVE";function Lp(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ii(r,e=0,t=r.length){let n=e,o=new ve({},Re),i=new kt;if(!Nt(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=ve;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=_.EndOfContent;break;case 1:c=_.Boolean;break;case 2:c=_.Integer;break;case 3:c=_.BitString;break;case 4:c=_.OctetString;break;case 5:c=_.Null;break;case 6:c=_.ObjectIdentifier;break;case 10:c=_.Enumerated;break;case 12:c=_.Utf8String;break;case 13:c=_.RelativeObjectIdentifier;break;case 14:c=_.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=_.Sequence;break;case 17:c=_.Set;break;case 18:c=_.NumericString;break;case 19:c=_.PrintableString;break;case 20:c=_.TeletexString;break;case 21:c=_.VideotexString;break;case 22:c=_.IA5String;break;case 23:c=_.UTCTime;break;case 24:c=_.GeneralizedTime;break;case 25:c=_.GraphicString;break;case 26:c=_.VisibleString;break;case 27:c=_.GeneralString;break;case 28:c=_.UniversalString;break;case 29:c=_.CharacterString;break;case 30:c=_.BmpString;break;case 31:c=_.DATE;break;case 32:c=_.TimeOfDay;break;case 33:c=_.DateTime;break;case 34:c=_.Duration;break;default:{let f=o.idBlock.isConstructed?new _.Constructed:new _.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?_.Constructed:_.Primitive}return o=Lp(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function Wr(r){if(!r.byteLength){let e=new ve({},Re);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ii(Y.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Dp(r,e){return r?1:e}var ht=class extends Re{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);if(!Nt(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;Dp(this.isIndefiniteForm,n)>0;){let s=ii(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===En)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===En?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new xn;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?rt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};ht.NAME="ConstructedValueBlock";var Su,Zt=class extends ve{constructor(e={}){super(e,ht),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
2
|
+
"use strict";var HeliaRouters=(()=>{var sh=Object.create;var qn=Object.defineProperty;var ah=Object.getOwnPropertyDescriptor;var ch=Object.getOwnPropertyNames;var uh=Object.getPrototypeOf,lh=Object.prototype.hasOwnProperty;var nr=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),me=(r,e)=>{for(var t in e)qn(r,t,{get:e[t],enumerable:!0})},Oa=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ch(e))!lh.call(r,o)&&o!==t&&qn(r,o,{get:()=>e[o],enumerable:!(n=ah(e,o))||n.enumerable});return r};var Dt=(r,e,t)=>(t=r!=null?sh(uh(r)):{},Oa(e||!r||!r.__esModule?qn(t,"default",{value:r,enumerable:!0}):t,r)),fh=r=>Oa(qn({},"__esModule",{value:!0}),r);var $a=nr((fm,Ka)=>{var wr=1e3,br=wr*60,xr=br*60,or=xr*24,hh=or*7,dh=or*365.25;Ka.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return ph(r);if(t==="number"&&isFinite(r))return e.long?mh(r):gh(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function ph(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*dh;case"weeks":case"week":case"w":return t*hh;case"days":case"day":case"d":return t*or;case"hours":case"hour":case"hrs":case"hr":case"h":return t*xr;case"minutes":case"minute":case"mins":case"min":case"m":return t*br;case"seconds":case"second":case"secs":case"sec":case"s":return t*wr;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function gh(r){var e=Math.abs(r);return e>=or?Math.round(r/or)+"d":e>=xr?Math.round(r/xr)+"h":e>=br?Math.round(r/br)+"m":e>=wr?Math.round(r/wr)+"s":r+"ms"}function mh(r){var e=Math.abs(r);return e>=or?zn(r,e,or,"day"):e>=xr?zn(r,e,xr,"hour"):e>=br?zn(r,e,br,"minute"):e>=wr?zn(r,e,wr,"second"):r+" ms"}function zn(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var za=nr((hm,qa)=>{function yh(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=$a(),t.destroy=f,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let l=0;for(let d=0;d<u.length;d++)l=(l<<5)-l+u.charCodeAt(d),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(u){let l,d=null,E,g;function h(...p){if(!h.enabled)return;let b=h,R=Number(new Date),v=R-(l||R);b.diff=v,b.prev=l,b.curr=R,l=R,p[0]=t.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let L=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(k,C)=>{if(k==="%%")return"%";L++;let y=t.formatters[C];if(typeof y=="function"){let N=p[L];k=y.call(b,N),p.splice(L,1),L--}return k}),t.formatArgs.call(b,p),(b.log||t.log).apply(b,p)}return h.namespace=u,h.useColors=t.useColors(),h.color=t.selectColor(u),h.extend=n,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(E!==t.namespaces&&(E=t.namespaces,g=t.enabled(u)),g),set:p=>{d=p}}),typeof t.init=="function"&&t.init(h),h}function n(u,l){let d=t(this.namespace+(typeof l>"u"?":":l)+u);return d.log=this.log,d}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let l,d=(typeof u=="string"?u:"").split(/[\s,]+/),E=d.length;for(l=0;l<E;l++)d[l]&&(u=d[l].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.slice(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...t.names.map(a),...t.skips.map(a).map(l=>"-"+l)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,d;for(l=0,d=t.skips.length;l<d;l++)if(t.skips[l].test(u))return!1;for(l=0,d=t.names.length;l<d;l++)if(t.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack||u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}qa.exports=yh});var Ga=nr((Oe,Gn)=>{Oe.formatArgs=bh;Oe.save=xh;Oe.load=Eh;Oe.useColors=wh;Oe.storage=vh();Oe.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();Oe.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function wh(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function bh(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Gn.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}Oe.log=console.debug||console.log||(()=>{});function xh(r){try{r?Oe.storage.setItem("debug",r):Oe.storage.removeItem("debug")}catch{}}function Eh(){let r;try{r=Oe.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function vh(){try{return localStorage}catch{}}Gn.exports=za()(Oe);var{formatters:Bh}=Gn.exports;Bh.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var gu=nr(Gr=>{"use strict";var Ap="[object ArrayBuffer]",Rt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ap}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Ys="string",Sp=/^[0-9a-f]+$/i,Ip=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Rp=/^[a-zA-Z0-9-_]+$/,bo=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=Rt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Ge=class{static toString(e,t=!1){let n=Rt.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},xo=class r{static isHex(e){return typeof e===Ys&&Sp.test(e)}static isBase64(e){return typeof e===Ys&&Ip.test(e)}static isBase64Url(e){return typeof e===Ys&&Rp.test(e)}static ToString(e,t="utf8"){let n=Rt.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Ge.toString(n,!0);case"utf16":case"utf16be":return Ge.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Ge.fromString(e,!0);case"utf16":case"utf16be":return Ge.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Rt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return bo.fromString(e);case"utf16":case"utf16be":return Ge.fromString(e);case"utf16le":case"usc2":return Ge.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return bo.toString(e);case"utf16":case"utf16be":return Ge.toString(e);case"utf16le":case"usc2":return Ge.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Rt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Rt.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ge.toString(e,t)}static FromUtf16String(e,t=!1){return Ge.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};xo.DEFAULT_UTF8_ENCODING="utf8";function kp(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function Tp(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function Np(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}Gr.BufferSourceConverter=Rt;Gr.Convert=xo;Gr.assign=kp;Gr.combine=Tp;Gr.isEqual=Np});var ui=nr((L1,El)=>{"use strict";function xl(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function hg(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return xl(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),xl(new o,t)}}El.exports=hg});var la=nr((M1,ua)=>{var F1=function(){typeof ua<"u"&&(ua.exports=h);var r=86400,e=3200,t=146097*e/400,n=r*t,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(y){var N=y-y%1;return N==0&&(y<0||y===0&&1/y!=1/0)?-0:N},u=h.prototype,l=(h.fromDate=function(y){return new h(+y)},h.fromInt64BE=L(0,1,2,3,0,4),h.fromInt64LE=L(3,2,1,0,4,0),h.fromString=function(T){var N,D=new h,T=(T+="").replace(/^\s*[+\-]?\d+/,function(H){var H=+H,J=1970+(H-1970)%400;return D.year=H-J,J}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(P,H,J){return H<0&&(J*=-1),N=6e4*(60*+H+ +J),""}).replace(/\.\d+$/,function(P){return D.nano=+(P+c).substr(1,9),""}).split(/\D+/);if(1<T.length?T[1]--:T[1]=0,D.time=N=Date.UTC.apply(Date,T)-(N||0),isNaN(N))throw new TypeError("Invalid Date");return p(D)},h.fromTimeT=function(y){return R(y,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(y){return this.nano+=+y||0,this},u.getNano=function(){var y=p(this);return(y.time%1e3*a+ +y.nano+1e9)%1e9},u.getTimeT=function(){var N=p(this),y=Math.floor(N.time/1e3),N=N.year;return N&&(y+=N*t*r/e),y},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return b(p(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(y){var N=this,D=N.toDate(),T={H:function(){return k(D.getUTCHours())},L:function(){return C(D.getUTCMilliseconds(),3)},M:function(){return k(D.getUTCMinutes())},N:function(){return C(N.getNano(),9)},S:function(){return k(D.getUTCSeconds())},Y:function(){var P=N.getYear();return 999999<P?"+"+P:9999<P?"+"+C(P,6):0<=P?C(P,4):-999999<=P?"-"+C(-P,6):P},a:function(){return E[D.getUTCDay()]},b:function(){return d[D.getUTCMonth()]},d:function(){return k(D.getUTCDate())},e:function(){return function(P){return(9<P?"":" ")+(0|P)}(D.getUTCDate())},m:function(){return k(D.getUTCMonth()+1)}};return function P(H){return H.replace(/%./g,function(J){var A=J[1],x=g[A],A=T[A];return x?P(x):A?A():J})}(y||l)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],E=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],g={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return h;function h(y,N,D){var T=this;if(!(T instanceof h))return new h(y,N,D);T.time=+y||0,T.nano=+N||0,T.year=+D||0,p(T)}function p(y){var N,D,T,P=y.year,H=y.time,J=y.nano,x=((J<0||a<=J)&&(J-=(D=Math.floor(J/a))*a,H+=D,D=1),P%e);return(H<-i||i<H||x)&&((N=f(H/o))&&(P+=N*e,H-=N*o),(T=b(H)).setUTCFullYear(x+T.getUTCFullYear()),T=(H=+T)+(N=f((P-=x)/e))*o,N&&-i<=T&&T<=i&&(P-=N*e,H=T),D=1),D&&(y.year=P,y.time=H,y.nano=J),y}function b(y){var N=new Date(0);return N.setTime(y),N}function R(P,T){P=+P||0;var D=f((T=(T|0)*s)/n)+f(P/n),T=T%n+P%n,P=f(T/n);return P&&(D+=P,T-=P*n),new h(1e3*T,0,D*e)}function v(y,N,D,T,P,H){return function(x,A){var B=p(this);x=x||new Array(8),S(x,A|=0);var w=Math.floor(B.time/1e3),B=B.year*(t*r/e),M=f(B/s)+f(w/s),B=B%s+w%s,w=Math.floor(B/s);return w&&(M+=w,B-=w*s),J(x,A+P,M),J(x,A+H,B),x};function J(x,A,M){x[A+y]=M>>24&255,x[A+N]=M>>16&255,x[A+D]=M>>8&255,x[A+T]=255&M}}function L(y,N,D,T,P,H){return function(x,A){S(x,A|=0);var M=J(x,A+P);return R(J(x,A+H),M)};function J(x,A){return 16777216*x[A+y]+(x[A+N]<<16|x[A+D]<<8|x[A+T])}}function S(y,N){if(y=y&&y.length,y==null)throw new TypeError("Invalid Buffer");if(y<N+8)throw new RangeError("Out of range")}function k(y){return(9<y?"":"0")+(0|y)}function C(y,N){return(c+(0|y)).substr(-N)}}()});var Mf=nr((k2,Ea)=>{"use strict";var Jg=Object.prototype.hasOwnProperty,Ue="~";function Mn(){}Object.create&&(Mn.prototype=Object.create(null),new Mn().__proto__||(Ue=!1));function Xg(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Ff(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Xg(t,n||r,o),s=Ue?Ue+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function Bi(r,e){--r._eventsCount===0?r._events=new Mn:delete r._events[e]}function ke(){this._events=new Mn,this._eventsCount=0}ke.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Jg.call(t,n)&&e.push(Ue?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ke.prototype.listeners=function(e){var t=Ue?Ue+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};ke.prototype.listenerCount=function(e){var t=Ue?Ue+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ke.prototype.emit=function(e,t,n,o,i,s){var a=Ue?Ue+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,o),!0;case 5:return c.fn.call(c.context,t,n,o,i),!0;case 6:return c.fn.call(c.context,t,n,o,i,s),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,E;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(e,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,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,o);break;default:if(!u)for(E=1,u=new Array(f-1);E<f;E++)u[E-1]=arguments[E];c[l].fn.apply(c[l].context,u)}}return!0};ke.prototype.on=function(e,t,n){return Ff(this,e,t,n,!1)};ke.prototype.once=function(e,t,n){return Ff(this,e,t,n,!0)};ke.prototype.removeListener=function(e,t,n,o){var i=Ue?Ue+e:e;if(!this._events[i])return this;if(!t)return Bi(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&Bi(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==t||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:Bi(this,i)}return this};ke.prototype.removeAllListeners=function(e){var t;return e?(t=Ue?Ue+e:e,this._events[t]&&Bi(this,t)):(this._events=new Mn,this._eventsCount=0),this};ke.prototype.off=ke.prototype.removeListener;ke.prototype.addListener=ke.prototype.on;ke.prefixed=Ue;ke.EventEmitter=ke;typeof Ea<"u"&&(Ea.exports=ke)});var om={};me(om,{delegatedHTTPRouting:()=>Wf,libp2pRouting:()=>Jf});var Pa=Symbol.for("@libp2p/content-routing");var Ni=Symbol.for("@libp2p/peer-id");function Fa(r){return r!=null&&!!r[Ni]}var Ma=Symbol.for("@libp2p/peer-routing");var O=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Ha=(r,...e)=>{try{[...e]}catch{}};var Pe=Dt(Ga(),1);var Vi={};me(Vi,{base32:()=>We,base32hex:()=>Ch,base32hexpad:()=>Uh,base32hexpadupper:()=>Lh,base32hexupper:()=>_h,base32pad:()=>Th,base32padupper:()=>Nh,base32upper:()=>Qa,base32z:()=>Vh});var dm=new Uint8Array(0);function ja(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function bt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ya(r){return new TextEncoder().encode(r)}function Za(r){return new TextDecoder().decode(r)}function Ah(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var h=0,p=0,b=0,R=g.length;b!==R&&g[b]===0;)b++,h++;for(var v=(R-b)*u+1>>>0,L=new Uint8Array(v);b!==R;){for(var S=g[b],k=0,C=v-1;(S!==0||k<p)&&C!==-1;C--,k++)S+=256*L[C]>>>0,L[C]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");p=k,b++}for(var y=v-p;y!==v&&L[y]===0;)y++;for(var N=c.repeat(h);y<v;++y)N+=r.charAt(L[y]);return N}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var h=0;if(g[h]!==" "){for(var p=0,b=0;g[h]===c;)p++,h++;for(var R=(g.length-h)*f+1>>>0,v=new Uint8Array(R);g[h];){var L=t[g.charCodeAt(h)];if(L===255)return;for(var S=0,k=R-1;(L!==0||S<b)&&k!==-1;k--,S++)L+=a*v[k]>>>0,v[k]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=S,h++}if(g[h]!==" "){for(var C=R-b;C!==R&&v[C]===0;)C++;for(var y=new Uint8Array(p+(R-C)),N=p;C!==R;)y[N++]=v[C++];return y}}}function E(g){var h=d(g);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:E}}var Sh=Ah,Ih=Sh,Ja=Ih;var Ci=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},_i=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xa(this,e)}},Ui=class{decoders;constructor(e){this.decoders=e}or(e){return Xa(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xa(r,e){return new Ui({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Li=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ci(e,t,n),this.decoder=new _i(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Er({name:r,prefix:e,encode:t,decode:n}){return new Li(r,e,t,n)}function Ot({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Ja(t,r);return Er({prefix:e,name:r,encode:n,decode:i=>bt(o(i))})}function Rh(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function kh(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function ae({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Er({prefix:e,name:r,encode(o){return kh(o,n,t)},decode(o){return Rh(o,n,t,r)}})}var We=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Qa=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Th=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nh=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ch=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_h=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uh=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lh=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vh=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Di={};me(Di,{base58btc:()=>le,base58flickr:()=>Dh});var le=Ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Dh=Ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Oi={};me(Oi,{base64:()=>on,base64pad:()=>Oh,base64url:()=>Ph,base64urlpad:()=>Fh});var on=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oh=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ph=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fh=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});Pe.default.formatters.b=r=>r==null?"undefined":le.baseEncode(r);Pe.default.formatters.t=r=>r==null?"undefined":We.baseEncode(r);Pe.default.formatters.m=r=>r==null?"undefined":on.baseEncode(r);Pe.default.formatters.p=r=>r==null?"undefined":r.toString();Pe.default.formatters.c=r=>r==null?"undefined":r.toString();Pe.default.formatters.k=r=>r==null?"undefined":r.toString();Pe.default.formatters.a=r=>r==null?"undefined":r.toString();function Mh(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function Pt(r){let e=Mh(`${r}:trace`);return Pe.default.enabled(`${r}:trace`)&&Pe.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,Pe.default)(`${r}:trace`)),Object.assign((0,Pe.default)(r),{error:(0,Pe.default)(`${r}:error`),trace:e})}var Pi={};me(Pi,{base10:()=>Hh});var Hh=Ot({prefix:"9",name:"base10",alphabet:"0123456789"});var Fi={};me(Fi,{base16:()=>Kh,base16upper:()=>$h});var Kh=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$h=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Mi={};me(Mi,{base2:()=>qh});var qh=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Hi={};me(Hi,{base256emoji:()=>Zh});var ec=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}"),zh=ec.reduce((r,e,t)=>(r[t]=e,r),[]),Gh=ec.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function jh(r){return r.reduce((e,t)=>(e+=zh[t],e),"")}function Yh(r){let e=[];for(let t of r){let n=Gh[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Zh=Er({prefix:"\u{1F680}",name:"base256emoji",encode:jh,decode:Yh});var Ki={};me(Ki,{base36:()=>jn,base36upper:()=>Wh});var jn=Ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wh=Ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $i={};me($i,{base8:()=>Jh});var Jh=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qi={};me(qi,{identity:()=>Xh});var Xh=Er({prefix:"\0",name:"identity",encode:r=>Za(r),decode:r=>Ya(r)});var Um=new TextEncoder,Lm=new TextDecoder;var Gi={};me(Gi,{identity:()=>ut});var td=nc,tc=128,rd=127,nd=~rd,od=Math.pow(2,31);function nc(r,e,t){e=e||[],t=t||0;for(var n=t;r>=od;)e[t++]=r&255|tc,r/=128;for(;r&nd;)e[t++]=r&255|tc,r>>>=7;return e[t]=r|0,nc.bytes=t-n+1,e}var id=zi,sd=128,rc=127;function zi(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw zi.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&rc)<<o:(s&rc)*Math.pow(2,o),o+=7}while(s>=sd);return zi.bytes=i-n,t}var ad=Math.pow(2,7),cd=Math.pow(2,14),ud=Math.pow(2,21),ld=Math.pow(2,28),fd=Math.pow(2,35),hd=Math.pow(2,42),dd=Math.pow(2,49),pd=Math.pow(2,56),gd=Math.pow(2,63),md=function(r){return r<ad?1:r<cd?2:r<ud?3:r<ld?4:r<fd?5:r<hd?6:r<dd?7:r<pd?8:r<gd?9:10},yd={encode:td,decode:id,encodingLength:md},wd=yd,sn=wd;function an(r,e=0){return[sn.decode(r,e),sn.decode.bytes]}function vr(r,e,t=0){return sn.encode(r,e,t),e}function Br(r){return sn.encodingLength(r)}function ct(r,e){let t=e.byteLength,n=Br(r),o=n+Br(t),i=new Uint8Array(o+t);return vr(r,i,0),vr(t,i,n),i.set(e,o),new Ar(r,t,e,i)}function Ft(r){let e=bt(r),[t,n]=an(e),[o,i]=an(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ar(t,o,s,e)}function oc(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ja(r.bytes,t.bytes)}}var Ar=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var ic=0,bd="identity",sc=bt;function xd(r){return ct(ic,sc(r))}var ut={code:ic,name:bd,encode:sc,digest:xd};var Zi={};me(Zi,{sha256:()=>Ee,sha512:()=>Ed});function Yi({name:r,code:e,encode:t}){return new ji(r,e,t)}var ji=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?ct(this.code,t):t.then(n=>ct(this.code,n))}else throw Error("Unknown type, must be binary type")}};function cc(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ee=Yi({name:"sha2-256",code:18,encode:cc("SHA-256")}),Ed=Yi({name:"sha2-512",code:19,encode:cc("SHA-512")});function uc(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Bd(t,Wi(r),e??le.encoder);default:return Ad(t,Wi(r),e??We.encoder)}}var lc=new WeakMap;function Wi(r){let e=lc.get(r);if(e==null){let t=new Map;return lc.set(r,t),t}return e}var Te=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==cn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=ct(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&oc(e.multihash,n.multihash)}toString(e){return uc(this,e)}toJSON(){return{"/":uc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??fc(n,o,i.bytes))}else if(t[Id]===!0){let{version:n,multihash:o,code:i}=t,s=Ft(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==cn)throw new Error(`Version 0 CID must use dag-pb (code: ${cn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=fc(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,cn,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=bt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Ar(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,d]=an(e.subarray(t));return t+=d,l},o=n(),i=cn;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,o]=vd(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Wi(i).set(n,e),i}};function vd(r,e){switch(r[0]){case"Q":{let t=e??le;return[le.prefix,t.decode(`${le.prefix}${r}`)]}case le.prefix:{let t=e??le;return[le.prefix,t.decode(r)]}case We.prefix:{let t=e??We;return[We.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Bd(r,e,t){let{prefix:n}=t;if(n!==le.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Ad(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var cn=112,Sd=18;function fc(r,e,t){let n=Br(r),o=n+Br(e),i=new Uint8Array(o+t.byteLength);return vr(r,i,0),vr(e,i,n),i.set(t,o),i}var Id=Symbol.for("@ipld/js-cid/CID");var Ht={...qi,...Mi,...$i,...Pi,...Fi,...Vi,...Ki,...Di,...Oi,...Hi},ty={...Zi,...Gi};function ce(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Rd=Symbol.for("nodejs.util.inspect.custom"),hc=Object.values(Ht).map(r=>r.decoder).reduce((r,e)=>r.or(e),Ht.identity.decoder),dc=114,Ji=36,Xi=37,un=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ni]=!0;toString(){return this.string==null&&(this.string=le.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Te.createV1(dc,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return Qi(e).equals(this);if(e?.multihash?.bytes!=null)return ce(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Rd](){return`PeerId(${this.toString()})`}},Sr=class extends un{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ir=class extends un{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Rr=class extends un{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Qi(r,e){if(e=e??hc,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Ft(le.decode(`z${r}`));return r.startsWith("12D")?new Ir({multihash:t}):r.startsWith("16U")?new Rr({multihash:t}):new Sr({multihash:t})}return ln(hc.decode(r))}function ln(r){try{let e=Ft(r);if(e.code===ut.code){if(e.digest.length===Ji)return new Ir({multihash:e});if(e.digest.length===Xi)return new Rr({multihash:e})}if(e.code===Ee.code)return new Sr({multihash:e})}catch{return kd(Te.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function kd(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==dc)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Ee.code)return new Sr({multihash:r.multihash});if(e.code===ut.code){if(e.digest.length===Ji)return new Ir({multihash:r.multihash});if(e.digest.length===Xi)return new Rr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function pc(r,e){return r.length===Ji?new Ir({multihash:ct(ut.code,r),privateKey:e}):r.length===Xi?new Rr({multihash:ct(ut.code,r),privateKey:e}):new Sr({multihash:await Ee.digest(r),publicKey:r,privateKey:e})}function ir(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Je(r=0){return globalThis.Buffer?.allocUnsafe!=null?ir(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function mc(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var gc=mc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),es=mc("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Je(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Td={utf8:gc,"utf-8":gc,hex:Ht.base16,latin1:es,ascii:es,binary:es,...Ht},Zn=Td;function W(r,e="utf8"){let t=Zn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Nd=Math.pow(2,7),Cd=Math.pow(2,14),_d=Math.pow(2,21),ts=Math.pow(2,28),rs=Math.pow(2,35),ns=Math.pow(2,42),os=Math.pow(2,49),ee=128,Se=127;function lt(r){if(r<Nd)return 1;if(r<Cd)return 2;if(r<_d)return 3;if(r<ts)return 4;if(r<rs)return 5;if(r<ns)return 6;if(r<os)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ud(r,e,t=0){switch(lt(r)){case 8:e[t++]=r&255|ee,r/=128;case 7:e[t++]=r&255|ee,r/=128;case 6:e[t++]=r&255|ee,r/=128;case 5:e[t++]=r&255|ee,r/=128;case 4:e[t++]=r&255|ee,r>>>=7;case 3:e[t++]=r&255|ee,r>>>=7;case 2:e[t++]=r&255|ee,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Ld(r,e,t=0){switch(lt(r)){case 8:e.set(t++,r&255|ee),r/=128;case 7:e.set(t++,r&255|ee),r/=128;case 6:e.set(t++,r&255|ee),r/=128;case 5:e.set(t++,r&255|ee),r/=128;case 4:e.set(t++,r&255|ee),r>>>=7;case 3:e.set(t++,r&255|ee),r>>>=7;case 2:e.set(t++,r&255|ee),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Vd(r,e){let t=r[e],n=0;if(n+=t&Se,t<ee||(t=r[e+1],n+=(t&Se)<<7,t<ee)||(t=r[e+2],n+=(t&Se)<<14,t<ee)||(t=r[e+3],n+=(t&Se)<<21,t<ee)||(t=r[e+4],n+=(t&Se)*ts,t<ee)||(t=r[e+5],n+=(t&Se)*rs,t<ee)||(t=r[e+6],n+=(t&Se)*ns,t<ee)||(t=r[e+7],n+=(t&Se)*os,t<ee))return n;throw new RangeError("Could not decode varint")}function Dd(r,e){let t=r.get(e),n=0;if(n+=t&Se,t<ee||(t=r.get(e+1),n+=(t&Se)<<7,t<ee)||(t=r.get(e+2),n+=(t&Se)<<14,t<ee)||(t=r.get(e+3),n+=(t&Se)<<21,t<ee)||(t=r.get(e+4),n+=(t&Se)*ts,t<ee)||(t=r.get(e+5),n+=(t&Se)*rs,t<ee)||(t=r.get(e+6),n+=(t&Se)*ns,t<ee)||(t=r.get(e+7),n+=(t&Se)*os,t<ee))return n;throw new RangeError("Could not decode varint")}function kr(r,e,t=0){return e==null&&(e=Je(lt(r))),e instanceof Uint8Array?Ud(r,e,t):Ld(r,e,t)}function sr(r,e=0){return r instanceof Uint8Array?Vd(r,e):Dd(r,e)}function Ne(r,e){if(globalThis.Buffer!=null)return ir(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=Je(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return ir(t)}var Wn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=e,i+=u,i>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var wc=45,Od=15,Tr=new Wn;function is(r){if(!(r.length>Od))return Tr.new(r).parseWith(()=>Tr.readIPv4Addr())}function ss(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wc))return Tr.new(r).parseWith(()=>Tr.readIPv6Addr())}function Jn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wc))return Tr.new(r).parseWith(()=>Tr.readIPAddr())}var Uy=parseInt("0xFFFF",16),Ly=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function j(r,e="utf8"){let t=Zn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?ir(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Ec(r){return!!is(r)}function vc(r){return!!ss(r)}function Xn(r){return!!Jn(r)}var Bc=Ec,Kd=vc,as=function(r){let e=0;if(r=r.toString().trim(),Bc(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Kd(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Bc(t[n]),s;i&&(s=as(t[n]),t[n]=W(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,W(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},Ac=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Nr={},cs={},qd=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];qd.forEach(r=>{let e=zd(...r);cs[e.code]=e,Nr[e.name]=e});function zd(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function ne(r){if(typeof r=="number"){if(cs[r]!=null)return cs[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Nr[r]!=null)return Nr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var xw=ne("ip4"),Ew=ne("ip6"),vw=ne("ipcidr");function ls(r,e){switch(ne(r).code){case 4:case 41:return jd(e);case 42:return Rc(e);case 6:case 273:case 33:case 132:return Tc(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Rc(e);case 421:return Jd(e);case 444:return kc(e);case 445:return kc(e);case 466:return Wd(e);default:return W(e,"base16")}}function fs(r,e){switch(ne(r).code){case 4:return Sc(e);case 41:return Sc(e);case 42:return Ic(e);case 6:case 273:case 33:case 132:return hs(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ic(e);case 421:return Yd(e);case 444:return Xd(e);case 445:return Qd(e);case 466:return Zd(e);default:return j(e,"base16")}}var us=Object.values(Ht).map(r=>r.decoder),Gd=function(){let r=us[0].or(us[1]);return us.slice(2).forEach(e=>r=r.or(e)),r}();function Sc(r){if(!Xn(r))throw new Error("invalid ip address");return as(r)}function jd(r){let e=Ac(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Xn(e))throw new Error("invalid ip address");return e}function hs(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Tc(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ic(r){let e=j(r),t=Uint8Array.from(kr(e.length));return Ne([t,e],t.length+e.length)}function Rc(r){let e=sr(r);if(r=r.slice(lt(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function Yd(r){let e;r[0]==="Q"||r[0]==="1"?e=Ft(le.decode(`z${r}`)).bytes:e=Te.parse(r).multihash.bytes;let t=Uint8Array.from(kr(e.length));return Ne([t,e],t.length+e.length)}function Zd(r){let e=Gd.decode(r),t=Uint8Array.from(kr(e.length));return Ne([t,e],t.length+e.length)}function Wd(r){let e=sr(r),t=r.slice(lt(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function Jd(r){let e=sr(r),t=r.slice(lt(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function Xd(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=We.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=hs(n);return Ne([t,o],t.length+o.length)}function Qd(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=We.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=hs(n);return Ne([t,o],t.length+o.length)}function kc(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=Tc(t);return`${n}:${o}`}function Nc(r){r=ds(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=ne(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw _c("invalid address: "+r);if(a.path===!0){n=ds(o.slice(i).join("/")),e.push([a.code,fs(a.code,n)]),t.push([a.code,n]);break}let c=fs(a.code,o[i]);e.push([a.code,c]),t.push([a.code,ls(a.code,c)])}return{string:Cc(t),bytes:gs(e),tuples:e,stringTuples:t,path:n}}function ps(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=sr(r,o),s=lt(i),a=ne(i),c=e0(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw _c("Invalid address Uint8Array: "+W(r,"base16"));e.push([i,f]);let u=ls(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Cc(t),tuples:e,stringTuples:t,path:n}}function Cc(r){let e=[];return r.map(t=>{let n=ne(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ds(e.join("/"))}function gs(r){return Ne(r.map(e=>{let t=ne(e[0]),n=Uint8Array.from(kr(t.code));return e.length>1&&e[1]!=null&&(n=Ne([n,e[1]])),n}))}function e0(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=sr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+lt(t)}}function ds(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function _c(r){return new Error("Error parsing address: "+r)}var t0=Symbol.for("nodejs.util.inspect.custom"),ms=Symbol.for("@multiformats/js-multiaddr/multiaddr"),r0=[ne("dns").code,ne("dns4").code,ne("dns6").code,ne("dnsaddr").code],Qn=class r{bytes;#e;#r;#i;#a;[ms]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ps(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Nc(e)}else if(Lc(e))t=ps(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#r=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=ne("tcp"),a=ne("udp"),c=ne("ip4"),f=ne("ip6"),u=ne("dns6"),l=ne("ip6zone");for(let[E,g]of this.stringTuples())E===l.code&&(i=`%${g??""}`),r0.includes(E)&&(t=s.name,o=443,n=`${g??""}${i}`,e=E===u.code?6:4),(E===s.code||E===a.code)&&(t=ne(E).name,o=parseInt(g??"")),(E===c.code||E===f.code)&&(t=ne(E).name,n=`${g??""}${i}`,e=E===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#r.map(([e])=>Object.assign({},ne(e)))}protoCodes(){return this.#r.map(([e])=>e)}protoNames(){return this.#r.map(([e])=>ne(e).name)}tuples(){return this.#r}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(gs(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Nr.p2p.code&&e.push([n,o]),n===Nr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(le.decode(`z${n}`),"base58btc"):W(Te.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return ce(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Uc.get(t.name);if(n==null)throw new O(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>new r(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[t0](){return`Multiaddr(${this.#e})`}};var Uc=new Map;function Lc(r){return!!r?.[ms]}function ys(r){return new Qn(r)}function fn(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}async function*eo(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var Gs={};me(Gs,{Ed25519PrivateKey:()=>hr,Ed25519PublicKey:()=>wn,generateKeyPair:()=>Ep,generateKeyPairFromSeed:()=>pu,unmarshalEd25519PrivateKey:()=>bp,unmarshalEd25519PublicKey:()=>xp});function ze(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Cr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function n0(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ws(r,...e){if(!n0(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function to(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Cr(r.outputLen),Cr(r.blockLen)}function _r(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Vc(r,e){ws(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ro=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Dc(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Lr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Xe=(r,e)=>r<<32-e|r>>>e,o0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!o0)throw new Error("Non little-endian hardware is not supported");var i0=async()=>{};async function Oc(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await i0(),n+=i)}}function bs(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Kt(r){if(typeof r=="string"&&(r=bs(r)),!Dc(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function no(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];if(!Dc(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Ur=class{clone(){return this._cloneInto()}},s0={}.toString;function Pc(r,e){if(e!==void 0&&s0.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function oo(r){let e=n=>r().update(Kt(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Vr(r=32){if(ro&&typeof ro.getRandomValues=="function")return ro.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function a0(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}var Dr=class extends Ur{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Lr(this.buffer)}update(e){_r(this);let{view:t,buffer:n,blockLen:o}=this;e=Kt(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Lr(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){_r(this),Vc(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)t[l]=0;a0(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Lr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should 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],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var io=BigInt(4294967295),xs=BigInt(32);function Fc(r,e=!1){return e?{h:Number(r&io),l:Number(r>>xs&io)}:{h:Number(r>>xs&io)|0,l:Number(r&io)|0}}function c0(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Fc(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var u0=(r,e)=>BigInt(r>>>0)<<xs|BigInt(e>>>0),l0=(r,e,t)=>r>>>t,f0=(r,e,t)=>r<<32-t|e>>>t,h0=(r,e,t)=>r>>>t|e<<32-t,d0=(r,e,t)=>r<<32-t|e>>>t,p0=(r,e,t)=>r<<64-t|e>>>t-32,g0=(r,e,t)=>r>>>t-32|e<<64-t,m0=(r,e)=>e,y0=(r,e)=>r,w0=(r,e,t)=>r<<t|e>>>32-t,b0=(r,e,t)=>e<<t|r>>>32-t,x0=(r,e,t)=>e<<t-32|r>>>64-t,E0=(r,e,t)=>r<<t-32|e>>>64-t;function v0(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var B0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),A0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,S0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),I0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,R0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),k0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var T0={fromBig:Fc,split:c0,toBig:u0,shrSH:l0,shrSL:f0,rotrSH:h0,rotrSL:d0,rotrBH:p0,rotrBL:g0,rotr32H:m0,rotr32L:y0,rotlSH:w0,rotlSL:b0,rotlBH:x0,rotlBL:E0,add:v0,add3L:B0,add3H:A0,add4L:S0,add4H:I0,add5H:k0,add5L:R0},q=T0;var[N0,C0]=q.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),$t=new Uint32Array(80),qt=new Uint32Array(80),Es=class extends Dr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:E,Gl:g,Hh:h,Hl:p}=this;return[e,t,n,o,i,s,a,c,f,u,l,d,E,g,h,p]}set(e,t,n,o,i,s,a,c,f,u,l,d,E,g,h,p){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=h|0,this.Hl=p|0}process(e,t){for(let v=0;v<16;v++,t+=4)$t[v]=e.getUint32(t),qt[v]=e.getUint32(t+=4);for(let v=16;v<80;v++){let L=$t[v-15]|0,S=qt[v-15]|0,k=q.rotrSH(L,S,1)^q.rotrSH(L,S,8)^q.shrSH(L,S,7),C=q.rotrSL(L,S,1)^q.rotrSL(L,S,8)^q.shrSL(L,S,7),y=$t[v-2]|0,N=qt[v-2]|0,D=q.rotrSH(y,N,19)^q.rotrBH(y,N,61)^q.shrSH(y,N,6),T=q.rotrSL(y,N,19)^q.rotrBL(y,N,61)^q.shrSL(y,N,6),P=q.add4L(C,T,qt[v-7],qt[v-16]),H=q.add4H(P,k,D,$t[v-7],$t[v-16]);$t[v]=H|0,qt[v]=P|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:E,Fl:g,Gh:h,Gl:p,Hh:b,Hl:R}=this;for(let v=0;v<80;v++){let L=q.rotrSH(l,d,14)^q.rotrSH(l,d,18)^q.rotrBH(l,d,41),S=q.rotrSL(l,d,14)^q.rotrSL(l,d,18)^q.rotrBL(l,d,41),k=l&E^~l&h,C=d&g^~d&p,y=q.add5L(R,S,C,C0[v],qt[v]),N=q.add5H(y,b,L,k,N0[v],$t[v]),D=y|0,T=q.rotrSH(n,o,28)^q.rotrBH(n,o,34)^q.rotrBH(n,o,39),P=q.rotrSL(n,o,28)^q.rotrBL(n,o,34)^q.rotrBL(n,o,39),H=n&i^n&a^i&a,J=o&s^o&c^s&c;b=h|0,R=p|0,h=E|0,p=g|0,E=l|0,g=d|0,{h:l,l:d}=q.add(f|0,u|0,N|0,D|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let x=q.add3L(D,P,J);n=q.add3H(x,N,T,H),o=x|0}({h:n,l:o}=q.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=q.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=q.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=q.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=q.add(this.Eh|0,this.El|0,l|0,d|0),{h:E,l:g}=q.add(this.Fh|0,this.Fl|0,E|0,g|0),{h,l:p}=q.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:b,l:R}=q.add(this.Hh|0,this.Hl|0,b|0,R|0),this.set(n,o,i,s,a,c,f,u,l,d,E,g,h,p,b,R)}roundClean(){$t.fill(0),qt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Or=oo(()=>new Es);var ao={};me(ao,{bitGet:()=>P0,bitLen:()=>O0,bitMask:()=>hn,bitSet:()=>F0,bytesToHex:()=>Et,bytesToNumberBE:()=>vt,bytesToNumberLE:()=>zt,concatBytes:()=>Bt,createHmacDrbg:()=>As,ensureBytes:()=>ue,equalBytes:()=>V0,hexToBytes:()=>ar,hexToNumber:()=>Bs,isBytes:()=>Qe,numberToBytesBE:()=>Gt,numberToBytesLE:()=>cr,numberToHexUnpadded:()=>$c,numberToVarBytesBE:()=>L0,utf8ToBytes:()=>D0,validateObject:()=>ft});var Kc=BigInt(0),so=BigInt(1),_0=BigInt(2);function Qe(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var U0=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Et(r){if(!Qe(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=U0[r[t]];return e}function $c(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Bs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var xt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Mc(r){if(r>=xt._0&&r<=xt._9)return r-xt._0;if(r>=xt._A&&r<=xt._F)return r-(xt._A-10);if(r>=xt._a&&r<=xt._f)return r-(xt._a-10)}function ar(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=Mc(r.charCodeAt(i)),a=Mc(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function vt(r){return Bs(Et(r))}function zt(r){if(!Qe(r))throw new Error("Uint8Array expected");return Bs(Et(Uint8Array.from(r).reverse()))}function Gt(r,e){return ar(r.toString(16).padStart(e*2,"0"))}function cr(r,e){return Gt(r,e).reverse()}function L0(r){return ar($c(r))}function ue(r,e,t){let n;if(typeof e=="string")try{n=ar(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Qe(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function Bt(...r){let e=0;for(let o=0;o<r.length;o++){let i=r[o];if(!Qe(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e),n=0;for(let o=0;o<r.length;o++){let i=r[o];t.set(i,n),n+=i.length}return t}function V0(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function D0(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function O0(r){let e;for(e=0;r>Kc;r>>=so,e+=1);return e}function P0(r,e){return r>>BigInt(e)&so}var F0=(r,e,t)=>r|(t?so:Kc)<<BigInt(e),hn=r=>(_0<<BigInt(r-1))-so,vs=r=>new Uint8Array(r),Hc=r=>Uint8Array.from(r);function As(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=vs(r),o=vs(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>t(o,n,...l),c=(l=vs())=>{o=a(Hc([0]),l),n=a(),l.length!==0&&(o=a(Hc([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<e;){n=a();let E=n.slice();d.push(E),l+=n.length}return Bt(...d)};return(l,d)=>{s(),c(l);let E;for(;!(E=d(f()));)c();return s(),E}}var M0={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Qe(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function ft(r,e,t={}){let n=(o,i,s)=>{let a=M0[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${i}`)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}var ge=BigInt(0),oe=BigInt(1),ur=BigInt(2),H0=BigInt(3),Ss=BigInt(4),qc=BigInt(5),zc=BigInt(8),K0=BigInt(9),$0=BigInt(16);function re(r,e){let t=r%e;return t>=ge?t:e+t}function q0(r,e,t){if(t<=ge||e<ge)throw new Error("Expected power/modulo > 0");if(t===oe)return ge;let n=oe;for(;e>ge;)e&oe&&(n=n*r%t),r=r*r%t,e>>=oe;return n}function ie(r,e,t){let n=r;for(;e-- >ge;)n*=n,n%=t;return n}function co(r,e){if(r===ge||e<=ge)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=re(r,e),n=e,o=ge,i=oe,s=oe,a=ge;for(;t!==ge;){let f=n/t,u=n%t,l=o-s*f,d=i-a*f;n=t,t=u,o=s,i=a,s=l,a=d}if(n!==oe)throw new Error("invert: does not exist");return re(o,e)}function z0(r){let e=(r-oe)/ur,t,n,o;for(t=r-oe,n=0;t%ur===ge;t/=ur,n++);for(o=ur;o<r&&q0(o,e,r)!==r-oe;o++);if(n===1){let s=(r+oe)/Ss;return function(c,f){let u=c.pow(f,s);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+oe)/ur;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),t),l=a.pow(c,i),d=a.pow(c,t);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let E=1;for(let h=a.sqr(d);E<f&&!a.eql(h,a.ONE);E++)h=a.sqr(h);let g=a.pow(u,oe<<BigInt(f-E-1));u=a.sqr(g),l=a.mul(l,g),d=a.mul(d,u),f=E}return l}}function G0(r){if(r%Ss===H0){let e=(r+oe)/Ss;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%zc===qc){let e=(r-qc)/zc;return function(n,o){let i=n.mul(o,ur),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,ur),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%$0,z0(r)}var Gc=(r,e)=>(re(r,e)&oe)===oe,j0=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Is(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=j0.reduce((n,o)=>(n[o]="function",n),e);return ft(r,t)}function Y0(r,e,t){if(t<ge)throw new Error("Expected power > 0");if(t===ge)return r.ONE;if(t===oe)return e;let n=r.ONE,o=e;for(;t>ge;)t&oe&&(n=r.mul(n,o)),o=r.sqr(o),t>>=oe;return n}function Z0(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function Rs(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function uo(r,e,t=!1,n={}){if(r<=ge)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Rs(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=G0(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:hn(o),ZERO:ge,ONE:oe,create:c=>re(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ge<=c&&c<r},is0:c=>c===ge,isOdd:c=>(c&oe)===oe,neg:c=>re(-c,r),eql:(c,f)=>c===f,sqr:c=>re(c*c,r),add:(c,f)=>re(c+f,r),sub:(c,f)=>re(c-f,r),mul:(c,f)=>re(c*f,r),pow:(c,f)=>Y0(a,c,f),div:(c,f)=>re(c*co(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>co(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>Z0(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?cr(c,i):Gt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?zt(c):vt(c)}});return Object.freeze(a)}function jc(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function Yc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function ks(r){let e=Yc(r);return e+Math.ceil(e/2)}function Zc(r,e,t=!1){let n=r.length,o=Yc(e),i=ks(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=t?vt(r):zt(r),a=re(s,e-oe)+oe;return t?cr(a,o):Gt(a,o)}var J0=BigInt(0),Ts=BigInt(1);function lo(r,e){let t=(o,i)=>{let s=i.negate();return o?s:i},n=o=>{let i=Math.ceil(e/o)+1,s=2**(o-1);return{windows:i,windowSize:s}};return{constTimeNegate:t,unsafeLadder(o,i){let s=r.ZERO,a=o;for(;i>J0;)i&Ts&&(s=s.add(a)),a=a.double(),i>>=Ts;return s},precomputeWindow(o,i){let{windows:s,windowSize:a}=n(i),c=[],f=o,u=f;for(let l=0;l<s;l++){u=f,c.push(u);for(let d=1;d<a;d++)u=u.add(f),c.push(u);f=u.double()}return c},wNAF(o,i,s){let{windows:a,windowSize:c}=n(o),f=r.ZERO,u=r.BASE,l=BigInt(2**o-1),d=2**o,E=BigInt(o);for(let g=0;g<a;g++){let h=g*c,p=Number(s&l);s>>=E,p>c&&(p-=d,s+=Ts);let b=h,R=h+Math.abs(p)-1,v=g%2!==0,L=p<0;p===0?u=u.add(t(v,i[b])):f=f.add(t(L,i[R]))}return{p:f,f:u}},wNAFCached(o,i,s,a){let c=o._WINDOW_SIZE||1,f=i.get(o);return f||(f=this.precomputeWindow(o,c),c!==1&&i.set(o,a(f))),this.wNAF(c,f,s)}}}function dn(r){return Is(r.Fp),ft(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Rs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var et=BigInt(0),Fe=BigInt(1),fo=BigInt(2),X0=BigInt(8),Q0={zip215:!0};function ep(r){let e=dn(r);return ft(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function ho(r){let e=ep(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=fo<<BigInt(a*8)-Fe,u=t.create,l=e.uvRatio||((B,w)=>{try{return{isValid:!0,value:t.sqrt(B*t.inv(w))}}catch{return{isValid:!1,value:et}}}),d=e.adjustScalarBytes||(B=>B),E=e.domain||((B,w,V)=>{if(w.length||V)throw new Error("Contexts/pre-hash are not supported");return B}),g=B=>typeof B=="bigint"&&et<B,h=(B,w)=>g(B)&&g(w)&&B<w,p=B=>B===et||h(B,f);function b(B,w){if(h(B,w))return B;throw new Error(`Expected valid scalar < ${w}, got ${typeof B} ${B}`)}function R(B){return B===et?B:b(B,n)}let v=new Map;function L(B){if(!(B instanceof S))throw new Error("ExtendedPoint expected")}class S{constructor(w,V,F,$){if(this.ex=w,this.ey=V,this.ez=F,this.et=$,!p(w))throw new Error("x required");if(!p(V))throw new Error("y required");if(!p(F))throw new Error("z required");if(!p($))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof S)throw new Error("extended point not allowed");let{x:V,y:F}=w||{};if(!p(V)||!p(F))throw new Error("invalid affine point");return new S(V,F,Fe,u(V*F))}static normalizeZ(w){let V=t.invertBatch(w.map(F=>F.ez));return w.map((F,$)=>F.toAffine(V[$])).map(S.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,v.delete(this)}assertValidity(){let{a:w,d:V}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:F,ey:$,ez:z,et:G}=this,te=u(F*F),Z=u($*$),X=u(z*z),he=u(X*X),se=u(te*w),be=u(X*u(se+Z)),xe=u(he+u(V*u(te*Z)));if(be!==xe)throw new Error("bad point: equation left != right (1)");let pe=u(F*$),Ae=u(z*G);if(pe!==Ae)throw new Error("bad point: equation left != right (2)")}equals(w){L(w);let{ex:V,ey:F,ez:$}=this,{ex:z,ey:G,ez:te}=w,Z=u(V*te),X=u(z*$),he=u(F*te),se=u(G*$);return Z===X&&he===se}is0(){return this.equals(S.ZERO)}negate(){return new S(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:w}=e,{ex:V,ey:F,ez:$}=this,z=u(V*V),G=u(F*F),te=u(fo*u($*$)),Z=u(w*z),X=V+F,he=u(u(X*X)-z-G),se=Z+G,be=se-te,xe=Z-G,pe=u(he*be),Ae=u(se*xe),wt=u(he*xe),rr=u(be*se);return new S(pe,Ae,rr,wt)}add(w){L(w);let{a:V,d:F}=e,{ex:$,ey:z,ez:G,et:te}=this,{ex:Z,ey:X,ez:he,et:se}=w;if(V===BigInt(-1)){let Na=u((z-$)*(X+Z)),Ca=u((z+$)*(X-Z)),Ti=u(Ca-Na);if(Ti===et)return this.double();let _a=u(G*fo*se),Ua=u(te*fo*he),La=Ua+_a,Va=Ca+Na,Da=Ua-_a,rh=u(La*Ti),nh=u(Va*Da),oh=u(La*Da),ih=u(Ti*Va);return new S(rh,nh,ih,oh)}let be=u($*Z),xe=u(z*X),pe=u(te*F*se),Ae=u(G*he),wt=u(($+z)*(Z+X)-be-xe),rr=Ae-pe,nn=Ae+pe,Ta=u(xe-V*be),Xf=u(wt*rr),Qf=u(nn*Ta),eh=u(wt*Ta),th=u(rr*nn);return new S(Xf,Qf,th,eh)}subtract(w){return this.add(w.negate())}wNAF(w){return y.wNAFCached(this,v,w,S.normalizeZ)}multiply(w){let{p:V,f:F}=this.wNAF(b(w,n));return S.normalizeZ([V,F])[0]}multiplyUnsafe(w){let V=R(w);return V===et?C:this.equals(C)||V===Fe?this:this.equals(k)?this.wNAF(V).p:y.unsafeLadder(this,V)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return y.unsafeLadder(this,n).is0()}toAffine(w){let{ex:V,ey:F,ez:$}=this,z=this.is0();w==null&&(w=z?X0:t.inv($));let G=u(V*w),te=u(F*w),Z=u($*w);if(z)return{x:et,y:Fe};if(Z!==Fe)throw new Error("invZ was invalid");return{x:G,y:te}}clearCofactor(){let{h:w}=e;return w===Fe?this:this.multiplyUnsafe(w)}static fromHex(w,V=!1){let{d:F,a:$}=e,z=t.BYTES;w=ue("pointHex",w,z);let G=w.slice(),te=w[z-1];G[z-1]=te&-129;let Z=zt(G);Z===et||(V?b(Z,f):b(Z,t.ORDER));let X=u(Z*Z),he=u(X-Fe),se=u(F*X-$),{isValid:be,value:xe}=l(he,se);if(!be)throw new Error("Point.fromHex: invalid y coordinate");let pe=(xe&Fe)===Fe,Ae=(te&128)!==0;if(!V&&xe===et&&Ae)throw new Error("Point.fromHex: x=0 and x_0=1");return Ae!==pe&&(xe=u(-xe)),S.fromAffine({x:xe,y:Z})}static fromPrivateKey(w){return T(w).point}toRawBytes(){let{x:w,y:V}=this.toAffine(),F=cr(V,t.BYTES);return F[F.length-1]|=w&Fe?128:0,F}toHex(){return Et(this.toRawBytes())}}S.BASE=new S(e.Gx,e.Gy,Fe,u(e.Gx*e.Gy)),S.ZERO=new S(et,Fe,Fe,et);let{BASE:k,ZERO:C}=S,y=lo(S,a*8);function N(B){return re(B,n)}function D(B){return N(zt(B))}function T(B){let w=a;B=ue("private key",B,w);let V=ue("hashed private key",i(B),2*w),F=d(V.slice(0,w)),$=V.slice(w,2*w),z=D(F),G=k.multiply(z),te=G.toRawBytes();return{head:F,prefix:$,scalar:z,point:G,pointBytes:te}}function P(B){return T(B).pointBytes}function H(B=new Uint8Array,...w){let V=Bt(...w);return D(i(E(V,ue("context",B),!!o)))}function J(B,w,V={}){B=ue("message",B),o&&(B=o(B));let{prefix:F,scalar:$,pointBytes:z}=T(w),G=H(V.context,F,B),te=k.multiply(G).toRawBytes(),Z=H(V.context,te,z,B),X=N(G+Z*$);R(X);let he=Bt(te,cr(X,t.BYTES));return ue("result",he,a*2)}let x=Q0;function A(B,w,V,F=x){let{context:$,zip215:z}=F,G=t.BYTES;B=ue("signature",B,2*G),w=ue("message",w),o&&(w=o(w));let te=zt(B.slice(G,2*G)),Z,X,he;try{Z=S.fromHex(V,z),X=S.fromHex(B.slice(0,G),z),he=k.multiplyUnsafe(te)}catch{return!1}if(!z&&Z.isSmallOrder())return!1;let se=H($,X.toRawBytes(),Z.toRawBytes(),w);return X.add(Z.multiplyUnsafe(se)).subtract(he).clearCofactor().equals(S.ZERO)}return k._setWindowSize(8),{CURVE:e,getPublicKey:P,sign:J,verify:A,ExtendedPoint:S,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>s(t.BYTES),precompute(B=8,w=S.BASE){return w._setWindowSize(B),w.multiply(BigInt(3)),w}}}}var Cs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Wc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),vb=BigInt(0),tp=BigInt(1),Ns=BigInt(2),rp=BigInt(5),Jc=BigInt(10),np=BigInt(20),op=BigInt(40),Xc=BigInt(80);function ip(r){let e=Cs,n=r*r%e*r%e,o=ie(n,Ns,e)*n%e,i=ie(o,tp,e)*r%e,s=ie(i,rp,e)*i%e,a=ie(s,Jc,e)*s%e,c=ie(a,np,e)*a%e,f=ie(c,op,e)*c%e,u=ie(f,Xc,e)*f%e,l=ie(u,Xc,e)*f%e,d=ie(l,Jc,e)*s%e;return{pow_p_5_8:ie(d,Ns,e)*r%e,b2:n}}function sp(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function ap(r,e){let t=Cs,n=re(e*e*e,t),o=re(n*n*e,t),i=ip(r*o).pow_p_5_8,s=re(r*n*i,t),a=re(e*s*s,t),c=s,f=re(s*Wc,t),u=a===r,l=a===re(-r,t),d=a===re(-r*Wc,t);return u&&(s=c),(l||d)&&(s=f),Gc(s,t)&&(s=re(-s,t)),{isValid:u||l,value:s}}var At=uo(Cs,void 0,!0),_s={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:At,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Or,randomBytes:Vr,adjustScalarBytes:sp,uvRatio:ap},Pr=ho(_s);function Qc(r,e,t){if(e.length>255)throw new Error("Context is too big");return no(bs("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var Bb=ho({..._s,domain:Qc}),Ab=ho({..._s,domain:Qc,prehash:Or});var cp=(At.ORDER+BigInt(3))/BigInt(8),Sb=At.pow(Ns,cp),Ib=At.sqrt(At.neg(At.ONE)),Rb=(At.ORDER-BigInt(5))/BigInt(8),kb=BigInt(486662);var Tb=jc(At,At.neg(BigInt(486664)));var Nb=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Cb=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),_b=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ub=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Lb=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Fr=32,St=64,po=32;function eu(){let r=Pr.utils.randomPrivateKey(),e=Pr.getPublicKey(r);return{privateKey:ou(r,e),publicKey:e}}function tu(r){if(r.length!==po)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=Pr.getPublicKey(e);return{privateKey:ou(e,t),publicKey:t}}function ru(r,e){let t=r.subarray(0,po);return Pr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function nu(r,e,t){return Pr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function ou(r,e){let t=new Uint8Array(St);for(let n=0;n<po;n++)t[n]=r[n],t[po+n]=e[n];return t}var Ce={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Us={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function iu(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",i=r?.saltLength??16,s=r?.iterations??32767,a=Ce.get();t*=8;async function c(l,d){let E=a.getRandomValues(new Uint8Array(i)),g=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:g};typeof d=="string"&&(d=j(d));let p;if(d.length===0){p=await a.subtle.importKey("jwk",Us,{name:"AES-GCM"},!0,["encrypt"]);try{let R={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},v=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(R,v,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",Us,{name:"AES-GCM"},!0,["encrypt"])}}else{let R={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},v=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(R,v,{name:e,length:t},!0,["encrypt"])}let b=await a.subtle.encrypt(h,p,l);return Ne([E,h.iv,new Uint8Array(b)])}async function f(l,d){let E=l.subarray(0,i),g=l.subarray(i,i+n),h=l.subarray(i+n),p={name:e,iv:g};typeof d=="string"&&(d=j(d));let b;if(d.length===0)try{let v={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},L=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(v,L,{name:e,length:t},!0,["decrypt"])}catch{b=await a.subtle.importKey("jwk",Us,{name:"AES-GCM"},!0,["decrypt"])}else{let v={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},L=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(v,L,{name:e,length:t},!0,["decrypt"])}let R=await a.subtle.decrypt(p,b,h);return new Uint8Array(R)}return{encrypt:c,decrypt:f}}async function Mr(r,e){let n=await iu().encrypt(r,e);return on.encode(n)}var Ls=new Float32Array([-0]),jt=new Uint8Array(Ls.buffer);function su(r,e,t){Ls[0]=r,e[t]=jt[0],e[t+1]=jt[1],e[t+2]=jt[2],e[t+3]=jt[3]}function au(r,e){return jt[0]=r[e],jt[1]=r[e+1],jt[2]=r[e+2],jt[3]=r[e+3],Ls[0]}var Vs=new Float64Array([-0]),Ie=new Uint8Array(Vs.buffer);function cu(r,e,t){Vs[0]=r,e[t]=Ie[0],e[t+1]=Ie[1],e[t+2]=Ie[2],e[t+3]=Ie[3],e[t+4]=Ie[4],e[t+5]=Ie[5],e[t+6]=Ie[6],e[t+7]=Ie[7]}function uu(r,e){return Ie[0]=r[e],Ie[1]=r[e+1],Ie[2]=r[e+2],Ie[3]=r[e+3],Ie[4]=r[e+4],Ie[5]=r[e+5],Ie[6]=r[e+6],Ie[7]=r[e+7],Vs[0]}var fp=BigInt(Number.MAX_SAFE_INTEGER),hp=BigInt(Number.MIN_SAFE_INTEGER),Le=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return lr;if(e<fp&&e>hp)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>lu&&(o=0n,++n>lu&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return lr;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):lr}},lr=new Le(0,0);lr.toBigInt=function(){return 0n};lr.zzEncode=lr.zzDecode=function(){return this};lr.length=function(){return 1};var lu=4294967296n;function fu(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function hu(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ds(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function tt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function go(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Os=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,tt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw tt(this,4);return go(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw tt(this,4);return go(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw tt(this,4);let e=au(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw tt(this,4);let e=uu(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw tt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return hu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw tt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw tt(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw tt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw tt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw tt(this,8);let e=go(this.buf,this.pos+=4),t=go(this.buf,this.pos+=4);return new Le(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 Ps(r){return new Os(r instanceof Uint8Array?r:r.subarray())}function Hr(r,e){let t=Ps(r);return e.decode(t)}function Fs(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return Je(s);o+s>e&&(n=Je(e),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var fr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Ms(){}var Ks=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},dp=Fs();function pp(r){return globalThis.Buffer!=null?Je(r):dp(r)}var mn=class{len;head;tail;states;constructor(){this.len=0,this.head=new fr(Ms,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new fr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new $s((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(pn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Le.fromBigInt(e);return this._push(pn,t.length(),t)}uint64Number(e){let t=Le.fromNumber(e);return this._push(pn,t.length(),t)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Le.fromBigInt(e).zzEncode();return this._push(pn,t.length(),t)}sint64Number(e){let t=Le.fromNumber(e).zzEncode();return this._push(pn,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Hs,1,e?1:0)}fixed32(e){return this._push(gn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Le.fromBigInt(e);return this._push(gn,4,t.lo)._push(gn,4,t.hi)}fixed64Number(e){let t=Le.fromNumber(e);return this._push(gn,4,t.lo)._push(gn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(su,4,e)}double(e){return this._push(cu,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Hs,1,0):this.uint32(t)._push(mp,t,e)}string(e){let t=fu(e);return t!==0?this.uint32(t)._push(Ds,t,e):this._push(Hs,1,0)}fork(){return this.states=new Ks(this),this.head=this.tail=new fr(Ms,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 fr(Ms,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=pp(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Hs(r,e,t){e[t]=r&255}function gp(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var $s=class extends fr{next;constructor(e,t){super(gp,e,t),this.next=void 0}};function pn(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function gn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function mp(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(mn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(yp,e,r),this},mn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(wp,e,r),this});function yp(r,e,t){e.set(r,t)}function wp(r,e,t){r.length<40?Ds(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(j(r),t)}function qs(){return new mn}function Kr(r,e){let t=qs();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var $r;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})($r||($r={}));function mo(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function yn(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return mo("enum",$r.VARINT,t,n)}function qr(r,e){return mo("message",$r.LENGTH_DELIMITED,r,e)}var fe;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(fe||(fe={}));var zs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(zs||(zs={}));(function(r){r.codec=()=>yn(zs)})(fe||(fe={}));var ht;(function(r){let e;r.codec=()=>(e==null&&(e=qr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),fe.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=fe.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>Kr(t,r.codec()),r.decode=t=>Hr(t,r.codec())})(ht||(ht={}));var It;(function(r){let e;r.codec=()=>(e==null&&(e=qr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),fe.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=fe.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>Kr(t,r.codec()),r.decode=t=>Hr(t,r.codec())})(It||(It={}));var wn=class{_key;constructor(e){this._key=zr(e,Fr)}verify(e,t){return nu(this._key,t,e)}marshal(){return this._key}get bytes(){return ht.encode({Type:fe.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return ze(e)?e.then(({bytes:t})=>t):e.bytes}},hr=class{_key;_publicKey;constructor(e,t){this._key=zr(e,St),this._publicKey=zr(t,Fr)}sign(e){return ru(this._key,e)}get public(){return new wn(this._publicKey)}marshal(){return this._key}get bytes(){return It.encode({Type:fe.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=Ee.digest(this.bytes),t;return ze(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=ut.digest(this.public.bytes);return le.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Mr(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function bp(r){if(r.length>St){r=zr(r,St+Fr);let n=r.subarray(0,St),o=r.subarray(St,r.length);return new hr(n,o)}r=zr(r,St);let e=r.subarray(0,St),t=r.subarray(Fr);return new hr(e,t)}function xp(r){return r=zr(r,Fr),new wn(r)}async function Ep(){let{privateKey:r,publicKey:e}=eu();return new hr(r,e)}async function pu(r){let{privateKey:e,publicKey:t}=tu(r);return new hr(e,t)}function zr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new O(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var ra={};me(ra,{MAX_RSA_KEY_SIZE:()=>Nn,RsaPrivateKey:()=>Wr,RsaPublicKey:()=>Tn,fromJwk:()=>Yp,generateKeyPair:()=>Zp,unmarshalRsaPrivateKey:()=>ea,unmarshalRsaPublicKey:()=>jp});function dr(r){if(isNaN(r)||r<=0)throw new O("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Vr(r)}var Jt={};me(Jt,{exportToPem:()=>Kp,importFromPem:()=>$p,jwkToPkcs1:()=>Pp,jwkToPkix:()=>Mp,pkcs1ToJwk:()=>Op,pkixToJwk:()=>Fp});var wo=class extends Ur{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,to(e);let n=Kt(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return _r(this),this.iHash.update(e),this}digestInto(e){_r(this),ws(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},bn=(r,e,t)=>new wo(r,e).update(t).digest();bn.create=(r,e)=>new wo(r,e);function vp(r,e,t,n){to(r);let o=Pc({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(Cr(i),Cr(s),Cr(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Kt(e),f=Kt(t),u=new Uint8Array(s),l=bn.create(r,c),d=l._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:a,DK:u,PRF:l,PRFSalt:d}}function Bp(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function js(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:f}=vp(r,e,t,n),u,l=new Uint8Array(4),d=Lr(l),E=new Uint8Array(c.outputLen);for(let g=1,h=0;h<i;g++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);d.setInt32(0,g,!1),(u=f._cloneInto(u)).update(l).digestInto(E),p.set(E.subarray(0,p.length)),await Oc(o-1,s,()=>{c._cloneInto(u).update(E).digestInto(E);for(let b=0;b<p.length;b++)p[b]^=E[b]})}return Bp(c,f,a,u,E)}var Y=Dt(gu());function pr(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Yt(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(o/l),o-=f[i-u-1]*l}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Eo(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Zs(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=pr(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,pr(i,8)-n}function mu(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=Yt(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=Yt(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function yu(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Ve(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var Ox=Math.log(2);function vo(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ws(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function Ct(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var En=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Ws(this.items)}},xn=[new Uint8Array([1])],wu="0123456789";var Yr="",nt=new ArrayBuffer(0),Js=new Uint8Array(0),vn="EndOfContent",xu="OCTET STRING",Eu="BIT STRING";function _t(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?Y.BufferSourceConverter.toUint8Array(i.valueHex):Js}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ct(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",nt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:Y.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var kt=class{constructor({blockLength:e=0,error:t=Yr,warnings:n=[],valueBeforeDecode:o=Js}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=Y.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:Y.Convert.ToHex(this.valueBeforeDecodeView)}}};kt.NAME="baseBlock";var Re=class extends kt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Re.NAME="valueBlock";var Bo=class extends _t(kt){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?Y.BufferSourceConverter.toUint8Array(e.valueHex):Js,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",nt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=Yt(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);if(!Ct(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let d=new Uint8Array(u);for(let E=0;E<f.length;E++)d[E]=f[E];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let d=0;d<c;d++)l[d]=f[d];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=pr(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Bo.NAME="identificationBlock";var Ao=class extends kt{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);if(!Ct(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=pr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=Yt(this.length,8);if(o.byteLength>127)return this.error="Too big length",nt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Ao.NAME="lengthBlock";var _={},ve=class extends kt{constructor({name:e=Yr,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Bo(o),this.lenBlock=new Ao(o),this.valueBlock=i?new i(o):new Re(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new En;t||vu(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?nt:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():Y.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${Y.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return yu(t,n)}};ve.NAME="BaseBlock";function vu(r){if(r instanceof _.Constructed)for(let e of r.valueBlock.value)vu(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var So=class extends ve{constructor({value:e=Yr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};So.NAME="BaseStringBlock";var Io=class extends _t(Re){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Io.NAME="PrimitiveValueBlock";var Bu,Ro=class extends ve{constructor(e={}){super(e,Io),this.idBlock.isConstructed=!1}};Bu=Ro;_.Primitive=Bu;Ro.NAME="PRIMITIVE";function _p(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function si(r,e=0,t=r.length){let n=e,o=new ve({},Re),i=new kt;if(!Ct(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=ve;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=_.EndOfContent;break;case 1:c=_.Boolean;break;case 2:c=_.Integer;break;case 3:c=_.BitString;break;case 4:c=_.OctetString;break;case 5:c=_.Null;break;case 6:c=_.ObjectIdentifier;break;case 10:c=_.Enumerated;break;case 12:c=_.Utf8String;break;case 13:c=_.RelativeObjectIdentifier;break;case 14:c=_.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=_.Sequence;break;case 17:c=_.Set;break;case 18:c=_.NumericString;break;case 19:c=_.PrintableString;break;case 20:c=_.TeletexString;break;case 21:c=_.VideotexString;break;case 22:c=_.IA5String;break;case 23:c=_.UTCTime;break;case 24:c=_.GeneralizedTime;break;case 25:c=_.GraphicString;break;case 26:c=_.VisibleString;break;case 27:c=_.GeneralString;break;case 28:c=_.UniversalString;break;case 29:c=_.CharacterString;break;case 30:c=_.BmpString;break;case 31:c=_.DATE;break;case 32:c=_.TimeOfDay;break;case 33:c=_.DateTime;break;case 34:c=_.Duration;break;default:{let f=o.idBlock.isConstructed?new _.Constructed:new _.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?_.Constructed:_.Primitive}return o=_p(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function Zr(r){if(!r.byteLength){let e=new ve({},Re);return e.error="Input buffer has zero length",{offset:-1,result:e}}return si(Y.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Up(r,e){return r?1:e}var dt=class extends Re{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);if(!Ct(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;Up(this.isIndefiniteForm,n)>0;){let s=si(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===vn)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===vn?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new En;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?nt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};dt.NAME="ConstructedValueBlock";var Au,Zt=class extends ve{constructor(e={}){super(e,dt),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
4
4
|
`).map(o=>` ${o}`).join(`
|
|
5
5
|
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
6
6
|
${e.join(`
|
|
7
|
-
`)}`:`${t} :`}};Su=Zt;_.Constructed=Su;Zt.NAME="CONSTRUCTED";var Ro=class extends Re{fromBER(e,t,n){return t}toBER(e){return rt}};Ro.override="EndOfContentValueBlock";var Iu,ko=class extends ve{constructor(e={}){super(e,Ro),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Iu=ko;_.EndOfContent=Iu;ko.NAME=En;var Ru,Wt=class extends ve{constructor(e={}){super(e,Re),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ru=Wt;_.Null=Ru;Wt.NAME="NULL";var To=class extends _t(Re){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=Y.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);return Nt(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Ys.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};To.NAME="BooleanValueBlock";var ku,Co=class extends ve{constructor(e={}){super(e,To),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};ku=Co;_.Boolean=ku;Co.NAME="BOOLEAN";var No=class extends _t(ht){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=ht.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===En){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Eu)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?ht.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};No.NAME="OctetStringValueBlock";var Tu,Tt=class r extends ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},No),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=ii(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Zt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${Y.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return Y.BufferSourceConverter.concat(e)}};Tu=Tt;_.OctetString=Tu;Tt.NAME=Eu;var _o=class extends _t(ht){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=ht.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===En){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==vu)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=Y.BufferSourceConverter.toUint8Array(e);if(!Nt(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=ii(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return ht.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return rt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};_o.NAME="BitStringValueBlock";var Cu,Yr=class extends ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},_o),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Zt.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Cu=Yr;_.BitString=Cu;Yr.NAME=vu;var Nu;function Vp(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,u=c<s?s:c,l=0;for(let d=u;d>=0;d--,l++){switch(!0){case l<a.length:f=i[s-l]+a[c-l]+t[0];break;default:f=i[s-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=xo(new Uint8Array([f%10]),i);break;default:i[s-l]=f%10}}return t[0]>0&&(i=xo(t,i)),i}function xu(r){if(r>=bn.length)for(let e=bn.length;e<=r;e++){let t=new Uint8Array([0]),n=bn[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=xo(t,n)),bn.push(n)}return bn[r]}function Op(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[s-u]-a[c-u]-t,!0){case f<0:t=1,i[s-u]=f+10;break;default:t=0,i[s-u]=f}if(t>0)for(let l=s-c+1;l>=0;l--,u++)if(f=i[s-u]-t,f<0)t=1,i[s-u]=f+10;else{t=0,i[s-u]=f;break}return i.slice()}var vn=class extends _t(Re){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Ys.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(yu(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=Op(xu(n),t),s="-";break;default:t=Vp(t,xu(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=bu.charAt(t[c]));return a===!1&&(s+=bu.charAt(0)),s}};Nu=vn;vn.NAME="IntegerValueBlock";Object.defineProperty(Nu.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var _u,de=class r extends ve{constructor(e={}){super(e,vn),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Eo(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Eo();let t=BigInt(e),n=new xn,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(Y.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${Y.Convert.ToHex(a)}`)+t,u=Y.BufferSourceConverter.toUint8Array(Y.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};_u=de;_.Integer=_u;de.NAME="INTEGER";var Uu,Uo=class extends de{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Uu=Uo;_.Enumerated=Uu;Uo.NAME="ENUMERATED";var Bn=class extends _t(Re){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=Y.BufferSourceConverter.toUint8Array(e);if(!Nt(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=gr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Eo();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Yt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",rt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=Y.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Bn.NAME="sidBlock";var Lo=class extends Re{constructor({value:e=Zr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Bn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,rt;t.push(o)}return Zs(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new Bn;if(o>Number.MAX_SAFE_INTEGER){Eo();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Lo.NAME="ObjectIdentifierValueBlock";var Lu,tt=class extends ve{constructor(e={}){super(e,Lo),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Lu=tt;_.ObjectIdentifier=Lu;tt.NAME="OBJECT IDENTIFIER";var An=class extends _t(kt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=Y.BufferSourceConverter.toUint8Array(e);if(!Nt(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=gr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Yt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",rt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=Y.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};An.NAME="relativeSidBlock";var Do=class extends Re{constructor({value:e=Zr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new An;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,rt;n.push(i)}return Zs(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new An;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Do.NAME="RelativeObjectIdentifierValueBlock";var Du,Vo=class extends ve{constructor(e={}){super(e,Do),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Du=Vo;_.RelativeObjectIdentifier=Du;Vo.NAME="RelativeObjectIdentifier";var Vu,ye=class extends Zt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Vu=ye;_.Sequence=Vu;ye.NAME="SEQUENCE";var Ou,Oo=class extends Zt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ou=Oo;_.Set=Ou;Oo.NAME="SET";var Po=class extends _t(Re){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Zr}toJSON(){return{...super.toJSON(),value:this.value}}};Po.NAME="StringValueBlock";var Fo=class extends Po{};Fo.NAME="SimpleStringValueBlock";var _e=class extends Ao{constructor({...e}={}){super(e,Fo)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,Y.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};_e.NAME="SIMPLE STRING";var Mo=class extends _e{fromBuffer(e){this.valueBlock.valueHexView=Y.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=Y.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=Y.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(Y.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Mo.NAME="Utf8StringValueBlock";var Pu,Ct=class extends Mo{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Pu=Ct;_.Utf8String=Pu;Ct.NAME="UTF8String";var Ho=class extends _e{fromBuffer(e){this.valueBlock.value=Y.Convert.ToUtf16String(e),this.valueBlock.valueHexView=Y.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(Y.Convert.FromUtf16String(e))}};Ho.NAME="BmpStringValueBlock";var Fu,Ko=class extends Ho{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Fu=Ko;_.BmpString=Fu;Ko.NAME="BMPString";var $o=class extends _e{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=Yt(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};$o.NAME="UniversalStringValueBlock";var Mu,qo=class extends $o{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Mu=qo;_.UniversalString=Mu;qo.NAME="UniversalString";var Hu,zo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Hu=zo;_.NumericString=Hu;zo.NAME="NumericString";var Ku,Go=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ku=Go;_.PrintableString=Ku;Go.NAME="PrintableString";var $u,jo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};$u=jo;_.TeletexString=$u;jo.NAME="TeletexString";var qu,Yo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};qu=Yo;_.VideotexString=qu;Yo.NAME="VideotexString";var zu,Zo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};zu=Zo;_.IA5String=zu;Zo.NAME="IA5String";var Gu,Wo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Gu=Wo;_.GraphicString=Gu;Wo.NAME="GraphicString";var ju,Sn=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};ju=Sn;_.VisibleString=ju;Sn.NAME="VisibleString";var Yu,Jo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Yu=Jo;_.GeneralString=Yu;Jo.NAME="GeneralString";var Zu,Xo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Zu=Xo;_.CharacterString=Zu;Xo.NAME="CharacterString";var Wu,In=class extends Sn{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,Y.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=De(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=De(this.month,2),t[2]=De(this.day,2),t[3]=De(this.hour,2),t[4]=De(this.minute,2),t[5]=De(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Wu=In;_.UTCTime=Wu;In.NAME="UTCTime";var Ju,Qo=class extends In{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,d=n.indexOf("+"),E="";if(d===-1&&(d=n.indexOf("-"),l=-1),d!==-1){if(E=n.substring(d+1),n=n.substring(0,d),E.length!==2&&E.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(E.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*g,E.length===4){if(g=parseInt(E.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=l*g}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=s.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(De(this.year,4)),t.push(De(this.month,2)),t.push(De(this.day,2)),t.push(De(this.hour,2)),t.push(De(this.minute,2)),t.push(De(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(De(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Ju=Qo;_.GeneralizedTime=Ju;Qo.NAME="GeneralizedTime";var Xu,ei=class extends Ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Xu=ei;_.DATE=Xu;ei.NAME="DATE";var Qu,ti=class extends Ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Qu=ti;_.TimeOfDay=Qu;ti.NAME="TimeOfDay";var el,ri=class extends Ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};el=ri;_.DateTime=el;ri.NAME="DateTime";var tl,ni=class extends Ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};tl=ni;_.Duration=tl;ni.NAME="Duration";var rl,oi=class extends Ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};rl=oi;_.TIME=rl;oi.NAME="TIME";function Fp(r){let{result:e}=Wr(r),t=e.valueBlock.value;return{n:W(dt(t[1].toBigInt()),"base64url"),e:W(dt(t[2].toBigInt()),"base64url"),d:W(dt(t[3].toBigInt()),"base64url"),p:W(dt(t[4].toBigInt()),"base64url"),q:W(dt(t[5].toBigInt()),"base64url"),dp:W(dt(t[6].toBigInt()),"base64url"),dq:W(dt(t[7].toBigInt()),"base64url"),qi:W(dt(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Mp(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ye({value:[new de({value:0}),de.fromBigInt(pt(j(r.n,"base64url"))),de.fromBigInt(pt(j(r.e,"base64url"))),de.fromBigInt(pt(j(r.d,"base64url"))),de.fromBigInt(pt(j(r.p,"base64url"))),de.fromBigInt(pt(j(r.q,"base64url"))),de.fromBigInt(pt(j(r.dp,"base64url"))),de.fromBigInt(pt(j(r.dq,"base64url"))),de.fromBigInt(pt(j(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Hp(r){let{result:e}=Wr(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:W(dt(t[0].toBigInt()),"base64url"),e:W(dt(t[1].toBigInt()),"base64url")}}function Kp(r){if(r.n==null||r.e==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ye({value:[new ye({value:[new tt({value:"1.2.840.113549.1.1.1"}),new Wt]}),new Yr({valueHex:new ye({value:[de.fromBigInt(pt(j(r.n,"base64url"))),de.fromBigInt(pt(j(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function dt(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,i=0;for(;o<t;)n[o]=parseInt(e.slice(i,i+2),16),o+=1,i+=2;return n}function pt(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var $p=16,Js=32,Xs=1e4;async function qp(r,e){let t=Ne.get(),o=new ye({value:[new de({value:0}),new ye({value:[new tt({value:"1.2.840.113549.1.1.1"}),new Wt]}),new Tt({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(o,0,o.byteLength),s=pr($p),a=await Gs(Pr,e,s,{c:Xs,dkLen:Js}),c=pr(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new ye({value:[new Tt({valueHex:s}),new de({value:Xs}),new de({value:Js}),new ye({value:[new tt({value:"1.2.840.113549.2.11"}),new Wt]})]}),d=new ye({value:[new tt({value:"1.2.840.113549.1.5.13"}),new ye({value:[new ye({value:[new tt({value:"1.2.840.113549.1.5.12"}),l]}),new ye({value:[new tt({value:"2.16.840.1.101.3.4.1.42"}),new Tt({valueHex:c})]})]})]}),g=new ye({value:[d,new Tt({valueHex:u})]}).toBER(),h=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...W(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
-
`)}async function zp(r,e){let t=Ne.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Wr(o),{iv:s,salt:a,iterations:c,keySize:f,cipherText:u}=Gp(i),l=await Gs(Pr,e,a,{c,dkLen:f}),d=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),E=Rn(await t.subtle.decrypt({name:"AES-CBC",iv:s},d,u)),{result:g}=Wr(E);n=nl(g)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Wr(o);n=nl(i)}else throw new O("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Qs(n)}function Gp(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new O("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new O("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],s=Rn(i.valueBlock.value[0].getValue()),a=Xs,c=Js;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new O("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new O("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=Rn(f.valueBlock.value[1].getValue());return{cipherText:Rn(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:l}}function nl(r){return Rn(r.valueBlock.value[2].getValue())}function Rn(r){return new Uint8Array(r,0,r.byteLength)}async function ol(r){let e=await Ne.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await al(e);return{privateKey:t[0],publicKey:t[1]}}async function ea(r){let t=[await Ne.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await jp(r)],n=await al({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function il(r,e){let t=await Ne.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ne.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function sl(r,e,t){let n=await Ne.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ne.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function al(r){if(r.privateKey==null||r.publicKey==null)throw new O("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ne.get().subtle.exportKey("jwk",r.privateKey),Ne.get().subtle.exportKey("jwk",r.publicKey)])}async function jp(r){return Ne.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function si(r){if(r.kty!=="RSA")throw new O("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new O("invalid key modulus","ERR_INVALID_KEY_MODULUS");return j(r.n,"base64url").length*8}var Tn=8192,kn=class{_key;constructor(e){this._key=e}verify(e,t){return sl(this._key,t,e)}marshal(){return Jt.jwkToPkix(this._key)}get bytes(){return ft.encode({Type:fe.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return qe(e)?e.then(({bytes:t})=>t):e.bytes}},Jr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return pr(16)}sign(e){return il(this._key,e)}get public(){if(this._publicKey==null)throw new O("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new kn(this._publicKey)}marshal(){return Jt.jwkToPkcs1(this._key)}get bytes(){return It.encode({Type:fe.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return qe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Jt.exportToPem(this,e);if(t==="libp2p-key")return Hr(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Qs(r){let e=Jt.pkcs1ToJwk(r);if(si(e)>Tn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await ea(e);return new Jr(t.privateKey,t.publicKey)}function Zp(r){let e=Jt.pkixToJwk(r);if(si(e)>Tn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new kn(e)}async function Wp(r){if(si(r)>Tn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ea(r);return new Jr(e.privateKey,e.publicKey)}async function Jp(r){if(r>Tn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ol(r);return new Jr(e.privateKey,e.publicKey)}var sa={};me(sa,{Secp256k1PrivateKey:()=>Nn,Secp256k1PublicKey:()=>Cn,generateKeyPair:()=>hg,unmarshalSecp256k1PrivateKey:()=>lg,unmarshalSecp256k1PublicKey:()=>fg});var Xp=(r,e,t)=>r&e^~r&t,Qp=(r,e,t)=>r&e^r&t^e&t,eg=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Xt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qt=new Uint32Array(64),ra=class extends Or{constructor(){super(64,32,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Qt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let d=Qt[l-15],E=Qt[l-2],g=Je(d,7)^Je(d,18)^d>>>3,h=Je(E,17)^Je(E,19)^E>>>10;Qt[l]=h+Qt[l-7]+g+Qt[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Je(a,6)^Je(a,11)^Je(a,25),E=u+d+Xp(a,c,f)+eg[l]+Qt[l]|0,h=(Je(n,2)^Je(n,13)^Je(n,22))+Qp(n,o,i)|0;u=f,f=c,c=a,a=s+E|0,s=i,i=o,o=n,n=E+h|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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){Qt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var cl=no(()=>new ra);function tg(r){let e=hn(r);lt(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:rg,hexToBytes:ng}=so,mr={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=mr;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:rg(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=mr,t=typeof r=="string"?ng(r):r;if(!Xe(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:o,l:i}=mr._parseInt(t.subarray(2)),{d:s,l:a}=mr._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(r){let e=f=>Number.parseInt(f[0],16)&8?"00"+f:f,t=f=>{let u=f.toString(16);return u.length&1?`0${u}`:u},n=e(t(r.s)),o=e(t(r.r)),i=n.length/2,s=o.length/2,a=t(i),c=t(s);return`30${t(s+i+4)}02${c}${o}02${a}${n}`}},Ut=BigInt(0),Ge=BigInt(1),h1=BigInt(2),ul=BigInt(3),d1=BigInt(4);function og(r){let e=tg(r),{Fp:t}=e,n=e.toBytes||((g,h,p)=>{let b=h.toAffine();return Bt(Uint8Array.from([4]),t.toBytes(b.x),t.toBytes(b.y))}),o=e.fromBytes||(g=>{let h=g.subarray(1),p=t.fromBytes(h.subarray(0,t.BYTES)),b=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:p,y:b}});function i(g){let{a:h,b:p}=e,b=t.sqr(g),R=t.mul(b,g);return t.add(t.add(R,t.mul(g,h)),p)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&Ut<g&&g<e.n}function a(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){let{allowedPrivateKeyLengths:h,nByteLength:p,wrapPrivateKey:b,n:R}=e;if(h&&typeof g!="bigint"){if(Xe(g)&&(g=Et(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let v;try{v=typeof g=="bigint"?g:vt(ue("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return b&&(v=re(v,R)),a(v),v}let f=new Map;function u(g){if(!(g instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(h,p,b){if(this.px=h,this.py=p,this.pz=b,h==null||!t.isValid(h))throw new Error("x required");if(p==null||!t.isValid(p))throw new Error("y required");if(b==null||!t.isValid(b))throw new Error("z required")}static fromAffine(h){let{x:p,y:b}=h||{};if(!h||!t.isValid(p)||!t.isValid(b))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let R=v=>t.eql(v,t.ZERO);return R(p)&&R(b)?l.ZERO:new l(p,b,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let p=t.invertBatch(h.map(b=>b.pz));return h.map((b,R)=>b.toAffine(p[R])).map(l.fromAffine)}static fromHex(h){let p=l.fromAffine(o(ue("pointHex",h)));return p.assertValidity(),p}static fromPrivateKey(h){return l.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,f.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=this.toAffine();if(!t.isValid(h)||!t.isValid(p))throw new Error("bad point: x or y not FE");let b=t.sqr(p),R=i(h);if(!t.eql(b,R))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:p,py:b,pz:R}=this,{px:v,py:L,pz:S}=h,k=t.eql(t.mul(p,S),t.mul(v,R)),N=t.eql(t.mul(b,S),t.mul(L,R));return k&&N}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:p}=e,b=t.mul(p,ul),{px:R,py:v,pz:L}=this,S=t.ZERO,k=t.ZERO,N=t.ZERO,y=t.mul(R,R),C=t.mul(v,v),V=t.mul(L,L),T=t.mul(R,v);return T=t.add(T,T),N=t.mul(R,L),N=t.add(N,N),S=t.mul(h,N),k=t.mul(b,V),k=t.add(S,k),S=t.sub(C,k),k=t.add(C,k),k=t.mul(S,k),S=t.mul(T,S),N=t.mul(b,N),V=t.mul(h,V),T=t.sub(y,V),T=t.mul(h,T),T=t.add(T,N),N=t.add(y,y),y=t.add(N,y),y=t.add(y,V),y=t.mul(y,T),k=t.add(k,y),V=t.mul(v,L),V=t.add(V,V),y=t.mul(V,T),S=t.sub(S,y),N=t.mul(V,C),N=t.add(N,N),N=t.add(N,N),new l(S,k,N)}add(h){u(h);let{px:p,py:b,pz:R}=this,{px:v,py:L,pz:S}=h,k=t.ZERO,N=t.ZERO,y=t.ZERO,C=e.a,V=t.mul(e.b,ul),T=t.mul(p,v),P=t.mul(b,L),H=t.mul(R,S),J=t.add(p,b),x=t.add(v,L);J=t.mul(J,x),x=t.add(T,P),J=t.sub(J,x),x=t.add(p,R);let A=t.add(v,S);return x=t.mul(x,A),A=t.add(T,H),x=t.sub(x,A),A=t.add(b,R),k=t.add(L,S),A=t.mul(A,k),k=t.add(P,H),A=t.sub(A,k),y=t.mul(C,x),k=t.mul(V,H),y=t.add(k,y),k=t.sub(P,y),y=t.add(P,y),N=t.mul(k,y),P=t.add(T,T),P=t.add(P,T),H=t.mul(C,H),x=t.mul(V,x),P=t.add(P,H),H=t.sub(T,H),H=t.mul(C,H),x=t.add(x,H),T=t.mul(P,x),N=t.add(N,T),T=t.mul(A,x),k=t.mul(J,k),k=t.sub(k,T),T=t.mul(J,P),y=t.mul(A,y),y=t.add(y,T),new l(k,N,y)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return E.wNAFCached(this,f,h,p=>{let b=t.invertBatch(p.map(R=>R.pz));return p.map((R,v)=>R.toAffine(b[v])).map(l.fromAffine)})}multiplyUnsafe(h){let p=l.ZERO;if(h===Ut)return p;if(a(h),h===Ge)return this;let{endo:b}=e;if(!b)return E.unsafeLadder(this,h);let{k1neg:R,k1:v,k2neg:L,k2:S}=b.splitScalar(h),k=p,N=p,y=this;for(;v>Ut||S>Ut;)v&Ge&&(k=k.add(y)),S&Ge&&(N=N.add(y)),y=y.double(),v>>=Ge,S>>=Ge;return R&&(k=k.negate()),L&&(N=N.negate()),N=new l(t.mul(N.px,b.beta),N.py,N.pz),k.add(N)}multiply(h){a(h);let p=h,b,R,{endo:v}=e;if(v){let{k1neg:L,k1:S,k2neg:k,k2:N}=v.splitScalar(p),{p:y,f:C}=this.wNAF(S),{p:V,f:T}=this.wNAF(N);y=E.constTimeNegate(L,y),V=E.constTimeNegate(k,V),V=new l(t.mul(V.px,v.beta),V.py,V.pz),b=y.add(V),R=C.add(T)}else{let{p:L,f:S}=this.wNAF(p);b=L,R=S}return l.normalizeZ([b,R])[0]}multiplyAndAddUnsafe(h,p,b){let R=l.BASE,v=(S,k)=>k===Ut||k===Ge||!S.equals(R)?S.multiplyUnsafe(k):S.multiply(k),L=v(this,p).add(v(h,b));return L.is0()?void 0:L}toAffine(h){let{px:p,py:b,pz:R}=this,v=this.is0();h==null&&(h=v?t.ONE:t.inv(R));let L=t.mul(p,h),S=t.mul(b,h),k=t.mul(R,h);if(v)return{x:t.ZERO,y:t.ZERO};if(!t.eql(k,t.ONE))throw new Error("invZ was invalid");return{x:L,y:S}}isTorsionFree(){let{h,isTorsionFree:p}=e;if(h===Ge)return!0;if(p)return p(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:p}=e;return h===Ge?this:p?p(l,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(l,this,h)}toHex(h=!0){return Et(this.toRawBytes(h))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let d=e.nBitLength,E=uo(l,e.endo?Math.ceil(d/2):d);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function ig(r){let e=hn(r);return lt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ll(r){let e=ig(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(x){return Ut<x&&x<t.ORDER}function a(x){return re(x,n)}function c(x){return ao(x,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:d}=og({...e,toBytes(x,A,M){let B=A.toAffine(),w=t.toBytes(B.x),D=Bt;return M?D(Uint8Array.from([A.hasEvenY()?2:3]),w):D(Uint8Array.from([4]),w,t.toBytes(B.y))},fromBytes(x){let A=x.length,M=x[0],B=x.subarray(1);if(A===o&&(M===2||M===3)){let w=vt(B);if(!s(w))throw new Error("Point is not on curve");let D=l(w),F=t.sqrt(D),$=(F&Ge)===Ge;return(M&1)===1!==$&&(F=t.neg(F)),{x:w,y:F}}else if(A===i&&M===4){let w=t.fromBytes(B.subarray(0,t.BYTES)),D=t.fromBytes(B.subarray(t.BYTES,2*t.BYTES));return{x:w,y:D}}else throw new Error(`Point of length ${A} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),E=x=>Et(Gt(x,e.nByteLength));function g(x){let A=n>>Ge;return x>A}function h(x){return g(x)?a(-x):x}let p=(x,A,M)=>vt(x.slice(A,M));class b{constructor(A,M,B){this.r=A,this.s=M,this.recovery=B,this.assertValidity()}static fromCompact(A){let M=e.nByteLength;return A=ue("compactSignature",A,M*2),new b(p(A,0,M),p(A,M,2*M))}static fromDER(A){let{r:M,s:B}=mr.toSig(ue("DER",A));return new b(M,B)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(A){return new b(this.r,this.s,A)}recoverPublicKey(A){let{r:M,s:B,recovery:w}=this,D=N(ue("msgHash",A));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let F=w===2||w===3?M+e.n:M;if(F>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let $=w&1?"03":"02",z=f.fromHex($+E(F)),G=c(F),te=a(-D*G),Z=a(B*G),X=f.BASE.multiplyAndAddUnsafe(z,te,Z);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return cr(this.toDERHex())}toDERHex(){return mr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return cr(this.toCompactHex())}toCompactHex(){return E(this.r)+E(this.s)}}let R={isValidPrivateKey(x){try{return u(x),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let x=Rs(e.n);return Wc(e.randomBytes(x),e.n)},precompute(x=8,A=f.BASE){return A._setWindowSize(x),A.multiply(BigInt(3)),A}};function v(x,A=!0){return f.fromPrivateKey(x).toRawBytes(A)}function L(x){let A=Xe(x),M=typeof x=="string",B=(A||M)&&x.length;return A?B===o||B===i:M?B===2*o||B===2*i:x instanceof f}function S(x,A,M=!0){if(L(x))throw new Error("first arg must be private key");if(!L(A))throw new Error("second arg must be public key");return f.fromHex(A).multiply(u(x)).toRawBytes(M)}let k=e.bits2int||function(x){let A=vt(x),M=x.length*8-e.nBitLength;return M>0?A>>BigInt(M):A},N=e.bits2int_modN||function(x){return a(k(x))},y=fn(e.nBitLength);function C(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(Ut<=x&&x<y))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Gt(x,e.nByteLength)}function V(x,A,M=T){if(["recovered","canonical"].some(se=>se in M))throw new Error("sign() legacy options not supported");let{hash:B,randomBytes:w}=e,{lowS:D,prehash:F,extraEntropy:$}=M;D==null&&(D=!0),x=ue("msgHash",x),F&&(x=ue("prehashed msgHash",B(x)));let z=N(x),G=u(A),te=[C(G),C(z)];if($!=null){let se=$===!0?w(t.BYTES):$;te.push(ue("extraEntropy",se))}let Z=Bt(...te),X=z;function he(se){let be=k(se);if(!d(be))return;let xe=c(be),pe=f.BASE.multiply(be).toAffine(),Ae=a(pe.x);if(Ae===Ut)return;let wt=a(xe*a(X+Ae*G));if(wt===Ut)return;let rr=(pe.x===Ae?0:2)|Number(pe.y&Ge),nn=wt;return D&&g(wt)&&(nn=h(wt),rr^=1),new b(Ae,nn,rr)}return{seed:Z,k2sig:he}}let T={lowS:e.lowS,prehash:!1},P={lowS:e.lowS,prehash:!1};function H(x,A,M=T){let{seed:B,k2sig:w}=V(x,A,M),D=e;return Bs(D.hash.outputLen,D.nByteLength,D.hmac)(B,w)}f.BASE._setWindowSize(8);function J(x,A,M,B=P){let w=x;if(A=ue("msgHash",A),M=ue("publicKey",M),"strict"in B)throw new Error("options.strict was renamed to lowS");let{lowS:D,prehash:F}=B,$,z;try{if(typeof w=="string"||Xe(w))try{$=b.fromDER(w)}catch(pe){if(!(pe instanceof mr.Err))throw pe;$=b.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:pe,s:Ae}=w;$=new b(pe,Ae)}else throw new Error("PARSE");z=f.fromHex(M)}catch(pe){if(pe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&$.hasHighS())return!1;F&&(A=e.hash(A));let{r:G,s:te}=$,Z=N(A),X=c(te),he=a(Z*X),se=a(G*X),be=f.BASE.multiplyAndAddUnsafe(z,he,se)?.toAffine();return be?a(be.x)===G:!1}return{CURVE:e,getPublicKey:v,getSharedSecret:S,sign:H,verify:J,ProjectivePoint:f,Signature:b,utils:R}}function sg(r){return{hash:r,hmac:(e,...t)=>wn(r,e,ro(...t)),randomBytes:Vr}}function fl(r,e){let t=n=>ll({...r,...sg(n)});return Object.freeze({...t(e),create:t})}var pl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),hl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ag=BigInt(1),na=BigInt(2),dl=(r,e)=>(r+e/na)/e;function cg(r){let e=pl,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=ie(u,t,e)*u%e,d=ie(l,t,e)*u%e,E=ie(d,na,e)*f%e,g=ie(E,o,e)*E%e,h=ie(g,i,e)*g%e,p=ie(h,a,e)*h%e,b=ie(p,c,e)*p%e,R=ie(b,a,e)*h%e,v=ie(R,t,e)*u%e,L=ie(v,s,e)*g%e,S=ie(L,n,e)*f%e,k=ie(S,na,e);if(!oa.eql(oa.sqr(k),r))throw new Error("Cannot find square root");return k}var oa=co(pl,void 0,void 0,{sqrt:cg}),nt=fl({a:BigInt(0),b:BigInt(7),Fp:oa,n:hl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=hl,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ag*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=dl(i*r,e),c=dl(-n*r,e),f=re(r-a*t-c*o,e),u=re(-a*n-c*i,e),l=f>s,d=u>s;if(l&&(f=e-f),d&&(u=e-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},cl),v1=BigInt(0);var B1=nt.ProjectivePoint;function gl(){return nt.utils.randomPrivateKey()}function ml(r,e){let t=Ee.digest(e instanceof Uint8Array?e:e.subarray());if(qe(t))return t.then(({digest:n})=>nt.sign(n,r).toDERRawBytes()).catch(n=>{throw new O(String(n),"ERR_INVALID_INPUT")});try{return nt.sign(t.digest,r).toDERRawBytes()}catch(n){throw new O(String(n),"ERR_INVALID_INPUT")}}function yl(r,e,t){let n=Ee.digest(t instanceof Uint8Array?t:t.subarray());if(qe(n))return n.then(({digest:o})=>nt.verify(e,o,r)).catch(o=>{throw new O(String(o),"ERR_INVALID_INPUT")});try{return nt.verify(e,n.digest,r)}catch(o){throw new O(String(o),"ERR_INVALID_INPUT")}}function wl(r){return nt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function bl(r){try{nt.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}function ia(r){try{nt.ProjectivePoint.fromHex(r)}catch(e){throw new O(String(e),"ERR_INVALID_PUBLIC_KEY")}}function xl(r){try{return nt.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}var Cn=class{_key;constructor(e){ia(e),this._key=e}verify(e,t){return yl(this._key,t,e)}marshal(){return wl(this._key)}get bytes(){return ft.encode({Type:fe.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=Ee.digest(this.bytes),t;return qe(e)?{bytes:t}=await e:t=e.bytes,t}},Nn=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??xl(e),bl(this._key),ia(this._publicKey)}sign(e){return ml(this._key,e)}get public(){return new Cn(this._publicKey)}marshal(){return this._key}get bytes(){return It.encode({Type:fe.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return qe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Hr(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function lg(r){return new Nn(r)}function fg(r){return new Cn(r)}async function hg(){let r=gl();return new Nn(r)}var ai={rsa:ta,ed25519:zs,secp256k1:sa};function dg(r){let e=Object.keys(ai).join(" / ");return new O(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function aa(r){let e=ft.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case fe.RSA:return ai.rsa.unmarshalRsaPublicKey(t);case fe.Ed25519:return ai.ed25519.unmarshalEd25519PublicKey(t);case fe.Secp256k1:return ai.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw dg(e.Type??"unknown")}}var Zg=Vt(ci(),1);var gg="/",mg=new TextEncoder().encode(gg),M1=mg[0];var Wg=Vt(ua(),1);var Bl="ERR_IPNS_EXPIRED_RECORD",ui="ERR_UNRECOGNIZED_VALIDITY";var Lt="ERR_SIGNATURE_VERIFICATION",Al="ERR_UNRECOGNIZED_FORMAT";var la="ERR_UNDEFINED_PARAMETER",Sl="ERR_INVALID_RECORD_DATA",Il="ERR_INVALID_VALUE",Rl="ERR_INVALID_EMBEDDED_KEY";var kl="ERR_RECORD_TOO_LARGE";var ot;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>mn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=zr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.value=o.bytes();break;case 2:s.signatureV1=o.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(o);break;case 4:s.validity=o.bytes();break;case 5:s.sequence=o.uint64();break;case 6:s.ttl=o.uint64();break;case 7:s.pubKey=o.bytes();break;case 8:s.signatureV2=o.bytes();break;case 9:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>$r(o,r.codec()),r.decode=o=>Kr(o,r.codec())})(ot||(ot={}));var yg=["string","number","bigint","symbol"],wg=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Cl(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(yg.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(bg(r))return"Buffer";let t=xg(r);return t||"Object"}function bg(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function xg(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(wg.includes(e))return e}var m=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};m.uint=new m(0,"uint",!0);m.negint=new m(1,"negint",!0);m.bytes=new m(2,"bytes",!0);m.string=new m(3,"string",!0);m.array=new m(4,"array",!1);m.map=new m(5,"map",!1);m.tag=new m(6,"tag",!1);m.float=new m(7,"float",!0);m.false=new m(7,"false",!0);m.true=new m(7,"true",!0);m.null=new m(7,"null",!0);m.undefined=new m(7,"undefined",!0);m.break=new m(7,"break",!0);var U=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Xr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Eg=new TextDecoder,vg=new TextEncoder;function li(r){return Xr&&globalThis.Buffer.isBuffer(r)}function Ll(r){return r instanceof Uint8Array?li(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Dl=Xr?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):_l(r,e,t):(r,e,t)=>t-e>64?Eg.decode(r.subarray(e,t)):_l(r,e,t),Vl=Xr?r=>r.length>64?globalThis.Buffer.from(r):Nl(r):r=>r.length>64?vg.encode(r):Nl(r);var Qr=Xr?(r,e,t)=>li(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Ol=Xr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Ll(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Pl=Xr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Fl(r,e){if(li(r)&&li(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Nl(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function _l(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],f=r[e+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Bg(n)}var Ul=4096;function Bg(r){let e=r.length;if(e<=Ul)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Ul));return t}var Ag=256,fi=class{constructor(e=Ag){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Pl(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Qr(n,0,this.cursor)}else t=Ol(this.chunks,this.cursor);return e&&this.reset(),t}};var K="CBOR decode error:",fa="CBOR encode error:",_n=[];_n[23]=1;_n[24]=2;_n[25]=3;_n[26]=5;_n[27]=9;function Dt(r,e,t){if(r.length-e<t)throw new Error(`${K} not enough data for type`)}var we=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Me(r,e,t){Dt(r,e,1);let n=r[e];if(t.strict===!0&&n<we[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function He(r,e,t){Dt(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<we[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ke(r,e,t){Dt(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<we[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function $e(r,e,t){Dt(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<we[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function Ml(r,e,t,n){return new U(m.uint,Me(r,e+1,n),2)}function Hl(r,e,t,n){return new U(m.uint,He(r,e+1,n),3)}function Kl(r,e,t,n){return new U(m.uint,Ke(r,e+1,n),5)}function $l(r,e,t,n){return new U(m.uint,$e(r,e+1,n),9)}function je(r,e){return Be(r,0,e.value)}function Be(r,e,t){if(t<we[0]){let n=Number(t);r.push([e|n])}else if(t<we[1]){let n=Number(t);r.push([e|24,n])}else if(t<we[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<we[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<we[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}je.encodedSize=function(e){return Be.encodedSize(e.value)};Be.encodedSize=function(e){return e<we[0]?1:e<we[1]?2:e<we[2]?3:e<we[3]?5:9};je.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function ql(r,e,t,n){return new U(m.negint,-1-Me(r,e+1,n),2)}function zl(r,e,t,n){return new U(m.negint,-1-He(r,e+1,n),3)}function Gl(r,e,t,n){return new U(m.negint,-1-Ke(r,e+1,n),5)}var ha=BigInt(-1),jl=BigInt(1);function Yl(r,e,t,n){let o=$e(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new U(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new U(m.negint,ha-BigInt(o),9)}function hi(r,e){let t=e.value,n=typeof t=="bigint"?t*ha-jl:t*-1-1;Be(r,e.type.majorEncoded,n)}hi.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*ha-jl:t*-1-1;return n<we[0]?1:n<we[1]?2:n<we[2]?3:n<we[3]?5:9};hi.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Un(r,e,t,n){Dt(r,e,t+n);let o=Qr(r,e+t,e+t+n);return new U(m.bytes,o,t+n)}function Zl(r,e,t,n){return Un(r,e,1,t)}function Wl(r,e,t,n){return Un(r,e,2,Me(r,e+1,n))}function Jl(r,e,t,n){return Un(r,e,3,He(r,e+1,n))}function Xl(r,e,t,n){return Un(r,e,5,Ke(r,e+1,n))}function Ql(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return Un(r,e,9,o)}function di(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===m.string?Vl(r.value):r.value),r.encodedBytes}function en(r,e){let t=di(e);Be(r,e.type.majorEncoded,t.length),r.push(t)}en.encodedSize=function(e){let t=di(e);return Be.encodedSize(t.length)+t.length};en.compareTokens=function(e,t){return Ig(di(e),di(t))};function Ig(r,e){return r.length<e.length?-1:r.length>e.length?1:Fl(r,e)}function Ln(r,e,t,n,o){let i=t+n;Dt(r,e,i);let s=new U(m.string,Dl(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Qr(r,e+t,e+i)),s}function ef(r,e,t,n){return Ln(r,e,1,t,n)}function tf(r,e,t,n){return Ln(r,e,2,Me(r,e+1,n),n)}function rf(r,e,t,n){return Ln(r,e,3,He(r,e+1,n),n)}function nf(r,e,t,n){return Ln(r,e,5,Ke(r,e+1,n),n)}function of(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return Ln(r,e,9,o,n)}var sf=en;function tn(r,e,t,n){return new U(m.array,n,t)}function af(r,e,t,n){return tn(r,e,1,t)}function cf(r,e,t,n){return tn(r,e,2,Me(r,e+1,n))}function uf(r,e,t,n){return tn(r,e,3,He(r,e+1,n))}function lf(r,e,t,n){return tn(r,e,5,Ke(r,e+1,n))}function ff(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return tn(r,e,9,o)}function hf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return tn(r,e,1,1/0)}function pi(r,e){Be(r,m.array.majorEncoded,e.value)}pi.compareTokens=je.compareTokens;pi.encodedSize=function(e){return Be.encodedSize(e.value)};function rn(r,e,t,n){return new U(m.map,n,t)}function df(r,e,t,n){return rn(r,e,1,t)}function pf(r,e,t,n){return rn(r,e,2,Me(r,e+1,n))}function gf(r,e,t,n){return rn(r,e,3,He(r,e+1,n))}function mf(r,e,t,n){return rn(r,e,5,Ke(r,e+1,n))}function yf(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return rn(r,e,9,o)}function wf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return rn(r,e,1,1/0)}function gi(r,e){Be(r,m.map.majorEncoded,e.value)}gi.compareTokens=je.compareTokens;gi.encodedSize=function(e){return Be.encodedSize(e.value)};function bf(r,e,t,n){return new U(m.tag,t,1)}function xf(r,e,t,n){return new U(m.tag,Me(r,e+1,n),2)}function Ef(r,e,t,n){return new U(m.tag,He(r,e+1,n),3)}function vf(r,e,t,n){return new U(m.tag,Ke(r,e+1,n),5)}function Bf(r,e,t,n){return new U(m.tag,$e(r,e+1,n),9)}function mi(r,e){Be(r,m.tag.majorEncoded,e.value)}mi.compareTokens=je.compareTokens;mi.encodedSize=function(e){return Be.encodedSize(e.value)};var _g=20,Ug=21,Lg=22,Dg=23;function Af(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new U(m.null,null,1):new U(m.undefined,void 0,1)}function Sf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new U(m.break,void 0,1)}function da(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${K} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new U(m.float,r,e)}function If(r,e,t,n){return da(pa(r,e+1),3,n)}function Rf(r,e,t,n){return da(ga(r,e+1),5,n)}function kf(r,e,t,n){return da(_f(r,e+1),9,n)}function yi(r,e,t){let n=e.value;if(n===!1)r.push([m.float.majorEncoded|_g]);else if(n===!0)r.push([m.float.majorEncoded|Ug]);else if(n===null)r.push([m.float.majorEncoded|Lg]);else if(n===void 0)r.push([m.float.majorEncoded|Dg]);else{let o,i=!1;(!t||t.float64!==!0)&&(Cf(n),o=pa(it,1),n===o||Number.isNaN(n)?(it[0]=249,r.push(it.slice(0,3)),i=!0):(Nf(n),o=ga(it,1),n===o&&(it[0]=250,r.push(it.slice(0,5)),i=!0))),i||(Vg(n),o=_f(it,1),it[0]=251,r.push(it.slice(0,9)))}}yi.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Cf(n);let o=pa(it,1);if(n===o||Number.isNaN(n))return 3;if(Nf(n),o=ga(it,1),n===o)return 5}return 9};var Tf=new ArrayBuffer(9),Ye=new DataView(Tf,1),it=new Uint8Array(Tf,0);function Cf(r){if(r===1/0)Ye.setUint16(0,31744,!1);else if(r===-1/0)Ye.setUint16(0,64512,!1);else if(Number.isNaN(r))Ye.setUint16(0,32256,!1);else{Ye.setFloat32(0,r);let e=Ye.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Ye.setUint16(0,31744,!1);else if(t===0)Ye.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Ye.setUint16(0,0):o<-14?Ye.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Ye.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function pa(r,e){if(r.length-e<2)throw new Error(`${K} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Nf(r){Ye.setFloat32(0,r,!1)}function ga(r,e){if(r.length-e<4)throw new Error(`${K} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Vg(r){Ye.setFloat64(0,r,!1)}function _f(r,e){if(r.length-e<8)throw new Error(`${K} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}yi.compareTokens=je.compareTokens;function Q(r,e,t){throw new Error(`${K} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function wi(r){return()=>{throw new Error(`${K} ${r}`)}}var I=[];for(let r=0;r<=23;r++)I[r]=Q;I[24]=Ml;I[25]=Hl;I[26]=Kl;I[27]=$l;I[28]=Q;I[29]=Q;I[30]=Q;I[31]=Q;for(let r=32;r<=55;r++)I[r]=Q;I[56]=ql;I[57]=zl;I[58]=Gl;I[59]=Yl;I[60]=Q;I[61]=Q;I[62]=Q;I[63]=Q;for(let r=64;r<=87;r++)I[r]=Zl;I[88]=Wl;I[89]=Jl;I[90]=Xl;I[91]=Ql;I[92]=Q;I[93]=Q;I[94]=Q;I[95]=wi("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)I[r]=ef;I[120]=tf;I[121]=rf;I[122]=nf;I[123]=of;I[124]=Q;I[125]=Q;I[126]=Q;I[127]=wi("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)I[r]=af;I[152]=cf;I[153]=uf;I[154]=lf;I[155]=ff;I[156]=Q;I[157]=Q;I[158]=Q;I[159]=hf;for(let r=160;r<=183;r++)I[r]=df;I[184]=pf;I[185]=gf;I[186]=mf;I[187]=yf;I[188]=Q;I[189]=Q;I[190]=Q;I[191]=wf;for(let r=192;r<=215;r++)I[r]=bf;I[216]=xf;I[217]=Ef;I[218]=vf;I[219]=Bf;I[220]=Q;I[221]=Q;I[222]=Q;I[223]=Q;for(let r=224;r<=243;r++)I[r]=wi("simple values are not supported");I[244]=Q;I[245]=Q;I[246]=Q;I[247]=Af;I[248]=wi("simple values are not supported");I[249]=If;I[250]=Rf;I[251]=kf;I[252]=Q;I[253]=Q;I[254]=Q;I[255]=Sf;var st=[];for(let r=0;r<24;r++)st[r]=new U(m.uint,r,1);for(let r=-1;r>=-24;r--)st[31-r]=new U(m.negint,r,1);st[64]=new U(m.bytes,new Uint8Array(0),1);st[96]=new U(m.string,"",1);st[128]=new U(m.array,0,1);st[160]=new U(m.map,0,1);st[244]=new U(m.false,!1,1);st[245]=new U(m.true,!0,1);st[246]=new U(m.null,null,1);function Pg(){let r=[];return r[m.uint.major]=je,r[m.negint.major]=hi,r[m.bytes.major]=en,r[m.string.major]=sf,r[m.array.major]=pi,r[m.map.major]=gi,r[m.tag.major]=mi,r[m.float.major]=yi,r}var OE=Pg(),PE=new fi,bi=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${fa} object contains circular references`);return new r(t,e)}},er={null:new U(m.null,null),undefined:new U(m.undefined,void 0),true:new U(m.true,!0),false:new U(m.false,!1),emptyArray:new U(m.array,0),emptyMap:new U(m.map,0)},tr={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new U(m.float,r):r>=0?new U(m.uint,r):new U(m.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new U(m.uint,r):new U(m.negint,r)},Uint8Array(r,e,t,n){return new U(m.bytes,r)},string(r,e,t,n){return new U(m.string,r)},boolean(r,e,t,n){return r?er.true:er.false},null(r,e,t,n){return er.null},undefined(r,e,t,n){return er.undefined},ArrayBuffer(r,e,t,n){return new U(m.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new U(m.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[er.emptyArray,new U(m.break)]:er.emptyArray;n=bi.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=ma(s,t,n);return t.addBreakTokens?[new U(m.array,r.length),o,new U(m.break)]:[new U(m.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[er.emptyMap,new U(m.break)]:er.emptyMap;n=bi.createCheck(n,r);let a=[],c=0;for(let f of i)a[c++]=[ma(f,t,n),ma(o?r.get(f):r[f],t,n)];return Fg(a,t),t.addBreakTokens?[new U(m.map,s),a,new U(m.break)]:[new U(m.map,s),a]}};tr.Map=tr.Object;tr.Buffer=tr.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))tr[`${r}Array`]=tr.DataView;function ma(r,e={},t){let n=Cl(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||tr[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=tr[n];if(!i)throw new Error(`${fa} unsupported type: ${n}`);return i(r,n,e,t)}function Fg(r,e){e.mapSorter&&r.sort(e.mapSorter)}var Mg={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ya=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=st[e];if(t===void 0){let n=I[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Dn=Symbol.for("DONE"),xi=Symbol.for("BREAK");function Hg(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Vn(e,t);if(i===xi){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Dn)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Kg(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Vn(e,t);if(a===xi){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(a===Dn)throw new Error(`${K} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${K} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${K} found repeat map key "${a}"`);let c=Vn(e,t);if(c===Dn)throw new Error(`${K} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Vn(r,e){if(r.done())return Dn;let t=r.next();if(t.type===m.break)return xi;if(t.type.terminal)return t.value;if(t.type===m.array)return Hg(t,r,e);if(t.type===m.map)return Kg(t,r,e);if(t.type===m.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Vn(r,e);return e.tags[t.value](n)}throw new Error(`${K} tag not supported (${t.value})`)}throw new Error("unsupported")}function Uf(r,e){if(!(r instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},Mg,e);let t=e.tokenizer||new ya(r,e),n=Vn(t,e);if(n===Dn)throw new Error(`${K} did not find any content to decode`);if(n===xi)throw new Error(`${K} got unexpected break`);return[n,r.subarray(t.pos())]}function wa(r,e){let[t,n]=Uf(r,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return t}var Ve=Vt(ci(),1);var Lf=Vt(ua(),1);var ba=Pt("ipns:utils"),Df=j("/ipns/"),zg=114;function Gg(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),o=parseInt(t[2],10)-1,i=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),f=parseInt(t[7].padEnd(6,"0").slice(0,3),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var Vf=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw ba.error(n),(0,Ve.default)(n,la)}let t;if(e.pubKey!=null){try{t=aa(e.pubKey)}catch(o){throw ba.error(o),o}if(!(await gc(e.pubKey)).equals(r))throw(0,Ve.default)(new Error("Embedded public key did not match PeerID"),Rl)}else r.publicKey!=null&&(t=aa(r.publicKey));if(t!=null)return t;throw(0,Ve.default)(new Error("no public key is available"),la)};var Of=r=>{let e=j("ipns-signature:");return Ce([e,r])},wr=r=>"signatureV1"in r?ot.encode({value:j(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:j(r.validity.toString()),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):ot.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function gt(r){let e=ot.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,Ve.default)(new Error("missing data or signatureV2"),Lt);let t=Ff(e.data),n=jg(t.Value),o;try{o=Lf.default.fromDate(Gg(W(t.Validity)))}catch{throw ba.error("unrecognized validity format (not an rfc3339 format)"),(0,Ve.default)(new Error("unrecognized validity format (not an rfc3339 format)"),Al)}if(e.value!=null&&e.signatureV1!=null)return Yg(e),{value:n,validityType:ot.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:ot.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var xa=r=>Ce([Df,r.toBytes()]),Pf=r=>ir(r.slice(Df.length));var Ff=r=>{let e=wa(r);if(e.ValidityType===0)e.ValidityType=ot.ValidityType.EOL;else throw(0,Ve.default)(new Error("Unknown validity type"),ui);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},jg=r=>{if(r!=null){if(Ma(r))return`/ipns/${r.toCID().toString(Gn)}`;if(r instanceof Uint8Array){let n=W(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=Te.asCID(r);if(t!=null)return t.code===zg?`/ipns/${t.toString(Gn)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${Te.decode(r).toV1().toString()}`:`/ipfs/${Te.parse(e).toV1().toString()}`}catch{}}throw(0,Ve.default)(new Error("Value must be a valid content path starting with /"),Il)},Yg=r=>{if(r.data==null)throw(0,Ve.default)(new Error("Record data is missing"),Sl);let e=Ff(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw(0,Ve.default)(new Error('Field "value" did not match between protobuf and CBOR'),Lt);if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw(0,Ve.default)(new Error('Field "validity" did not match between protobuf and CBOR'),Lt);if(e.ValidityType!==r.validityType)throw(0,Ve.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),Lt);if(e.Sequence!==r.sequence)throw(0,Ve.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),Lt);if(e.TTL!==r.ttl)throw(0,Ve.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),Lt)};var h2=Pt("ipns"),d2=ct.code,Jg="/ipns/",p2=Jg.length;var On=Vt(ci(),1);var Ei=Pt("ipns:validator"),Xg=1024*10,Qg=async(r,e)=>{let t=gt(e),n;try{let o=Of(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw Ei.error("record signature verification failed"),(0,On.default)(new Error("record signature verification failed"),Lt);if(t.validityType===ot.ValidityType.EOL){if(t.validity.toDate().getTime()<Date.now())throw Ei.error("record has expired"),(0,On.default)(new Error("record has expired"),Bl)}else if(t.validityType!=null)throw Ei.error("unrecognized validity type"),(0,On.default)(new Error("unrecognized validity type"),ui);Ei("ipns record for %b is valid",t.value)};async function Mf(r,e){if(e.byteLength>Xg)throw(0,On.default)(new Error("record too large"),kl);let t=Pf(r),n=gt(e),o=await Vf(t,n);await Qg(o,e)}async function*Pn(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let o of r){typeof o=="string"&&(o=new TextEncoder().encode(o)),n+=t.decode(o,{stream:!0});let i=n.split(e);n=i.pop()??"";for(let s=0;s<i.length;s++)yield JSON.parse(i[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}function mt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var va=Vt(Kf(),1);var Mn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ba=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},$f=r=>globalThis.DOMException===void 0?new Ba(r):new DOMException(r),qf=r=>{let e=r.reason===void 0?$f("This operation was aborted."):r.reason;return e instanceof Error?e:$f(e)};function Aa(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&u(qf(d)),d.addEventListener("abort",()=>{u(qf(d))})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new Mn;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?u(o):(l.message=o??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(d){u(d)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}function Sa(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Hn=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=Sa(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Kn=class extends va.default{#e;#r;#i=0;#a;#c;#p=0;#n;#u;#t;#g;#o=0;#l;#s;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Hn,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#r=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#t=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#s=e.autoStart===!1}get#b(){return this.#r||this.#i<this.#a}get#x(){return this.#o<this.#l}#E(){this.#o--,this.#f(),this.emit("next")}#v(){this.#w(),this.#y(),this.#u=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#o:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#s){let e=!this.#B;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#r||this.#n!==void 0||(this.#n=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#i===0&&this.#o===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#o:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#h()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#m,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#o++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Aa(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Mn&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#s?(this.#s=!1,this.#h(),this):this}pause(){this.#s=!0}clear(){this.#t=new this.#g}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#o===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#s}};function rm(r){return r[Symbol.asyncIterator]!=null}function nm(r){if(rm(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Bi=nm;function om(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var zf=om;function im(r){return r[Symbol.asyncIterator]!=null}function sm(r,e){if(im(r))return async function*(){for await(let a of r)yield e(a)}();let t=zf(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){yield await i;for await(let a of t)yield e(a)}();let s=e;return function*(){yield i;for(let a of t)yield s(a)}()}var Ai=sm;var Ia=j("/ipns/");function Gf(r){return ce(r.subarray(0,Ia.byteLength),Ia)}var jf=r=>ir(r.slice(Ia.length)),Si=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*Ai(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!Gf(e))return;let o=jf(e),i=gt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!Gf(e))throw new O("Not found","ERR_NOT_FOUND");let n=jf(e);try{let o=await this.client.getIPNS(n,t);return wr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):o}}},Ii=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Bi(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var yt=Pt("delegated-routing-v1-http-api-client"),Yf={concurrentRequests:4,timeout:3e4},Ri=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,Ka(1/0,this.shutDownController.signal),this.httpQueue=new Kn({concurrency:t.concurrentRequests??Yf.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??Yf.timeout,this.contentRouting=new Si(this),this.peerRouting=new Ii(this)}get[Fa](){return this.contentRouting}get[Ha](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,t={}){yt("getProviders starts: %c",e);let n=ln([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=mt(),i=mt();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let u=await c.json();for(let l of u.Providers){let d=this.#e(l);d!=null&&(yield d)}}else for await(let u of Pn(Qn(c.body))){let l=this.#e(u);l!=null&&(yield l)}}catch(s){yt.error("getProviders errored:",s)}finally{n.clear(),i.resolve(),yt("getProviders finished: %c",e)}}async*getPeers(e,t={}){yt("getPeers starts: %c",e);let n=ln([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=mt(),i=mt();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let u=await c.json();for(let l of u.Peers){let d=this.#e(l);d!=null&&(yield d)}}else for await(let u of Pn(Qn(c.body))){let l=this.#e(u);l!=null&&(yield l)}}catch(s){yt.error("getPeers errored:",s)}finally{n.clear(),i.resolve(),yt("getPeers finished: %c",e)}}async getIPNS(e,t={}){yt("getIPNS starts: %c",e);let n=ln([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=mt(),i=mt();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.promise;let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("GET ipns response had no body","ERR_BAD_RESPONSE");let f=new Uint8Array(await c.arrayBuffer());return await Mf(xa(e),f),gt(f)}finally{n.clear(),i.resolve(),yt("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){yt("getIPNS starts: %c",e);let o=ln([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),i=mt(),s=mt();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=wr(t),c=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;if((await fetch(c,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:a,signal:o})).status!==200)throw new O("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}finally{o.clear(),s.resolve(),yt("getIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(ms)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Xi(e.ID),Addrs:n,Protocols:t}}};function Zf(r,e={}){return new Ri(new URL(r),e)}var Ra=j("/ipns/");function Wf(r){return ce(r.subarray(0,Ra.byteLength),Ra)}var Jf=r=>ir(r.slice(Ra.length)),ka=class{client;constructor(e){this.client=Zf(e)}async provide(e,t){}async*findProviders(e,t){yield*Ai(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!Wf(e))return;let o=Jf(e),i=gt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!Wf(e))throw new O("Not found","ERR_NOT_FOUND");let n=Jf(e);try{let o=await this.client.getIPNS(n,t);return wr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):o}}async findPeer(e,t){let n=await Bi(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function Xf(r){return new ka(new URL(r))}var Ta=class{libp2p;constructor(e){this.libp2p=e}async provide(e,t){await this.libp2p.contentRouting.provide(e,t)}async*findProviders(e,t){yield*this.libp2p.contentRouting.findProviders(e,t)}async put(e,t,n){await this.libp2p.contentRouting.put(e,t,n)}async get(e,t){return this.libp2p.contentRouting.get(e,t)}async findPeer(e,t){return this.libp2p.peerRouting.findPeer(e,t)}async*getClosestPeers(e,t){yield*this.libp2p.peerRouting.getClosestPeers(e,t)}};function Qf(r){return new Ta(r)}return dh(am);})();
|
|
7
|
+
`)}`:`${t} :`}};Au=Zt;_.Constructed=Au;Zt.NAME="CONSTRUCTED";var ko=class extends Re{fromBER(e,t,n){return t}toBER(e){return nt}};ko.override="EndOfContentValueBlock";var Su,To=class extends ve{constructor(e={}){super(e,ko),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Su=To;_.EndOfContent=Su;To.NAME=vn;var Iu,Wt=class extends ve{constructor(e={}){super(e,Re),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Iu=Wt;_.Null=Iu;Wt.NAME="NULL";var No=class extends _t(Re){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=Y.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let o=Y.BufferSourceConverter.toUint8Array(e);return Ct(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Zs.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};No.NAME="BooleanValueBlock";var Ru,Co=class extends ve{constructor(e={}){super(e,No),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Ru=Co;_.Boolean=Ru;Co.NAME="BOOLEAN";var _o=class extends _t(dt){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=dt.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===vn){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==xu)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?dt.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};_o.NAME="OctetStringValueBlock";var ku,Tt=class r extends ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},_o),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=si(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Zt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${Y.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return Y.BufferSourceConverter.concat(e)}};ku=Tt;_.OctetString=ku;Tt.NAME=xu;var Uo=class extends _t(dt){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=dt.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===vn){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Eu)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=Y.BufferSourceConverter.toUint8Array(e);if(!Ct(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=si(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return dt.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return nt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Uo.NAME="BitStringValueBlock";var Tu,jr=class extends ve{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Uo),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Zt.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Tu=jr;_.BitString=Tu;jr.NAME=Eu;var Nu;function Lp(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,u=c<s?s:c,l=0;for(let d=u;d>=0;d--,l++){switch(!0){case l<a.length:f=i[s-l]+a[c-l]+t[0];break;default:f=i[s-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=Eo(new Uint8Array([f%10]),i);break;default:i[s-l]=f%10}}return t[0]>0&&(i=Eo(t,i)),i}function bu(r){if(r>=xn.length)for(let e=xn.length;e<=r;e++){let t=new Uint8Array([0]),n=xn[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=Eo(t,n)),xn.push(n)}return xn[r]}function Vp(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[s-u]-a[c-u]-t,!0){case f<0:t=1,i[s-u]=f+10;break;default:t=0,i[s-u]=f}if(t>0)for(let l=s-c+1;l>=0;l--,u++)if(f=i[s-u]-t,f<0)t=1,i[s-u]=f+10;else{t=0,i[s-u]=f;break}return i.slice()}var Bn=class extends _t(Re){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Zs.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(mu(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=Vp(bu(n),t),s="-";break;default:t=Lp(t,bu(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=wu.charAt(t[c]));return a===!1&&(s+=wu.charAt(0)),s}};Nu=Bn;Bn.NAME="IntegerValueBlock";Object.defineProperty(Nu.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Cu,de=class r extends ve{constructor(e={}){super(e,Bn),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return vo(),BigInt(this.valueBlock.toString())}static fromBigInt(e){vo();let t=BigInt(e),n=new En,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(Y.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${Y.Convert.ToHex(a)}`)+t,u=Y.BufferSourceConverter.toUint8Array(Y.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Cu=de;_.Integer=Cu;de.NAME="INTEGER";var _u,Lo=class extends de{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};_u=Lo;_.Enumerated=_u;Lo.NAME="ENUMERATED";var An=class extends _t(Re){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=Y.BufferSourceConverter.toUint8Array(e);if(!Ct(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=pr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){vo();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Yt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",nt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=Y.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};An.NAME="sidBlock";var Vo=class extends Re{constructor({value:e=Yr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new An;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,nt;t.push(o)}return Ws(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new An;if(o>Number.MAX_SAFE_INTEGER){vo();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Vo.NAME="ObjectIdentifierValueBlock";var Uu,rt=class extends ve{constructor(e={}){super(e,Vo),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Uu=rt;_.ObjectIdentifier=Uu;rt.NAME="OBJECT IDENTIFIER";var Sn=class extends _t(kt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=Y.BufferSourceConverter.toUint8Array(e);if(!Ct(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=pr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Yt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",nt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=Y.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Sn.NAME="relativeSidBlock";var Do=class extends Re{constructor({value:e=Yr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Sn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,nt;n.push(i)}return Ws(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new Sn;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Do.NAME="RelativeObjectIdentifierValueBlock";var Lu,Oo=class extends ve{constructor(e={}){super(e,Do),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Lu=Oo;_.RelativeObjectIdentifier=Lu;Oo.NAME="RelativeObjectIdentifier";var Vu,ye=class extends Zt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Vu=ye;_.Sequence=Vu;ye.NAME="SEQUENCE";var Du,Po=class extends Zt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Du=Po;_.Set=Du;Po.NAME="SET";var Fo=class extends _t(Re){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Yr}toJSON(){return{...super.toJSON(),value:this.value}}};Fo.NAME="StringValueBlock";var Mo=class extends Fo{};Mo.NAME="SimpleStringValueBlock";var _e=class extends So{constructor({...e}={}){super(e,Mo)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,Y.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};_e.NAME="SIMPLE STRING";var Ho=class extends _e{fromBuffer(e){this.valueBlock.valueHexView=Y.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=Y.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=Y.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(Y.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Ho.NAME="Utf8StringValueBlock";var Ou,Nt=class extends Ho{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ou=Nt;_.Utf8String=Ou;Nt.NAME="UTF8String";var Ko=class extends _e{fromBuffer(e){this.valueBlock.value=Y.Convert.ToUtf16String(e),this.valueBlock.valueHexView=Y.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(Y.Convert.FromUtf16String(e))}};Ko.NAME="BmpStringValueBlock";var Pu,$o=class extends Ko{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Pu=$o;_.BmpString=Pu;$o.NAME="BMPString";var qo=class extends _e{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=Yt(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};qo.NAME="UniversalStringValueBlock";var Fu,zo=class extends qo{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Fu=zo;_.UniversalString=Fu;zo.NAME="UniversalString";var Mu,Go=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Mu=Go;_.NumericString=Mu;Go.NAME="NumericString";var Hu,jo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Hu=jo;_.PrintableString=Hu;jo.NAME="PrintableString";var Ku,Yo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Ku=Yo;_.TeletexString=Ku;Yo.NAME="TeletexString";var $u,Zo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};$u=Zo;_.VideotexString=$u;Zo.NAME="VideotexString";var qu,Wo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};qu=Wo;_.IA5String=qu;Wo.NAME="IA5String";var zu,Jo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};zu=Jo;_.GraphicString=zu;Jo.NAME="GraphicString";var Gu,In=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Gu=In;_.VisibleString=Gu;In.NAME="VisibleString";var ju,Xo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ju=Xo;_.GeneralString=ju;Xo.NAME="GeneralString";var Yu,Qo=class extends _e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Yu=Qo;_.CharacterString=Yu;Qo.NAME="CharacterString";var Zu,Rn=class extends In{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,Y.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ve(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ve(this.month,2),t[2]=Ve(this.day,2),t[3]=Ve(this.hour,2),t[4]=Ve(this.minute,2),t[5]=Ve(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Zu=Rn;_.UTCTime=Zu;Rn.NAME="UTCTime";var Wu,ei=class extends Rn{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,d=n.indexOf("+"),E="";if(d===-1&&(d=n.indexOf("-"),l=-1),d!==-1){if(E=n.substring(d+1),n=n.substring(0,d),E.length!==2&&E.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(E.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*g,E.length===4){if(g=parseInt(E.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=l*g}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=s.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Ve(this.year,4)),t.push(Ve(this.month,2)),t.push(Ve(this.day,2)),t.push(Ve(this.hour,2)),t.push(Ve(this.minute,2)),t.push(Ve(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ve(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Wu=ei;_.GeneralizedTime=Wu;ei.NAME="GeneralizedTime";var Ju,ti=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Ju=ti;_.DATE=Ju;ti.NAME="DATE";var Xu,ri=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Xu=ri;_.TimeOfDay=Xu;ri.NAME="TimeOfDay";var Qu,ni=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Qu=ni;_.DateTime=Qu;ni.NAME="DateTime";var el,oi=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};el=oi;_.Duration=el;oi.NAME="Duration";var tl,ii=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};tl=ii;_.TIME=tl;ii.NAME="TIME";function Op(r){let{result:e}=Zr(r),t=e.valueBlock.value;return{n:W(pt(t[1].toBigInt()),"base64url"),e:W(pt(t[2].toBigInt()),"base64url"),d:W(pt(t[3].toBigInt()),"base64url"),p:W(pt(t[4].toBigInt()),"base64url"),q:W(pt(t[5].toBigInt()),"base64url"),dp:W(pt(t[6].toBigInt()),"base64url"),dq:W(pt(t[7].toBigInt()),"base64url"),qi:W(pt(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Pp(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ye({value:[new de({value:0}),de.fromBigInt(gt(j(r.n,"base64url"))),de.fromBigInt(gt(j(r.e,"base64url"))),de.fromBigInt(gt(j(r.d,"base64url"))),de.fromBigInt(gt(j(r.p,"base64url"))),de.fromBigInt(gt(j(r.q,"base64url"))),de.fromBigInt(gt(j(r.dp,"base64url"))),de.fromBigInt(gt(j(r.dq,"base64url"))),de.fromBigInt(gt(j(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Fp(r){let{result:e}=Zr(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:W(pt(t[0].toBigInt()),"base64url"),e:W(pt(t[1].toBigInt()),"base64url")}}function Mp(r){if(r.n==null||r.e==null)throw new O("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ye({value:[new ye({value:[new rt({value:"1.2.840.113549.1.1.1"}),new Wt]}),new jr({valueHex:new ye({value:[de.fromBigInt(gt(j(r.n,"base64url"))),de.fromBigInt(gt(j(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function pt(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,i=0;for(;o<t;)n[o]=parseInt(e.slice(i,i+2),16),o+=1,i+=2;return n}function gt(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var Hp=16,Xs=32,Qs=1e4;async function Kp(r,e){let t=Ce.get(),o=new ye({value:[new de({value:0}),new ye({value:[new rt({value:"1.2.840.113549.1.1.1"}),new Wt]}),new Tt({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(o,0,o.byteLength),s=dr(Hp),a=await js(Or,e,s,{c:Qs,dkLen:Xs}),c=dr(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new ye({value:[new Tt({valueHex:s}),new de({value:Qs}),new de({value:Xs}),new ye({value:[new rt({value:"1.2.840.113549.2.11"}),new Wt]})]}),d=new ye({value:[new rt({value:"1.2.840.113549.1.5.13"}),new ye({value:[new ye({value:[new rt({value:"1.2.840.113549.1.5.12"}),l]}),new ye({value:[new rt({value:"2.16.840.1.101.3.4.1.42"}),new Tt({valueHex:c})]})]})]}),g=new ye({value:[d,new Tt({valueHex:u})]}).toBER(),h=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...W(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
+
`)}async function $p(r,e){let t=Ce.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Zr(o),{iv:s,salt:a,iterations:c,keySize:f,cipherText:u}=qp(i),l=await js(Or,e,a,{c,dkLen:f}),d=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),E=kn(await t.subtle.decrypt({name:"AES-CBC",iv:s},d,u)),{result:g}=Zr(E);n=rl(g)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Zr(o);n=rl(i)}else throw new O("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return ea(n)}function qp(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new O("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new O("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],s=kn(i.valueBlock.value[0].getValue()),a=Qs,c=Xs;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new O("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new O("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=kn(f.valueBlock.value[1].getValue());return{cipherText:kn(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:l}}function rl(r){return kn(r.valueBlock.value[2].getValue())}function kn(r){return new Uint8Array(r,0,r.byteLength)}async function nl(r){let e=await Ce.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await sl(e);return{privateKey:t[0],publicKey:t[1]}}async function ta(r){let t=[await Ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await zp(r)],n=await sl({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function ol(r,e){let t=await Ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ce.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function il(r,e,t){let n=await Ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ce.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function sl(r){if(r.privateKey==null||r.publicKey==null)throw new O("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ce.get().subtle.exportKey("jwk",r.privateKey),Ce.get().subtle.exportKey("jwk",r.publicKey)])}async function zp(r){return Ce.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function ai(r){if(r.kty!=="RSA")throw new O("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new O("invalid key modulus","ERR_INVALID_KEY_MODULUS");return j(r.n,"base64url").length*8}var Nn=8192,Tn=class{_key;constructor(e){this._key=e}verify(e,t){return il(this._key,t,e)}marshal(){return Jt.jwkToPkix(this._key)}get bytes(){return ht.encode({Type:fe.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return ze(e)?e.then(({bytes:t})=>t):e.bytes}},Wr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return dr(16)}sign(e){return ol(this._key,e)}get public(){if(this._publicKey==null)throw new O("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Tn(this._publicKey)}marshal(){return Jt.jwkToPkcs1(this._key)}get bytes(){return It.encode({Type:fe.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return ze(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Jt.exportToPem(this,e);if(t==="libp2p-key")return Mr(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function ea(r){let e=Jt.pkcs1ToJwk(r);if(ai(e)>Nn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await ta(e);return new Wr(t.privateKey,t.publicKey)}function jp(r){let e=Jt.pkixToJwk(r);if(ai(e)>Nn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Tn(e)}async function Yp(r){if(ai(r)>Nn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ta(r);return new Wr(e.privateKey,e.publicKey)}async function Zp(r){if(r>Nn)throw new O("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await nl(r);return new Wr(e.privateKey,e.publicKey)}var aa={};me(aa,{Secp256k1PrivateKey:()=>_n,Secp256k1PublicKey:()=>Cn,generateKeyPair:()=>lg,unmarshalSecp256k1PrivateKey:()=>cg,unmarshalSecp256k1PublicKey:()=>ug});var Wp=(r,e,t)=>r&e^~r&t,Jp=(r,e,t)=>r&e^r&t^e&t,Xp=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Xt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qt=new Uint32Array(64),na=class extends Dr{constructor(){super(64,32,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Qt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let d=Qt[l-15],E=Qt[l-2],g=Xe(d,7)^Xe(d,18)^d>>>3,h=Xe(E,17)^Xe(E,19)^E>>>10;Qt[l]=h+Qt[l-7]+g+Qt[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Xe(a,6)^Xe(a,11)^Xe(a,25),E=u+d+Wp(a,c,f)+Xp[l]+Qt[l]|0,h=(Xe(n,2)^Xe(n,13)^Xe(n,22))+Jp(n,o,i)|0;u=f,f=c,c=a,a=s+E|0,s=i,i=o,o=n,n=E+h|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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){Qt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var al=oo(()=>new na);function Qp(r){let e=dn(r);ft(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:eg,hexToBytes:tg}=ao,gr={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=gr;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:eg(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=gr,t=typeof r=="string"?tg(r):r;if(!Qe(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:o,l:i}=gr._parseInt(t.subarray(2)),{d:s,l:a}=gr._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(r){let e=f=>Number.parseInt(f[0],16)&8?"00"+f:f,t=f=>{let u=f.toString(16);return u.length&1?`0${u}`:u},n=e(t(r.s)),o=e(t(r.r)),i=n.length/2,s=o.length/2,a=t(i),c=t(s);return`30${t(s+i+4)}02${c}${o}02${a}${n}`}},Ut=BigInt(0),je=BigInt(1),u1=BigInt(2),cl=BigInt(3),l1=BigInt(4);function rg(r){let e=Qp(r),{Fp:t}=e,n=e.toBytes||((g,h,p)=>{let b=h.toAffine();return Bt(Uint8Array.from([4]),t.toBytes(b.x),t.toBytes(b.y))}),o=e.fromBytes||(g=>{let h=g.subarray(1),p=t.fromBytes(h.subarray(0,t.BYTES)),b=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:p,y:b}});function i(g){let{a:h,b:p}=e,b=t.sqr(g),R=t.mul(b,g);return t.add(t.add(R,t.mul(g,h)),p)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&Ut<g&&g<e.n}function a(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){let{allowedPrivateKeyLengths:h,nByteLength:p,wrapPrivateKey:b,n:R}=e;if(h&&typeof g!="bigint"){if(Qe(g)&&(g=Et(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let v;try{v=typeof g=="bigint"?g:vt(ue("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return b&&(v=re(v,R)),a(v),v}let f=new Map;function u(g){if(!(g instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(h,p,b){if(this.px=h,this.py=p,this.pz=b,h==null||!t.isValid(h))throw new Error("x required");if(p==null||!t.isValid(p))throw new Error("y required");if(b==null||!t.isValid(b))throw new Error("z required")}static fromAffine(h){let{x:p,y:b}=h||{};if(!h||!t.isValid(p)||!t.isValid(b))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let R=v=>t.eql(v,t.ZERO);return R(p)&&R(b)?l.ZERO:new l(p,b,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let p=t.invertBatch(h.map(b=>b.pz));return h.map((b,R)=>b.toAffine(p[R])).map(l.fromAffine)}static fromHex(h){let p=l.fromAffine(o(ue("pointHex",h)));return p.assertValidity(),p}static fromPrivateKey(h){return l.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,f.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=this.toAffine();if(!t.isValid(h)||!t.isValid(p))throw new Error("bad point: x or y not FE");let b=t.sqr(p),R=i(h);if(!t.eql(b,R))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:p,py:b,pz:R}=this,{px:v,py:L,pz:S}=h,k=t.eql(t.mul(p,S),t.mul(v,R)),C=t.eql(t.mul(b,S),t.mul(L,R));return k&&C}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:p}=e,b=t.mul(p,cl),{px:R,py:v,pz:L}=this,S=t.ZERO,k=t.ZERO,C=t.ZERO,y=t.mul(R,R),N=t.mul(v,v),D=t.mul(L,L),T=t.mul(R,v);return T=t.add(T,T),C=t.mul(R,L),C=t.add(C,C),S=t.mul(h,C),k=t.mul(b,D),k=t.add(S,k),S=t.sub(N,k),k=t.add(N,k),k=t.mul(S,k),S=t.mul(T,S),C=t.mul(b,C),D=t.mul(h,D),T=t.sub(y,D),T=t.mul(h,T),T=t.add(T,C),C=t.add(y,y),y=t.add(C,y),y=t.add(y,D),y=t.mul(y,T),k=t.add(k,y),D=t.mul(v,L),D=t.add(D,D),y=t.mul(D,T),S=t.sub(S,y),C=t.mul(D,N),C=t.add(C,C),C=t.add(C,C),new l(S,k,C)}add(h){u(h);let{px:p,py:b,pz:R}=this,{px:v,py:L,pz:S}=h,k=t.ZERO,C=t.ZERO,y=t.ZERO,N=e.a,D=t.mul(e.b,cl),T=t.mul(p,v),P=t.mul(b,L),H=t.mul(R,S),J=t.add(p,b),x=t.add(v,L);J=t.mul(J,x),x=t.add(T,P),J=t.sub(J,x),x=t.add(p,R);let A=t.add(v,S);return x=t.mul(x,A),A=t.add(T,H),x=t.sub(x,A),A=t.add(b,R),k=t.add(L,S),A=t.mul(A,k),k=t.add(P,H),A=t.sub(A,k),y=t.mul(N,x),k=t.mul(D,H),y=t.add(k,y),k=t.sub(P,y),y=t.add(P,y),C=t.mul(k,y),P=t.add(T,T),P=t.add(P,T),H=t.mul(N,H),x=t.mul(D,x),P=t.add(P,H),H=t.sub(T,H),H=t.mul(N,H),x=t.add(x,H),T=t.mul(P,x),C=t.add(C,T),T=t.mul(A,x),k=t.mul(J,k),k=t.sub(k,T),T=t.mul(J,P),y=t.mul(A,y),y=t.add(y,T),new l(k,C,y)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return E.wNAFCached(this,f,h,p=>{let b=t.invertBatch(p.map(R=>R.pz));return p.map((R,v)=>R.toAffine(b[v])).map(l.fromAffine)})}multiplyUnsafe(h){let p=l.ZERO;if(h===Ut)return p;if(a(h),h===je)return this;let{endo:b}=e;if(!b)return E.unsafeLadder(this,h);let{k1neg:R,k1:v,k2neg:L,k2:S}=b.splitScalar(h),k=p,C=p,y=this;for(;v>Ut||S>Ut;)v&je&&(k=k.add(y)),S&je&&(C=C.add(y)),y=y.double(),v>>=je,S>>=je;return R&&(k=k.negate()),L&&(C=C.negate()),C=new l(t.mul(C.px,b.beta),C.py,C.pz),k.add(C)}multiply(h){a(h);let p=h,b,R,{endo:v}=e;if(v){let{k1neg:L,k1:S,k2neg:k,k2:C}=v.splitScalar(p),{p:y,f:N}=this.wNAF(S),{p:D,f:T}=this.wNAF(C);y=E.constTimeNegate(L,y),D=E.constTimeNegate(k,D),D=new l(t.mul(D.px,v.beta),D.py,D.pz),b=y.add(D),R=N.add(T)}else{let{p:L,f:S}=this.wNAF(p);b=L,R=S}return l.normalizeZ([b,R])[0]}multiplyAndAddUnsafe(h,p,b){let R=l.BASE,v=(S,k)=>k===Ut||k===je||!S.equals(R)?S.multiplyUnsafe(k):S.multiply(k),L=v(this,p).add(v(h,b));return L.is0()?void 0:L}toAffine(h){let{px:p,py:b,pz:R}=this,v=this.is0();h==null&&(h=v?t.ONE:t.inv(R));let L=t.mul(p,h),S=t.mul(b,h),k=t.mul(R,h);if(v)return{x:t.ZERO,y:t.ZERO};if(!t.eql(k,t.ONE))throw new Error("invZ was invalid");return{x:L,y:S}}isTorsionFree(){let{h,isTorsionFree:p}=e;if(h===je)return!0;if(p)return p(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:p}=e;return h===je?this:p?p(l,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(l,this,h)}toHex(h=!0){return Et(this.toRawBytes(h))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let d=e.nBitLength,E=lo(l,e.endo?Math.ceil(d/2):d);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function ng(r){let e=dn(r);return ft(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ul(r){let e=ng(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(x){return Ut<x&&x<t.ORDER}function a(x){return re(x,n)}function c(x){return co(x,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:d}=rg({...e,toBytes(x,A,M){let B=A.toAffine(),w=t.toBytes(B.x),V=Bt;return M?V(Uint8Array.from([A.hasEvenY()?2:3]),w):V(Uint8Array.from([4]),w,t.toBytes(B.y))},fromBytes(x){let A=x.length,M=x[0],B=x.subarray(1);if(A===o&&(M===2||M===3)){let w=vt(B);if(!s(w))throw new Error("Point is not on curve");let V=l(w),F=t.sqrt(V),$=(F&je)===je;return(M&1)===1!==$&&(F=t.neg(F)),{x:w,y:F}}else if(A===i&&M===4){let w=t.fromBytes(B.subarray(0,t.BYTES)),V=t.fromBytes(B.subarray(t.BYTES,2*t.BYTES));return{x:w,y:V}}else throw new Error(`Point of length ${A} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),E=x=>Et(Gt(x,e.nByteLength));function g(x){let A=n>>je;return x>A}function h(x){return g(x)?a(-x):x}let p=(x,A,M)=>vt(x.slice(A,M));class b{constructor(A,M,B){this.r=A,this.s=M,this.recovery=B,this.assertValidity()}static fromCompact(A){let M=e.nByteLength;return A=ue("compactSignature",A,M*2),new b(p(A,0,M),p(A,M,2*M))}static fromDER(A){let{r:M,s:B}=gr.toSig(ue("DER",A));return new b(M,B)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(A){return new b(this.r,this.s,A)}recoverPublicKey(A){let{r:M,s:B,recovery:w}=this,V=C(ue("msgHash",A));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let F=w===2||w===3?M+e.n:M;if(F>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let $=w&1?"03":"02",z=f.fromHex($+E(F)),G=c(F),te=a(-V*G),Z=a(B*G),X=f.BASE.multiplyAndAddUnsafe(z,te,Z);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return ar(this.toDERHex())}toDERHex(){return gr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ar(this.toCompactHex())}toCompactHex(){return E(this.r)+E(this.s)}}let R={isValidPrivateKey(x){try{return u(x),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let x=ks(e.n);return Zc(e.randomBytes(x),e.n)},precompute(x=8,A=f.BASE){return A._setWindowSize(x),A.multiply(BigInt(3)),A}};function v(x,A=!0){return f.fromPrivateKey(x).toRawBytes(A)}function L(x){let A=Qe(x),M=typeof x=="string",B=(A||M)&&x.length;return A?B===o||B===i:M?B===2*o||B===2*i:x instanceof f}function S(x,A,M=!0){if(L(x))throw new Error("first arg must be private key");if(!L(A))throw new Error("second arg must be public key");return f.fromHex(A).multiply(u(x)).toRawBytes(M)}let k=e.bits2int||function(x){let A=vt(x),M=x.length*8-e.nBitLength;return M>0?A>>BigInt(M):A},C=e.bits2int_modN||function(x){return a(k(x))},y=hn(e.nBitLength);function N(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(Ut<=x&&x<y))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Gt(x,e.nByteLength)}function D(x,A,M=T){if(["recovered","canonical"].some(se=>se in M))throw new Error("sign() legacy options not supported");let{hash:B,randomBytes:w}=e,{lowS:V,prehash:F,extraEntropy:$}=M;V==null&&(V=!0),x=ue("msgHash",x),F&&(x=ue("prehashed msgHash",B(x)));let z=C(x),G=u(A),te=[N(G),N(z)];if($!=null){let se=$===!0?w(t.BYTES):$;te.push(ue("extraEntropy",se))}let Z=Bt(...te),X=z;function he(se){let be=k(se);if(!d(be))return;let xe=c(be),pe=f.BASE.multiply(be).toAffine(),Ae=a(pe.x);if(Ae===Ut)return;let wt=a(xe*a(X+Ae*G));if(wt===Ut)return;let rr=(pe.x===Ae?0:2)|Number(pe.y&je),nn=wt;return V&&g(wt)&&(nn=h(wt),rr^=1),new b(Ae,nn,rr)}return{seed:Z,k2sig:he}}let T={lowS:e.lowS,prehash:!1},P={lowS:e.lowS,prehash:!1};function H(x,A,M=T){let{seed:B,k2sig:w}=D(x,A,M),V=e;return As(V.hash.outputLen,V.nByteLength,V.hmac)(B,w)}f.BASE._setWindowSize(8);function J(x,A,M,B=P){let w=x;if(A=ue("msgHash",A),M=ue("publicKey",M),"strict"in B)throw new Error("options.strict was renamed to lowS");let{lowS:V,prehash:F}=B,$,z;try{if(typeof w=="string"||Qe(w))try{$=b.fromDER(w)}catch(pe){if(!(pe instanceof gr.Err))throw pe;$=b.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:pe,s:Ae}=w;$=new b(pe,Ae)}else throw new Error("PARSE");z=f.fromHex(M)}catch(pe){if(pe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(V&&$.hasHighS())return!1;F&&(A=e.hash(A));let{r:G,s:te}=$,Z=C(A),X=c(te),he=a(Z*X),se=a(G*X),be=f.BASE.multiplyAndAddUnsafe(z,he,se)?.toAffine();return be?a(be.x)===G:!1}return{CURVE:e,getPublicKey:v,getSharedSecret:S,sign:H,verify:J,ProjectivePoint:f,Signature:b,utils:R}}function og(r){return{hash:r,hmac:(e,...t)=>bn(r,e,no(...t)),randomBytes:Vr}}function ll(r,e){let t=n=>ul({...r,...og(n)});return Object.freeze({...t(e),create:t})}var dl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),fl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ig=BigInt(1),oa=BigInt(2),hl=(r,e)=>(r+e/oa)/e;function sg(r){let e=dl,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=ie(u,t,e)*u%e,d=ie(l,t,e)*u%e,E=ie(d,oa,e)*f%e,g=ie(E,o,e)*E%e,h=ie(g,i,e)*g%e,p=ie(h,a,e)*h%e,b=ie(p,c,e)*p%e,R=ie(b,a,e)*h%e,v=ie(R,t,e)*u%e,L=ie(v,s,e)*g%e,S=ie(L,n,e)*f%e,k=ie(S,oa,e);if(!ia.eql(ia.sqr(k),r))throw new Error("Cannot find square root");return k}var ia=uo(dl,void 0,void 0,{sqrt:sg}),ot=ll({a:BigInt(0),b:BigInt(7),Fp:ia,n:fl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=fl,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ig*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=hl(i*r,e),c=hl(-n*r,e),f=re(r-a*t-c*o,e),u=re(-a*n-c*i,e),l=f>s,d=u>s;if(l&&(f=e-f),d&&(u=e-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},al),b1=BigInt(0);var x1=ot.ProjectivePoint;function pl(){return ot.utils.randomPrivateKey()}function gl(r,e){let t=Ee.digest(e instanceof Uint8Array?e:e.subarray());if(ze(t))return t.then(({digest:n})=>ot.sign(n,r).toDERRawBytes()).catch(n=>{throw new O(String(n),"ERR_INVALID_INPUT")});try{return ot.sign(t.digest,r).toDERRawBytes()}catch(n){throw new O(String(n),"ERR_INVALID_INPUT")}}function ml(r,e,t){let n=Ee.digest(t instanceof Uint8Array?t:t.subarray());if(ze(n))return n.then(({digest:o})=>ot.verify(e,o,r)).catch(o=>{throw new O(String(o),"ERR_INVALID_INPUT")});try{return ot.verify(e,n.digest,r)}catch(o){throw new O(String(o),"ERR_INVALID_INPUT")}}function yl(r){return ot.ProjectivePoint.fromHex(r).toRawBytes(!0)}function wl(r){try{ot.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}function sa(r){try{ot.ProjectivePoint.fromHex(r)}catch(e){throw new O(String(e),"ERR_INVALID_PUBLIC_KEY")}}function bl(r){try{return ot.getPublicKey(r,!0)}catch(e){throw new O(String(e),"ERR_INVALID_PRIVATE_KEY")}}var Cn=class{_key;constructor(e){sa(e),this._key=e}verify(e,t){return ml(this._key,t,e)}marshal(){return yl(this._key)}get bytes(){return ht.encode({Type:fe.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=Ee.digest(this.bytes),t;return ze(e)?{bytes:t}=await e:t=e.bytes,t}},_n=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??bl(e),wl(this._key),sa(this._publicKey)}sign(e){return gl(this._key,e)}get public(){return new Cn(this._publicKey)}marshal(){return this._key}get bytes(){return It.encode({Type:fe.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=Ee.digest(this.bytes);return ze(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Mr(this.bytes,e);throw new O(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function cg(r){return new _n(r)}function ug(r){return new Cn(r)}async function lg(){let r=pl();return new _n(r)}var ci={rsa:ra,ed25519:Gs,secp256k1:aa};function fg(r){let e=Object.keys(ci).join(" / ");return new O(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function ca(r){let e=ht.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case fe.RSA:return ci.rsa.unmarshalRsaPublicKey(t);case fe.Ed25519:return ci.ed25519.unmarshalEd25519PublicKey(t);case fe.Secp256k1:return ci.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw fg(e.Type??"unknown")}}var Gg=Dt(ui(),1);var dg="/",pg=new TextEncoder().encode(dg),O1=pg[0];var jg=Dt(la(),1);var vl="ERR_IPNS_EXPIRED_RECORD",li="ERR_UNRECOGNIZED_VALIDITY";var Lt="ERR_SIGNATURE_VERIFICATION";var fa="ERR_UNDEFINED_PARAMETER",Bl="ERR_INVALID_RECORD_DATA",Al="ERR_INVALID_VALUE",Sl="ERR_INVALID_EMBEDDED_KEY";var Il="ERR_RECORD_TOO_LARGE";var it;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>yn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=qr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.value=o.bytes();break;case 2:s.signatureV1=o.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(o);break;case 4:s.validity=o.bytes();break;case 5:s.sequence=o.uint64();break;case 6:s.ttl=o.uint64();break;case 7:s.pubKey=o.bytes();break;case 8:s.signatureV2=o.bytes();break;case 9:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>Kr(o,r.codec()),r.decode=o=>Hr(o,r.codec())})(it||(it={}));var gg=["string","number","bigint","symbol"],mg=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function kl(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(gg.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(yg(r))return"Buffer";let t=wg(r);return t||"Object"}function yg(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function wg(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(mg.includes(e))return e}var m=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};m.uint=new m(0,"uint",!0);m.negint=new m(1,"negint",!0);m.bytes=new m(2,"bytes",!0);m.string=new m(3,"string",!0);m.array=new m(4,"array",!1);m.map=new m(5,"map",!1);m.tag=new m(6,"tag",!1);m.float=new m(7,"float",!0);m.false=new m(7,"false",!0);m.true=new m(7,"true",!0);m.null=new m(7,"null",!0);m.undefined=new m(7,"undefined",!0);m.break=new m(7,"break",!0);var U=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Jr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",bg=new TextDecoder,xg=new TextEncoder;function fi(r){return Jr&&globalThis.Buffer.isBuffer(r)}function _l(r){return r instanceof Uint8Array?fi(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Ul=Jr?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Nl(r,e,t):(r,e,t)=>t-e>64?bg.decode(r.subarray(e,t)):Nl(r,e,t),Ll=Jr?r=>r.length>64?globalThis.Buffer.from(r):Tl(r):r=>r.length>64?xg.encode(r):Tl(r);var Xr=Jr?(r,e,t)=>fi(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Vl=Jr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),_l(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Dl=Jr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Ol(r,e){if(fi(r)&&fi(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Tl(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function Nl(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],f=r[e+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Eg(n)}var Cl=4096;function Eg(r){let e=r.length;if(e<=Cl)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Cl));return t}var vg=256,hi=class{constructor(e=vg){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Dl(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Xr(n,0,this.cursor)}else t=Vl(this.chunks,this.cursor);return e&&this.reset(),t}};var K="CBOR decode error:",ha="CBOR encode error:",Un=[];Un[23]=1;Un[24]=2;Un[25]=3;Un[26]=5;Un[27]=9;function Vt(r,e,t){if(r.length-e<t)throw new Error(`${K} not enough data for type`)}var we=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Me(r,e,t){Vt(r,e,1);let n=r[e];if(t.strict===!0&&n<we[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function He(r,e,t){Vt(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<we[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ke(r,e,t){Vt(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<we[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function $e(r,e,t){Vt(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<we[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function Pl(r,e,t,n){return new U(m.uint,Me(r,e+1,n),2)}function Fl(r,e,t,n){return new U(m.uint,He(r,e+1,n),3)}function Ml(r,e,t,n){return new U(m.uint,Ke(r,e+1,n),5)}function Hl(r,e,t,n){return new U(m.uint,$e(r,e+1,n),9)}function Ye(r,e){return Be(r,0,e.value)}function Be(r,e,t){if(t<we[0]){let n=Number(t);r.push([e|n])}else if(t<we[1]){let n=Number(t);r.push([e|24,n])}else if(t<we[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<we[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<we[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}Ye.encodedSize=function(e){return Be.encodedSize(e.value)};Be.encodedSize=function(e){return e<we[0]?1:e<we[1]?2:e<we[2]?3:e<we[3]?5:9};Ye.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Kl(r,e,t,n){return new U(m.negint,-1-Me(r,e+1,n),2)}function $l(r,e,t,n){return new U(m.negint,-1-He(r,e+1,n),3)}function ql(r,e,t,n){return new U(m.negint,-1-Ke(r,e+1,n),5)}var da=BigInt(-1),zl=BigInt(1);function Gl(r,e,t,n){let o=$e(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new U(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new U(m.negint,da-BigInt(o),9)}function di(r,e){let t=e.value,n=typeof t=="bigint"?t*da-zl:t*-1-1;Be(r,e.type.majorEncoded,n)}di.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*da-zl:t*-1-1;return n<we[0]?1:n<we[1]?2:n<we[2]?3:n<we[3]?5:9};di.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Ln(r,e,t,n){Vt(r,e,t+n);let o=Xr(r,e+t,e+t+n);return new U(m.bytes,o,t+n)}function jl(r,e,t,n){return Ln(r,e,1,t)}function Yl(r,e,t,n){return Ln(r,e,2,Me(r,e+1,n))}function Zl(r,e,t,n){return Ln(r,e,3,He(r,e+1,n))}function Wl(r,e,t,n){return Ln(r,e,5,Ke(r,e+1,n))}function Jl(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return Ln(r,e,9,o)}function pi(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===m.string?Ll(r.value):r.value),r.encodedBytes}function Qr(r,e){let t=pi(e);Be(r,e.type.majorEncoded,t.length),r.push(t)}Qr.encodedSize=function(e){let t=pi(e);return Be.encodedSize(t.length)+t.length};Qr.compareTokens=function(e,t){return Ag(pi(e),pi(t))};function Ag(r,e){return r.length<e.length?-1:r.length>e.length?1:Ol(r,e)}function Vn(r,e,t,n,o){let i=t+n;Vt(r,e,i);let s=new U(m.string,Ul(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Xr(r,e+t,e+i)),s}function Xl(r,e,t,n){return Vn(r,e,1,t,n)}function Ql(r,e,t,n){return Vn(r,e,2,Me(r,e+1,n),n)}function ef(r,e,t,n){return Vn(r,e,3,He(r,e+1,n),n)}function tf(r,e,t,n){return Vn(r,e,5,Ke(r,e+1,n),n)}function rf(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return Vn(r,e,9,o,n)}var nf=Qr;function en(r,e,t,n){return new U(m.array,n,t)}function of(r,e,t,n){return en(r,e,1,t)}function sf(r,e,t,n){return en(r,e,2,Me(r,e+1,n))}function af(r,e,t,n){return en(r,e,3,He(r,e+1,n))}function cf(r,e,t,n){return en(r,e,5,Ke(r,e+1,n))}function uf(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return en(r,e,9,o)}function lf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return en(r,e,1,1/0)}function gi(r,e){Be(r,m.array.majorEncoded,e.value)}gi.compareTokens=Ye.compareTokens;gi.encodedSize=function(e){return Be.encodedSize(e.value)};function tn(r,e,t,n){return new U(m.map,n,t)}function ff(r,e,t,n){return tn(r,e,1,t)}function hf(r,e,t,n){return tn(r,e,2,Me(r,e+1,n))}function df(r,e,t,n){return tn(r,e,3,He(r,e+1,n))}function pf(r,e,t,n){return tn(r,e,5,Ke(r,e+1,n))}function gf(r,e,t,n){let o=$e(r,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return tn(r,e,9,o)}function mf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return tn(r,e,1,1/0)}function mi(r,e){Be(r,m.map.majorEncoded,e.value)}mi.compareTokens=Ye.compareTokens;mi.encodedSize=function(e){return Be.encodedSize(e.value)};function yf(r,e,t,n){return new U(m.tag,t,1)}function wf(r,e,t,n){return new U(m.tag,Me(r,e+1,n),2)}function bf(r,e,t,n){return new U(m.tag,He(r,e+1,n),3)}function xf(r,e,t,n){return new U(m.tag,Ke(r,e+1,n),5)}function Ef(r,e,t,n){return new U(m.tag,$e(r,e+1,n),9)}function yi(r,e){Be(r,m.tag.majorEncoded,e.value)}yi.compareTokens=Ye.compareTokens;yi.encodedSize=function(e){return Be.encodedSize(e.value)};var Ng=20,Cg=21,_g=22,Ug=23;function vf(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new U(m.null,null,1):new U(m.undefined,void 0,1)}function Bf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new U(m.break,void 0,1)}function pa(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${K} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new U(m.float,r,e)}function Af(r,e,t,n){return pa(ga(r,e+1),3,n)}function Sf(r,e,t,n){return pa(ma(r,e+1),5,n)}function If(r,e,t,n){return pa(Nf(r,e+1),9,n)}function wi(r,e,t){let n=e.value;if(n===!1)r.push([m.float.majorEncoded|Ng]);else if(n===!0)r.push([m.float.majorEncoded|Cg]);else if(n===null)r.push([m.float.majorEncoded|_g]);else if(n===void 0)r.push([m.float.majorEncoded|Ug]);else{let o,i=!1;(!t||t.float64!==!0)&&(kf(n),o=ga(st,1),n===o||Number.isNaN(n)?(st[0]=249,r.push(st.slice(0,3)),i=!0):(Tf(n),o=ma(st,1),n===o&&(st[0]=250,r.push(st.slice(0,5)),i=!0))),i||(Lg(n),o=Nf(st,1),st[0]=251,r.push(st.slice(0,9)))}}wi.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){kf(n);let o=ga(st,1);if(n===o||Number.isNaN(n))return 3;if(Tf(n),o=ma(st,1),n===o)return 5}return 9};var Rf=new ArrayBuffer(9),Ze=new DataView(Rf,1),st=new Uint8Array(Rf,0);function kf(r){if(r===1/0)Ze.setUint16(0,31744,!1);else if(r===-1/0)Ze.setUint16(0,64512,!1);else if(Number.isNaN(r))Ze.setUint16(0,32256,!1);else{Ze.setFloat32(0,r);let e=Ze.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Ze.setUint16(0,31744,!1);else if(t===0)Ze.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Ze.setUint16(0,0):o<-14?Ze.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Ze.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ga(r,e){if(r.length-e<2)throw new Error(`${K} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Tf(r){Ze.setFloat32(0,r,!1)}function ma(r,e){if(r.length-e<4)throw new Error(`${K} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Lg(r){Ze.setFloat64(0,r,!1)}function Nf(r,e){if(r.length-e<8)throw new Error(`${K} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}wi.compareTokens=Ye.compareTokens;function Q(r,e,t){throw new Error(`${K} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function bi(r){return()=>{throw new Error(`${K} ${r}`)}}var I=[];for(let r=0;r<=23;r++)I[r]=Q;I[24]=Pl;I[25]=Fl;I[26]=Ml;I[27]=Hl;I[28]=Q;I[29]=Q;I[30]=Q;I[31]=Q;for(let r=32;r<=55;r++)I[r]=Q;I[56]=Kl;I[57]=$l;I[58]=ql;I[59]=Gl;I[60]=Q;I[61]=Q;I[62]=Q;I[63]=Q;for(let r=64;r<=87;r++)I[r]=jl;I[88]=Yl;I[89]=Zl;I[90]=Wl;I[91]=Jl;I[92]=Q;I[93]=Q;I[94]=Q;I[95]=bi("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)I[r]=Xl;I[120]=Ql;I[121]=ef;I[122]=tf;I[123]=rf;I[124]=Q;I[125]=Q;I[126]=Q;I[127]=bi("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)I[r]=of;I[152]=sf;I[153]=af;I[154]=cf;I[155]=uf;I[156]=Q;I[157]=Q;I[158]=Q;I[159]=lf;for(let r=160;r<=183;r++)I[r]=ff;I[184]=hf;I[185]=df;I[186]=pf;I[187]=gf;I[188]=Q;I[189]=Q;I[190]=Q;I[191]=mf;for(let r=192;r<=215;r++)I[r]=yf;I[216]=wf;I[217]=bf;I[218]=xf;I[219]=Ef;I[220]=Q;I[221]=Q;I[222]=Q;I[223]=Q;for(let r=224;r<=243;r++)I[r]=bi("simple values are not supported");I[244]=Q;I[245]=Q;I[246]=Q;I[247]=vf;I[248]=bi("simple values are not supported");I[249]=Af;I[250]=Sf;I[251]=If;I[252]=Q;I[253]=Q;I[254]=Q;I[255]=Bf;var at=[];for(let r=0;r<24;r++)at[r]=new U(m.uint,r,1);for(let r=-1;r>=-24;r--)at[31-r]=new U(m.negint,r,1);at[64]=new U(m.bytes,new Uint8Array(0),1);at[96]=new U(m.string,"",1);at[128]=new U(m.array,0,1);at[160]=new U(m.map,0,1);at[244]=new U(m.false,!1,1);at[245]=new U(m.true,!0,1);at[246]=new U(m.null,null,1);function Dg(){let r=[];return r[m.uint.major]=Ye,r[m.negint.major]=di,r[m.bytes.major]=Qr,r[m.string.major]=nf,r[m.array.major]=gi,r[m.map.major]=mi,r[m.tag.major]=yi,r[m.float.major]=wi,r}var LE=Dg(),VE=new hi,xi=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${ha} object contains circular references`);return new r(t,e)}},er={null:new U(m.null,null),undefined:new U(m.undefined,void 0),true:new U(m.true,!0),false:new U(m.false,!1),emptyArray:new U(m.array,0),emptyMap:new U(m.map,0)},tr={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new U(m.float,r):r>=0?new U(m.uint,r):new U(m.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new U(m.uint,r):new U(m.negint,r)},Uint8Array(r,e,t,n){return new U(m.bytes,r)},string(r,e,t,n){return new U(m.string,r)},boolean(r,e,t,n){return r?er.true:er.false},null(r,e,t,n){return er.null},undefined(r,e,t,n){return er.undefined},ArrayBuffer(r,e,t,n){return new U(m.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new U(m.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[er.emptyArray,new U(m.break)]:er.emptyArray;n=xi.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=ya(s,t,n);return t.addBreakTokens?[new U(m.array,r.length),o,new U(m.break)]:[new U(m.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[er.emptyMap,new U(m.break)]:er.emptyMap;n=xi.createCheck(n,r);let a=[],c=0;for(let f of i)a[c++]=[ya(f,t,n),ya(o?r.get(f):r[f],t,n)];return Og(a,t),t.addBreakTokens?[new U(m.map,s),a,new U(m.break)]:[new U(m.map,s),a]}};tr.Map=tr.Object;tr.Buffer=tr.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))tr[`${r}Array`]=tr.DataView;function ya(r,e={},t){let n=kl(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||tr[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=tr[n];if(!i)throw new Error(`${ha} unsupported type: ${n}`);return i(r,n,e,t)}function Og(r,e){e.mapSorter&&r.sort(e.mapSorter)}var Pg={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},wa=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=at[e];if(t===void 0){let n=I[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Dn=Symbol.for("DONE"),Ei=Symbol.for("BREAK");function Fg(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=On(e,t);if(i===Ei){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Dn)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Mg(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=On(e,t);if(a===Ei){if(r.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(a===Dn)throw new Error(`${K} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${K} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${K} found repeat map key "${a}"`);let c=On(e,t);if(c===Dn)throw new Error(`${K} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function On(r,e){if(r.done())return Dn;let t=r.next();if(t.type===m.break)return Ei;if(t.type.terminal)return t.value;if(t.type===m.array)return Fg(t,r,e);if(t.type===m.map)return Mg(t,r,e);if(t.type===m.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=On(r,e);return e.tags[t.value](n)}throw new Error(`${K} tag not supported (${t.value})`)}throw new Error("unsupported")}function Cf(r,e){if(!(r instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},Pg,e);let t=e.tokenizer||new wa(r,e),n=On(t,e);if(n===Dn)throw new Error(`${K} did not find any content to decode`);if(n===Ei)throw new Error(`${K} got unexpected break`);return[n,r.subarray(t.pos())]}function ba(r,e){let[t,n]=Cf(r,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return t}var qe=Dt(ui(),1);var _f=Pt("ipns:utils"),Uf=j("/ipns/"),$g=114,Lf=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw _f.error(n),(0,qe.default)(n,fa)}let t;if(e.pubKey!=null){try{t=ca(e.pubKey)}catch(o){throw _f.error(o),o}if(!(await pc(e.pubKey)).equals(r))throw(0,qe.default)(new Error("Embedded public key did not match PeerID"),Sl)}else r.publicKey!=null&&(t=ca(r.publicKey));if(t!=null)return t;throw(0,qe.default)(new Error("no public key is available"),fa)};var Vf=r=>{let e=j("ipns-signature:");return Ne([e,r])},yr=r=>"signatureV1"in r?it.encode({value:j(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:j(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):it.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function mt(r){let e=it.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,qe.default)(new Error("missing data or signatureV2"),Lt);let t=Df(e.data),n=qg(t.Value),o=W(t.Validity);if(e.value!=null&&e.signatureV1!=null)return zg(e),{value:n,validityType:it.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:it.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var xa=r=>Ne([Uf,r.toBytes()]),rn=r=>ln(r.slice(Uf.length));var Df=r=>{let e=ba(r);if(e.ValidityType===0)e.ValidityType=it.ValidityType.EOL;else throw(0,qe.default)(new Error("Unknown validity type"),li);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},qg=r=>{if(r!=null){if(Fa(r))return`/ipns/${r.toCID().toString(jn)}`;if(r instanceof Uint8Array){let n=W(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=Te.asCID(r);if(t!=null)return t.code===$g?`/ipns/${t.toString(jn)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${Te.decode(r).toV1().toString()}`:`/ipfs/${Te.parse(e).toV1().toString()}`}catch{}}throw(0,qe.default)(new Error("Value must be a valid content path starting with /"),Al)},zg=r=>{if(r.data==null)throw(0,qe.default)(new Error("Record data is missing"),Bl);let e=Df(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw(0,qe.default)(new Error('Field "value" did not match between protobuf and CBOR'),Lt);if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw(0,qe.default)(new Error('Field "validity" did not match between protobuf and CBOR'),Lt);if(e.ValidityType!==r.validityType)throw(0,qe.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),Lt);if(e.Sequence!==r.sequence)throw(0,qe.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),Lt);if(e.TTL!==r.ttl)throw(0,qe.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),Lt)};var u2=Pt("ipns"),l2=ut.code,Yg="/ipns/",f2=Yg.length;var Pn=Dt(ui(),1),Of=Dt(la(),1);var vi=Pt("ipns:validator"),Zg=1024*10,Wg=async(r,e)=>{let t=mt(e),n;try{let o=Vf(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw vi.error("record signature verification failed"),(0,Pn.default)(new Error("record signature verification failed"),Lt);if(t.validityType===it.ValidityType.EOL){if(Of.default.fromString(t.validity).toDate().getTime()<Date.now())throw vi.error("record has expired"),(0,Pn.default)(new Error("record has expired"),vl)}else if(t.validityType!=null)throw vi.error("unrecognized validity type"),(0,Pn.default)(new Error("unrecognized validity type"),li);vi("ipns record for %s is valid",t.value)};async function Pf(r,e){if(e.byteLength>Zg)throw(0,Pn.default)(new Error("record too large"),Il);let t=rn(r),n=mt(e),o=await Lf(t,n);await Wg(o,e)}async function*Fn(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let o of r){typeof o=="string"&&(o=new TextEncoder().encode(o)),n+=t.decode(o,{stream:!0});let i=n.split(e);n=i.pop()??"";for(let s=0;s<i.length;s++)yield JSON.parse(i[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}function yt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var va=Dt(Mf(),1);var Hn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ba=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Hf=r=>globalThis.DOMException===void 0?new Ba(r):new DOMException(r),Kf=r=>{let e=r.reason===void 0?Hf("This operation was aborted."):r.reason;return e instanceof Error?e:Hf(e)};function Aa(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&u(Kf(d)),d.addEventListener("abort",()=>{u(Kf(d))})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new Hn;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?u(o):(l.message=o??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(d){u(d)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}function Sa(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Kn=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=Sa(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var $n=class extends va.default{#e;#r;#i=0;#a;#c;#p=0;#n;#u;#t;#g;#o=0;#l;#s;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Kn,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#r=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#t=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#s=e.autoStart===!1}get#b(){return this.#r||this.#i<this.#a}get#x(){return this.#o<this.#l}#E(){this.#o--,this.#f(),this.emit("next")}#v(){this.#w(),this.#y(),this.#u=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#o:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#s){let e=!this.#B;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#r||this.#n!==void 0||(this.#n=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#i===0&&this.#o===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#o:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#h()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#m,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#o++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Aa(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Hn&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#s?(this.#s=!1,this.#h(),this):this}pause(){this.#s=!0}clear(){this.#t=new this.#g}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#o===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#s}};function Qg(r){return r[Symbol.asyncIterator]!=null}function em(r){if(Qg(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Ai=em;function tm(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var $f=tm;function rm(r){return r[Symbol.asyncIterator]!=null}function nm(r,e){if(rm(r))return async function*(){for await(let a of r)yield e(a)}();let t=$f(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){yield await i;for await(let a of t)yield e(a)}();let s=e;return function*(){yield i;for(let a of t)yield s(a)}()}var Si=nm;var Ia=j("/ipns/");function qf(r){return ce(r.subarray(0,Ia.byteLength),Ia)}var zf=r=>ln(r.slice(Ia.length)),Ii=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*Si(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!qf(e))return;let o=zf(e),i=mt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!qf(e))throw new O("Not found","ERR_NOT_FOUND");let n=zf(e);try{let o=await this.client.getIPNS(n,t);return yr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):o}}},Ri=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Ai(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){}};var De=Pt("delegated-routing-v1-http-api-client"),Gf={concurrentRequests:4,timeout:3e4},ki=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,Ha(1/0,this.shutDownController.signal),this.httpQueue=new $n({concurrency:t.concurrentRequests??Gf.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??Gf.timeout,this.contentRouting=new Ii(this),this.peerRouting=new Ri(this)}get[Pa](){return this.contentRouting}get[Ma](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,t={}){De("getProviders starts: %c",e);let n=fn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=yt(),i=yt();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let u=await c.json();for(let l of u.Providers){let d=this.#e(l);d!=null&&(yield d)}}else for await(let u of Fn(eo(c.body))){let l=this.#e(u);l!=null&&(yield l)}}catch(s){De.error("getProviders errored:",s)}finally{n.clear(),i.resolve(),De("getProviders finished: %c",e)}}async*getPeers(e,t={}){De("getPeers starts: %c",e);let n=fn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=yt(),i=yt();this.httpQueue.add(async()=>(o.resolve(),i.promise));try{await o.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let u=await c.json();for(let l of u.Peers){let d=this.#e(l);d!=null&&(yield d)}}else for await(let u of Fn(eo(c.body))){let l=this.#e(u);l!=null&&(yield l)}}catch(s){De.error("getPeers errored:",s)}finally{n.clear(),i.resolve(),De("getPeers finished: %c",e)}}async getIPNS(e,t={}){De("getIPNS starts: %c",e);let n=fn([this.shutDownController.signal,t.signal,AbortSignal.timeout(this.timeout)]),o=yt(),i=yt();this.httpQueue.add(async()=>(o.resolve(),i.promise));let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await o.promise;let c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(De("getIPNS GET %s %d",s,c.status),c.status===404)throw new O("No matching records found.","ERR_NOT_FOUND");if(c.status===422)throw new O("Request does not conform to schema or semantic constraints.","ERR_INVALID_REQUEST");if(c.body==null)throw new O("GET ipns response had no body","ERR_BAD_RESPONSE");let f=await c.arrayBuffer(),u=new Uint8Array(f,0,f.byteLength);return t.validate!==!1&&await Pf(xa(e),u),mt(u)}catch(a){throw De.error("getIPNS GET %s error:",s,a),a}finally{n.clear(),i.resolve(),De("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){De("putIPNS starts: %c",e);let o=fn([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),i=yt(),s=yt();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;try{await i.promise;let c=yr(t),u=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:c,signal:o});if(De("putIPNS PUT %s %d",a,u.status),u.status!==200)throw new O("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}catch(c){throw De.error("putIPNS PUT %s error:",a,c.stack),c}finally{o.clear(),s.resolve(),De("putIPNS finished: %c",e)}}#e(e){let t=[],n=e.Addrs?.map(ys)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:Qi(e.ID),Addrs:n,Protocols:t}}};function jf(r,e={}){return new ki(new URL(r),e)}var Yf=j("/ipns/");function Zf(r){return ce(r.subarray(0,Yf.byteLength),Yf)}var Ra=class{client;constructor(e){this.client=jf(e)}async provide(e,t){}async*findProviders(e,t){yield*Si(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!Zf(e))return;let o=rn(e),i=mt(t);await this.client.putIPNS(o,i,n)}async get(e,t){if(!Zf(e))throw new O("Not found","ERR_NOT_FOUND");let n=rn(e);try{let o=await this.client.getIPNS(n,t);return yr(o)}catch(o){throw o.code==="ERR_BAD_RESPONSE"?new O("Not found","ERR_NOT_FOUND"):o}}async findPeer(e,t){let n=await Ai(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new O("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,t){}};function Wf(r){return new Ra(new URL(r))}var ka=class{libp2p;constructor(e){this.libp2p=e}async provide(e,t){await this.libp2p.contentRouting.provide(e,t)}async*findProviders(e,t){yield*this.libp2p.contentRouting.findProviders(e,t)}async put(e,t,n){await this.libp2p.contentRouting.put(e,t,n)}async get(e,t){return this.libp2p.contentRouting.get(e,t)}async findPeer(e,t){return this.libp2p.peerRouting.findPeer(e,t)}async*getClosestPeers(e,t){yield*this.libp2p.peerRouting.getClosestPeers(e,t)}};function Jf(r){return new ka(r)}return fh(om);})();
|
|
9
9
|
/*! Bundled license information:
|
|
10
10
|
|
|
11
11
|
pvtsutils/build/index.js:
|