@libp2p/multistream-select 5.0.3-c00378909 → 5.0.3-cd8cafcd5

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.
Files changed (2) hide show
  1. package/dist/index.min.js +10 -10
  2. package/package.json +3 -3
package/dist/index.min.js CHANGED
@@ -1,16 +1,16 @@
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 Gt=Object.create;var oe=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,Ht=Object.prototype.hasOwnProperty;var Xt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),T=(r,t)=>{for(var e in t)oe(r,e,{get:t[e],enumerable:!0})},Qe=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of zt(t))!Ht.call(r,o)&&o!==e&&oe(r,o,{get:()=>t[o],enumerable:!(n=$t(t,o))||n.enumerable});return r};var qt=(r,t,e)=>(e=r!=null?Gt(jt(r)):{},Qe(t||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),Jt=r=>Qe(oe({},"__esModule",{value:!0}),r);var ht=Xt((Xo,ut)=>{"use strict";function lt(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function rr(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return lt(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),lt(new o,e)}}ut.exports=rr});var bn={};T(bn,{PROTOCOL_ID:()=>x,handle:()=>kt,select:()=>Vt});var x="/multistream/1.0.0";var Ln=Symbol.for("@libp2p/connection");var En=Symbol.for("@libp2p/content-routing");var vn=Symbol.for("@libp2p/peer-discovery");var Rn=Symbol.for("@libp2p/peer-id");var On=Symbol.for("@libp2p/peer-routing");var Ze;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ze||(Ze={}));var _n=Symbol.for("@libp2p/transport");var et;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(et||(et={}));var V=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var xe=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},Fn=globalThis.CustomEvent??xe;function K(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function I(r=0){return globalThis.Buffer?.alloc!=null?K(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function Y(r=0){return globalThis.Buffer?.allocUnsafe!=null?K(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Le(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=Y(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return K(e)}function tt(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 nt=Symbol.for("@achingbrain/uint8arraylist");function rt(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?.[nt]}var L=class r{bufs;length;[nt]=!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,this.bufs.push(...n.bufs);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=rt(this.bufs,t);return e.buf[e.index]}set(t,e){let n=rt(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 Le(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Le(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_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 i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(d){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}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 i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let l=e;l<=c;l+=d){d=0;for(let b=f;b>=0;b--){let P=this.get(l+b);if(n[b]!==P){d=Math.max(1,b-a[P]);break}}if(d===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Y(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=I(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=I(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=I(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=Y(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=I(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=I(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=I(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=I(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=I(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(!tt(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,i)=>o+i.byteLength,0)),n.length=e,n}};function D(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var se=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function ae(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new se(e?.errorMessage,e?.errorCode));let n,o=new se(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ae=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=D(),this.haveNext=D()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=D(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=D(),await ae(this.needNext.promise,e?.signal,e)}};function ot(){return new Ae}var ce=class extends Error{code;constructor(t,e){super(t),this.code=e}},Ee=class extends ce{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function it(r,t){let e=ot();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new L;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,f=new Promise((d,l)=>{c=()=>{l(new Ee("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:l,value:b}=await Promise.race([n.next(),f]);return l===!0?new L:b}for(;o.byteLength<s;){let{value:l,done:b}=await Promise.race([n.next(),f]);if(b===!0)throw new ce("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(l)}let d=o.sublist(0,s);return o.consume(s),d}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}function st(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function at(r=0){return globalThis.Buffer?.allocUnsafe!=null?st(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Wt=Math.pow(2,7),Kt=Math.pow(2,14),Yt=Math.pow(2,21),Se=Math.pow(2,28),Ue=Math.pow(2,35),ve=Math.pow(2,42),Te=Math.pow(2,49),h=128,A=127;function _(r){if(r<Wt)return 1;if(r<Kt)return 2;if(r<Yt)return 3;if(r<Se)return 4;if(r<Ue)return 5;if(r<ve)return 6;if(r<Te)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qt(r,t,e=0){switch(_(r)){case 8:t[e++]=r&255|h,r/=128;case 7:t[e++]=r&255|h,r/=128;case 6:t[e++]=r&255|h,r/=128;case 5:t[e++]=r&255|h,r/=128;case 4:t[e++]=r&255|h,r>>>=7;case 3:t[e++]=r&255|h,r>>>=7;case 2:t[e++]=r&255|h,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Zt(r,t,e=0){switch(_(r)){case 8:t.set(e++,r&255|h),r/=128;case 7:t.set(e++,r&255|h),r/=128;case 6:t.set(e++,r&255|h),r/=128;case 5:t.set(e++,r&255|h),r/=128;case 4:t.set(e++,r&255|h),r>>>=7;case 3:t.set(e++,r&255|h),r>>>=7;case 2:t.set(e++,r&255|h),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function er(r,t){let e=r[t],n=0;if(n+=e&A,e<h||(e=r[t+1],n+=(e&A)<<7,e<h)||(e=r[t+2],n+=(e&A)<<14,e<h)||(e=r[t+3],n+=(e&A)<<21,e<h)||(e=r[t+4],n+=(e&A)*Se,e<h)||(e=r[t+5],n+=(e&A)*Ue,e<h)||(e=r[t+6],n+=(e&A)*ve,e<h)||(e=r[t+7],n+=(e&A)*Te,e<h))return n;throw new RangeError("Could not decode varint")}function tr(r,t){let e=r.get(t),n=0;if(n+=e&A,e<h||(e=r.get(t+1),n+=(e&A)<<7,e<h)||(e=r.get(t+2),n+=(e&A)<<14,e<h)||(e=r.get(t+3),n+=(e&A)<<21,e<h)||(e=r.get(t+4),n+=(e&A)*Se,e<h)||(e=r.get(t+5),n+=(e&A)*Ue,e<h)||(e=r.get(t+6),n+=(e&A)*ve,e<h)||(e=r.get(t+7),n+=(e&A)*Te,e<h))return n;throw new RangeError("Could not decode varint")}function fe(r,t,e=0){return t==null&&(t=at(_(r))),t instanceof Uint8Array?Qt(r,t,e):Zt(r,t,e)}function le(r,t=0){return r instanceof Uint8Array?er(r,t):tr(r,t)}function ct(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function ft(r=0){return globalThis.Buffer?.allocUnsafe!=null?ct(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function he(r){return r[Symbol.asyncIterator]!=null}var de=r=>{let t=_(r),e=ft(t);return fe(r,e),de.bytes=t,e};de.bytes=0;function k(r,t){t=t??{};let e=t.lengthEncoder??de;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return he(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}k.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??de;return new L(e(r.byteLength),r)};var j=qt(ht(),1);var nr=8,or=1024*1024*4,G;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(G||(G={}));var De=r=>{let t=le(r);return De.bytes=_(t),t};De.bytes=0;function Re(r,t){let e=new L,n=G.LENGTH,o=-1,i=t?.lengthDecoder??De,s=t?.maxLengthLength??nr,a=t?.maxDataLength??or;function*c(){for(;e.byteLength>0;){if(n===G.LENGTH)try{if(o=i(e),o<0)throw(0,j.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,j.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=i.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=G.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>s)throw(0,j.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===G.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=G.LENGTH}}}return he(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,j.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,j.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Re.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Re(n,{...t??{},onLength:i=>{e=i}})};var pe=class extends Error{code;constructor(t,e){super(t),this.code=e}},dt=r=>le(r);dt.bytes=0;function Q(r,t={}){let e=it(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=_(t.maxDataLength)),{read:async o=>{let i=-1,s=new L,a=t?.lengthDecoder??dt;for(;;){s.append(await e.read(1,o));try{i=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new pe("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new pe("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(k.single(o,t),i)},writeV:async(o,i)=>{let s=new L(...o.map(a=>k.single(a,t)));await e.write(s,i)},unwrap:()=>e.unwrap()}}function me(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var _e={};T(_e,{base10:()=>ur});function sr(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 i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var w=0,N=0,U=0,p=u.length;U!==p&&u[U]===0;)U++,w++;for(var y=(p-U)*d+1>>>0,m=new Uint8Array(y);U!==p;){for(var S=u[U],R=0,v=y-1;(S!==0||R<N)&&v!==-1;v--,R++)S+=256*m[v]>>>0,m[v]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");N=R,U++}for(var C=y-N;C!==y&&m[C]===0;)C++;for(var ne=c.repeat(w);C<y;++C)ne+=r.charAt(m[C]);return ne}function b(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var w=0;if(u[w]!==" "){for(var N=0,U=0;u[w]===c;)N++,w++;for(var p=(u.length-w)*f+1>>>0,y=new Uint8Array(p);u[w];){var m=e[u.charCodeAt(w)];if(m===255)return;for(var S=0,R=p-1;(m!==0||S<U)&&R!==-1;R--,S++)m+=a*y[R]>>>0,y[R]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");U=S,w++}if(u[w]!==" "){for(var v=p-U;v!==p&&y[v]===0;)v++;for(var C=new Uint8Array(N+(p-v)),ne=N;v!==p;)C[ne++]=y[v++];return C}}}function P(u){var w=b(u);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:P}}var ar=sr,cr=ar,pt=cr;var ni=new Uint8Array(0);var mt=(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},B=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")};var gt=r=>new TextEncoder().encode(r),wt=r=>new TextDecoder().decode(r);var Oe=class{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")}},Ne=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 yt(this,t)}},Ce=class{constructor(t){this.decoders=t}or(t){return yt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},yt=(r,t)=>new Ce({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),Ie=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oe(t,e,n),this.decoder=new Ne(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},H=({name:r,prefix:t,encode:e,decode:n})=>new Ie(r,t,e,n),F=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=pt(e,t);return H({prefix:r,name:t,encode:n,decode:i=>B(o(i))})},fr=(r,t,e,n)=>{let o={};for(let d=0;d<t.length;++d)o[t[d]]=d;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let d=0;d<i;++d){let l=o[r[d]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},lr=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},g=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>H({prefix:t,name:r,encode(o){return lr(o,n,e)},decode(o){return fr(o,n,e,r)}});var ur=F({prefix:"9",name:"base10",alphabet:"0123456789"});var Be={};T(Be,{base16:()=>hr,base16upper:()=>dr});var hr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),dr=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pe={};T(Pe,{base2:()=>pr});var pr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Fe={};T(Fe,{base256emoji:()=>yr});var xt=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}"),mr=xt.reduce((r,t,e)=>(r[e]=t,r),[]),gr=xt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function wr(r){return r.reduce((t,e)=>(t+=mr[e],t),"")}function br(r){let t=[];for(let e of r){let n=gr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var yr=H({prefix:"\u{1F680}",name:"base256emoji",encode:wr,decode:br});var Me={};T(Me,{base32:()=>X,base32hex:()=>Er,base32hexpad:()=>Ur,base32hexpadupper:()=>vr,base32hexupper:()=>Sr,base32pad:()=>Lr,base32padupper:()=>Ar,base32upper:()=>xr,base32z:()=>Tr});var X=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Lr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ar=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Er=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Sr=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ur=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Tr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ve={};T(Ve,{base36:()=>Rr,base36upper:()=>Dr});var Rr=F({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Dr=F({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ke={};T(ke,{base58btc:()=>O,base58flickr:()=>Or});var O=F({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Or=F({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ge={};T(Ge,{base64:()=>Nr,base64pad:()=>Cr,base64url:()=>Ir,base64urlpad:()=>_r});var Nr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Cr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ir=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_r=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $e={};T($e,{base8:()=>Br});var Br=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ze={};T(ze,{identity:()=>Pr});var Pr=H({prefix:"\0",name:"identity",encode:r=>wt(r),decode:r=>gt(r)});var bi=new TextEncoder,yi=new TextDecoder;var He={};T(He,{identity:()=>sn});var Vr=Et,Lt=128,kr=127,Gr=~kr,$r=Math.pow(2,31);function Et(r,t,e){t=t||[],e=e||0;for(var n=e;r>=$r;)t[e++]=r&255|Lt,r/=128;for(;r&Gr;)t[e++]=r&255|Lt,r>>>=7;return t[e]=r|0,Et.bytes=e-n+1,t}var zr=je,jr=128,At=127;function je(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw je.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&At)<<o:(s&At)*Math.pow(2,o),o+=7}while(s>=jr);return je.bytes=i-n,e}var Hr=Math.pow(2,7),Xr=Math.pow(2,14),qr=Math.pow(2,21),Jr=Math.pow(2,28),Wr=Math.pow(2,35),Kr=Math.pow(2,42),Yr=Math.pow(2,49),Qr=Math.pow(2,56),Zr=Math.pow(2,63),en=function(r){return r<Hr?1:r<Xr?2:r<qr?3:r<Jr?4:r<Wr?5:r<Kr?6:r<Yr?7:r<Qr?8:r<Zr?9:10},tn={encode:Vr,decode:zr,encodingLength:en},rn=tn,Z=rn;var ee=(r,t=0)=>[Z.decode(r,t),Z.decode.bytes],q=(r,t,e=0)=>(Z.encode(r,t,e),t),J=r=>Z.encodingLength(r);var $=(r,t)=>{let e=t.byteLength,n=J(r),o=n+J(e),i=new Uint8Array(o+e);return q(r,i,0),q(e,i,n),i.set(t,o),new W(r,e,t,i)},St=r=>{let t=B(r),[e,n]=ee(t),[o,i]=ee(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new W(e,o,s,t)},Ut=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&mt(r.bytes,e.bytes)}},W=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var vt=0,nn="identity",Tt=B,on=r=>$(vt,Tt(r)),sn={code:vt,name:nn,encode:Tt,digest:on};var Je={};T(Je,{sha256:()=>an,sha512:()=>cn});var qe=({name:r,code:t,encode:e})=>new Xe(r,t,e),Xe=class{constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?$(this.code,e):e.then(n=>$(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Dt=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),an=qe({name:"sha2-256",code:18,encode:Dt("SHA-256")}),cn=qe({name:"sha2-512",code:19,encode:Dt("SHA-512")});var Ot=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return ln(e,We(r),t||O.encoder);default:return un(e,We(r),t||X.encoder)}};var Nt=new WeakMap,We=r=>{let t=Nt.get(r);if(t==null){let e=new Map;return Nt.set(r,e),e}return t},we=class r{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!==re)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==hn)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=$(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&&t.code===n.code&&t.version===n.version&&Ut(t.multihash,n.multihash)}toString(t){return Ot(this,t)}toJSON(){return{"/":Ot(this)}}link(){return this}get[Symbol.toStringTag](){return"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:i,bytes:s}=e;return new r(n,o,i,s||Ct(n,o,i.bytes))}else if(e[dn]===!0){let{version:n,multihash:o,code:i}=e,s=St(o);return r.create(n,i,s)}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!==re)throw new Error(`Version 0 CID must use dag-pb (code: ${re}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ct(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,re,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=B(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new W(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,b]=ee(t.subarray(e));return e+=b,l},o=n(),i=re;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),f=e+c,d=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=fn(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return We(i).set(n,t),i}},fn=(r,t)=>{switch(r[0]){case"Q":{let e=t||O;return[O.prefix,e.decode(`${O.prefix}${r}`)]}case O.prefix:{let e=t||O;return[O.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 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},ln=(r,t,e)=>{let{prefix:n}=e;if(n!==O.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},un=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},re=112,hn=18,Ct=(r,t,e)=>{let n=J(r),o=n+J(t),i=new Uint8Array(o+e.byteLength);return q(r,i,0),q(t,i,n),i.set(e,o),i},dn=Symbol.for("@ipld/js-cid/CID");var Ke={...ze,...Pe,...$e,..._e,...Be,...Me,...Ve,...ke,...Ge,...Fe},Bi={...Je,...He};function It(r=0){return globalThis.Buffer?.allocUnsafe!=null?me(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Bt(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var _t=Bt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ye=Bt("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=It(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),pn={utf8:_t,"utf-8":_t,hex:Ke.base16,latin1:Ye,ascii:Ye,binary:Ye,...Ke},be=pn;function E(r,t="utf8"){let e=be[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?me(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Pt(r,t="utf8"){let e=be[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var mn=E(`
3
- `);async function z(r,t,e){await r.write(t,e)}async function Ft(r,t,e){await r.writeV(t,e)}async function gn(r,t){let e=await r.read(t);if(e.byteLength===0||e.get(e.byteLength-1)!==mn[0])throw t.log.error("Invalid mss message - missing newline",e),new V("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return e.sublist(0,-1)}async function M(r,t){let e=await gn(r,t);return Pt(e.subarray())}async function Vt(r,t,e){if(t=Array.isArray(t)?[...t]:[t],t.length===1)return wn(r,t[0],e);let n=Q(r,{...e,maxDataLength:1024}),o=t.shift();if(o==null)throw new Error("At least one protocol must be specified");e.log.trace('select: write ["%s", "%s"]',x,o);let i=E(`${x}
2
+ "use strict";var Libp2PMultistreamSelect=(()=>{var Mt=Object.create;var oe=Object.defineProperty;var Bt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var kt=Object.getPrototypeOf,Gt=Object.prototype.hasOwnProperty;var zt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),R=(r,t)=>{for(var e in t)oe(r,e,{get:t[e],enumerable:!0})},Qe=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Vt(t))!Gt.call(r,o)&&o!==e&&oe(r,o,{get:()=>t[o],enumerable:!(n=Bt(t,o))||n.enumerable});return r};var $t=(r,t,e)=>(e=r!=null?Mt(kt(r)):{},Qe(t||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),jt=r=>Qe(oe({},"__esModule",{value:!0}),r);var ct=zt((Fo,at)=>{"use strict";function st(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Qt(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return st(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),st(new o,e)}}at.exports=Qt});var pn={};R(pn,{PROTOCOL_ID:()=>x,handle:()=>Ft,select:()=>Pt});var x="/multistream/1.0.0";var wn=Symbol.for("@libp2p/connection");var yn=Symbol.for("@libp2p/content-routing");var An=Symbol.for("@libp2p/peer-discovery");var Sn=Symbol.for("@libp2p/peer-id");var Un=Symbol.for("@libp2p/peer-routing");var Ze;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ze||(Ze={}));var On=Symbol.for("@libp2p/transport");var et;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(et||(et={}));var k=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var xe=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},In=globalThis.CustomEvent??xe;function Y(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function I(r=0){return globalThis.Buffer?.alloc!=null?Y(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function _(r=0){return globalThis.Buffer?.allocUnsafe!=null?Y(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Le(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=_(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return Y(e)}function tt(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 nt=Symbol.for("@achingbrain/uint8arraylist");function rt(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?.[nt]}var L=class r{bufs;length;[nt]=!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,this.bufs.push(...n.bufs);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=rt(this.bufs,t);return e.buf[e.index]}set(t,e){let n=rt(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 Le(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Le(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_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 i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(d){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}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 i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let l=e;l<=c;l+=d){d=0;for(let b=f;b>=0;b--){let M=this.get(l+b);if(n[b]!==M){d=Math.max(1,b-a[M]);break}}if(d===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=_(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=I(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=I(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=I(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=_(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=I(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=I(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=I(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=I(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=I(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(!tt(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,i)=>o+i.byteLength,0)),n.length=e,n}};function T(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var se=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function ae(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new se(e?.errorMessage,e?.errorCode));let n,o=new se(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ae=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=T(),this.haveNext=T()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=T(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=T(),await ae(this.needNext.promise,e?.signal,e)}};function ot(){return new Ae}var ce=class extends Error{code;constructor(t,e){super(t),this.code=e}},Ee=class extends ce{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function it(r,t){let e=ot();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new L;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,f=new Promise((d,l)=>{c=()=>{l(new Ee("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:l,value:b}=await Promise.race([n.next(),f]);return l===!0?new L:b}for(;o.byteLength<s;){let{value:l,done:b}=await Promise.race([n.next(),f]);if(b===!0)throw new ce("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(l)}let d=o.sublist(0,s);return o.consume(s),d}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Ht=Math.pow(2,7),Xt=Math.pow(2,14),qt=Math.pow(2,21),Se=Math.pow(2,28),ve=Math.pow(2,35),Ue=Math.pow(2,42),Re=Math.pow(2,49),u=128,A=127;function P(r){if(r<Ht)return 1;if(r<Xt)return 2;if(r<qt)return 3;if(r<Se)return 4;if(r<ve)return 5;if(r<Ue)return 6;if(r<Re)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Jt(r,t,e=0){switch(P(r)){case 8:t[e++]=r&255|u,r/=128;case 7:t[e++]=r&255|u,r/=128;case 6:t[e++]=r&255|u,r/=128;case 5:t[e++]=r&255|u,r/=128;case 4:t[e++]=r&255|u,r>>>=7;case 3:t[e++]=r&255|u,r>>>=7;case 2:t[e++]=r&255|u,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Wt(r,t,e=0){switch(P(r)){case 8:t.set(e++,r&255|u),r/=128;case 7:t.set(e++,r&255|u),r/=128;case 6:t.set(e++,r&255|u),r/=128;case 5:t.set(e++,r&255|u),r/=128;case 4:t.set(e++,r&255|u),r>>>=7;case 3:t.set(e++,r&255|u),r>>>=7;case 2:t.set(e++,r&255|u),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Kt(r,t){let e=r[t],n=0;if(n+=e&A,e<u||(e=r[t+1],n+=(e&A)<<7,e<u)||(e=r[t+2],n+=(e&A)<<14,e<u)||(e=r[t+3],n+=(e&A)<<21,e<u)||(e=r[t+4],n+=(e&A)*Se,e<u)||(e=r[t+5],n+=(e&A)*ve,e<u)||(e=r[t+6],n+=(e&A)*Ue,e<u)||(e=r[t+7],n+=(e&A)*Re,e<u))return n;throw new RangeError("Could not decode varint")}function Yt(r,t){let e=r.get(t),n=0;if(n+=e&A,e<u||(e=r.get(t+1),n+=(e&A)<<7,e<u)||(e=r.get(t+2),n+=(e&A)<<14,e<u)||(e=r.get(t+3),n+=(e&A)<<21,e<u)||(e=r.get(t+4),n+=(e&A)*Se,e<u)||(e=r.get(t+5),n+=(e&A)*ve,e<u)||(e=r.get(t+6),n+=(e&A)*Ue,e<u)||(e=r.get(t+7),n+=(e&A)*Re,e<u))return n;throw new RangeError("Could not decode varint")}function fe(r,t,e=0){return t==null&&(t=_(P(r))),t instanceof Uint8Array?Jt(r,t,e):Wt(r,t,e)}function le(r,t=0){return r instanceof Uint8Array?Kt(r,t):Yt(r,t)}function ue(r){return r[Symbol.asyncIterator]!=null}var de=r=>{let t=P(r),e=_(t);return fe(r,e),de.bytes=t,e};de.bytes=0;function G(r,t){t=t??{};let e=t.lengthEncoder??de;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return ue(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}G.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??de;return new L(e(r.byteLength),r)};var H=$t(ct(),1);var Zt=8,er=1024*1024*4,z;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(z||(z={}));var Te=r=>{let t=le(r);return Te.bytes=P(t),t};Te.bytes=0;function De(r,t){let e=new L,n=z.LENGTH,o=-1,i=t?.lengthDecoder??Te,s=t?.maxLengthLength??Zt,a=t?.maxDataLength??er;function*c(){for(;e.byteLength>0;){if(n===z.LENGTH)try{if(o=i(e),o<0)throw(0,H.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,H.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=i.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=z.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>s)throw(0,H.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===z.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=z.LENGTH}}}return ue(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,H.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,H.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}De.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return De(n,{...t??{},onLength:i=>{e=i}})};var pe=class extends Error{code;constructor(t,e){super(t),this.code=e}},ft=r=>le(r);ft.bytes=0;function Q(r,t={}){let e=it(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=P(t.maxDataLength)),{read:async o=>{let i=-1,s=new L,a=t?.lengthDecoder??ft;for(;;){s.append(await e.read(1,o));try{i=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new pe("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new pe("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(G.single(o,t),i)},writeV:async(o,i)=>{let s=new L(...o.map(a=>G.single(a,t)));await e.write(s,i)},unwrap:()=>e.unwrap()}}function me(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var _e={};R(_e,{base10:()=>ar});function rr(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 i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(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,N=0,v=0,p=h.length;v!==p&&h[v]===0;)v++,w++;for(var y=(p-v)*d+1>>>0,m=new Uint8Array(y);v!==p;){for(var S=h[v],D=0,U=y-1;(S!==0||D<N)&&U!==-1;U--,D++)S+=256*m[U]>>>0,m[U]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");N=D,v++}for(var C=y-N;C!==y&&m[C]===0;)C++;for(var ne=c.repeat(w);C<y;++C)ne+=r.charAt(m[C]);return ne}function b(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 N=0,v=0;h[w]===c;)N++,w++;for(var p=(h.length-w)*f+1>>>0,y=new Uint8Array(p);h[w];){var m=e[h.charCodeAt(w)];if(m===255)return;for(var S=0,D=p-1;(m!==0||S<v)&&D!==-1;D--,S++)m+=a*y[D]>>>0,y[D]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");v=S,w++}if(h[w]!==" "){for(var U=p-v;U!==p&&y[U]===0;)U++;for(var C=new Uint8Array(N+(p-U)),ne=N;U!==p;)C[ne++]=y[U++];return C}}}function M(h){var w=b(h);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:M}}var nr=rr,or=nr,lt=or;var qo=new Uint8Array(0);var ht=(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},F=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")};var ut=r=>new TextEncoder().encode(r),dt=r=>new TextDecoder().decode(r);var Oe=class{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")}},Ne=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 mt(this,t)}},Ce=class{constructor(t){this.decoders=t}or(t){return mt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},mt=(r,t)=>new Ce({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),Ie=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oe(t,e,n),this.decoder=new Ne(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},X=({name:r,prefix:t,encode:e,decode:n})=>new Ie(r,t,e,n),B=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=lt(e,t);return X({prefix:r,name:t,encode:n,decode:i=>F(o(i))})},ir=(r,t,e,n)=>{let o={};for(let d=0;d<t.length;++d)o[t[d]]=d;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let d=0;d<i;++d){let l=o[r[d]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},sr=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},g=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>X({prefix:t,name:r,encode(o){return sr(o,n,e)},decode(o){return ir(o,n,e,r)}});var ar=B({prefix:"9",name:"base10",alphabet:"0123456789"});var Pe={};R(Pe,{base16:()=>cr,base16upper:()=>fr});var cr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),fr=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Fe={};R(Fe,{base2:()=>lr});var lr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Me={};R(Me,{base256emoji:()=>mr});var gt=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}"),hr=gt.reduce((r,t,e)=>(r[e]=t,r),[]),ur=gt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function dr(r){return r.reduce((t,e)=>(t+=hr[e],t),"")}function pr(r){let t=[];for(let e of r){let n=ur[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var mr=X({prefix:"\u{1F680}",name:"base256emoji",encode:dr,decode:pr});var Be={};R(Be,{base32:()=>q,base32hex:()=>yr,base32hexpad:()=>Lr,base32hexpadupper:()=>Ar,base32hexupper:()=>xr,base32pad:()=>wr,base32padupper:()=>br,base32upper:()=>gr,base32z:()=>Er});var q=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),gr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),wr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),br=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yr=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xr=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ar=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Er=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ve={};R(Ve,{base36:()=>Sr,base36upper:()=>vr});var Sr=B({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vr=B({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ke={};R(ke,{base58btc:()=>O,base58flickr:()=>Ur});var O=B({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ur=B({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ge={};R(Ge,{base64:()=>Rr,base64pad:()=>Dr,base64url:()=>Tr,base64urlpad:()=>Or});var Rr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Dr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Or=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ze={};R(ze,{base8:()=>Nr});var Nr=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $e={};R($e,{identity:()=>Cr});var Cr=X({prefix:"\0",name:"identity",encode:r=>dt(r),decode:r=>ut(r)});var ci=new TextEncoder,fi=new TextDecoder;var He={};R(He,{identity:()=>tn});var Pr=yt,wt=128,Fr=127,Mr=~Fr,Br=Math.pow(2,31);function yt(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Br;)t[e++]=r&255|wt,r/=128;for(;r&Mr;)t[e++]=r&255|wt,r>>>=7;return t[e]=r|0,yt.bytes=e-n+1,t}var Vr=je,kr=128,bt=127;function je(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw je.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&bt)<<o:(s&bt)*Math.pow(2,o),o+=7}while(s>=kr);return je.bytes=i-n,e}var Gr=Math.pow(2,7),zr=Math.pow(2,14),$r=Math.pow(2,21),jr=Math.pow(2,28),Hr=Math.pow(2,35),Xr=Math.pow(2,42),qr=Math.pow(2,49),Jr=Math.pow(2,56),Wr=Math.pow(2,63),Kr=function(r){return r<Gr?1:r<zr?2:r<$r?3:r<jr?4:r<Hr?5:r<Xr?6:r<qr?7:r<Jr?8:r<Wr?9:10},Yr={encode:Pr,decode:Vr,encodingLength:Kr},Qr=Yr,Z=Qr;var ee=(r,t=0)=>[Z.decode(r,t),Z.decode.bytes],J=(r,t,e=0)=>(Z.encode(r,t,e),t),W=r=>Z.encodingLength(r);var $=(r,t)=>{let e=t.byteLength,n=W(r),o=n+W(e),i=new Uint8Array(o+e);return J(r,i,0),J(e,i,n),i.set(t,o),new K(r,e,t,i)},xt=r=>{let t=F(r),[e,n]=ee(t),[o,i]=ee(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new K(e,o,s,t)},Lt=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ht(r.bytes,e.bytes)}},K=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var At=0,Zr="identity",Et=F,en=r=>$(At,Et(r)),tn={code:At,name:Zr,encode:Et,digest:en};var Je={};R(Je,{sha256:()=>rn,sha512:()=>nn});var qe=({name:r,code:t,encode:e})=>new Xe(r,t,e),Xe=class{constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?$(this.code,e):e.then(n=>$(this.code,n))}else throw Error("Unknown type, must be binary type")}};var vt=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),rn=qe({name:"sha2-256",code:18,encode:vt("SHA-256")}),nn=qe({name:"sha2-512",code:19,encode:vt("SHA-512")});var Ut=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return sn(e,We(r),t||O.encoder);default:return an(e,We(r),t||q.encoder)}};var Rt=new WeakMap,We=r=>{let t=Rt.get(r);if(t==null){let e=new Map;return Rt.set(r,e),e}return t},we=class r{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!==re)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==cn)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=$(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&&t.code===n.code&&t.version===n.version&&Lt(t.multihash,n.multihash)}toString(t){return Ut(this,t)}toJSON(){return{"/":Ut(this)}}link(){return this}get[Symbol.toStringTag](){return"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:i,bytes:s}=e;return new r(n,o,i,s||Dt(n,o,i.bytes))}else if(e[fn]===!0){let{version:n,multihash:o,code:i}=e,s=xt(o);return r.create(n,i,s)}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!==re)throw new Error(`Version 0 CID must use dag-pb (code: ${re}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Dt(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,re,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=F(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new K(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,b]=ee(t.subarray(e));return e+=b,l},o=n(),i=re;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),f=e+c,d=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=on(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return We(i).set(n,t),i}},on=(r,t)=>{switch(r[0]){case"Q":{let e=t||O;return[O.prefix,e.decode(`${O.prefix}${r}`)]}case O.prefix:{let e=t||O;return[O.prefix,e.decode(r)]}case q.prefix:{let e=t||q;return[q.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},sn=(r,t,e)=>{let{prefix:n}=e;if(n!==O.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},an=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},re=112,cn=18,Dt=(r,t,e)=>{let n=W(r),o=n+W(t),i=new Uint8Array(o+e.byteLength);return J(r,i,0),J(t,i,n),i.set(e,o),i},fn=Symbol.for("@ipld/js-cid/CID");var Ke={...$e,...Fe,...ze,..._e,...Pe,...Be,...Ve,...ke,...Ge,...Me},vi={...Je,...He};function Tt(r=0){return globalThis.Buffer?.allocUnsafe!=null?me(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Nt(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ot=Nt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ye=Nt("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=Tt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ln={utf8:Ot,"utf-8":Ot,hex:Ke.base16,latin1:Ye,ascii:Ye,binary:Ye,...Ke},be=ln;function E(r,t="utf8"){let e=be[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?me(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Ct(r,t="utf8"){let e=be[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var hn=E(`
3
+ `);async function j(r,t,e){await r.write(t,e)}async function It(r,t,e){await r.writeV(t,e)}async function un(r,t){let e=await r.read(t);if(e.byteLength===0||e.get(e.byteLength-1)!==hn[0])throw t.log.error("Invalid mss message - missing newline",e),new k("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return e.sublist(0,-1)}async function V(r,t){let e=await un(r,t);return Ct(e.subarray())}async function Pt(r,t,e){if(t=Array.isArray(t)?[...t]:[t],t.length===1)return dn(r,t[0],e);let n=Q(r,{...e,maxDataLength:1024}),o=t.shift();if(o==null)throw new Error("At least one protocol must be specified");e.log.trace('select: write ["%s", "%s"]',x,o);let i=E(`${x}
4
4
  `),s=E(`${o}
5
- `);await Ft(n,[i,s],e),e.log.trace("select: reading multistream-select header");let a=await M(n,e);if(e.log.trace('select: read "%s"',a),a===x&&(e.log.trace("select: reading protocol response"),a=await M(n,e),e.log.trace('select: read "%s"',a)),a===o)return{stream:n.unwrap(),protocol:o};for(let c of t){e.log.trace('select: write "%s"',c),await z(n,E(`${c}
6
- `),e),e.log.trace("select: reading protocol response");let f=await M(n,e);if(e.log.trace('select: read "%s" for "%s"',f,c),f===c)return{stream:n.unwrap(),protocol:c}}throw new V("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}function wn(r,t,e){let n=r.sink.bind(r),o=r.source,i=!1,s=!1,a=D(),c=!1,f=!1,d=D(),l=!1,b=!1,P=D(),u=Q({sink:n,source:o},{...e,maxDataLength:1024});r.sink=async p=>{let{sink:y}=u.unwrap();await y(async function*(){let m=!1;for await(let S of p){if(f&&await d.promise,c)yield S;else{f=!0,e.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink',x,t,S.byteLength);let R=`${t}
5
+ `);await It(n,[i,s],e),e.log.trace("select: reading multistream-select header");let a=await V(n,e);if(e.log.trace('select: read "%s"',a),a===x&&(e.log.trace("select: reading protocol response"),a=await V(n,e),e.log.trace('select: read "%s"',a)),a===o)return{stream:n.unwrap(),protocol:o};for(let c of t){e.log.trace('select: write "%s"',c),await j(n,E(`${c}
6
+ `),e),e.log.trace("select: reading protocol response");let f=await V(n,e);if(e.log.trace('select: read "%s" for "%s"',f,c),f===c)return{stream:n.unwrap(),protocol:c}}throw new k("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}function dn(r,t,e){let n=r.sink.bind(r),o=r.source,i=!1,s=!1,a=T(),c=!1,f=!1,d=T(),l=!1,b=!1,M=T(),h=Q({sink:n,source:o},{...e,maxDataLength:1024});r.sink=async p=>{let{sink:y}=h.unwrap();await y(async function*(){let m=!1;for await(let S of p){if(f&&await d.promise,c)yield S;else{f=!0,e.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink',x,t,S.byteLength);let D=`${t}
7
7
  `;yield new L(Uint8Array.from([19]),E(`${x}
8
- `),fe(R.length),E(R),S).subarray(),e.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink',x,t,S.byteLength),c=!0,f=!1,d.resolve(),w().catch(v=>{e.log.error("could not finish optimistic protocol negotiation of %s",t,v)})}m=!0}m||await w()}())};async function w(){if(s){e.log.trace("optimistic: already negotiating %s stream",t),await a.promise;return}s=!0;try{c||(e.log.trace("optimistic: doing send protocol for %s stream",t),await N()),l||(e.log.trace("optimistic: doing read protocol for %s stream",t),await U())}finally{s=!1,i=!0,a.resolve()}}async function N(){if(f){await d.promise;return}f=!0;try{e.log.trace('optimistic: write ["%s", "%s", data] in source',x,t),await u.writeV([E(`${x}
8
+ `),fe(D.length),E(D),S).subarray(),e.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink',x,t,S.byteLength),c=!0,f=!1,d.resolve(),w().catch(U=>{e.log.error("could not finish optimistic protocol negotiation of %s",t,U)})}m=!0}m||await w()}())};async function w(){if(s){e.log.trace("optimistic: already negotiating %s stream",t),await a.promise;return}s=!0;try{c||(e.log.trace("optimistic: doing send protocol for %s stream",t),await N()),l||(e.log.trace("optimistic: doing read protocol for %s stream",t),await v())}finally{s=!1,i=!0,a.resolve()}}async function N(){if(f){await d.promise;return}f=!0;try{e.log.trace('optimistic: write ["%s", "%s", data] in source',x,t),await h.writeV([E(`${x}
9
9
  `),E(`${t}
10
- `)]),e.log.trace('optimistic: wrote ["%s", "%s", data] in source',x,t)}finally{c=!0,f=!1,d.resolve()}}async function U(){if(b){await P.promise;return}b=!0;try{e.log.trace("optimistic: reading multistream select header");let p=await M(u,e);if(e.log.trace('optimistic: read multistream select header "%s"',p),p===x&&(p=await M(u,e)),e.log.trace('optimistic: read protocol "%s", expecting "%s"',p,t),p!==t)throw new V("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}finally{l=!0,b=!1,P.resolve()}}if(r.source=async function*(){await w(),e.log.trace('optimistic: reading data from "%s" stream',t),yield*u.unwrap().source}(),r.closeRead!=null){let p=r.closeRead.bind(r);r.closeRead=async y=>{i||await w().catch(m=>{e.log.error("could not negotiate protocol before close read",m)}),await p(y)}}if(r.closeWrite!=null){let p=r.closeWrite.bind(r);r.closeWrite=async y=>{i||await w().catch(m=>{e.log.error("could not negotiate protocol before close write",m)}),await p(y)}}if(r.close!=null){let p=r.close.bind(r);r.close=async y=>{let m=[];f&&m.push(d.promise),b&&m.push(P.promise),m.length>0?await ae(Promise.all(m),y?.signal):(i=!0,s=!1,a.resolve()),await p(y)}}return{stream:r,protocol:t}}async function kt(r,t,e){t=Array.isArray(t)?t:[t],e.log.trace("handle: available protocols %s",t);let n=Q(r,{...e,maxDataLength:1024,maxLengthLength:2});for(;;){e.log.trace("handle: reading incoming string");let o=await M(n,e);if(e.log.trace('handle: read "%s"',o),o===x){e.log.trace('handle: respond with "%s" for "%s"',x,o),await z(n,E(`${x}
11
- `),e),e.log.trace('handle: responded with "%s" for "%s"',x,o);continue}if(t.includes(o))return e.log.trace('handle: respond with "%s" for "%s"',o,o),await z(n,E(`${o}
12
- `),e),e.log.trace('handle: responded with "%s" for "%s"',o,o),{stream:n.unwrap(),protocol:o};if(o==="ls"){let i=new L(...t.map(s=>k.single(E(`${s}
10
+ `)]),e.log.trace('optimistic: wrote ["%s", "%s", data] in source',x,t)}finally{c=!0,f=!1,d.resolve()}}async function v(){if(b){await M.promise;return}b=!0;try{e.log.trace("optimistic: reading multistream select header");let p=await V(h,e);if(e.log.trace('optimistic: read multistream select header "%s"',p),p===x&&(p=await V(h,e)),e.log.trace('optimistic: read protocol "%s", expecting "%s"',p,t),p!==t)throw new k("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}finally{l=!0,b=!1,M.resolve()}}if(r.source=async function*(){await w(),e.log.trace('optimistic: reading data from "%s" stream',t),yield*h.unwrap().source}(),r.closeRead!=null){let p=r.closeRead.bind(r);r.closeRead=async y=>{i||await w().catch(m=>{e.log.error("could not negotiate protocol before close read",m)}),await p(y)}}if(r.closeWrite!=null){let p=r.closeWrite.bind(r);r.closeWrite=async y=>{i||await w().catch(m=>{e.log.error("could not negotiate protocol before close write",m)}),await p(y)}}if(r.close!=null){let p=r.close.bind(r);r.close=async y=>{let m=[];f&&m.push(d.promise),b&&m.push(M.promise),m.length>0?await ae(Promise.all(m),y?.signal):(i=!0,s=!1,a.resolve()),await p(y)}}return{stream:r,protocol:t}}async function Ft(r,t,e){t=Array.isArray(t)?t:[t],e.log.trace("handle: available protocols %s",t);let n=Q(r,{...e,maxDataLength:1024,maxLengthLength:2});for(;;){e.log.trace("handle: reading incoming string");let o=await V(n,e);if(e.log.trace('handle: read "%s"',o),o===x){e.log.trace('handle: respond with "%s" for "%s"',x,o),await j(n,E(`${x}
11
+ `),e),e.log.trace('handle: responded with "%s" for "%s"',x,o);continue}if(t.includes(o))return e.log.trace('handle: respond with "%s" for "%s"',o,o),await j(n,E(`${o}
12
+ `),e),e.log.trace('handle: responded with "%s" for "%s"',o,o),{stream:n.unwrap(),protocol:o};if(o==="ls"){let i=new L(...t.map(s=>G.single(E(`${s}
13
13
  `))),E(`
14
- `));e.log.trace('handle: respond with "%s" for %s',t,o),await z(n,i,e),e.log.trace('handle: responded with "%s" for %s',t,o);continue}e.log('handle: respond with "na" for "%s"',o),await z(n,E(`na
15
- `),e),e.log('handle: responded with "na" for "%s"',o)}}return Jt(bn);})();
14
+ `));e.log.trace('handle: respond with "%s" for %s',t,o),await j(n,i,e),e.log.trace('handle: responded with "%s" for %s',t,o);continue}e.log('handle: respond with "na" for "%s"',o),await j(n,E(`na
15
+ `),e),e.log('handle: responded with "na" for "%s"',o)}}return jt(pn);})();
16
16
  return Libp2PMultistreamSelect}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/multistream-select",
3
- "version": "5.0.3-c00378909",
3
+ "version": "5.0.3-cd8cafcd5",
4
4
  "description": "JavaScript implementation of multistream-select",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/multistream-select#readme",
@@ -57,7 +57,7 @@
57
57
  "test:electron-main": "aegir test -t electron-main"
58
58
  },
59
59
  "dependencies": {
60
- "@libp2p/interface": "1.0.2-c00378909",
60
+ "@libp2p/interface": "1.0.2-cd8cafcd5",
61
61
  "it-length-prefixed": "^9.0.3",
62
62
  "it-length-prefixed-stream": "^1.1.1",
63
63
  "it-pipe": "^3.0.1",
@@ -69,7 +69,7 @@
69
69
  "uint8arrays": "^5.0.0"
70
70
  },
71
71
  "devDependencies": {
72
- "@libp2p/logger": "4.0.2-c00378909",
72
+ "@libp2p/logger": "4.0.2-cd8cafcd5",
73
73
  "aegir": "^41.0.2",
74
74
  "iso-random-stream": "^2.0.2",
75
75
  "it-all": "^3.0.3",