@libp2p/circuit-relay-v2 3.2.2 → 3.2.3-4939ef7ae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,9 +1,9 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCircuitRelayV2 = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PCircuitRelayV2=(()=>{var Cf=Object.create;var Sn=Object.defineProperty;var Nf=Object.getOwnPropertyDescriptor;var Rf=Object.getOwnPropertyNames;var Lf=Object.getPrototypeOf,Uf=Object.prototype.hasOwnProperty;var Df=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ke=(r,e)=>{for(var t in e)Sn(r,t,{get:e[t],enumerable:!0})},rc=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Rf(e))!Uf.call(r,s)&&s!==t&&Sn(r,s,{get:()=>e[s],enumerable:!(n=Nf(e,s))||n.enumerable});return r};var Of=(r,e,t)=>(t=r!=null?Cf(Lf(r)):{},rc(e||!r||!r.__esModule?Sn(t,"default",{value:r,enumerable:!0}):t,r)),Mf=r=>rc(Sn({},"__esModule",{value:!0}),r);var ll=Df(vr=>{"use strict";var op="[object ArrayBuffer]",wt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===op}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),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[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 o of t)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of t){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Wo="string",ap=/^[0-9a-f\s]+$/i,cp=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,lp=/^[a-zA-Z0-9-_]+$/,Gn=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=wt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},$e=class{static toString(e,t=!1){let n=wt.toArrayBuffer(e),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return n}},Wn=class r{static isHex(e){return typeof e===Wo&&ap.test(e)}static isBase64(e){return typeof e===Wo&&cp.test(e)}static isBase64Url(e){return typeof e===Wo&&lp.test(e)}static ToString(e,t="utf8"){let n=wt.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 $e.toString(n,!0);case"utf16":case"utf16be":return $e.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 $e.fromString(e,!0);case"utf16":case"utf16be":return $e.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=wt.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 Gn.fromString(e);case"utf16":case"utf16be":return $e.fromString(e);case"utf16le":case"usc2":return $e.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 Gn.toString(e);case"utf16":case"utf16be":return $e.toString(e);case"utf16le":case"usc2":return $e.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 s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=wt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=wt.toUint8Array(e),n="",s=t.length;for(let i=0;i<s;i++){let o=t[i];o<16&&(n+="0"),n+=o.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 s=0;s<t.length;s=s+2){let i=t.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return $e.toString(e,t)}static FromUtf16String(e,t=!1){return $e.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,"")||""}};Wn.DEFAULT_UTF8_ENCODING="utf8";function up(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)t[i]=s[i]}return t}function fp(...r){let e=r.map(s=>s.byteLength).reduce((s,i)=>s+i),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)t[n++]=i}),t.buffer}function hp(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}vr.BufferSourceConverter=wt;vr.Convert=Wn;vr.assign=up;vr.combine=fp;vr.isEqual=hp});var _0={};ke(_0,{RELAY_V2_HOP_CODEC:()=>Ge,RELAY_V2_STOP_CODEC:()=>nr,circuitRelayServer:()=>lf,circuitRelayTransport:()=>vf});var Mi=Symbol.for("@libp2p/peer-id");var Pi="keep-alive";var sc=Symbol.for("@libp2p/transport");var nc;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(nc||(nc={}));var ut=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ar=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var An=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Bn=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Pr=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}},$t=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}};var cr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ke=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:i})=>i!==t),this.#e.set(e,s))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:s})=>!s),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function ic(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function oc(...r){let e=[];for(let t of r)ic(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function ac(...r){let e=[];for(let t of r)ic(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var cc=Symbol.for("@libp2p/service-capabilities"),lc=Symbol.for("@libp2p/service-dependencies");var qi={};ke(qi,{base58btc:()=>J,base58flickr:()=>qf});var rm=new Uint8Array(0);function uc(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 ft(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 fc(r){return new TextEncoder().encode(r)}function hc(r){return new TextDecoder().decode(r)}function Pf(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 s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var b=0,d=0,x=0,E=y.length;x!==E&&y[x]===0;)x++,b++;for(var g=(E-x)*l+1>>>0,_=new Uint8Array(g);x!==E;){for(var N=y[x],R=0,I=g-1;(N!==0||R<d)&&I!==-1;I--,R++)N+=256*_[I]>>>0,_[I]=N%a>>>0,N=N/a>>>0;if(N!==0)throw new Error("Non-zero carry");d=R,x++}for(var C=g-d;C!==g&&_[C]===0;)C++;for(var T=c.repeat(b);C<g;++C)T+=r.charAt(_[C]);return T}function h(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var b=0;if(y[b]!==" "){for(var d=0,x=0;y[b]===c;)d++,b++;for(var E=(y.length-b)*u+1>>>0,g=new Uint8Array(E);y[b];){var _=t[y.charCodeAt(b)];if(_===255)return;for(var N=0,R=E-1;(_!==0||N<x)&&R!==-1;R--,N++)_+=a*g[R]>>>0,g[R]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");x=N,b++}if(y[b]!==" "){for(var I=E-x;I!==E&&g[I]===0;)I++;for(var C=new Uint8Array(d+(E-I)),T=d;I!==E;)C[T++]=g[I++];return C}}}function p(y){var b=h(y);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var Vf=Pf,Hf=Vf,pc=Hf;var Vi=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")}},Hi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 mc(this,e)}},Fi=class{decoders;constructor(e){this.decoders=e}or(e){return mc(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 mc(r,e){return new Fi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ki=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Vi(e,t,n),this.decoder=new Hi(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function lr({name:r,prefix:e,encode:t,decode:n}){return new Ki(r,e,t,n)}function Tt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=pc(t,r);return lr({prefix:e,name:r,encode:n,decode:i=>ft(s(i))})}function Ff(r,e,t,n){let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let l=0;l<i;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Kf(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;i.length*t&7;)i+="=";return i}function ce({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return lr({prefix:e,name:r,encode(s){return Kf(s,n,t)},decode(s){return Ff(s,n,t,r)}})}var J=Tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qf=Tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zi={};ke(zi,{base32:()=>ht,base32hex:()=>Wf,base32hexpad:()=>jf,base32hexpadupper:()=>Yf,base32hexupper:()=>Zf,base32pad:()=>$f,base32padupper:()=>Gf,base32upper:()=>zf,base32z:()=>Xf});var ht=ce({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zf=ce({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$f=ce({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gf=ce({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wf=ce({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zf=ce({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),jf=ce({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yf=ce({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Xf=ce({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $i={};ke($i,{base36:()=>Vr,base36upper:()=>Jf});var Vr=Tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Jf=Tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qf=bc,gc=128,eh=127,th=~eh,rh=Math.pow(2,31);function bc(r,e,t){e=e||[],t=t||0;for(var n=t;r>=rh;)e[t++]=r&255|gc,r/=128;for(;r&th;)e[t++]=r&255|gc,r>>>=7;return e[t]=r|0,bc.bytes=t-n+1,e}var nh=Gi,sh=128,yc=127;function Gi(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Gi.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&yc)<<s:(o&yc)*Math.pow(2,s),s+=7}while(o>=sh);return Gi.bytes=i-n,t}var ih=Math.pow(2,7),oh=Math.pow(2,14),ah=Math.pow(2,21),ch=Math.pow(2,28),lh=Math.pow(2,35),uh=Math.pow(2,42),fh=Math.pow(2,49),hh=Math.pow(2,56),dh=Math.pow(2,63),ph=function(r){return r<ih?1:r<oh?2:r<ah?3:r<ch?4:r<lh?5:r<uh?6:r<fh?7:r<hh?8:r<dh?9:10},mh={encode:Qf,decode:nh,encodingLength:ph},gh=mh,Hr=gh;function Fr(r,e=0){return[Hr.decode(r,e),Hr.decode.bytes]}function ur(r,e,t=0){return Hr.encode(r,e,t),e}function fr(r){return Hr.encodingLength(r)}function We(r,e){let t=e.byteLength,n=fr(r),s=n+fr(t),i=new Uint8Array(s+t);return ur(r,i,0),ur(t,i,n),i.set(e,s),new hr(r,t,e,i)}function qe(r){let e=ft(r),[t,n]=Fr(e),[s,i]=Fr(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new hr(t,s,o,e)}function wc(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&uc(r.bytes,t.bytes)}}var hr=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};function xc(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return bh(t,Wi(r),e??J.encoder);default:return wh(t,Wi(r),e??ht.encoder)}}var vc=new WeakMap;function Wi(r){let e=vc.get(r);if(e==null){let t=new Map;return vc.set(r,t),t}return e}var pe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}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!==Kr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==xh)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=We(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&&wc(e.multihash,n.multihash)}toString(e){return xc(this,e)}toJSON(){return{"/":xc(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:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??Ec(n,s,i.bytes))}else if(t[vh]===!0){let{version:n,multihash:s,code:i}=t,o=qe(s);return r.create(n,i,o)}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!==Kr)throw new Error(`Version 0 CID must use dag-pb (code: ${Kr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=Ec(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Kr,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,s=ft(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new hr(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,h]=Fr(e.subarray(t));return t+=h,f},s=n(),i=Kr;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),u=t+c,l=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=yh(e,t),i=r.decode(s);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 yh(r,e){switch(r[0]){case"Q":{let t=e??J;return[J.prefix,t.decode(`${J.prefix}${r}`)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case ht.prefix:{let t=e??ht;return[ht.prefix,t.decode(r)]}case Vr.prefix:{let t=e??Vr;return[Vr.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function bh(r,e,t){let{prefix:n}=t;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function wh(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var Kr=112,xh=18;function Ec(r,e,t){let n=fr(r),s=n+fr(e),i=new Uint8Array(s+t.byteLength);return ur(r,i,0),ur(e,i,n),i.set(t,s),i}var vh=Symbol.for("@ipld/js-cid/CID");var Zi={};ke(Zi,{identity:()=>dt});var Sc=0,Eh="identity",Ac=ft;function Sh(r){return We(Sc,Ac(r))}var dt={code:Sc,name:Eh,encode:Ac,digest:Sh};function me(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Bc(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ah(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function dr(r,...e){if(!Ah(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function _c(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Bc(r.outputLen),Bc(r.blockLen)}function pr(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 Ic(r,e){dr(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}var Gt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function In(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ze(r,e){return r<<32-e|r>>>e}function Tc(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function qr(r){return typeof r=="string"&&(r=Tc(r)),dr(r),r}function ji(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];dr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}var mr=class{clone(){return this._cloneInto()}};function Tn(r){let e=n=>r().update(qr(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function kn(r=32){if(Gt&&typeof Gt.getRandomValues=="function")return Gt.getRandomValues(new Uint8Array(r));if(Gt&&typeof Gt.randomBytes=="function")return Gt.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Bh(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(t>>s&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+u,a,n)}function kc(r,e,t){return r&e^~r&t}function Cc(r,e,t){return r&e^r&t^e&t}var gr=class extends mr{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=In(this.buffer)}update(e){pr(this);let{view:t,buffer:n,blockLen:s}=this;e=qr(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=In(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){pr(this),Ic(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let f=o;f<s;f++)t[f]=0;Bh(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=In(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%t&&e.buffer.set(n),e}};var Cn=BigInt(4294967295),Yi=BigInt(32);function Nc(r,e=!1){return e?{h:Number(r&Cn),l:Number(r>>Yi&Cn)}:{h:Number(r>>Yi&Cn)|0,l:Number(r&Cn)|0}}function _h(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=Nc(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var Ih=(r,e)=>BigInt(r>>>0)<<Yi|BigInt(e>>>0),Th=(r,e,t)=>r>>>t,kh=(r,e,t)=>r<<32-t|e>>>t,Ch=(r,e,t)=>r>>>t|e<<32-t,Nh=(r,e,t)=>r<<32-t|e>>>t,Rh=(r,e,t)=>r<<64-t|e>>>t-32,Lh=(r,e,t)=>r>>>t-32|e<<64-t,Uh=(r,e)=>e,Dh=(r,e)=>r,Oh=(r,e,t)=>r<<t|e>>>32-t,Mh=(r,e,t)=>e<<t|r>>>32-t,Ph=(r,e,t)=>e<<t-32|r>>>64-t,Vh=(r,e,t)=>r<<t-32|e>>>64-t;function Hh(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Fh=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Kh=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,qh=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),zh=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,$h=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Gh=(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0;var Wh={fromBig:Nc,split:_h,toBig:Ih,shrSH:Th,shrSL:kh,rotrSH:Ch,rotrSL:Nh,rotrBH:Rh,rotrBL:Lh,rotr32H:Uh,rotr32L:Dh,rotlSH:Oh,rotlSL:Mh,rotlBH:Ph,rotlBL:Vh,add:Hh,add3L:Fh,add3H:Kh,add4L:qh,add4H:zh,add5H:Gh,add5L:$h},O=Wh;var[Zh,jh]=O.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))),kt=new Uint32Array(80),Ct=new Uint32Array(80),Xi=class extends gr{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:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:p,Gl:y,Hh:b,Hl:d}=this;return[e,t,n,s,i,o,a,c,u,l,f,h,p,y,b,d]}set(e,t,n,s,i,o,a,c,u,l,f,h,p,y,b,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=y|0,this.Hh=b|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)kt[g]=e.getUint32(t),Ct[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let _=kt[g-15]|0,N=Ct[g-15]|0,R=O.rotrSH(_,N,1)^O.rotrSH(_,N,8)^O.shrSH(_,N,7),I=O.rotrSL(_,N,1)^O.rotrSL(_,N,8)^O.shrSL(_,N,7),C=kt[g-2]|0,T=Ct[g-2]|0,re=O.rotrSH(C,T,19)^O.rotrBH(C,T,61)^O.shrSH(C,T,6),$=O.rotrSL(C,T,19)^O.rotrBL(C,T,61)^O.shrSL(C,T,6),F=O.add4L(I,$,Ct[g-7],Ct[g-16]),le=O.add4H(F,R,re,kt[g-7],kt[g-16]);kt[g]=le|0,Ct[g]=F|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:p,Fl:y,Gh:b,Gl:d,Hh:x,Hl:E}=this;for(let g=0;g<80;g++){let _=O.rotrSH(f,h,14)^O.rotrSH(f,h,18)^O.rotrBH(f,h,41),N=O.rotrSL(f,h,14)^O.rotrSL(f,h,18)^O.rotrBL(f,h,41),R=f&p^~f&b,I=h&y^~h&d,C=O.add5L(E,N,I,jh[g],Ct[g]),T=O.add5H(C,x,_,R,Zh[g],kt[g]),re=C|0,$=O.rotrSH(n,s,28)^O.rotrBH(n,s,34)^O.rotrBH(n,s,39),F=O.rotrSL(n,s,28)^O.rotrBL(n,s,34)^O.rotrBL(n,s,39),le=n&i^n&a^i&a,S=s&o^s&c^o&c;x=b|0,E=d|0,b=p|0,d=y|0,p=f|0,y=h|0,{h:f,l:h}=O.add(u|0,l|0,T|0,re|0),u=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let k=O.add3L(re,F,S);n=O.add3H(k,T,$,le),s=k|0}({h:n,l:s}=O.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=O.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=O.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=O.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=O.add(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:y}=O.add(this.Fh|0,this.Fl|0,p|0,y|0),{h:b,l:d}=O.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:x,l:E}=O.add(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,i,o,a,c,u,l,f,h,p,y,b,d,x,E)}roundClean(){kt.fill(0),Ct.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 Rc=Tn(()=>new Xi);var Ln={};ke(Ln,{aInRange:()=>Re,abool:()=>je,abytes:()=>yr,bitGet:()=>td,bitLen:()=>to,bitMask:()=>$r,bitSet:()=>rd,bytesToHex:()=>mt,bytesToNumberBE:()=>gt,bytesToNumberLE:()=>Rt,concatBytes:()=>yt,createHmacDrbg:()=>ro,ensureBytes:()=>ie,equalBytes:()=>Qh,hexToBytes:()=>Zt,hexToNumber:()=>eo,inRange:()=>zr,isBytes:()=>Nt,memoized:()=>Yt,notImplemented:()=>sd,numberToBytesBE:()=>Lt,numberToBytesLE:()=>jt,numberToHexUnpadded:()=>Wt,numberToVarBytesBE:()=>Jh,utf8ToBytes:()=>ed,validateObject:()=>st});var Nn=BigInt(0),Rn=BigInt(1),Yh=BigInt(2);function Nt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function yr(r){if(!Nt(r))throw new Error("Uint8Array expected")}function je(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}var Xh=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function mt(r){yr(r);let e="";for(let t=0;t<r.length;t++)e+=Xh[r[t]];return e}function Wt(r){let e=r.toString(16);return e.length&1?"0"+e:e}function eo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Nn:BigInt("0x"+r)}var pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Lc(r){if(r>=pt._0&&r<=pt._9)return r-pt._0;if(r>=pt.A&&r<=pt.F)return r-(pt.A-10);if(r>=pt.a&&r<=pt.f)return r-(pt.a-10)}function Zt(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("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){let o=Lc(r.charCodeAt(i)),a=Lc(r.charCodeAt(i+1));if(o===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[s]=o*16+a}return n}function gt(r){return eo(mt(r))}function Rt(r){return yr(r),eo(mt(Uint8Array.from(r).reverse()))}function Lt(r,e){return Zt(r.toString(16).padStart(e*2,"0"))}function jt(r,e){return Lt(r,e).reverse()}function Jh(r){return Zt(Wt(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=Zt(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Nt(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(r+" of length "+t+" expected, got "+s);return n}function yt(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];yr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}function Qh(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 ed(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Ji=r=>typeof r=="bigint"&&Nn<=r;function zr(r,e,t){return Ji(r)&&Ji(e)&&Ji(t)&&e<=r&&r<t}function Re(r,e,t,n){if(!zr(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function to(r){let e;for(e=0;r>Nn;r>>=Rn,e+=1);return e}function td(r,e){return r>>BigInt(e)&Rn}function rd(r,e,t){return r|(t?Rn:Nn)<<BigInt(e)}var $r=r=>(Yh<<BigInt(r-1))-Rn,Qi=r=>new Uint8Array(r),Uc=r=>Uint8Array.from(r);function ro(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=Qi(r),s=Qi(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...f)=>t(s,n,...f),c=(f=Qi())=>{s=a(Uc([0]),f),n=a(),f.length!==0&&(s=a(Uc([1]),f),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=a();let p=n.slice();h.push(p),f+=n.length}return yt(...h)};return(f,h)=>{o(),c(f);let p;for(;!(p=h(u()));)c();return o(),p}}var nd={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"||Nt(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 st(r,e,t={}){let n=(s,i,o)=>{let a=nd[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error("param "+String(s)+" is invalid. Expected "+i+", got "+c)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(t))n(s,i,!0);return r}var sd=()=>{throw new Error("not implemented")};function Yt(r){let e=new WeakMap;return(t,...n)=>{let s=e.get(t);if(s!==void 0)return s;let i=r(t,...n);return e.set(t,i),i}}var ue=BigInt(0),ne=BigInt(1),Xt=BigInt(2),id=BigInt(3),no=BigInt(4),Dc=BigInt(5),Oc=BigInt(8),od=BigInt(9),ad=BigInt(16);function Y(r,e){let t=r%e;return t>=ue?t:e+t}function cd(r,e,t){if(e<ue)throw new Error("invalid exponent, negatives unsupported");if(t<=ue)throw new Error("invalid modulus");if(t===ne)return ue;let n=ne;for(;e>ue;)e&ne&&(n=n*r%t),r=r*r%t,e>>=ne;return n}function se(r,e,t){let n=r;for(;e-- >ue;)n*=n,n%=t;return n}function Un(r,e){if(r===ue)throw new Error("invert: expected non-zero number");if(e<=ue)throw new Error("invert: expected positive modulus, got "+e);let t=Y(r,e),n=e,s=ue,i=ne,o=ne,a=ue;for(;t!==ue;){let u=n/t,l=n%t,f=s-o*u,h=i-a*u;n=t,t=l,s=o,i=a,o=f,a=h}if(n!==ne)throw new Error("invert: does not exist");return Y(s,e)}function ld(r){let e=(r-ne)/Xt,t,n,s;for(t=r-ne,n=0;t%Xt===ue;t/=Xt,n++);for(s=Xt;s<r&&cd(s,e,r)!==r-ne;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let o=(r+ne)/no;return function(c,u){let l=c.pow(u,o);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let i=(t+ne)/Xt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),t),f=a.pow(c,i),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let p=1;for(let b=a.sqr(h);p<u&&!a.eql(b,a.ONE);p++)b=a.sqr(b);let y=a.pow(l,ne<<BigInt(u-p-1));l=a.sqr(y),f=a.mul(f,y),h=a.mul(h,l),u=p}return f}}function ud(r){if(r%no===id){let e=(r+ne)/no;return function(n,s){let i=n.pow(s,e);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%Oc===Dc){let e=(r-Dc)/Oc;return function(n,s){let i=n.mul(s,Xt),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,Xt),o),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%ad,ld(r)}var Mc=(r,e)=>(Y(r,e)&ne)===ne,fd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=fd.reduce((n,s)=>(n[s]="function",n),e);return st(r,t)}function hd(r,e,t){if(t<ue)throw new Error("invalid exponent, negatives unsupported");if(t===ue)return r.ONE;if(t===ne)return e;let n=r.ONE,s=e;for(;t>ue;)t&ne&&(n=r.mul(n,s)),s=r.sqr(s),t>>=ne;return n}function dd(r,e){let t=new Array(e.length),n=e.reduce((i,o,a)=>r.is0(o)?i:(t[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return e.reduceRight((i,o,a)=>r.is0(o)?i:(t[a]=r.mul(i,t[a]),r.mul(i,o)),s),t}function io(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Ut(r,e,t=!1,n={}){if(r<=ue)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:s,nByteLength:i}=io(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o,a=Object.freeze({ORDER:r,isLE:t,BITS:s,BYTES:i,MASK:$r(s),ZERO:ue,ONE:ne,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ue<=c&&c<r},is0:c=>c===ue,isOdd:c=>(c&ne)===ne,neg:c=>Y(-c,r),eql:(c,u)=>c===u,sqr:c=>Y(c*c,r),add:(c,u)=>Y(c+u,r),sub:(c,u)=>Y(c-u,r),mul:(c,u)=>Y(c*u,r),pow:(c,u)=>hd(a,c,u),div:(c,u)=>Y(c*Un(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Un(c,r),sqrt:n.sqrt||(c=>(o||(o=ud(r)),o(a,c))),invertBatch:c=>dd(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?jt(c,i):Lt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?Rt(c):gt(c)}});return Object.freeze(a)}function Pc(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 oo(r){let e=Pc(r);return e+Math.ceil(e/2)}function Vc(r,e,t=!1){let n=r.length,s=Pc(e),i=oo(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=t?Rt(r):gt(r),a=Y(o,e-ne)+ne;return t?jt(a,s):Lt(a,s)}var Hc=BigInt(0),Dn=BigInt(1);function ao(r,e){let t=e.negate();return r?t:e}function Fc(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function co(r,e){Fc(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1);return{windows:t,windowSize:n}}function pd(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function md(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var lo=new WeakMap,Kc=new WeakMap;function uo(r){return Kc.get(r)||1}function On(r,e){return{constTimeNegate:ao,hasPrecomputes(t){return uo(t)!==1},unsafeLadder(t,n,s=r.ZERO){let i=t;for(;n>Hc;)n&Dn&&(s=s.add(i)),i=i.double(),n>>=Dn;return s},precomputeWindow(t,n){let{windows:s,windowSize:i}=co(n,e),o=[],a=t,c=a;for(let u=0;u<s;u++){c=a,o.push(c);for(let l=1;l<i;l++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(t,n,s){let{windows:i,windowSize:o}=co(t,e),a=r.ZERO,c=r.BASE,u=BigInt(2**t-1),l=2**t,f=BigInt(t);for(let h=0;h<i;h++){let p=h*o,y=Number(s&u);s>>=f,y>o&&(y-=l,s+=Dn);let b=p,d=p+Math.abs(y)-1,x=h%2!==0,E=y<0;y===0?c=c.add(ao(x,n[b])):a=a.add(ao(E,n[d]))}return{p:a,f:c}},wNAFUnsafe(t,n,s,i=r.ZERO){let{windows:o,windowSize:a}=co(t,e),c=BigInt(2**t-1),u=2**t,l=BigInt(t);for(let f=0;f<o;f++){let h=f*a;if(s===Hc)break;let p=Number(s&c);if(s>>=l,p>a&&(p-=u,s+=Dn),p===0)continue;let y=n[h+Math.abs(p)-1];p<0&&(y=y.negate()),i=i.add(y)}return i},getPrecomputes(t,n,s){let i=lo.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&lo.set(n,s(i))),i},wNAFCached(t,n,s){let i=uo(t);return this.wNAF(i,this.getPrecomputes(i,t,s),n)},wNAFCachedUnsafe(t,n,s,i){let o=uo(t);return o===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(o,this.getPrecomputes(o,t,s),n,i)},setWindowSize(t,n){Fc(n,e),Kc.set(t,n),lo.delete(t)}}}function Mn(r,e,t,n){if(pd(t,r),md(n,e),t.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,i=to(BigInt(t.length)),o=i>12?i-3:i>4?i-2:i?2:1,a=(1<<o)-1,c=new Array(a+1).fill(s),u=Math.floor((e.BITS-1)/o)*o,l=s;for(let f=u;f>=0;f-=o){c.fill(s);for(let p=0;p<n.length;p++){let y=n[p],b=Number(y>>BigInt(f)&BigInt(a));c[b]=c[b].add(t[p])}let h=s;for(let p=c.length-1,y=s;p>0;p--)y=y.add(c[p]),h=h.add(y);if(l=l.add(h),f!==0)for(let p=0;p<o;p++)l=l.double()}return l}function Gr(r){return so(r.Fp),st(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...io(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ye=BigInt(0),Le=BigInt(1),Pn=BigInt(2),gd=BigInt(8),yd={zip215:!0};function bd(r){let e=Gr(r);return st(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function qc(r){let e=bd(r),{Fp:t,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,u=Pn<<BigInt(a*8)-Le,l=t.create,f=Ut(e.n,e.nBitLength),h=e.uvRatio||((w,m)=>{try{return{isValid:!0,value:t.sqrt(w*t.inv(m))}}catch{return{isValid:!1,value:Ye}}}),p=e.adjustScalarBytes||(w=>w),y=e.domain||((w,m,v)=>{if(je("phflag",v),m.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,m){Re("coordinate "+w,m,Ye,u)}function d(w){if(!(w instanceof g))throw new Error("ExtendedPoint expected")}let x=Yt((w,m)=>{let{ex:v,ey:B,ez:L}=w,U=w.is0();m==null&&(m=U?gd:t.inv(L));let M=l(v*m),q=l(B*m),D=l(L*m);if(U)return{x:Ye,y:Le};if(D!==Le)throw new Error("invZ was invalid");return{x:M,y:q}}),E=Yt(w=>{let{a:m,d:v}=e;if(w.is0())throw new Error("bad point: ZERO");let{ex:B,ey:L,ez:U,et:M}=w,q=l(B*B),D=l(L*L),Z=l(U*U),ee=l(Z*Z),he=l(q*m),de=l(Z*l(he+D)),ye=l(ee+l(v*l(q*D)));if(de!==ye)throw new Error("bad point: equation left != right (1)");let xe=l(B*L),Ne=l(U*M);if(xe!==Ne)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(m,v,B,L){this.ex=m,this.ey=v,this.ez=B,this.et=L,b("x",m),b("y",v),b("z",B),b("t",L),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof g)throw new Error("extended point not allowed");let{x:v,y:B}=m||{};return b("x",v),b("y",B),new g(v,B,Le,l(v*B))}static normalizeZ(m){let v=t.invertBatch(m.map(B=>B.ez));return m.map((B,L)=>B.toAffine(v[L])).map(g.fromAffine)}static msm(m,v){return Mn(g,f,m,v)}_setWindowSize(m){R.setWindowSize(this,m)}assertValidity(){E(this)}equals(m){d(m);let{ex:v,ey:B,ez:L}=this,{ex:U,ey:M,ez:q}=m,D=l(v*q),Z=l(U*L),ee=l(B*q),he=l(M*L);return D===Z&&ee===he}is0(){return this.equals(g.ZERO)}negate(){return new g(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:m}=e,{ex:v,ey:B,ez:L}=this,U=l(v*v),M=l(B*B),q=l(Pn*l(L*L)),D=l(m*U),Z=v+B,ee=l(l(Z*Z)-U-M),he=D+M,de=he-q,ye=D-M,xe=l(ee*de),Ne=l(he*ye),Te=l(ee*ye),rt=l(de*he);return new g(xe,Ne,rt,Te)}add(m){d(m);let{a:v,d:B}=e,{ex:L,ey:U,ez:M,et:q}=this,{ex:D,ey:Z,ez:ee,et:he}=m;if(v===BigInt(-1)){let ja=l((U-L)*(Z+D)),Ya=l((U+L)*(Z-D)),Oi=l(Ya-ja);if(Oi===Ye)return this.double();let Xa=l(M*Pn*he),Ja=l(q*Pn*ee),Qa=Ja+Xa,ec=Ya+ja,tc=Ja-Xa,_f=l(Qa*Oi),If=l(ec*tc),Tf=l(Qa*tc),kf=l(Oi*ec);return new g(_f,If,kf,Tf)}let de=l(L*D),ye=l(U*Z),xe=l(q*B*he),Ne=l(M*ee),Te=l((L+U)*(D+Z)-de-ye),rt=Ne-xe,lt=Ne+xe,Mr=l(ye-v*de),Ef=l(Te*rt),Sf=l(lt*Mr),Af=l(Te*Mr),Bf=l(rt*lt);return new g(Ef,Sf,Bf,Af)}subtract(m){return this.add(m.negate())}wNAF(m){return R.wNAFCached(this,m,g.normalizeZ)}multiply(m){let v=m;Re("scalar",v,Le,n);let{p:B,f:L}=this.wNAF(v);return g.normalizeZ([B,L])[0]}multiplyUnsafe(m,v=g.ZERO){let B=m;return Re("scalar",B,Ye,n),B===Ye?N:this.is0()||B===Le?this:R.wNAFCachedUnsafe(this,B,g.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(m){return x(this,m)}clearCofactor(){let{h:m}=e;return m===Le?this:this.multiplyUnsafe(m)}static fromHex(m,v=!1){let{d:B,a:L}=e,U=t.BYTES;m=ie("pointHex",m,U),je("zip215",v);let M=m.slice(),q=m[U-1];M[U-1]=q&-129;let D=Rt(M),Z=v?u:t.ORDER;Re("pointHex.y",D,Ye,Z);let ee=l(D*D),he=l(ee-Le),de=l(B*ee-L),{isValid:ye,value:xe}=h(he,de);if(!ye)throw new Error("Point.fromHex: invalid y coordinate");let Ne=(xe&Le)===Le,Te=(q&128)!==0;if(!v&&xe===Ye&&Te)throw new Error("Point.fromHex: x=0 and x_0=1");return Te!==Ne&&(xe=l(-xe)),g.fromAffine({x:xe,y:D})}static fromPrivateKey(m){return T(m).point}toRawBytes(){let{x:m,y:v}=this.toAffine(),B=jt(v,t.BYTES);return B[B.length-1]|=m&Le?128:0,B}toHex(){return mt(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Le,l(e.Gx*e.Gy)),g.ZERO=new g(Ye,Le,Le,Ye);let{BASE:_,ZERO:N}=g,R=On(g,a*8);function I(w){return Y(w,n)}function C(w){return I(Rt(w))}function T(w){let m=t.BYTES;w=ie("private key",w,m);let v=ie("hashed private key",i(w),2*m),B=p(v.slice(0,m)),L=v.slice(m,2*m),U=C(B),M=_.multiply(U),q=M.toRawBytes();return{head:B,prefix:L,scalar:U,point:M,pointBytes:q}}function re(w){return T(w).pointBytes}function $(w=new Uint8Array,...m){let v=yt(...m);return C(i(y(v,ie("context",w),!!s)))}function F(w,m,v={}){w=ie("message",w),s&&(w=s(w));let{prefix:B,scalar:L,pointBytes:U}=T(m),M=$(v.context,B,w),q=_.multiply(M).toRawBytes(),D=$(v.context,q,U,w),Z=I(M+D*L);Re("signature.s",Z,Ye,n);let ee=yt(q,jt(Z,t.BYTES));return ie("result",ee,t.BYTES*2)}let le=yd;function S(w,m,v,B=le){let{context:L,zip215:U}=B,M=t.BYTES;w=ie("signature",w,2*M),m=ie("message",m),v=ie("publicKey",v,M),U!==void 0&&je("zip215",U),s&&(m=s(m));let q=Rt(w.slice(M,2*M)),D,Z,ee;try{D=g.fromHex(v,U),Z=g.fromHex(w.slice(0,M),U),ee=_.multiplyUnsafe(q)}catch{return!1}if(!U&&D.isSmallOrder())return!1;let he=$(L,Z.toRawBytes(),D.toRawBytes(),m);return Z.add(D.multiplyUnsafe(he)).subtract(ee).clearCofactor().equals(g.ZERO)}return _._setWindowSize(8),{CURVE:e,getPublicKey:re,sign:F,verify:S,ExtendedPoint:g,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>o(t.BYTES),precompute(w=8,m=g.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}}}}var fo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),zc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Zm=BigInt(0),wd=BigInt(1),$c=BigInt(2),jm=BigInt(3),xd=BigInt(5),vd=BigInt(8);function Ed(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),s=BigInt(80),i=fo,a=r*r%i*r%i,c=se(a,$c,i)*a%i,u=se(c,wd,i)*r%i,l=se(u,xd,i)*u%i,f=se(l,e,i)*l%i,h=se(f,t,i)*f%i,p=se(h,n,i)*h%i,y=se(p,s,i)*p%i,b=se(y,s,i)*p%i,d=se(b,e,i)*l%i;return{pow_p_5_8:se(d,$c,i)*r%i,b2:a}}function Sd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ad(r,e){let t=fo,n=Y(e*e*e,t),s=Y(n*n*e,t),i=Ed(r*s).pow_p_5_8,o=Y(r*n*i,t),a=Y(e*o*o,t),c=o,u=Y(o*zc,t),l=a===r,f=a===Y(-r,t),h=a===Y(-r*zc,t);return l&&(o=c),(f||h)&&(o=u),Mc(o,t)&&(o=Y(-o,t)),{isValid:l||f,value:o}}var Bd=Ut(fo,void 0,!0),_d={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Bd,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:vd,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Rc,randomBytes:kn,adjustScalarBytes:Sd,uvRatio:Ad},Gc=qc(_d);var Vn=32;function Wc(r,e,t){return Gc.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}var Hn=class{type="Ed25519";raw;constructor(e){this.raw=ho(e,Vn)}toMultihash(){return dt.digest(Dt(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t){return Wc(this.raw,t,e)}};function po(r){return r=ho(r,Vn),new Hn(r)}function ho(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}function oe(r=0){return new Uint8Array(r)}function Ue(r=0){return new Uint8Array(r)}var Td=Math.pow(2,7),kd=Math.pow(2,14),Cd=Math.pow(2,21),mo=Math.pow(2,28),go=Math.pow(2,35),yo=Math.pow(2,42),bo=Math.pow(2,49),W=128,Ee=127;function Se(r){if(r<Td)return 1;if(r<kd)return 2;if(r<Cd)return 3;if(r<mo)return 4;if(r<go)return 5;if(r<yo)return 6;if(r<bo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function wo(r,e,t=0){switch(Se(r)){case 8:e[t++]=r&255|W,r/=128;case 7:e[t++]=r&255|W,r/=128;case 6:e[t++]=r&255|W,r/=128;case 5:e[t++]=r&255|W,r/=128;case 4:e[t++]=r&255|W,r>>>=7;case 3:e[t++]=r&255|W,r>>>=7;case 2:e[t++]=r&255|W,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Nd(r,e,t=0){switch(Se(r)){case 8:e.set(t++,r&255|W),r/=128;case 7:e.set(t++,r&255|W),r/=128;case 6:e.set(t++,r&255|W),r/=128;case 5:e.set(t++,r&255|W),r/=128;case 4:e.set(t++,r&255|W),r>>>=7;case 3:e.set(t++,r&255|W),r>>>=7;case 2:e.set(t++,r&255|W),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function xo(r,e){let t=r[e],n=0;if(n+=t&Ee,t<W||(t=r[e+1],n+=(t&Ee)<<7,t<W)||(t=r[e+2],n+=(t&Ee)<<14,t<W)||(t=r[e+3],n+=(t&Ee)<<21,t<W)||(t=r[e+4],n+=(t&Ee)*mo,t<W)||(t=r[e+5],n+=(t&Ee)*go,t<W)||(t=r[e+6],n+=(t&Ee)*yo,t<W)||(t=r[e+7],n+=(t&Ee)*bo,t<W))return n;throw new RangeError("Could not decode varint")}function Rd(r,e){let t=r.get(e),n=0;if(n+=t&Ee,t<W||(t=r.get(e+1),n+=(t&Ee)<<7,t<W)||(t=r.get(e+2),n+=(t&Ee)<<14,t<W)||(t=r.get(e+3),n+=(t&Ee)<<21,t<W)||(t=r.get(e+4),n+=(t&Ee)*mo,t<W)||(t=r.get(e+5),n+=(t&Ee)*go,t<W)||(t=r.get(e+6),n+=(t&Ee)*yo,t<W)||(t=r.get(e+7),n+=(t&Ee)*bo,t<W))return n;throw new RangeError("Could not decode varint")}function ze(r,e,t=0){return e==null&&(e=Ue(Se(r))),e instanceof Uint8Array?wo(r,e,t):Nd(r,e,t)}function bt(r,e=0){return r instanceof Uint8Array?xo(r,e):Rd(r,e)}var vo=new Float32Array([-0]),Ot=new Uint8Array(vo.buffer);function jc(r,e,t){vo[0]=r,e[t]=Ot[0],e[t+1]=Ot[1],e[t+2]=Ot[2],e[t+3]=Ot[3]}function Yc(r,e){return Ot[0]=r[e],Ot[1]=r[e+1],Ot[2]=r[e+2],Ot[3]=r[e+3],vo[0]}var Eo=new Float64Array([-0]),Ae=new Uint8Array(Eo.buffer);function Xc(r,e,t){Eo[0]=r,e[t]=Ae[0],e[t+1]=Ae[1],e[t+2]=Ae[2],e[t+3]=Ae[3],e[t+4]=Ae[4],e[t+5]=Ae[5],e[t+6]=Ae[6],e[t+7]=Ae[7]}function Jc(r,e){return Ae[0]=r[e],Ae[1]=r[e+1],Ae[2]=r[e+2],Ae[3]=r[e+3],Ae[4]=r[e+4],Ae[5]=r[e+5],Ae[6]=r[e+6],Ae[7]=r[e+7],Eo[0]}var Ld=BigInt(Number.MAX_SAFE_INTEGER),Ud=BigInt(Number.MIN_SAFE_INTEGER),Ve=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 Jt;if(e<Ld&&e>Ud)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Qc&&(s=0n,++n>Qc&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return Jt;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):Jt}},Jt=new Ve(0,0);Jt.toBigInt=function(){return 0n};Jt.zzEncode=Jt.zzDecode=function(){return this};Jt.length=function(){return 1};var Qc=4294967296n;function el(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 tl(r,e,t){if(t-e<1)return"";let s,i=[],o=0,a;for(;e<t;)a=r[e++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(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[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function So(r,e,t){let n=t,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function Xe(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Kn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ao=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,Xe(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 Xe(this,4);return Kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Xe(this,4);return Kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Xe(this,4);let e=Yc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Xe(this,4);let e=Jc(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 Xe(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return tl(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Xe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Xe(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 Ve(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 Xe(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 Xe(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 Xe(this,8);let e=Kn(this.buf,this.pos+=4),t=Kn(this.buf,this.pos+=4);return new Ve(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=xo(this.buf,this.pos);return this.pos+=Se(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Bo(r){return new Ao(r instanceof Uint8Array?r:r.subarray())}function De(r,e,t){let n=Bo(r);return e.decode(n,void 0,t)}var _o={};ke(_o,{base10:()=>Dd});var Dd=Tt({prefix:"9",name:"base10",alphabet:"0123456789"});var Io={};ke(Io,{base16:()=>Od,base16upper:()=>Md});var Od=ce({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Md=ce({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var To={};ke(To,{base2:()=>Pd});var Pd=ce({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ko={};ke(ko,{base256emoji:()=>qd});var nl=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}"),Vd=nl.reduce((r,e,t)=>(r[t]=e,r),[]),Hd=nl.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Fd(r){return r.reduce((e,t)=>(e+=Vd[t],e),"")}function Kd(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Hd[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var qd=lr({prefix:"\u{1F680}",name:"base256emoji",encode:Fd,decode:Kd});var No={};ke(No,{base64:()=>zd,base64pad:()=>$d,base64url:()=>Co,base64urlpad:()=>Gd});var zd=ce({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$d=ce({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Co=ce({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gd=ce({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ro={};ke(Ro,{base8:()=>Wd});var Wd=ce({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lo={};ke(Lo,{identity:()=>Zd});var Zd=lr({prefix:"\0",name:"identity",encode:r=>hc(r),decode:r=>fc(r)});var Ng=new TextEncoder,Rg=new TextDecoder;var Oo={};ke(Oo,{sha256:()=>br,sha512:()=>Xd});function Do({name:r,code:e,encode:t}){return new Uo(r,e,t)}var Uo=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?We(this.code,t):t.then(n=>We(this.code,n))}else throw Error("Unknown type, must be binary type")}};function il(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var br=Do({name:"sha2-256",code:18,encode:il("SHA-256")}),Xd=Do({name:"sha2-512",code:19,encode:il("SHA-512")});var Wr={...Lo,...To,...Ro,..._o,...Io,...zi,...$i,...qi,...No,...ko},zg={...Oo,...Zi};function al(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ol=al("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mo=al("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=Ue(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Jd={utf8:ol,"utf-8":ol,hex:Wr.base16,latin1:Mo,ascii:Mo,binary:Mo,...Wr},qn=Jd;function z(r,e="utf8"){let t=qn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Po(r){let e=r??8192,t=e>>>1,n,s=e;return function(o){if(o<1||o>t)return Ue(o);s+o>e&&(n=Ue(e),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var Qt=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Vo(){}var Fo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Qd=Po();function ep(r){return globalThis.Buffer!=null?Ue(r):Qd(r)}var jr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Qt(Vo,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Qt(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ko((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(zn,10,Ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ve.fromBigInt(e);return this._push(zn,t.length(),t)}uint64Number(e){return this._push(wo,Se(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ve.fromBigInt(e).zzEncode();return this._push(zn,t.length(),t)}sint64Number(e){let t=Ve.fromNumber(e).zzEncode();return this._push(zn,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ho,1,e?1:0)}fixed32(e){return this._push(Zr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ve.fromBigInt(e);return this._push(Zr,4,t.lo)._push(Zr,4,t.hi)}fixed64Number(e){let t=Ve.fromNumber(e);return this._push(Zr,4,t.lo)._push(Zr,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(jc,4,e)}double(e){return this._push(Xc,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ho,1,0):this.uint32(t)._push(rp,t,e)}string(e){let t=el(e);return t!==0?this.uint32(t)._push(So,t,e):this._push(Ho,1,0)}fork(){return this.states=new Fo(this),this.head=this.tail=new Qt(Vo,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 Qt(Vo,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=ep(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ho(r,e,t){e[t]=r&255}function tp(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Ko=class extends Qt{next;constructor(e,t){super(tp,e,t),this.next=void 0}};function zn(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 Zr(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 rp(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(jr.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(np,e,r),this},jr.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sp,e,r),this});function np(r,e,t){e.set(r,t)}function sp(r,e,t){r.length<40?So(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(z(r),t)}function qo(){return new jr}function Oe(r,e){let t=qo();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var wr;(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"})(wr||(wr={}));function $n(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function er(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,o){let a=e(i);o.int32(a)},n=function(i){let o=i.int32();return e(o)};return $n("enum",wr.VARINT,t,n)}function Me(r,e){return $n("message",wr.LENGTH_DELIMITED,r,e)}var Yr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var fe;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(fe||(fe={}));var zo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(zo||(zo={}));(function(r){r.codec=()=>er(zo)})(fe||(fe={}));var it;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.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)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=fe.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(it||(it={}));var $o;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.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)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=fe.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})($o||($o={}));var an={};ke(an,{MAX_RSA_KEY_SIZE:()=>Os,generateRSAKeyPair:()=>su,jwkToJWKKeyPair:()=>iu,jwkToPkcs1:()=>xp,jwkToPkix:()=>ea,jwkToRSAPrivateKey:()=>nu,pkcs1ToJwk:()=>eu,pkcs1ToRSAPrivateKey:()=>ru,pkixToJwk:()=>tu,pkixToRSAPublicKey:()=>ta});var ip=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]),Mt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pt=new Uint32Array(64),Go=class extends gr{constructor(){super(64,32,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:e,B:t,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,t,n,s,i,o,a,c]}set(e,t,n,s,i,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)Pt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=Pt[f-15],p=Pt[f-2],y=Ze(h,7)^Ze(h,18)^h>>>3,b=Ze(p,17)^Ze(p,19)^p>>>10;Pt[f]=b+Pt[f-7]+y+Pt[f-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Ze(a,6)^Ze(a,11)^Ze(a,25),p=l+h+kc(a,c,u)+ip[f]+Pt[f]|0,b=(Ze(n,2)^Ze(n,13)^Ze(n,22))+Cc(n,s,i)|0;l=u,u=c,c=a,a=o+p|0,o=i,i=s,s=n,n=p+b|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,u,l)}roundClean(){Pt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var xr=Tn(()=>new Go);var K=Of(ll());function tr(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 Vt(r,e,t=-1){let n=t,s=r,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){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 u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[i-l-1]=Math.floor(s/f),s-=u[i-l-1]*f}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Zn(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let i of r)s.set(i,t),t+=i.length;return s}function Zo(){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=tr(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,tr(i,8)-n}function ul(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=Vt(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Vt(e,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function fl(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function Pe(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(t)}var By=Math.log(2);function jn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function jo(r){let e=0,t=0;for(let s=0;s<r.length;s++){let i=r[s];e+=i.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function St(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 Jr=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return jo(this.items)}},Xr=[new Uint8Array([1])],hl="0123456789";var Br="",Je=new ArrayBuffer(0),Yo=new Uint8Array(0),Qr="EndOfContent",pl="OCTET STRING",ml="BIT STRING";function At(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?K.BufferSourceConverter.toUint8Array(i.valueHex):Yo}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!St(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}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",Je)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:K.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var xt=class{constructor({blockLength:e=0,error:t=Br,warnings:n=[],valueBeforeDecode:s=Yo}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=K.BufferSourceConverter.toUint8Array(s)}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:K.Convert.ToHex(this.valueBeforeDecodeView)}}};xt.NAME="baseBlock";var Be=class extends xt{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'")}};Be.NAME="valueBlock";var Yn=class extends At(xt){constructor({idBlock:e={}}={}){var t,n,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?K.BufferSourceConverter.toUint8Array(e.valueHex):Yo,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-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",Je}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=Vt(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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,u=this.valueHexView=new Uint8Array(255),l=255;for(;i[c]&128;){if(u[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let h=new Uint8Array(l);for(let p=0;p<u.length;p++)h[p]=u[p];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=i[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=u[h];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=tr(u,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}}};Yn.NAME="identificationBlock";var Xn=class extends xt{constructor({lenBlock:e={}}={}){var t,n,s;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=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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 o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=tr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+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 s=Vt(this.length,8);if(s.byteLength>127)return this.error="Too big length",Je;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let i=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];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}}};Xn.NAME="lengthBlock";var A={},be=class extends xt{constructor({name:e=Br,optional:t=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Yn(s),this.lenBlock=new Xn(s),this.valueBlock=i?new i(s):new Be(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}toBER(e,t){let n=t||new Jr;t||gl(this);let s=this.idBlock.toBER(e);if(n.write(s),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 o=this.lenBlock.toBER(e);n.write(o),n.write(i)}return t?Je: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():K.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${K.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 fl(t,n)}};be.NAME="BaseBlock";function gl(r){if(r instanceof A.Constructed)for(let e of r.valueBlock.value)gl(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Jn=class extends be{constructor({value:e=Br,...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 s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Jn.NAME="BaseStringBlock";var Qn=class extends At(Be){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Qn.NAME="PrimitiveValueBlock";var yl,es=class extends be{constructor(e={}){super(e,Qn),this.idBlock.isConstructed=!1}};yl=es;A.Primitive=yl;es.NAME="PRIMITIVE";function pp(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 Us(r,e=0,t=r.length){let n=e,s=new be({},Be),i=new xt;if(!St(i,r,e,t))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=be;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=A.EndOfContent;break;case 1:c=A.Boolean;break;case 2:c=A.Integer;break;case 3:c=A.BitString;break;case 4:c=A.OctetString;break;case 5:c=A.Null;break;case 6:c=A.ObjectIdentifier;break;case 10:c=A.Enumerated;break;case 12:c=A.Utf8String;break;case 13:c=A.RelativeObjectIdentifier;break;case 14:c=A.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=A.Sequence;break;case 17:c=A.Set;break;case 18:c=A.NumericString;break;case 19:c=A.PrintableString;break;case 20:c=A.TeletexString;break;case 21:c=A.VideotexString;break;case 22:c=A.IA5String;break;case 23:c=A.UTCTime;break;case 24:c=A.GeneralizedTime;break;case 25:c=A.GraphicString;break;case 26:c=A.VisibleString;break;case 27:c=A.GeneralString;break;case 28:c=A.UniversalString;break;case 29:c=A.CharacterString;break;case 30:c=A.BmpString;break;case 31:c=A.DATE;break;case 32:c=A.TimeOfDay;break;case 33:c=A.DateTime;break;case 34:c=A.Duration;break;default:{let u=s.idBlock.isConstructed?new A.Constructed:new A.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?A.Constructed:A.Primitive}return s=pp(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function Xo(r){if(!r.byteLength){let e=new be({},Be);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Us(K.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function mp(r,e){return r?1:e}var ot=class extends Be{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;mp(this.isIndefiniteForm,n)>0;){let o=Us(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Qr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Qr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Jr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?Je:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};ot.NAME="ConstructedValueBlock";var bl,Ht=class extends be{constructor(e={}){super(e,ot),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
2
+ "use strict";var Libp2PCircuitRelayV2=(()=>{var Cf=Object.create;var Sn=Object.defineProperty;var Nf=Object.getOwnPropertyDescriptor;var Rf=Object.getOwnPropertyNames;var Lf=Object.getPrototypeOf,Uf=Object.prototype.hasOwnProperty;var Df=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ke=(r,e)=>{for(var t in e)Sn(r,t,{get:e[t],enumerable:!0})},tc=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Rf(e))!Uf.call(r,s)&&s!==t&&Sn(r,s,{get:()=>e[s],enumerable:!(n=Nf(e,s))||n.enumerable});return r};var Of=(r,e,t)=>(t=r!=null?Cf(Lf(r)):{},tc(e||!r||!r.__esModule?Sn(t,"default",{value:r,enumerable:!0}):t,r)),Mf=r=>tc(Sn({},"__esModule",{value:!0}),r);var cl=Df(vr=>{"use strict";var op="[object ArrayBuffer]",wt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===op}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),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[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 o of t)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of t){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Wo="string",ap=/^[0-9a-f\s]+$/i,cp=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,lp=/^[a-zA-Z0-9-_]+$/,Gn=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=wt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},$e=class{static toString(e,t=!1){let n=wt.toArrayBuffer(e),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return n}},Wn=class r{static isHex(e){return typeof e===Wo&&ap.test(e)}static isBase64(e){return typeof e===Wo&&cp.test(e)}static isBase64Url(e){return typeof e===Wo&&lp.test(e)}static ToString(e,t="utf8"){let n=wt.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 $e.toString(n,!0);case"utf16":case"utf16be":return $e.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 $e.fromString(e,!0);case"utf16":case"utf16be":return $e.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=wt.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 Gn.fromString(e);case"utf16":case"utf16be":return $e.fromString(e);case"utf16le":case"usc2":return $e.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 Gn.toString(e);case"utf16":case"utf16be":return $e.toString(e);case"utf16le":case"usc2":return $e.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 s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=wt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=wt.toUint8Array(e),n="",s=t.length;for(let i=0;i<s;i++){let o=t[i];o<16&&(n+="0"),n+=o.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 s=0;s<t.length;s=s+2){let i=t.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return $e.toString(e,t)}static FromUtf16String(e,t=!1){return $e.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,"")||""}};Wn.DEFAULT_UTF8_ENCODING="utf8";function up(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)t[i]=s[i]}return t}function fp(...r){let e=r.map(s=>s.byteLength).reduce((s,i)=>s+i),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)t[n++]=i}),t.buffer}function hp(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}vr.BufferSourceConverter=wt;vr.Convert=Wn;vr.assign=up;vr.combine=fp;vr.isEqual=hp});var _0={};ke(_0,{RELAY_V2_HOP_CODEC:()=>Ge,RELAY_V2_STOP_CODEC:()=>nr,circuitRelayServer:()=>cf,circuitRelayTransport:()=>vf});var Mi=Symbol.for("@libp2p/peer-id");var Pi="keep-alive";var nc=Symbol.for("@libp2p/transport");var rc;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(rc||(rc={}));var ut=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ar=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var An=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Bn=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Pr=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}},$t=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}};var cr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ke=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:i})=>i!==t),this.#e.set(e,s))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:s})=>!s),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function sc(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function ic(...r){let e=[];for(let t of r)sc(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function oc(...r){let e=[];for(let t of r)sc(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var ac=Symbol.for("@libp2p/service-capabilities"),cc=Symbol.for("@libp2p/service-dependencies");var qi={};ke(qi,{base58btc:()=>J,base58flickr:()=>qf});var rm=new Uint8Array(0);function lc(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 ft(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 uc(r){return new TextEncoder().encode(r)}function fc(r){return new TextDecoder().decode(r)}function Pf(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 s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var b=0,d=0,x=0,E=y.length;x!==E&&y[x]===0;)x++,b++;for(var g=(E-x)*l+1>>>0,_=new Uint8Array(g);x!==E;){for(var N=y[x],R=0,I=g-1;(N!==0||R<d)&&I!==-1;I--,R++)N+=256*_[I]>>>0,_[I]=N%a>>>0,N=N/a>>>0;if(N!==0)throw new Error("Non-zero carry");d=R,x++}for(var C=g-d;C!==g&&_[C]===0;)C++;for(var T=c.repeat(b);C<g;++C)T+=r.charAt(_[C]);return T}function h(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var b=0;if(y[b]!==" "){for(var d=0,x=0;y[b]===c;)d++,b++;for(var E=(y.length-b)*u+1>>>0,g=new Uint8Array(E);y[b];){var _=t[y.charCodeAt(b)];if(_===255)return;for(var N=0,R=E-1;(_!==0||N<x)&&R!==-1;R--,N++)_+=a*g[R]>>>0,g[R]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");x=N,b++}if(y[b]!==" "){for(var I=E-x;I!==E&&g[I]===0;)I++;for(var C=new Uint8Array(d+(E-I)),T=d;I!==E;)C[T++]=g[I++];return C}}}function p(y){var b=h(y);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var Vf=Pf,Hf=Vf,dc=Hf;var Vi=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")}},Hi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 pc(this,e)}},Fi=class{decoders;constructor(e){this.decoders=e}or(e){return pc(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 pc(r,e){return new Fi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ki=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Vi(e,t,n),this.decoder=new Hi(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function lr({name:r,prefix:e,encode:t,decode:n}){return new Ki(r,e,t,n)}function Tt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=dc(t,r);return lr({prefix:e,name:r,encode:n,decode:i=>ft(s(i))})}function Ff(r,e,t,n){let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let l=0;l<i;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=t||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}function Kf(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function ce({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return lr({prefix:e,name:r,encode(s){return Kf(s,n,t)},decode(s){return Ff(s,n,t,r)}})}var J=Tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qf=Tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zi={};ke(zi,{base32:()=>ht,base32hex:()=>Wf,base32hexpad:()=>jf,base32hexpadupper:()=>Yf,base32hexupper:()=>Zf,base32pad:()=>$f,base32padupper:()=>Gf,base32upper:()=>zf,base32z:()=>Xf});var ht=ce({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zf=ce({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$f=ce({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gf=ce({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wf=ce({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zf=ce({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),jf=ce({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yf=ce({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Xf=ce({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $i={};ke($i,{base36:()=>Vr,base36upper:()=>Jf});var Vr=Tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Jf=Tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qf=yc,mc=128,eh=127,th=~eh,rh=Math.pow(2,31);function yc(r,e,t){e=e||[],t=t||0;for(var n=t;r>=rh;)e[t++]=r&255|mc,r/=128;for(;r&th;)e[t++]=r&255|mc,r>>>=7;return e[t]=r|0,yc.bytes=t-n+1,e}var nh=Gi,sh=128,gc=127;function Gi(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Gi.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&gc)<<s:(o&gc)*Math.pow(2,s),s+=7}while(o>=sh);return Gi.bytes=i-n,t}var ih=Math.pow(2,7),oh=Math.pow(2,14),ah=Math.pow(2,21),ch=Math.pow(2,28),lh=Math.pow(2,35),uh=Math.pow(2,42),fh=Math.pow(2,49),hh=Math.pow(2,56),dh=Math.pow(2,63),ph=function(r){return r<ih?1:r<oh?2:r<ah?3:r<ch?4:r<lh?5:r<uh?6:r<fh?7:r<hh?8:r<dh?9:10},mh={encode:Qf,decode:nh,encodingLength:ph},gh=mh,Hr=gh;function Fr(r,e=0){return[Hr.decode(r,e),Hr.decode.bytes]}function ur(r,e,t=0){return Hr.encode(r,e,t),e}function fr(r){return Hr.encodingLength(r)}function We(r,e){let t=e.byteLength,n=fr(r),s=n+fr(t),i=new Uint8Array(s+t);return ur(r,i,0),ur(t,i,n),i.set(e,s),new hr(r,t,e,i)}function qe(r){let e=ft(r),[t,n]=Fr(e),[s,i]=Fr(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new hr(t,s,o,e)}function bc(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&lc(r.bytes,t.bytes)}}var hr=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};function wc(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return bh(t,Wi(r),e??J.encoder);default:return wh(t,Wi(r),e??ht.encoder)}}var xc=new WeakMap;function Wi(r){let e=xc.get(r);if(e==null){let t=new Map;return xc.set(r,t),t}return e}var pe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}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!==Kr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==xh)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=We(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&&bc(e.multihash,n.multihash)}toString(e){return wc(this,e)}toJSON(){return{"/":wc(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:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??vc(n,s,i.bytes))}else if(t[vh]===!0){let{version:n,multihash:s,code:i}=t,o=qe(s);return r.create(n,i,o)}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!==Kr)throw new Error(`Version 0 CID must use dag-pb (code: ${Kr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=vc(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Kr,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,s=ft(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new hr(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,h]=Fr(e.subarray(t));return t+=h,f},s=n(),i=Kr;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),u=t+c,l=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=yh(e,t),i=r.decode(s);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 yh(r,e){switch(r[0]){case"Q":{let t=e??J;return[J.prefix,t.decode(`${J.prefix}${r}`)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case ht.prefix:{let t=e??ht;return[ht.prefix,t.decode(r)]}case Vr.prefix:{let t=e??Vr;return[Vr.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function bh(r,e,t){let{prefix:n}=t;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function wh(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var Kr=112,xh=18;function vc(r,e,t){let n=fr(r),s=n+fr(e),i=new Uint8Array(s+t.byteLength);return ur(r,i,0),ur(e,i,n),i.set(t,s),i}var vh=Symbol.for("@ipld/js-cid/CID");var Zi={};ke(Zi,{identity:()=>dt});var Ec=0,Eh="identity",Sc=ft;function Sh(r){return We(Ec,Sc(r))}var dt={code:Ec,name:Eh,encode:Sc,digest:Sh};function me(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Ac(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ah(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function dr(r,...e){if(!Ah(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Bc(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ac(r.outputLen),Ac(r.blockLen)}function pr(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 _c(r,e){dr(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}var Gt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function In(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ze(r,e){return r<<32-e|r>>>e}function Ic(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function qr(r){return typeof r=="string"&&(r=Ic(r)),dr(r),r}function ji(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];dr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}var mr=class{clone(){return this._cloneInto()}};function Tn(r){let e=n=>r().update(qr(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function kn(r=32){if(Gt&&typeof Gt.getRandomValues=="function")return Gt.getRandomValues(new Uint8Array(r));if(Gt&&typeof Gt.randomBytes=="function")return Gt.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Bh(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(t>>s&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+u,a,n)}function Tc(r,e,t){return r&e^~r&t}function kc(r,e,t){return r&e^r&t^e&t}var gr=class extends mr{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=In(this.buffer)}update(e){pr(this);let{view:t,buffer:n,blockLen:s}=this;e=qr(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=In(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){pr(this),_c(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let f=o;f<s;f++)t[f]=0;Bh(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=In(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%t&&e.buffer.set(n),e}};var Cn=BigInt(4294967295),Yi=BigInt(32);function Cc(r,e=!1){return e?{h:Number(r&Cn),l:Number(r>>Yi&Cn)}:{h:Number(r>>Yi&Cn)|0,l:Number(r&Cn)|0}}function _h(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=Cc(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var Ih=(r,e)=>BigInt(r>>>0)<<Yi|BigInt(e>>>0),Th=(r,e,t)=>r>>>t,kh=(r,e,t)=>r<<32-t|e>>>t,Ch=(r,e,t)=>r>>>t|e<<32-t,Nh=(r,e,t)=>r<<32-t|e>>>t,Rh=(r,e,t)=>r<<64-t|e>>>t-32,Lh=(r,e,t)=>r>>>t-32|e<<64-t,Uh=(r,e)=>e,Dh=(r,e)=>r,Oh=(r,e,t)=>r<<t|e>>>32-t,Mh=(r,e,t)=>e<<t|r>>>32-t,Ph=(r,e,t)=>e<<t-32|r>>>64-t,Vh=(r,e,t)=>r<<t-32|e>>>64-t;function Hh(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Fh=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Kh=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,qh=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),zh=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,$h=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Gh=(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0;var Wh={fromBig:Cc,split:_h,toBig:Ih,shrSH:Th,shrSL:kh,rotrSH:Ch,rotrSL:Nh,rotrBH:Rh,rotrBL:Lh,rotr32H:Uh,rotr32L:Dh,rotlSH:Oh,rotlSL:Mh,rotlBH:Ph,rotlBL:Vh,add:Hh,add3L:Fh,add3H:Kh,add4L:qh,add4H:zh,add5H:Gh,add5L:$h},O=Wh;var[Zh,jh]=O.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))),kt=new Uint32Array(80),Ct=new Uint32Array(80),Xi=class extends gr{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:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:p,Gl:y,Hh:b,Hl:d}=this;return[e,t,n,s,i,o,a,c,u,l,f,h,p,y,b,d]}set(e,t,n,s,i,o,a,c,u,l,f,h,p,y,b,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=y|0,this.Hh=b|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)kt[g]=e.getUint32(t),Ct[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let _=kt[g-15]|0,N=Ct[g-15]|0,R=O.rotrSH(_,N,1)^O.rotrSH(_,N,8)^O.shrSH(_,N,7),I=O.rotrSL(_,N,1)^O.rotrSL(_,N,8)^O.shrSL(_,N,7),C=kt[g-2]|0,T=Ct[g-2]|0,re=O.rotrSH(C,T,19)^O.rotrBH(C,T,61)^O.shrSH(C,T,6),$=O.rotrSL(C,T,19)^O.rotrBL(C,T,61)^O.shrSL(C,T,6),F=O.add4L(I,$,Ct[g-7],Ct[g-16]),le=O.add4H(F,R,re,kt[g-7],kt[g-16]);kt[g]=le|0,Ct[g]=F|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:p,Fl:y,Gh:b,Gl:d,Hh:x,Hl:E}=this;for(let g=0;g<80;g++){let _=O.rotrSH(f,h,14)^O.rotrSH(f,h,18)^O.rotrBH(f,h,41),N=O.rotrSL(f,h,14)^O.rotrSL(f,h,18)^O.rotrBL(f,h,41),R=f&p^~f&b,I=h&y^~h&d,C=O.add5L(E,N,I,jh[g],Ct[g]),T=O.add5H(C,x,_,R,Zh[g],kt[g]),re=C|0,$=O.rotrSH(n,s,28)^O.rotrBH(n,s,34)^O.rotrBH(n,s,39),F=O.rotrSL(n,s,28)^O.rotrBL(n,s,34)^O.rotrBL(n,s,39),le=n&i^n&a^i&a,S=s&o^s&c^o&c;x=b|0,E=d|0,b=p|0,d=y|0,p=f|0,y=h|0,{h:f,l:h}=O.add(u|0,l|0,T|0,re|0),u=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let k=O.add3L(re,F,S);n=O.add3H(k,T,$,le),s=k|0}({h:n,l:s}=O.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=O.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=O.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=O.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=O.add(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:y}=O.add(this.Fh|0,this.Fl|0,p|0,y|0),{h:b,l:d}=O.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:x,l:E}=O.add(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,i,o,a,c,u,l,f,h,p,y,b,d,x,E)}roundClean(){kt.fill(0),Ct.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 Nc=Tn(()=>new Xi);var Ln={};ke(Ln,{aInRange:()=>Re,abool:()=>je,abytes:()=>yr,bitGet:()=>td,bitLen:()=>to,bitMask:()=>$r,bitSet:()=>rd,bytesToHex:()=>mt,bytesToNumberBE:()=>gt,bytesToNumberLE:()=>Rt,concatBytes:()=>yt,createHmacDrbg:()=>ro,ensureBytes:()=>ie,equalBytes:()=>Qh,hexToBytes:()=>Zt,hexToNumber:()=>eo,inRange:()=>zr,isBytes:()=>Nt,memoized:()=>Yt,notImplemented:()=>sd,numberToBytesBE:()=>Lt,numberToBytesLE:()=>jt,numberToHexUnpadded:()=>Wt,numberToVarBytesBE:()=>Jh,utf8ToBytes:()=>ed,validateObject:()=>st});var Nn=BigInt(0),Rn=BigInt(1),Yh=BigInt(2);function Nt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function yr(r){if(!Nt(r))throw new Error("Uint8Array expected")}function je(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}var Xh=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function mt(r){yr(r);let e="";for(let t=0;t<r.length;t++)e+=Xh[r[t]];return e}function Wt(r){let e=r.toString(16);return e.length&1?"0"+e:e}function eo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Nn:BigInt("0x"+r)}var pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Rc(r){if(r>=pt._0&&r<=pt._9)return r-pt._0;if(r>=pt.A&&r<=pt.F)return r-(pt.A-10);if(r>=pt.a&&r<=pt.f)return r-(pt.a-10)}function Zt(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("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){let o=Rc(r.charCodeAt(i)),a=Rc(r.charCodeAt(i+1));if(o===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[s]=o*16+a}return n}function gt(r){return eo(mt(r))}function Rt(r){return yr(r),eo(mt(Uint8Array.from(r).reverse()))}function Lt(r,e){return Zt(r.toString(16).padStart(e*2,"0"))}function jt(r,e){return Lt(r,e).reverse()}function Jh(r){return Zt(Wt(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=Zt(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Nt(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(r+" of length "+t+" expected, got "+s);return n}function yt(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];yr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}function Qh(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 ed(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Ji=r=>typeof r=="bigint"&&Nn<=r;function zr(r,e,t){return Ji(r)&&Ji(e)&&Ji(t)&&e<=r&&r<t}function Re(r,e,t,n){if(!zr(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function to(r){let e;for(e=0;r>Nn;r>>=Rn,e+=1);return e}function td(r,e){return r>>BigInt(e)&Rn}function rd(r,e,t){return r|(t?Rn:Nn)<<BigInt(e)}var $r=r=>(Yh<<BigInt(r-1))-Rn,Qi=r=>new Uint8Array(r),Lc=r=>Uint8Array.from(r);function ro(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=Qi(r),s=Qi(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...f)=>t(s,n,...f),c=(f=Qi())=>{s=a(Lc([0]),f),n=a(),f.length!==0&&(s=a(Lc([1]),f),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=a();let p=n.slice();h.push(p),f+=n.length}return yt(...h)};return(f,h)=>{o(),c(f);let p;for(;!(p=h(u()));)c();return o(),p}}var nd={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"||Nt(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 st(r,e,t={}){let n=(s,i,o)=>{let a=nd[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error("param "+String(s)+" is invalid. Expected "+i+", got "+c)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(t))n(s,i,!0);return r}var sd=()=>{throw new Error("not implemented")};function Yt(r){let e=new WeakMap;return(t,...n)=>{let s=e.get(t);if(s!==void 0)return s;let i=r(t,...n);return e.set(t,i),i}}var ue=BigInt(0),ne=BigInt(1),Xt=BigInt(2),id=BigInt(3),no=BigInt(4),Uc=BigInt(5),Dc=BigInt(8),od=BigInt(9),ad=BigInt(16);function Y(r,e){let t=r%e;return t>=ue?t:e+t}function cd(r,e,t){if(e<ue)throw new Error("invalid exponent, negatives unsupported");if(t<=ue)throw new Error("invalid modulus");if(t===ne)return ue;let n=ne;for(;e>ue;)e&ne&&(n=n*r%t),r=r*r%t,e>>=ne;return n}function se(r,e,t){let n=r;for(;e-- >ue;)n*=n,n%=t;return n}function Un(r,e){if(r===ue)throw new Error("invert: expected non-zero number");if(e<=ue)throw new Error("invert: expected positive modulus, got "+e);let t=Y(r,e),n=e,s=ue,i=ne,o=ne,a=ue;for(;t!==ue;){let u=n/t,l=n%t,f=s-o*u,h=i-a*u;n=t,t=l,s=o,i=a,o=f,a=h}if(n!==ne)throw new Error("invert: does not exist");return Y(s,e)}function ld(r){let e=(r-ne)/Xt,t,n,s;for(t=r-ne,n=0;t%Xt===ue;t/=Xt,n++);for(s=Xt;s<r&&cd(s,e,r)!==r-ne;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let o=(r+ne)/no;return function(c,u){let l=c.pow(u,o);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let i=(t+ne)/Xt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),t),f=a.pow(c,i),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let p=1;for(let b=a.sqr(h);p<u&&!a.eql(b,a.ONE);p++)b=a.sqr(b);let y=a.pow(l,ne<<BigInt(u-p-1));l=a.sqr(y),f=a.mul(f,y),h=a.mul(h,l),u=p}return f}}function ud(r){if(r%no===id){let e=(r+ne)/no;return function(n,s){let i=n.pow(s,e);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%Dc===Uc){let e=(r-Uc)/Dc;return function(n,s){let i=n.mul(s,Xt),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,Xt),o),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%ad,ld(r)}var Oc=(r,e)=>(Y(r,e)&ne)===ne,fd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=fd.reduce((n,s)=>(n[s]="function",n),e);return st(r,t)}function hd(r,e,t){if(t<ue)throw new Error("invalid exponent, negatives unsupported");if(t===ue)return r.ONE;if(t===ne)return e;let n=r.ONE,s=e;for(;t>ue;)t&ne&&(n=r.mul(n,s)),s=r.sqr(s),t>>=ne;return n}function dd(r,e){let t=new Array(e.length),n=e.reduce((i,o,a)=>r.is0(o)?i:(t[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return e.reduceRight((i,o,a)=>r.is0(o)?i:(t[a]=r.mul(i,t[a]),r.mul(i,o)),s),t}function io(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Ut(r,e,t=!1,n={}){if(r<=ue)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:s,nByteLength:i}=io(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o,a=Object.freeze({ORDER:r,isLE:t,BITS:s,BYTES:i,MASK:$r(s),ZERO:ue,ONE:ne,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ue<=c&&c<r},is0:c=>c===ue,isOdd:c=>(c&ne)===ne,neg:c=>Y(-c,r),eql:(c,u)=>c===u,sqr:c=>Y(c*c,r),add:(c,u)=>Y(c+u,r),sub:(c,u)=>Y(c-u,r),mul:(c,u)=>Y(c*u,r),pow:(c,u)=>hd(a,c,u),div:(c,u)=>Y(c*Un(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Un(c,r),sqrt:n.sqrt||(c=>(o||(o=ud(r)),o(a,c))),invertBatch:c=>dd(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?jt(c,i):Lt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?Rt(c):gt(c)}});return Object.freeze(a)}function Mc(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 oo(r){let e=Mc(r);return e+Math.ceil(e/2)}function Pc(r,e,t=!1){let n=r.length,s=Mc(e),i=oo(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=t?Rt(r):gt(r),a=Y(o,e-ne)+ne;return t?jt(a,s):Lt(a,s)}var Vc=BigInt(0),Dn=BigInt(1);function ao(r,e){let t=e.negate();return r?t:e}function Hc(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function co(r,e){Hc(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1);return{windows:t,windowSize:n}}function pd(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function md(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var lo=new WeakMap,Fc=new WeakMap;function uo(r){return Fc.get(r)||1}function On(r,e){return{constTimeNegate:ao,hasPrecomputes(t){return uo(t)!==1},unsafeLadder(t,n,s=r.ZERO){let i=t;for(;n>Vc;)n&Dn&&(s=s.add(i)),i=i.double(),n>>=Dn;return s},precomputeWindow(t,n){let{windows:s,windowSize:i}=co(n,e),o=[],a=t,c=a;for(let u=0;u<s;u++){c=a,o.push(c);for(let l=1;l<i;l++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(t,n,s){let{windows:i,windowSize:o}=co(t,e),a=r.ZERO,c=r.BASE,u=BigInt(2**t-1),l=2**t,f=BigInt(t);for(let h=0;h<i;h++){let p=h*o,y=Number(s&u);s>>=f,y>o&&(y-=l,s+=Dn);let b=p,d=p+Math.abs(y)-1,x=h%2!==0,E=y<0;y===0?c=c.add(ao(x,n[b])):a=a.add(ao(E,n[d]))}return{p:a,f:c}},wNAFUnsafe(t,n,s,i=r.ZERO){let{windows:o,windowSize:a}=co(t,e),c=BigInt(2**t-1),u=2**t,l=BigInt(t);for(let f=0;f<o;f++){let h=f*a;if(s===Vc)break;let p=Number(s&c);if(s>>=l,p>a&&(p-=u,s+=Dn),p===0)continue;let y=n[h+Math.abs(p)-1];p<0&&(y=y.negate()),i=i.add(y)}return i},getPrecomputes(t,n,s){let i=lo.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&lo.set(n,s(i))),i},wNAFCached(t,n,s){let i=uo(t);return this.wNAF(i,this.getPrecomputes(i,t,s),n)},wNAFCachedUnsafe(t,n,s,i){let o=uo(t);return o===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(o,this.getPrecomputes(o,t,s),n,i)},setWindowSize(t,n){Hc(n,e),Fc.set(t,n),lo.delete(t)}}}function Mn(r,e,t,n){if(pd(t,r),md(n,e),t.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,i=to(BigInt(t.length)),o=i>12?i-3:i>4?i-2:i?2:1,a=(1<<o)-1,c=new Array(a+1).fill(s),u=Math.floor((e.BITS-1)/o)*o,l=s;for(let f=u;f>=0;f-=o){c.fill(s);for(let p=0;p<n.length;p++){let y=n[p],b=Number(y>>BigInt(f)&BigInt(a));c[b]=c[b].add(t[p])}let h=s;for(let p=c.length-1,y=s;p>0;p--)y=y.add(c[p]),h=h.add(y);if(l=l.add(h),f!==0)for(let p=0;p<o;p++)l=l.double()}return l}function Gr(r){return so(r.Fp),st(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...io(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ye=BigInt(0),Le=BigInt(1),Pn=BigInt(2),gd=BigInt(8),yd={zip215:!0};function bd(r){let e=Gr(r);return st(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Kc(r){let e=bd(r),{Fp:t,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,u=Pn<<BigInt(a*8)-Le,l=t.create,f=Ut(e.n,e.nBitLength),h=e.uvRatio||((w,m)=>{try{return{isValid:!0,value:t.sqrt(w*t.inv(m))}}catch{return{isValid:!1,value:Ye}}}),p=e.adjustScalarBytes||(w=>w),y=e.domain||((w,m,v)=>{if(je("phflag",v),m.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,m){Re("coordinate "+w,m,Ye,u)}function d(w){if(!(w instanceof g))throw new Error("ExtendedPoint expected")}let x=Yt((w,m)=>{let{ex:v,ey:B,ez:L}=w,U=w.is0();m==null&&(m=U?gd:t.inv(L));let M=l(v*m),q=l(B*m),D=l(L*m);if(U)return{x:Ye,y:Le};if(D!==Le)throw new Error("invZ was invalid");return{x:M,y:q}}),E=Yt(w=>{let{a:m,d:v}=e;if(w.is0())throw new Error("bad point: ZERO");let{ex:B,ey:L,ez:U,et:M}=w,q=l(B*B),D=l(L*L),Z=l(U*U),ee=l(Z*Z),he=l(q*m),de=l(Z*l(he+D)),ye=l(ee+l(v*l(q*D)));if(de!==ye)throw new Error("bad point: equation left != right (1)");let xe=l(B*L),Ne=l(U*M);if(xe!==Ne)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(m,v,B,L){this.ex=m,this.ey=v,this.ez=B,this.et=L,b("x",m),b("y",v),b("z",B),b("t",L),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof g)throw new Error("extended point not allowed");let{x:v,y:B}=m||{};return b("x",v),b("y",B),new g(v,B,Le,l(v*B))}static normalizeZ(m){let v=t.invertBatch(m.map(B=>B.ez));return m.map((B,L)=>B.toAffine(v[L])).map(g.fromAffine)}static msm(m,v){return Mn(g,f,m,v)}_setWindowSize(m){R.setWindowSize(this,m)}assertValidity(){E(this)}equals(m){d(m);let{ex:v,ey:B,ez:L}=this,{ex:U,ey:M,ez:q}=m,D=l(v*q),Z=l(U*L),ee=l(B*q),he=l(M*L);return D===Z&&ee===he}is0(){return this.equals(g.ZERO)}negate(){return new g(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:m}=e,{ex:v,ey:B,ez:L}=this,U=l(v*v),M=l(B*B),q=l(Pn*l(L*L)),D=l(m*U),Z=v+B,ee=l(l(Z*Z)-U-M),he=D+M,de=he-q,ye=D-M,xe=l(ee*de),Ne=l(he*ye),Te=l(ee*ye),rt=l(de*he);return new g(xe,Ne,rt,Te)}add(m){d(m);let{a:v,d:B}=e,{ex:L,ey:U,ez:M,et:q}=this,{ex:D,ey:Z,ez:ee,et:he}=m;if(v===BigInt(-1)){let Za=l((U-L)*(Z+D)),ja=l((U+L)*(Z-D)),Oi=l(ja-Za);if(Oi===Ye)return this.double();let Ya=l(M*Pn*he),Xa=l(q*Pn*ee),Ja=Xa+Ya,Qa=ja+Za,ec=Xa-Ya,_f=l(Ja*Oi),If=l(Qa*ec),Tf=l(Ja*ec),kf=l(Oi*Qa);return new g(_f,If,kf,Tf)}let de=l(L*D),ye=l(U*Z),xe=l(q*B*he),Ne=l(M*ee),Te=l((L+U)*(D+Z)-de-ye),rt=Ne-xe,lt=Ne+xe,Mr=l(ye-v*de),Ef=l(Te*rt),Sf=l(lt*Mr),Af=l(Te*Mr),Bf=l(rt*lt);return new g(Ef,Sf,Bf,Af)}subtract(m){return this.add(m.negate())}wNAF(m){return R.wNAFCached(this,m,g.normalizeZ)}multiply(m){let v=m;Re("scalar",v,Le,n);let{p:B,f:L}=this.wNAF(v);return g.normalizeZ([B,L])[0]}multiplyUnsafe(m,v=g.ZERO){let B=m;return Re("scalar",B,Ye,n),B===Ye?N:this.is0()||B===Le?this:R.wNAFCachedUnsafe(this,B,g.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(m){return x(this,m)}clearCofactor(){let{h:m}=e;return m===Le?this:this.multiplyUnsafe(m)}static fromHex(m,v=!1){let{d:B,a:L}=e,U=t.BYTES;m=ie("pointHex",m,U),je("zip215",v);let M=m.slice(),q=m[U-1];M[U-1]=q&-129;let D=Rt(M),Z=v?u:t.ORDER;Re("pointHex.y",D,Ye,Z);let ee=l(D*D),he=l(ee-Le),de=l(B*ee-L),{isValid:ye,value:xe}=h(he,de);if(!ye)throw new Error("Point.fromHex: invalid y coordinate");let Ne=(xe&Le)===Le,Te=(q&128)!==0;if(!v&&xe===Ye&&Te)throw new Error("Point.fromHex: x=0 and x_0=1");return Te!==Ne&&(xe=l(-xe)),g.fromAffine({x:xe,y:D})}static fromPrivateKey(m){return T(m).point}toRawBytes(){let{x:m,y:v}=this.toAffine(),B=jt(v,t.BYTES);return B[B.length-1]|=m&Le?128:0,B}toHex(){return mt(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Le,l(e.Gx*e.Gy)),g.ZERO=new g(Ye,Le,Le,Ye);let{BASE:_,ZERO:N}=g,R=On(g,a*8);function I(w){return Y(w,n)}function C(w){return I(Rt(w))}function T(w){let m=t.BYTES;w=ie("private key",w,m);let v=ie("hashed private key",i(w),2*m),B=p(v.slice(0,m)),L=v.slice(m,2*m),U=C(B),M=_.multiply(U),q=M.toRawBytes();return{head:B,prefix:L,scalar:U,point:M,pointBytes:q}}function re(w){return T(w).pointBytes}function $(w=new Uint8Array,...m){let v=yt(...m);return C(i(y(v,ie("context",w),!!s)))}function F(w,m,v={}){w=ie("message",w),s&&(w=s(w));let{prefix:B,scalar:L,pointBytes:U}=T(m),M=$(v.context,B,w),q=_.multiply(M).toRawBytes(),D=$(v.context,q,U,w),Z=I(M+D*L);Re("signature.s",Z,Ye,n);let ee=yt(q,jt(Z,t.BYTES));return ie("result",ee,t.BYTES*2)}let le=yd;function S(w,m,v,B=le){let{context:L,zip215:U}=B,M=t.BYTES;w=ie("signature",w,2*M),m=ie("message",m),v=ie("publicKey",v,M),U!==void 0&&je("zip215",U),s&&(m=s(m));let q=Rt(w.slice(M,2*M)),D,Z,ee;try{D=g.fromHex(v,U),Z=g.fromHex(w.slice(0,M),U),ee=_.multiplyUnsafe(q)}catch{return!1}if(!U&&D.isSmallOrder())return!1;let he=$(L,Z.toRawBytes(),D.toRawBytes(),m);return Z.add(D.multiplyUnsafe(he)).subtract(ee).clearCofactor().equals(g.ZERO)}return _._setWindowSize(8),{CURVE:e,getPublicKey:re,sign:F,verify:S,ExtendedPoint:g,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>o(t.BYTES),precompute(w=8,m=g.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}}}}var fo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),qc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Zm=BigInt(0),wd=BigInt(1),zc=BigInt(2),jm=BigInt(3),xd=BigInt(5),vd=BigInt(8);function Ed(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),s=BigInt(80),i=fo,a=r*r%i*r%i,c=se(a,zc,i)*a%i,u=se(c,wd,i)*r%i,l=se(u,xd,i)*u%i,f=se(l,e,i)*l%i,h=se(f,t,i)*f%i,p=se(h,n,i)*h%i,y=se(p,s,i)*p%i,b=se(y,s,i)*p%i,d=se(b,e,i)*l%i;return{pow_p_5_8:se(d,zc,i)*r%i,b2:a}}function Sd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ad(r,e){let t=fo,n=Y(e*e*e,t),s=Y(n*n*e,t),i=Ed(r*s).pow_p_5_8,o=Y(r*n*i,t),a=Y(e*o*o,t),c=o,u=Y(o*qc,t),l=a===r,f=a===Y(-r,t),h=a===Y(-r*qc,t);return l&&(o=c),(f||h)&&(o=u),Oc(o,t)&&(o=Y(-o,t)),{isValid:l||f,value:o}}var Bd=Ut(fo,void 0,!0),_d={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Bd,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:vd,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Nc,randomBytes:kn,adjustScalarBytes:Sd,uvRatio:Ad},$c=Kc(_d);var Vn=32;function Gc(r,e,t){return $c.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}var Hn=class{type="Ed25519";raw;constructor(e){this.raw=ho(e,Vn)}toMultihash(){return dt.digest(Dt(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t){return Gc(this.raw,t,e)}};function po(r){return r=ho(r,Vn),new Hn(r)}function ho(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}function oe(r=0){return new Uint8Array(r)}function Ue(r=0){return new Uint8Array(r)}var Td=Math.pow(2,7),kd=Math.pow(2,14),Cd=Math.pow(2,21),mo=Math.pow(2,28),go=Math.pow(2,35),yo=Math.pow(2,42),bo=Math.pow(2,49),W=128,Ee=127;function Se(r){if(r<Td)return 1;if(r<kd)return 2;if(r<Cd)return 3;if(r<mo)return 4;if(r<go)return 5;if(r<yo)return 6;if(r<bo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function wo(r,e,t=0){switch(Se(r)){case 8:e[t++]=r&255|W,r/=128;case 7:e[t++]=r&255|W,r/=128;case 6:e[t++]=r&255|W,r/=128;case 5:e[t++]=r&255|W,r/=128;case 4:e[t++]=r&255|W,r>>>=7;case 3:e[t++]=r&255|W,r>>>=7;case 2:e[t++]=r&255|W,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Nd(r,e,t=0){switch(Se(r)){case 8:e.set(t++,r&255|W),r/=128;case 7:e.set(t++,r&255|W),r/=128;case 6:e.set(t++,r&255|W),r/=128;case 5:e.set(t++,r&255|W),r/=128;case 4:e.set(t++,r&255|W),r>>>=7;case 3:e.set(t++,r&255|W),r>>>=7;case 2:e.set(t++,r&255|W),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function xo(r,e){let t=r[e],n=0;if(n+=t&Ee,t<W||(t=r[e+1],n+=(t&Ee)<<7,t<W)||(t=r[e+2],n+=(t&Ee)<<14,t<W)||(t=r[e+3],n+=(t&Ee)<<21,t<W)||(t=r[e+4],n+=(t&Ee)*mo,t<W)||(t=r[e+5],n+=(t&Ee)*go,t<W)||(t=r[e+6],n+=(t&Ee)*yo,t<W)||(t=r[e+7],n+=(t&Ee)*bo,t<W))return n;throw new RangeError("Could not decode varint")}function Rd(r,e){let t=r.get(e),n=0;if(n+=t&Ee,t<W||(t=r.get(e+1),n+=(t&Ee)<<7,t<W)||(t=r.get(e+2),n+=(t&Ee)<<14,t<W)||(t=r.get(e+3),n+=(t&Ee)<<21,t<W)||(t=r.get(e+4),n+=(t&Ee)*mo,t<W)||(t=r.get(e+5),n+=(t&Ee)*go,t<W)||(t=r.get(e+6),n+=(t&Ee)*yo,t<W)||(t=r.get(e+7),n+=(t&Ee)*bo,t<W))return n;throw new RangeError("Could not decode varint")}function ze(r,e,t=0){return e==null&&(e=Ue(Se(r))),e instanceof Uint8Array?wo(r,e,t):Nd(r,e,t)}function bt(r,e=0){return r instanceof Uint8Array?xo(r,e):Rd(r,e)}var vo=new Float32Array([-0]),Ot=new Uint8Array(vo.buffer);function Zc(r,e,t){vo[0]=r,e[t]=Ot[0],e[t+1]=Ot[1],e[t+2]=Ot[2],e[t+3]=Ot[3]}function jc(r,e){return Ot[0]=r[e],Ot[1]=r[e+1],Ot[2]=r[e+2],Ot[3]=r[e+3],vo[0]}var Eo=new Float64Array([-0]),Ae=new Uint8Array(Eo.buffer);function Yc(r,e,t){Eo[0]=r,e[t]=Ae[0],e[t+1]=Ae[1],e[t+2]=Ae[2],e[t+3]=Ae[3],e[t+4]=Ae[4],e[t+5]=Ae[5],e[t+6]=Ae[6],e[t+7]=Ae[7]}function Xc(r,e){return Ae[0]=r[e],Ae[1]=r[e+1],Ae[2]=r[e+2],Ae[3]=r[e+3],Ae[4]=r[e+4],Ae[5]=r[e+5],Ae[6]=r[e+6],Ae[7]=r[e+7],Eo[0]}var Ld=BigInt(Number.MAX_SAFE_INTEGER),Ud=BigInt(Number.MIN_SAFE_INTEGER),Ve=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 Jt;if(e<Ld&&e>Ud)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Jc&&(s=0n,++n>Jc&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return Jt;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):Jt}},Jt=new Ve(0,0);Jt.toBigInt=function(){return 0n};Jt.zzEncode=Jt.zzDecode=function(){return this};Jt.length=function(){return 1};var Jc=4294967296n;function Qc(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 el(r,e,t){if(t-e<1)return"";let s,i=[],o=0,a;for(;e<t;)a=r[e++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(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[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function So(r,e,t){let n=t,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function Xe(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Kn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ao=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,Xe(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 Xe(this,4);return Kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Xe(this,4);return Kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Xe(this,4);let e=jc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Xe(this,4);let e=Xc(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 Xe(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return el(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Xe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Xe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ve(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 Xe(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 Xe(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 Xe(this,8);let e=Kn(this.buf,this.pos+=4),t=Kn(this.buf,this.pos+=4);return new Ve(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=xo(this.buf,this.pos);return this.pos+=Se(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Bo(r){return new Ao(r instanceof Uint8Array?r:r.subarray())}function De(r,e,t){let n=Bo(r);return e.decode(n,void 0,t)}var _o={};ke(_o,{base10:()=>Dd});var Dd=Tt({prefix:"9",name:"base10",alphabet:"0123456789"});var Io={};ke(Io,{base16:()=>Od,base16upper:()=>Md});var Od=ce({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Md=ce({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var To={};ke(To,{base2:()=>Pd});var Pd=ce({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ko={};ke(ko,{base256emoji:()=>qd});var rl=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}"),Vd=rl.reduce((r,e,t)=>(r[t]=e,r),[]),Hd=rl.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Fd(r){return r.reduce((e,t)=>(e+=Vd[t],e),"")}function Kd(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Hd[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var qd=lr({prefix:"\u{1F680}",name:"base256emoji",encode:Fd,decode:Kd});var No={};ke(No,{base64:()=>zd,base64pad:()=>$d,base64url:()=>Co,base64urlpad:()=>Gd});var zd=ce({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$d=ce({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Co=ce({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gd=ce({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ro={};ke(Ro,{base8:()=>Wd});var Wd=ce({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lo={};ke(Lo,{identity:()=>Zd});var Zd=lr({prefix:"\0",name:"identity",encode:r=>fc(r),decode:r=>uc(r)});var Ng=new TextEncoder,Rg=new TextDecoder;var Oo={};ke(Oo,{sha256:()=>br,sha512:()=>Xd});function Do({name:r,code:e,encode:t}){return new Uo(r,e,t)}var Uo=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?We(this.code,t):t.then(n=>We(this.code,n))}else throw Error("Unknown type, must be binary type")}};function sl(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var br=Do({name:"sha2-256",code:18,encode:sl("SHA-256")}),Xd=Do({name:"sha2-512",code:19,encode:sl("SHA-512")});var Wr={...Lo,...To,...Ro,..._o,...Io,...zi,...$i,...qi,...No,...ko},zg={...Oo,...Zi};function ol(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var il=ol("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mo=ol("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=Ue(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Jd={utf8:il,"utf-8":il,hex:Wr.base16,latin1:Mo,ascii:Mo,binary:Mo,...Wr},qn=Jd;function z(r,e="utf8"){let t=qn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Po(r){let e=r??8192,t=e>>>1,n,s=e;return function(o){if(o<1||o>t)return Ue(o);s+o>e&&(n=Ue(e),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}var Qt=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Vo(){}var Fo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Qd=Po();function ep(r){return globalThis.Buffer!=null?Ue(r):Qd(r)}var jr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Qt(Vo,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Qt(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ko((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(zn,10,Ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ve.fromBigInt(e);return this._push(zn,t.length(),t)}uint64Number(e){return this._push(wo,Se(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ve.fromBigInt(e).zzEncode();return this._push(zn,t.length(),t)}sint64Number(e){let t=Ve.fromNumber(e).zzEncode();return this._push(zn,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ho,1,e?1:0)}fixed32(e){return this._push(Zr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ve.fromBigInt(e);return this._push(Zr,4,t.lo)._push(Zr,4,t.hi)}fixed64Number(e){let t=Ve.fromNumber(e);return this._push(Zr,4,t.lo)._push(Zr,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(Zc,4,e)}double(e){return this._push(Yc,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ho,1,0):this.uint32(t)._push(rp,t,e)}string(e){let t=Qc(e);return t!==0?this.uint32(t)._push(So,t,e):this._push(Ho,1,0)}fork(){return this.states=new Fo(this),this.head=this.tail=new Qt(Vo,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 Qt(Vo,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=ep(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ho(r,e,t){e[t]=r&255}function tp(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Ko=class extends Qt{next;constructor(e,t){super(tp,e,t),this.next=void 0}};function zn(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 Zr(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 rp(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(jr.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(np,e,r),this},jr.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sp,e,r),this});function np(r,e,t){e.set(r,t)}function sp(r,e,t){r.length<40?So(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(z(r),t)}function qo(){return new jr}function Oe(r,e){let t=qo();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var wr;(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"})(wr||(wr={}));function $n(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function er(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,o){let a=e(i);o.int32(a)},n=function(i){let o=i.int32();return e(o)};return $n("enum",wr.VARINT,t,n)}function Me(r,e){return $n("message",wr.LENGTH_DELIMITED,r,e)}var Yr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var fe;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(fe||(fe={}));var zo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(zo||(zo={}));(function(r){r.codec=()=>er(zo)})(fe||(fe={}));var it;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.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)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=fe.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(it||(it={}));var $o;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.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)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=fe.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})($o||($o={}));var an={};ke(an,{MAX_RSA_KEY_SIZE:()=>Os,generateRSAKeyPair:()=>nu,jwkToJWKKeyPair:()=>su,jwkToPkcs1:()=>xp,jwkToPkix:()=>ea,jwkToRSAPrivateKey:()=>ru,pkcs1ToJwk:()=>Ql,pkcs1ToRSAPrivateKey:()=>tu,pkixToJwk:()=>eu,pkixToRSAPublicKey:()=>ta});var ip=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]),Mt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pt=new Uint32Array(64),Go=class extends gr{constructor(){super(64,32,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:e,B:t,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,t,n,s,i,o,a,c]}set(e,t,n,s,i,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)Pt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=Pt[f-15],p=Pt[f-2],y=Ze(h,7)^Ze(h,18)^h>>>3,b=Ze(p,17)^Ze(p,19)^p>>>10;Pt[f]=b+Pt[f-7]+y+Pt[f-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Ze(a,6)^Ze(a,11)^Ze(a,25),p=l+h+Tc(a,c,u)+ip[f]+Pt[f]|0,b=(Ze(n,2)^Ze(n,13)^Ze(n,22))+kc(n,s,i)|0;l=u,u=c,c=a,a=o+p|0,o=i,i=s,s=n,n=p+b|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,u,l)}roundClean(){Pt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var xr=Tn(()=>new Go);var K=Of(cl());function tr(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 Vt(r,e,t=-1){let n=t,s=r,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){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 u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[i-l-1]=Math.floor(s/f),s-=u[i-l-1]*f}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Zn(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let i of r)s.set(i,t),t+=i.length;return s}function Zo(){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=tr(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,tr(i,8)-n}function ll(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=Vt(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Vt(e,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ul(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function Pe(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(t)}var By=Math.log(2);function jn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function jo(r){let e=0,t=0;for(let s=0;s<r.length;s++){let i=r[s];e+=i.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function St(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 Jr=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return jo(this.items)}},Xr=[new Uint8Array([1])],fl="0123456789";var Br="",Je=new ArrayBuffer(0),Yo=new Uint8Array(0),Qr="EndOfContent",dl="OCTET STRING",pl="BIT STRING";function At(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?K.BufferSourceConverter.toUint8Array(i.valueHex):Yo}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!St(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}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",Je)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:K.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var xt=class{constructor({blockLength:e=0,error:t=Br,warnings:n=[],valueBeforeDecode:s=Yo}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=K.BufferSourceConverter.toUint8Array(s)}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:K.Convert.ToHex(this.valueBeforeDecodeView)}}};xt.NAME="baseBlock";var Be=class extends xt{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'")}};Be.NAME="valueBlock";var Yn=class extends At(xt){constructor({idBlock:e={}}={}){var t,n,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?K.BufferSourceConverter.toUint8Array(e.valueHex):Yo,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-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",Je}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=Vt(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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,u=this.valueHexView=new Uint8Array(255),l=255;for(;i[c]&128;){if(u[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let h=new Uint8Array(l);for(let p=0;p<u.length;p++)h[p]=u[p];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=i[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=u[h];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=tr(u,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}}};Yn.NAME="identificationBlock";var Xn=class extends xt{constructor({lenBlock:e={}}={}){var t,n,s;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=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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 o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=tr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+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 s=Vt(this.length,8);if(s.byteLength>127)return this.error="Too big length",Je;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let i=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];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}}};Xn.NAME="lengthBlock";var A={},be=class extends xt{constructor({name:e=Br,optional:t=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Yn(s),this.lenBlock=new Xn(s),this.valueBlock=i?new i(s):new Be(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}toBER(e,t){let n=t||new Jr;t||ml(this);let s=this.idBlock.toBER(e);if(n.write(s),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 o=this.lenBlock.toBER(e);n.write(o),n.write(i)}return t?Je: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():K.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${K.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 ul(t,n)}};be.NAME="BaseBlock";function ml(r){if(r instanceof A.Constructed)for(let e of r.valueBlock.value)ml(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Jn=class extends be{constructor({value:e=Br,...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 s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Jn.NAME="BaseStringBlock";var Qn=class extends At(Be){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Qn.NAME="PrimitiveValueBlock";var gl,es=class extends be{constructor(e={}){super(e,Qn),this.idBlock.isConstructed=!1}};gl=es;A.Primitive=gl;es.NAME="PRIMITIVE";function pp(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 Us(r,e=0,t=r.length){let n=e,s=new be({},Be),i=new xt;if(!St(i,r,e,t))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=be;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=A.EndOfContent;break;case 1:c=A.Boolean;break;case 2:c=A.Integer;break;case 3:c=A.BitString;break;case 4:c=A.OctetString;break;case 5:c=A.Null;break;case 6:c=A.ObjectIdentifier;break;case 10:c=A.Enumerated;break;case 12:c=A.Utf8String;break;case 13:c=A.RelativeObjectIdentifier;break;case 14:c=A.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=A.Sequence;break;case 17:c=A.Set;break;case 18:c=A.NumericString;break;case 19:c=A.PrintableString;break;case 20:c=A.TeletexString;break;case 21:c=A.VideotexString;break;case 22:c=A.IA5String;break;case 23:c=A.UTCTime;break;case 24:c=A.GeneralizedTime;break;case 25:c=A.GraphicString;break;case 26:c=A.VisibleString;break;case 27:c=A.GeneralString;break;case 28:c=A.UniversalString;break;case 29:c=A.CharacterString;break;case 30:c=A.BmpString;break;case 31:c=A.DATE;break;case 32:c=A.TimeOfDay;break;case 33:c=A.DateTime;break;case 34:c=A.Duration;break;default:{let u=s.idBlock.isConstructed?new A.Constructed:new A.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?A.Constructed:A.Primitive}return s=pp(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function Xo(r){if(!r.byteLength){let e=new be({},Be);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Us(K.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function mp(r,e){return r?1:e}var ot=class extends Be{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;mp(this.isIndefiniteForm,n)>0;){let o=Us(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Qr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Qr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Jr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?Je:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};ot.NAME="ConstructedValueBlock";var yl,Ht=class extends be{constructor(e={}){super(e,ot),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
3
3
  `).map(s=>` ${s}`).join(`
