@libp2p/multistream-select 5.1.0 → 5.1.1-900236724
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 +14 -14
- package/package.json +5 -5
- package/dist/typedoc-urls.json +0 -9
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 Vt=Object.create;var oe=Object.defineProperty;var kt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var zt=Object.getPrototypeOf,$t=Object.prototype.hasOwnProperty;var jt=(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})},Ze=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Gt(t))!$t.call(r,o)&&o!==e&&oe(r,o,{get:()=>t[o],enumerable:!(n=kt(t,o))||n.enumerable});return r};var Ht=(r,t,e)=>(e=r!=null?Vt(zt(r)):{},Ze(t||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),Xt=r=>Ze(oe({},"__esModule",{value:!0}),r);var ut=jt((jo,lt)=>{"use strict";function ft(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function er(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 ft(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),ft(new o,e)}}lt.exports=er});var gn={};R(gn,{PROTOCOL_ID:()=>x,handle:()=>Mt,select:()=>Pt});var x="/multistream/1.0.0";var yn=Symbol.for("@libp2p/connection");var Ln=Symbol.for("@libp2p/content-routing");var Sn=Symbol.for("@libp2p/peer-discovery");var Un=Symbol.for("@libp2p/peer-id");var Tn=Symbol.for("@libp2p/peer-routing");var et;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(et||(et={}));var Cn=Symbol.for("@libp2p/transport");var tt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(tt||(tt={}));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 Le=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},Fn=globalThis.CustomEvent??Le;function K(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function _(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 Ae(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 rt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var ot=Symbol.for("@achingbrain/uint8arraylist");function nt(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?.[ot]}var L=class r{bufs;length;[ot]=!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=nt(this.bufs,t);return e.buf[e.index]}set(t,e){let n=nt(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 Ae(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ae(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 B=this.get(l+b);if(n[b]!==B){d=Math.max(1,b-a[B]);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=_(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=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=_(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(!rt(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 Ee=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 it(){return new Ee}var ce=class extends Error{code;constructor(t,e){super(t),this.code=e}},Se=class extends ce{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function st(r,t){let e=it();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 Se("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 fe(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function le(r=0){return globalThis.Buffer?.allocUnsafe!=null?fe(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var qt=Math.pow(2,7),Jt=Math.pow(2,14),Wt=Math.pow(2,21),ve=Math.pow(2,28),Ue=Math.pow(2,35),Re=Math.pow(2,42),Te=Math.pow(2,49),h=128,A=127;function I(r){if(r<qt)return 1;if(r<Jt)return 2;if(r<Wt)return 3;if(r<ve)return 4;if(r<Ue)return 5;if(r<Re)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 Kt(r,t,e=0){switch(I(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 Yt(r,t,e=0){switch(I(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 Qt(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)*ve,e<h)||(e=r[t+5],n+=(e&A)*Ue,e<h)||(e=r[t+6],n+=(e&A)*Re,e<h)||(e=r[t+7],n+=(e&A)*Te,e<h))return n;throw new RangeError("Could not decode varint")}function Zt(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)*ve,e<h)||(e=r.get(t+5),n+=(e&A)*Ue,e<h)||(e=r.get(t+6),n+=(e&A)*Re,e<h)||(e=r.get(t+7),n+=(e&A)*Te,e<h))return n;throw new RangeError("Could not decode varint")}function ue(r,t,e=0){return t==null&&(t=le(I(r))),t instanceof Uint8Array?Kt(r,t,e):Yt(r,t,e)}function he(r,t=0){return r instanceof Uint8Array?Qt(r,t):Zt(r,t)}function at(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function ct(r=0){return globalThis.Buffer?.allocUnsafe!=null?at(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function pe(r){return r[Symbol.asyncIterator]!=null}var me=r=>{let t=I(r),e=ct(t);return ue(r,e),me.bytes=t,e};me.bytes=0;function k(r,t){t=t??{};let e=t.lengthEncoder??me;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return pe(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??me;return new L(e(r.byteLength),r)};var j=Ht(ut(),1);var tr=8,rr=1024*1024*4,G;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(G||(G={}));var Oe=r=>{let t=he(r);return Oe.bytes=I(t),t};Oe.bytes=0;function De(r,t){let e=new L,n=G.LENGTH,o=-1,i=t?.lengthDecoder??Oe,s=t?.maxLengthLength??tr,a=t?.maxDataLength??rr;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 pe(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")}()}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 ge=class extends Error{code;constructor(t,e){super(t),this.code=e}},ht=r=>he(r);ht.bytes=0;function Q(r,t={}){let e=st(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=I(t.maxDataLength)),{read:async o=>{let i=-1,s=new L,a=t?.lengthDecoder??ht;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 ge("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new ge("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()}}var Fe={};R(Fe,{base10:()=>fr});var Zo=new Uint8Array(0);function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function 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")}function pt(r){return new TextEncoder().encode(r)}function mt(r){return new TextDecoder().decode(r)}function or(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,v=0,p=u.length;v!==p&&u[v]===0;)v++,w++;for(var y=(p-v)*d+1>>>0,m=new Uint8Array(y);v!==p;){for(var S=u[v],T=0,U=y-1;(S!==0||T<N)&&U!==-1;U--,T++)S+=256*m[U]>>>0,m[U]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");N=T,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(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,v=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,T=p-1;(m!==0||S<v)&&T!==-1;T--,S++)m+=a*y[T]>>>0,y[T]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");v=S,w++}if(u[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 B(u){var w=b(u);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:B}}var ir=or,sr=ir,wt=sr;var Ne=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ce=class{name;prefix;baseDecode;prefixCodePoint;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 bt(this,t)}},_e=class{decoders;constructor(t){this.decoders=t}or(t){return bt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function bt(r,t){return new _e({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ie=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ne(t,e,n),this.decoder=new Ce(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function H({name:r,prefix:t,encode:e,decode:n}){return new Ie(r,t,e,n)}function P({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=wt(e,r);return H({prefix:t,name:r,encode:n,decode:i=>F(o(i))})}function ar(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}function cr(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!==0&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i}function g({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return H({prefix:t,name:r,encode(o){return cr(o,n,e)},decode(o){return ar(o,n,e,r)}})}var fr=P({prefix:"9",name:"base10",alphabet:"0123456789"});var Be={};R(Be,{base16:()=>lr,base16upper:()=>ur});var lr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ur=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pe={};R(Pe,{base2:()=>hr});var hr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Me={};R(Me,{base256emoji:()=>wr});var yt=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}"),dr=yt.reduce((r,t,e)=>(r[e]=t,r),[]),pr=yt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function mr(r){return r.reduce((t,e)=>(t+=dr[e],t),"")}function gr(r){let t=[];for(let e of r){let n=pr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var wr=H({prefix:"\u{1F680}",name:"base256emoji",encode:mr,decode:gr});var Ve={};R(Ve,{base32:()=>X,base32hex:()=>Lr,base32hexpad:()=>Er,base32hexpadupper:()=>Sr,base32hexupper:()=>Ar,base32pad:()=>yr,base32padupper:()=>xr,base32upper:()=>br,base32z:()=>vr});var X=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),br=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),xr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lr=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ar=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Er=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Sr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ke={};R(ke,{base36:()=>Ur,base36upper:()=>Rr});var Ur=P({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Rr=P({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ge={};R(Ge,{base58btc:()=>O,base58flickr:()=>Tr});var O=P({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tr=P({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ze={};R(ze,{base64:()=>Dr,base64pad:()=>Or,base64url:()=>Nr,base64urlpad:()=>Cr});var Dr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Or=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $e={};R($e,{base8:()=>_r});var _r=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var je={};R(je,{identity:()=>Ir});var Ir=H({prefix:"\0",name:"identity",encode:r=>mt(r),decode:r=>pt(r)});var mi=new TextEncoder,gi=new TextDecoder;var Xe={};R(Xe,{identity:()=>nn});var Pr=At,xt=128,Mr=127,Vr=~Mr,kr=Math.pow(2,31);function At(r,t,e){t=t||[],e=e||0;for(var n=e;r>=kr;)t[e++]=r&255|xt,r/=128;for(;r&Vr;)t[e++]=r&255|xt,r>>>=7;return t[e]=r|0,At.bytes=e-n+1,t}var Gr=He,zr=128,Lt=127;function He(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw He.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Lt)<<o:(s&Lt)*Math.pow(2,o),o+=7}while(s>=zr);return He.bytes=i-n,e}var $r=Math.pow(2,7),jr=Math.pow(2,14),Hr=Math.pow(2,21),Xr=Math.pow(2,28),qr=Math.pow(2,35),Jr=Math.pow(2,42),Wr=Math.pow(2,49),Kr=Math.pow(2,56),Yr=Math.pow(2,63),Qr=function(r){return r<$r?1:r<jr?2:r<Hr?3:r<Xr?4:r<qr?5:r<Jr?6:r<Wr?7:r<Kr?8:r<Yr?9:10},Zr={encode:Pr,decode:Gr,encodingLength:Qr},en=Zr,Z=en;function ee(r,t=0){return[Z.decode(r,t),Z.decode.bytes]}function q(r,t,e=0){return Z.encode(r,t,e),t}function J(r){return Z.encodingLength(r)}function z(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)}function Et(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 W(e,o,s,t)}function St(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&dt(r.bytes,e.bytes)}}var W=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var vt=0,tn="identity",Ut=F;function rn(r){return z(vt,Ut(r))}var nn={code:vt,name:tn,encode:Ut,digest:rn};var We={};R(We,{sha256:()=>on,sha512:()=>sn});function Je({name:r,code:t,encode:e}){return new qe(r,t,e)}var qe=class{name;code;encode;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?z(this.code,e):e.then(n=>z(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Tt(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var on=Je({name:"sha2-256",code:18,encode:Tt("SHA-256")}),sn=Je({name:"sha2-512",code:19,encode:Tt("SHA-512")});function Dt(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cn(e,Ke(r),t??O.encoder);default:return fn(e,Ke(r),t??X.encoder)}}var Ot=new WeakMap;function Ke(r){let t=Ot.get(r);if(t==null){let e=new Map;return Ot.set(r,e),e}return t}var be=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==re)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ln)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=z(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&St(t.multihash,n.multihash)}toString(t){return Dt(this,t)}toJSON(){return{"/":Dt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:s}=e;return new r(n,o,i,s??Nt(n,o,i.bytes))}else if(e[un]===!0){let{version:n,multihash:o,code:i}=e,s=Et(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=Nt(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!==0)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 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]=an(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 Ke(i).set(n,t),i}};function an(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)]}}}function cn(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}function fn(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}var re=112,ln=18;function Nt(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}var un=Symbol.for("@ipld/js-cid/CID");var Ye={...je,...Pe,...$e,...Fe,...Be,...Ve,...ke,...Ge,...ze,...Me},Pi={...We,...Xe};function _t(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ct=_t("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qe=_t("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=le(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),hn={utf8:Ct,"utf-8":Ct,hex:Ye.base16,latin1:Qe,ascii:Qe,binary:Qe,...Ye},ye=hn;function E(r,t="utf8"){let e=ye[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?fe(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function It(r,t="utf8"){let e=ye[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 dn=E(`
|
|
3
|
-
`);async function
|
|
4
|
-
`),s=
|
|
5
|
-
`);await
|
|
6
|
-
`),e),e.log.trace("select: reading protocol response");let f=await
|
|
7
|
-
`;yield new L(Uint8Array.from([19]),
|
|
8
|
-
`),
|
|
9
|
-
`),
|
|
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
|
|
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
|
|
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=>
|
|
13
|
-
`))),
|
|
14
|
-
`));e.log.trace('handle: respond with "%s" for %s',t,o),await
|
|
15
|
-
`),e),e.log('handle: responded with "na" for "%s"',o)}}return
|
|
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),U=(r,t)=>{for(var e in t)oe(r,e,{get:t[e],enumerable:!0})},Ye=(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)):{},Ye(t||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),zt=r=>Ye(oe({},"__esModule",{value:!0}),r);var at=kt((Io,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 hn={};U(hn,{PROTOCOL_ID:()=>x,handle:()=>It,select:()=>_t});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 Qe;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Qe||(Qe={}));var Dn=Symbol.for("@libp2p/transport");var Ze;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ze||(Ze={}));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 ye=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},On=globalThis.CustomEvent??ye;function B(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function I(r=0){return globalThis.Buffer?.alloc!=null?B(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function T(r=0){return globalThis.Buffer?.allocUnsafe!=null?B(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function xe(r,t){if(globalThis.Buffer!=null)return B(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 B(e)}function et(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 rt=Symbol.for("@achingbrain/uint8arraylist");function tt(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?.[rt]}var L=class r{bufs;length;[rt]=!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=tt(this.bufs,t);return e.buf[e.index]}set(t,e){let n=tt(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 xe(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:xe(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=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=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=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=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(!et(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 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 Le=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=N(),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 ae(this.needNext.promise,e?.signal,e)}};function nt(){return new Le}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 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 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 $t=Math.pow(2,7),jt=Math.pow(2,14),Ht=Math.pow(2,21),Ae=Math.pow(2,28),Se=Math.pow(2,35),ve=Math.pow(2,42),Re=Math.pow(2,49),h=128,E=127;function F(r){if(r<$t)return 1;if(r<jt)return 2;if(r<Ht)return 3;if(r<Ae)return 4;if(r<Se)return 5;if(r<ve)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 Xt(r,t,e=0){switch(F(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 qt(r,t,e=0){switch(F(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 Jt(r,t){let e=r[t],n=0;if(n+=e&E,e<h||(e=r[t+1],n+=(e&E)<<7,e<h)||(e=r[t+2],n+=(e&E)<<14,e<h)||(e=r[t+3],n+=(e&E)<<21,e<h)||(e=r[t+4],n+=(e&E)*Ae,e<h)||(e=r[t+5],n+=(e&E)*Se,e<h)||(e=r[t+6],n+=(e&E)*ve,e<h)||(e=r[t+7],n+=(e&E)*Re,e<h))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<h||(e=r.get(t+1),n+=(e&E)<<7,e<h)||(e=r.get(t+2),n+=(e&E)<<14,e<h)||(e=r.get(t+3),n+=(e&E)<<21,e<h)||(e=r.get(t+4),n+=(e&E)*Ae,e<h)||(e=r.get(t+5),n+=(e&E)*Se,e<h)||(e=r.get(t+6),n+=(e&E)*ve,e<h)||(e=r.get(t+7),n+=(e&E)*Re,e<h))return n;throw new RangeError("Could not decode varint")}function fe(r,t,e=0){return t==null&&(t=T(F(r))),t instanceof Uint8Array?Xt(r,t,e):qt(r,t,e)}function le(r,t=0){return r instanceof Uint8Array?Jt(r,t):Wt(r,t)}function he(r){return r[Symbol.asyncIterator]!=null}var de=r=>{let t=F(r),e=T(t);return fe(r,e),de.bytes=t,e};de.bytes=0;function z(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)}()}z.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??de;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 De=r=>{let t=le(r);return De.bytes=F(t),t};De.bytes=0;function Ue(r,t){let e=new L,n=$.LENGTH,o=-1,i=t?.lengthDecoder??De,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")}()}Ue.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 Ue(n,{...t??{},onLength:i=>{e=i}})};var pe=class extends Error{code;constructor(t,e){super(t),this.code=e}},ct=r=>le(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 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(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 _e={};U(_e,{base10:()=>ir});var $o=new Uint8Array(0);function ft(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function 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")}function lt(r){return new TextEncoder().encode(r)}function ut(r){return new TextDecoder().decode(r)}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(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,C=0,v=0,p=u.length;v!==p&&u[v]===0;)v++,w++;for(var y=(p-v)*d+1>>>0,m=new Uint8Array(y);v!==p;){for(var S=u[v],D=0,R=y-1;(S!==0||D<C)&&R!==-1;R--,D++)S+=256*m[R]>>>0,m[R]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");C=D,v++}for(var _=y-C;_!==y&&m[_]===0;)_++;for(var ne=c.repeat(w);_<y;++_)ne+=r.charAt(m[_]);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 C=0,v=0;u[w]===c;)C++,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,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(u[w]!==" "){for(var R=p-v;R!==p&&y[R]===0;)R++;for(var _=new Uint8Array(C+(p-R)),ne=C;R!==p;)_[ne++]=y[R++];return _}}}function M(u){var w=b(u);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:M}}var tr=er,rr=tr,dt=rr;var Te=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ne=class{name;prefix;baseDecode;prefixCodePoint;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)}},Oe=class{decoders;constructor(t){this.decoders=t}or(t){return pt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function pt(r,t){return new Oe({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ce=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Te(t,e,n),this.decoder=new Ne(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function q({name:r,prefix:t,encode:e,decode:n}){return new Ce(r,t,e,n)}function V({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=dt(e,r);return q({prefix:t,name:r,encode:n,decode:i=>P(o(i))})}function 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}function 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!==0&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i}function g({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return q({prefix:t,name:r,encode(o){return or(o,n,e)},decode(o){return nr(o,n,e,r)}})}var ir=V({prefix:"9",name:"base10",alphabet:"0123456789"});var Ie={};U(Ie,{base16:()=>sr,base16upper:()=>ar});var sr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ar=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Fe={};U(Fe,{base2:()=>cr});var cr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pe={};U(Pe,{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 ur(r){return r.reduce((t,e)=>(t+=fr[e],t),"")}function hr(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:ur,decode:hr});var Me={};U(Me,{base32:()=>J,base32hex:()=>wr,base32hexpad:()=>yr,base32hexpadupper:()=>xr,base32hexupper:()=>br,base32pad:()=>mr,base32padupper:()=>gr,base32upper:()=>pr,base32z:()=>Lr});var J=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),mr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wr=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),br=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Lr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Be={};U(Be,{base36:()=>Er,base36upper:()=>Ar});var Er=V({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ar=V({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ve={};U(Ve,{base58btc:()=>O,base58flickr:()=>Sr});var O=V({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sr=V({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ke={};U(ke,{base64:()=>vr,base64pad:()=>Rr,base64url:()=>Ur,base64urlpad:()=>Dr});var vr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Rr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ur=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ge={};U(Ge,{base8:()=>Tr});var Tr=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ze={};U(ze,{identity:()=>Nr});var Nr=q({prefix:"\0",name:"identity",encode:r=>ut(r),decode:r=>lt(r)});var ii=new TextEncoder,si=new TextDecoder;var je={};U(je,{identity:()=>Zr});var _r=bt,gt=128,Ir=127,Fr=~Ir,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=$e,Br=128,wt=127;function $e(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw $e.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 $e.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:_r,decode:Mr,encodingLength:Jr},Kr=Wr,Z=Kr;function ee(r,t=0){return[Z.decode(r,t),Z.decode.bytes]}function W(r,t,e=0){return Z.encode(r,t,e),t}function K(r){return Z.encodingLength(r)}function 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)}function 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)}function xt(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ft(r.bytes,e.bytes)}}var Y=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Lt=0,Yr="identity",Et=P;function Qr(r){return j(Lt,Et(r))}var Zr={code:Lt,name:Yr,encode:Et,digest:Qr};var qe={};U(qe,{sha256:()=>en,sha512:()=>tn});function Xe({name:r,code:t,encode:e}){return new He(r,t,e)}var He=class{name;code;encode;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")}};function St(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var en=Xe({name:"sha2-256",code:18,encode:St("SHA-256")}),tn=Xe({name:"sha2-512",code:19,encode:St("SHA-512")});function vt(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return nn(e,Je(r),t??O.encoder);default:return on(e,Je(r),t??J.encoder)}}var Rt=new WeakMap;function Je(r){let t=Rt.get(r);if(t==null){let e=new Map;return Rt.set(r,e),e}return t}var ge=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==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!=null&&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}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash: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!==0)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 Je(i).set(n,t),i}};function 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)]}}}function 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}function 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}var re=112,sn=18;function 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}var an=Symbol.for("@ipld/js-cid/CID");var We={...ze,...Fe,...Ge,..._e,...Ie,...Me,...Be,...Ve,...ke,...Pe},Ui={...qe,...je};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))),Ke=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:We.base16,latin1:Ke,ascii:Ke,binary:Ke,...We},we=cn;function A(r,t="utf8"){let e=we[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?B(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Nt(r,t="utf8"){let e=we[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 k(r,t){let e=await ln(r,t);return Nt(e.subarray())}async function _t(r,t,e){if(t=Array.isArray(t)?[...t]:[t],t.length===1&&e.negotiateFully===!1)return un(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
|
+
`),s=A(`${o}
|
|
5
|
+
`);await Ot(n,[i,s],e),e.log.trace("select: reading multistream-select header");let a=await k(n,e);if(e.log.trace('select: read "%s"',a),a===x&&(e.log.trace("select: reading protocol response"),a=await k(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 k(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 un(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,M=N(),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 D=`${t}
|
|
7
|
+
`;yield new L(Uint8Array.from([19]),A(`${x}
|
|
8
|
+
`),fe(D.length),A(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(R=>{e.log.error("could not finish optimistic protocol negotiation of %s",t,R)})}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 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 u.writeV([A(`${x}
|
|
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 M.promise;return}b=!0;try{e.log.trace("optimistic: reading multistream select header");let p=await k(u,e);if(e.log.trace('optimistic: read multistream select header "%s"',p),p===x&&(p=await k(u,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,M.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(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 It(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 k(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
|
+
`))),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(hn);})();
|
|
16
16
|
return Libp2PMultistreamSelect}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/multistream-select",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1-900236724",
|
|
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,10 +57,9 @@
|
|
|
57
57
|
"test:electron-main": "aegir test -t electron-main"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@libp2p/interface": "
|
|
60
|
+
"@libp2p/interface": "1.1.1-900236724",
|
|
61
61
|
"it-length-prefixed": "^9.0.3",
|
|
62
62
|
"it-length-prefixed-stream": "^1.1.1",
|
|
63
|
-
"it-pipe": "^3.0.1",
|
|
64
63
|
"it-stream-types": "^2.0.1",
|
|
65
64
|
"p-defer": "^4.0.0",
|
|
66
65
|
"race-signal": "^1.0.2",
|
|
@@ -69,12 +68,13 @@
|
|
|
69
68
|
"uint8arrays": "^5.0.0"
|
|
70
69
|
},
|
|
71
70
|
"devDependencies": {
|
|
72
|
-
"@libp2p/logger": "
|
|
73
|
-
"aegir": "^
|
|
71
|
+
"@libp2p/logger": "4.0.4-900236724",
|
|
72
|
+
"aegir": "^42.0.0",
|
|
74
73
|
"iso-random-stream": "^2.0.2",
|
|
75
74
|
"it-all": "^3.0.3",
|
|
76
75
|
"it-drain": "^3.0.5",
|
|
77
76
|
"it-pair": "^2.0.6",
|
|
77
|
+
"it-pipe": "^3.0.1",
|
|
78
78
|
"p-timeout": "^6.0.0"
|
|
79
79
|
}
|
|
80
80
|
}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"MultistreamSelectInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_multistream_select.MultistreamSelectInit.html",
|
|
3
|
-
".:MultistreamSelectInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_multistream_select.MultistreamSelectInit.html",
|
|
4
|
-
"ProtocolStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_multistream_select.ProtocolStream.html",
|
|
5
|
-
".:ProtocolStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_multistream_select.ProtocolStream.html",
|
|
6
|
-
"PROTOCOL_ID": "https://libp2p.github.io/js-libp2p/variables/_libp2p_multistream_select.PROTOCOL_ID.html",
|
|
7
|
-
"handle": "https://libp2p.github.io/js-libp2p/functions/_libp2p_multistream_select.handle.html",
|
|
8
|
-
"select": "https://libp2p.github.io/js-libp2p/functions/_libp2p_multistream_select.select.html"
|
|
9
|
-
}
|