@libp2p/mplex 11.0.47 → 12.0.0-049bfa0fa
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 +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/encode.d.ts +1 -2
- package/dist/src/encode.d.ts.map +1 -1
- package/dist/src/encode.js +4 -6
- package/dist/src/encode.js.map +1 -1
- package/dist/src/index.d.ts +5 -31
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/mplex.d.ts +11 -53
- package/dist/src/mplex.d.ts.map +1 -1
- package/dist/src/mplex.js +56 -222
- package/dist/src/mplex.js.map +1 -1
- package/dist/src/stream.d.ts +17 -23
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +56 -28
- package/dist/src/stream.js.map +1 -1
- package/package.json +12 -15
- package/src/encode.ts +5 -7
- package/src/index.ts +10 -43
- package/src/mplex.ts +58 -273
- package/src/stream.ts +78 -46
- package/dist/typedoc-urls.json +0 -7
package/dist/index.min.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PMplex = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PMplex=(()=>{var xe=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Wt=Object.prototype.hasOwnProperty;var I=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},qt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Gt(e))!Wt.call(r,s)&&s!==t&&xe(r,s,{get:()=>e[s],enumerable:!(n=$t(e,s))||n.enumerable});return r};var Kt=r=>qt(xe({},"__esModule",{value:!0}),r);var On={};I(On,{mplex:()=>Un});var te=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},re=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},ne=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}};var K=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var se=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(e="Too many outbound protocol streams"){super(e),this.name="TooManyOutboundProtocolStreamsError"}};var rt=Symbol.for("@libp2p/service-capabilities"),Fn=Symbol.for("@libp2p/service-dependencies");function nt(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function st(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function oe(r,e){let t=nt(r).return?.();st(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var ot=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},jt=new WeakMap;function Xt({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:s}={})=>{if(s?.aborted)return Promise.reject(ot());let o,i,a,u=r??clearTimeout,f=()=>{u(o),a(ot())},g=()=>{s&&s.removeEventListener("abort",f)},d=new Promise((y,N)=>{i=()=>{g(),y(n)},a=N,o=(e??setTimeout)(i,t)});return s&&s.addEventListener("abort",f,{once:!0}),jt.set(d,()=>{u(o),o=null,i()}),d}}var Jt=Xt(),it=Jt;var ie=class extends Error{remainingPoints;msBeforeNext;consumedPoints;isFirstInDuration;constructor(e="Rate limit exceeded",t){super(e),this.name="RateLimitError",this.remainingPoints=t.remainingPoints,this.msBeforeNext=t.msBeforeNext,this.consumedPoints=t.consumedPoints,this.isFirstInDuration=t.isFirstInDuration}};var ae=class{memoryStorage;points;duration;blockDuration;execEvenly;execEvenlyMinDelayMs;keyPrefix;constructor(e={}){this.points=e.points??4,this.duration=e.duration??1,this.blockDuration=e.blockDuration??0,this.execEvenly=e.execEvenly??!1,this.execEvenlyMinDelayMs=e.execEvenlyMinDelayMs??this.duration*1e3/this.points,this.keyPrefix=e.keyPrefix??"rlflx",this.memoryStorage=new Ee}async consume(e,t=1,n={}){let s=this.getKey(e),o=this._getKeySecDuration(n),i=this.memoryStorage.incrby(s,t,o);if(i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i.consumedPoints>this.points)throw this.blockDuration>0&&i.consumedPoints<=this.points+t&&(i=this.memoryStorage.set(s,i.consumedPoints,this.blockDuration)),new ie("Rate limit exceeded",i);if(this.execEvenly&&i.msBeforeNext>0&&!i.isFirstInDuration){let a=Math.ceil(i.msBeforeNext/(i.remainingPoints+2));a<this.execEvenlyMinDelayMs&&(a=i.consumedPoints*this.execEvenlyMinDelayMs),await it(a)}return i}penalty(e,t=1,n={}){let s=this.getKey(e),o=this._getKeySecDuration(n),i=this.memoryStorage.incrby(s,t,o);return i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i}reward(e,t=1,n={}){let s=this.getKey(e),o=this._getKeySecDuration(n),i=this.memoryStorage.incrby(s,-t,o);return i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i}block(e,t){let n=t*1e3,s=this.points+1;return this.memoryStorage.set(this.getKey(e),s,t),{remainingPoints:0,msBeforeNext:n===0?-1:n,consumedPoints:s,isFirstInDuration:!1}}set(e,t,n=0){let s=(n>=0?n:this.duration)*1e3;return this.memoryStorage.set(this.getKey(e),t,n),{remainingPoints:0,msBeforeNext:s===0?-1:s,consumedPoints:t,isFirstInDuration:!1}}get(e){let t=this.memoryStorage.get(this.getKey(e));return t!=null&&(t.remainingPoints=Math.max(this.points-t.consumedPoints,0)),t}delete(e){this.memoryStorage.delete(this.getKey(e))}_getKeySecDuration(e){return e?.customDuration!=null&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}},Ee=class{storage;constructor(){this.storage=new Map}incrby(e,t,n){let s=this.storage.get(e);if(s!=null){let o=s.expiresAt!=null?s.expiresAt.getTime()-new Date().getTime():-1;return s.expiresAt==null||o>0?(s.value+=t,{remainingPoints:0,msBeforeNext:o,consumedPoints:s.value,isFirstInDuration:!1}):this.set(e,t,n)}return this.set(e,t,n)}set(e,t,n){let s=n*1e3,o=this.storage.get(e);o!=null&&clearTimeout(o.timeoutId);let i={value:t,expiresAt:s>0?new Date(Date.now()+s):void 0};return this.storage.set(e,i),s>0&&(i.timeoutId=setTimeout(()=>{this.storage.delete(e)},s),i.timeoutId.unref!=null&&i.timeoutId.unref()),{remainingPoints:0,msBeforeNext:s===0?-1:s,consumedPoints:i.value,isFirstInDuration:!0}}get(e){let t=this.storage.get(e);if(t!=null)return{remainingPoints:0,msBeforeNext:t.expiresAt!=null?t.expiresAt.getTime()-new Date().getTime():-1,consumedPoints:t.value,isFirstInDuration:!1}}delete(e){let t=this.storage.get(e);return t!=null?(t.timeoutId!=null&&clearTimeout(t.timeoutId),this.storage.delete(e),!0):!1}};function v(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var ce=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},F=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ce(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new ce(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Se=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function z(r={}){return Qt(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Qt(r,e){e=e??{};let t=e.onEnd,n=new F,s,o,i,a=v(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,b)=>{o=x=>{o=null,n.push(x);try{h(r(n))}catch(w){b(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=v()})}},f=h=>o!=null?o(h):(n.push(h),s),g=h=>(n=new F,o!=null?o({error:h}):(n.push({error:h}),s)),d=h=>{if(i)return s;if(e?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:h})},y=h=>i?s:(i=!0,h!=null?g(h):f({done:!0})),N=()=>(n=new F,y(),{done:!0}),l=h=>(y(h),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:u,return:N,throw:l,push:d,end:y,get readableLength(){return n.size},onEmpty:async h=>{let b=h?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let x,w;b!=null&&(x=new Promise((S,_)=>{w=()=>{_(new Se)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,x])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},t==null)return s;let p=s;return s={[Symbol.asyncIterator](){return this},next(){return p.next()},throw(h){return p.throw(h),t!=null&&(t(h),t=void 0),{done:!0}},return(){return p.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(h){return p.end(h),t!=null&&(t(h),t=void 0),s},get readableLength(){return p.readableLength},onEmpty:h=>p.onEmpty(h)},s}var ue=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function P(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new ue(t?.errorMessage,t?.errorCode,t?.errorName));let n,s=new ue(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Ie=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=v(),this.haveNext=v()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=v(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=v(),await P(this.readNext.promise,t?.signal,t)}};function at(){return new Ie}function Ht(r){return r[Symbol.asyncIterator]!=null}async function Zt(r,e,t){try{await Promise.all(r.map(async n=>{for await(let s of n)await e.push(s,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*Yt(r){let e=new AbortController,t=at();Zt(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*er(r){for(let e of r)yield*e}function tr(...r){let e=[];for(let t of r)Ht(t)||e.push(t);return e.length===r.length?er(e):Yt(r)}var ct=tr;function ut(r,...e){if(r==null)throw new Error("Empty pipeline");if(ve(r)){let n=r;r=()=>n.source}else if(lt(r)||ht(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&ve(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)ve(t[n])&&(t[n]=nr(t[n]));return rr(...t)}var rr=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},ht=r=>r?.[Symbol.asyncIterator]!=null,lt=r=>r?.[Symbol.iterator]!=null,ve=r=>r==null?!1:r.sink!=null&&r.source!=null,nr=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=z({objectMode:!0});t.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(ht(o))s=async function*(){yield*o,n.end()};else if(lt(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ct(n,s())}return r.source};function Ae(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function D(r=0){return new Uint8Array(r)}function A(r=0){return new Uint8Array(r)}function he(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=A(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Le={};I(Le,{base10:()=>lr});var Vs=new Uint8Array(0);function dt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return 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 ft(r){return new TextEncoder().encode(r)}function mt(r){return new TextDecoder().decode(r)}function or(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,u=r.charAt(0),f=Math.log(a)/Math.log(256),g=Math.log(256)/Math.log(a);function d(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var p=0,h=0,b=0,x=l.length;b!==x&&l[b]===0;)b++,p++;for(var w=(x-b)*g+1>>>0,S=new Uint8Array(w);b!==x;){for(var _=l[b],U=0,R=w-1;(_!==0||U<h)&&R!==-1;R--,U++)_+=256*S[R]>>>0,S[R]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");h=U,b++}for(var L=w-h;L!==w&&S[L]===0;)L++;for(var ee=u.repeat(p);L<w;++L)ee+=r.charAt(S[L]);return ee}function y(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var p=0;if(l[p]!==" "){for(var h=0,b=0;l[p]===u;)h++,p++;for(var x=(l.length-p)*f+1>>>0,w=new Uint8Array(x);l[p];){var S=t[l.charCodeAt(p)];if(S===255)return;for(var _=0,U=x-1;(S!==0||_<b)&&U!==-1;U--,_++)S+=a*w[U]>>>0,w[U]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");b=_,p++}if(l[p]!==" "){for(var R=x-b;R!==x&&w[R]===0;)R++;for(var L=new Uint8Array(h+(x-R)),ee=h;R!==x;)L[ee++]=w[R++];return L}}}function N(l){var p=y(l);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:y,decode:N}}var ir=or,ar=ir,bt=ar;var _e=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Re=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return gt(this,e)}},Ce=class{decoders;constructor(e){this.decoders=e}or(e){return gt(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function gt(r,e){return new Ce({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Te=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new _e(e,t,n),this.decoder=new Re(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function V({name:r,prefix:e,encode:t,decode:n}){return new Te(r,e,t,n)}function O({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=bt(t,r);return V({prefix:e,name:r,encode:n,decode:o=>M(s(o))})}function cr(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),i=0,a=0,u=0;for(let f=0;f<s;++f){let g=e[r[f]];if(g===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|g,i+=t,i>=8&&(i-=8,o[u++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function ur(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function hr(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function m({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let s=hr(n);return V({prefix:e,name:r,encode(o){return ur(o,n,t)},decode(o){return cr(o,s,t,r)}})}var lr=O({prefix:"9",name:"base10",alphabet:"0123456789"});var De={};I(De,{base16:()=>dr,base16upper:()=>fr});var dr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),fr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Me={};I(Me,{base2:()=>mr});var mr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ne={};I(Ne,{base256emoji:()=>yr});var wt=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}"),pr=wt.reduce((r,e,t)=>(r[t]=e,r),[]),br=wt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function gr(r){return r.reduce((e,t)=>(e+=pr[t],e),"")}function wr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=br[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var yr=V({prefix:"\u{1F680}",name:"base256emoji",encode:gr,decode:wr});var Ue={};I(Ue,{base32:()=>B,base32hex:()=>Ir,base32hexpad:()=>Ar,base32hexpadupper:()=>_r,base32hexupper:()=>vr,base32pad:()=>Er,base32padupper:()=>Sr,base32upper:()=>xr,base32z:()=>Rr});var B=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Er=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sr=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ir=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ar=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_r=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Rr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Oe={};I(Oe,{base36:()=>j,base36upper:()=>Cr});var j=O({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Cr=O({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Pe={};I(Pe,{base58btc:()=>C,base58flickr:()=>Tr});var C=O({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tr=O({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ke={};I(ke,{base64:()=>Lr,base64pad:()=>Dr,base64url:()=>Mr,base64urlpad:()=>Nr});var Lr=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Dr=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mr=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Nr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fe={};I(Fe,{base8:()=>Ur});var Ur=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ze={};I(ze,{identity:()=>Or});var Or=V({prefix:"\0",name:"identity",encode:r=>mt(r),decode:r=>ft(r)});var ro=new TextEncoder,no=new TextDecoder;var Be={};I(Be,{identity:()=>sn});var Fr=Et,yt=128,zr=127,Vr=~zr,Br=Math.pow(2,31);function Et(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Br;)e[t++]=r&255|yt,r/=128;for(;r&Vr;)e[t++]=r&255|yt,r>>>=7;return e[t]=r|0,Et.bytes=t-n+1,e}var $r=Ve,Gr=128,xt=127;function Ve(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ve.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&xt)<<s:(i&xt)*Math.pow(2,s),s+=7}while(i>=Gr);return Ve.bytes=o-n,t}var Wr=Math.pow(2,7),qr=Math.pow(2,14),Kr=Math.pow(2,21),jr=Math.pow(2,28),Xr=Math.pow(2,35),Jr=Math.pow(2,42),Qr=Math.pow(2,49),Hr=Math.pow(2,56),Zr=Math.pow(2,63),Yr=function(r){return r<Wr?1:r<qr?2:r<Kr?3:r<jr?4:r<Xr?5:r<Jr?6:r<Qr?7:r<Hr?8:r<Zr?9:10},en={encode:Fr,decode:$r,encodingLength:Yr},tn=en,X=tn;function J(r,e=0){return[X.decode(r,e),X.decode.bytes]}function $(r,e,t=0){return X.encode(r,e,t),e}function G(r){return X.encodingLength(r)}function q(r,e){let t=e.byteLength,n=G(r),s=n+G(t),o=new Uint8Array(s+t);return $(r,o,0),$(t,o,n),o.set(e,s),new W(r,t,e,o)}function St(r){let e=M(r),[t,n]=J(e),[s,o]=J(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new W(t,s,i,e)}function It(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&dt(r.bytes,t.bytes)}}var W=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var vt=0,rn="identity",At=M;function nn(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return q(vt,At(r))}var sn={code:vt,name:rn,encode:At,digest:nn};var We={};I(We,{sha256:()=>an,sha512:()=>cn});var on=20;function Ge({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new $e(r,e,t,n,s)}var $e=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??on,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?_t(n,this.code,t?.truncate):n.then(s=>_t(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function _t(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return q(e,r)}function Ct(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var an=Ge({name:"sha2-256",code:18,encode:Ct("SHA-256")}),cn=Ge({name:"sha2-512",code:19,encode:Ct("SHA-512")});function Tt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return hn(t,qe(r),e??C.encoder);default:return ln(t,qe(r),e??B.encoder)}}var Lt=new WeakMap;function qe(r){let e=Lt.get(r);if(e==null){let t=new Map;return Lt.set(r,t),t}return e}var de=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==H)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==dn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=q(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&It(e.multihash,n.multihash)}toString(e){return Tt(this,e)}toJSON(){return{"/":Tt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??Dt(n,s,o.bytes))}else if(t[fn]===!0){let{version:n,multihash:s,code:o}=t,i=St(s);return r.create(n,o,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==H)throw new Error(`Version 0 CID must use dag-pb (code: ${H}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=Dt(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,H,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=M(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new W(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,y]=J(e.subarray(t));return t+=y,d},s=n(),o=H;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),u=n(),f=t+u,g=f-i;return{version:s,codec:o,multihashCode:a,digestSize:u,multihashSize:g,size:f}}static parse(e,t){let[n,s]=un(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qe(o).set(n,e),o}};function un(r,e){switch(r[0]){case"Q":{let t=e??C;return[C.prefix,t.decode(`${C.prefix}${r}`)]}case C.prefix:{let t=e??C;return[C.prefix,t.decode(r)]}case B.prefix:{let t=e??B;return[B.prefix,t.decode(r)]}case j.prefix:{let t=e??j;return[j.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function hn(r,e,t){let{prefix:n}=t;if(n!==C.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function ln(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var H=112,dn=18;function Dt(r,e,t){let n=G(r),s=n+G(e),o=new Uint8Array(s+t.byteLength);return $(r,o,0),$(e,o,n),o.set(t,s),o}var fn=Symbol.for("@ipld/js-cid/CID");var Ke={...ze,...Me,...Fe,...Le,...De,...Ue,...Oe,...Pe,...ke,...Ne},_o={...We,...Be};function Nt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Mt=Nt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),je=Nt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=A(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),mn={utf8:Mt,"utf-8":Mt,hex:Ke.base16,latin1:je,ascii:je,binary:je,...Ke},fe=mn;function Xe(r,e="utf8"){let t=fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Z(r,e="utf8"){let t=fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Ot=Symbol.for("@achingbrain/uint8arraylist");function Ut(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function me(r){return!!r?.[Ot]}var T=class r{bufs;length;[Ot]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(me(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(me(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=Ut(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Ut(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(me(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return he(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:he(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,u=a+i.byteLength;if(s=u,e>=u)continue;let f=e>=a&&e<u,g=t>a&&t<=u;if(f&&g){if(e===a&&t===u){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(t-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(g){if(t===u){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!me(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let d=0;d<o;d++)i[d]=-1;for(let d=0;d<s;d++)i[n[d]]=d;let a=i,u=this.byteLength-n.byteLength,f=n.byteLength-1,g;for(let d=t;d<=u;d+=g){g=0;for(let y=f;y>=0;y--){let N=this.get(d+y);if(n[y]!==N){g=Math.max(1,y-a[N]);break}}if(g===0)return d}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=A(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=D(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=D(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=D(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=A(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=D(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=D(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=D(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=D(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=D(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,o)=>s+o.byteLength,0)),n.length=t,n}};var c;(function(r){r[r.NEW_STREAM=0]="NEW_STREAM",r[r.MESSAGE_RECEIVER=1]="MESSAGE_RECEIVER",r[r.MESSAGE_INITIATOR=2]="MESSAGE_INITIATOR",r[r.CLOSE_RECEIVER=3]="CLOSE_RECEIVER",r[r.CLOSE_INITIATOR=4]="CLOSE_INITIATOR",r[r.RESET_RECEIVER=5]="RESET_RECEIVER",r[r.RESET_INITIATOR=6]="RESET_INITIATOR"})(c||(c={}));var Y=Object.freeze({0:"NEW_STREAM",1:"MESSAGE_RECEIVER",2:"MESSAGE_INITIATOR",3:"CLOSE_RECEIVER",4:"CLOSE_INITIATOR",5:"RESET_RECEIVER",6:"RESET_INITIATOR"}),Je=Object.freeze({NEW_STREAM:c.NEW_STREAM,MESSAGE:c.MESSAGE_INITIATOR,CLOSE:c.CLOSE_INITIATOR,RESET:c.RESET_INITIATOR}),Pt=Object.freeze({MESSAGE:c.MESSAGE_RECEIVER,CLOSE:c.CLOSE_RECEIVER,RESET:c.RESET_RECEIVER});var Qe=1<<20,pn=4<<20,pe=class{_buffer;_headerInfo;_maxMessageSize;_maxUnprocessedMessageQueueSize;constructor(e=Qe,t=pn){this._buffer=new T,this._headerInfo=null,this._maxMessageSize=e,this._maxUnprocessedMessageQueueSize=t}write(e){if(e==null||e.length===0)return[];if(this._buffer.append(e),this._buffer.byteLength>this._maxUnprocessedMessageQueueSize)throw new K("Unprocessed message queue size too large!");let t=[];for(;this._buffer.length!==0;){if(this._headerInfo==null)try{this._headerInfo=this._decodeHeader(this._buffer)}catch(f){if(f.name==="InvalidMessageError")throw f;break}let{id:n,type:s,length:o,offset:i}=this._headerInfo;if(this._buffer.length-i<o)break;let u={id:n,type:s};(s===c.NEW_STREAM||s===c.MESSAGE_INITIATOR||s===c.MESSAGE_RECEIVER)&&(u.data=this._buffer.sublist(i,i+o)),t.push(u),this._buffer.consume(i+o),this._headerInfo=null}return t}_decodeHeader(e){let{value:t,offset:n}=Ft(e),{value:s,offset:o}=Ft(e,n),i=t&7;if(Y[i]==null)throw new Error(`Invalid type received: ${i}`);if(s>this._maxMessageSize)throw new K("Message size too large");return{id:t>>3,type:i,offset:n+o,length:s}}},bn=128,kt=127;function Ft(r,e=0){let t=0,n=0,s=e,o,i=r.length;do{if(s>=i||n>49)throw e=0,new RangeError("Could not decode varint");o=r.get(s++),t+=n<28?(o&kt)<<n:(o&kt)*Math.pow(2,n),n+=7}while(o>=bn);return e=s-e,{value:t,offset:e}}var gn=Math.pow(2,7),wn=Math.pow(2,14),yn=Math.pow(2,21),xn=Math.pow(2,28),En=Math.pow(2,35),Sn=Math.pow(2,42),In=Math.pow(2,49),E=128;function k(r){if(r<gn)return 1;if(r<wn)return 2;if(r<yn)return 3;if(r<xn)return 4;if(r<En)return 5;if(r<Sn)return 6;if(r<In)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function vn(r,e,t=0){switch(k(r)){case 8:e[t++]=r&255|E,r/=128;case 7:e[t++]=r&255|E,r/=128;case 6:e[t++]=r&255|E,r/=128;case 5:e[t++]=r&255|E,r/=128;case 4:e[t++]=r&255|E,r>>>=7;case 3:e[t++]=r&255|E,r>>>=7;case 2:e[t++]=r&255|E,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function An(r,e,t=0){switch(k(r)){case 8:e.set(t++,r&255|E),r/=128;case 7:e.set(t++,r&255|E),r/=128;case 6:e.set(t++,r&255|E),r/=128;case 5:e.set(t++,r&255|E),r/=128;case 4:e.set(t++,r&255|E),r>>>=7;case 3:e.set(t++,r&255|E),r>>>=7;case 2:e.set(t++,r&255|E),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function be(r,e,t=0){return e==null&&(e=A(k(r))),e instanceof Uint8Array?vn(r,e,t):An(r,e,t)}var He=10*1024,Ze=class{_pool;_poolOffset;constructor(){this._pool=A(He),this._poolOffset=0}write(e,t){let n=this._pool,s=this._poolOffset;be(e.id<<3|e.type,n,s),s+=k(e.id<<3|e.type),(e.type===c.NEW_STREAM||e.type===c.MESSAGE_INITIATOR||e.type===c.MESSAGE_RECEIVER)&&e.data!=null?(be(e.data.length,n,s),s+=k(e.data.length)):(be(0,n,s),s+=k(0));let o=n.subarray(this._poolOffset,s);He-s<100?(this._pool=A(He),this._poolOffset=0):this._poolOffset=s,t.append(o),(e.type===c.NEW_STREAM||e.type===c.MESSAGE_INITIATOR||e.type===c.MESSAGE_RECEIVER)&&e.data!=null&&t.append(e.data)}},Rn=new Ze;async function*zt(r){for await(let e of r){let t=new T;Rn.write(e,t),yield t}}var ge=class extends Error{constructor(e="Stream input buffer error"){super(e),this.name="StreamInputBufferError"}};var Cn=5e3;function Ye(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var we=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=v(),this.closed=v(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??Cn,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=z({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new ne(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let s=this.sendNewStream(t);Ye(s)&&await s}let n=()=>{oe(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let s of e){s=s instanceof Uint8Array?new T(s):s;let o=this.sendData(s,t);Ye(o)&&(this.sendingData=v(),await o,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await P(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await P(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await P(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await P(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Ye(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new re("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};var et=class extends we{name;streamId;send;types;maxDataSize;constructor(e){super(e),this.types=e.direction==="outbound"?Je:Pt,this.send=e.send,this.name=e.name,this.streamId=e.streamId,this.maxDataSize=e.maxDataSize}async sendNewStream(){await this.send({id:this.streamId,type:Je.NEW_STREAM,data:new T(Xe(this.name))})}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxDataSize);await this.send({id:this.streamId,type:this.types.MESSAGE,data:e.sublist(0,t)}),e.consume(t)}}async sendReset(){await this.send({id:this.streamId,type:this.types.RESET})}async sendCloseWrite(){await this.send({id:this.streamId,type:this.types.CLOSE})}async sendCloseRead(){}};function Vt(r){let{id:e,name:t,send:n,onEnd:s,type:o="initiator",maxMsgSize:i=Qe}=r,a=o==="initiator"?"outbound":"inbound";return new et({id:o==="initiator"?`i${e}`:`r${e}`,streamId:e,name:`${t??e}`,direction:a,maxDataSize:i,onEnd:s,send:n,log:r.log.newScope(`${a}:${e}`)})}var Tn=1024,Ln=1024,Dn=1024*1024*4,Mn=5,Nn=500;function Bt(r){let e={...r,type:`${Y[r.type]} (${r.type})`};return r.type===c.NEW_STREAM&&(e.data=Z(r.data instanceof Uint8Array?r.data:r.data.subarray())),(r.type===c.MESSAGE_INITIATOR||r.type===c.MESSAGE_RECEIVER)&&(e.data=Z(r.data instanceof Uint8Array?r.data:r.data.subarray(),"base16")),e}var ye=class{protocol="/mplex/6.7.0";sink;source;log;_streamId;_streams;_init;_source;closeController;rateLimiter;closeTimeout;logger;constructor(e,t){t=t??{},this.log=t.log?.newScope("mplex")??e.logger.forComponent("libp2p:mplex"),this.logger=e.logger,this._streamId=0,this._streams={initiators:new Map,receivers:new Map},this._init=t,this.closeTimeout=t.closeTimeout??Nn,this.sink=this._createSink(),this._source=z({objectMode:!0,onEnd:()=>{for(let n of this._streams.initiators.values())n.destroy();for(let n of this._streams.receivers.values())n.destroy()}}),this.source=ut(this._source,n=>zt(n)),this.closeController=new AbortController,this.rateLimiter=new ae({points:t.disconnectThreshold??Mn,duration:1})}get streams(){let e=[];for(let t of this._streams.initiators.values())e.push(t);for(let t of this._streams.receivers.values())e.push(t);return e}newStream(e){if(this.closeController.signal.aborted)throw new te("Muxer already closed");let t=this._streamId++;e=e==null?t.toString():e.toString();let n=this._streams.initiators;return this._newStream({id:t,name:e,type:"initiator",registry:n})}async close(e){if(this.closeController.signal.aborted)return;let t=e?.signal??AbortSignal.timeout(this.closeTimeout);try{await Promise.all(this.streams.map(async n=>n.close({signal:t}))),this._source.end(),await this._source.onEmpty({signal:t}),this.closeController.abort()}catch(n){this.abort(n)}}abort(e){this.closeController.signal.aborted||(this.streams.forEach(t=>{t.abort(e)}),this.closeController.abort(e))}_newReceiverStream(e){let{id:t,name:n}=e,s=this._streams.receivers;return this._newStream({id:t,name:n,type:"receiver",registry:s})}_newStream(e){let{id:t,name:n,type:s,registry:o}=e;if(this.log("new %s stream %s",s,t),s==="initiator"&&this._streams.initiators.size===(this._init.maxOutboundStreams??Ln))throw new se("Too many outbound streams open");if(o.has(t))throw new Error(`${s} stream ${t} already exists!`);let u=Vt({id:t,name:n,send:async f=>{this.log.enabled&&this.log.trace("%s stream %s send",s,t,Bt(f)),this._source.push(f)},type:s,onEnd:()=>{this.log("%s stream with id %s and protocol %s ended",s,t,u.protocol),o.delete(t),this._init.onStreamEnd!=null&&this._init.onStreamEnd(u)},maxMsgSize:this._init.maxMsgSize,log:this.log});return o.set(t,u),u}_createSink(){return async t=>{let n=()=>{oe(t,this.log)};this.closeController.signal.addEventListener("abort",n);try{let s=new pe(this._init.maxMsgSize,this._init.maxUnprocessedMessageQueueSize);for await(let o of t)for(let i of s.write(o))await this._handleIncoming(i);this._source.end()}catch(s){this.log("error in sink",s),this._source.end(s)}finally{this.closeController.signal.removeEventListener("abort",n)}}}async _handleIncoming(e){let{id:t,type:n}=e;if(this.log.enabled&&this.log.trace("incoming message",Bt(e)),e.type===c.NEW_STREAM){if(this._streams.receivers.size===(this._init.maxInboundStreams??Tn)){this.log("too many inbound streams open"),this._source.push({id:t,type:c.RESET_RECEIVER});try{await this.rateLimiter.consume("new-stream",1)}catch{this.log("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),this.abort(new Error("Too many open streams"));return}return}let a=this._newReceiverStream({id:t,name:Z(e.data instanceof Uint8Array?e.data:e.data.subarray())});this._init.onIncomingStream!=null&&this._init.onIncomingStream(a);return}let o=((n&1)===1?this._streams.initiators:this._streams.receivers).get(t);if(o==null){this.log("missing stream %s for message type %s",t,Y[n]);try{await this.rateLimiter.consume("missing-stream",1)}catch{this.log("rate limit hit when receiving messages for streams that do not exist - closing remote connection"),this.abort(new Error("Too many messages for missing streams"));return}return}let i=this._init.maxStreamBufferSize??Dn;try{switch(n){case c.MESSAGE_INITIATOR:case c.MESSAGE_RECEIVER:if(o.sourceReadableLength()>i)throw this._source.push({id:e.id,type:n===c.MESSAGE_INITIATOR?c.RESET_RECEIVER:c.RESET_INITIATOR}),new ge("Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers");o.sourcePush(e.data);break;case c.CLOSE_INITIATOR:case c.CLOSE_RECEIVER:o.remoteCloseWrite();break;case c.RESET_INITIATOR:case c.RESET_RECEIVER:o.reset();break;default:this.log("unknown message type %s",n)}}catch(a){this.log.error("error while processing message",a),o.abort(a)}}};var tt=class{protocol="/mplex/6.7.0";_init;components;constructor(e,t={}){this.components=e,this._init=t}[Symbol.toStringTag]="@libp2p/mplex";[rt]=["@libp2p/stream-multiplexing"];createStreamMuxer(e){return new ye(this.components,{...e,...this._init})}};function Un(r={}){return e=>new tt(e,r)}return Kt(On);})();
|
2
|
+
"use strict";var Libp2PMplex=(()=>{var Ie=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var L=(r,e)=>{for(var t in e)Ie(r,t,{get:e[t],enumerable:!0})},Gt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Wt(e))!qt.call(r,n)&&n!==t&&Ie(r,n,{get:()=>e[n],enumerable:!(s=$t(e,n))||s.enumerable});return r};var jt=r=>Gt(Ie({},"__esModule",{value:!0}),r);var vs={};L(vs,{mplex:()=>Ss});var P=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},ne=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var U=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},K=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var ie=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},F=class extends Event{error;local;constructor(e,t,s){super("close",s),this.error=t,this.local=e}},oe=class extends F{constructor(e,t){super(!0,e,t)}},ae=class extends F{constructor(e,t){super(!1,e,t)}};var z=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,s){super.addEventListener(e,t,s);let n=this.#e.get(e);n==null&&(n=[],this.#e.set(e,n)),n.push({callback:t,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(e,t,s){super.removeEventListener(e.toString(),t??null,s);let n=this.#e.get(e);n!=null&&(n=n.filter(({callback:i})=>i!==t),this.#e.set(e,n))}dispatchEvent(e){let t=super.dispatchEvent(e),s=this.#e.get(e.type);return s==null||(s=s.filter(({once:n})=>!n),this.#e.set(e.type,s)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var ct=Symbol.for("@libp2p/service-capabilities"),Ds=Symbol.for("@libp2p/service-dependencies");var Ce={};L(Ce,{base58btc:()=>R,base58flickr:()=>Yt});var en=new Uint8Array(0);function ut(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return 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 ht(r){return new TextEncoder().encode(r)}function ft(r){return new TextDecoder().decode(r)}function Kt(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),s=0;s<t.length;s++)t[s]=255;for(var n=0;n<r.length;n++){var i=r.charAt(n),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var a=r.length,h=r.charAt(0),m=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function c(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var x=0,u=0,w=0,E=l.length;w!==E&&l[w]===0;)w++,x++;for(var y=(E-w)*p+1>>>0,v=new Uint8Array(y);w!==E;){for(var T=l[w],_=0,D=y-1;(T!==0||_<u)&&D!==-1;D--,_++)T+=256*v[D]>>>0,v[D]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");u=_,w++}for(var C=y-u;C!==y&&v[C]===0;)C++;for(var se=h.repeat(x);C<y;++C)se+=r.charAt(v[C]);return se}function b(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var x=0;if(l[x]!==" "){for(var u=0,w=0;l[x]===h;)u++,x++;for(var E=(l.length-x)*m+1>>>0,y=new Uint8Array(E);l[x];){var v=t[l.charCodeAt(x)];if(v===255)return;for(var T=0,_=E-1;(v!==0||T<w)&&_!==-1;_--,T++)v+=a*y[_]>>>0,y[_]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");w=T,x++}if(l[x]!==" "){for(var D=E-w;D!==E&&y[D]===0;)D++;for(var C=new Uint8Array(u+(E-D)),se=u;D!==E;)C[se++]=y[D++];return C}}}function d(l){var x=b(l);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:c,decodeUnsafe:b,decode:d}}var Qt=Kt,Xt=Qt,dt=Xt;var Ae=class{name;prefix;baseEncode;constructor(e,t,s){this.name=e,this.prefix=t,this.baseEncode=s}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Te=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,s){this.name=e,this.prefix=t;let n=t.codePointAt(0);if(n===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n,this.baseDecode=s}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return mt(this,e)}},De=class{decoders;constructor(e){this.decoders=e}or(e){return mt(this,e)}decode(e){let t=e[0],s=this.decoders[t];if(s!=null)return s.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function mt(r,e){return new De({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Re=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,s,n){this.name=e,this.prefix=t,this.baseEncode=s,this.baseDecode=n,this.encoder=new Ae(e,t,s),this.decoder=new Te(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function V({name:r,prefix:e,encode:t,decode:s}){return new Re(r,e,t,s)}function N({name:r,prefix:e,alphabet:t}){let{encode:s,decode:n}=dt(t,r);return V({prefix:e,name:r,encode:s,decode:i=>M(n(i))})}function Ht(r,e,t,s){let n=r.length;for(;r[n-1]==="=";)--n;let i=new Uint8Array(n*t/8|0),o=0,a=0,h=0;for(let m=0;m<n;++m){let p=e[r[m]];if(p===void 0)throw new SyntaxError(`Non-${s} character`);a=a<<t|p,o+=t,o>=8&&(o-=8,i[h++]=255&a>>o)}if(o>=t||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function Jt(r,e,t){let s=e[e.length-1]==="=",n=(1<<t)-1,i="",o=0,a=0;for(let h=0;h<r.length;++h)for(a=a<<8|r[h],o+=8;o>t;)o-=t,i+=e[n&a>>o];if(o!==0&&(i+=e[n&a<<t-o]),s)for(;(i.length*t&7)!==0;)i+="=";return i}function Zt(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function g({name:r,prefix:e,bitsPerChar:t,alphabet:s}){let n=Zt(s);return V({prefix:e,name:r,encode(i){return Jt(i,s,t)},decode(i){return Ht(i,n,t,r)}})}var R=N({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yt=N({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Me={};L(Me,{base32:()=>k,base32hex:()=>sr,base32hexpad:()=>ir,base32hexpadupper:()=>or,base32hexupper:()=>nr,base32pad:()=>tr,base32padupper:()=>rr,base32upper:()=>er,base32z:()=>ar});var k=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),er=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),sr=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nr=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ir=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),or=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ar=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Be={};L(Be,{base36:()=>X,base36upper:()=>cr});var X=N({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cr=N({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ur=bt,pt=128,hr=127,fr=~hr,lr=Math.pow(2,31);function bt(r,e,t){e=e||[],t=t||0;for(var s=t;r>=lr;)e[t++]=r&255|pt,r/=128;for(;r&fr;)e[t++]=r&255|pt,r>>>=7;return e[t]=r|0,bt.bytes=t-s+1,e}var dr=_e,mr=128,gt=127;function _e(r,s){var t=0,s=s||0,n=0,i=s,o,a=r.length;do{if(i>=a)throw _e.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=n<28?(o>)<<n:(o>)*Math.pow(2,n),n+=7}while(o>=mr);return _e.bytes=i-s,t}var pr=Math.pow(2,7),gr=Math.pow(2,14),br=Math.pow(2,21),xr=Math.pow(2,28),wr=Math.pow(2,35),yr=Math.pow(2,42),Er=Math.pow(2,49),Sr=Math.pow(2,56),vr=Math.pow(2,63),Lr=function(r){return r<pr?1:r<gr?2:r<br?3:r<xr?4:r<wr?5:r<yr?6:r<Er?7:r<Sr?8:r<vr?9:10},Ir={encode:ur,decode:dr,encodingLength:Lr},Ar=Ir,H=Ar;function J(r,e=0){return[H.decode(r,e),H.decode.bytes]}function $(r,e,t=0){return H.encode(r,e,t),e}function W(r){return H.encodingLength(r)}function G(r,e){let t=e.byteLength,s=W(r),n=s+W(t),i=new Uint8Array(n+t);return $(r,i,0),$(t,i,s),i.set(e,n),new q(r,t,e,i)}function xt(r){let e=M(r),[t,s]=J(e),[n,i]=J(e.subarray(s)),o=e.subarray(s+i);if(o.byteLength!==n)throw new Error("Incorrect length");return new q(t,n,o,e)}function wt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ut(r.bytes,t.bytes)}}var q=class{code;size;digest;bytes;constructor(e,t,s,n){this.code=e,this.size=t,this.digest=s,this.bytes=n}};function yt(r,e){let{bytes:t,version:s}=r;switch(s){case 0:return Dr(t,Ne(r),e??R.encoder);default:return Rr(t,Ne(r),e??k.encoder)}}var Et=new WeakMap;function Ne(r){let e=Et.get(r);if(e==null){let t=new Map;return Et.set(r,t),t}return e}var ue=class r{code;version;multihash;bytes;"/";constructor(e,t,s,n){this.code=t,this.version=e,this.multihash=s,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Y)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Cr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,s=G(e,t);return r.createV1(this.code,s)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let s=t;return s!=null&&e.code===s.code&&e.version===s.version&&wt(e.multihash,s.multihash)}toString(e){return yt(this,e)}toJSON(){return{"/":yt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:s,code:n,multihash:i,bytes:o}=t;return new r(s,n,i,o??St(s,n,i.bytes))}else if(t[Mr]===!0){let{version:s,multihash:n,code:i}=t,o=xt(n);return r.create(s,i,o)}else return null}static create(e,t,s){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(s.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Y)throw new Error(`Version 0 CID must use dag-pb (code: ${Y}) block encoding`);return new r(e,t,s,s.bytes)}case 1:{let n=St(e,t,s.bytes);return new r(e,t,s,n)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Y,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,s]=r.decodeFirst(e);if(s.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),s=t.size-t.multihashSize,n=M(e.subarray(s,s+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=n.subarray(t.multihashSize-t.digestSize),o=new q(t.multihashCode,t.digestSize,i,n);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,s=()=>{let[c,b]=J(e.subarray(t));return t+=b,c},n=s(),i=Y;if(n===18?(n=0,t=0):i=s(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let o=t,a=s(),h=s(),m=t+h,p=m-o;return{version:n,codec:i,multihashCode:a,digestSize:h,multihashSize:p,size:m}}static parse(e,t){let[s,n]=Tr(e,t),i=r.decode(n);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ne(i).set(s,e),i}};function Tr(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case k.prefix:{let t=e??k;return[k.prefix,t.decode(r)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Dr(r,e,t){let{prefix:s}=t;if(s!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(s);if(n==null){let i=t.encode(r).slice(1);return e.set(s,i),i}else return n}function Rr(r,e,t){let{prefix:s}=t,n=e.get(s);if(n==null){let i=t.encode(r);return e.set(s,i),i}else return n}var Y=112,Cr=18;function St(r,e,t){let s=W(r),n=s+W(e),i=new Uint8Array(n+t.byteLength);return $(r,i,0),$(e,i,s),i.set(t,n),i}var Mr=Symbol.for("@ipld/js-cid/CID");var Ue={};L(Ue,{identity:()=>Nr});var vt=0,Br="identity",Lt=M;function _r(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return G(vt,Lt(r))}var Nr={code:vt,name:Br,encode:Lt,digest:_r};function Oe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function B(r=0){return new Uint8Array(r)}function I(r=0){return new Uint8Array(r)}function he(r,e){e==null&&(e=r.reduce((n,i)=>n+i.length,0));let t=I(e),s=0;for(let n of r)t.set(n,s),s+=n.length;return t}var At=Symbol.for("@achingbrain/uint8arraylist");function It(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let s of r){let n=t+s.byteLength;if(e<n)return{buf:s,index:e-t};t=n}throw new RangeError("index is out of bounds")}function fe(r){return!!r?.[At]}var A=class r{bufs;length;[At]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let s of e)if(s instanceof Uint8Array)t+=s.byteLength,this.bufs.push(s);else if(fe(s))t+=s.byteLength,this.bufs.push(...s.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let s of e.reverse())if(s instanceof Uint8Array)t+=s.byteLength,this.bufs.unshift(s);else if(fe(s))t+=s.byteLength,this.bufs.unshift(...s.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=It(this.bufs,e);return t.buf[t.index]}set(e,t){let s=It(this.bufs,e);s.buf[s.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let s=0;s<e.length;s++)this.set(t+s,e[s]);else if(fe(e))for(let s=0;s<e.length;s++)this.set(t+s,e.get(s));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:s,length:n}=this._subList(e,t);return he(s,n)}subarray(e,t){let{bufs:s,length:n}=this._subList(e,t);return s.length===1?s[0]:he(s,n)}sublist(e,t){let{bufs:s,length:n}=this._subList(e,t),i=new r;return i.length=n,i.bufs=[...s],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let s=[],n=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=n,h=a+o.byteLength;if(n=h,e>=h)continue;let m=e>=a&&e<h,p=t>a&&t<=h;if(m&&p){if(e===a&&t===h){s.push(o);break}let c=e-a;s.push(o.subarray(c,c+(t-e)));break}if(m){if(e===0){s.push(o);continue}s.push(o.subarray(e-a));continue}if(p){if(t===h){s.push(o);break}s.push(o.subarray(0,t-a));break}s.push(o)}return{bufs:s,length:t-e}}indexOf(e,t=0){if(!fe(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let s=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let n=s.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let c=0;c<i;c++)o[c]=-1;for(let c=0;c<n;c++)o[s[c]]=c;let a=o,h=this.byteLength-s.byteLength,m=s.byteLength-1,p;for(let c=t;c<=h;c+=p){p=0;for(let b=m;b>=0;b--){let d=this.get(c+b);if(s[b]!==d){p=Math.max(1,b-a[d]);break}}if(p===0)return c}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let s=I(1);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt8(0,t),this.write(s,e)}getInt16(e,t){let s=this.subarray(e,e+2);return new DataView(s.buffer,s.byteOffset,s.byteLength).getInt16(0,t)}setInt16(e,t,s){let n=B(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,t,s),this.write(n,e)}getInt32(e,t){let s=this.subarray(e,e+4);return new DataView(s.buffer,s.byteOffset,s.byteLength).getInt32(0,t)}setInt32(e,t,s){let n=B(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,t,s),this.write(n,e)}getBigInt64(e,t){let s=this.subarray(e,e+8);return new DataView(s.buffer,s.byteOffset,s.byteLength).getBigInt64(0,t)}setBigInt64(e,t,s){let n=B(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,t,s),this.write(n,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let s=I(1);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint8(0,t),this.write(s,e)}getUint16(e,t){let s=this.subarray(e,e+2);return new DataView(s.buffer,s.byteOffset,s.byteLength).getUint16(0,t)}setUint16(e,t,s){let n=B(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,t,s),this.write(n,e)}getUint32(e,t){let s=this.subarray(e,e+4);return new DataView(s.buffer,s.byteOffset,s.byteLength).getUint32(0,t)}setUint32(e,t,s){let n=B(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,t,s),this.write(n,e)}getBigUint64(e,t){let s=this.subarray(e,e+8);return new DataView(s.buffer,s.byteOffset,s.byteLength).getBigUint64(0,t)}setBigUint64(e,t,s){let n=B(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,t,s),this.write(n,e)}getFloat32(e,t){let s=this.subarray(e,e+4);return new DataView(s.buffer,s.byteOffset,s.byteLength).getFloat32(0,t)}setFloat32(e,t,s){let n=B(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,t,s),this.write(n,e)}getFloat64(e,t){let s=this.subarray(e,e+8);return new DataView(s.buffer,s.byteOffset,s.byteLength).getFloat64(0,t)}setFloat64(e,t,s){let n=B(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,s),this.write(n,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Oe(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let s=new r;return s.bufs=e,t==null&&(t=e.reduce((n,i)=>n+i.byteLength,0)),s.length=t,s}};var Pe={};L(Pe,{base10:()=>Or});var Or=N({prefix:"9",name:"base10",alphabet:"0123456789"});var Fe={};L(Fe,{base16:()=>Pr,base16upper:()=>Fr});var Pr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fr=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ze={};L(ze,{base2:()=>zr});var zr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ve={};L(Ve,{base256emoji:()=>qr});var Tt=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}"),Vr=Tt.reduce((r,e,t)=>(r[t]=e,r),[]),kr=Tt.reduce((r,e,t)=>{let s=e.codePointAt(0);if(s==null)throw new Error(`Invalid character: ${e}`);return r[s]=t,r},[]);function $r(r){return r.reduce((e,t)=>(e+=Vr[t],e),"")}function Wr(r){let e=[];for(let t of r){let s=t.codePointAt(0);if(s==null)throw new Error(`Invalid character: ${t}`);let n=kr[s];if(n==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var qr=V({prefix:"\u{1F680}",name:"base256emoji",encode:$r,decode:Wr});var ke={};L(ke,{base64:()=>Gr,base64pad:()=>jr,base64url:()=>Kr,base64urlpad:()=>Qr});var Gr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Kr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $e={};L($e,{base8:()=>Xr});var Xr=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var We={};L(We,{identity:()=>Hr});var Hr=V({prefix:"\0",name:"identity",encode:r=>ft(r),decode:r=>ht(r)});var Pn=new TextEncoder,Fn=new TextDecoder;var je={};L(je,{sha256:()=>es,sha512:()=>ts});var Yr=20;function Ge({name:r,code:e,encode:t,minDigestLength:s,maxDigestLength:n}){return new qe(r,e,t,s,n)}var qe=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,s,n,i){this.name=e,this.code=t,this.encode=s,this.minDigestLength=n??Yr,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let s=this.encode(e);return s instanceof Uint8Array?Dt(s,this.code,t?.truncate):s.then(n=>Dt(n,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Dt(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return G(e,r)}function Ct(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var es=Ge({name:"sha2-256",code:18,encode:Ct("SHA-256")}),ts=Ge({name:"sha2-512",code:19,encode:Ct("SHA-512")});var Ke={...We,...ze,...$e,...Pe,...Fe,...Me,...Be,...Ce,...ke,...Ve},Hn={...je,...Ue};function Bt(r,e,t,s){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:s}}}var Mt=Bt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qe=Bt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=I(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),rs={utf8:Mt,"utf-8":Mt,hex:Ke.base16,latin1:Qe,ascii:Qe,binary:Qe,...Ke},le=rs;function Xe(r,e="utf8"){let t=le[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function de(r,e="utf8"){let t=le[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var ss=Math.pow(2,7),ns=Math.pow(2,14),is=Math.pow(2,21),os=Math.pow(2,28),as=Math.pow(2,35),cs=Math.pow(2,42),us=Math.pow(2,49),S=128;function O(r){if(r<ss)return 1;if(r<ns)return 2;if(r<is)return 3;if(r<os)return 4;if(r<as)return 5;if(r<cs)return 6;if(r<us)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function hs(r,e,t=0){switch(O(r)){case 8:e[t++]=r&255|S,r/=128;case 7:e[t++]=r&255|S,r/=128;case 6:e[t++]=r&255|S,r/=128;case 5:e[t++]=r&255|S,r/=128;case 4:e[t++]=r&255|S,r>>>=7;case 3:e[t++]=r&255|S,r>>>=7;case 2:e[t++]=r&255|S,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function fs(r,e,t=0){switch(O(r)){case 8:e.set(t++,r&255|S),r/=128;case 7:e.set(t++,r&255|S),r/=128;case 6:e.set(t++,r&255|S),r/=128;case 5:e.set(t++,r&255|S),r/=128;case 4:e.set(t++,r&255|S),r>>>=7;case 3:e.set(t++,r&255|S),r>>>=7;case 2:e.set(t++,r&255|S),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function me(r,e,t=0){return e==null&&(e=I(O(r))),e instanceof Uint8Array?hs(r,e,t):fs(r,e,t)}function pe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var ge=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},j=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ge(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new ge(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var He=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function _t(r={}){return ds(t=>{let s=t.shift();if(s==null)return{done:!0};if(s.error!=null)throw s.error;return{done:s.done===!0,value:s.value}},r)}function ds(r,e){e=e??{};let t=e.onEnd,s=new j,n,i,o,a=pe(),h=async()=>{try{return s.isEmpty()?o?{done:!0}:await new Promise((u,w)=>{i=E=>{i=null,s.push(E);try{u(r(s))}catch(y){w(y)}return n}}):r(s)}finally{s.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pe()})}},m=u=>i!=null?i(u):(s.push(u),n),p=u=>(s=new j,i!=null?i({error:u}):(s.push({error:u}),n)),c=u=>{if(o)return n;if(e?.objectMode!==!0&&u?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return m({done:!1,value:u})},b=u=>o?n:(o=!0,u!=null?p(u):m({done:!0})),d=()=>(s=new j,b(),{done:!0}),l=u=>(b(u),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:h,return:d,throw:l,push:c,end:b,get readableLength(){return s.size},onEmpty:async u=>{let w=u?.signal;if(w?.throwIfAborted(),s.isEmpty())return;let E,y;w!=null&&(E=new Promise((v,T)=>{y=()=>{T(new He)},w.addEventListener("abort",y)}));try{await Promise.race([a.promise,E])}finally{y!=null&&w!=null&&w?.removeEventListener("abort",y)}}},t==null)return n;let x=n;return n={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(u){return x.throw(u),t!=null&&(t(u),t=void 0),{done:!0}},return(){return x.return(),t!=null&&(t(),t=void 0),{done:!0}},push:c,end(u){return x.end(u),t!=null&&(t(u),t=void 0),n},get readableLength(){return x.readableLength},onEmpty:u=>x.onEmpty(u)},n}var Je=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ze=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nt=r=>globalThis.DOMException===void 0?new Ze(r):new DOMException(r),Ut=r=>{let e=r.reason===void 0?Nt("This operation was aborted."):r.reason;return e instanceof Error?e:Nt(e)};function Ye(r,e){let{milliseconds:t,fallback:s,message:n,customTimers:i={setTimeout,clearTimeout}}=e,o,a,m=new Promise((p,c)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&c(Ut(d)),a=()=>{c(Ut(d))},d.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,c);return}let b=new Je;o=i.setTimeout.call(void 0,()=>{if(s){try{p(s())}catch(d){c(d)}return}typeof r.cancel=="function"&&r.cancel(),n===!1?p():n instanceof Error?c(n):(b.message=n??`Promise timed out after ${t} milliseconds`,c(b))},t),(async()=>{try{p(await r)}catch(d){c(d)}})()}).finally(()=>{m.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return m.clear=()=>{i.clearTimeout.call(void 0,o),o=void 0},m}var ms=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function ps(r,e,t){let s,n=new Promise((i,o)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),h=[],{addListener:m,removeListener:p}=ms(r),c=(...d)=>{let l=t.multiArgs?d:d[0];t.filter&&!t.filter(l)||(h.push(l),t.count===h.length&&(s(),i(h)))},b=d=>{s(),o(d)};s=()=>{for(let d of a)p(d,c);for(let d of t.rejectionEvents)p(d,b)};for(let d of a)m(d,c);for(let d of t.rejectionEvents)m(d,b);t.signal&&t.signal.addEventListener("abort",()=>{b(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(h)});if(n.cancel=s,typeof t.timeout=="number"){let i=Ye(n,{milliseconds:t.timeout});return i.cancel=s,i}return n}function et(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let s=ps(r,e,t),n=s.then(i=>i[0]);return n.cancel=s.cancel,n}var be=class extends Error{remainingPoints;msBeforeNext;consumedPoints;isFirstInDuration;constructor(e="Rate limit exceeded",t){super(e),this.name="RateLimitError",this.remainingPoints=t.remainingPoints,this.msBeforeNext=t.msBeforeNext,this.consumedPoints=t.consumedPoints,this.isFirstInDuration=t.isFirstInDuration}};var xe=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function gs(r){return r.reason}async function Ot(r,e,t){if(e==null)return r;let s=t?.translateError??gs;if(e.aborted)return r.catch(()=>{}),Promise.reject(s(e));let n;try{return await Promise.race([r,new Promise((i,o)=>{n=()=>{o(s(e))},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var bs=Math.pow(2,20)*4,we=class extends z{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??bs,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new A,this.writeBuffer=new A,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=_t(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let s=i=>{e.end(i.error)};this.addEventListener("close",s);let n=()=>{e.end()};this.addEventListener("remoteCloseWrite",n);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",s),this.removeEventListener("remoteCloseWrite",n)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new U(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new oe(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new U("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new U("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new U(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new ne;this.dispatchEvent(new ae(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new F))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,s=0;for(;this.writeBuffer.byteLength>0;){let n=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(n===0){e=!1;break}let i=this.writeBuffer.sublist(0,n),o=new A(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,s+=a.sentBytes,a.sentBytes!==o.byteLength&&(o.consume(a.sentBytes),this.writeBuffer.prepend(o)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",s,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new ie(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new K(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new K(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};function Pt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var ye=class extends z{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let s=o=>{try{this.onData(o.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",s);let n=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(o=>{o.onMuxerDrain()})};this.maConn.addEventListener("drain",n);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await Ot(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new P;let t=this.onCreateStream({...this.streamOptions,...e});return Pt(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new xe(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=s=>{let n=this.streams.findIndex(i=>i===e);n!==-1&&this.streams.splice(n,1),s.error!=null?s.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var Ee=class extends we{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await et(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await et(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var Se=class{memoryStorage;points;duration;blockDuration;keyPrefix;constructor(e={}){this.points=e.points??4,this.duration=e.duration??1,this.blockDuration=e.blockDuration??0,this.keyPrefix=e.keyPrefix??"rlflx",this.memoryStorage=new tt}consume(e,t=1,s={}){let n=this.getKey(e),i=this._getKeySecDuration(s),o=this.memoryStorage.incrby(n,t,i);if(o.remainingPoints=Math.max(this.points-o.consumedPoints,0),o.consumedPoints>this.points)throw this.blockDuration>0&&o.consumedPoints<=this.points+t&&(o=this.memoryStorage.set(n,o.consumedPoints,this.blockDuration)),new be("Rate limit exceeded",o);return o}penalty(e,t=1,s={}){let n=this.getKey(e),i=this._getKeySecDuration(s),o=this.memoryStorage.incrby(n,t,i);return o.remainingPoints=Math.max(this.points-o.consumedPoints,0),o}reward(e,t=1,s={}){let n=this.getKey(e),i=this._getKeySecDuration(s),o=this.memoryStorage.incrby(n,-t,i);return o.remainingPoints=Math.max(this.points-o.consumedPoints,0),o}block(e,t){let s=t*1e3,n=this.points+1;return this.memoryStorage.set(this.getKey(e),n,t),{remainingPoints:0,msBeforeNext:s===0?-1:s,consumedPoints:n,isFirstInDuration:!1}}set(e,t,s=0){let n=(s>=0?s:this.duration)*1e3;return this.memoryStorage.set(this.getKey(e),t,s),{remainingPoints:0,msBeforeNext:n===0?-1:n,consumedPoints:t,isFirstInDuration:!1}}get(e){let t=this.memoryStorage.get(this.getKey(e));return t!=null&&(t.remainingPoints=Math.max(this.points-t.consumedPoints,0)),t}delete(e){this.memoryStorage.delete(this.getKey(e))}_getKeySecDuration(e){return e?.customDuration!=null&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}},tt=class{storage;constructor(){this.storage=new Map}incrby(e,t,s){let n=this.storage.get(e);if(n!=null){let i=n.expiresAt!=null?n.expiresAt.getTime()-new Date().getTime():-1;return n.expiresAt==null||i>0?(n.value+=t,{remainingPoints:0,msBeforeNext:i,consumedPoints:n.value,isFirstInDuration:!1}):this.set(e,t,s)}return this.set(e,t,s)}set(e,t,s){let n=s*1e3,i=this.storage.get(e);i!=null&&clearTimeout(i.timeoutId);let o={value:t,expiresAt:n>0?new Date(Date.now()+n):void 0};return this.storage.set(e,o),n>0&&(o.timeoutId=setTimeout(()=>{this.storage.delete(e)},n),o.timeoutId.unref!=null&&o.timeoutId.unref()),{remainingPoints:0,msBeforeNext:n===0?-1:n,consumedPoints:o.value,isFirstInDuration:!0}}get(e){let t=this.storage.get(e);if(t!=null)return{remainingPoints:0,msBeforeNext:t.expiresAt!=null?t.expiresAt.getTime()-new Date().getTime():-1,consumedPoints:t.value,isFirstInDuration:!1}}delete(e){let t=this.storage.get(e);return t!=null?(t.timeoutId!=null&&clearTimeout(t.timeoutId),this.storage.delete(e),!0):!1}};var f;(function(r){r[r.NEW_STREAM=0]="NEW_STREAM",r[r.MESSAGE_RECEIVER=1]="MESSAGE_RECEIVER",r[r.MESSAGE_INITIATOR=2]="MESSAGE_INITIATOR",r[r.CLOSE_RECEIVER=3]="CLOSE_RECEIVER",r[r.CLOSE_INITIATOR=4]="CLOSE_INITIATOR",r[r.RESET_RECEIVER=5]="RESET_RECEIVER",r[r.RESET_INITIATOR=6]="RESET_INITIATOR"})(f||(f={}));var ee=Object.freeze({0:"NEW_STREAM",1:"MESSAGE_RECEIVER",2:"MESSAGE_INITIATOR",3:"CLOSE_RECEIVER",4:"CLOSE_INITIATOR",5:"RESET_RECEIVER",6:"RESET_INITIATOR"}),rt=Object.freeze({NEW_STREAM:f.NEW_STREAM,MESSAGE:f.MESSAGE_INITIATOR,CLOSE:f.CLOSE_INITIATOR,RESET:f.RESET_INITIATOR}),Ft=Object.freeze({MESSAGE:f.MESSAGE_RECEIVER,CLOSE:f.CLOSE_RECEIVER,RESET:f.RESET_RECEIVER});var te=1<<20,st=4<<20,ve=class{_buffer;_headerInfo;_maxMessageSize;_maxUnprocessedMessageQueueSize;constructor(e=te,t=st){this._buffer=new A,this._headerInfo=null,this._maxMessageSize=e,this._maxUnprocessedMessageQueueSize=t}write(e){if(e==null||e.length===0)return[];if(this._buffer.append(e),this._buffer.byteLength>this._maxUnprocessedMessageQueueSize)throw new Q("Unprocessed message queue size too large!");let t=[];for(;this._buffer.length!==0;){if(this._headerInfo==null)try{this._headerInfo=this._decodeHeader(this._buffer)}catch(m){if(m.name==="InvalidMessageError")throw m;break}let{id:s,type:n,length:i,offset:o}=this._headerInfo;if(this._buffer.length-o<i)break;let h={id:s,type:n};(n===f.NEW_STREAM||n===f.MESSAGE_INITIATOR||n===f.MESSAGE_RECEIVER)&&(h.data=this._buffer.sublist(o,o+i)),t.push(h),this._buffer.consume(o+i),this._headerInfo=null}return t}_decodeHeader(e){let{value:t,offset:s}=Vt(e),{value:n,offset:i}=Vt(e,s),o=t&7;if(ee[o]==null)throw new Error(`Invalid type received: ${o}`);if(n>this._maxMessageSize)throw new Q("Message size too large");return{id:t>>3,type:o,offset:s+i,length:n}}},xs=128,zt=127;function Vt(r,e=0){let t=0,s=0,n=e,i,o=r.length;do{if(n>=o||s>49)throw e=0,new RangeError("Could not decode varint");i=r.get(n++),t+=s<28?(i&zt)<<s:(i&zt)*Math.pow(2,s),s+=7}while(i>=xs);return e=n-e,{value:t,offset:e}}var nt=10*1024,it=class{_pool;_poolOffset;constructor(){this._pool=I(nt),this._poolOffset=0}write(e,t){let s=this._pool,n=this._poolOffset;me(e.id<<3|e.type,s,n),n+=O(e.id<<3|e.type),(e.type===f.NEW_STREAM||e.type===f.MESSAGE_INITIATOR||e.type===f.MESSAGE_RECEIVER)&&e.data!=null?(me(e.data.length,s,n),n+=O(e.data.length)):(me(0,s,n),n+=O(0));let i=s.subarray(this._poolOffset,n);nt-n<100?(this._pool=I(nt),this._poolOffset=0):this._poolOffset=n,t.append(i),(e.type===f.NEW_STREAM||e.type===f.MESSAGE_INITIATOR||e.type===f.MESSAGE_RECEIVER)&&e.data!=null&&t.append(e.data)}},ws=new it;function re(r){let e=new A;return ws.write(r,e),e}var ot=class extends Ee{streamId;types;maxDataSize;muxer;constructor(e){super(e),this.types=e.direction==="outbound"?rt:Ft,this.maxDataSize=e.maxDataSize,this.muxer=e.muxer,this.streamId=parseInt(this.id.substring(1)),e.direction==="outbound"&&queueMicrotask(()=>{this.muxer.send(re({id:this.streamId,type:rt.NEW_STREAM,data:new A(Xe(this.id))}))})}sendData(e){let t=new A,s=e.byteLength;for(;e.byteLength>0;){let n=Math.min(e.byteLength,this.maxDataSize),i=e.sublist(0,n);e=e.sublist(n),t.append(re({id:this.streamId,type:this.types.MESSAGE,data:i}))}return{sentBytes:s,canSendMore:this.muxer.send(t)}}sendReset(){return this.muxer.send(re({id:this.streamId,type:this.types.RESET}))}async sendCloseWrite(e){this.muxer.send(re({id:this.streamId,type:this.types.CLOSE})),e?.signal?.throwIfAborted()}async sendCloseRead(e){e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}};function kt(r){let{id:e,muxer:t,direction:s,maxMsgSize:n=te}=r;return new ot({...r,id:s==="outbound"?`i${e}`:`r${e}`,direction:s,maxDataSize:n,muxer:t,log:r.log.newScope(`${s}:${e}`),protocol:""})}var ys=5;function Es(r){let e={...r,type:`${ee[r.type]} (${r.type})`};return r.type===f.NEW_STREAM&&(e.data=de(r.data.subarray())),(r.type===f.MESSAGE_INITIATOR||r.type===f.MESSAGE_RECEIVER)&&(e.data=de(r.data.subarray(),"base16")),e}var Le=class extends ye{_streamId;rateLimiter;maxMessageSize;maxUnprocessedMessageQueueSize;decoder;constructor(e,t){super(e,{...t,protocol:"/mplex/6.7.0",name:"mplex"}),this._streamId=0,this.maxMessageSize=t.maxMessageSize??te,this.maxUnprocessedMessageQueueSize=t.maxUnprocessedMessageQueueSize??st,this.decoder=new ve(this.maxMessageSize,this.maxUnprocessedMessageQueueSize),this.rateLimiter=new Se({points:t.disconnectThreshold??ys,duration:1})}onData(e){for(let t of this.decoder.write(e))this.handleMessage(t)}onCreateStream(e){if(this.status!=="open")throw new P("Muxer already closed");let t=this._streamId++;return this._newStream(t,"outbound",e)}_newStream(e,t,s){return this.log("new %s stream %s",t,e),kt({...s,id:e,direction:t,maxMsgSize:this.maxMessageSize,log:this.log,muxer:this})}handleMessage(e){if(this.log.enabled&&this.log.trace("incoming message",Es(e)),e.type===f.NEW_STREAM){try{this.rateLimiter.consume("new-stream",1)}catch{this.log("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),this.abort(new Error("Too many open streams"));return}let n=this._newStream(e.id,"inbound",this.streamOptions);this.onRemoteStream(n);return}let t=`${(e.type&1)===1?"i":"r"}${e.id}`,s=this.streams.find(n=>n.id===t);if(s==null){this.log("missing stream %s for message type %s",t,ee[e.type]);try{this.rateLimiter.consume("missing-stream",1)}catch{this.log("rate limit hit when receiving messages for streams that do not exist - closing remote connection"),this.abort(new Error("Too many messages for missing streams"));return}return}try{switch(e.type){case f.MESSAGE_INITIATOR:case f.MESSAGE_RECEIVER:s.onData(e.data);break;case f.CLOSE_INITIATOR:case f.CLOSE_RECEIVER:s.onRemoteCloseWrite();break;case f.RESET_INITIATOR:case f.RESET_RECEIVER:s.onRemoteReset();break;default:this.log("unknown message type")}}catch(n){this.log.error("error while processing message - %e",n),s.abort(n)}}};var at=class{protocol="/mplex/6.7.0";_init;constructor(e={}){this._init=e}[Symbol.toStringTag]="@libp2p/mplex";[ct]=["@libp2p/stream-multiplexing"];createStreamMuxer(e){return new Le(e,{...this._init})}};function Ss(r={}){return()=>new at(r)}return jt(vs);})();
|
3
3
|
return Libp2PMplex}));
|
4
4
|
//# sourceMappingURL=index.min.js.map
|