@libp2p/multistream-select 7.0.20 → 7.0.21

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,13 +1,13 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PMultistreamSelect = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PMultistreamSelect=(()=>{var ge=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Pt=Object.getOwnPropertyNames;var Rt=Object.prototype.hasOwnProperty;var y=(r,t)=>{for(var e in t)ge(r,e,{get:t[e],enumerable:!0})},Vt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pt(t))!Rt.call(r,o)&&o!==e&&ge(r,o,{get:()=>t[o],enumerable:!(n=Ft(t,o))||n.enumerable});return r};var _t=r=>Vt(ge({},"__esModule",{value:!0}),r);var dn={};y(dn,{PROTOCOL_ID:()=>S,handle:()=>Mt,select:()=>Ot});var S="/multistream/1.0.0";var te=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var re=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},ne=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var ve={};y(ve,{base58btc:()=>N,base58flickr:()=>jt});var wn=new Uint8Array(0);function rt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function O(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function nt(r){return new TextEncoder().encode(r)}function ot(r){return new TextDecoder().decode(r)}function Bt(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var w=0,V=0,v=0,D=h.length;v!==D&&h[v]===0;)v++,w++;for(var T=(D-v)*l+1>>>0,E=new Uint8Array(T);v!==D;){for(var U=h[v],P=0,A=T-1;(U!==0||P<V)&&A!==-1;A--,P++)U+=256*E[A]>>>0,E[A]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");V=P,v++}for(var C=T-V;C!==T&&E[C]===0;)C++;for(var ee=c.repeat(w);C<T;++C)ee+=r.charAt(E[C]);return ee}function m(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var w=0;if(h[w]!==" "){for(var V=0,v=0;h[w]===c;)V++,w++;for(var D=(h.length-w)*u+1>>>0,T=new Uint8Array(D);h[w];){var E=e[h.charCodeAt(w)];if(E===255)return;for(var U=0,P=D-1;(E!==0||U<v)&&P!==-1;P--,U++)E+=a*T[P]>>>0,T[P]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");v=U,w++}if(h[w]!==" "){for(var A=D-v;A!==D&&T[A]===0;)A++;for(var C=new Uint8Array(V+(D-A)),ee=V;A!==D;)C[ee++]=T[A++];return C}}}function p(h){var w=m(h);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:m,decode:p}}var zt=Bt,kt=zt,it=kt;var ye=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},xe=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return at(this,t)}},Ee=class{decoders;constructor(t){this.decoders=t}or(t){return at(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function at(r,t){return new Ee({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Le=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new ye(t,e,n),this.decoder=new xe(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function z({name:r,prefix:t,encode:e,decode:n}){return new Le(r,t,e,n)}function R({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=it(e,r);return z({prefix:t,name:r,encode:n,decode:s=>O(o(s))})}function $t(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Gt(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ht(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function b({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ht(n);return z({prefix:t,name:r,encode(s){return Gt(s,n,e)},decode(s){return $t(s,o,e,r)}})}var N=R({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jt=R({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ae={};y(Ae,{base32:()=>k,base32hex:()=>Jt,base32hexpad:()=>Qt,base32hexpadupper:()=>Yt,base32hexupper:()=>Kt,base32pad:()=>Xt,base32padupper:()=>Wt,base32upper:()=>qt,base32z:()=>Zt});var k=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qt=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xt=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wt=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Jt=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kt=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qt=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yt=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zt=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Se={};y(Se,{base36:()=>X,base36upper:()=>er});var X=R({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),er=R({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var tr=lt,ct=128,rr=127,nr=~rr,or=Math.pow(2,31);function lt(r,t,e){t=t||[],e=e||0;for(var n=e;r>=or;)t[e++]=r&255|ct,r/=128;for(;r&nr;)t[e++]=r&255|ct,r>>>=7;return t[e]=r|0,lt.bytes=e-n+1,t}var sr=Ie,ir=128,ut=127;function Ie(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ie.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ut)<<o:(i&ut)*Math.pow(2,o),o+=7}while(i>=ir);return Ie.bytes=s-n,e}var ar=Math.pow(2,7),cr=Math.pow(2,14),ur=Math.pow(2,21),lr=Math.pow(2,28),fr=Math.pow(2,35),hr=Math.pow(2,42),dr=Math.pow(2,49),mr=Math.pow(2,56),pr=Math.pow(2,63),br=function(r){return r<ar?1:r<cr?2:r<ur?3:r<lr?4:r<fr?5:r<hr?6:r<dr?7:r<mr?8:r<pr?9:10},wr={encode:tr,decode:sr,encodingLength:br},gr=wr,W=gr;function J(r,t=0){return[W.decode(r,t),W.decode.bytes]}function $(r,t,e=0){return W.encode(r,t,e),t}function G(r){return W.encodingLength(r)}function j(r,t){let e=t.byteLength,n=G(r),o=n+G(e),s=new Uint8Array(o+e);return $(r,s,0),$(e,s,n),s.set(t,o),new H(r,e,t,s)}function ft(r){let t=O(r),[e,n]=J(t),[o,s]=J(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new H(e,o,i,t)}function ht(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&rt(r.bytes,e.bytes)}}var H=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function dt(r,t){let{bytes:e,version:n}=r;return n===0?xr(e,De(r),t??N.encoder):Er(e,De(r),t??k.encoder)}var mt=new WeakMap;function De(r){let t=mt.get(r);if(t==null){let e=new Map;return mt.set(r,e),e}return t}var se=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Q)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Lr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=j(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ht(t.multihash,n.multihash)}toString(t){return dt(this,t)}toJSON(){return{"/":dt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??pt(n,o,s.bytes))}else if(e[vr]===!0){let{version:n,multihash:o,code:s}=e,i=ft(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Q)throw new Error(`Version 0 CID must use dag-pb (code: ${Q}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=pt(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Q,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=O(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new H(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,m]=J(t.subarray(e));return e+=m,f},o=n(),s=Q;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=yr(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return De(s).set(n,t),s}};function yr(r,t){switch(r[0]){case"Q":{let e=t??N;return[N.prefix,e.decode(`${N.prefix}${r}`)]}case N.prefix:{let e=t??N;return[N.prefix,e.decode(r)]}case k.prefix:{let e=t??k;return[k.prefix,e.decode(r)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function xr(r,t,e){let{prefix:n}=e;if(n!==N.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Er(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Q=112,Lr=18;function pt(r,t,e){let n=G(r),o=n+G(t),s=new Uint8Array(o+e.byteLength);return $(r,s,0),$(t,s,n),s.set(e,o),s}var vr=Symbol.for("@ipld/js-cid/CID");var Te={};y(Te,{identity:()=>Ir});var bt=0,Ar="identity",wt=O;function Sr(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return j(bt,wt(r))}var Ir={code:bt,name:Ar,encode:wt,digest:Sr};function gt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function M(r=0){return new Uint8Array(r)}function I(r=0){return new Uint8Array(r)}function Ue(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=I(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var xt=Symbol.for("@achingbrain/uint8arraylist");function yt(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function ie(r){return!!r?.[xt]}var x=class r{bufs;length;[xt]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ie(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ie(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=yt(this.bufs,t);return e.buf[e.index]}set(t,e){let n=yt(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ie(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Ue(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ue(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ie(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let p=this.get(f+m);if(n[m]!==p){l=Math.max(1,m-a[p]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=I(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=M(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=M(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=M(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=I(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=M(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=M(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=M(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=M(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=M(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!gt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Ne={};y(Ne,{base10:()=>Dr});var Dr=R({prefix:"9",name:"base10",alphabet:"0123456789"});var Ce={};y(Ce,{base16:()=>Tr,base16upper:()=>Ur});var Tr=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ur=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Oe={};y(Oe,{base2:()=>Nr});var Nr=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Me={};y(Me,{base256emoji:()=>Pr});var Et=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}"),Cr=Et.reduce((r,t,e)=>(r[e]=t,r),[]),Or=Et.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Mr(r){return r.reduce((t,e)=>(t+=Cr[e],t),"")}function Fr(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Or[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Pr=z({prefix:"\u{1F680}",name:"base256emoji",encode:Mr,decode:Fr});var Fe={};y(Fe,{base64:()=>Rr,base64pad:()=>Vr,base64url:()=>_r,base64urlpad:()=>Br});var Rr=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vr=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_r=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Br=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pe={};y(Pe,{base8:()=>zr});var zr=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Re={};y(Re,{identity:()=>kr});var kr=z({prefix:"\0",name:"identity",encode:r=>ot(r),decode:r=>nt(r)});var eo=new TextEncoder,to=new TextDecoder;var Be={};y(Be,{sha256:()=>jr,sha512:()=>qr});var Hr=20;function _e({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Ve(r,t,e,n,o)}var Ve=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Hr,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Lt(n,this.code,e?.truncate):n.then(o=>Lt(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Lt(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return j(t,r)}function At(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var jr=_e({name:"sha2-256",code:18,encode:At("SHA-256")}),qr=_e({name:"sha2-512",code:19,encode:At("SHA-512")});var ze={...Re,...Oe,...Pe,...Ne,...Ce,...Ae,...Se,...ve,...Fe,...Me},mo={...Be,...Te};function It(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var St=It("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ke=It("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=I(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Xr={utf8:St,"utf-8":St,hex:ze.base16,latin1:ke,ascii:ke,binary:ke,...ze},ae=Xr;function L(r,t="utf8"){let e=ae[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Dt(r,t="utf8"){let e=ae[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Wr=Math.pow(2,7),Jr=Math.pow(2,14),Kr=Math.pow(2,21),$e=Math.pow(2,28),Ge=Math.pow(2,35),He=Math.pow(2,42),je=Math.pow(2,49),d=128,g=127;function F(r){if(r<Wr)return 1;if(r<Jr)return 2;if(r<Kr)return 3;if(r<$e)return 4;if(r<Ge)return 5;if(r<He)return 6;if(r<je)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qr(r,t,e=0){switch(F(r)){case 8:t[e++]=r&255|d,r/=128;case 7:t[e++]=r&255|d,r/=128;case 6:t[e++]=r&255|d,r/=128;case 5:t[e++]=r&255|d,r/=128;case 4:t[e++]=r&255|d,r>>>=7;case 3:t[e++]=r&255|d,r>>>=7;case 2:t[e++]=r&255|d,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Yr(r,t,e=0){switch(F(r)){case 8:t.set(e++,r&255|d),r/=128;case 7:t.set(e++,r&255|d),r/=128;case 6:t.set(e++,r&255|d),r/=128;case 5:t.set(e++,r&255|d),r/=128;case 4:t.set(e++,r&255|d),r>>>=7;case 3:t.set(e++,r&255|d),r>>>=7;case 2:t.set(e++,r&255|d),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Zr(r,t){let e=r[t],n=0;if(n+=e&g,e<d||(e=r[t+1],n+=(e&g)<<7,e<d)||(e=r[t+2],n+=(e&g)<<14,e<d)||(e=r[t+3],n+=(e&g)<<21,e<d)||(e=r[t+4],n+=(e&g)*$e,e<d)||(e=r[t+5],n+=(e&g)*Ge,e<d)||(e=r[t+6],n+=(e&g)*He,e<d)||(e=r[t+7],n+=(e&g)*je,e<d))return n;throw new RangeError("Could not decode varint")}function en(r,t){let e=r.get(t),n=0;if(n+=e&g,e<d||(e=r.get(t+1),n+=(e&g)<<7,e<d)||(e=r.get(t+2),n+=(e&g)<<14,e<d)||(e=r.get(t+3),n+=(e&g)<<21,e<d)||(e=r.get(t+4),n+=(e&g)*$e,e<d)||(e=r.get(t+5),n+=(e&g)*Ge,e<d)||(e=r.get(t+6),n+=(e&g)*He,e<d)||(e=r.get(t+7),n+=(e&g)*je,e<d))return n;throw new RangeError("Could not decode varint")}function ce(r,t,e=0){return t==null&&(t=I(F(r))),t instanceof Uint8Array?Qr(r,t,e):Yr(r,t,e)}function ue(r,t=0){return r instanceof Uint8Array?Zr(r,t):en(r,t)}var Xe=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Tt=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function We(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,l=new Promise((f,m)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){m(Tt(i));return}if(i&&(c=()=>{m(Tt(i))},i.addEventListener("abort",c,{once:!0})),r.then(f,m),e===Number.POSITIVE_INFINITY)return;let p=new Xe;a=s.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(h){m(h)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?m(o):(p.message=o??`Promise timed out after ${e} milliseconds`,m(p))},e)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var tn=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function rn(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=tn(r),f=async(...p)=>{let h=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(h))return}catch(w){n(),i(w);return}c.push(h),e.count===c.length&&(n(),s(c))},m=(...p)=>{n(),i(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)l(p,f);for(let p of e.rejectionEvents)a.includes(p)||l(p,m)};for(let p of a)u(p,f);for(let p of e.rejectionEvents)a.includes(p)||u(p,m);e.signal&&e.signal.addEventListener("abort",()=>{m(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=We(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Ut(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=rn(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var _=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function nn(r){return r.reason}async function Je(r,t,e){if(t==null)return r;let n=e?.translateError??nn;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var sn=4194304,le=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Qe=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ye=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ze=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function an(r){return typeof r?.closeRead=="function"}function cn(r){return typeof r?.close=="function"}function Ke(r){return an(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:cn(r)?r.status!=="open":!1}function un(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function ln(r,t){let e=t?.maxBufferSize??sn,n=new x,o,s=!1;if(!un(r))throw new te("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>e){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new le("Stream was unwrapped");if(Ke(r)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new _(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let f=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await Je(o.promise,l?.signal),Ke(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let m=l?.bytes??n.byteLength;if(n.byteLength<m){if(Ke(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,m),new _(`Unexpected EOF - stream closed while reading ${n.byteLength}/${m} bytes`);return u.read(l)}let p=n.sublist(0,m);return n.consume(m),p},async write(l,f){if(s===!0)throw new le("Stream was unwrapped");r.send(l)||await Ut(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return u}function fe(r,t={}){let e=ln(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=F(t.maxDataLength));let n=t?.lengthDecoder??ue,o=t?.lengthEncoder??ce;return{async read(i){let a=-1,c=new x;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Qe("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ze(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ye(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new _(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new _(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new x(o(i.byteLength),i),a)},async writeV(i,a){let c=new x(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}var he=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},q=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},de=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Y=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function me(r){return r[Symbol.asyncIterator]!=null}function Nt(r,t){if(r.byteLength>t)throw new q("Message length too long")}var be=r=>{let t=F(r),e=I(t);return ce(r,e),be.bytes=t,e};be.bytes=0;function we(r,t){t=t??{};let e=t.lengthEncoder??be,n=t?.maxDataLength??4194304;function*o(s){Nt(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return me(r)?(async function*(){for await(let s of r)yield*o(s)})():(function*(){for(let s of r)yield*o(s)})()}we.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??be,n=t?.maxDataLength??4194304;return Nt(r,n),new x(e(r.byteLength),r)};var B;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(B||(B={}));var tt=r=>{let t=ue(r);return tt.bytes=F(t),t};tt.bytes=0;function et(r,t){let e=new x,n=B.LENGTH,o=-1,s=t?.lengthDecoder??tt,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===B.LENGTH)try{if(o=s(e),o<0)throw new he("Invalid message length");if(o>a)throw new q("Message length too long");let u=s.bytes;e.consume(u),t?.onLength!=null&&t.onLength(o),n=B.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>i)throw new de("Message length length too long");break}throw u}if(n===B.DATA){if(e.byteLength<o)break;let u=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(u),yield u,n=B.LENGTH}}}return me(r)?(async function*(){for await(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new Y("Unexpected end of input")})():(function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new Y("Unexpected end of input")})()}et.fromReader=(r,t)=>{let e=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}})();return et(n,{...t??{},onLength:s=>{e=s}})};var hn=L(`
3
- `);async function Z(r,t){let n=(await r.read(t)).subarray();if(n.byteLength===0||n[n.length-1]!==hn[0])throw new ne("Missing newline");return Dt(n).trimEnd()}async function Ot(r,t,e={}){if(t=Array.isArray(t)?[...t]:[t],t.length===0)throw new Error("At least one protocol must be specified");let n=r.log.newScope("mss:select"),o=fe(r,{...e,maxDataLength:1024});for(let s=0;s<t.length;s++){let i=t[s],a;if(s===0){n.trace('write ["%s", "%s"]',S,i);let c=L(`${S}
4
- `),u=L(`${i}
5
- `);if(await o.writeV([c,u],e),n.trace("reading multistream-select header"),a=await Z(o,e),n.trace('read "%s"',a),a!==S){n.error("did not read multistream-select header from response");break}}else n.trace('write "%s"',i),await o.write(L(`${i}
6
- `),e);if(n.trace("reading protocol response"),a=await Z(o,e),n.trace('read "%s"',a),a===i)return n.trace('selected "%s" after negotiation',a),o.unwrap(),i}throw new re(`Protocol selection failed - could not negotiate ${t}`)}async function Mt(r,t,e={}){t=Array.isArray(t)?t:[t];let n=r.log.newScope("mss:handle"),o=fe(r,{...e,maxDataLength:1024,maxLengthLength:2});for(;;){n.trace("reading incoming string");let s=await Z(o,e);if(n.trace('read "%s"',s),s===S){n.trace('respond with "%s" for "%s"',S,s),await o.write(L(`${S}
7
- `),e),n.trace('responded with "%s" for "%s"',S,s);continue}if(t.includes(s))return n.trace('respond with "%s" for "%s"',s,s),await o.write(L(`${s}
8
- `),e),n.trace('responded with "%s" for "%s"',s,s),o.unwrap(),s;if(s==="ls"){let i=new x(...t.map(a=>we.single(L(`${a}
9
- `))),L(`
10
- `));n.trace('respond with "%s" for %s',t,s),await o.write(i,e),n.trace('responded with "%s" for %s',t,s);continue}n.trace('respond with "na" for "%s"',s),await o.write(L(`na
11
- `),e),n('responded with "na" for "%s"',s)}}return _t(dn);})();
2
+ "use strict";var Libp2PMultistreamSelect=(()=>{var Ee=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var Jt=Object.prototype.hasOwnProperty;var E=(r,t)=>{for(var e in t)Ee(r,e,{get:t[e],enumerable:!0})},Kt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Wt(t))!Jt.call(r,o)&&o!==e&&Ee(r,o,{get:()=>t[o],enumerable:!(n=Xt(t,o))||n.enumerable});return r};var Qt=r=>Kt(Ee({},"__esModule",{value:!0}),r);var Pn={};E(Pn,{PROTOCOL_ID:()=>U,handle:()=>qt,select:()=>jt});var U="/multistream/1.0.0";var se=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var ie=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},ae=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ie={};E(Ie,{base58btc:()=>F,base58flickr:()=>sr});var Vn=new Uint8Array(0);function ct(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return B(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return B(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function ut(r){return new TextEncoder().encode(r)}function lt(r){return new TextDecoder().decode(r)}function Yt(r){return r?.buffer instanceof ArrayBuffer}function B(r){return Yt(r)?r:r.slice()}function Zt(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var b=0,_=0,S=0,D=f.length;S!==D&&f[S]===0;)S++,b++;for(var N=(D-S)*l+1>>>0,v=new Uint8Array(N);S!==D;){for(var T=f[S],P=0,I=N-1;(T!==0||P<_)&&I!==-1;I--,P++)T+=256*v[I]>>>0,v[I]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");_=P,S++}for(var C=N-_;C!==N&&v[C]===0;)C++;for(var oe=c.repeat(b);C<N;++C)oe+=r.charAt(v[C]);return oe}function m(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var b=0;if(f[b]!==" "){for(var _=0,S=0;f[b]===c;)_++,b++;for(var D=(f.length-b)*u+1>>>0,N=new Uint8Array(D);f[b];){var v=e[f.charCodeAt(b)];if(v===255)return;for(var T=0,P=D-1;(v!==0||T<S)&&P!==-1;P--,T++)v+=a*N[P]>>>0,N[P]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");S=T,b++}if(f[b]!==" "){for(var I=D-S;I!==D&&N[I]===0;)I++;for(var C=new Uint8Array(_+(D-I)),oe=_;I!==D;)C[oe++]=N[I++];return C}}}function w(f){var b=m(f);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:m,decode:w}}var er=Zt,tr=er,ft=tr;var Le=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ve=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return dt(this,t)}},Ae=class{decoders;constructor(t){this.decoders=t}or(t){return dt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function dt(r,t){return new Ae({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Se=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Le(t,e,n),this.decoder=new ve(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $({name:r,prefix:t,encode:e,decode:n}){return new Se(r,t,e,n)}function R({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ft(e,r);return $({prefix:t,name:r,encode:n,decode:s=>M(o(s))})}function rr(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function nr(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function or(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function g({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=or(n);return $({prefix:t,name:r,encode(s){return nr(s,n,e)},decode(s){return rr(s,o,e,r)}})}var F=R({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sr=R({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ue={};E(Ue,{base32:()=>G,base32hex:()=>ur,base32hexpad:()=>hr,base32hexpadupper:()=>fr,base32hexupper:()=>lr,base32pad:()=>ar,base32padupper:()=>cr,base32upper:()=>ir,base32z:()=>dr});var G=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ir=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ar=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ur=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),lr=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),dr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var De={};E(De,{base36:()=>J,base36upper:()=>pr});var J=R({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pr=R({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mr=wt,pt=128,wr=127,gr=~wr,br=Math.pow(2,31);function wt(r,t,e){t=t||[],e=e||0;for(var n=e;r>=br;)t[e++]=r&255|pt,r/=128;for(;r&gr;)t[e++]=r&255|pt,r>>>=7;return t[e]=r|0,wt.bytes=e-n+1,t}var yr=Ne,xr=128,mt=127;function Ne(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ne.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&mt)<<o:(i&mt)*Math.pow(2,o),o+=7}while(i>=xr);return Ne.bytes=s-n,e}var Er=Math.pow(2,7),Lr=Math.pow(2,14),vr=Math.pow(2,21),Ar=Math.pow(2,28),Sr=Math.pow(2,35),Ir=Math.pow(2,42),Ur=Math.pow(2,49),Dr=Math.pow(2,56),Nr=Math.pow(2,63),Tr=function(r){return r<Er?1:r<Lr?2:r<vr?3:r<Ar?4:r<Sr?5:r<Ir?6:r<Ur?7:r<Dr?8:r<Nr?9:10},Fr={encode:mr,decode:yr,encodingLength:Tr},Cr=Fr,K=Cr;function Q(r,t=0){return[K.decode(r,t),K.decode.bytes]}function H(r,t,e=0){return K.encode(r,t,e),t}function j(r){return K.encodingLength(r)}function X(r,t){let e=t.byteLength,n=j(r),o=n+j(e),s=new Uint8Array(o+e);return H(r,s,0),H(e,s,n),s.set(t,o),new q(r,e,t,s)}function gt(r){let t=M(r),[e,n]=Q(t),[o,s]=Q(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new q(e,o,i,t)}function bt(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ct(r.bytes,e.bytes)}}var q=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=B(n),this.bytes=B(o)}};function yt(r,t){let{bytes:e,version:n}=r;return n===0?Or(e,Te(r),t??F.encoder):Pr(e,Te(r),t??G.encoder)}var xt=new WeakMap;function Te(r){let t=xt.get(r);if(t==null){let e=new Map;return xt.set(r,e),e}return t}var ue=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=B(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Z)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Rr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=X(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&bt(t.multihash,n.multihash)}toString(t){return yt(this,t)}toJSON(){return{"/":yt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Et(n,o,s.bytes))}else if(e[_r]===!0){let{version:n,multihash:o,code:s}=e,i=gt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Z)throw new Error(`Version 0 CID must use dag-pb (code: ${Z}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Et(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Z,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=M(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new q(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,m]=Q(t.subarray(e));return e+=m,h},o=n(),s=Z;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=Mr(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Te(s).set(n,t),s}};function Mr(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case J.prefix:{let e=t??J;return[J.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Or(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Pr(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Z=112,Rr=18;function Et(r,t,e){let n=j(r),o=n+j(t),s=new Uint8Array(o+e.byteLength);return H(r,s,0),H(t,s,n),s.set(e,o),s}var _r=Symbol.for("@ipld/js-cid/CID");var Fe={};E(Fe,{identity:()=>kr});var Lt=0,Br="identity",vt=M;function Vr(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return X(Lt,vt(r))}var kr={code:Lt,name:Br,encode:vt,digest:Vr};function O(r=0){return new Uint8Array(r)}function ee(r=0){return new Uint8Array(r)}function Ce(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ee(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function At(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var It=Symbol.for("@achingbrain/uint8arraylist");function St(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function le(r){return!!r?.[It]}var L=class r{bufs;length;[It]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(le(n)){e+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(le(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=St(this.bufs,t);return e.buf[e.index]}set(t,e){let n=St(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(le(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Ce(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ce(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!le(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=e;h<=c;h+=l){l=0;for(let m=u;m>=0;m--){let w=this.get(h+m);if(n[m]!==w){l=Math.max(1,m-a[w]);break}}if(l===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=O(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=O(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!At(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Me={};E(Me,{base10:()=>zr});var zr=R({prefix:"9",name:"base10",alphabet:"0123456789"});var Oe={};E(Oe,{base16:()=>$r,base16upper:()=>Gr});var $r=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Gr=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pe={};E(Pe,{base2:()=>Hr});var Hr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Re={};E(Re,{base256emoji:()=>Jr});var Ut=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}"),jr=Ut.reduce((r,t,e)=>(r[e]=t,r),[]),qr=Ut.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Xr(r){return r.reduce((t,e)=>(t+=jr[e],t),"")}function Wr(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=qr[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Jr=$({prefix:"\u{1F680}",name:"base256emoji",encode:Xr,decode:Wr});var _e={};E(_e,{base64:()=>Kr,base64pad:()=>Qr,base64url:()=>Yr,base64urlpad:()=>Zr});var Kr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Zr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Be={};E(Be,{base8:()=>en});var en=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ve={};E(Ve,{identity:()=>tn});var tn=$({prefix:"\0",name:"identity",encode:r=>lt(r),decode:r=>ut(r)});var vo=new TextEncoder,Ao=new TextDecoder;var $e={};E($e,{sha256:()=>sn,sha512:()=>an});var on=20;function ze({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new ke(r,t,e,n,o)}var ke=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??on,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Dt(n,this.code,e?.truncate):n.then(o=>Dt(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Dt(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return X(t,r)}function Tt(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var sn=ze({name:"sha2-256",code:18,encode:Tt("SHA-256")}),an=ze({name:"sha2-512",code:19,encode:Tt("SHA-512")});var Ge={...Ve,...Pe,...Be,...Me,...Oe,...Ue,...De,...Ie,..._e,...Re},Ro={...$e,...Fe};function Ft(r=0){return new Uint8Array(r)}function Mt(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ct=Mt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),He=Mt("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),cn={utf8:Ct,"utf-8":Ct,hex:Ge.base16,latin1:He,ascii:He,binary:He,...Ge},he=cn;function A(r,t="utf8"){let e=he[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Ot(r,t="utf8"){let e=he[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var je=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Pt=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function qe(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,l=new Promise((h,m)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){m(Pt(i));return}if(i&&(c=()=>{m(Pt(i))},i.addEventListener("abort",c,{once:!0})),r.then(h,m),e===Number.POSITIVE_INFINITY)return;let w=new je;a=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(f){m(f)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?m(o):(w.message=o??`Promise timed out after ${e} milliseconds`,m(w))},e)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var un=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function ln(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=un(r),h=async(...w)=>{let f=e.multiArgs?w:w[0];if(e.filter)try{if(!await e.filter(f))return}catch(b){n(),i(b);return}c.push(f),e.count===c.length&&(n(),s(c))},m=(...w)=>{n(),i(e.rejectionMultiArgs?w:w[0])};n=()=>{for(let w of a)l(w,h);for(let w of e.rejectionEvents)a.includes(w)||l(w,m)};for(let w of a)u(w,h);for(let w of e.rejectionEvents)a.includes(w)||u(w,m);e.signal&&e.signal.addEventListener("abort",()=>{m(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=qe(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Rt(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=ln(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var V=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function hn(r){return r.reason}async function Xe(r,t,e){if(t==null)return r;let n=e?.translateError??hn;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}function _t(r=0){return new Uint8Array(r)}var fn=Math.pow(2,7),dn=Math.pow(2,14),pn=Math.pow(2,21),We=Math.pow(2,28),Je=Math.pow(2,35),Ke=Math.pow(2,42),Qe=Math.pow(2,49),d=128,y=127;function te(r){if(r<fn)return 1;if(r<dn)return 2;if(r<pn)return 3;if(r<We)return 4;if(r<Je)return 5;if(r<Ke)return 6;if(r<Qe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function mn(r,t,e=0){switch(te(r)){case 8:t[e++]=r&255|d,r/=128;case 7:t[e++]=r&255|d,r/=128;case 6:t[e++]=r&255|d,r/=128;case 5:t[e++]=r&255|d,r/=128;case 4:t[e++]=r&255|d,r>>>=7;case 3:t[e++]=r&255|d,r>>>=7;case 2:t[e++]=r&255|d,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function wn(r,t,e=0){switch(te(r)){case 8:t.set(e++,r&255|d),r/=128;case 7:t.set(e++,r&255|d),r/=128;case 6:t.set(e++,r&255|d),r/=128;case 5:t.set(e++,r&255|d),r/=128;case 4:t.set(e++,r&255|d),r>>>=7;case 3:t.set(e++,r&255|d),r>>>=7;case 2:t.set(e++,r&255|d),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function gn(r,t){let e=r[t],n=0;if(n+=e&y,e<d||(e=r[t+1],n+=(e&y)<<7,e<d)||(e=r[t+2],n+=(e&y)<<14,e<d)||(e=r[t+3],n+=(e&y)<<21,e<d)||(e=r[t+4],n+=(e&y)*We,e<d)||(e=r[t+5],n+=(e&y)*Je,e<d)||(e=r[t+6],n+=(e&y)*Ke,e<d)||(e=r[t+7],n+=(e&y)*Qe,e<d))return n;throw new RangeError("Could not decode varint")}function bn(r,t){let e=r.get(t),n=0;if(n+=e&y,e<d||(e=r.get(t+1),n+=(e&y)<<7,e<d)||(e=r.get(t+2),n+=(e&y)<<14,e<d)||(e=r.get(t+3),n+=(e&y)<<21,e<d)||(e=r.get(t+4),n+=(e&y)*We,e<d)||(e=r.get(t+5),n+=(e&y)*Je,e<d)||(e=r.get(t+6),n+=(e&y)*Ke,e<d)||(e=r.get(t+7),n+=(e&y)*Qe,e<d))return n;throw new RangeError("Could not decode varint")}function Bt(r,t,e=0){return t==null&&(t=_t(te(r))),t instanceof Uint8Array?mn(r,t,e):wn(r,t,e)}function Vt(r,t=0){return r instanceof Uint8Array?gn(r,t):bn(r,t)}var En=4194304,fe=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ze=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},et=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},tt=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ln(r){return typeof r?.closeRead=="function"}function vn(r){return typeof r?.close=="function"}function Ye(r){return Ln(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:vn(r)?r.status!=="open":!1}function An(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Sn(r,t){let e=t?.maxBufferSize??En,n=new L,o,s=!1;if(!An(r))throw new se("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>e){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${e}`))}o?.resolve()};r.addEventListener("message",i);let a=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(s===!0)throw new fe("Stream was unwrapped");if(Ye(r)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new V(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Xe(o.promise,l?.signal),Ye(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let m=l?.bytes??n.byteLength;if(n.byteLength<m){if(Ye(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,m),new V(`Unexpected EOF - stream closed while reading ${n.byteLength}/${m} bytes`);return u.read(l)}let w=n.sublist(0,m);return n.consume(m),w},async write(l,h){if(s===!0)throw new fe("Stream was unwrapped");r.send(l)||await Rt(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return u}function de(r,t={}){let e=Sn(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=te(t.maxDataLength));let n=t?.lengthDecoder??Vt,o=t?.lengthEncoder??Bt;return{async read(i){let a=-1,c=new L;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ze("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new tt(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new et(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...i,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new V(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new V(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await e.write(new L(o(i.byteLength),i),a)},async writeV(i,a){let c=new L(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function pe(r=0){return new Uint8Array(r)}var In=Math.pow(2,7),Un=Math.pow(2,14),Dn=Math.pow(2,21),rt=Math.pow(2,28),nt=Math.pow(2,35),ot=Math.pow(2,42),st=Math.pow(2,49),p=128,x=127;function k(r){if(r<In)return 1;if(r<Un)return 2;if(r<Dn)return 3;if(r<rt)return 4;if(r<nt)return 5;if(r<ot)return 6;if(r<st)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Nn(r,t,e=0){switch(k(r)){case 8:t[e++]=r&255|p,r/=128;case 7:t[e++]=r&255|p,r/=128;case 6:t[e++]=r&255|p,r/=128;case 5:t[e++]=r&255|p,r/=128;case 4:t[e++]=r&255|p,r>>>=7;case 3:t[e++]=r&255|p,r>>>=7;case 2:t[e++]=r&255|p,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Tn(r,t,e=0){switch(k(r)){case 8:t.set(e++,r&255|p),r/=128;case 7:t.set(e++,r&255|p),r/=128;case 6:t.set(e++,r&255|p),r/=128;case 5:t.set(e++,r&255|p),r/=128;case 4:t.set(e++,r&255|p),r>>>=7;case 3:t.set(e++,r&255|p),r>>>=7;case 2:t.set(e++,r&255|p),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Fn(r,t){let e=r[t],n=0;if(n+=e&x,e<p||(e=r[t+1],n+=(e&x)<<7,e<p)||(e=r[t+2],n+=(e&x)<<14,e<p)||(e=r[t+3],n+=(e&x)<<21,e<p)||(e=r[t+4],n+=(e&x)*rt,e<p)||(e=r[t+5],n+=(e&x)*nt,e<p)||(e=r[t+6],n+=(e&x)*ot,e<p)||(e=r[t+7],n+=(e&x)*st,e<p))return n;throw new RangeError("Could not decode varint")}function Cn(r,t){let e=r.get(t),n=0;if(n+=e&x,e<p||(e=r.get(t+1),n+=(e&x)<<7,e<p)||(e=r.get(t+2),n+=(e&x)<<14,e<p)||(e=r.get(t+3),n+=(e&x)<<21,e<p)||(e=r.get(t+4),n+=(e&x)*rt,e<p)||(e=r.get(t+5),n+=(e&x)*nt,e<p)||(e=r.get(t+6),n+=(e&x)*ot,e<p)||(e=r.get(t+7),n+=(e&x)*st,e<p))return n;throw new RangeError("Could not decode varint")}function kt(r,t,e=0){return t==null&&(t=pe(k(r))),t instanceof Uint8Array?Nn(r,t,e):Tn(r,t,e)}function zt(r,t=0){return r instanceof Uint8Array?Fn(r,t):Cn(r,t)}var me=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},W=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},we=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},re=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ge(r){return r[Symbol.asyncIterator]!=null}function Gt(r,t){if(r.byteLength>t)throw new W("Message length too long")}var ye=r=>{let t=k(r),e=pe(t);return kt(r,e),ye.bytes=t,e};ye.bytes=0;function xe(r,t){t=t??{};let e=t.lengthEncoder??ye,n=t?.maxDataLength??4194304;function*o(s){Gt(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return ge(r)?(async function*(){for await(let s of r)yield*o(s)})():(function*(){for(let s of r)yield*o(s)})()}xe.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ye,n=t?.maxDataLength??4194304;return Gt(r,n),new L(e(r.byteLength),r)};var z;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(z||(z={}));var at=r=>{let t=zt(r);return at.bytes=k(t),t};at.bytes=0;function it(r,t){let e=new L,n=z.LENGTH,o=-1,s=t?.lengthDecoder??at,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===z.LENGTH)try{if(o=s(e),o<0)throw new me("Invalid message length");if(o>a)throw new W("Message length too long");let u=s.bytes;e.consume(u),t?.onLength!=null&&t.onLength(o),n=z.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>i)throw new we("Message length length too long");break}throw u}if(n===z.DATA){if(e.byteLength<o)break;let u=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(u),yield u,n=z.LENGTH}}}return ge(r)?(async function*(){for await(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new re("Unexpected end of input")})():(function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new re("Unexpected end of input")})()}it.fromReader=(r,t)=>{let e=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}})();return it(n,{...t??{},onLength:s=>{e=s}})};var On=A(`
3
+ `);async function ne(r,t){let n=(await r.read(t)).subarray();if(n.byteLength===0||n[n.length-1]!==On[0])throw new ae("Missing newline");return Ot(n).trimEnd()}async function jt(r,t,e={}){if(t=Array.isArray(t)?[...t]:[t],t.length===0)throw new Error("At least one protocol must be specified");let n=r.log.newScope("mss:select"),o=de(r,{...e,maxDataLength:1024});for(let s=0;s<t.length;s++){let i=t[s],a;if(s===0){n.trace('write ["%s", "%s"]',U,i);let c=A(`${U}
4
+ `),u=A(`${i}
5
+ `);if(await o.writeV([c,u],e),n.trace("reading multistream-select header"),a=await ne(o,e),n.trace('read "%s"',a),a!==U){n.error("did not read multistream-select header from response");break}}else n.trace('write "%s"',i),await o.write(A(`${i}
6
+ `),e);if(n.trace("reading protocol response"),a=await ne(o,e),n.trace('read "%s"',a),a===i)return n.trace('selected "%s" after negotiation',a),o.unwrap(),i}throw new ie(`Protocol selection failed - could not negotiate ${t}`)}async function qt(r,t,e={}){t=Array.isArray(t)?t:[t];let n=r.log.newScope("mss:handle"),o=de(r,{...e,maxDataLength:1024,maxLengthLength:2});for(;;){n.trace("reading incoming string");let s=await ne(o,e);if(n.trace('read "%s"',s),s===U){n.trace('respond with "%s" for "%s"',U,s),await o.write(A(`${U}
7
+ `),e),n.trace('responded with "%s" for "%s"',U,s);continue}if(t.includes(s))return n.trace('respond with "%s" for "%s"',s,s),await o.write(A(`${s}
8
+ `),e),n.trace('responded with "%s" for "%s"',s,s),o.unwrap(),s;if(s==="ls"){let i=new L(...t.map(a=>xe.single(A(`${a}
9
+ `))),A(`
10
+ `));n.trace('respond with "%s" for %s',t,s),await o.write(i,e),n.trace('responded with "%s" for %s',t,s);continue}n.trace('respond with "na" for "%s"',s),await o.write(A(`na
11
+ `),e),n('responded with "na" for "%s"',s)}}return Qt(Pn);})();
12
12
  return Libp2PMultistreamSelect}));
13
13
  //# sourceMappingURL=index.min.js.map