4
4
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
5
5
  ${e.join(`
6
- `)}`:`${t} :`}};bl=Ht;A.Constructed=bl;Ht.NAME="CONSTRUCTED";var ts=class extends Be{fromBER(e,t,n){return t}toBER(e){return Je}};ts.override="EndOfContentValueBlock";var wl,rs=class extends be{constructor(e={}){super(e,ts),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};wl=rs;A.EndOfContent=wl;rs.NAME=Qr;var xl,Er=class extends be{constructor(e={}){super(e,Be),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 s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};xl=Er;A.Null=xl;Er.NAME="NULL";var ns=class extends At(Be){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=K.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 s=K.BufferSourceConverter.toUint8Array(e);return St(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Zo.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};ns.NAME="BooleanValueBlock";var vl,ss=class extends be{constructor(e={}){super(e,ns),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}`}};vl=ss;A.Boolean=vl;ss.NAME="BOOLEAN";var is=class extends At(ot){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=ot.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===Qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==pl)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?ot.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};is.NAME="OctetStringValueBlock";var El,os=class r extends be{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==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},is),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 o=Us(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Ht.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${K.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 K.BufferSourceConverter.concat(e)}};El=os;A.OctetString=El;os.NAME=pl;var as=class extends At(ot){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 s=-1;if(this.isConstructed){if(s=ot.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==ml)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let i=K.BufferSourceConverter.toUint8Array(e);if(!St(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=Us(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+n}toBER(e,t){if(this.isConstructed)return ot.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Je;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}}};as.NAME="BitStringValueBlock";var Sl,Sr=class extends be{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==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},as),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 Ht.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Sl=Sr;A.BitString=Sl;Sr.NAME=ml;var Al;function gp(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,u=0,l=c<o?o:c,f=0;for(let h=l;h>=0;h--,f++){switch(!0){case f<a.length:u=i[o-f]+a[c-f]+t[0];break;default:u=i[o-f]+t[0]}switch(t[0]=u/10,!0){case f>=i.length:i=Zn(new Uint8Array([u%10]),i);break;default:i[o-f]=u%10}}return t[0]>0&&(i=Zn(t,i)),i}function dl(r){if(r>=Xr.length)for(let e=Xr.length;e<=r;e++){let t=new Uint8Array([0]),n=Xr[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=i[0]/10,n[s]=i[0]%10}t[0]>0&&(n=Zn(t,n)),Xr.push(n)}return Xr[r]}function yp(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=i[o-l]-a[c-l]-t,!0){case u<0:t=1,i[o-l]=u+10;break;default:t=0,i[o-l]=u}if(t>0)for(let f=o-c+1;f>=0;f--,l++)if(u=i[o-l]-t,u<0)t=1,i[o-l]=u+10;else{t=0,i[o-l]=u;break}return i.slice()}var en=class extends At(Be){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=Zo.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ul(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.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 s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}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,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case e:t=yp(dl(n),t),o="-";break;default:t=gp(t,dl(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=hl.charAt(t[c]));return a===!1&&(o+=hl.charAt(0)),o}};Al=en;en.NAME="IntegerValueBlock";Object.defineProperty(Al.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Bl,we=class r extends be{constructor(e={}){super(e,en),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return jn(),BigInt(this.valueBlock.toString())}static fromBigInt(e){jn();let t=BigInt(e),n=new Jr,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(K.Convert.FromHex(s));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${K.Convert.ToHex(a)}`)+t,l=K.BufferSourceConverter.toUint8Array(K.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}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()}`}};Bl=we;A.Integer=Bl;we.NAME="INTEGER";var _l,cs=class extends we{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};_l=cs;A.Enumerated=_l;cs.NAME="ENUMERATED";var tn=class extends At(Be){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 s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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 o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,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=tr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){jn();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+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 s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=Vt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let e="";if(this.isHexOnly)e=K.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}}};tn.NAME="sidBlock";var ls=class extends Be{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new tn;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,Je;t.push(s)}return jo(t)}fromString(e){this.value=[];let t=0,n=0,s="",i=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new tn;if(s>Number.MAX_SAFE_INTEGER){jn();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}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}};ls.NAME="ObjectIdentifierValueBlock";var Il,Ar=class extends be{constructor(e={}){super(e,ls),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()}}};Il=Ar;A.ObjectIdentifier=Il;Ar.NAME="OBJECT IDENTIFIER";var rn=class extends At(xt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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 o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,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=tr(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 s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=Vt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=K.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};rn.NAME="relativeSidBlock";var us=class extends Be{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new rn;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,Je;n.push(i)}return jo(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let i=new rn;if(i.valueDec=parseInt(s,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 s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}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}};us.NAME="RelativeObjectIdentifierValueBlock";var Tl,fs=class extends be{constructor(e={}){super(e,us),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()}}};Tl=fs;A.RelativeObjectIdentifier=Tl;fs.NAME="RelativeObjectIdentifier";var kl,vt=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};kl=vt;A.Sequence=kl;vt.NAME="SEQUENCE";var Cl,hs=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Cl=hs;A.Set=Cl;hs.NAME="SET";var ds=class extends At(Be){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Br}toJSON(){return{...super.toJSON(),value:this.value}}};ds.NAME="StringValueBlock";var ps=class extends ds{};ps.NAME="SimpleStringValueBlock";var Ce=class extends Jn{constructor({...e}={}){super(e,ps)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,K.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};Ce.NAME="SIMPLE STRING";var ms=class extends Ce{fromBuffer(e){this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=K.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=K.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf8String(e)),this.valueBlock.value=e}};ms.NAME="Utf8StringValueBlock";var Nl,Et=class extends ms{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Nl=Et;A.Utf8String=Nl;Et.NAME="UTF8String";var gs=class extends Ce{fromBuffer(e){this.valueBlock.value=K.Convert.ToUtf16String(e),this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf16String(e))}};gs.NAME="BmpStringValueBlock";var Rl,ys=class extends gs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Rl=ys;A.BmpString=Rl;ys.NAME="BMPString";var bs=class extends Ce{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+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 s=0;s<t;s++){let i=Vt(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=e}};bs.NAME="UniversalStringValueBlock";var Ll,ws=class extends bs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Ll=ws;A.UniversalString=Ll;ws.NAME="UniversalString";var Ul,xs=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Ul=xs;A.NumericString=Ul;xs.NAME="NumericString";var Dl,vs=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Dl=vs;A.PrintableString=Dl;vs.NAME="PrintableString";var Ol,Es=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Ol=Es;A.TeletexString=Ol;Es.NAME="TeletexString";var Ml,Ss=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Ml=Ss;A.VideotexString=Ml;Ss.NAME="VideotexString";var Pl,As=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Pl=As;A.IA5String=Pl;As.NAME="IA5String";var Vl,Bs=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Vl=Bs;A.GraphicString=Vl;Bs.NAME="GraphicString";var Hl,nn=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Hl=nn;A.VisibleString=Hl;nn.NAME="VisibleString";var Fl,_s=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Fl=_s;A.GeneralString=Fl;_s.NAME="GeneralString";var Kl,Is=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Kl=Is;A.CharacterString=Kl;Is.NAME="CharacterString";var ql,sn=class extends nn{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 s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}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,K.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);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 s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,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]=Pe(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Pe(this.month,2),t[2]=Pe(this.day,2),t[3]=Pe(this.hour,2),t[4]=Pe(this.minute,2),t[5]=Pe(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}}};ql=sn;A.UTCTime=ql;sn.NAME="UTCTime";var zl,Ts=class extends sn{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="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.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 f=1,h=n.indexOf("+"),p="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(p=n.substring(h+1),n=n.substring(0,h),p.length!==2&&p.length!==4)throw new Error("Wrong input string for conversion");let y=parseInt(p.substring(0,2),10);if(isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*y,p.length===4){if(y=parseInt(p.substring(2,4),10),isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");c=f*y}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");i=f.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*i;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=o.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Pe(this.year,4)),t.push(Pe(this.month,2)),t.push(Pe(this.day,2)),t.push(Pe(this.hour,2)),t.push(Pe(this.minute,2)),t.push(Pe(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Pe(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};zl=Ts;A.GeneralizedTime=zl;Ts.NAME="GeneralizedTime";var $l,ks=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};$l=ks;A.DATE=$l;ks.NAME="DATE";var Gl,Cs=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Gl=Cs;A.TimeOfDay=Gl;Cs.NAME="TimeOfDay";var Wl,Ns=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Wl=Ns;A.DateTime=Wl;Ns.NAME="DateTime";var Zl,Rs=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Zl=Rs;A.Duration=Zl;Rs.NAME="Duration";var jl,Ls=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};jl=Ls;A.TIME=jl;Ls.NAME="TIME";function ae(r,e="utf8"){let t=qn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var on=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Ds=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Yl={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new Ds("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Ft=Yl;async function Xl(r){let e=await Ft.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 wp(e);return{privateKey:t[0],publicKey:t[1]}}async function Jl(r,e){let t=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ft.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ql(r,e,t){let n=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ft.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function wp(r){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");return Promise.all([Ft.get().subtle.exportKey("jwk",r.privateKey),Ft.get().subtle.exportKey("jwk",r.publicKey)])}function Jo(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return z(r.n,"base64url").length*8}var _r=class{type="RSA";_key;_raw;_multihash;constructor(e,t){this._key=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=an.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return pe.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t){return Ql(this._key,t,e)}},cn=class{type="RSA";_key;_raw;publicKey;constructor(e,t){this._key=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this._key)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e){return Jl(this._key,e)}};var Os=8192,Qo=18;function eu(r){let{result:e}=Xo(r),t=e.valueBlock.value;return{n:at(t[1]),e:at(t[2]),d:at(t[3]),p:at(t[4]),q:at(t[5]),dp:at(t[6]),dq:at(t[7]),qi:at(t[8]),kty:"RSA",alg:"RS256"}}function xp(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 ve("JWK was missing components");let t=new vt({value:[new we({value:0}),we.fromBigInt(ct(z(r.n,"base64url"))),we.fromBigInt(ct(z(r.e,"base64url"))),we.fromBigInt(ct(z(r.d,"base64url"))),we.fromBigInt(ct(z(r.p,"base64url"))),we.fromBigInt(ct(z(r.q,"base64url"))),we.fromBigInt(ct(z(r.dp,"base64url"))),we.fromBigInt(ct(z(r.dq,"base64url"))),we.fromBigInt(ct(z(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function tu(r){let{result:e}=Xo(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:at(t[0]),e:at(t[1])}}function ea(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");let t=new vt({value:[new vt({value:[new Ar({value:"1.2.840.113549.1.1.1"}),new Er]}),new Sr({valueHex:new vt({value:[we.fromBigInt(ct(z(r.n,"base64url"))),we.fromBigInt(ct(z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function at(r){let e=r.valueBlock.valueHexView;for(;e[0]===0;)e=e.subarray(1);return ae(e,"base64url")}function ct(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(""))}function ru(r){let e=eu(r);return nu(e)}function ta(r){let e=tu(r);if(Jo(e)>Os)throw new ar("Key size is too large");let t=xr(it.encode({Type:fe.RSA,Data:r})),n=We(Qo,t);return new _r(e,n)}function nu(r){if(Jo(r)>Os)throw new ve("Key size is too large");let e=iu(r),t=xr(it.encode({Type:fe.RSA,Data:ea(e.publicKey)})),n=We(Qo,t);return new cn(e.privateKey,new _r(e.publicKey,n))}async function su(r){if(r>Os)throw new ve("Key size is too large");let e=await Xl(r),t=xr(it.encode({Type:fe.RSA,Data:ea(e.publicKey)})),n=We(Qo,t);return new cn(e.privateKey,new _r(e.publicKey,n))}function iu(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Ms=class extends mr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,_c(e);let n=qr(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 s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(e){return pr(this),this.iHash.update(e),this}digestInto(e){pr(this),dr(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:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,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()}},ra=(r,e,t)=>new Ms(r,e).update(t).digest();ra.create=(r,e)=>new Ms(r,e);function ou(r){r.lowS!==void 0&&je("lowS",r.lowS),r.prehash!==void 0&&je("prehash",r.prehash)}function vp(r){let e=Gr(r);st(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:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("invalid 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("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:Ep,hexToBytes:Sp}=Ln,na=class extends Error{constructor(e=""){super(e)}},Bt={Err:na,_tlv:{encode:(r,e)=>{let{Err:t}=Bt;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,s=Wt(n);if(s.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Wt(s.length/2|128):"";return Wt(r)+i+s+e},decode(r,e){let{Err:t}=Bt,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)o=o<<8|l;if(n+=c,o<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(r){let{Err:e}=Bt;if(r<_t)throw new e("integer: negative integers are not allowed");let t=Wt(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=Bt;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ep(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Bt,s=typeof r=="string"?Sp(r):r;yr(s);let{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(r){let{_tlv:e,_int:t}=Bt,n=e.encode(2,t.encode(r.r)),s=e.encode(2,t.encode(r.s)),i=n+s;return e.encode(48,i)}},_t=BigInt(0),ge=BigInt(1),nb=BigInt(2),au=BigInt(3),sb=BigInt(4);function Ap(r){let e=vp(r),{Fp:t}=e,n=Ut(e.n,e.nBitLength),s=e.toBytes||((b,d,x)=>{let E=d.toAffine();return yt(Uint8Array.from([4]),t.toBytes(E.x),t.toBytes(E.y))}),i=e.fromBytes||(b=>{let d=b.subarray(1),x=t.fromBytes(d.subarray(0,t.BYTES)),E=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x,y:E}});function o(b){let{a:d,b:x}=e,E=t.sqr(b),g=t.mul(E,b);return t.add(t.add(g,t.mul(b,d)),x)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return zr(b,ge,e.n)}function c(b){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:E,n:g}=e;if(d&&typeof b!="bigint"){if(Nt(b)&&(b=mt(b)),typeof b!="string"||!d.includes(b.length))throw new Error("invalid private key");b=b.padStart(x*2,"0")}let _;try{_=typeof b=="bigint"?b:gt(ie("private key",b,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof b)}return E&&(_=Y(_,g)),Re("private key",_,ge,g),_}function u(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let l=Yt((b,d)=>{let{px:x,py:E,pz:g}=b;if(t.eql(g,t.ONE))return{x,y:E};let _=b.is0();d==null&&(d=_?t.ONE:t.inv(g));let N=t.mul(x,d),R=t.mul(E,d),I=t.mul(g,d);if(_)return{x:t.ZERO,y:t.ZERO};if(!t.eql(I,t.ONE))throw new Error("invZ was invalid");return{x:N,y:R}}),f=Yt(b=>{if(b.is0()){if(e.allowInfinityPoint&&!t.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=b.toAffine();if(!t.isValid(d)||!t.isValid(x))throw new Error("bad point: x or y not FE");let E=t.sqr(x),g=o(d);if(!t.eql(E,g))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,x,E){if(this.px=d,this.py=x,this.pz=E,d==null||!t.isValid(d))throw new Error("x required");if(x==null||!t.isValid(x))throw new Error("y required");if(E==null||!t.isValid(E))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x,y:E}=d||{};if(!d||!t.isValid(x)||!t.isValid(E))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let g=_=>t.eql(_,t.ZERO);return g(x)&&g(E)?h.ZERO:new h(x,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=t.invertBatch(d.map(E=>E.pz));return d.map((E,g)=>E.toAffine(x[g])).map(h.fromAffine)}static fromHex(d){let x=h.fromAffine(i(ie("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,x){return Mn(h,n,d,x)}_setWindowSize(d){y.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:x,py:E,pz:g}=this,{px:_,py:N,pz:R}=d,I=t.eql(t.mul(x,R),t.mul(_,g)),C=t.eql(t.mul(E,R),t.mul(N,g));return I&&C}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:x}=e,E=t.mul(x,au),{px:g,py:_,pz:N}=this,R=t.ZERO,I=t.ZERO,C=t.ZERO,T=t.mul(g,g),re=t.mul(_,_),$=t.mul(N,N),F=t.mul(g,_);return F=t.add(F,F),C=t.mul(g,N),C=t.add(C,C),R=t.mul(d,C),I=t.mul(E,$),I=t.add(R,I),R=t.sub(re,I),I=t.add(re,I),I=t.mul(R,I),R=t.mul(F,R),C=t.mul(E,C),$=t.mul(d,$),F=t.sub(T,$),F=t.mul(d,F),F=t.add(F,C),C=t.add(T,T),T=t.add(C,T),T=t.add(T,$),T=t.mul(T,F),I=t.add(I,T),$=t.mul(_,N),$=t.add($,$),T=t.mul($,F),R=t.sub(R,T),C=t.mul($,re),C=t.add(C,C),C=t.add(C,C),new h(R,I,C)}add(d){u(d);let{px:x,py:E,pz:g}=this,{px:_,py:N,pz:R}=d,I=t.ZERO,C=t.ZERO,T=t.ZERO,re=e.a,$=t.mul(e.b,au),F=t.mul(x,_),le=t.mul(E,N),S=t.mul(g,R),k=t.add(x,E),w=t.add(_,N);k=t.mul(k,w),w=t.add(F,le),k=t.sub(k,w),w=t.add(x,g);let m=t.add(_,R);return w=t.mul(w,m),m=t.add(F,S),w=t.sub(w,m),m=t.add(E,g),I=t.add(N,R),m=t.mul(m,I),I=t.add(le,S),m=t.sub(m,I),T=t.mul(re,w),I=t.mul($,S),T=t.add(I,T),I=t.sub(le,T),T=t.add(le,T),C=t.mul(I,T),le=t.add(F,F),le=t.add(le,F),S=t.mul(re,S),w=t.mul($,w),le=t.add(le,S),S=t.sub(F,S),S=t.mul(re,S),w=t.add(w,S),F=t.mul(le,w),C=t.add(C,F),F=t.mul(m,w),I=t.mul(k,I),I=t.sub(I,F),F=t.mul(k,le),T=t.mul(m,T),T=t.add(T,F),new h(I,C,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return y.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:x,n:E}=e;Re("scalar",d,_t,E);let g=h.ZERO;if(d===_t)return g;if(this.is0()||d===ge)return this;if(!x||y.hasPrecomputes(this))return y.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:_,k1:N,k2neg:R,k2:I}=x.splitScalar(d),C=g,T=g,re=this;for(;N>_t||I>_t;)N&ge&&(C=C.add(re)),I&ge&&(T=T.add(re)),re=re.double(),N>>=ge,I>>=ge;return _&&(C=C.negate()),R&&(T=T.negate()),T=new h(t.mul(T.px,x.beta),T.py,T.pz),C.add(T)}multiply(d){let{endo:x,n:E}=e;Re("scalar",d,ge,E);let g,_;if(x){let{k1neg:N,k1:R,k2neg:I,k2:C}=x.splitScalar(d),{p:T,f:re}=this.wNAF(R),{p:$,f:F}=this.wNAF(C);T=y.constTimeNegate(N,T),$=y.constTimeNegate(I,$),$=new h(t.mul($.px,x.beta),$.py,$.pz),g=T.add($),_=re.add(F)}else{let{p:N,f:R}=this.wNAF(d);g=N,_=R}return h.normalizeZ([g,_])[0]}multiplyAndAddUnsafe(d,x,E){let g=h.BASE,_=(R,I)=>I===_t||I===ge||!R.equals(g)?R.multiplyUnsafe(I):R.multiply(I),N=_(this,x).add(_(d,E));return N.is0()?void 0:N}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=e;if(d===ge)return!0;if(x)return x(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=e;return d===ge?this:x?x(h,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return je("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return je("isCompressed",d),mt(this.toRawBytes(d))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let p=e.nBitLength,y=On(h,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function Bp(r){let e=Gr(r);return st(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function cu(r){let e=Bp(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(S){return Y(S,n)}function a(S){return Un(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Ap({...e,toBytes(S,k,w){let m=k.toAffine(),v=t.toBytes(m.x),B=yt;return je("isCompressed",w),w?B(Uint8Array.from([k.hasEvenY()?2:3]),v):B(Uint8Array.from([4]),v,t.toBytes(m.y))},fromBytes(S){let k=S.length,w=S[0],m=S.subarray(1);if(k===s&&(w===2||w===3)){let v=gt(m);if(!zr(v,ge,t.ORDER))throw new Error("Point is not on curve");let B=l(v),L;try{L=t.sqrt(B)}catch(q){let D=q instanceof Error?": "+q.message:"";throw new Error("Point is not on curve"+D)}let U=(L&ge)===ge;return(w&1)===1!==U&&(L=t.neg(L)),{x:v,y:L}}else if(k===i&&w===4){let v=t.fromBytes(m.subarray(0,t.BYTES)),B=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:v,y:B}}else{let v=s,B=i;throw new Error("invalid Point, expected length of "+v+", or uncompressed "+B+", got "+k)}}}),h=S=>mt(Lt(S,e.nByteLength));function p(S){let k=n>>ge;return S>k}function y(S){return p(S)?o(-S):S}let b=(S,k,w)=>gt(S.slice(k,w));class d{constructor(k,w,m){this.r=k,this.s=w,this.recovery=m,this.assertValidity()}static fromCompact(k){let w=e.nByteLength;return k=ie("compactSignature",k,w*2),new d(b(k,0,w),b(k,w,2*w))}static fromDER(k){let{r:w,s:m}=Bt.toSig(ie("DER",k));return new d(w,m)}assertValidity(){Re("r",this.r,ge,n),Re("s",this.s,ge,n)}addRecoveryBit(k){return new d(this.r,this.s,k)}recoverPublicKey(k){let{r:w,s:m,recovery:v}=this,B=R(ie("msgHash",k));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let L=v===2||v===3?w+e.n:w;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let U=v&1?"03":"02",M=c.fromHex(U+h(L)),q=a(L),D=o(-B*q),Z=o(m*q),ee=c.BASE.multiplyAndAddUnsafe(M,D,Z);if(!ee)throw new Error("point at infinify");return ee.assertValidity(),ee}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Zt(this.toDERHex())}toDERHex(){return Bt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Zt(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let x={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=oo(e.n);return Vc(e.randomBytes(S),e.n)},precompute(S=8,k=c.BASE){return k._setWindowSize(S),k.multiply(BigInt(3)),k}};function E(S,k=!0){return c.fromPrivateKey(S).toRawBytes(k)}function g(S){let k=Nt(S),w=typeof S=="string",m=(k||w)&&S.length;return k?m===s||m===i:w?m===2*s||m===2*i:S instanceof c}function _(S,k,w=!0){if(g(S))throw new Error("first arg must be private key");if(!g(k))throw new Error("second arg must be public key");return c.fromHex(k).multiply(u(S)).toRawBytes(w)}let N=e.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let k=gt(S),w=S.length*8-e.nBitLength;return w>0?k>>BigInt(w):k},R=e.bits2int_modN||function(S){return o(N(S))},I=$r(e.nBitLength);function C(S){return Re("num < 2^"+e.nBitLength,S,_t,I),Lt(S,e.nByteLength)}function T(S,k,w=re){if(["recovered","canonical"].some(de=>de in w))throw new Error("sign() legacy options not supported");let{hash:m,randomBytes:v}=e,{lowS:B,prehash:L,extraEntropy:U}=w;B==null&&(B=!0),S=ie("msgHash",S),ou(w),L&&(S=ie("prehashed msgHash",m(S)));let M=R(S),q=u(k),D=[C(q),C(M)];if(U!=null&&U!==!1){let de=U===!0?v(t.BYTES):U;D.push(ie("extraEntropy",de))}let Z=yt(...D),ee=M;function he(de){let ye=N(de);if(!f(ye))return;let xe=a(ye),Ne=c.BASE.multiply(ye).toAffine(),Te=o(Ne.x);if(Te===_t)return;let rt=o(xe*o(ee+Te*q));if(rt===_t)return;let lt=(Ne.x===Te?0:2)|Number(Ne.y&ge),Mr=rt;return B&&p(rt)&&(Mr=y(rt),lt^=1),new d(Te,Mr,lt)}return{seed:Z,k2sig:he}}let re={lowS:e.lowS,prehash:!1},$={lowS:e.lowS,prehash:!1};function F(S,k,w=re){let{seed:m,k2sig:v}=T(S,k,w),B=e;return ro(B.hash.outputLen,B.nByteLength,B.hmac)(m,v)}c.BASE._setWindowSize(8);function le(S,k,w,m=$){let v=S;k=ie("msgHash",k),w=ie("publicKey",w);let{lowS:B,prehash:L,format:U}=m;if(ou(m),"strict"in m)throw new Error("options.strict was renamed to lowS");if(U!==void 0&&U!=="compact"&&U!=="der")throw new Error("format must be compact or der");let M=typeof v=="string"||Nt(v),q=!M&&!U&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!M&&!q)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let D,Z;try{if(q&&(D=new d(v.r,v.s)),M){try{U!=="compact"&&(D=d.fromDER(v))}catch(lt){if(!(lt instanceof Bt.Err))throw lt}!D&&U!=="der"&&(D=d.fromCompact(v))}Z=c.fromHex(w)}catch{return!1}if(!D||B&&D.hasHighS())return!1;L&&(k=e.hash(k));let{r:ee,s:he}=D,de=R(k),ye=a(he),xe=o(de*ye),Ne=o(ee*ye),Te=c.BASE.multiplyAndAddUnsafe(Z,xe,Ne)?.toAffine();return Te?o(Te.x)===ee:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:_,sign:F,verify:le,ProjectivePoint:c,Signature:d,utils:x}}function _p(r){return{hash:r,hmac:(e,...t)=>ra(r,e,ji(...t)),randomBytes:kn}}function lu(r,e){let t=n=>cu({...r,..._p(n)});return{...t(e),create:t}}var hu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),uu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ip=BigInt(1),sa=BigInt(2),fu=(r,e)=>(r+e/sa)/e;function Tp(r){let e=hu,t=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=se(l,t,e)*l%e,h=se(f,t,e)*l%e,p=se(h,sa,e)*u%e,y=se(p,s,e)*p%e,b=se(y,i,e)*y%e,d=se(b,a,e)*b%e,x=se(d,c,e)*d%e,E=se(x,a,e)*b%e,g=se(E,t,e)*l%e,_=se(g,o,e)*y%e,N=se(_,n,e)*u%e,R=se(N,sa,e);if(!ia.eql(ia.sqr(R),r))throw new Error("Cannot find square root");return R}var ia=Ut(hu,void 0,void 0,{sqrt:Tp}),rr=lu({a:BigInt(0),b:BigInt(7),Fp:ia,n:uu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=uu,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ip*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=fu(i*r,e),c=fu(-n*r,e),u=Y(r-a*t-c*s,e),l=Y(-a*n-c*i,e),f=u>o,h=l>o;if(f&&(u=e-u),h&&(l=e-l),u>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},xr),db=BigInt(0);var pb=rr.ProjectivePoint;function He(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=Ue(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}function du(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function pu(r,e,t){let n=br.digest(t instanceof Uint8Array?t:t.subarray());if(du(n))return n.then(({digest:s})=>rr.verify(e,s,r)).catch(s=>{throw new on(String(s))});try{return rr.verify(e,n.digest,r)}catch(s){throw new on(String(s))}}var Ps=class{type="secp256k1";raw;_key;constructor(e){this._key=gu(e),this.raw=mu(this._key)}toMultihash(){return dt.digest(Dt(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t){return pu(this._key,t,e)}};function oa(r){return new Ps(r)}function mu(r){return rr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function gu(r){try{return rr.ProjectivePoint.fromHex(r),r}catch(e){throw new ar(String(e))}}function yu(r){let{Type:e,Data:t}=it.decode(r),n=t??new Uint8Array;switch(e){case fe.RSA:return ta(n);case fe.Ed25519:return po(n);case fe.secp256k1:return oa(n);default:throw new cr}}function bu(r){let{Type:e,Data:t}=it.decode(r.digest),n=t??new Uint8Array;switch(e){case fe.Ed25519:return po(n);case fe.secp256k1:return oa(n);default:throw new cr}}function Dt(r){return it.encode({Type:fe[r.type],Data:r.raw})}var wu=Symbol.for("nodejs.util.inspect.custom"),kp=114,ln=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Mi]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return pe.createV1(kp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return me(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return me(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[wu](){return`PeerId(${this.toString()})`}},Vs=class extends ln{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Hs=class extends ln{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Fs=class extends ln{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Cp=2336,Ks=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=dt.digest(z(this.url))}[wu](){return`PeerId(${this.url})`}[Mi]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return pe.createV1(Cp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ae(e)),e.toString()===this.toString())}};function aa(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=qe(J.decode(`z${r}`));else{if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=qe(e.decode(r))}return un(t)}function un(r){if(Rp(r))return new Vs({multihash:r});if(Np(r))try{let e=bu(r);if(e.type==="Ed25519")return new Hs({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Fs({multihash:r,publicKey:e})}catch{let t=ae(r.digest);return new Ks(new URL(t))}throw new An("Supplied PeerID Multihash is invalid")}function Np(r){return r.code===dt.code}function Rp(r){return r.code===br.code}var vu=Symbol.for("@achingbrain/uint8arraylist");function xu(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function qs(r){return!!r?.[vu]}var Qe=class r{bufs;length;[vu]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(qs(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(qs(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=xu(this.bufs,e);return t.buf[t.index]}set(e,t){let n=xu(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(qs(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return He(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:He(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),i=new r;return i.length=s,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(o);break}let f=e-a;n.push(o.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(l){if(t===c){n.push(o);break}n.push(o.subarray(0,t-a));break}n.push(o)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!qs(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let f=0;f<i;f++)o[f]=-1;for(let f=0;f<s;f++)o[n[f]]=f;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let p=this.get(f+h);if(n[h]!==p){l=Math.max(1,h-a[p]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Ue(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=oe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=oe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=oe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Ue(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=oe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=oe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=oe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=oe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=oe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!me(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,i)=>s+i.byteLength,0)),n.length=t,n}};var fn;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&t.payload.byteLength>0&&(n.uint32(26),n.bytes(t.payload)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={publicKey:oe(0),payloadType:oe(0),payload:oe(0),signature:oe(0)},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.publicKey=t.bytes();break}case 2:{i.payloadType=t.bytes();break}case 3:{i.payload=t.bytes();break}case 5:{i.signature=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(fn||(fn={}));var zs=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var hn=class r{static createFromProtobuf=async e=>{let t=fn.decode(e),n=yu(t.publicKey);return new r({publicKey:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})};static seal=async(e,t)=>{if(t==null)throw new Error("Missing private key");let n=e.domain,s=e.codec,i=e.marshal(),o=Eu(n,s,i),a=await t.sign(o.subarray());return new r({publicKey:t.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(e,t)=>{let n=await r.createFromProtobuf(e);if(!await n.validate(t))throw new zs("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:t,payloadType:n,payload:s,signature:i}=e;this.publicKey=t,this.payloadType=n,this.payload=s,this.signature=i}marshal(){return this.marshaled==null&&(this.marshaled=fn.encode({publicKey:Dt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return me(this.marshal(),e.marshal())}async validate(e){let t=Eu(e,this.payloadType,this.payload);return this.publicKey.verify(t.subarray(),this.signature)}},Eu=(r,e,t)=>{let n=z(r),s=ze(n.byteLength),i=ze(e.length),o=ze(t.length);return new Qe(s,n,i,e,o,t)};var $s=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,s){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,e);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=e,i+=l,i>u||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!n&&c&&o>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 s=n*2;if(n<t.length-3){let o=this.readSeparator(":",n,()=>this.readIPv4Addr());if(o!==void 0)return t[s]=o[0],t[s+1]=o[1],t[s+2]=o[2],t[s+3]=o[3],[s+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[s,!1];t[s]=i>>8,t[s+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(n+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Su=45,Lp=15,Ir=new $s;function ca(r){if(!(r.length>Lp))return Ir.new(r).parseWith(()=>Ir.readIPv4Addr())}function la(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Su))return Ir.new(r).parseWith(()=>Ir.readIPv6Addr())}function Gs(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Su)return;let t=Ir.new(r).parseWith(()=>Ir.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var $w=parseInt("0xFFFF",16),Gw=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ws(r){return!!ca(r)}function Zs(r){return!!la(r)}function js(r){return!!Gs(r)}var _u=Ws,Pp=Zs,ua=function(r){let e=0;if(r=r.toString().trim(),_u(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Pp(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=_u(t[n]),o;i&&(o=ua(t[n]),t[n]=ae(o.slice(0,2),"base16")),o!=null&&++n<8&&t.splice(n,0,ae(o.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 s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);s[e++]=i>>8&255,s[e++]=i&255}return s}throw new Error("invalid ip address")},Iu=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let i=0;i<t;i++)s.push(r[e+i]);return s.join(".")}if(t===16){let s=[];for(let i=0;i<t;i+=2)s.push(n.getUint16(e+i).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Tr={},fa={},Hp=[[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"],[481,-1,"http-path"],[777,-1,"memory"]];Hp.forEach(r=>{let e=Fp(...r);fa[e.code]=e,Tr[e.name]=e});function Fp(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function Q(r){if(typeof r=="number"){if(fa[r]!=null)return fa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Tr[r]!=null)return Tr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var kx=Q("ip4"),Cx=Q("ip6"),Nx=Q("ipcidr");function ma(r,e){switch(Q(r).code){case 4:case 41:return qp(e);case 42:return pa(e);case 43:return ae(e,"base10");case 6:case 273:case 33:case 132:return Cu(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return pa(e);case 421:return Wp(e);case 444:return ku(e);case 445:return ku(e);case 466:return Gp(e);case 481:return globalThis.encodeURIComponent(pa(e));default:return ae(e,"base16")}}function ga(r,e){switch(Q(r).code){case 4:return Tu(e);case 41:return Tu(e);case 42:return da(e);case 43:return z(e,"base10");case 6:case 273:case 33:case 132:return ya(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return da(e);case 421:return zp(e);case 444:return Zp(e);case 445:return jp(e);case 466:return $p(e);case 481:return da(globalThis.decodeURIComponent(e));default:return z(e,"base16")}}var ha=Object.values(Wr).map(r=>r.decoder),Kp=function(){let r=ha[0].or(ha[1]);return ha.slice(2).forEach(e=>r=r.or(e)),r}();function Tu(r){if(!js(r))throw new Error("invalid ip address");return ua(r)}function qp(r){let e=Iu(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!js(e))throw new Error("invalid ip address");return e}function ya(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Cu(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function da(r){let e=z(r),t=Uint8Array.from(ze(e.length));return He([t,e],t.length+e.length)}function pa(r){let e=bt(r);if(r=r.slice(Se(e)),r.length!==e)throw new Error("inconsistent lengths");return ae(r)}function zp(r){let e;r[0]==="Q"||r[0]==="1"?e=qe(J.decode(`z${r}`)).bytes:e=pe.parse(r).multihash.bytes;let t=Uint8Array.from(ze(e.length));return He([t,e],t.length+e.length)}function $p(r){let e=Kp.decode(r),t=Uint8Array.from(ze(e.length));return He([t,e],t.length+e.length)}function Gp(r){let e=bt(r),t=r.slice(Se(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ae(t,"base64url")}function Wp(r){let e=bt(r),t=r.slice(Se(e));if(t.length!==e)throw new Error("inconsistent lengths");return ae(t,"base58btc")}function Zp(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=ht.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 s=ya(n);return He([t,s],t.length+s.length)}function jp(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=ht.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 s=ya(n);return He([t,s],t.length+s.length)}function ku(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ae(e,"base32"),s=Cu(t);return`${n}:${s}`}function Nu(r){r=ba(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){let o=s[i],a=Q(o);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=s.length)throw new Ys("invalid address: "+r);if(a.path===!0){n=ba(s.slice(i).join("/")),e.push([a.code,ga(a.code,n)]),t.push([a.code,n]);break}let c=ga(a.code,s[i]);e.push([a.code,c]),t.push([a.code,ma(a.code,c)])}return{string:Ru(t),bytes:Xs(e),tuples:e,stringTuples:t,path:n}}function wa(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let i=bt(r,s),o=Se(i),a=Q(i),c=Yp(a,r.slice(s+o));if(c===0){e.push([i]),t.push([i]),s+=o;continue}let u=r.slice(s+o,s+o+c);if(s+=c+o,s>r.length)throw new Ys("Invalid address Uint8Array: "+ae(r,"base16"));e.push([i,u]);let l=ma(i,u);if(t.push([i,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Ru(t),tuples:e,stringTuples:t,path:n}}function Ru(r){let e=[];return r.map(t=>{let n=Q(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ba(e.join("/"))}function Xs(r){return He(r.map(e=>{let t=Q(e[0]),n=Uint8Array.from(ze(t.code));return e.length>1&&e[1]!=null&&(n=He([n,e[1]])),n}))}function Yp(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=bt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Se(t)}}function ba(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var Ys=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var Xp=Symbol.for("nodejs.util.inspect.custom"),va=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Jp=[Q("dns").code,Q("dns4").code,Q("dns6").code,Q("dnsaddr").code],xa=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Js=class r{bytes;#e;#t;#r;#n;[va]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=wa(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Nu(e)}else if(Uu(e))t=wa(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,i="",o=Q("tcp"),a=Q("udp"),c=Q("ip4"),u=Q("ip6"),l=Q("dns6"),f=Q("ip6zone");for(let[p,y]of this.stringTuples())p===f.code&&(i=`%${y??""}`),Jp.includes(p)&&(t=o.name==="tcp"?"tcp":"udp",s=443,n=`${y??""}${i}`,e=p===l.code?6:4),(p===o.code||p===a.code)&&(t=Q(p).name==="tcp"?"tcp":"udp",s=parseInt(y??"")),(p===c.code||p===u.code)&&(t=Q(p).name==="tcp"?"tcp":"udp",n=`${y??""}${i}`,e=p===u.code?6:4);if(e==null||t==null||n==null||s==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:s}}protos(){return this.#t.map(([e])=>Object.assign({},Q(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Q(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Xs(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===Tr.p2p.code&&e.push([n,s]),n===Tr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ae(J.decode(`z${n}`),"base58btc"):ae(pe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return me(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Lu.get(t.name);if(n==null)throw new xa(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>_e(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)}[Xp](){return`Multiaddr(${this.#e})`}};var Lu=new Map;function Uu(r){return!!r?.[va]}function _e(r){return new Js(r)}function et(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Qs=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function ei(r,e,t){if(e==null)return r;if(e.aborted){let i=Promise.reject(new Qs(t?.errorMessage,t?.errorCode,t?.errorName));return Promise.race([i,Promise.resolve().then(async()=>{try{await r}catch{}return i})])}let n,s=new Qs(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,o)=>{n=()=>{o(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Ea=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=et(),this.haveNext=et()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=et(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=et(),await ei(this.readNext.promise,t?.signal,t)}};function Du(){return new Ea}var ti=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Sa=class extends Error{code;constructor(e,t){super(e),this.code=t}},Aa=class extends Sa{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Ou(r,e){let t=Du();r.sink(t).catch(async o=>{await t.end(o)}),r.sink=async o=>{for await(let a of o)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new Qe;return{read:async(o,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new Aa("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(o==null){let{done:f,value:h}=await Promise.race([n.next(),u]);return f===!0?new Qe:h}for(;s.byteLength<o;){let{value:f,done:h}=await Promise.race([n.next(),u]);if(h===!0)throw new ti("unexpected end of input");s.append(f)}let l=s.sublist(0,o);return s.consume(o),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(o,a)=>{a?.signal?.throwIfAborted(),o instanceof Uint8Array?await t.push(o,a):await t.push(o.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let o=r.source;r.source=async function*(){e?.yieldBytes===!1?yield s:yield*s,yield*o}()}return r}}}var ri=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ni=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},si=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Mu(r,e={}){let t=Ou(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Se(e.maxDataLength));let n=e?.lengthDecoder??bt,s=e?.lengthEncoder??ze;return{read:async o=>{let a=-1,c=new Qe;for(;;){c.append(await t.read(1,o));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new ri("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new si("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ni("message length too long");return t.read(a,o)},write:async(o,a)=>{await t.write(new Qe(s(o.byteLength),o),a)},writeV:async(o,a)=>{let c=new Qe(...o.flatMap(u=>[s(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Kt(r,e){let t=Mu(r,e),n={read:async(s,i)=>{let o=await t.read(i);return s.decode(o)},write:async(s,i,o)=>{await t.write(i.encode(s),o)},writeV:async(s,i,o)=>{await t.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ba=1e3,Pu=60*Ba,ii=290,Vu=15,Hu=2*60*Pu,Fu=1,oi=2e3,Ku=100,_a="circuit-relay-source",dn=`${Pi}-circuit-relay`,Ia=`${Pi}-circuit-relay-source`,qu=2*Pu,zu=BigInt(1<<17),Ge="/libp2p/circuit/relay/0.2.0/hop",nr="/libp2p/circuit/relay/0.2.0/stop",$u=30*Ba,S1=30*Ba,pn=300,Gu=4096,Wu=.001;var j;(function(r){let e;(function(s){s.RESERVE="RESERVE",s.CONNECT="CONNECT",s.STATUS="STATUS"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.RESERVE=0]="RESERVE",s[s.CONNECT=1]="CONNECT",s[s.STATUS=2]="STATUS"})(t||(t={})),function(s){s.codec=()=>er(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Me((s,i,o={})=>{o.lengthDelimited!==!1&&i.fork(),s.type!=null&&(i.uint32(8),r.Type.codec().encode(s.type,i)),s.peer!=null&&(i.uint32(18),kr.codec().encode(s.peer,i)),s.reservation!=null&&(i.uint32(26),ai.codec().encode(s.reservation,i)),s.limit!=null&&(i.uint32(34),Cr.codec().encode(s.limit,i)),s.status!=null&&(i.uint32(40),V.codec().encode(s.status,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(s);break}case 2:{a.peer=kr.codec().decode(s,s.uint32(),{limits:o.limits?.peer});break}case 3:{a.reservation=ai.codec().decode(s,s.uint32(),{limits:o.limits?.reservation});break}case 4:{a.limit=Cr.codec().decode(s,s.uint32(),{limits:o.limits?.limit});break}case 5:{a.status=V.codec().decode(s);break}default:{s.skipType(u&7);break}}}return a})),n),r.encode=s=>Oe(s,r.codec()),r.decode=(s,i)=>De(s,r.codec(),i)})(j||(j={}));var Fe;(function(r){let e;(function(s){s.CONNECT="CONNECT",s.STATUS="STATUS"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.CONNECT=0]="CONNECT",s[s.STATUS=1]="STATUS"})(t||(t={})),function(s){s.codec=()=>er(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Me((s,i,o={})=>{o.lengthDelimited!==!1&&i.fork(),s.type!=null&&(i.uint32(8),r.Type.codec().encode(s.type,i)),s.peer!=null&&(i.uint32(18),kr.codec().encode(s.peer,i)),s.limit!=null&&(i.uint32(26),Cr.codec().encode(s.limit,i)),s.status!=null&&(i.uint32(32),V.codec().encode(s.status,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(s);break}case 2:{a.peer=kr.codec().decode(s,s.uint32(),{limits:o.limits?.peer});break}case 3:{a.limit=Cr.codec().decode(s,s.uint32(),{limits:o.limits?.limit});break}case 4:{a.status=V.codec().decode(s);break}default:{s.skipType(u&7);break}}}return a})),n),r.encode=s=>Oe(s,r.codec()),r.decode=(s,i)=>De(s,r.codec(),i)})(Fe||(Fe={}));var kr;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),t.id!=null&&t.id.byteLength>0&&(n.uint32(10),n.bytes(t.id)),t.addrs!=null)for(let i of t.addrs)n.uint32(18),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={id:oe(0),addrs:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.id=t.bytes();break}case 2:{if(s.limits?.addrs!=null&&i.addrs.length===s.limits.addrs)throw new Yr('Decode error - map field "addrs" had too many elements');i.addrs.push(t.bytes());break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(kr||(kr={}));var ai;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),t.expire!=null&&t.expire!==0n&&(n.uint32(8),n.uint64(t.expire)),t.addrs!=null)for(let i of t.addrs)n.uint32(18),n.bytes(i);t.voucher!=null&&(n.uint32(26),ci.codec().encode(t.voucher,n)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={expire:0n,addrs:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.expire=t.uint64();break}case 2:{if(s.limits?.addrs!=null&&i.addrs.length===s.limits.addrs)throw new Yr('Decode error - map field "addrs" had too many elements');i.addrs.push(t.bytes());break}case 3:{i.voucher=ci.codec().decode(t,t.uint32(),{limits:s.limits?.voucher});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(ai||(ai={}));var Cr;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.duration!=null&&(n.uint32(8),n.uint32(t.duration)),t.data!=null&&(n.uint32(16),n.uint64(t.data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.duration=t.uint32();break}case 2:{i.data=t.uint64();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(Cr||(Cr={}));var V;(function(r){r.UNUSED="UNUSED",r.OK="OK",r.RESERVATION_REFUSED="RESERVATION_REFUSED",r.RESOURCE_LIMIT_EXCEEDED="RESOURCE_LIMIT_EXCEEDED",r.PERMISSION_DENIED="PERMISSION_DENIED",r.CONNECTION_FAILED="CONNECTION_FAILED",r.NO_RESERVATION="NO_RESERVATION",r.MALFORMED_MESSAGE="MALFORMED_MESSAGE",r.UNEXPECTED_MESSAGE="UNEXPECTED_MESSAGE"})(V||(V={}));var Ta;(function(r){r[r.UNUSED=0]="UNUSED",r[r.OK=100]="OK",r[r.RESERVATION_REFUSED=200]="RESERVATION_REFUSED",r[r.RESOURCE_LIMIT_EXCEEDED=201]="RESOURCE_LIMIT_EXCEEDED",r[r.PERMISSION_DENIED=202]="PERMISSION_DENIED",r[r.CONNECTION_FAILED=203]="CONNECTION_FAILED",r[r.NO_RESERVATION=204]="NO_RESERVATION",r[r.MALFORMED_MESSAGE=400]="MALFORMED_MESSAGE",r[r.UNEXPECTED_MESSAGE=401]="UNEXPECTED_MESSAGE"})(Ta||(Ta={}));(function(r){r.codec=()=>er(Ta)})(V||(V={}));var Nr;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.relay!=null&&t.relay.byteLength>0&&(n.uint32(10),n.bytes(t.relay)),t.peer!=null&&t.peer.byteLength>0&&(n.uint32(18),n.bytes(t.peer)),t.expiration!=null&&t.expiration!==0n&&(n.uint32(24),n.uint64(t.expiration)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={relay:oe(0),peer:oe(0),expiration:0n},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.relay=t.bytes();break}case 2:{i.peer=t.bytes();break}case 3:{i.expiration=t.uint64();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(Nr||(Nr={}));var ci;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&(n.uint32(26),Nr.codec().encode(t.payload,n)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={publicKey:oe(0),payloadType:oe(0),signature:oe(0)},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.publicKey=t.bytes();break}case 2:{i.payloadType=t.bytes();break}case 3:{i.payload=Nr.codec().decode(t,t.uint32(),{limits:s.limits?.payload});break}case 5:{i.signature=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(ci||(ci={}));var Qp=r=>r.toString().split("/").slice(1),Rr=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),P=r=>({match:e=>Rr(t=>t===r).match(e),pattern:r}),sr=()=>({match:r=>Rr(e=>typeof e=="string").match(r),pattern:"{string}"}),mn=()=>({match:r=>Rr(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),X=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{J.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),gn=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Co.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),G=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Ie=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),H=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function te(...r){function e(s){let i=Qp(s);for(let o of r){let a=o.match(i);if(a===!1)return!1;i=a}return i}function t(s){return e(s)!==!1}function n(s){let i=e(s);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var ui=H(P("dns4"),sr()),fi=H(P("dns6"),sr()),hi=H(P("dnsaddr"),sr()),Ca=H(P("dns"),sr()),L1=te(ui,G(X())),U1=te(fi,G(X())),D1=te(hi,G(X())),O1=te(Ie(Ca,hi,ui,fi),G(X())),Zu=H(P("ip4"),Rr(Ws)),ju=H(P("ip6"),Rr(Zs)),Na=Ie(Zu,ju),It=Ie(Na,Ca,ui,fi,hi),M1=te(Ie(Na,H(Ie(Ca,hi,ui,fi),G(X())))),P1=te(Zu),V1=te(ju),H1=te(Na),Ra=H(It,P("tcp"),mn()),yn=H(It,P("udp"),mn()),F1=te(H(Ra,G(X()))),K1=te(yn),La=H(yn,P("quic"),G(X())),di=H(yn,P("quic-v1"),G(X())),e0=Ie(La,di),q1=te(La),z1=te(di),ka=Ie(It,Ra,yn,La,di),Yu=Ie(H(ka,P("ws"),G(X()))),$1=te(Yu),Xu=Ie(H(ka,P("wss"),G(X())),H(ka,P("tls"),G(H(P("sni"),sr())),P("ws"),G(X()))),G1=te(Xu),Ju=H(yn,P("webrtc-direct"),G(gn()),G(gn()),G(X())),W1=te(Ju),Qu=H(di,P("webtransport"),G(gn()),G(gn()),G(X())),Z1=te(Qu),li=Ie(Yu,Xu,H(Ra,G(X())),H(e0,G(X())),H(It,G(X())),Ju,Qu,X()),ef=te(li),t0=H(li,P("p2p-circuit"),X()),pi=te(t0),r0=Ie(H(li,P("p2p-circuit"),P("webrtc"),G(X())),H(li,P("webrtc"),G(X())),H(P("webrtc"),G(X()))),j1=te(r0),n0=Ie(H(It,P("tcp"),mn(),P("http"),G(X())),H(It,P("http"),G(X()))),Y1=te(n0),s0=Ie(H(It,P("tcp"),Ie(H(P("443"),P("http")),H(mn(),P("https"))),G(X())),H(It,P("tls"),P("http"),G(X())),H(It,P("https"),G(X()))),X1=te(s0),i0=Ie(H(P("memory"),sr(),G(X()))),J1=te(i0);function mi(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 s=e.signal;return s.clear=n,s}var gi=class extends Error{constructor(e="Transfer limit error"){super(e),this.name="TransferLimitError"}},bn=class extends Error{constructor(e="Duration limit error"){super(e),this.name="DurationLimitError"}},wn=class extends Error{static name="HadEnoughRelaysError";name="HadEnoughRelaysError"},yi=class extends Error{static name="DoubleRelayError";name="DoubleRelayError"},bi=class extends Error{static name="RelayQueueFullError";name="RelayQueueFullError"};async function*tf(r,e,t){let n=e.remaining;for await(let s of r){let i=BigInt(s.byteLength);if(e.remaining-i<0){let o=Number(e.remaining);e.remaining=0n;try{o!==0&&(yield s.subarray(0,o))}catch(a){t.log.error(a)}throw new gi(`data limit of ${n} bytes exceeded`)}e.remaining-=i,yield s}}function rf(r,e,t,n,s){function i(f){r.abort(f),e.abort(f)}let o=[t,n.signal];n.limit?.duration!=null&&(s.log("limiting relayed connection duration to %dms",n.limit.duration),o.push(AbortSignal.timeout(n.limit.duration)));let a=mi(o),c=!1,u=!1,l;n.limit?.data!=null&&(l={remaining:n.limit.data}),queueMicrotask(()=>{let f=()=>{s.log("relayed connection reached time limit"),e.abort(new bn(`duration limit of ${n.limit?.duration} ms exceeded`))};a.addEventListener("abort",f,{once:!0}),e.sink(l==null?r.source:tf(r.source,l,s)).catch(h=>{s.log.error("error while relaying streams src -> dst",h),i(h)}).finally(()=>{c=!0,u&&(a.removeEventListener("abort",f),a.clear())})}),queueMicrotask(()=>{let f=()=>{s.log("relayed connection reached time limit"),r.abort(new bn(`duration limit of ${n.limit?.duration} ms exceeded`))};a.addEventListener("abort",f,{once:!0}),r.sink(l==null?e.source:tf(e.source,l,s)).catch(h=>{s.log.error("error while relaying streams dst -> src",h),i(h)}).finally(()=>{u=!0,c&&(a.removeEventListener("abort",f),a.clear())})})}function Ua(r){let e=r*BigInt(1e3),t=new Date().getTime();return Number(e-BigInt(t))}var xn=class{expires;bytes;constructor(e){e?.duration!=null&&e?.duration!==0&&(this.expires=Date.now()+e.duration*1e3),this.bytes=e?.data,this.bytes===0n&&(this.bytes=void 0),this.onData=this.onData.bind(this)}onData(e){this.bytes!=null&&(this.bytes-=BigInt(e.byteLength),this.bytes<0n&&(this.bytes=0n))}getLimits(){if(this.expires==null&&this.bytes==null)return;let e={};if(this.bytes!=null){let t=this;Object.defineProperty(e,"bytes",{get(){return t.bytes}})}if(this.expires!=null){let t=this;Object.defineProperty(e,"seconds",{get(){return Math.round(((t.expires??0)-Date.now())/1e3)}})}return e}},wi=te(H(ef.matchers[0],P("p2p-circuit"))),xi=te(P("p2p-circuit"));function vi(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return t}var qt=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[t,n]of e.entries())this.map.set(t.toString(),{key:t,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return vi(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((t,n)=>{e(t.value,t.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,t){this.map.set(e.toString(),{key:e,value:t})}keys(){return vi(this.map.values(),e=>e.key)}values(){return vi(this.map.values(),e=>e.value)}get size(){return this.map.size}};var Da={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},nf={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},sf=new globalThis.TextEncoder;function o0(r,e){let t=Da[e],n=nf[e];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(e,n*t);return n}function a0(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Da[e],s=nf[e],i=r;for(;i.length>0;){let o=sf.encodeInto(i,t);i=i.slice(o.read);for(let a=0;a<o.written;a++)s^=BigInt(t[a]),s=BigInt.asUintN(e,s*n)}return s}function Oa(r,{size:e=32,utf8Buffer:t}={}){if(!Da[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return a0(r,e,t);r=sf.encode(r)}return o0(r,e)}var vn={hash:r=>Number(Oa(r,{size:32})),hashV:(r,e)=>c0(vn.hash(r,e))};function c0(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),z(e,"base16")}var Ma=64,tt=class{fp;h;seed;constructor(e,t,n,s=2){if(s>Ma)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),o=oe(s);for(let a=0;a<o.length;a++)o[a]=i[a];o.length===0&&(o[0]=7),this.fp=o,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?me(this.fp,e.fp):!1}};function ir(r,e){return Math.floor(Math.random()*(e-r))+r}var or=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");let t=ir(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var l0=500,En=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??vn,this.seed=e.seed??ir(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=z(e));let t=new tt(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new or(this.bucketSize)),this.buckets[s]==null&&(this.buckets[s]=new or(this.bucketSize)),this.buckets[n].add(t)||this.buckets[s].add(t))return this.count++,!0;let i=[n,s],o=i[ir(0,i.length-1)];this.buckets[o]==null&&(this.buckets[o]=new or(this.bucketSize));for(let a=0;a<l0;a++){let c=this.buckets[o].swap(t);if(c!=null&&(o=(o^c.hash())%this.filterSize,this.buckets[o]==null&&(this.buckets[o]=new or(this.bucketSize)),this.buckets[o].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=z(e));let t=new tt(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.has(t)??!1;if(s)return s;let i=(n^t.hash())%this.filterSize;return this.buckets[i]?.has(t)??!1}remove(e){typeof e=="string"&&(e=z(e));let t=new tt(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.remove(t)??!1;if(s)return this.count--,s;let i=(n^t.hash())%this.filterSize,o=this.buckets[i]?.remove(t)??!1;return o&&this.count--,o}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},u0={1:.5,2:.84,4:.95,8:.98};function f0(r=.001){return r>.002?2:r>1e-5?4:8}function of(r,e=.001){let t=f0(e),n=u0[t],s=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Ma);return{filterSize:s,bucketSize:t,fingerprintSize:i}}var Ei=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??vn,this.seed=e.seed??ir(0,Math.pow(2,10)),this.filterSeries=[new En({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=z(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new En({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=z(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=z(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function Lr(r,e=.001,t){return new Ei({...of(r,e),...t??{}})}var Si=class{filter;constructor(e,t){this.filter=Lr(e,t)}has(e){return this.filter.has(e.toMultihash().bytes)}add(e){this.filter.add(e.toMultihash().bytes)}remove(e){this.filter.remove?.(e.toMultihash().bytes)}};function Pa(r,e=.001){return new Si(r,e)}var Va=class extends qt{metric;constructor(e){super();let{name:t,metrics:n}=e;this.metric=n.registerMetric(t),this.updateComponentMetric()}set(e,t){return super.set(e,t),this.updateComponentMetric(),this}delete(e){let t=super.delete(e);return this.updateComponentMetric(),t}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Ha(r){let{name:e,metrics:t}=r,n;return t!=null?n=new Va({name:e,metrics:t}):n=new qt,n}var Fa=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};function af(r,e){let t=new Fa(e?.errorMessage,e?.errorCode,e?.errorName),n=new AbortController,s=()=>{n.abort(t)},i=AbortSignal.timeout(r);i.addEventListener("abort",s);let o=n.signal;return o.reset=a=>{i?.removeEventListener("abort",s),i=AbortSignal.timeout(a??r),i.addEventListener("abort",()=>{n.abort(t)})},o.clear=()=>{i?.removeEventListener("abort",s),i=void 0},o}var Ai=class{reservations;maxReservations;applyDefaultLimit;reservationTtl;defaultDurationLimit;defaultDataLimit;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:circuit-relay:server:reservation-store"),this.maxReservations=t.maxReservations??Vu,this.applyDefaultLimit=t.applyDefaultLimit!==!1,this.reservationTtl=t.reservationTtl??Hu,this.defaultDurationLimit=t.defaultDurationLimit??qu,this.defaultDataLimit=t.defaultDataLimit??zu,this.reservations=Ha({metrics:e.metrics,name:"libp2p_circuit_relay_server_reservations_total"})}reserve(e,t,n){let s=this.reservations.get(e);if(this.reservations.size>=this.maxReservations&&s==null)return{status:V.RESERVATION_REFUSED};let i=new Date(Date.now()+this.reservationTtl),o;return this.applyDefaultLimit&&(o=n??{data:this.defaultDataLimit,duration:this.defaultDurationLimit}),s!=null?(this.log("refreshing reservation for client %p",e),s.signal.reset(this.reservationTtl)):(this.log("creating new reservation for client %p",e),s={addr:t,expiry:i,limit:o,signal:af(this.reservationTtl)}),this.reservations.set(e,s),s.signal.addEventListener("abort",()=>{this.reservations.delete(e)}),{status:V.OK,expire:Math.round(i.getTime()/1e3)}}removeReservation(e){this.reservations.delete(e)}get(e){return this.reservations.get(e)}clear(){this.reservations.clear()}};var Bi=class r{domain="libp2p-relay-rsvp";codec=new Uint8Array([3,2]);relay;peer;expiration;constructor({relay:e,peer:t,expiration:n}){this.relay=e,this.peer=t,this.expiration=n}marshal(){return Nr.encode({relay:this.relay.toMultihash().bytes,peer:this.peer.toMultihash().bytes,expiration:BigInt(this.expiration)})}equals(e){return!(!(e instanceof r)||!this.peer.equals(e.peer)||!this.relay.equals(e.relay)||this.expiration!==e.expiration)}};var cf=r=>r.protoCodes().includes(ii),h0={maxOutboundStopStreams:pn},Ka=class extends Ke{registrar;peerStore;addressManager;peerId;privateKey;connectionManager;connectionGater;reservationStore;started;hopTimeout;shutdownController;maxInboundHopStreams;maxOutboundHopStreams;maxOutboundStopStreams;log;constructor(e,t={}){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:server"),this.registrar=e.registrar,this.peerStore=e.peerStore,this.addressManager=e.addressManager,this.peerId=e.peerId,this.privateKey=e.privateKey,this.connectionManager=e.connectionManager,this.connectionGater=e.connectionGater,this.started=!1,this.hopTimeout=t?.hopTimeout??$u,this.maxInboundHopStreams=t.maxInboundHopStreams,this.maxOutboundHopStreams=t.maxOutboundHopStreams,this.maxOutboundStopStreams=t.maxOutboundStopStreams??h0.maxOutboundStopStreams,this.reservationStore=new Ai(e,t.reservations),this.shutdownController=new AbortController,this.shutdownController.signal}[Symbol.toStringTag]="@libp2p/circuit-relay-v2-server";isStarted(){return this.started}async start(){this.started||(await this.registrar.handle(Ge,e=>{this.onHop(e).catch(t=>{this.log.error(t)})},{maxInboundStreams:this.maxInboundHopStreams,maxOutboundStreams:this.maxOutboundHopStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){this.reservationStore.clear(),this.shutdownController.abort(),await this.registrar.unhandle(Ge),this.started=!1}async onHop({connection:e,stream:t}){this.log("received circuit v2 hop protocol stream from %p",e.remotePeer);let n={signal:AbortSignal.timeout(this.hopTimeout)},s=Kt(t);try{let i=await s.pb(j).read(n);if(i?.type==null)throw new Error("request was invalid, could not read from stream");this.log("received",i.type),await this.handleHopProtocol({connection:e,stream:s,request:i},n)}catch(i){this.log.error("error while handling hop",i),await s.pb(j).write({type:j.Type.STATUS,status:V.MALFORMED_MESSAGE},n),t.abort(i)}}async handleHopProtocol({stream:e,request:t,connection:n},s){switch(this.log("received hop message"),t.type){case j.Type.RESERVE:await this.handleReserve({stream:e,request:t,connection:n},s);break;case j.Type.CONNECT:await this.handleConnect({stream:e,request:t,connection:n},s);break;default:this.log.error("invalid hop request type %s via peer %p",t.type,n.remotePeer),await e.pb(j).write({type:j.Type.STATUS,status:V.UNEXPECTED_MESSAGE})}}async handleReserve({stream:e,connection:t},n){let s=e.pb(j);if(this.log("hop reserve request from %p",t.remotePeer),cf(t.remoteAddr)){this.log.error("relay reservation over circuit connection denied for peer: %p",t.remotePeer),await s.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},n);return}if(await this.connectionGater.denyInboundRelayReservation?.(t.remotePeer)===!0){this.log.error("reservation for %p denied by connection gater",t.remotePeer),await s.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},n);return}let i=this.reservationStore.reserve(t.remotePeer,t.remoteAddr);try{if(i.status!==V.OK){await s.write({type:j.Type.STATUS,status:i.status},n);return}if(i.expire!=null){let o=i.expire*1e3-Date.now();await this.peerStore.merge(t.remotePeer,{tags:{[_a]:{value:1,ttl:o},[Ia]:{value:1,ttl:o}}})}await s.write({type:j.Type.STATUS,status:V.OK,reservation:await this.makeReservation(t.remotePeer,BigInt(i.expire??0)),limit:this.reservationStore.get(t.remotePeer)?.limit},n),this.log("sent confirmation response to %s",t.remotePeer)}catch(o){this.log.error("failed to send confirmation response to %p - %e",t.remotePeer,o),this.reservationStore.removeReservation(t.remotePeer);try{await this.peerStore.merge(t.remotePeer,{tags:{[_a]:void 0,[Ia]:void 0}})}catch(a){this.log.error("failed to untag relay source peer %p - %e",t.remotePeer,a)}}}async makeReservation(e,t){let n=[];for(let i of this.addressManager.getAddresses())i.toString().includes("/p2p-circuit")||n.push(i.bytes);let s=await hn.seal(new Bi({peer:e,relay:this.peerId,expiration:t}),this.privateKey);return{addrs:n,expire:t,voucher:{publicKey:Dt(s.publicKey),payloadType:s.payloadType,payload:{peer:e.toMultihash().bytes,relay:this.peerId.toMultihash().bytes,expiration:t},signature:s.signature}}}async handleConnect({stream:e,request:t,connection:n},s){let i=e.pb(j);if(cf(n.remoteAddr)){this.log.error("relay reservation over circuit connection denied for peer: %p",n.remotePeer),await i.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},s);return}this.log("hop connect request from %p",n.remotePeer);let o;try{if(t.peer==null)throw this.log.error("no peer info in hop connect request"),new Error("no peer info in request");t.peer.addrs.forEach(_e),o=un(qe(t.peer.id))}catch(h){this.log.error("invalid hop connect request via peer %p %s",n.remotePeer,h),await i.write({type:j.Type.STATUS,status:V.MALFORMED_MESSAGE},s);return}let a=this.reservationStore.get(o);if(a==null){this.log.error("hop connect denied for destination peer %p not having a reservation for %p with status %s",o,n.remotePeer,V.NO_RESERVATION),await i.write({type:j.Type.STATUS,status:V.NO_RESERVATION},s);return}if(await this.connectionGater.denyOutboundRelayedConnection?.(n.remotePeer,o)===!0){this.log.error("hop connect for %p to %p denied by connection gater",n.remotePeer,o),await i.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},s);return}let c=this.connectionManager.getConnections(o);if(c.length===0){this.log("hop connect denied for destination peer %p not having a connection for %p as there is no destination connection",o,n.remotePeer),await i.write({type:j.Type.STATUS,status:V.NO_RESERVATION},s);return}let u=c[0],l=await this.stopHop({connection:u,request:{type:Fe.Type.CONNECT,peer:{id:n.remotePeer.toMultihash().bytes,addrs:[]},limit:a?.limit}},s);if(l==null){this.log.error("failed to open stream to destination peer %p",u?.remotePeer),await i.write({type:j.Type.STATUS,status:V.CONNECTION_FAILED},s);return}await i.write({type:j.Type.STATUS,status:V.OK,limit:a?.limit},s);let f=e.unwrap();this.log("connection from %p to %p established - merging streams",n.remotePeer,o),rf(f,l,this.shutdownController.signal,a,{log:this.log})}async stopHop({connection:e,request:t},n){this.log("starting circuit relay v2 stop request to %s",e.remotePeer);let s=await e.newStream([nr],{maxOutboundStreams:this.maxOutboundStopStreams,runOnLimitedConnection:!0,...n}),i=Kt(s),o=i.pb(Fe);await o.write(t,n);let a;try{a=await o.read(n)}catch{this.log.error("error parsing stop message response from %p",e.remotePeer)}if(a==null){this.log.error("could not read response from %p",e.remotePeer),await s.close(n);return}if(a.status===V.OK)return this.log("stop request to %p was successful",e.remotePeer),i.unwrap();this.log("stop request failed with code %d",a.status),await s.close(n)}get reservations(){return this.reservationStore.reservations}};function lf(r={}){return e=>new Ka(e,r)}function d0(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var uf=d0;function p0(r){return r[Symbol.asyncIterator]!=null}function ff(r){return r?.then!=null}function m0(r,e){let t=0;if(p0(r))return async function*(){for await(let c of r){let u=e(c,t++);ff(u)&&await u,yield c}}();let n=uf(r),{value:s,done:i}=n.next();if(i===!0)return function*(){}();if(typeof e(s,t++)?.then=="function")return async function*(){yield s;for await(let c of n){let u=e(c,t++);ff(u)&&await u,yield c}}();let a=e;return function*(){yield s;for(let c of n)a(c,t++),yield c}()}var hf=m0;var Ii=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ur=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ii(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Ii(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var qa=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Dr(r={}){return g0(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function g0(r,e){e=e??{};let t=e.onEnd,n=new Ur,s,i,o,a=et(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((d,x)=>{i=E=>{i=null,n.push(E);try{d(r(n))}catch(g){x(g)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=et()})}},u=d=>i!=null?i(d):(n.push(d),s),l=d=>(n=new Ur,i!=null?i({error:d}):(n.push({error:d}),s)),f=d=>{if(o)return s;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},h=d=>o?s:(o=!0,d!=null?l(d):u({done:!0})),p=()=>(n=new Ur,h(),{done:!0}),y=d=>(h(d),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:y,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let x=d?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,g;x!=null&&(E=new Promise((_,N)=>{g=()=>{N(new qa)},x.addEventListener("abort",g)}));try{await Promise.race([a.promise,E])}finally{g!=null&&x!=null&&x?.removeEventListener("abort",g)}}},t==null)return s;let b=s;return s={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(d){return b.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return b.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return b.end(d),t!=null&&(t(d),t=void 0),s},get readableLength(){return b.readableLength},onEmpty:d=>b.onEmpty(d)},s}function y0(r){return r[Symbol.asyncIterator]!=null}function b0(...r){let e=[];for(let t of r)y0(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Dr({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)t.push(s)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var df=b0;function pf(r,...e){if(r==null)throw new Error("Empty pipeline");if(za(r)){let n=r;r=()=>n.source}else if(gf(r)||mf(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&za(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)za(t[n])&&(t[n]=x0(t[n]));return w0(...t)}var w0=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},mf=r=>r?.[Symbol.asyncIterator]!=null,gf=r=>r?.[Symbol.iterator]!=null,za=r=>r==null?!1:r.sink!=null&&r.source!=null,x0=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Dr({objectMode:!0});t.then(()=>{n.end()},o=>{n.end(o)});let s,i=r.source;if(mf(i))s=async function*(){yield*i,n.end()};else if(gf(i))s=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return df(n,s())}return r.source};function $a(r){let{stream:e,remoteAddr:t,logger:n,onDataRead:s,onDataWrite:i}=r,o=n.forComponent("libp2p:stream:converter"),a=!1,c=!1,u=e.close.bind(e);e.close=async y=>{await u(y),p(!0)};let l=e.abort.bind(e);e.abort=y=>{l(y),p(!0)};let f=e.sink.bind(e);e.sink=async y=>{try{await f(pf(y,b=>hf(b,d=>i?.(d))))}catch(b){b.type!=="aborted"&&o.error("%s error in sink",t,b)}finally{c=!0,p()}};let h={log:o,sink:e.sink,source:async function*(){try{for await(let y of e.source)s?.(y),yield y}finally{a=!0,p()}}(),remoteAddr:t,timeline:{open:Date.now(),close:void 0},close:e.close,abort:e.abort};function p(y){y===!0&&(a=!0,c=!0),a&&c&&h.timeline.close==null&&(h.timeline.close=Date.now())}return h}var zt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Ga=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Ti(r,e,t,n){let s=new Ga(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(s):new Promise((i,o)=>{function a(){t?.removeEventListener("abort",l),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),o(h);return}a(),i(f)},u=f=>{a(),o(f.detail)},l=()=>{a(),o(s)};t?.addEventListener("abort",l),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var ki=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Ci=class{deferred;signal;constructor(e){this.signal=e,this.deferred=et(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new ut)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function v0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ni=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=v0(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new ut),this.cleanup())}async join(e={}){let t=new Ci(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await ei(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Ri=class extends Ke{concurrency;maxSize;queue;pending;sort;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new ki;let n=new Ni(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("error",{detail:s}),this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new ut)}),this.clear()}async onEmpty(e){this.size!==0&&await Ti(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Ti(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ti(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Dr({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},s=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail)},o=()=>{n()},a=()=>{n(new ut("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("error",i),this.addEventListener("idle",o),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",s),this.removeEventListener("error",i),this.removeEventListener("idle",o),e?.signal?.removeEventListener("abort",a),n()}}};var Or=class extends Ri{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};var Li=class extends Ke{peerStore;registrar;connectionManager;randomWalk;started;running;topologyId;log;discoveryController;filter;queue;constructor(e,t={}){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:discover-relays"),this.started=!1,this.running=!1,this.peerStore=e.peerStore,this.registrar=e.registrar,this.connectionManager=e.connectionManager,this.randomWalk=e.randomWalk,this.filter=t.filter,this.discoveryController=new AbortController,this.discoveryController.signal}isStarted(){return this.started}async start(){this.topologyId=await this.registrar.register(Ge,{filter:this.filter,onConnect:e=>{this.log.trace("discovered relay %p queue (length: %d, active %d)",e,this.queue?.size,this.queue?.running),this.safeDispatchEvent("relay:discover",{detail:e})}}),this.started=!0}stop(){this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.discoveryController?.abort(),this.started=!1}startDiscovery(){this.running||(this.log("start discovery"),this.running=!0,this.discoveryController=new AbortController,this.discoveryController.signal,Promise.resolve().then(async()=>{this.log("searching peer store for relays");let e=await this.peerStore.all({filters:[n=>n.protocols.includes(Ge)],orders:[()=>Math.random()<.5?1:-1,(n,s)=>{let i=yf(n),o=yf(s);return i>o?-1:o>i?1:0}]});for(let n of e)this.log.trace("found relay peer %p in peer store",n.id),this.safeDispatchEvent("relay:discover",{detail:n.id});this.log("found %d relay peers in peer store",e.length);let t=this.queue=new Or({concurrency:5});this.log("start random walk");for await(let n of this.randomWalk.walk({signal:this.discoveryController.signal})){if(this.log.trace("found random peer %p",n.id),t.has(n.id)){this.log.trace("random peer %p was already in queue",n.id);continue}if(this.connectionManager.getConnections(n.id)?.length>0){this.log.trace("random peer %p was already connected",n.id);continue}if(!await this.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable",n.id,n.multiaddrs.map(s=>s.toString()));continue}t.queued>10&&(this.log.trace("wait for space in queue for %p",n.id),await t.onSizeLessThan(10,{signal:this.discoveryController.signal})),this.log("adding random peer %p to dial queue (length: %d, active %d)",n.id,t.size,t.running),t.add(async()=>{let s=mi([this.discoveryController.signal,AbortSignal.timeout(5e3)]);try{await this.connectionManager.openConnection(n.id,{signal:s})}finally{s.clear()}},{peerId:n.id,signal:this.discoveryController.signal}).catch(s=>{this.log.error("error opening connection to random peer %p",n.id,s)})}this.log("stop random walk"),await t.onIdle()}).catch(e=>{this.discoveryController.signal.aborted||this.log.error("failed when finding relays on the network",e)}))}stopDiscovery(){this.log("stop discovery"),this.running=!1,this.discoveryController?.abort()}};function yf(r){let e=r.metadata.get("last-dial-success");return e==null?0:new Date(ae(e)).getTime()}var Wa=class extends Ke{peerId;connectionManager;addressManager;reservationStore;listeningAddrs;log;listenTimeout;reservationId;relay;constructor(e,t={}){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:transport:listener"),this.peerId=e.peerId,this.connectionManager=e.connectionManager,this.addressManager=e.addressManager,this.reservationStore=e.reservationStore,this.listeningAddrs=[],this.listenTimeout=t.listenTimeout??oi,this.reservationStore.addEventListener("relay:removed",this._onRemoveRelayPeer),this.reservationStore.addEventListener("relay:created-reservation",this._onAddRelayPeer)}_onRemoveRelayPeer=e=>{this.log("relay removed %p our relay %p",e.detail.relay,this.relay,this.relay?.equals(e.detail.relay)),this.relay?.equals(e.detail.relay)===!0&&(this.log("relay peer removed %p",e.detail.relay),this.listeningAddrs.forEach(t=>{this.addressManager.removeObservedAddr(t)}),this.listeningAddrs=[],this.safeDispatchEvent("listening"))};_onAddRelayPeer=e=>{let{details:t}=e.detail;t.type!=="configured"&&t.id===this.reservationId&&this.addedRelay(e.detail)};async listen(e){if(this.log("listen on %a",e),xi.exactMatch(e))this.reservationId=this.reservationStore.reserveRelay();else if(wi.exactMatch(e)){let t=AbortSignal.timeout(this.listenTimeout);let n=e.decapsulate("/p2p-circuit"),s=await this.connectionManager.openConnection(n,{signal:t});if(!this.reservationStore.hasReservation(s.remotePeer)){this.log("making reservation on peer %p",s.remotePeer);let i=await this.reservationStore.addRelay(s.remotePeer,"configured");this.addedRelay(i)}}else throw new $t(`Could not listen on p2p-circuit address "${e}"`)}getAddrs(){return[...this.listeningAddrs.values()].flat()}updateAnnounceAddrs(){}async close(){this.reservationStore.cancelReservations(),this.listeningAddrs=[],this.reservationStore.removeEventListener("relay:removed",this._onRemoveRelayPeer),queueMicrotask(()=>{this.safeDispatchEvent("close")})}addedRelay(e){this.log("relay peer added %p",e.relay),this.relay=e.relay,this.listeningAddrs=e.details.reservation.addrs.map(t=>_e(t).encapsulate("/p2p-circuit")),this.listeningAddrs.forEach(t=>{this.addressManager.confirmObservedAddr(t,{type:"transport"})}),queueMicrotask(()=>{this.safeDispatchEvent("listening")})}};function bf(r){return new Wa(r)}var wf="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var xf=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)e+=wf[t[r]&63];return e};var E0=60*1e3*10,S0=60*1e3*5,A0=30*1e3,Ui=class extends Ke{peerId;connectionManager;peerStore;events;reserveQueue;reservations;pendingReservations;maxReservationQueueLength;reservationCompletionTimeout;started;log;relayFilter;constructor(e,t){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:transport:reservation-store"),this.peerId=e.peerId,this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.events=e.events,this.reservations=new qt,this.pendingReservations=[],this.maxReservationQueueLength=t?.maxReservationQueueLength??Ku,this.reservationCompletionTimeout=t?.reservationCompletionTimeout??oi,this.started=!1,this.relayFilter=Lr(100),this.reserveQueue=new Or({concurrency:t?.reservationConcurrency??Fu,metricName:"libp2p_relay_reservation_queue",metrics:e.metrics}),this.events.addEventListener("connection:close",n=>{[...this.reservations.values()].find(i=>i.connection===n.detail.id)!=null&&this.#t(n.detail.remotePeer).catch(i=>{this.log("could not remove relay %p - %e",n.detail,i)})})}isStarted(){return this.started}start(){this.started=!0}afterStart(){Promise.resolve().then(async()=>{let e=await this.peerStore.all({filters:[t=>t.tags.has(dn)]});this.log("removing tag from %d old relays",e.length),await Promise.all(e.map(async t=>{await this.peerStore.merge(t.id,{tags:{[dn]:void 0}})})),this.log("redialing %d old relays",e.length),await Promise.all(e.map(async t=>this.addRelay(t.id,"discovered"))),this.#r()}).catch(e=>{this.log.error(e)})}stop(){this.reserveQueue.clear(),this.reservations.forEach(({timeout:e})=>{clearTimeout(e)}),this.reservations.clear(),this.started=!1}reserveRelay(){let e=xf();return this.pendingReservations.push(e),this.#r(),e}async addRelay(e,t){if(this.peerId.equals(e))throw this.log.trace("not trying to use self as relay"),new $t("Cannot use self as relay");if(this.reserveQueue.size>this.maxReservationQueueLength)throw new bi("The reservation queue is full");let n=this.reserveQueue.find(e);if(n!=null)return this.log.trace("potential relay peer %p is already in the reservation queue",e),n.join();if(this.relayFilter.has(e.toMultihash().bytes))throw new $t("The relay was previously invalid");return this.log.trace("try to reserve relay slot with %p",e),this.reserveQueue.add(async()=>{let s=Date.now();try{let i=this.reservations.get(e);if(i!=null){let y=this.connectionManager.getConnections(e),b=!1;if(y.length===0&&this.log("already have relay reservation with %p but we are no longer connected",e),y.map(d=>d.id).includes(i.connection)&&(this.log("already have relay reservation with %p and the original connection is still open",e),b=!0),b&&Ua(i.reservation.expire)>E0)return this.log("already have relay reservation with %p but we are still connected and it does not expire soon",e),{relay:e,details:i};await this.#t(e)}if(t==="discovered"&&this.pendingReservations.length===0)throw new wn("Not making reservation on discovered relay because we do not need any more relays");let o=AbortSignal.timeout(this.reservationCompletionTimeout);let a=await this.connectionManager.openConnection(e,{signal:o});if(pi.matches(a.remoteAddr))throw new yi("not creating reservation over relayed connection");let c=await this.#e(a,{signal:o}),u=Ua(c.expire);this.log("created reservation on relay peer %p, expiry date is %s",e,new Date(Date.now()+u).toString());let l=Math.min(Math.max(u-S0,A0),Math.pow(2,31)-1),f=setTimeout(()=>{this.log("refresh reservation to relay %p",e),this.addRelay(e,t).catch(async y=>{this.log.error("could not refresh reservation to relay %p - %e",e,y),await this.#t(e)}).catch(y=>{this.log.error("could not remove expired reservation to relay %p - %e",e,y)})},l),h;if(t==="discovered"){let y=this.pendingReservations.pop();if(y==null)throw new wn("Made reservation on relay but did not need any more discovered relays");h={timeout:f,reservation:c,type:t,connection:a.id,id:y}}else h={timeout:f,reservation:c,type:t,connection:a.id};this.reservations.set(e,h),await this.peerStore.merge(e,{tags:{[dn]:{value:1,ttl:u}}}),this.#r();let p={relay:e,details:h};return this.safeDispatchEvent("relay:created-reservation",{detail:p}),p}catch(i){throw t==="discovered"&&i.name==="HadEnoughRelaysError"||this.log.error("could not reserve slot on %p after %dms - %e",e,Date.now()-s,i),(i.name==="DialError"||i.name==="UnsupportedProtocolError")&&this.relayFilter.add(e.toMultihash().bytes),this.#t(e).catch(o=>{this.log.error("could not remove reservation on %p after reserving slot failed - %e",e,o)}),i}},{peerId:e})}hasReservation(e){return this.reservations.has(e)}getReservation(e){return this.reservations.get(e)?.reservation}reservationCount(e){return e==null?this.reservations.size:[...this.reservations.values()].reduce((t,n)=>(n.type===e&&t++,t),0)}cancelReservations(){[...this.reservations.values()].forEach(e=>{clearTimeout(e.timeout)}),this.reservations.clear()}async#e(e,t){t.signal?.throwIfAborted(),this.log("requesting reservation from %p",e.remotePeer);let n=await e.newStream(Ge,t),i=Kt(n).pb(j);this.log.trace("send RESERVE to %p",e.remotePeer),await i.write({type:j.Type.RESERVE},t);let o;try{this.log.trace("reading response from %p",e.remotePeer),o=await i.read(t)}catch(c){throw n.abort(c),c}finally{n.status!=="closed"&&await n.close(t)}if(this.log.trace("read response %o",o),o.status===V.OK&&o.reservation!=null){let c=new Set;c.add(e.remoteAddr.toString());for(let u of o.reservation.addrs){let l=_e(u);l.getPeerId()==null&&(l=l.encapsulate(`/p2p/${e.remotePeer}`)),l=_e(l.toString().replace(`/p2p/${e.remotePeer}/p2p/${e.remotePeer}`,`/p2p/${e.remotePeer}`)),c.add(l.toString())}return o.reservation.addrs=[...c].map(u=>_e(u).bytes),o.reservation}let a=`reservation failed with status ${o.status??"undefined"}`;throw this.log.error(a),new Error(a)}async#t(e){let t=this.reservations.get(e);t!=null&&(this.log("removing relay reservation with %p from local store",e),clearTimeout(t.timeout),this.reservations.delete(e),t.type==="discovered"&&this.pendingReservations.push(t.id),await this.peerStore.merge(e,{tags:{[dn]:void 0}}),this.safeDispatchEvent("relay:removed",{detail:{relay:e,details:t}}),this.#r())}#r(){if(this.pendingReservations.length===0){this.log.trace("have discovered enough relays"),this.reserveQueue.clear(),this.safeDispatchEvent("relay:found-enough-relays");return}this.relayFilter=Lr(100),this.log("not discovered enough relays %d/%d",this.reservations.size,this.pendingReservations.length),this.safeDispatchEvent("relay:not-enough-relays")}};var B0=r=>{if(r.peer==null)return!1;try{r.peer.addrs.forEach(_e)}catch{return!1}return!0},Za={maxInboundStopStreams:pn,maxOutboundStopStreams:pn,stopTimeout:3e4},Di=class{discovery;registrar;peerStore;connectionManager;transportManager;peerId;upgrader;addressManager;connectionGater;reservationStore;logger;maxInboundStopStreams;maxOutboundStopStreams;stopTimeout;started;log;constructor(e,t){this.log=e.logger.forComponent("libp2p:circuit-relay:transport"),this.registrar=e.registrar,this.peerStore=e.peerStore,this.connectionManager=e.connectionManager,this.transportManager=e.transportManager,this.logger=e.logger,this.peerId=e.peerId,this.upgrader=e.upgrader,this.addressManager=e.addressManager,this.connectionGater=e.connectionGater,this.maxInboundStopStreams=t.maxInboundStopStreams??Za.maxInboundStopStreams,this.maxOutboundStopStreams=t.maxOutboundStopStreams??Za.maxOutboundStopStreams,this.stopTimeout=t.stopTimeout??Za.stopTimeout,this.discovery=new Li(e,{filter:t.discoveryFilter??Pa(Gu,Wu)}),this.discovery.addEventListener("relay:discover",n=>{this.reservationStore.addRelay(n.detail,"discovered").catch(s=>{s.name!=="HadEnoughRelaysError"&&s.name!=="RelayQueueFullError"&&this.log.error("could not add discovered relay %p",n.detail,s)})}),this.reservationStore=new Ui(e,t),this.reservationStore.addEventListener("relay:not-enough-relays",()=>{this.discovery?.startDiscovery()}),this.reservationStore.addEventListener("relay:found-enough-relays",()=>{this.discovery?.stopDiscovery()}),this.started=!1}[Symbol.toStringTag]="@libp2p/circuit-relay-v2-transport";[cc]=["@libp2p/transport","@libp2p/circuit-relay-v2-transport"];get[lc](){return this.discovery!=null?["@libp2p/identify"]:[]}[sc]=!0;isStarted(){return this.started}async start(){await this.registrar.handle(nr,e=>{this.onStop(e).catch(t=>{this.log.error("error while handling STOP protocol",t),e.stream.abort(t)})},{maxInboundStreams:this.maxInboundStopStreams,maxOutboundStreams:this.maxOutboundStopStreams,runOnLimitedConnection:!0}),await oc(this.discovery,this.reservationStore),this.started=!0}async stop(){await ac(this.discovery,this.reservationStore),await this.registrar.unhandle(nr),this.started=!1}async dial(e,t){if(e.protoCodes().filter(p=>p===ii).length!==1){let p="Invalid circuit relay address";throw this.log.error(p,e),new Pr(p)}let n=e.toString().split("/p2p-circuit"),s=_e(n[0]),i=_e(n[n.length-1]),o=s.getPeerId(),a=i.getPeerId();if(o==null||a==null){let p=`ircuit relay dial to ${e.toString()} failed as address did not have both relay and destination PeerIDs`;throw this.log.error(`c${p}`),new Pr(`C${p}`)}let c=aa(o),u=aa(a),f=this.connectionManager.getConnections(c)[0];f==null?(await this.peerStore.merge(c,{multiaddrs:[s]}),t.onProgress?.(new zt("circuit-relay:open-connection")),f=await this.connectionManager.openConnection(c,t)):t.onProgress?.(new zt("circuit-relay:reuse-connection"));let h;try{t.onProgress?.(new zt("circuit-relay:open-hop-stream")),h=await f.newStream(Ge,t);let p=Kt(h),y=p.pb(j);t.onProgress?.(new zt("circuit-relay:write-connect-message")),await y.write({type:j.Type.CONNECT,peer:{id:u.toMultihash().bytes,addrs:[_e(i).bytes]}},t),t.onProgress?.(new zt("circuit-relay:read-connect-response"));let b=await y.read(t);if(b.status!==V.OK)throw new Bn(`failed to connect via relay with status ${b?.status?.toString()??"undefined"}`);let d=new xn(b.limit),x=$a({stream:p.unwrap(),remoteAddr:e,localAddr:s.encapsulate(`/p2p-circuit/p2p/${this.peerId.toString()}`),logger:this.logger,onDataRead:d.onData,onDataWrite:d.onData});return this.log("new outbound relayed connection %a",x.remoteAddr),await this.upgrader.upgradeOutbound(x,{...t,limits:d.getLimits()})}catch(p){throw this.log.error("circuit relay dial to destination %p via relay %p failed",u,c,p),h?.abort(p),p}}createListener(e){return bf({peerId:this.peerId,connectionManager:this.connectionManager,addressManager:this.addressManager,reservationStore:this.reservationStore,logger:this.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>wi.exactMatch(t)||xi.exactMatch(t))}dialFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>pi.exactMatch(t))}async onStop({connection:e,stream:t}){if(!this.reservationStore.hasReservation(e.remotePeer))try{this.log("dialed via relay we did not have a reservation on, start listening on that relay address"),await this.transportManager.listen([e.remoteAddr.encapsulate("/p2p-circuit")])}catch(f){this.log.error("failed to listen on a relay peer we were dialed via but did not have a reservation on",f)}let n=AbortSignal.timeout(this.stopTimeout),s=Kt(t).pb(Fe),i=await s.read({signal:n});if(this.log("new circuit relay v2 stop stream from %p with type %s",e.remotePeer,i.type),i?.type===void 0){this.log.error("type was missing from circuit v2 stop protocol request from %s",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.MALFORMED_MESSAGE},{signal:n}),await t.close();return}if(i.type!==Fe.Type.CONNECT){this.log.error("invalid stop connect request via peer %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.UNEXPECTED_MESSAGE},{signal:n}),await t.close();return}if(!B0(i)){this.log.error("invalid stop connect request via peer %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.MALFORMED_MESSAGE},{signal:n}),await t.close();return}let o=un(qe(i.peer.id));if(await this.connectionGater.denyInboundRelayedConnection?.(e.remotePeer,o)===!0){this.log.error("connection gater denied inbound relayed connection from %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.PERMISSION_DENIED},{signal:n}),await t.close();return}this.log.trace("sending success response to %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.OK},{signal:n});let a=new xn(i.limit),c=e.remoteAddr.encapsulate(`/p2p-circuit/p2p/${o.toString()}`),u=this.addressManager.getAddresses()[0],l=$a({stream:s.unwrap().unwrap(),remoteAddr:c,localAddr:u,logger:this.logger,onDataRead:a.onData,onDataWrite:a.onData});this.log("new inbound relayed connection %a",l.remoteAddr),await this.upgrader.upgradeInbound(l,{limits:a.getLimits()}),this.log("%s connection %a upgraded","inbound",l.remoteAddr)}};function vf(r={}){return e=>new Di(e,r)}return Mf(_0);})();
6
+ `)}`:`${t} :`}};yl=Ht;A.Constructed=yl;Ht.NAME="CONSTRUCTED";var ts=class extends Be{fromBER(e,t,n){return t}toBER(e){return Je}};ts.override="EndOfContentValueBlock";var bl,rs=class extends be{constructor(e={}){super(e,ts),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};bl=rs;A.EndOfContent=bl;rs.NAME=Qr;var wl,Er=class extends be{constructor(e={}){super(e,Be),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 s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};wl=Er;A.Null=wl;Er.NAME="NULL";var ns=class extends At(Be){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=K.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 s=K.BufferSourceConverter.toUint8Array(e);return St(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Zo.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};ns.NAME="BooleanValueBlock";var xl,ss=class extends be{constructor(e={}){super(e,ns),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}`}};xl=ss;A.Boolean=xl;ss.NAME="BOOLEAN";var is=class extends At(ot){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=ot.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===Qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==dl)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?ot.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};is.NAME="OctetStringValueBlock";var vl,os=class r extends be{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==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},is),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 o=Us(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Ht.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${K.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 K.BufferSourceConverter.concat(e)}};vl=os;A.OctetString=vl;os.NAME=dl;var as=class extends At(ot){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 s=-1;if(this.isConstructed){if(s=ot.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==pl)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let i=K.BufferSourceConverter.toUint8Array(e);if(!St(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=Us(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+n}toBER(e,t){if(this.isConstructed)return ot.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Je;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}}};as.NAME="BitStringValueBlock";var El,Sr=class extends be{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==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},as),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 Ht.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};El=Sr;A.BitString=El;Sr.NAME=pl;var Sl;function gp(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,u=0,l=c<o?o:c,f=0;for(let h=l;h>=0;h--,f++){switch(!0){case f<a.length:u=i[o-f]+a[c-f]+t[0];break;default:u=i[o-f]+t[0]}switch(t[0]=u/10,!0){case f>=i.length:i=Zn(new Uint8Array([u%10]),i);break;default:i[o-f]=u%10}}return t[0]>0&&(i=Zn(t,i)),i}function hl(r){if(r>=Xr.length)for(let e=Xr.length;e<=r;e++){let t=new Uint8Array([0]),n=Xr[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=i[0]/10,n[s]=i[0]%10}t[0]>0&&(n=Zn(t,n)),Xr.push(n)}return Xr[r]}function yp(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=i[o-l]-a[c-l]-t,!0){case u<0:t=1,i[o-l]=u+10;break;default:t=0,i[o-l]=u}if(t>0)for(let f=o-c+1;f>=0;f--,l++)if(u=i[o-l]-t,u<0)t=1,i[o-l]=u+10;else{t=0,i[o-l]=u;break}return i.slice()}var en=class extends At(Be){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=Zo.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ll(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&(o[1]&128)!==0?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.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 s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}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,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case e:t=yp(hl(n),t),o="-";break;default:t=gp(t,hl(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=fl.charAt(t[c]));return a===!1&&(o+=fl.charAt(0)),o}};Sl=en;en.NAME="IntegerValueBlock";Object.defineProperty(Sl.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Al,we=class r extends be{constructor(e={}){super(e,en),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return jn(),BigInt(this.valueBlock.toString())}static fromBigInt(e){jn();let t=BigInt(e),n=new Jr,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(K.Convert.FromHex(s));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${K.Convert.ToHex(a)}`)+t,l=K.BufferSourceConverter.toUint8Array(K.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}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()}`}};Al=we;A.Integer=Al;we.NAME="INTEGER";var Bl,cs=class extends we{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Bl=cs;A.Enumerated=Bl;cs.NAME="ENUMERATED";var tn=class extends At(Be){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 s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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)!==0);a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,(i[this.blockLength-1]&128)!==0?(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=tr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){jn();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+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 s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=Vt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let e="";if(this.isHexOnly)e=K.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}}};tn.NAME="sidBlock";var ls=class extends Be{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new tn;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,Je;t.push(s)}return jo(t)}fromString(e){this.value=[];let t=0,n=0,s="",i=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new tn;if(s>Number.MAX_SAFE_INTEGER){jn();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}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}};ls.NAME="ObjectIdentifierValueBlock";var _l,Ar=class extends be{constructor(e={}){super(e,ls),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()}}};_l=Ar;A.ObjectIdentifier=_l;Ar.NAME="OBJECT IDENTIFIER";var rn=class extends At(xt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=K.BufferSourceConverter.toUint8Array(e);if(!St(this,s,t,n))return-1;let i=s.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)!==0);a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,(i[this.blockLength-1]&128)!==0?(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=tr(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 s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=Vt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=K.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};rn.NAME="relativeSidBlock";var us=class extends Be{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new rn;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,Je;n.push(i)}return jo(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let i=new rn;if(i.valueDec=parseInt(s,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 s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}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}};us.NAME="RelativeObjectIdentifierValueBlock";var Il,fs=class extends be{constructor(e={}){super(e,us),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()}}};Il=fs;A.RelativeObjectIdentifier=Il;fs.NAME="RelativeObjectIdentifier";var Tl,vt=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Tl=vt;A.Sequence=Tl;vt.NAME="SEQUENCE";var kl,hs=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};kl=hs;A.Set=kl;hs.NAME="SET";var ds=class extends At(Be){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Br}toJSON(){return{...super.toJSON(),value:this.value}}};ds.NAME="StringValueBlock";var ps=class extends ds{};ps.NAME="SimpleStringValueBlock";var Ce=class extends Jn{constructor({...e}={}){super(e,ps)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,K.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};Ce.NAME="SIMPLE STRING";var ms=class extends Ce{fromBuffer(e){this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=K.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=K.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf8String(e)),this.valueBlock.value=e}};ms.NAME="Utf8StringValueBlock";var Cl,Et=class extends ms{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Cl=Et;A.Utf8String=Cl;Et.NAME="UTF8String";var gs=class extends Ce{fromBuffer(e){this.valueBlock.value=K.Convert.ToUtf16String(e),this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf16String(e))}};gs.NAME="BmpStringValueBlock";var Nl,ys=class extends gs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Nl=ys;A.BmpString=Nl;ys.NAME="BMPString";var bs=class extends Ce{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+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 s=0;s<t;s++){let i=Vt(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=e}};bs.NAME="UniversalStringValueBlock";var Rl,ws=class extends bs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Rl=ws;A.UniversalString=Rl;ws.NAME="UniversalString";var Ll,xs=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Ll=xs;A.NumericString=Ll;xs.NAME="NumericString";var Ul,vs=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ul=vs;A.PrintableString=Ul;vs.NAME="PrintableString";var Dl,Es=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Dl=Es;A.TeletexString=Dl;Es.NAME="TeletexString";var Ol,Ss=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Ol=Ss;A.VideotexString=Ol;Ss.NAME="VideotexString";var Ml,As=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Ml=As;A.IA5String=Ml;As.NAME="IA5String";var Pl,Bs=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Pl=Bs;A.GraphicString=Pl;Bs.NAME="GraphicString";var Vl,nn=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Vl=nn;A.VisibleString=Vl;nn.NAME="VisibleString";var Hl,_s=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Hl=_s;A.GeneralString=Hl;_s.NAME="GeneralString";var Fl,Is=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Fl=Is;A.CharacterString=Fl;Is.NAME="CharacterString";var Kl,sn=class extends nn{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 s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}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,K.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);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 s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,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]=Pe(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Pe(this.month,2),t[2]=Pe(this.day,2),t[3]=Pe(this.hour,2),t[4]=Pe(this.minute,2),t[5]=Pe(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}}};Kl=sn;A.UTCTime=Kl;sn.NAME="UTCTime";var ql,Ts=class extends sn{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="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.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 f=1,h=n.indexOf("+"),p="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(p=n.substring(h+1),n=n.substring(0,h),p.length!==2&&p.length!==4)throw new Error("Wrong input string for conversion");let y=parseInt(p.substring(0,2),10);if(isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*y,p.length===4){if(y=parseInt(p.substring(2,4),10),isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");c=f*y}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");i=f.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*i;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=o.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Pe(this.year,4)),t.push(Pe(this.month,2)),t.push(Pe(this.day,2)),t.push(Pe(this.hour,2)),t.push(Pe(this.minute,2)),t.push(Pe(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Pe(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};ql=Ts;A.GeneralizedTime=ql;Ts.NAME="GeneralizedTime";var zl,ks=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};zl=ks;A.DATE=zl;ks.NAME="DATE";var $l,Cs=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};$l=Cs;A.TimeOfDay=$l;Cs.NAME="TimeOfDay";var Gl,Ns=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Gl=Ns;A.DateTime=Gl;Ns.NAME="DateTime";var Wl,Rs=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Wl=Rs;A.Duration=Wl;Rs.NAME="Duration";var Zl,Ls=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Zl=Ls;A.TIME=Zl;Ls.NAME="TIME";function ae(r,e="utf8"){let t=qn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var on=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Ds=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var jl={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new Ds("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Ft=jl;async function Yl(r){let e=await Ft.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 wp(e);return{privateKey:t[0],publicKey:t[1]}}async function Xl(r,e){let t=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ft.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Jl(r,e,t){let n=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ft.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function wp(r){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");return Promise.all([Ft.get().subtle.exportKey("jwk",r.privateKey),Ft.get().subtle.exportKey("jwk",r.publicKey)])}function Jo(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return z(r.n,"base64url").length*8}var _r=class{type="RSA";_key;_raw;_multihash;constructor(e,t){this._key=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=an.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return pe.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t){return Jl(this._key,t,e)}},cn=class{type="RSA";_key;_raw;publicKey;constructor(e,t){this._key=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this._key)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e){return Xl(this._key,e)}};var Os=8192,Qo=18;function Ql(r){let{result:e}=Xo(r),t=e.valueBlock.value;return{n:at(t[1]),e:at(t[2]),d:at(t[3]),p:at(t[4]),q:at(t[5]),dp:at(t[6]),dq:at(t[7]),qi:at(t[8]),kty:"RSA",alg:"RS256"}}function xp(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 ve("JWK was missing components");let t=new vt({value:[new we({value:0}),we.fromBigInt(ct(z(r.n,"base64url"))),we.fromBigInt(ct(z(r.e,"base64url"))),we.fromBigInt(ct(z(r.d,"base64url"))),we.fromBigInt(ct(z(r.p,"base64url"))),we.fromBigInt(ct(z(r.q,"base64url"))),we.fromBigInt(ct(z(r.dp,"base64url"))),we.fromBigInt(ct(z(r.dq,"base64url"))),we.fromBigInt(ct(z(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function eu(r){let{result:e}=Xo(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:at(t[0]),e:at(t[1])}}function ea(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");let t=new vt({value:[new vt({value:[new Ar({value:"1.2.840.113549.1.1.1"}),new Er]}),new Sr({valueHex:new vt({value:[we.fromBigInt(ct(z(r.n,"base64url"))),we.fromBigInt(ct(z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function at(r){let e=r.valueBlock.valueHexView;for(;e[0]===0;)e=e.subarray(1);return ae(e,"base64url")}function ct(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(""))}function tu(r){let e=Ql(r);return ru(e)}function ta(r){let e=eu(r);if(Jo(e)>Os)throw new ar("Key size is too large");let t=xr(it.encode({Type:fe.RSA,Data:r})),n=We(Qo,t);return new _r(e,n)}function ru(r){if(Jo(r)>Os)throw new ve("Key size is too large");let e=su(r),t=xr(it.encode({Type:fe.RSA,Data:ea(e.publicKey)})),n=We(Qo,t);return new cn(e.privateKey,new _r(e.publicKey,n))}async function nu(r){if(r>Os)throw new ve("Key size is too large");let e=await Yl(r),t=xr(it.encode({Type:fe.RSA,Data:ea(e.publicKey)})),n=We(Qo,t);return new cn(e.privateKey,new _r(e.publicKey,n))}function su(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Ms=class extends mr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Bc(e);let n=qr(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 s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(e){return pr(this),this.iHash.update(e),this}digestInto(e){pr(this),dr(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:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,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()}},ra=(r,e,t)=>new Ms(r,e).update(t).digest();ra.create=(r,e)=>new Ms(r,e);function iu(r){r.lowS!==void 0&&je("lowS",r.lowS),r.prehash!==void 0&&je("prehash",r.prehash)}function vp(r){let e=Gr(r);st(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:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("invalid 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("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:Ep,hexToBytes:Sp}=Ln,na=class extends Error{constructor(e=""){super(e)}},Bt={Err:na,_tlv:{encode:(r,e)=>{let{Err:t}=Bt;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,s=Wt(n);if(s.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Wt(s.length/2|128):"";return Wt(r)+i+s+e},decode(r,e){let{Err:t}=Bt,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)o=o<<8|l;if(n+=c,o<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(r){let{Err:e}=Bt;if(r<_t)throw new e("integer: negative integers are not allowed");let t=Wt(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=Bt;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ep(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Bt,s=typeof r=="string"?Sp(r):r;yr(s);let{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(r){let{_tlv:e,_int:t}=Bt,n=e.encode(2,t.encode(r.r)),s=e.encode(2,t.encode(r.s)),i=n+s;return e.encode(48,i)}},_t=BigInt(0),ge=BigInt(1),nb=BigInt(2),ou=BigInt(3),sb=BigInt(4);function Ap(r){let e=vp(r),{Fp:t}=e,n=Ut(e.n,e.nBitLength),s=e.toBytes||((b,d,x)=>{let E=d.toAffine();return yt(Uint8Array.from([4]),t.toBytes(E.x),t.toBytes(E.y))}),i=e.fromBytes||(b=>{let d=b.subarray(1),x=t.fromBytes(d.subarray(0,t.BYTES)),E=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x,y:E}});function o(b){let{a:d,b:x}=e,E=t.sqr(b),g=t.mul(E,b);return t.add(t.add(g,t.mul(b,d)),x)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return zr(b,ge,e.n)}function c(b){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:E,n:g}=e;if(d&&typeof b!="bigint"){if(Nt(b)&&(b=mt(b)),typeof b!="string"||!d.includes(b.length))throw new Error("invalid private key");b=b.padStart(x*2,"0")}let _;try{_=typeof b=="bigint"?b:gt(ie("private key",b,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof b)}return E&&(_=Y(_,g)),Re("private key",_,ge,g),_}function u(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let l=Yt((b,d)=>{let{px:x,py:E,pz:g}=b;if(t.eql(g,t.ONE))return{x,y:E};let _=b.is0();d==null&&(d=_?t.ONE:t.inv(g));let N=t.mul(x,d),R=t.mul(E,d),I=t.mul(g,d);if(_)return{x:t.ZERO,y:t.ZERO};if(!t.eql(I,t.ONE))throw new Error("invZ was invalid");return{x:N,y:R}}),f=Yt(b=>{if(b.is0()){if(e.allowInfinityPoint&&!t.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=b.toAffine();if(!t.isValid(d)||!t.isValid(x))throw new Error("bad point: x or y not FE");let E=t.sqr(x),g=o(d);if(!t.eql(E,g))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,x,E){if(this.px=d,this.py=x,this.pz=E,d==null||!t.isValid(d))throw new Error("x required");if(x==null||!t.isValid(x))throw new Error("y required");if(E==null||!t.isValid(E))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x,y:E}=d||{};if(!d||!t.isValid(x)||!t.isValid(E))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let g=_=>t.eql(_,t.ZERO);return g(x)&&g(E)?h.ZERO:new h(x,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=t.invertBatch(d.map(E=>E.pz));return d.map((E,g)=>E.toAffine(x[g])).map(h.fromAffine)}static fromHex(d){let x=h.fromAffine(i(ie("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,x){return Mn(h,n,d,x)}_setWindowSize(d){y.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:x,py:E,pz:g}=this,{px:_,py:N,pz:R}=d,I=t.eql(t.mul(x,R),t.mul(_,g)),C=t.eql(t.mul(E,R),t.mul(N,g));return I&&C}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:x}=e,E=t.mul(x,ou),{px:g,py:_,pz:N}=this,R=t.ZERO,I=t.ZERO,C=t.ZERO,T=t.mul(g,g),re=t.mul(_,_),$=t.mul(N,N),F=t.mul(g,_);return F=t.add(F,F),C=t.mul(g,N),C=t.add(C,C),R=t.mul(d,C),I=t.mul(E,$),I=t.add(R,I),R=t.sub(re,I),I=t.add(re,I),I=t.mul(R,I),R=t.mul(F,R),C=t.mul(E,C),$=t.mul(d,$),F=t.sub(T,$),F=t.mul(d,F),F=t.add(F,C),C=t.add(T,T),T=t.add(C,T),T=t.add(T,$),T=t.mul(T,F),I=t.add(I,T),$=t.mul(_,N),$=t.add($,$),T=t.mul($,F),R=t.sub(R,T),C=t.mul($,re),C=t.add(C,C),C=t.add(C,C),new h(R,I,C)}add(d){u(d);let{px:x,py:E,pz:g}=this,{px:_,py:N,pz:R}=d,I=t.ZERO,C=t.ZERO,T=t.ZERO,re=e.a,$=t.mul(e.b,ou),F=t.mul(x,_),le=t.mul(E,N),S=t.mul(g,R),k=t.add(x,E),w=t.add(_,N);k=t.mul(k,w),w=t.add(F,le),k=t.sub(k,w),w=t.add(x,g);let m=t.add(_,R);return w=t.mul(w,m),m=t.add(F,S),w=t.sub(w,m),m=t.add(E,g),I=t.add(N,R),m=t.mul(m,I),I=t.add(le,S),m=t.sub(m,I),T=t.mul(re,w),I=t.mul($,S),T=t.add(I,T),I=t.sub(le,T),T=t.add(le,T),C=t.mul(I,T),le=t.add(F,F),le=t.add(le,F),S=t.mul(re,S),w=t.mul($,w),le=t.add(le,S),S=t.sub(F,S),S=t.mul(re,S),w=t.add(w,S),F=t.mul(le,w),C=t.add(C,F),F=t.mul(m,w),I=t.mul(k,I),I=t.sub(I,F),F=t.mul(k,le),T=t.mul(m,T),T=t.add(T,F),new h(I,C,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return y.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:x,n:E}=e;Re("scalar",d,_t,E);let g=h.ZERO;if(d===_t)return g;if(this.is0()||d===ge)return this;if(!x||y.hasPrecomputes(this))return y.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:_,k1:N,k2neg:R,k2:I}=x.splitScalar(d),C=g,T=g,re=this;for(;N>_t||I>_t;)N&ge&&(C=C.add(re)),I&ge&&(T=T.add(re)),re=re.double(),N>>=ge,I>>=ge;return _&&(C=C.negate()),R&&(T=T.negate()),T=new h(t.mul(T.px,x.beta),T.py,T.pz),C.add(T)}multiply(d){let{endo:x,n:E}=e;Re("scalar",d,ge,E);let g,_;if(x){let{k1neg:N,k1:R,k2neg:I,k2:C}=x.splitScalar(d),{p:T,f:re}=this.wNAF(R),{p:$,f:F}=this.wNAF(C);T=y.constTimeNegate(N,T),$=y.constTimeNegate(I,$),$=new h(t.mul($.px,x.beta),$.py,$.pz),g=T.add($),_=re.add(F)}else{let{p:N,f:R}=this.wNAF(d);g=N,_=R}return h.normalizeZ([g,_])[0]}multiplyAndAddUnsafe(d,x,E){let g=h.BASE,_=(R,I)=>I===_t||I===ge||!R.equals(g)?R.multiplyUnsafe(I):R.multiply(I),N=_(this,x).add(_(d,E));return N.is0()?void 0:N}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=e;if(d===ge)return!0;if(x)return x(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=e;return d===ge?this:x?x(h,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return je("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return je("isCompressed",d),mt(this.toRawBytes(d))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let p=e.nBitLength,y=On(h,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function Bp(r){let e=Gr(r);return st(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function au(r){let e=Bp(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(S){return Y(S,n)}function a(S){return Un(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Ap({...e,toBytes(S,k,w){let m=k.toAffine(),v=t.toBytes(m.x),B=yt;return je("isCompressed",w),w?B(Uint8Array.from([k.hasEvenY()?2:3]),v):B(Uint8Array.from([4]),v,t.toBytes(m.y))},fromBytes(S){let k=S.length,w=S[0],m=S.subarray(1);if(k===s&&(w===2||w===3)){let v=gt(m);if(!zr(v,ge,t.ORDER))throw new Error("Point is not on curve");let B=l(v),L;try{L=t.sqrt(B)}catch(q){let D=q instanceof Error?": "+q.message:"";throw new Error("Point is not on curve"+D)}let U=(L&ge)===ge;return(w&1)===1!==U&&(L=t.neg(L)),{x:v,y:L}}else if(k===i&&w===4){let v=t.fromBytes(m.subarray(0,t.BYTES)),B=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:v,y:B}}else{let v=s,B=i;throw new Error("invalid Point, expected length of "+v+", or uncompressed "+B+", got "+k)}}}),h=S=>mt(Lt(S,e.nByteLength));function p(S){let k=n>>ge;return S>k}function y(S){return p(S)?o(-S):S}let b=(S,k,w)=>gt(S.slice(k,w));class d{constructor(k,w,m){this.r=k,this.s=w,this.recovery=m,this.assertValidity()}static fromCompact(k){let w=e.nByteLength;return k=ie("compactSignature",k,w*2),new d(b(k,0,w),b(k,w,2*w))}static fromDER(k){let{r:w,s:m}=Bt.toSig(ie("DER",k));return new d(w,m)}assertValidity(){Re("r",this.r,ge,n),Re("s",this.s,ge,n)}addRecoveryBit(k){return new d(this.r,this.s,k)}recoverPublicKey(k){let{r:w,s:m,recovery:v}=this,B=R(ie("msgHash",k));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let L=v===2||v===3?w+e.n:w;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let U=(v&1)===0?"02":"03",M=c.fromHex(U+h(L)),q=a(L),D=o(-B*q),Z=o(m*q),ee=c.BASE.multiplyAndAddUnsafe(M,D,Z);if(!ee)throw new Error("point at infinify");return ee.assertValidity(),ee}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Zt(this.toDERHex())}toDERHex(){return Bt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Zt(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let x={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=oo(e.n);return Pc(e.randomBytes(S),e.n)},precompute(S=8,k=c.BASE){return k._setWindowSize(S),k.multiply(BigInt(3)),k}};function E(S,k=!0){return c.fromPrivateKey(S).toRawBytes(k)}function g(S){let k=Nt(S),w=typeof S=="string",m=(k||w)&&S.length;return k?m===s||m===i:w?m===2*s||m===2*i:S instanceof c}function _(S,k,w=!0){if(g(S))throw new Error("first arg must be private key");if(!g(k))throw new Error("second arg must be public key");return c.fromHex(k).multiply(u(S)).toRawBytes(w)}let N=e.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let k=gt(S),w=S.length*8-e.nBitLength;return w>0?k>>BigInt(w):k},R=e.bits2int_modN||function(S){return o(N(S))},I=$r(e.nBitLength);function C(S){return Re("num < 2^"+e.nBitLength,S,_t,I),Lt(S,e.nByteLength)}function T(S,k,w=re){if(["recovered","canonical"].some(de=>de in w))throw new Error("sign() legacy options not supported");let{hash:m,randomBytes:v}=e,{lowS:B,prehash:L,extraEntropy:U}=w;B==null&&(B=!0),S=ie("msgHash",S),iu(w),L&&(S=ie("prehashed msgHash",m(S)));let M=R(S),q=u(k),D=[C(q),C(M)];if(U!=null&&U!==!1){let de=U===!0?v(t.BYTES):U;D.push(ie("extraEntropy",de))}let Z=yt(...D),ee=M;function he(de){let ye=N(de);if(!f(ye))return;let xe=a(ye),Ne=c.BASE.multiply(ye).toAffine(),Te=o(Ne.x);if(Te===_t)return;let rt=o(xe*o(ee+Te*q));if(rt===_t)return;let lt=(Ne.x===Te?0:2)|Number(Ne.y&ge),Mr=rt;return B&&p(rt)&&(Mr=y(rt),lt^=1),new d(Te,Mr,lt)}return{seed:Z,k2sig:he}}let re={lowS:e.lowS,prehash:!1},$={lowS:e.lowS,prehash:!1};function F(S,k,w=re){let{seed:m,k2sig:v}=T(S,k,w),B=e;return ro(B.hash.outputLen,B.nByteLength,B.hmac)(m,v)}c.BASE._setWindowSize(8);function le(S,k,w,m=$){let v=S;k=ie("msgHash",k),w=ie("publicKey",w);let{lowS:B,prehash:L,format:U}=m;if(iu(m),"strict"in m)throw new Error("options.strict was renamed to lowS");if(U!==void 0&&U!=="compact"&&U!=="der")throw new Error("format must be compact or der");let M=typeof v=="string"||Nt(v),q=!M&&!U&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!M&&!q)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let D,Z;try{if(q&&(D=new d(v.r,v.s)),M){try{U!=="compact"&&(D=d.fromDER(v))}catch(lt){if(!(lt instanceof Bt.Err))throw lt}!D&&U!=="der"&&(D=d.fromCompact(v))}Z=c.fromHex(w)}catch{return!1}if(!D||B&&D.hasHighS())return!1;L&&(k=e.hash(k));let{r:ee,s:he}=D,de=R(k),ye=a(he),xe=o(de*ye),Ne=o(ee*ye),Te=c.BASE.multiplyAndAddUnsafe(Z,xe,Ne)?.toAffine();return Te?o(Te.x)===ee:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:_,sign:F,verify:le,ProjectivePoint:c,Signature:d,utils:x}}function _p(r){return{hash:r,hmac:(e,...t)=>ra(r,e,ji(...t)),randomBytes:kn}}function cu(r,e){let t=n=>au({...r,..._p(n)});return{...t(e),create:t}}var fu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),lu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ip=BigInt(1),sa=BigInt(2),uu=(r,e)=>(r+e/sa)/e;function Tp(r){let e=fu,t=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=se(l,t,e)*l%e,h=se(f,t,e)*l%e,p=se(h,sa,e)*u%e,y=se(p,s,e)*p%e,b=se(y,i,e)*y%e,d=se(b,a,e)*b%e,x=se(d,c,e)*d%e,E=se(x,a,e)*b%e,g=se(E,t,e)*l%e,_=se(g,o,e)*y%e,N=se(_,n,e)*u%e,R=se(N,sa,e);if(!ia.eql(ia.sqr(R),r))throw new Error("Cannot find square root");return R}var ia=Ut(fu,void 0,void 0,{sqrt:Tp}),rr=cu({a:BigInt(0),b:BigInt(7),Fp:ia,n:lu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=lu,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ip*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=uu(i*r,e),c=uu(-n*r,e),u=Y(r-a*t-c*s,e),l=Y(-a*n-c*i,e),f=u>o,h=l>o;if(f&&(u=e-u),h&&(l=e-l),u>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},xr),db=BigInt(0);var pb=rr.ProjectivePoint;function He(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=Ue(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}function hu(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function du(r,e,t){let n=br.digest(t instanceof Uint8Array?t:t.subarray());if(hu(n))return n.then(({digest:s})=>rr.verify(e,s,r)).catch(s=>{throw new on(String(s))});try{return rr.verify(e,n.digest,r)}catch(s){throw new on(String(s))}}var Ps=class{type="secp256k1";raw;_key;constructor(e){this._key=mu(e),this.raw=pu(this._key)}toMultihash(){return dt.digest(Dt(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,t){return du(this._key,t,e)}};function oa(r){return new Ps(r)}function pu(r){return rr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function mu(r){try{return rr.ProjectivePoint.fromHex(r),r}catch(e){throw new ar(String(e))}}function gu(r){let{Type:e,Data:t}=it.decode(r),n=t??new Uint8Array;switch(e){case fe.RSA:return ta(n);case fe.Ed25519:return po(n);case fe.secp256k1:return oa(n);default:throw new cr}}function yu(r){let{Type:e,Data:t}=it.decode(r.digest),n=t??new Uint8Array;switch(e){case fe.Ed25519:return po(n);case fe.secp256k1:return oa(n);default:throw new cr}}function Dt(r){return it.encode({Type:fe[r.type],Data:r.raw})}var bu=Symbol.for("nodejs.util.inspect.custom"),kp=114,ln=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Mi]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return pe.createV1(kp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return me(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return me(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[bu](){return`PeerId(${this.toString()})`}},Vs=class extends ln{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Hs=class extends ln{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Fs=class extends ln{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Cp=2336,Ks=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=dt.digest(z(this.url))}[bu](){return`PeerId(${this.url})`}[Mi]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return pe.createV1(Cp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ae(e)),e.toString()===this.toString())}};function aa(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=qe(J.decode(`z${r}`));else{if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=qe(e.decode(r))}return un(t)}function un(r){if(Rp(r))return new Vs({multihash:r});if(Np(r))try{let e=yu(r);if(e.type==="Ed25519")return new Hs({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Fs({multihash:r,publicKey:e})}catch{let t=ae(r.digest);return new Ks(new URL(t))}throw new An("Supplied PeerID Multihash is invalid")}function Np(r){return r.code===dt.code}function Rp(r){return r.code===br.code}var xu=Symbol.for("@achingbrain/uint8arraylist");function wu(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function qs(r){return!!r?.[xu]}var Qe=class r{bufs;length;[xu]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(qs(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(qs(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=wu(this.bufs,e);return t.buf[t.index]}set(e,t){let n=wu(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(qs(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return He(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:He(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),i=new r;return i.length=s,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(o);break}let f=e-a;n.push(o.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(l){if(t===c){n.push(o);break}n.push(o.subarray(0,t-a));break}n.push(o)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!qs(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let f=0;f<i;f++)o[f]=-1;for(let f=0;f<s;f++)o[n[f]]=f;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let p=this.get(f+h);if(n[h]!==p){l=Math.max(1,h-a[p]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Ue(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=oe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=oe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=oe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Ue(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=oe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=oe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=oe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=oe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=oe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!me(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,i)=>s+i.byteLength,0)),n.length=t,n}};var fn;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&t.payload.byteLength>0&&(n.uint32(26),n.bytes(t.payload)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={publicKey:oe(0),payloadType:oe(0),payload:oe(0),signature:oe(0)},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.publicKey=t.bytes();break}case 2:{i.payloadType=t.bytes();break}case 3:{i.payload=t.bytes();break}case 5:{i.signature=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(fn||(fn={}));var zs=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var hn=class r{static createFromProtobuf=async e=>{let t=fn.decode(e),n=gu(t.publicKey);return new r({publicKey:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})};static seal=async(e,t)=>{if(t==null)throw new Error("Missing private key");let n=e.domain,s=e.codec,i=e.marshal(),o=vu(n,s,i),a=await t.sign(o.subarray());return new r({publicKey:t.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(e,t)=>{let n=await r.createFromProtobuf(e);if(!await n.validate(t))throw new zs("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:t,payloadType:n,payload:s,signature:i}=e;this.publicKey=t,this.payloadType=n,this.payload=s,this.signature=i}marshal(){return this.marshaled==null&&(this.marshaled=fn.encode({publicKey:Dt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return me(this.marshal(),e.marshal())}async validate(e){let t=vu(e,this.payloadType,this.payload);return this.publicKey.verify(t.subarray(),this.signature)}},vu=(r,e,t)=>{let n=z(r),s=ze(n.byteLength),i=ze(e.length),o=ze(t.length);return new Qe(s,n,i,e,o,t)};var $s=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,s){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,e);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=e,i+=l,i>u||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!n&&c&&o>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 s=n*2;if(n<t.length-3){let o=this.readSeparator(":",n,()=>this.readIPv4Addr());if(o!==void 0)return t[s]=o[0],t[s+1]=o[1],t[s+2]=o[2],t[s+3]=o[3],[s+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[s,!1];t[s]=i>>8,t[s+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(n+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Eu=45,Lp=15,Ir=new $s;function ca(r){if(!(r.length>Lp))return Ir.new(r).parseWith(()=>Ir.readIPv4Addr())}function la(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Eu))return Ir.new(r).parseWith(()=>Ir.readIPv6Addr())}function Gs(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Eu)return;let t=Ir.new(r).parseWith(()=>Ir.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var $w=parseInt("0xFFFF",16),Gw=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ws(r){return!!ca(r)}function Zs(r){return!!la(r)}function js(r){return!!Gs(r)}var Bu=Ws,Pp=Zs,ua=function(r){let e=0;if(r=r.toString().trim(),Bu(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Pp(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Bu(t[n]),o;i&&(o=ua(t[n]),t[n]=ae(o.slice(0,2),"base16")),o!=null&&++n<8&&t.splice(n,0,ae(o.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 s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);s[e++]=i>>8&255,s[e++]=i&255}return s}throw new Error("invalid ip address")},_u=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let i=0;i<t;i++)s.push(r[e+i]);return s.join(".")}if(t===16){let s=[];for(let i=0;i<t;i+=2)s.push(n.getUint16(e+i).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Tr={},fa={},Hp=[[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"],[481,-1,"http-path"],[777,-1,"memory"]];Hp.forEach(r=>{let e=Fp(...r);fa[e.code]=e,Tr[e.name]=e});function Fp(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function Q(r){if(typeof r=="number"){if(fa[r]!=null)return fa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Tr[r]!=null)return Tr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var kx=Q("ip4"),Cx=Q("ip6"),Nx=Q("ipcidr");function ma(r,e){switch(Q(r).code){case 4:case 41:return qp(e);case 42:return pa(e);case 43:return ae(e,"base10");case 6:case 273:case 33:case 132:return ku(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return pa(e);case 421:return Wp(e);case 444:return Tu(e);case 445:return Tu(e);case 466:return Gp(e);case 481:return globalThis.encodeURIComponent(pa(e));default:return ae(e,"base16")}}function ga(r,e){switch(Q(r).code){case 4:return Iu(e);case 41:return Iu(e);case 42:return da(e);case 43:return z(e,"base10");case 6:case 273:case 33:case 132:return ya(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return da(e);case 421:return zp(e);case 444:return Zp(e);case 445:return jp(e);case 466:return $p(e);case 481:return da(globalThis.decodeURIComponent(e));default:return z(e,"base16")}}var ha=Object.values(Wr).map(r=>r.decoder),Kp=function(){let r=ha[0].or(ha[1]);return ha.slice(2).forEach(e=>r=r.or(e)),r}();function Iu(r){if(!js(r))throw new Error("invalid ip address");return ua(r)}function qp(r){let e=_u(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!js(e))throw new Error("invalid ip address");return e}function ya(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function ku(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function da(r){let e=z(r),t=Uint8Array.from(ze(e.length));return He([t,e],t.length+e.length)}function pa(r){let e=bt(r);if(r=r.slice(Se(e)),r.length!==e)throw new Error("inconsistent lengths");return ae(r)}function zp(r){let e;r[0]==="Q"||r[0]==="1"?e=qe(J.decode(`z${r}`)).bytes:e=pe.parse(r).multihash.bytes;let t=Uint8Array.from(ze(e.length));return He([t,e],t.length+e.length)}function $p(r){let e=Kp.decode(r),t=Uint8Array.from(ze(e.length));return He([t,e],t.length+e.length)}function Gp(r){let e=bt(r),t=r.slice(Se(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ae(t,"base64url")}function Wp(r){let e=bt(r),t=r.slice(Se(e));if(t.length!==e)throw new Error("inconsistent lengths");return ae(t,"base58btc")}function Zp(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=ht.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 s=ya(n);return He([t,s],t.length+s.length)}function jp(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=ht.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 s=ya(n);return He([t,s],t.length+s.length)}function Tu(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ae(e,"base32"),s=ku(t);return`${n}:${s}`}function Cu(r){r=ba(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){let o=s[i],a=Q(o);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=s.length)throw new Ys("invalid address: "+r);if(a.path===!0){n=ba(s.slice(i).join("/")),e.push([a.code,ga(a.code,n)]),t.push([a.code,n]);break}let c=ga(a.code,s[i]);e.push([a.code,c]),t.push([a.code,ma(a.code,c)])}return{string:Nu(t),bytes:Xs(e),tuples:e,stringTuples:t,path:n}}function wa(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let i=bt(r,s),o=Se(i),a=Q(i),c=Yp(a,r.slice(s+o));if(c===0){e.push([i]),t.push([i]),s+=o;continue}let u=r.slice(s+o,s+o+c);if(s+=c+o,s>r.length)throw new Ys("Invalid address Uint8Array: "+ae(r,"base16"));e.push([i,u]);let l=ma(i,u);if(t.push([i,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Nu(t),tuples:e,stringTuples:t,path:n}}function Nu(r){let e=[];return r.map(t=>{let n=Q(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ba(e.join("/"))}function Xs(r){return He(r.map(e=>{let t=Q(e[0]),n=Uint8Array.from(ze(t.code));return e.length>1&&e[1]!=null&&(n=He([n,e[1]])),n}))}function Yp(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=bt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Se(t)}}function ba(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var Ys=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var Xp=Symbol.for("nodejs.util.inspect.custom"),va=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Jp=[Q("dns").code,Q("dns4").code,Q("dns6").code,Q("dnsaddr").code],xa=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Js=class r{bytes;#e;#t;#r;#n;[va]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=wa(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Cu(e)}else if(Lu(e))t=wa(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,i="",o=Q("tcp"),a=Q("udp"),c=Q("ip4"),u=Q("ip6"),l=Q("dns6"),f=Q("ip6zone");for(let[p,y]of this.stringTuples())p===f.code&&(i=`%${y??""}`),Jp.includes(p)&&(t=o.name==="tcp"?"tcp":"udp",s=443,n=`${y??""}${i}`,e=p===l.code?6:4),(p===o.code||p===a.code)&&(t=Q(p).name==="tcp"?"tcp":"udp",s=parseInt(y??"")),(p===c.code||p===u.code)&&(t=Q(p).name==="tcp"?"tcp":"udp",n=`${y??""}${i}`,e=p===u.code?6:4);if(e==null||t==null||n==null||s==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:s}}protos(){return this.#t.map(([e])=>Object.assign({},Q(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Q(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Xs(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===Tr.p2p.code&&e.push([n,s]),n===Tr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ae(J.decode(`z${n}`),"base58btc"):ae(pe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return me(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Ru.get(t.name);if(n==null)throw new xa(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>_e(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)}[Xp](){return`Multiaddr(${this.#e})`}};var Ru=new Map;function Lu(r){return!!r?.[va]}function _e(r){return new Js(r)}function et(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Qs=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function ei(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new Qs(t?.errorMessage,t?.errorCode,t?.errorName));let n,s=new Qs(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,o)=>{n=()=>{o(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Ea=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=et(),this.haveNext=et()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=et(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=et(),await ei(this.readNext.promise,t?.signal,t)}};function Uu(){return new Ea}var ti=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Sa=class extends Error{code;constructor(e,t){super(e),this.code=t}},Aa=class extends Sa{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Du(r,e){let t=Uu();r.sink(t).catch(async o=>{await t.end(o)}),r.sink=async o=>{for await(let a of o)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new Qe;return{read:async(o,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new Aa("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(o==null){let{done:f,value:h}=await Promise.race([n.next(),u]);return f===!0?new Qe:h}for(;s.byteLength<o;){let{value:f,done:h}=await Promise.race([n.next(),u]);if(h===!0)throw new ti("unexpected end of input");s.append(f)}let l=s.sublist(0,o);return s.consume(o),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(o,a)=>{a?.signal?.throwIfAborted(),o instanceof Uint8Array?await t.push(o,a):await t.push(o.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let o=r.source;r.source=async function*(){e?.yieldBytes===!1?yield s:yield*s,yield*o}()}return r}}}var ri=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ni=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},si=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ou(r,e={}){let t=Du(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Se(e.maxDataLength));let n=e?.lengthDecoder??bt,s=e?.lengthEncoder??ze;return{read:async o=>{let a=-1,c=new Qe;for(;;){c.append(await t.read(1,o));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new ri("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new si("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ni("message length too long");return t.read(a,o)},write:async(o,a)=>{await t.write(new Qe(s(o.byteLength),o),a)},writeV:async(o,a)=>{let c=new Qe(...o.flatMap(u=>[s(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Kt(r,e){let t=Ou(r,e),n={read:async(s,i)=>{let o=await t.read(i);return s.decode(o)},write:async(s,i,o)=>{await t.write(i.encode(s),o)},writeV:async(s,i,o)=>{await t.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ba=1e3,Mu=60*Ba,ii=290,Pu=15,Vu=2*60*Mu,Hu=1,oi=2e3,Fu=100,_a="circuit-relay-source",dn=`${Pi}-circuit-relay`,Ia=`${Pi}-circuit-relay-source`,Ku=2*Mu,qu=BigInt(1<<17),Ge="/libp2p/circuit/relay/0.2.0/hop",nr="/libp2p/circuit/relay/0.2.0/stop",zu=30*Ba,S1=30*Ba,pn=300,$u=4096,Gu=.001;var j;(function(r){let e;(function(s){s.RESERVE="RESERVE",s.CONNECT="CONNECT",s.STATUS="STATUS"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.RESERVE=0]="RESERVE",s[s.CONNECT=1]="CONNECT",s[s.STATUS=2]="STATUS"})(t||(t={})),function(s){s.codec=()=>er(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Me((s,i,o={})=>{o.lengthDelimited!==!1&&i.fork(),s.type!=null&&(i.uint32(8),r.Type.codec().encode(s.type,i)),s.peer!=null&&(i.uint32(18),kr.codec().encode(s.peer,i)),s.reservation!=null&&(i.uint32(26),ai.codec().encode(s.reservation,i)),s.limit!=null&&(i.uint32(34),Cr.codec().encode(s.limit,i)),s.status!=null&&(i.uint32(40),V.codec().encode(s.status,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(s);break}case 2:{a.peer=kr.codec().decode(s,s.uint32(),{limits:o.limits?.peer});break}case 3:{a.reservation=ai.codec().decode(s,s.uint32(),{limits:o.limits?.reservation});break}case 4:{a.limit=Cr.codec().decode(s,s.uint32(),{limits:o.limits?.limit});break}case 5:{a.status=V.codec().decode(s);break}default:{s.skipType(u&7);break}}}return a})),n),r.encode=s=>Oe(s,r.codec()),r.decode=(s,i)=>De(s,r.codec(),i)})(j||(j={}));var Fe;(function(r){let e;(function(s){s.CONNECT="CONNECT",s.STATUS="STATUS"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.CONNECT=0]="CONNECT",s[s.STATUS=1]="STATUS"})(t||(t={})),function(s){s.codec=()=>er(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Me((s,i,o={})=>{o.lengthDelimited!==!1&&i.fork(),s.type!=null&&(i.uint32(8),r.Type.codec().encode(s.type,i)),s.peer!=null&&(i.uint32(18),kr.codec().encode(s.peer,i)),s.limit!=null&&(i.uint32(26),Cr.codec().encode(s.limit,i)),s.status!=null&&(i.uint32(32),V.codec().encode(s.status,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(s);break}case 2:{a.peer=kr.codec().decode(s,s.uint32(),{limits:o.limits?.peer});break}case 3:{a.limit=Cr.codec().decode(s,s.uint32(),{limits:o.limits?.limit});break}case 4:{a.status=V.codec().decode(s);break}default:{s.skipType(u&7);break}}}return a})),n),r.encode=s=>Oe(s,r.codec()),r.decode=(s,i)=>De(s,r.codec(),i)})(Fe||(Fe={}));var kr;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),t.id!=null&&t.id.byteLength>0&&(n.uint32(10),n.bytes(t.id)),t.addrs!=null)for(let i of t.addrs)n.uint32(18),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={id:oe(0),addrs:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.id=t.bytes();break}case 2:{if(s.limits?.addrs!=null&&i.addrs.length===s.limits.addrs)throw new Yr('Decode error - map field "addrs" had too many elements');i.addrs.push(t.bytes());break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(kr||(kr={}));var ai;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),t.expire!=null&&t.expire!==0n&&(n.uint32(8),n.uint64(t.expire)),t.addrs!=null)for(let i of t.addrs)n.uint32(18),n.bytes(i);t.voucher!=null&&(n.uint32(26),ci.codec().encode(t.voucher,n)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={expire:0n,addrs:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.expire=t.uint64();break}case 2:{if(s.limits?.addrs!=null&&i.addrs.length===s.limits.addrs)throw new Yr('Decode error - map field "addrs" had too many elements');i.addrs.push(t.bytes());break}case 3:{i.voucher=ci.codec().decode(t,t.uint32(),{limits:s.limits?.voucher});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(ai||(ai={}));var Cr;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.duration!=null&&(n.uint32(8),n.uint32(t.duration)),t.data!=null&&(n.uint32(16),n.uint64(t.data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.duration=t.uint32();break}case 2:{i.data=t.uint64();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(Cr||(Cr={}));var V;(function(r){r.UNUSED="UNUSED",r.OK="OK",r.RESERVATION_REFUSED="RESERVATION_REFUSED",r.RESOURCE_LIMIT_EXCEEDED="RESOURCE_LIMIT_EXCEEDED",r.PERMISSION_DENIED="PERMISSION_DENIED",r.CONNECTION_FAILED="CONNECTION_FAILED",r.NO_RESERVATION="NO_RESERVATION",r.MALFORMED_MESSAGE="MALFORMED_MESSAGE",r.UNEXPECTED_MESSAGE="UNEXPECTED_MESSAGE"})(V||(V={}));var Ta;(function(r){r[r.UNUSED=0]="UNUSED",r[r.OK=100]="OK",r[r.RESERVATION_REFUSED=200]="RESERVATION_REFUSED",r[r.RESOURCE_LIMIT_EXCEEDED=201]="RESOURCE_LIMIT_EXCEEDED",r[r.PERMISSION_DENIED=202]="PERMISSION_DENIED",r[r.CONNECTION_FAILED=203]="CONNECTION_FAILED",r[r.NO_RESERVATION=204]="NO_RESERVATION",r[r.MALFORMED_MESSAGE=400]="MALFORMED_MESSAGE",r[r.UNEXPECTED_MESSAGE=401]="UNEXPECTED_MESSAGE"})(Ta||(Ta={}));(function(r){r.codec=()=>er(Ta)})(V||(V={}));var Nr;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.relay!=null&&t.relay.byteLength>0&&(n.uint32(10),n.bytes(t.relay)),t.peer!=null&&t.peer.byteLength>0&&(n.uint32(18),n.bytes(t.peer)),t.expiration!=null&&t.expiration!==0n&&(n.uint32(24),n.uint64(t.expiration)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={relay:oe(0),peer:oe(0),expiration:0n},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.relay=t.bytes();break}case 2:{i.peer=t.bytes();break}case 3:{i.expiration=t.uint64();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(Nr||(Nr={}));var ci;(function(r){let e;r.codec=()=>(e==null&&(e=Me((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&(n.uint32(26),Nr.codec().encode(t.payload,n)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n,s={})=>{let i={publicKey:oe(0),payloadType:oe(0),signature:oe(0)},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{i.publicKey=t.bytes();break}case 2:{i.payloadType=t.bytes();break}case 3:{i.payload=Nr.codec().decode(t,t.uint32(),{limits:s.limits?.payload});break}case 5:{i.signature=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Oe(t,r.codec()),r.decode=(t,n)=>De(t,r.codec(),n)})(ci||(ci={}));var Qp=r=>r.toString().split("/").slice(1),Rr=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),P=r=>({match:e=>Rr(t=>t===r).match(e),pattern:r}),sr=()=>({match:r=>Rr(e=>typeof e=="string").match(r),pattern:"{string}"}),mn=()=>({match:r=>Rr(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),X=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{J.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),gn=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Co.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),G=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Ie=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),H=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function te(...r){function e(s){let i=Qp(s);for(let o of r){let a=o.match(i);if(a===!1)return!1;i=a}return i}function t(s){return e(s)!==!1}function n(s){let i=e(s);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var ui=H(P("dns4"),sr()),fi=H(P("dns6"),sr()),hi=H(P("dnsaddr"),sr()),Ca=H(P("dns"),sr()),L1=te(ui,G(X())),U1=te(fi,G(X())),D1=te(hi,G(X())),O1=te(Ie(Ca,hi,ui,fi),G(X())),Wu=H(P("ip4"),Rr(Ws)),Zu=H(P("ip6"),Rr(Zs)),Na=Ie(Wu,Zu),It=Ie(Na,Ca,ui,fi,hi),M1=te(Ie(Na,H(Ie(Ca,hi,ui,fi),G(X())))),P1=te(Wu),V1=te(Zu),H1=te(Na),Ra=H(It,P("tcp"),mn()),yn=H(It,P("udp"),mn()),F1=te(H(Ra,G(X()))),K1=te(yn),La=H(yn,P("quic"),G(X())),di=H(yn,P("quic-v1"),G(X())),e0=Ie(La,di),q1=te(La),z1=te(di),ka=Ie(It,Ra,yn,La,di),ju=Ie(H(ka,P("ws"),G(X()))),$1=te(ju),Yu=Ie(H(ka,P("wss"),G(X())),H(ka,P("tls"),G(H(P("sni"),sr())),P("ws"),G(X()))),G1=te(Yu),Xu=H(yn,P("webrtc-direct"),G(gn()),G(gn()),G(X())),W1=te(Xu),Ju=H(di,P("webtransport"),G(gn()),G(gn()),G(X())),Z1=te(Ju),li=Ie(ju,Yu,H(Ra,G(X())),H(e0,G(X())),H(It,G(X())),Xu,Ju,X()),Qu=te(li),t0=H(li,P("p2p-circuit"),X()),pi=te(t0),r0=Ie(H(li,P("p2p-circuit"),P("webrtc"),G(X())),H(li,P("webrtc"),G(X())),H(P("webrtc"),G(X()))),j1=te(r0),n0=Ie(H(It,P("tcp"),mn(),P("http"),G(X())),H(It,P("http"),G(X()))),Y1=te(n0),s0=Ie(H(It,P("tcp"),Ie(H(P("443"),P("http")),H(mn(),P("https"))),G(X())),H(It,P("tls"),P("http"),G(X())),H(It,P("https"),G(X()))),X1=te(s0),i0=Ie(H(P("memory"),sr(),G(X()))),J1=te(i0);function mi(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 s=e.signal;return s.clear=n,s}var gi=class extends Error{constructor(e="Transfer limit error"){super(e),this.name="TransferLimitError"}},bn=class extends Error{constructor(e="Duration limit error"){super(e),this.name="DurationLimitError"}},wn=class extends Error{static name="HadEnoughRelaysError";name="HadEnoughRelaysError"},yi=class extends Error{static name="DoubleRelayError";name="DoubleRelayError"},bi=class extends Error{static name="RelayQueueFullError";name="RelayQueueFullError"};async function*ef(r,e,t){let n=e.remaining;for await(let s of r){let i=BigInt(s.byteLength);if(e.remaining-i<0){let o=Number(e.remaining);e.remaining=0n;try{o!==0&&(yield s.subarray(0,o))}catch(a){t.log.error(a)}throw new gi(`data limit of ${n} bytes exceeded`)}e.remaining-=i,yield s}}function tf(r,e,t,n,s){function i(f){r.abort(f),e.abort(f)}let o=[t,n.signal];n.limit?.duration!=null&&(s.log("limiting relayed connection duration to %dms",n.limit.duration),o.push(AbortSignal.timeout(n.limit.duration)));let a=mi(o),c=!1,u=!1,l;n.limit?.data!=null&&(l={remaining:n.limit.data}),queueMicrotask(()=>{let f=()=>{s.log("relayed connection reached time limit"),e.abort(new bn(`duration limit of ${n.limit?.duration} ms exceeded`))};a.addEventListener("abort",f,{once:!0}),e.sink(l==null?r.source:ef(r.source,l,s)).catch(h=>{s.log.error("error while relaying streams src -> dst",h),i(h)}).finally(()=>{c=!0,u&&(a.removeEventListener("abort",f),a.clear())})}),queueMicrotask(()=>{let f=()=>{s.log("relayed connection reached time limit"),r.abort(new bn(`duration limit of ${n.limit?.duration} ms exceeded`))};a.addEventListener("abort",f,{once:!0}),r.sink(l==null?e.source:ef(e.source,l,s)).catch(h=>{s.log.error("error while relaying streams dst -> src",h),i(h)}).finally(()=>{u=!0,c&&(a.removeEventListener("abort",f),a.clear())})})}function Ua(r){let e=r*BigInt(1e3),t=new Date().getTime();return Number(e-BigInt(t))}var xn=class{expires;bytes;constructor(e){e?.duration!=null&&e?.duration!==0&&(this.expires=Date.now()+e.duration*1e3),this.bytes=e?.data,this.bytes===0n&&(this.bytes=void 0),this.onData=this.onData.bind(this)}onData(e){this.bytes!=null&&(this.bytes-=BigInt(e.byteLength),this.bytes<0n&&(this.bytes=0n))}getLimits(){if(this.expires==null&&this.bytes==null)return;let e={};if(this.bytes!=null){let t=this;Object.defineProperty(e,"bytes",{get(){return t.bytes}})}if(this.expires!=null){let t=this;Object.defineProperty(e,"seconds",{get(){return Math.round(((t.expires??0)-Date.now())/1e3)}})}return e}},wi=te(H(Qu.matchers[0],P("p2p-circuit"))),xi=te(P("p2p-circuit"));function vi(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return t}var qt=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[t,n]of e.entries())this.map.set(t.toString(),{key:t,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return vi(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((t,n)=>{e(t.value,t.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,t){this.map.set(e.toString(),{key:e,value:t})}keys(){return vi(this.map.values(),e=>e.key)}values(){return vi(this.map.values(),e=>e.value)}get size(){return this.map.size}};var Da={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},rf={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},nf=new globalThis.TextEncoder;function o0(r,e){let t=Da[e],n=rf[e];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(e,n*t);return n}function a0(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Da[e],s=rf[e],i=r;for(;i.length>0;){let o=nf.encodeInto(i,t);i=i.slice(o.read);for(let a=0;a<o.written;a++)s^=BigInt(t[a]),s=BigInt.asUintN(e,s*n)}return s}function Oa(r,{size:e=32,utf8Buffer:t}={}){if(!Da[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return a0(r,e,t);r=nf.encode(r)}return o0(r,e)}var vn={hash:r=>Number(Oa(r,{size:32})),hashV:(r,e)=>c0(vn.hash(r,e))};function c0(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),z(e,"base16")}var Ma=64,tt=class{fp;h;seed;constructor(e,t,n,s=2){if(s>Ma)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),o=oe(s);for(let a=0;a<o.length;a++)o[a]=i[a];o.length===0&&(o[0]=7),this.fp=o,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?me(this.fp,e.fp):!1}};function ir(r,e){return Math.floor(Math.random()*(e-r))+r}var or=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");let t=ir(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof tt))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var l0=500,En=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??vn,this.seed=e.seed??ir(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=z(e));let t=new tt(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new or(this.bucketSize)),this.buckets[s]==null&&(this.buckets[s]=new or(this.bucketSize)),this.buckets[n].add(t)||this.buckets[s].add(t))return this.count++,!0;let i=[n,s],o=i[ir(0,i.length-1)];this.buckets[o]==null&&(this.buckets[o]=new or(this.bucketSize));for(let a=0;a<l0;a++){let c=this.buckets[o].swap(t);if(c!=null&&(o=(o^c.hash())%this.filterSize,this.buckets[o]==null&&(this.buckets[o]=new or(this.bucketSize)),this.buckets[o].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=z(e));let t=new tt(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.has(t)??!1;if(s)return s;let i=(n^t.hash())%this.filterSize;return this.buckets[i]?.has(t)??!1}remove(e){typeof e=="string"&&(e=z(e));let t=new tt(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.remove(t)??!1;if(s)return this.count--,s;let i=(n^t.hash())%this.filterSize,o=this.buckets[i]?.remove(t)??!1;return o&&this.count--,o}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},u0={1:.5,2:.84,4:.95,8:.98};function f0(r=.001){return r>.002?2:r>1e-5?4:8}function sf(r,e=.001){let t=f0(e),n=u0[t],s=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Ma);return{filterSize:s,bucketSize:t,fingerprintSize:i}}var Ei=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??vn,this.seed=e.seed??ir(0,Math.pow(2,10)),this.filterSeries=[new En({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=z(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new En({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=z(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=z(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function Lr(r,e=.001,t){return new Ei({...sf(r,e),...t??{}})}var Si=class{filter;constructor(e,t){this.filter=Lr(e,t)}has(e){return this.filter.has(e.toMultihash().bytes)}add(e){this.filter.add(e.toMultihash().bytes)}remove(e){this.filter.remove?.(e.toMultihash().bytes)}};function Pa(r,e=.001){return new Si(r,e)}var Va=class extends qt{metric;constructor(e){super();let{name:t,metrics:n}=e;this.metric=n.registerMetric(t),this.updateComponentMetric()}set(e,t){return super.set(e,t),this.updateComponentMetric(),this}delete(e){let t=super.delete(e);return this.updateComponentMetric(),t}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Ha(r){let{name:e,metrics:t}=r,n;return t!=null?n=new Va({name:e,metrics:t}):n=new qt,n}var Fa=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};function of(r,e){let t=new Fa(e?.errorMessage,e?.errorCode,e?.errorName),n=new AbortController,s=()=>{n.abort(t)},i=AbortSignal.timeout(r);i.addEventListener("abort",s);let o=n.signal;return o.reset=a=>{i?.removeEventListener("abort",s),i=AbortSignal.timeout(a??r),i.addEventListener("abort",()=>{n.abort(t)})},o.clear=()=>{i?.removeEventListener("abort",s),i=void 0},o}var Ai=class{reservations;maxReservations;applyDefaultLimit;reservationTtl;defaultDurationLimit;defaultDataLimit;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:circuit-relay:server:reservation-store"),this.maxReservations=t.maxReservations??Pu,this.applyDefaultLimit=t.applyDefaultLimit!==!1,this.reservationTtl=t.reservationTtl??Vu,this.defaultDurationLimit=t.defaultDurationLimit??Ku,this.defaultDataLimit=t.defaultDataLimit??qu,this.reservations=Ha({metrics:e.metrics,name:"libp2p_circuit_relay_server_reservations_total"})}reserve(e,t,n){let s=this.reservations.get(e);if(this.reservations.size>=this.maxReservations&&s==null)return{status:V.RESERVATION_REFUSED};let i=new Date(Date.now()+this.reservationTtl),o;return this.applyDefaultLimit&&(o=n??{data:this.defaultDataLimit,duration:this.defaultDurationLimit}),s!=null?(this.log("refreshing reservation for client %p",e),s.signal.reset(this.reservationTtl)):(this.log("creating new reservation for client %p",e),s={addr:t,expiry:i,limit:o,signal:of(this.reservationTtl)}),this.reservations.set(e,s),s.signal.addEventListener("abort",()=>{this.reservations.delete(e)}),{status:V.OK,expire:Math.round(i.getTime()/1e3)}}removeReservation(e){this.reservations.delete(e)}get(e){return this.reservations.get(e)}clear(){this.reservations.clear()}};var Bi=class r{domain="libp2p-relay-rsvp";codec=new Uint8Array([3,2]);relay;peer;expiration;constructor({relay:e,peer:t,expiration:n}){this.relay=e,this.peer=t,this.expiration=n}marshal(){return Nr.encode({relay:this.relay.toMultihash().bytes,peer:this.peer.toMultihash().bytes,expiration:BigInt(this.expiration)})}equals(e){return!(!(e instanceof r)||!this.peer.equals(e.peer)||!this.relay.equals(e.relay)||this.expiration!==e.expiration)}};var af=r=>r.protoCodes().includes(ii),h0={maxOutboundStopStreams:pn},Ka=class extends Ke{registrar;peerStore;addressManager;peerId;privateKey;connectionManager;connectionGater;reservationStore;started;hopTimeout;shutdownController;maxInboundHopStreams;maxOutboundHopStreams;maxOutboundStopStreams;log;constructor(e,t={}){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:server"),this.registrar=e.registrar,this.peerStore=e.peerStore,this.addressManager=e.addressManager,this.peerId=e.peerId,this.privateKey=e.privateKey,this.connectionManager=e.connectionManager,this.connectionGater=e.connectionGater,this.started=!1,this.hopTimeout=t?.hopTimeout??zu,this.maxInboundHopStreams=t.maxInboundHopStreams,this.maxOutboundHopStreams=t.maxOutboundHopStreams,this.maxOutboundStopStreams=t.maxOutboundStopStreams??h0.maxOutboundStopStreams,this.reservationStore=new Ai(e,t.reservations),this.shutdownController=new AbortController,this.shutdownController.signal}[Symbol.toStringTag]="@libp2p/circuit-relay-v2-server";isStarted(){return this.started}async start(){this.started||(await this.registrar.handle(Ge,e=>{this.onHop(e).catch(t=>{this.log.error(t)})},{maxInboundStreams:this.maxInboundHopStreams,maxOutboundStreams:this.maxOutboundHopStreams,runOnLimitedConnection:!0}),this.started=!0)}async stop(){this.reservationStore.clear(),this.shutdownController.abort(),await this.registrar.unhandle(Ge),this.started=!1}async onHop({connection:e,stream:t}){this.log("received circuit v2 hop protocol stream from %p",e.remotePeer);let n={signal:AbortSignal.timeout(this.hopTimeout)},s=Kt(t);try{let i=await s.pb(j).read(n);if(i?.type==null)throw new Error("request was invalid, could not read from stream");this.log("received",i.type),await this.handleHopProtocol({connection:e,stream:s,request:i},n)}catch(i){this.log.error("error while handling hop",i),await s.pb(j).write({type:j.Type.STATUS,status:V.MALFORMED_MESSAGE},n),t.abort(i)}}async handleHopProtocol({stream:e,request:t,connection:n},s){switch(this.log("received hop message"),t.type){case j.Type.RESERVE:await this.handleReserve({stream:e,request:t,connection:n},s);break;case j.Type.CONNECT:await this.handleConnect({stream:e,request:t,connection:n},s);break;default:this.log.error("invalid hop request type %s via peer %p",t.type,n.remotePeer),await e.pb(j).write({type:j.Type.STATUS,status:V.UNEXPECTED_MESSAGE})}}async handleReserve({stream:e,connection:t},n){let s=e.pb(j);if(this.log("hop reserve request from %p",t.remotePeer),af(t.remoteAddr)){this.log.error("relay reservation over circuit connection denied for peer: %p",t.remotePeer),await s.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},n);return}if(await this.connectionGater.denyInboundRelayReservation?.(t.remotePeer)===!0){this.log.error("reservation for %p denied by connection gater",t.remotePeer),await s.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},n);return}let i=this.reservationStore.reserve(t.remotePeer,t.remoteAddr);try{if(i.status!==V.OK){await s.write({type:j.Type.STATUS,status:i.status},n);return}if(i.expire!=null){let o=i.expire*1e3-Date.now();await this.peerStore.merge(t.remotePeer,{tags:{[_a]:{value:1,ttl:o},[Ia]:{value:1,ttl:o}}})}await s.write({type:j.Type.STATUS,status:V.OK,reservation:await this.makeReservation(t.remotePeer,BigInt(i.expire??0)),limit:this.reservationStore.get(t.remotePeer)?.limit},n),this.log("sent confirmation response to %s",t.remotePeer)}catch(o){this.log.error("failed to send confirmation response to %p - %e",t.remotePeer,o),this.reservationStore.removeReservation(t.remotePeer);try{await this.peerStore.merge(t.remotePeer,{tags:{[_a]:void 0,[Ia]:void 0}})}catch(a){this.log.error("failed to untag relay source peer %p - %e",t.remotePeer,a)}}}async makeReservation(e,t){let n=[];for(let i of this.addressManager.getAddresses())i.toString().includes("/p2p-circuit")||n.push(i.bytes);let s=await hn.seal(new Bi({peer:e,relay:this.peerId,expiration:t}),this.privateKey);return{addrs:n,expire:t,voucher:{publicKey:Dt(s.publicKey),payloadType:s.payloadType,payload:{peer:e.toMultihash().bytes,relay:this.peerId.toMultihash().bytes,expiration:t},signature:s.signature}}}async handleConnect({stream:e,request:t,connection:n},s){let i=e.pb(j);if(af(n.remoteAddr)){this.log.error("relay reservation over circuit connection denied for peer: %p",n.remotePeer),await i.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},s);return}this.log("hop connect request from %p",n.remotePeer);let o;try{if(t.peer==null)throw this.log.error("no peer info in hop connect request"),new Error("no peer info in request");t.peer.addrs.forEach(_e),o=un(qe(t.peer.id))}catch(h){this.log.error("invalid hop connect request via peer %p %s",n.remotePeer,h),await i.write({type:j.Type.STATUS,status:V.MALFORMED_MESSAGE},s);return}let a=this.reservationStore.get(o);if(a==null){this.log.error("hop connect denied for destination peer %p not having a reservation for %p with status %s",o,n.remotePeer,V.NO_RESERVATION),await i.write({type:j.Type.STATUS,status:V.NO_RESERVATION},s);return}if(await this.connectionGater.denyOutboundRelayedConnection?.(n.remotePeer,o)===!0){this.log.error("hop connect for %p to %p denied by connection gater",n.remotePeer,o),await i.write({type:j.Type.STATUS,status:V.PERMISSION_DENIED},s);return}let c=this.connectionManager.getConnections(o);if(c.length===0){this.log("hop connect denied for destination peer %p not having a connection for %p as there is no destination connection",o,n.remotePeer),await i.write({type:j.Type.STATUS,status:V.NO_RESERVATION},s);return}let u=c[0],l=await this.stopHop({connection:u,request:{type:Fe.Type.CONNECT,peer:{id:n.remotePeer.toMultihash().bytes,addrs:[]},limit:a?.limit}},s);if(l==null){this.log.error("failed to open stream to destination peer %p",u?.remotePeer),await i.write({type:j.Type.STATUS,status:V.CONNECTION_FAILED},s);return}await i.write({type:j.Type.STATUS,status:V.OK,limit:a?.limit},s);let f=e.unwrap();this.log("connection from %p to %p established - merging streams",n.remotePeer,o),tf(f,l,this.shutdownController.signal,a,{log:this.log})}async stopHop({connection:e,request:t},n){this.log("starting circuit relay v2 stop request to %s",e.remotePeer);let s=await e.newStream([nr],{maxOutboundStreams:this.maxOutboundStopStreams,runOnLimitedConnection:!0,...n}),i=Kt(s),o=i.pb(Fe);await o.write(t,n);let a;try{a=await o.read(n)}catch{this.log.error("error parsing stop message response from %p",e.remotePeer)}if(a==null){this.log.error("could not read response from %p",e.remotePeer),await s.close(n);return}if(a.status===V.OK)return this.log("stop request to %p was successful",e.remotePeer),i.unwrap();this.log("stop request failed with code %d",a.status),await s.close(n)}get reservations(){return this.reservationStore.reservations}};function cf(r={}){return e=>new Ka(e,r)}function d0(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var lf=d0;function p0(r){return r[Symbol.asyncIterator]!=null}function uf(r){return r?.then!=null}function m0(r,e){let t=0;if(p0(r))return async function*(){for await(let c of r){let u=e(c,t++);uf(u)&&await u,yield c}}();let n=lf(r),{value:s,done:i}=n.next();if(i===!0)return function*(){}();if(typeof e(s,t++)?.then=="function")return async function*(){yield s;for await(let c of n){let u=e(c,t++);uf(u)&&await u,yield c}}();let a=e;return function*(){yield s;for(let c of n)a(c,t++),yield c}()}var ff=m0;var Ii=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ur=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ii(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Ii(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var qa=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Dr(r={}){return g0(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function g0(r,e){e=e??{};let t=e.onEnd,n=new Ur,s,i,o,a=et(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((d,x)=>{i=E=>{i=null,n.push(E);try{d(r(n))}catch(g){x(g)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=et()})}},u=d=>i!=null?i(d):(n.push(d),s),l=d=>(n=new Ur,i!=null?i({error:d}):(n.push({error:d}),s)),f=d=>{if(o)return s;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},h=d=>o?s:(o=!0,d!=null?l(d):u({done:!0})),p=()=>(n=new Ur,h(),{done:!0}),y=d=>(h(d),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:y,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let x=d?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,g;x!=null&&(E=new Promise((_,N)=>{g=()=>{N(new qa)},x.addEventListener("abort",g)}));try{await Promise.race([a.promise,E])}finally{g!=null&&x!=null&&x?.removeEventListener("abort",g)}}},t==null)return s;let b=s;return s={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(d){return b.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return b.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return b.end(d),t!=null&&(t(d),t=void 0),s},get readableLength(){return b.readableLength},onEmpty:d=>b.onEmpty(d)},s}function y0(r){return r[Symbol.asyncIterator]!=null}function b0(...r){let e=[];for(let t of r)y0(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Dr({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)t.push(s)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var hf=b0;function df(r,...e){if(r==null)throw new Error("Empty pipeline");if(za(r)){let n=r;r=()=>n.source}else if(mf(r)||pf(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&za(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)za(t[n])&&(t[n]=x0(t[n]));return w0(...t)}var w0=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},pf=r=>r?.[Symbol.asyncIterator]!=null,mf=r=>r?.[Symbol.iterator]!=null,za=r=>r==null?!1:r.sink!=null&&r.source!=null,x0=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Dr({objectMode:!0});t.then(()=>{n.end()},o=>{n.end(o)});let s,i=r.source;if(pf(i))s=async function*(){yield*i,n.end()};else if(mf(i))s=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return hf(n,s())}return r.source};function $a(r){let{stream:e,remoteAddr:t,logger:n,onDataRead:s,onDataWrite:i}=r,o=n.forComponent("libp2p:stream:converter"),a=!1,c=!1,u=e.close.bind(e);e.close=async y=>{await u(y),p(!0)};let l=e.abort.bind(e);e.abort=y=>{l(y),p(!0)};let f=e.sink.bind(e);e.sink=async y=>{try{await f(df(y,b=>ff(b,d=>i?.(d))))}catch(b){b.type!=="aborted"&&o.error("%s error in sink",t,b)}finally{c=!0,p()}};let h={log:o,sink:e.sink,source:async function*(){try{for await(let y of e.source)s?.(y),yield y}finally{a=!0,p()}}(),remoteAddr:t,timeline:{open:Date.now(),close:void 0},close:e.close,abort:e.abort};function p(y){y===!0&&(a=!0,c=!0),a&&c&&h.timeline.close==null&&(h.timeline.close=Date.now())}return h}var zt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Ga=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Ti(r,e,t,n){let s=new Ga(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(s):new Promise((i,o)=>{function a(){t?.removeEventListener("abort",l),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),o(h);return}a(),i(f)},u=f=>{a(),o(f.detail)},l=()=>{a(),o(s)};t?.addEventListener("abort",l),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var ki=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Ci=class{deferred;signal;constructor(e){this.signal=e,this.deferred=et(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new ut)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function v0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ni=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=v0(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new ut),this.cleanup())}async join(e={}){let t=new Ci(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await ei(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Ri=class extends Ke{concurrency;maxSize;queue;pending;sort;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new ki;let n=new Ni(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("error",{detail:s}),this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new ut)}),this.clear()}async onEmpty(e){this.size!==0&&await Ti(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Ti(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ti(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Dr({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},s=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail)},o=()=>{n()},a=()=>{n(new ut("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("error",i),this.addEventListener("idle",o),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",s),this.removeEventListener("error",i),this.removeEventListener("idle",o),e?.signal?.removeEventListener("abort",a),n()}}};var Or=class extends Ri{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};var Li=class extends Ke{peerStore;registrar;connectionManager;randomWalk;started;running;topologyId;log;discoveryController;filter;queue;constructor(e,t={}){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:discover-relays"),this.started=!1,this.running=!1,this.peerStore=e.peerStore,this.registrar=e.registrar,this.connectionManager=e.connectionManager,this.randomWalk=e.randomWalk,this.filter=t.filter,this.discoveryController=new AbortController,this.discoveryController.signal}isStarted(){return this.started}async start(){this.topologyId=await this.registrar.register(Ge,{filter:this.filter,onConnect:e=>{this.log.trace("discovered relay %p queue (length: %d, active %d)",e,this.queue?.size,this.queue?.running),this.safeDispatchEvent("relay:discover",{detail:e})}}),this.started=!0}stop(){this.topologyId!=null&&this.registrar.unregister(this.topologyId),this.discoveryController?.abort(),this.started=!1}startDiscovery(){this.running||(this.log("start discovery"),this.running=!0,this.discoveryController=new AbortController,this.discoveryController.signal,Promise.resolve().then(async()=>{this.log("searching peer store for relays");let e=await this.peerStore.all({filters:[n=>n.protocols.includes(Ge)],orders:[()=>Math.random()<.5?1:-1,(n,s)=>{let i=gf(n),o=gf(s);return i>o?-1:o>i?1:0}]});for(let n of e)this.log.trace("found relay peer %p in peer store",n.id),this.safeDispatchEvent("relay:discover",{detail:n.id});this.log("found %d relay peers in peer store",e.length);let t=this.queue=new Or({concurrency:5});this.log("start random walk");for await(let n of this.randomWalk.walk({signal:this.discoveryController.signal})){if(this.log.trace("found random peer %p",n.id),t.has(n.id)){this.log.trace("random peer %p was already in queue",n.id);continue}if(this.connectionManager.getConnections(n.id)?.length>0){this.log.trace("random peer %p was already connected",n.id);continue}if(!await this.connectionManager.isDialable(n.multiaddrs)){this.log.trace("random peer %p was not dialable",n.id,n.multiaddrs.map(s=>s.toString()));continue}t.queued>10&&(this.log.trace("wait for space in queue for %p",n.id),await t.onSizeLessThan(10,{signal:this.discoveryController.signal})),this.log("adding random peer %p to dial queue (length: %d, active %d)",n.id,t.size,t.running),t.add(async()=>{let s=mi([this.discoveryController.signal,AbortSignal.timeout(5e3)]);try{await this.connectionManager.openConnection(n.id,{signal:s})}finally{s.clear()}},{peerId:n.id,signal:this.discoveryController.signal}).catch(s=>{this.log.error("error opening connection to random peer %p",n.id,s)})}this.log("stop random walk"),await t.onIdle()}).catch(e=>{this.discoveryController.signal.aborted||this.log.error("failed when finding relays on the network",e)}))}stopDiscovery(){this.log("stop discovery"),this.running=!1,this.discoveryController?.abort()}};function gf(r){let e=r.metadata.get("last-dial-success");return e==null?0:new Date(ae(e)).getTime()}var Wa=class extends Ke{connectionManager;addressManager;reservationStore;listeningAddrs;log;listenTimeout;reservationId;relay;constructor(e,t={}){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:transport:listener"),this.connectionManager=e.connectionManager,this.addressManager=e.addressManager,this.reservationStore=e.reservationStore,this.listeningAddrs=[],this.listenTimeout=t.listenTimeout??oi,this.reservationStore.addEventListener("relay:removed",this._onRemoveRelayPeer),this.reservationStore.addEventListener("relay:created-reservation",this._onAddRelayPeer)}_onRemoveRelayPeer=e=>{this.log("relay removed %p our relay %p",e.detail.relay,this.relay,this.relay?.equals(e.detail.relay)),this.relay?.equals(e.detail.relay)===!0&&(this.log("relay peer removed %p",e.detail.relay),this.listeningAddrs.forEach(t=>{this.addressManager.removeObservedAddr(t)}),this.listeningAddrs=[],this.safeDispatchEvent("listening"))};_onAddRelayPeer=e=>{let{details:t}=e.detail;t.type!=="configured"&&t.id===this.reservationId&&this.addedRelay(e.detail)};async listen(e){if(xi.exactMatch(e))this.log("searching for circuit relay servers"),this.reservationId=this.reservationStore.reserveRelay();else if(wi.exactMatch(e)){this.log("listen on specific relay server %a",e);let t=AbortSignal.timeout(this.listenTimeout);let n=e.decapsulate("/p2p-circuit"),s=await this.connectionManager.openConnection(n,{signal:t});if(!this.reservationStore.hasReservation(s.remotePeer)){this.log("making reservation on peer %p",s.remotePeer);let i=await this.reservationStore.addRelay(s.remotePeer,"configured");this.addedRelay(i)}}else throw new $t(`Could not listen on p2p-circuit address "${e}"`)}getAddrs(){return[...this.listeningAddrs.values()].flat()}updateAnnounceAddrs(){}async close(){this.reservationStore.cancelReservations(),this.listeningAddrs=[],this.reservationStore.removeEventListener("relay:removed",this._onRemoveRelayPeer),queueMicrotask(()=>{this.safeDispatchEvent("close")})}addedRelay(e){this.log("relay peer added %p",e.relay),this.relay=e.relay,this.listeningAddrs=e.details.reservation.addrs.map(t=>_e(t).encapsulate("/p2p-circuit")),this.listeningAddrs.forEach(t=>{this.addressManager.confirmObservedAddr(t,{type:"transport"})}),queueMicrotask(()=>{this.safeDispatchEvent("listening")})}};function yf(r){return new Wa(r)}var bf="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var wf=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)e+=bf[t[r]&63];return e};var E0=60*1e3*10,S0=60*1e3*5,A0=30*1e3,Ui=class extends Ke{peerId;connectionManager;peerStore;events;reserveQueue;reservations;pendingReservations;maxReservationQueueLength;reservationCompletionTimeout;started;log;relayFilter;constructor(e,t){super(),this.log=e.logger.forComponent("libp2p:circuit-relay:transport:reservation-store"),this.peerId=e.peerId,this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.events=e.events,this.reservations=new qt,this.pendingReservations=[],this.maxReservationQueueLength=t?.maxReservationQueueLength??Fu,this.reservationCompletionTimeout=t?.reservationCompletionTimeout??oi,this.started=!1,this.relayFilter=Lr(100),this.reserveQueue=new Or({concurrency:t?.reservationConcurrency??Hu,metricName:"libp2p_relay_reservation_queue",metrics:e.metrics}),this.events.addEventListener("connection:close",n=>{[...this.reservations.values()].find(i=>i.connection===n.detail.id)!=null&&this.#t(n.detail.remotePeer).catch(i=>{this.log("could not remove relay %p - %e",n.detail,i)})})}isStarted(){return this.started}start(){this.started=!0}afterStart(){Promise.resolve().then(async()=>{let e=await this.peerStore.all({filters:[t=>t.tags.has(dn)]});this.log("removing tag from %d old relays",e.length),await Promise.all(e.map(async t=>{await this.peerStore.merge(t.id,{tags:{[dn]:void 0}})})),this.log("redialing %d old relays",e.length),await Promise.all(e.map(async t=>this.addRelay(t.id,"discovered"))),this.#r()}).catch(e=>{this.log.error(e)})}stop(){this.reserveQueue.clear(),this.reservations.forEach(({timeout:e})=>{clearTimeout(e)}),this.reservations.clear(),this.started=!1}reserveRelay(){let e=wf();return this.pendingReservations.push(e),this.#r(),e}async addRelay(e,t){if(this.peerId.equals(e))throw this.log.trace("not trying to use self as relay"),new $t("Cannot use self as relay");if(this.reserveQueue.size>this.maxReservationQueueLength)throw new bi("The reservation queue is full");let n=this.reserveQueue.find(e);if(n!=null)return this.log.trace("potential relay peer %p is already in the reservation queue",e),n.join();if(this.relayFilter.has(e.toMultihash().bytes))throw new $t("The relay was previously invalid");return this.log.trace("try to reserve relay slot with %p",e),this.reserveQueue.add(async()=>{let s=Date.now();try{let i=this.reservations.get(e);if(i!=null){let y=this.connectionManager.getConnections(e),b=!1;if(y.length===0&&this.log("already have relay reservation with %p but we are no longer connected",e),y.map(d=>d.id).includes(i.connection)&&(this.log("already have relay reservation with %p and the original connection is still open",e),b=!0),b&&Ua(i.reservation.expire)>E0)return this.log("already have relay reservation with %p but we are still connected and it does not expire soon",e),{relay:e,details:i};await this.#t(e)}if(t==="discovered"&&this.pendingReservations.length===0)throw new wn("Not making reservation on discovered relay because we do not need any more relays");let o=AbortSignal.timeout(this.reservationCompletionTimeout);let a=await this.connectionManager.openConnection(e,{signal:o});if(pi.matches(a.remoteAddr))throw new yi("not creating reservation over relayed connection");let c=await this.#e(a,{signal:o}),u=Ua(c.expire);this.log("created reservation on relay peer %p, expiry date is %s",e,new Date(Date.now()+u).toString());let l=Math.min(Math.max(u-S0,A0),Math.pow(2,31)-1),f=setTimeout(()=>{this.log("refresh reservation to relay %p",e),this.addRelay(e,t).catch(async y=>{this.log.error("could not refresh reservation to relay %p - %e",e,y),await this.#t(e)}).catch(y=>{this.log.error("could not remove expired reservation to relay %p - %e",e,y)})},l),h;if(t==="discovered"){let y=this.pendingReservations.pop();if(y==null)throw new wn("Made reservation on relay but did not need any more discovered relays");h={timeout:f,reservation:c,type:t,connection:a.id,id:y}}else h={timeout:f,reservation:c,type:t,connection:a.id};this.reservations.set(e,h),await this.peerStore.merge(e,{tags:{[dn]:{value:1,ttl:u}}}),this.#r();let p={relay:e,details:h};return this.safeDispatchEvent("relay:created-reservation",{detail:p}),p}catch(i){throw t==="discovered"&&i.name==="HadEnoughRelaysError"||this.log.error("could not reserve slot on %p after %dms - %e",e,Date.now()-s,i),(i.name==="DialError"||i.name==="UnsupportedProtocolError")&&this.relayFilter.add(e.toMultihash().bytes),this.#t(e).catch(o=>{this.log.error("could not remove reservation on %p after reserving slot failed - %e",e,o)}),i}},{peerId:e})}hasReservation(e){return this.reservations.has(e)}getReservation(e){return this.reservations.get(e)?.reservation}reservationCount(e){return e==null?this.reservations.size:[...this.reservations.values()].reduce((t,n)=>(n.type===e&&t++,t),0)}cancelReservations(){[...this.reservations.values()].forEach(e=>{clearTimeout(e.timeout)}),this.reservations.clear()}async#e(e,t){t.signal?.throwIfAborted(),this.log("requesting reservation from %p",e.remotePeer);let n=await e.newStream(Ge,t),i=Kt(n).pb(j);this.log.trace("send RESERVE to %p",e.remotePeer),await i.write({type:j.Type.RESERVE},t);let o;try{this.log.trace("reading response from %p",e.remotePeer),o=await i.read(t)}catch(c){throw n.abort(c),c}finally{n.status!=="closed"&&await n.close(t)}if(this.log.trace("read response %o",o),o.status===V.OK&&o.reservation!=null){let c=new Set;c.add(e.remoteAddr.toString());for(let u of o.reservation.addrs){let l=_e(u);l.getPeerId()==null&&(l=l.encapsulate(`/p2p/${e.remotePeer}`)),l=_e(l.toString().replace(`/p2p/${e.remotePeer}/p2p/${e.remotePeer}`,`/p2p/${e.remotePeer}`)),c.add(l.toString())}return o.reservation.addrs=[...c].map(u=>_e(u).bytes),o.reservation}let a=`reservation failed with status ${o.status??"undefined"}`;throw this.log.error(a),new Error(a)}async#t(e){let t=this.reservations.get(e);t!=null&&(this.log("removing relay reservation with %p from local store",e),clearTimeout(t.timeout),this.reservations.delete(e),t.type==="discovered"&&this.pendingReservations.push(t.id),await this.peerStore.merge(e,{tags:{[dn]:void 0}}),this.safeDispatchEvent("relay:removed",{detail:{relay:e,details:t}}),this.#r())}#r(){if(this.pendingReservations.length===0){this.log.trace("have discovered enough relays"),this.reserveQueue.clear(),this.safeDispatchEvent("relay:found-enough-relays");return}this.relayFilter=Lr(100),this.log("not discovered enough relays %d/%d",this.reservations.size,this.pendingReservations.length),this.safeDispatchEvent("relay:not-enough-relays")}};var B0=r=>{if(r.peer==null)return!1;try{r.peer.addrs.forEach(_e)}catch{return!1}return!0},xf={maxInboundStopStreams:pn,maxOutboundStopStreams:pn,stopTimeout:3e4},Di=class{discovery;registrar;peerStore;connectionManager;transportManager;peerId;upgrader;addressManager;connectionGater;reservationStore;logger;maxInboundStopStreams;maxOutboundStopStreams;started;log;shutdownController;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:circuit-relay:transport"),this.registrar=e.registrar,this.peerStore=e.peerStore,this.connectionManager=e.connectionManager,this.transportManager=e.transportManager,this.logger=e.logger,this.peerId=e.peerId,this.upgrader=e.upgrader,this.addressManager=e.addressManager,this.connectionGater=e.connectionGater,this.maxInboundStopStreams=t.maxInboundStopStreams??xf.maxInboundStopStreams,this.maxOutboundStopStreams=t.maxOutboundStopStreams??xf.maxOutboundStopStreams,this.shutdownController=new AbortController,this.discovery=new Li(e,{filter:t.discoveryFilter??Pa($u,Gu)}),this.discovery.addEventListener("relay:discover",n=>{this.reservationStore.addRelay(n.detail,"discovered").catch(s=>{s.name!=="HadEnoughRelaysError"&&s.name!=="RelayQueueFullError"&&this.log.error("could not add discovered relay %p",n.detail,s)})}),this.reservationStore=new Ui(e,t),this.reservationStore.addEventListener("relay:not-enough-relays",()=>{this.discovery?.startDiscovery()}),this.reservationStore.addEventListener("relay:found-enough-relays",()=>{this.discovery?.stopDiscovery()}),this.started=!1}[Symbol.toStringTag]="@libp2p/circuit-relay-v2-transport";[ac]=["@libp2p/transport","@libp2p/circuit-relay-v2-transport"];get[cc](){return this.discovery!=null?["@libp2p/identify"]:[]}[nc]=!0;isStarted(){return this.started}async start(){this.shutdownController=new AbortController,await this.registrar.handle(nr,e=>{let t=this.upgrader.createInboundAbortSignal(this.shutdownController.signal);this.onStop(e,t).catch(n=>{this.log.error("error while handling STOP protocol",n),e.stream.abort(n)}).finally(()=>{t.clear()})},{maxInboundStreams:this.maxInboundStopStreams,maxOutboundStreams:this.maxOutboundStopStreams,runOnLimitedConnection:!0}),await ic(this.discovery,this.reservationStore),this.started=!0}async stop(){this.shutdownController.abort(),await oc(this.discovery,this.reservationStore),await this.registrar.unhandle(nr),this.started=!1}async dial(e,t){if(e.protoCodes().filter(p=>p===ii).length!==1){let p="Invalid circuit relay address";throw this.log.error(p,e),new Pr(p)}let n=e.toString().split("/p2p-circuit"),s=_e(n[0]),i=_e(n[n.length-1]),o=s.getPeerId(),a=i.getPeerId();if(o==null||a==null){let p=`ircuit relay dial to ${e.toString()} failed as address did not have both relay and destination PeerIDs`;throw this.log.error(`c${p}`),new Pr(`C${p}`)}let c=aa(o),u=aa(a),f=this.connectionManager.getConnections(c)[0];f==null?(await this.peerStore.merge(c,{multiaddrs:[s]}),t.onProgress?.(new zt("circuit-relay:open-connection")),f=await this.connectionManager.openConnection(c,t)):t.onProgress?.(new zt("circuit-relay:reuse-connection"));let h;try{t.onProgress?.(new zt("circuit-relay:open-hop-stream")),h=await f.newStream(Ge,t);let p=Kt(h),y=p.pb(j);t.onProgress?.(new zt("circuit-relay:write-connect-message")),await y.write({type:j.Type.CONNECT,peer:{id:u.toMultihash().bytes,addrs:[_e(i).bytes]}},t),t.onProgress?.(new zt("circuit-relay:read-connect-response"));let b=await y.read(t);if(b.status!==V.OK)throw new Bn(`failed to connect via relay with status ${b?.status?.toString()??"undefined"}`);let d=new xn(b.limit),x=$a({stream:p.unwrap(),remoteAddr:e,localAddr:s.encapsulate(`/p2p-circuit/p2p/${this.peerId.toString()}`),logger:this.logger,onDataRead:d.onData,onDataWrite:d.onData});return this.log("new outbound relayed connection %a",x.remoteAddr),await this.upgrader.upgradeOutbound(x,{...t,limits:d.getLimits()})}catch(p){throw this.log.error("circuit relay dial to destination %p via relay %p failed",u,c,p),h?.abort(p),p}}createListener(e){return yf({peerId:this.peerId,connectionManager:this.connectionManager,addressManager:this.addressManager,reservationStore:this.reservationStore,logger:this.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>wi.exactMatch(t)||xi.exactMatch(t))}dialFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>pi.exactMatch(t))}async onStop({connection:e,stream:t},n){if(!this.reservationStore.hasReservation(e.remotePeer))try{this.log("dialed via relay we did not have a reservation on, start listening on that relay address"),await this.transportManager.listen([e.remoteAddr.encapsulate("/p2p-circuit")])}catch(f){this.log.error("failed to listen on a relay peer we were dialed via but did not have a reservation on",f)}let s=Kt(t).pb(Fe),i=await s.read({signal:n});if(this.log("new circuit relay v2 stop stream from %p with type %s",e.remotePeer,i.type),i?.type===void 0){this.log.error("type was missing from circuit v2 stop protocol request from %s",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.MALFORMED_MESSAGE},{signal:n}),await t.close();return}if(i.type!==Fe.Type.CONNECT){this.log.error("invalid stop connect request via peer %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.UNEXPECTED_MESSAGE},{signal:n}),await t.close();return}if(!B0(i)){this.log.error("invalid stop connect request via peer %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.MALFORMED_MESSAGE},{signal:n}),await t.close({signal:n});return}let o=un(qe(i.peer.id));if(await this.connectionGater.denyInboundRelayedConnection?.(e.remotePeer,o)===!0){this.log.error("connection gater denied inbound relayed connection from %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.PERMISSION_DENIED},{signal:n}),await t.close({signal:n});return}this.log.trace("sending success response to %p",e.remotePeer),await s.write({type:Fe.Type.STATUS,status:V.OK},{signal:n});let a=new xn(i.limit),c=e.remoteAddr.encapsulate(`/p2p-circuit/p2p/${o.toString()}`),u=this.addressManager.getAddresses()[0],l=$a({stream:s.unwrap().unwrap(),remoteAddr:c,localAddr:u,logger:this.logger,onDataRead:a.onData,onDataWrite:a.onData});this.log("new inbound relayed connection %a",l.remoteAddr),await this.upgrader.upgradeInbound(l,{limits:a.getLimits(),signal:n}),this.log("%s connection %a upgraded","inbound",l.remoteAddr)}};function vf(r={}){return e=>new Di(e,r)}return Mf(_0);})();
7
7
  /*! Bundled license information:
8
8
 
9
9
  pvtsutils/build/index.js: