@libp2p/multistream-select 7.0.21 → 7.0.22

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