@libp2p/multistream-select 4.0.8-53224004f → 4.0.8-561797a89

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,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
2
  "use strict";var Libp2PMultistreamSelect=(()=>{var Ft=Object.create;var oe=Object.defineProperty;var Pt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Bt=Object.getPrototypeOf,Vt=Object.prototype.hasOwnProperty;var kt=(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})},Ke=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mt(t))!Vt.call(r,o)&&o!==e&&oe(r,o,{get:()=>t[o],enumerable:!(n=Pt(t,o))||n.enumerable});return r};var Gt=(r,t,e)=>(e=r!=null?Ft(Bt(r)):{},Ke(t||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),zt=r=>Ke(oe({},"__esModule",{value:!0}),r);var at=kt((Co,st)=>{"use strict";function it(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Kt(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 it(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),it(new o,e)}}st.exports=Kt});var un={};R(un,{PROTOCOL_ID:()=>x,handle:()=>_t,select:()=>It});var x="/multistream/1.0.0";var mn=Symbol.for("@libp2p/connection");var wn=Symbol.for("@libp2p/content-routing");var xn=Symbol.for("@libp2p/peer-discovery");var En=Symbol.for("@libp2p/peer-id");var Sn=Symbol.for("@libp2p/peer-routing");var Ye;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ye||(Ye={}));var Dn=Symbol.for("@libp2p/transport");var Qe;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Qe||(Qe={}));var G=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var be=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},_n=globalThis.CustomEvent??be;function M(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function _(r=0){return globalThis.Buffer?.alloc!=null?M(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function T(r=0){return globalThis.Buffer?.allocUnsafe!=null?M(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function ye(r,t){if(globalThis.Buffer!=null)return M(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=T(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return M(e)}function Ze(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 tt=Symbol.for("@achingbrain/uint8arraylist");function et(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?.[tt]}var L=class r{bufs;length;[tt]=!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=et(this.bufs,t);return e.buf[e.index]}set(t,e){let n=et(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 ye(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ye(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 k=this.get(l+b);if(n[b]!==k){d=Math.max(1,b-a[k]);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=T(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=_(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=_(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=_(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=T(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=_(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=_(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=_(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=_(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=_(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(!Ze(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 N(){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 rt(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 xe=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=N(),this.needNext.resolve(),this.haveNext=N()}[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=N(),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=N(),await rt(this.needNext.promise,e?.signal,e)}};function nt(){return new xe}var ae=class extends Error{code;constructor(t,e){super(t),this.code=e}},Le=class extends ae{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function ot(r,t){let e=nt();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 Le("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 ae("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 $t=Math.pow(2,7),jt=Math.pow(2,14),Ht=Math.pow(2,21),Ee=Math.pow(2,28),Ae=Math.pow(2,35),Se=Math.pow(2,42),ve=Math.pow(2,49),u=128,E=127;function F(r){if(r<$t)return 1;if(r<jt)return 2;if(r<Ht)return 3;if(r<Ee)return 4;if(r<Ae)return 5;if(r<Se)return 6;if(r<ve)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xt(r,t,e=0){switch(F(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 qt(r,t,e=0){switch(F(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 Jt(r,t){let e=r[t],n=0;if(n+=e&E,e<u||(e=r[t+1],n+=(e&E)<<7,e<u)||(e=r[t+2],n+=(e&E)<<14,e<u)||(e=r[t+3],n+=(e&E)<<21,e<u)||(e=r[t+4],n+=(e&E)*Ee,e<u)||(e=r[t+5],n+=(e&E)*Ae,e<u)||(e=r[t+6],n+=(e&E)*Se,e<u)||(e=r[t+7],n+=(e&E)*ve,e<u))return n;throw new RangeError("Could not decode varint")}function Wt(r,t){let e=r.get(t),n=0;if(n+=e&E,e<u||(e=r.get(t+1),n+=(e&E)<<7,e<u)||(e=r.get(t+2),n+=(e&E)<<14,e<u)||(e=r.get(t+3),n+=(e&E)<<21,e<u)||(e=r.get(t+4),n+=(e&E)*Ee,e<u)||(e=r.get(t+5),n+=(e&E)*Ae,e<u)||(e=r.get(t+6),n+=(e&E)*Se,e<u)||(e=r.get(t+7),n+=(e&E)*ve,e<u))return n;throw new RangeError("Could not decode varint")}function ce(r,t,e=0){return t==null&&(t=T(F(r))),t instanceof Uint8Array?Xt(r,t,e):qt(r,t,e)}function fe(r,t=0){return r instanceof Uint8Array?Jt(r,t):Wt(r,t)}function he(r){return r[Symbol.asyncIterator]!=null}var ue=r=>{let t=F(r),e=T(t);return ce(r,e),ue.bytes=t,e};ue.bytes=0;function z(r,t){t=t??{};let e=t.lengthEncoder??ue;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)}()}z.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ue;return new L(e(r.byteLength),r)};var X=Gt(at(),1);var Yt=8,Qt=1024*1024*4,$;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})($||($={}));var Ue=r=>{let t=fe(r);return Ue.bytes=F(t),t};Ue.bytes=0;function Re(r,t){let e=new L,n=$.LENGTH,o=-1,i=t?.lengthDecoder??Ue,s=t?.maxLengthLength??Yt,a=t?.maxDataLength??Qt;function*c(){for(;e.byteLength>0;){if(n===$.LENGTH)try{if(o=i(e),o<0)throw(0,X.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,X.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=$.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>s)throw(0,X.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===$.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=$.LENGTH}}}return he(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,X.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,X.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 de=class extends Error{code;constructor(t,e){super(t),this.code=e}},ct=r=>fe(r);ct.bytes=0;function Q(r,t={}){let e=ot(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=F(t.maxDataLength)),{read:async o=>{let i=-1,s=new L,a=t?.lengthDecoder??ct;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 de("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new de("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(z.single(o,t),i)},writeV:async(o,i)=>{let s=new L(...o.map(a=>z.single(a,t)));await e.write(s,i)},unwrap:()=>e.unwrap()}}var Ce={};R(Ce,{base10:()=>ir});function er(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 g=0,C=0,v=0,p=h.length;v!==p&&h[v]===0;)v++,g++;for(var y=(p-v)*d+1>>>0,w=new Uint8Array(y);v!==p;){for(var S=h[v],U=0,D=y-1;(S!==0||U<C)&&D!==-1;D--,U++)S+=256*w[D]>>>0,w[D]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");C=U,v++}for(var I=y-C;I!==y&&w[I]===0;)I++;for(var ne=c.repeat(g);I<y;++I)ne+=r.charAt(w[I]);return ne}function b(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var g=0;if(h[g]!==" "){for(var C=0,v=0;h[g]===c;)C++,g++;for(var p=(h.length-g)*f+1>>>0,y=new Uint8Array(p);h[g];){var w=e[h.charCodeAt(g)];if(w===255)return;for(var S=0,U=p-1;(w!==0||S<v)&&U!==-1;U--,S++)w+=a*y[U]>>>0,y[U]=w%256>>>0,w=w/256>>>0;if(w!==0)throw new Error("Non-zero carry");v=S,g++}if(h[g]!==" "){for(var D=p-v;D!==p&&y[D]===0;)D++;for(var I=new Uint8Array(C+(p-D)),ne=C;D!==p;)I[ne++]=y[D++];return I}}}function k(h){var g=b(h);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:k}}var tr=er,rr=tr,ft=rr;var zo=new Uint8Array(0);var lt=(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},P=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 ht=r=>new TextEncoder().encode(r),ut=r=>new TextDecoder().decode(r);var De=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")}},Te=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 pt(this,t)}},Ne=class{constructor(t){this.decoders=t}or(t){return pt(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`)}},pt=(r,t)=>new Ne({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),Oe=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new De(t,e,n),this.decoder=new Te(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},q=({name:r,prefix:t,encode:e,decode:n})=>new Oe(r,t,e,n),B=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=ft(e,t);return q({prefix:r,name:t,encode:n,decode:i=>P(o(i))})},nr=(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},or=(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},m=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>q({prefix:t,name:r,encode(o){return or(o,n,e)},decode(o){return nr(o,n,e,r)}});var ir=B({prefix:"9",name:"base10",alphabet:"0123456789"});var Ie={};R(Ie,{base16:()=>sr,base16upper:()=>ar});var sr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ar=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _e={};R(_e,{base2:()=>cr});var cr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Fe={};R(Fe,{base256emoji:()=>dr});var mt=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}"),fr=mt.reduce((r,t,e)=>(r[e]=t,r),[]),lr=mt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function hr(r){return r.reduce((t,e)=>(t+=fr[e],t),"")}function ur(r){let t=[];for(let e of r){let n=lr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var dr=q({prefix:"\u{1F680}",name:"base256emoji",encode:hr,decode:ur});var Pe={};R(Pe,{base32:()=>J,base32hex:()=>wr,base32hexpad:()=>yr,base32hexpadupper:()=>xr,base32hexupper:()=>br,base32pad:()=>mr,base32padupper:()=>gr,base32upper:()=>pr,base32z:()=>Lr});var J=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),mr=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gr=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wr=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),br=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Lr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Me={};R(Me,{base36:()=>Er,base36upper:()=>Ar});var Er=B({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ar=B({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Be={};R(Be,{base58btc:()=>O,base58flickr:()=>Sr});var O=B({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sr=B({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ve={};R(Ve,{base64:()=>vr,base64pad:()=>Rr,base64url:()=>Ur,base64urlpad:()=>Dr});var vr=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Rr=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ur=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ke={};R(ke,{base8:()=>Tr});var Tr=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ge={};R(Ge,{identity:()=>Nr});var Nr=q({prefix:"\0",name:"identity",encode:r=>ut(r),decode:r=>ht(r)});var ni=new TextEncoder,oi=new TextDecoder;var $e={};R($e,{identity:()=>Zr});var Ir=bt,gt=128,_r=127,Fr=~_r,Pr=Math.pow(2,31);function bt(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Pr;)t[e++]=r&255|gt,r/=128;for(;r&Fr;)t[e++]=r&255|gt,r>>>=7;return t[e]=r|0,bt.bytes=e-n+1,t}var Mr=ze,Br=128,wt=127;function ze(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw ze.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&wt)<<o:(s&wt)*Math.pow(2,o),o+=7}while(s>=Br);return ze.bytes=i-n,e}var Vr=Math.pow(2,7),kr=Math.pow(2,14),Gr=Math.pow(2,21),zr=Math.pow(2,28),$r=Math.pow(2,35),jr=Math.pow(2,42),Hr=Math.pow(2,49),Xr=Math.pow(2,56),qr=Math.pow(2,63),Jr=function(r){return r<Vr?1:r<kr?2:r<Gr?3:r<zr?4:r<$r?5:r<jr?6:r<Hr?7:r<Xr?8:r<qr?9:10},Wr={encode:Ir,decode:Mr,encodingLength:Jr},Kr=Wr,Z=Kr;var ee=(r,t=0)=>[Z.decode(r,t),Z.decode.bytes],W=(r,t,e=0)=>(Z.encode(r,t,e),t),K=r=>Z.encodingLength(r);var j=(r,t)=>{let e=t.byteLength,n=K(r),o=n+K(e),i=new Uint8Array(o+e);return W(r,i,0),W(e,i,n),i.set(t,o),new Y(r,e,t,i)},yt=r=>{let t=P(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 Y(e,o,s,t)},xt=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&lt(r.bytes,e.bytes)}},Y=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Lt=0,Yr="identity",Et=P,Qr=r=>j(Lt,Et(r)),Zr={code:Lt,name:Yr,encode:Et,digest:Qr};var Xe={};R(Xe,{sha256:()=>en,sha512:()=>tn});var He=({name:r,code:t,encode:e})=>new je(r,t,e),je=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?j(this.code,e):e.then(n=>j(this.code,n))}else throw Error("Unknown type, must be binary type")}};var St=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),en=He({name:"sha2-256",code:18,encode:St("SHA-256")}),tn=He({name:"sha2-512",code:19,encode:St("SHA-512")});var vt=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return nn(e,qe(r),t||O.encoder);default:return on(e,qe(r),t||J.encoder)}};var Rt=new WeakMap,qe=r=>{let t=Rt.get(r);if(t==null){let e=new Map;return Rt.set(r,e),e}return t},me=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!==sn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=j(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&xt(t.multihash,n.multihash)}toString(t){return vt(this,t)}toJSON(){return{"/":vt(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||Ut(n,o,i.bytes))}else if(e[an]===!0){let{version:n,multihash:o,code:i}=e,s=yt(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=Ut(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=P(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 Y(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]=rn(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 qe(i).set(n,t),i}},rn=(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 J.prefix:{let e=t||J;return[J.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)]}}},nn=(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},on=(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,sn=18,Ut=(r,t,e)=>{let n=K(r),o=n+K(t),i=new Uint8Array(o+e.byteLength);return W(r,i,0),W(t,i,n),i.set(e,o),i},an=Symbol.for("@ipld/js-cid/CID");var Je={...Ge,..._e,...ke,...Ce,...Ie,...Pe,...Me,...Be,...Ve,...Fe},xi={...Xe,...$e};function Tt(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Dt=Tt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),We=Tt("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=T(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),cn={utf8:Dt,"utf-8":Dt,hex:Je.base16,latin1:We,ascii:We,binary:We,...Je},ge=cn;function A(r,t="utf8"){let e=ge[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?M(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Nt(r,t="utf8"){let e=ge[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 fn=A(`
3
- `);async function H(r,t,e){await r.write(t,e)}async function Ot(r,t,e){await r.writeV(t,e)}async function ln(r,t){let e=await r.read(t);if(e.byteLength===0||e.get(e.byteLength-1)!==fn[0])throw t?.log.error("Invalid mss message - missing newline",e),new G("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return e.sublist(0,-1)}async function V(r,t){let e=await ln(r,t);return Nt(e.subarray())}async function It(r,t,e){if(t=Array.isArray(t)?[...t]:[t],t.length===1)return hn(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=A(`${x}
3
+ `);async function H(r,t,e){await r.write(t,e)}async function Ot(r,t,e){await r.writeV(t,e)}async function ln(r,t){let e=await r.read(t);if(e.byteLength===0||e.get(e.byteLength-1)!==fn[0])throw t?.log?.error("Invalid mss message - missing newline",e),new G("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return e.sublist(0,-1)}async function V(r,t){let e=await ln(r,t);return Nt(e.subarray())}async function It(r,t,e){if(t=Array.isArray(t)?[...t]:[t],t.length===1)return hn(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=A(`${x}
4
4
  `),s=A(`${o}
5
- `);await Ot(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 H(n,A(`${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 G("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}function hn(r,t,e){let n=r.sink.bind(r),o=r.source,i=!1,s=!1,a=N(),c=!1,f=!1,d=N(),l=!1,b=!1,k=N(),h=Q({sink:n,source:o},{...e,maxDataLength:1024});r.sink=async p=>{let{sink:y}=h.unwrap();await y(async function*(){let w=!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 U=`${t}
5
+ `);await Ot(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 H(n,A(`${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 G("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}function hn(r,t,e){let n=r.sink.bind(r),o=r.source,i=!1,s=!1,a=N(),c=!1,f=!1,d=N(),l=!1,b=!1,k=N(),h=Q({sink:n,source:o},{...e,maxDataLength:1024});r.sink=async p=>{let{sink:y}=h.unwrap();await y(async function*(){let w=!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 U=`${t}
7
7
  `;yield new L(Uint8Array.from([19]),A(`${x}
8
- `),ce(U.length),A(U),S).subarray(),e?.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink',x,t,S.byteLength),c=!0,f=!1,d.resolve()}w=!0}w||await g()}())};async function g(){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 C()),l||(e?.log.trace("optimistic: doing read protocol for %s stream",t),await v())}finally{s=!1,i=!0,a.resolve()}}async function C(){if(f){await d.promise;return}f=!0;try{e?.log.trace('optimistic: write ["%s", "%s", data] in source',x,t),await h.writeV([A(`${x}
8
+ `),ce(U.length),A(U),S).subarray(),e?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink',x,t,S.byteLength),c=!0,f=!1,d.resolve()}w=!0}w||await g()}())};async function g(){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 C()),l||(e?.log?.trace("optimistic: doing read protocol for %s stream",t),await v())}finally{s=!1,i=!0,a.resolve()}}async function C(){if(f){await d.promise;return}f=!0;try{e?.log?.trace('optimistic: write ["%s", "%s", data] in source',x,t),await h.writeV([A(`${x}
9
9
  `),A(`${t}
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 k.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 G("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}finally{l=!0,b=!1,k.resolve()}}if(r.source=async function*(){await g(),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 g().catch(w=>{e?.log.error("could not negotiate protocol before close read",w)}),await p(y)}}if(r.closeWrite!=null){let p=r.closeWrite.bind(r);r.closeWrite=async y=>{i||await g().catch(w=>{e?.log.error("could not negotiate protocol before close write",w)}),await p(y)}}if(r.close!=null){let p=r.close.bind(r);r.close=async y=>{i||(i=!0,s=!1,a.resolve()),await p(y)}}return{stream:r,protocol:t}}async function _t(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 H(n,A(`${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 H(n,A(`${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=>z.single(A(`${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 k.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 G("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}finally{l=!0,b=!1,k.resolve()}}if(r.source=async function*(){await g(),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 g().catch(w=>{e?.log?.error("could not negotiate protocol before close read",w)}),await p(y)}}if(r.closeWrite!=null){let p=r.closeWrite.bind(r);r.closeWrite=async y=>{i||await g().catch(w=>{e?.log?.error("could not negotiate protocol before close write",w)}),await p(y)}}if(r.close!=null){let p=r.close.bind(r);r.close=async y=>{i||(i=!0,s=!1,a.resolve()),await p(y)}}return{stream:r,protocol:t}}async function _t(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 H(n,A(`${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 H(n,A(`${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=>z.single(A(`${s}
13
13
  `))),A(`
14
- `));e.log.trace('handle: respond with "%s" for %s',t,o),await H(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 H(n,A(`na
15
- `),e),e.log('handle: responded with "na" for "%s"',o)}}return zt(un);})();
14
+ `));e?.log?.trace('handle: respond with "%s" for %s',t,o),await H(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 H(n,A(`na
15
+ `),e),e?.log?.('handle: responded with "na" for "%s"',o)}}return zt(un);})();
16
16
  return Libp2PMultistreamSelect}));
@@ -52,39 +52,39 @@ import * as multistream from './multistream.js';
52
52
  */
53
53
  export async function handle(stream, protocols, options) {
54
54
  protocols = Array.isArray(protocols) ? protocols : [protocols];
55
- options.log.trace('handle: available protocols %s', protocols);
55
+ options?.log?.trace('handle: available protocols %s', protocols);
56
56
  const lp = lpStream(stream, {
57
57
  ...options,
58
58
  maxDataLength: MAX_PROTOCOL_LENGTH,
59
59
  maxLengthLength: 2 // 2 bytes is enough to length-prefix MAX_PROTOCOL_LENGTH
60
60
  });
61
61
  while (true) {
62
- options?.log.trace('handle: reading incoming string');
62
+ options?.log?.trace('handle: reading incoming string');
63
63
  const protocol = await multistream.readString(lp, options);
64
- options.log.trace('handle: read "%s"', protocol);
64
+ options?.log?.trace('handle: read "%s"', protocol);
65
65
  if (protocol === PROTOCOL_ID) {
66
- options.log.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol);
66
+ options?.log?.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol);
67
67
  await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options);
68
- options.log.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol);
68
+ options?.log?.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol);
69
69
  continue;
70
70
  }
71
71
  if (protocols.includes(protocol)) {
72
- options.log.trace('handle: respond with "%s" for "%s"', protocol, protocol);
72
+ options?.log?.trace('handle: respond with "%s" for "%s"', protocol, protocol);
73
73
  await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options);
74
- options.log.trace('handle: responded with "%s" for "%s"', protocol, protocol);
74
+ options?.log?.trace('handle: responded with "%s" for "%s"', protocol, protocol);
75
75
  return { stream: lp.unwrap(), protocol };
76
76
  }
77
77
  if (protocol === 'ls') {
78
78
  // <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n\n
79
79
  const protos = new Uint8ArrayList(...protocols.map(p => encode.single(uint8ArrayFromString(`${p}\n`))), uint8ArrayFromString('\n'));
80
- options.log.trace('handle: respond with "%s" for %s', protocols, protocol);
80
+ options?.log?.trace('handle: respond with "%s" for %s', protocols, protocol);
81
81
  await multistream.write(lp, protos, options);
82
- options.log.trace('handle: responded with "%s" for %s', protocols, protocol);
82
+ options?.log?.trace('handle: responded with "%s" for %s', protocols, protocol);
83
83
  continue;
84
84
  }
85
- options.log('handle: respond with "na" for "%s"', protocol);
85
+ options?.log?.('handle: respond with "na" for "%s"', protocol);
86
86
  await multistream.write(lp, uint8ArrayFromString('na\n'), options);
87
- options.log('handle: responded with "na" for "%s"', protocol);
87
+ options?.log?.('handle: responded with "na" for "%s"', protocol);
88
88
  }
89
89
  }
90
90
  //# sourceMappingURL=handle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA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YAC5C,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,oCAAoC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;YAC9E,SAAQ;QACV,CAAC;QAED,OAAO,EAAE,GAAG,EAAE,CAAC,oCAAoC,EAAE,QAAQ,CAAC,CAAA;QAC9D,MAAM,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,oBAAoB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAA;QAClE,OAAO,EAAE,GAAG,EAAE,CAAC,sCAAsC,EAAE,QAAQ,CAAC,CAAA;IAClE,CAAC;AACH,CAAC"}
@@ -21,7 +21,7 @@ export async function writeAll(writer, buffers, options) {
21
21
  export async function read(reader, options) {
22
22
  const buf = await reader.read(options);
23
23
  if (buf.byteLength === 0 || buf.get(buf.byteLength - 1) !== NewLine[0]) {
24
- options?.log.error('Invalid mss message - missing newline', buf);
24
+ options?.log?.error('Invalid mss message - missing newline', buf);
25
25
  throw new CodeError('missing newline', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE');
26
26
  }
27
27
  return buf.sublist(0, -1); // Remove newline
@@ -1 +1 @@
1
- {"version":3,"file":"multistream.js","sourceRoot":"","sources":["../../src/multistream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAuB,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAMtE,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAA;AAE1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,MAAqG,EAAE,MAAmC,EAAE,OAA+B;IACtM,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC;AAED;;GAEG;AACH,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AO,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAA;AAE1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,MAAqG,EAAE,MAAmC,EAAE,OAA+B;IACtM,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAE,MAAqG,EAAE,OAAqB,EAAE,OAA+B;IAC3L,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAE,MAAqG,EAAE,OAAsC;IACvK,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEtC,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAA;QACjE,MAAM,IAAI,SAAS,CAAC,iBAAiB,EAAE,wCAAwC,CAAC,CAAA;IAClF,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,CAAC,iBAAiB;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAE,MAAqG,EAAE,OAAsC;IAC7K,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEvC,OAAO,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;AAC3C,CAAC"}
@@ -63,18 +63,18 @@ export async function select(stream, protocols, options) {
63
63
  if (protocol == null) {
64
64
  throw new Error('At least one protocol must be specified');
65
65
  }
66
- options?.log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol);
66
+ options?.log?.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol);
67
67
  const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`);
68
68
  const p2 = uint8ArrayFromString(`${protocol}\n`);
69
69
  await multistream.writeAll(lp, [p1, p2], options);
70
- options?.log.trace('select: reading multistream-select header');
70
+ options?.log?.trace('select: reading multistream-select header');
71
71
  let response = await multistream.readString(lp, options);
72
- options?.log.trace('select: read "%s"', response);
72
+ options?.log?.trace('select: read "%s"', response);
73
73
  // Read the protocol response if we got the protocolId in return
74
74
  if (response === PROTOCOL_ID) {
75
- options?.log.trace('select: reading protocol response');
75
+ options?.log?.trace('select: reading protocol response');
76
76
  response = await multistream.readString(lp, options);
77
- options?.log.trace('select: read "%s"', response);
77
+ options?.log?.trace('select: read "%s"', response);
78
78
  }
79
79
  // We're done
80
80
  if (response === protocol) {
@@ -82,11 +82,11 @@ export async function select(stream, protocols, options) {
82
82
  }
83
83
  // We haven't gotten a valid ack, try the other protocols
84
84
  for (const protocol of protocols) {
85
- options?.log.trace('select: write "%s"', protocol);
85
+ options?.log?.trace('select: write "%s"', protocol);
86
86
  await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options);
87
- options?.log.trace('select: reading protocol response');
87
+ options?.log?.trace('select: reading protocol response');
88
88
  const response = await multistream.readString(lp, options);
89
- options?.log.trace('select: read "%s" for "%s"', response, protocol);
89
+ options?.log?.trace('select: read "%s" for "%s"', response, protocol);
90
90
  if (response === protocol) {
91
91
  return { stream: lp.unwrap(), protocol };
92
92
  }
@@ -132,12 +132,12 @@ function optimisticSelect(stream, protocol, options) {
132
132
  // writing before reading, send the protocol and the first chunk of data
133
133
  if (!sentProtocol) {
134
134
  sendingProtocol = true;
135
- options?.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
135
+ options?.log?.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
136
136
  const protocolString = `${protocol}\n`;
137
137
  // send protocols in first chunk of data written to transport
138
138
  yield new Uint8ArrayList(Uint8Array.from([19]), // length of PROTOCOL_ID plus newline
139
139
  uint8ArrayFromString(`${PROTOCOL_ID}\n`), varint.encode(protocolString.length), uint8ArrayFromString(protocolString), buf).subarray();
140
- options?.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
140
+ options?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
141
141
  sentProtocol = true;
142
142
  sendingProtocol = false;
143
143
  doneSendingProtocol.resolve();
@@ -156,7 +156,7 @@ function optimisticSelect(stream, protocol, options) {
156
156
  };
157
157
  async function negotiate() {
158
158
  if (negotiating) {
159
- options?.log.trace('optimistic: already negotiating %s stream', protocol);
159
+ options?.log?.trace('optimistic: already negotiating %s stream', protocol);
160
160
  await doneNegotiating.promise;
161
161
  return;
162
162
  }
@@ -164,12 +164,12 @@ function optimisticSelect(stream, protocol, options) {
164
164
  try {
165
165
  // we haven't sent the protocol yet, send it now
166
166
  if (!sentProtocol) {
167
- options?.log.trace('optimistic: doing send protocol for %s stream', protocol);
167
+ options?.log?.trace('optimistic: doing send protocol for %s stream', protocol);
168
168
  await doSendProtocol();
169
169
  }
170
170
  // if we haven't read the protocol response yet, do it now
171
171
  if (!readProtocol) {
172
- options?.log.trace('optimistic: doing read protocol for %s stream', protocol);
172
+ options?.log?.trace('optimistic: doing read protocol for %s stream', protocol);
173
173
  await doReadProtocol();
174
174
  }
175
175
  }
@@ -186,12 +186,12 @@ function optimisticSelect(stream, protocol, options) {
186
186
  }
187
187
  sendingProtocol = true;
188
188
  try {
189
- options?.log.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
189
+ options?.log?.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
190
190
  await lp.writeV([
191
191
  uint8ArrayFromString(`${PROTOCOL_ID}\n`),
192
192
  uint8ArrayFromString(`${protocol}\n`)
193
193
  ]);
194
- options?.log.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
194
+ options?.log?.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
195
195
  }
196
196
  finally {
197
197
  sentProtocol = true;
@@ -206,13 +206,13 @@ function optimisticSelect(stream, protocol, options) {
206
206
  }
207
207
  readingProtocol = true;
208
208
  try {
209
- options?.log.trace('optimistic: reading multistream select header');
209
+ options?.log?.trace('optimistic: reading multistream select header');
210
210
  let response = await multistream.readString(lp, options);
211
- options?.log.trace('optimistic: read multistream select header "%s"', response);
211
+ options?.log?.trace('optimistic: read multistream select header "%s"', response);
212
212
  if (response === PROTOCOL_ID) {
213
213
  response = await multistream.readString(lp, options);
214
214
  }
215
- options?.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol);
215
+ options?.log?.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol);
216
216
  if (response !== protocol) {
217
217
  throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL');
218
218
  }
@@ -226,7 +226,7 @@ function optimisticSelect(stream, protocol, options) {
226
226
  stream.source = (async function* () {
227
227
  // make sure we've done protocol negotiation before we read stream data
228
228
  await negotiate();
229
- options?.log.trace('optimistic: reading data from "%s" stream', protocol);
229
+ options?.log?.trace('optimistic: reading data from "%s" stream', protocol);
230
230
  yield* lp.unwrap().source;
231
231
  })();
232
232
  if (stream.closeRead != null) {
@@ -236,7 +236,7 @@ function optimisticSelect(stream, protocol, options) {
236
236
  // this before closing the readable end of the stream
237
237
  if (!negotiated) {
238
238
  await negotiate().catch(err => {
239
- options?.log.error('could not negotiate protocol before close read', err);
239
+ options?.log?.error('could not negotiate protocol before close read', err);
240
240
  });
241
241
  }
242
242
  // protocol has been negotiated, ok to close the readable end
@@ -250,7 +250,7 @@ function optimisticSelect(stream, protocol, options) {
250
250
  // this before closing the writable end of the stream
251
251
  if (!negotiated) {
252
252
  await negotiate().catch(err => {
253
- options?.log.error('could not negotiate protocol before close write', err);
253
+ options?.log?.error('could not negotiate protocol before close write', err);
254
254
  });
255
255
  }
256
256
  // protocol has been negotiated, ok to close the writable end
@@ -1 +1 @@
1
- {"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAYxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAgC,MAAc,EAAE,SAA4B,EAAE,OAA8B;IACtI,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEnE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE;QAC1B,GAAG,OAAO;QACV,aAAa,EAAE,mBAAmB;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",
3
- "version": "4.0.8-53224004f",
3
+ "version": "4.0.8-561797a89",
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.1-53224004f",
60
+ "@libp2p/interface": "1.0.1-561797a89",
61
61
  "it-length-prefixed": "^9.0.3",
62
62
  "it-length-prefixed-stream": "^1.1.1",
63
63
  "it-pipe": "^3.0.1",
@@ -68,7 +68,7 @@
68
68
  "uint8arrays": "^4.0.6"
69
69
  },
70
70
  "devDependencies": {
71
- "@libp2p/logger": "4.0.1-53224004f",
71
+ "@libp2p/logger": "4.0.1-561797a89",
72
72
  "aegir": "^41.0.2",
73
73
  "iso-random-stream": "^2.0.2",
74
74
  "it-all": "^3.0.3",
package/src/handle.ts CHANGED
@@ -55,7 +55,7 @@ import type { Duplex } from 'it-stream-types'
55
55
  */
56
56
  export async function handle <Stream extends Duplex<any, any, any>> (stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>> {
57
57
  protocols = Array.isArray(protocols) ? protocols : [protocols]
58
- options.log.trace('handle: available protocols %s', protocols)
58
+ options?.log?.trace('handle: available protocols %s', protocols)
59
59
 
60
60
  const lp = lpStream(stream, {
61
61
  ...options,
@@ -64,21 +64,21 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
64
64
  })
65
65
 
66
66
  while (true) {
67
- options?.log.trace('handle: reading incoming string')
67
+ options?.log?.trace('handle: reading incoming string')
68
68
  const protocol = await multistream.readString(lp, options)
69
- options.log.trace('handle: read "%s"', protocol)
69
+ options?.log?.trace('handle: read "%s"', protocol)
70
70
 
71
71
  if (protocol === PROTOCOL_ID) {
72
- options.log.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
72
+ options?.log?.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
73
73
  await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options)
74
- options.log.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
74
+ options?.log?.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
75
75
  continue
76
76
  }
77
77
 
78
78
  if (protocols.includes(protocol)) {
79
- options.log.trace('handle: respond with "%s" for "%s"', protocol, protocol)
79
+ options?.log?.trace('handle: respond with "%s" for "%s"', protocol, protocol)
80
80
  await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
81
- options.log.trace('handle: responded with "%s" for "%s"', protocol, protocol)
81
+ options?.log?.trace('handle: responded with "%s" for "%s"', protocol, protocol)
82
82
 
83
83
  return { stream: lp.unwrap(), protocol }
84
84
  }
@@ -90,14 +90,14 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
90
90
  uint8ArrayFromString('\n')
91
91
  )
92
92
 
93
- options.log.trace('handle: respond with "%s" for %s', protocols, protocol)
93
+ options?.log?.trace('handle: respond with "%s" for %s', protocols, protocol)
94
94
  await multistream.write(lp, protos, options)
95
- options.log.trace('handle: responded with "%s" for %s', protocols, protocol)
95
+ options?.log?.trace('handle: responded with "%s" for %s', protocols, protocol)
96
96
  continue
97
97
  }
98
98
 
99
- options.log('handle: respond with "na" for "%s"', protocol)
99
+ options?.log?.('handle: respond with "na" for "%s"', protocol)
100
100
  await multistream.write(lp, uint8ArrayFromString('na\n'), options)
101
- options.log('handle: responded with "na" for "%s"', protocol)
101
+ options?.log?.('handle: responded with "na" for "%s"', protocol)
102
102
  }
103
103
  }
@@ -30,7 +30,7 @@ export async function read (reader: LengthPrefixedStream<Duplex<AsyncGenerator<U
30
30
  const buf = await reader.read(options)
31
31
 
32
32
  if (buf.byteLength === 0 || buf.get(buf.byteLength - 1) !== NewLine[0]) {
33
- options?.log.error('Invalid mss message - missing newline', buf)
33
+ options?.log?.error('Invalid mss message - missing newline', buf)
34
34
  throw new CodeError('missing newline', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
35
35
  }
36
36
 
package/src/select.ts CHANGED
@@ -78,20 +78,20 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
78
78
  throw new Error('At least one protocol must be specified')
79
79
  }
80
80
 
81
- options?.log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
81
+ options?.log?.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
82
82
  const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`)
83
83
  const p2 = uint8ArrayFromString(`${protocol}\n`)
84
84
  await multistream.writeAll(lp, [p1, p2], options)
85
85
 
86
- options?.log.trace('select: reading multistream-select header')
86
+ options?.log?.trace('select: reading multistream-select header')
87
87
  let response = await multistream.readString(lp, options)
88
- options?.log.trace('select: read "%s"', response)
88
+ options?.log?.trace('select: read "%s"', response)
89
89
 
90
90
  // Read the protocol response if we got the protocolId in return
91
91
  if (response === PROTOCOL_ID) {
92
- options?.log.trace('select: reading protocol response')
92
+ options?.log?.trace('select: reading protocol response')
93
93
  response = await multistream.readString(lp, options)
94
- options?.log.trace('select: read "%s"', response)
94
+ options?.log?.trace('select: read "%s"', response)
95
95
  }
96
96
 
97
97
  // We're done
@@ -101,11 +101,11 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
101
101
 
102
102
  // We haven't gotten a valid ack, try the other protocols
103
103
  for (const protocol of protocols) {
104
- options?.log.trace('select: write "%s"', protocol)
104
+ options?.log?.trace('select: write "%s"', protocol)
105
105
  await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
106
- options?.log.trace('select: reading protocol response')
106
+ options?.log?.trace('select: reading protocol response')
107
107
  const response = await multistream.readString(lp, options)
108
- options?.log.trace('select: read "%s" for "%s"', response, protocol)
108
+ options?.log?.trace('select: read "%s" for "%s"', response, protocol)
109
109
 
110
110
  if (response === protocol) {
111
111
  return { stream: lp.unwrap(), protocol }
@@ -163,7 +163,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
163
163
  if (!sentProtocol) {
164
164
  sendingProtocol = true
165
165
 
166
- options?.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
166
+ options?.log?.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
167
167
 
168
168
  const protocolString = `${protocol}\n`
169
169
 
@@ -176,7 +176,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
176
176
  buf
177
177
  ).subarray()
178
178
 
179
- options?.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
179
+ options?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
180
180
 
181
181
  sentProtocol = true
182
182
  sendingProtocol = false
@@ -198,7 +198,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
198
198
 
199
199
  async function negotiate (): Promise<void> {
200
200
  if (negotiating) {
201
- options?.log.trace('optimistic: already negotiating %s stream', protocol)
201
+ options?.log?.trace('optimistic: already negotiating %s stream', protocol)
202
202
  await doneNegotiating.promise
203
203
  return
204
204
  }
@@ -208,13 +208,13 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
208
208
  try {
209
209
  // we haven't sent the protocol yet, send it now
210
210
  if (!sentProtocol) {
211
- options?.log.trace('optimistic: doing send protocol for %s stream', protocol)
211
+ options?.log?.trace('optimistic: doing send protocol for %s stream', protocol)
212
212
  await doSendProtocol()
213
213
  }
214
214
 
215
215
  // if we haven't read the protocol response yet, do it now
216
216
  if (!readProtocol) {
217
- options?.log.trace('optimistic: doing read protocol for %s stream', protocol)
217
+ options?.log?.trace('optimistic: doing read protocol for %s stream', protocol)
218
218
  await doReadProtocol()
219
219
  }
220
220
  } finally {
@@ -233,12 +233,12 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
233
233
  sendingProtocol = true
234
234
 
235
235
  try {
236
- options?.log.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
236
+ options?.log?.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
237
237
  await lp.writeV([
238
238
  uint8ArrayFromString(`${PROTOCOL_ID}\n`),
239
239
  uint8ArrayFromString(`${protocol}\n`)
240
240
  ])
241
- options?.log.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
241
+ options?.log?.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
242
242
  } finally {
243
243
  sentProtocol = true
244
244
  sendingProtocol = false
@@ -255,15 +255,15 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
255
255
  readingProtocol = true
256
256
 
257
257
  try {
258
- options?.log.trace('optimistic: reading multistream select header')
258
+ options?.log?.trace('optimistic: reading multistream select header')
259
259
  let response = await multistream.readString(lp, options)
260
- options?.log.trace('optimistic: read multistream select header "%s"', response)
260
+ options?.log?.trace('optimistic: read multistream select header "%s"', response)
261
261
 
262
262
  if (response === PROTOCOL_ID) {
263
263
  response = await multistream.readString(lp, options)
264
264
  }
265
265
 
266
- options?.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol)
266
+ options?.log?.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol)
267
267
 
268
268
  if (response !== protocol) {
269
269
  throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL')
@@ -279,7 +279,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
279
279
  // make sure we've done protocol negotiation before we read stream data
280
280
  await negotiate()
281
281
 
282
- options?.log.trace('optimistic: reading data from "%s" stream', protocol)
282
+ options?.log?.trace('optimistic: reading data from "%s" stream', protocol)
283
283
  yield * lp.unwrap().source
284
284
  })()
285
285
 
@@ -291,7 +291,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
291
291
  // this before closing the readable end of the stream
292
292
  if (!negotiated) {
293
293
  await negotiate().catch(err => {
294
- options?.log.error('could not negotiate protocol before close read', err)
294
+ options?.log?.error('could not negotiate protocol before close read', err)
295
295
  })
296
296
  }
297
297
 
@@ -308,7 +308,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
308
308
  // this before closing the writable end of the stream
309
309
  if (!negotiated) {
310
310
  await negotiate().catch(err => {
311
- options?.log.error('could not negotiate protocol before close write', err)
311
+ options?.log?.error('could not negotiate protocol before close write', err)
312
312
  })
313
313
  }
314
314