@libp2p/pnet 3.0.27-d5534174d → 3.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPnet = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPnet=(()=>{var ir=Object.create;var ge=Object.defineProperty;var or=Object.getOwnPropertyDescriptor;var ar=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var wt=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},P=(r,e)=>{for(var t in e)ge(r,t,{get:e[t],enumerable:!0})},bt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ar(e))!cr.call(r,s)&&s!==t&&ge(r,s,{get:()=>e[s],enumerable:!(n=or(e,s))||n.enumerable});return r};var ur=(r,e,t)=>(t=r!=null?ir(fr(r)):{},bt(e||!r||!r.__esModule?ge(t,"default",{value:r,enumerable:!0}):t,r)),hr=r=>bt(ge({},"__esModule",{value:!0}),r);var Xt=wt(($i,Yt)=>{var _n=(r,e)=>function(){return e||(0,r[Object.keys(r)[0]])((e={exports:{}}).exports,e),e.exports},Pn=(()=>{for(var r=new Uint8Array(128),e=0;e<64;e++)r[e<26?e+65:e<52?e+71:e<62?e-4:e*4-205]=e;return t=>{for(var n=t.length,s=new Uint8Array((n-(t[n-1]=="=")-(t[n-2]=="="))*3/4|0),o=0,a=0;o<n;){var f=r[t.charCodeAt(o++)],c=r[t.charCodeAt(o++)],l=r[t.charCodeAt(o++)],u=r[t.charCodeAt(o++)];s[a++]=f<<2|c>>4,s[a++]=c<<4|l>>2,s[a++]=l<<6|u}return s}})(),qn=_n({"wasm-binary:./xsalsa20.wat"(r,e){e.exports=Pn("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")}}),On=qn(),zn=new WebAssembly.Module(On);Yt.exports=r=>new WebAssembly.Instance(zn,r).exports});var rr=wt((Ji,tr)=>{var pe=typeof WebAssembly<"u"&&Xt()(),Fe=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]),z=144,se=z,Te=[];tr.exports=G;G.NONCEBYTES=24;G.KEYBYTES=32;G.core_hsalsa20=er;G.SIGMA=Fe;function G(r,e){if(!(this instanceof G))return new G(r,e);if(!r||r.length<24)throw new Error("nonce must be at least 24 bytes");if(!e||e.length<32)throw new Error("key must be at least 32 bytes");this._xor=pe?new _e(r,e):new dt(r,e)}G.prototype.update=function(r,e){if(!r)throw new Error("input must be Uint8Array or Buffer");return e||(e=new Uint8Array(r.length)),r.length&&this._xor.update(r,e),e};G.prototype.final=G.prototype.finalize=function(){this._xor.finalize(),this._xor=null};function _e(r,e){Te.length||(Te.push(z),z+=64),this._pointer=Te.pop(),this._nonce=this._pointer+8,this._key=this._nonce+24,this._overflow=0,this._memory=new Uint8Array(pe.memory.buffer),this._memory.fill(0,this._pointer,this._pointer+8),this._memory.set(r,this._nonce),this._memory.set(e,this._key)}_e.prototype.realloc=function(r){pe.memory.grow(Math.ceil(Math.abs(r-this._memory.length)/65536)),this._memory=new Uint8Array(pe.memory.buffer)};_e.prototype.update=function(r,e){var t=this._overflow+r.length,n=z+this._overflow;se=z+t,se>=this._memory.length&&this.realloc(se),this._memory.set(r,n),pe.xsalsa20_xor(this._pointer,z,z,t,this._nonce,this._key),e.set(this._memory.subarray(n,z+t)),this._overflow=t&63};_e.prototype.finalize=function(){this._memory.fill(0,this._pointer,this._key+32),se>z&&(this._memory.fill(0,z,se),se=0),Te.push(this._pointer)};function dt(r,e){this._s=new Uint8Array(32),this._z=new Uint8Array(16),this._overflow=0,er(this._s,r,e,Fe);for(var t=0;t<8;t++)this._z[t]=r[t+16]}dt.prototype.update=function(r,e){for(var t=new Uint8Array(64),n=0,s=this._overflow,o=r.length+this._overflow,a=this._z,f=-this._overflow,c=-this._overflow;o>=64;){for(Zt(t,a,this._s,Fe);s<64;s++)e[c+s]=r[f+s]^t[s];for(n=1,s=8;s<16;s++)n+=a[s]&255|0,a[s]=n&255,n>>>=8;o-=64,c+=64,f+=64,s=0}if(o>0)for(Zt(t,a,this._s,Fe);s<o;s++)e[c+s]=r[f+s]^t[s];this._overflow=o&63};dt.prototype.finalize=function(){this._s.fill(0),this._z.fill(0)};function Zt(r,e,t,n){for(var s=n[0]&255|(n[1]&255)<<8|(n[2]&255)<<16|(n[3]&255)<<24,o=t[0]&255|(t[1]&255)<<8|(t[2]&255)<<16|(t[3]&255)<<24,a=t[4]&255|(t[5]&255)<<8|(t[6]&255)<<16|(t[7]&255)<<24,f=t[8]&255|(t[9]&255)<<8|(t[10]&255)<<16|(t[11]&255)<<24,c=t[12]&255|(t[13]&255)<<8|(t[14]&255)<<16|(t[15]&255)<<24,l=n[4]&255|(n[5]&255)<<8|(n[6]&255)<<16|(n[7]&255)<<24,u=e[0]&255|(e[1]&255)<<8|(e[2]&255)<<16|(e[3]&255)<<24,h=e[4]&255|(e[5]&255)<<8|(e[6]&255)<<16|(e[7]&255)<<24,p=e[8]&255|(e[9]&255)<<8|(e[10]&255)<<16|(e[11]&255)<<24,x=e[12]&255|(e[13]&255)<<8|(e[14]&255)<<16|(e[15]&255)<<24,_=n[8]&255|(n[9]&255)<<8|(n[10]&255)<<16|(n[11]&255)<<24,F=t[16]&255|(t[17]&255)<<8|(t[18]&255)<<16|(t[19]&255)<<24,w=t[20]&255|(t[21]&255)<<8|(t[22]&255)<<16|(t[23]&255)<<24,d=t[24]&255|(t[25]&255)<<8|(t[26]&255)<<16|(t[27]&255)<<24,L=t[28]&255|(t[29]&255)<<8|(t[30]&255)<<16|(t[31]&255)<<24,N=n[12]&255|(n[13]&255)<<8|(n[14]&255)<<16|(n[15]&255)<<24,m=s,b=o,I=a,y=f,v=c,E=l,g=u,A=h,B=p,S=x,C=_,M=F,U=w,R=d,T=L,D=N,i,ie=0;ie<20;ie+=2)i=m+U|0,v^=i<<7|i>>>25,i=v+m|0,B^=i<<9|i>>>23,i=B+v|0,U^=i<<13|i>>>19,i=U+B|0,m^=i<<18|i>>>14,i=E+b|0,S^=i<<7|i>>>25,i=S+E|0,R^=i<<9|i>>>23,i=R+S|0,b^=i<<13|i>>>19,i=b+R|0,E^=i<<18|i>>>14,i=C+g|0,T^=i<<7|i>>>25,i=T+C|0,I^=i<<9|i>>>23,i=I+T|0,g^=i<<13|i>>>19,i=g+I|0,C^=i<<18|i>>>14,i=D+M|0,y^=i<<7|i>>>25,i=y+D|0,A^=i<<9|i>>>23,i=A+y|0,M^=i<<13|i>>>19,i=M+A|0,D^=i<<18|i>>>14,i=m+y|0,b^=i<<7|i>>>25,i=b+m|0,I^=i<<9|i>>>23,i=I+b|0,y^=i<<13|i>>>19,i=y+I|0,m^=i<<18|i>>>14,i=E+v|0,g^=i<<7|i>>>25,i=g+E|0,A^=i<<9|i>>>23,i=A+g|0,v^=i<<13|i>>>19,i=v+A|0,E^=i<<18|i>>>14,i=C+S|0,M^=i<<7|i>>>25,i=M+C|0,B^=i<<9|i>>>23,i=B+M|0,S^=i<<13|i>>>19,i=S+B|0,C^=i<<18|i>>>14,i=D+T|0,U^=i<<7|i>>>25,i=U+D|0,R^=i<<9|i>>>23,i=R+U|0,T^=i<<13|i>>>19,i=T+R|0,D^=i<<18|i>>>14;m=m+s|0,b=b+o|0,I=I+a|0,y=y+f|0,v=v+c|0,E=E+l|0,g=g+u|0,A=A+h|0,B=B+p|0,S=S+x|0,C=C+_|0,M=M+F|0,U=U+w|0,R=R+d|0,T=T+L|0,D=D+N|0,r[0]=m>>>0&255,r[1]=m>>>8&255,r[2]=m>>>16&255,r[3]=m>>>24&255,r[4]=b>>>0&255,r[5]=b>>>8&255,r[6]=b>>>16&255,r[7]=b>>>24&255,r[8]=I>>>0&255,r[9]=I>>>8&255,r[10]=I>>>16&255,r[11]=I>>>24&255,r[12]=y>>>0&255,r[13]=y>>>8&255,r[14]=y>>>16&255,r[15]=y>>>24&255,r[16]=v>>>0&255,r[17]=v>>>8&255,r[18]=v>>>16&255,r[19]=v>>>24&255,r[20]=E>>>0&255,r[21]=E>>>8&255,r[22]=E>>>16&255,r[23]=E>>>24&255,r[24]=g>>>0&255,r[25]=g>>>8&255,r[26]=g>>>16&255,r[27]=g>>>24&255,r[28]=A>>>0&255,r[29]=A>>>8&255,r[30]=A>>>16&255,r[31]=A>>>24&255,r[32]=B>>>0&255,r[33]=B>>>8&255,r[34]=B>>>16&255,r[35]=B>>>24&255,r[36]=S>>>0&255,r[37]=S>>>8&255,r[38]=S>>>16&255,r[39]=S>>>24&255,r[40]=C>>>0&255,r[41]=C>>>8&255,r[42]=C>>>16&255,r[43]=C>>>24&255,r[44]=M>>>0&255,r[45]=M>>>8&255,r[46]=M>>>16&255,r[47]=M>>>24&255,r[48]=U>>>0&255,r[49]=U>>>8&255,r[50]=U>>>16&255,r[51]=U>>>24&255,r[52]=R>>>0&255,r[53]=R>>>8&255,r[54]=R>>>16&255,r[55]=R>>>24&255,r[56]=T>>>0&255,r[57]=T>>>8&255,r[58]=T>>>16&255,r[59]=T>>>24&255,r[60]=D>>>0&255,r[61]=D>>>8&255,r[62]=D>>>16&255,r[63]=D>>>24&255}function er(r,e,t,n){for(var s=n[0]&255|(n[1]&255)<<8|(n[2]&255)<<16|(n[3]&255)<<24,o=t[0]&255|(t[1]&255)<<8|(t[2]&255)<<16|(t[3]&255)<<24,a=t[4]&255|(t[5]&255)<<8|(t[6]&255)<<16|(t[7]&255)<<24,f=t[8]&255|(t[9]&255)<<8|(t[10]&255)<<16|(t[11]&255)<<24,c=t[12]&255|(t[13]&255)<<8|(t[14]&255)<<16|(t[15]&255)<<24,l=n[4]&255|(n[5]&255)<<8|(n[6]&255)<<16|(n[7]&255)<<24,u=e[0]&255|(e[1]&255)<<8|(e[2]&255)<<16|(e[3]&255)<<24,h=e[4]&255|(e[5]&255)<<8|(e[6]&255)<<16|(e[7]&255)<<24,p=e[8]&255|(e[9]&255)<<8|(e[10]&255)<<16|(e[11]&255)<<24,x=e[12]&255|(e[13]&255)<<8|(e[14]&255)<<16|(e[15]&255)<<24,_=n[8]&255|(n[9]&255)<<8|(n[10]&255)<<16|(n[11]&255)<<24,F=t[16]&255|(t[17]&255)<<8|(t[18]&255)<<16|(t[19]&255)<<24,w=t[20]&255|(t[21]&255)<<8|(t[22]&255)<<16|(t[23]&255)<<24,d=t[24]&255|(t[25]&255)<<8|(t[26]&255)<<16|(t[27]&255)<<24,L=t[28]&255|(t[29]&255)<<8|(t[30]&255)<<16|(t[31]&255)<<24,N=n[12]&255|(n[13]&255)<<8|(n[14]&255)<<16|(n[15]&255)<<24,m=s,b=o,I=a,y=f,v=c,E=l,g=u,A=h,B=p,S=x,C=_,M=F,U=w,R=d,T=L,D=N,i,ie=0;ie<20;ie+=2)i=m+U|0,v^=i<<7|i>>>25,i=v+m|0,B^=i<<9|i>>>23,i=B+v|0,U^=i<<13|i>>>19,i=U+B|0,m^=i<<18|i>>>14,i=E+b|0,S^=i<<7|i>>>25,i=S+E|0,R^=i<<9|i>>>23,i=R+S|0,b^=i<<13|i>>>19,i=b+R|0,E^=i<<18|i>>>14,i=C+g|0,T^=i<<7|i>>>25,i=T+C|0,I^=i<<9|i>>>23,i=I+T|0,g^=i<<13|i>>>19,i=g+I|0,C^=i<<18|i>>>14,i=D+M|0,y^=i<<7|i>>>25,i=y+D|0,A^=i<<9|i>>>23,i=A+y|0,M^=i<<13|i>>>19,i=M+A|0,D^=i<<18|i>>>14,i=m+y|0,b^=i<<7|i>>>25,i=b+m|0,I^=i<<9|i>>>23,i=I+b|0,y^=i<<13|i>>>19,i=y+I|0,m^=i<<18|i>>>14,i=E+v|0,g^=i<<7|i>>>25,i=g+E|0,A^=i<<9|i>>>23,i=A+g|0,v^=i<<13|i>>>19,i=v+A|0,E^=i<<18|i>>>14,i=C+S|0,M^=i<<7|i>>>25,i=M+C|0,B^=i<<9|i>>>23,i=B+M|0,S^=i<<13|i>>>19,i=S+B|0,C^=i<<18|i>>>14,i=D+T|0,U^=i<<7|i>>>25,i=U+D|0,R^=i<<9|i>>>23,i=R+U|0,T^=i<<13|i>>>19,i=T+R|0,D^=i<<18|i>>>14;r[0]=m>>>0&255,r[1]=m>>>8&255,r[2]=m>>>16&255,r[3]=m>>>24&255,r[4]=E>>>0&255,r[5]=E>>>8&255,r[6]=E>>>16&255,r[7]=E>>>24&255,r[8]=C>>>0&255,r[9]=C>>>8&255,r[10]=C>>>16&255,r[11]=C>>>24&255,r[12]=D>>>0&255,r[13]=D>>>8&255,r[14]=D>>>16&255,r[15]=D>>>24&255,r[16]=g>>>0&255,r[17]=g>>>8&255,r[18]=g>>>16&255,r[19]=g>>>24&255,r[20]=A>>>0&255,r[21]=A>>>8&255,r[22]=A>>>16&255,r[23]=A>>>24&255,r[24]=B>>>0&255,r[25]=B>>>8&255,r[26]=B>>>16&255,r[27]=B>>>24&255,r[28]=S>>>0&255,r[29]=S>>>8&255,r[30]=S>>>16&255,r[31]=S>>>24&255}});var jn={};P(jn,{generateKey:()=>nr,preSharedKey:()=>kn});var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Ae=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var j=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},oe=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var xe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},J=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},we=class extends J{constructor(e,t){super(!0,e,t)}},be=class extends J{constructor(e,t){super(!1,e,t)}};function lr(r){return typeof r?.handleEvent=="function"}function dr(r){return r===!0||r===!1}function mr(r){return dr(r)?r:r?.capture??!1}function qe(r){let e={capture:mr(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function yt(r,e){return qe(r).capture===qe(e).capture}var ye=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,n){let s=qe(n);if(s?.signal?.aborted===!0)return;let o=l=>{s.once&&this.removeEventListener(e,t,s),lr(t)?t.handleEvent(l):t(l)},a=this.#e.get(e);if(a==null&&(a=[],this.#e.set(e,a)),a.some(l=>l.callback!==t?!1:yt(l.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,t,s)};s.signal?.addEventListener("abort",c),a.push({callback:t,wrapper:o,options:s,onAbort:c})}removeEventListener(e,t,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,s.filter(o=>o.callback===t&&yt(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function k(r=0){return new Uint8Array(r)}function V(r=0){return new Uint8Array(r)}function pr(r){return r?.buffer instanceof ArrayBuffer}function Et(r){if(pr(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Oe(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=V(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return Et(t)}function It(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Bt=Symbol.for("@achingbrain/uint8arraylist");function vt(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 Ee(r){return!!r?.[Bt]}var K=class r{bufs;length;[Bt]=!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(Ee(n)){t+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(Ee(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=vt(this.bufs,e);return t.buf[t.index]}set(e,t){let n=vt(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(Ee(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 Oe(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Oe(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 a=this.bufs[o],f=s,c=f+a.byteLength;if(s=c,e>=c)continue;let l=e>=f&&e<c,u=t>f&&t<=c;if(l&&u){if(e===f&&t===c){n.push(a);break}let h=e-f;n.push(a.subarray(h,h+(t-e)));break}if(l){if(e===0){n.push(a);continue}n.push(a.subarray(e-f));continue}if(u){if(t===c){n.push(a);break}n.push(a.subarray(0,t-f));break}n.push(a)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Ee(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,a=new Int32Array(o);for(let h=0;h<o;h++)a[h]=-1;for(let h=0;h<s;h++)a[n[h]]=h;let f=a,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let h=t;h<=c;h+=u){u=0;for(let p=l;p>=0;p--){let x=this.get(h+p);if(n[p]!==x){u=Math.max(1,p-f[x]);break}}if(u===0)return h}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=V(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=k(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=k(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=k(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=V(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=k(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=k(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=k(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=k(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=k(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(!It(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 Ve={};P(Ve,{base10:()=>Ir});var is=new Uint8Array(0);function St(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 q(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return H(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return H(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Ct(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Lt=4096;function Dt(r){let e=r.length;if(e<=Lt)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Lt));return t}function gr(r){return r?.buffer instanceof ArrayBuffer}function H(r){return gr(r)?r:r.slice()}function Ar(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<r.length;o++){var a=r.charAt(o),f=a.charCodeAt(0);if(n[f]!==255)throw new TypeError(a+" is ambiguous");if(n[f]=o,t){var c=a.toLowerCase().charCodeAt(0),l=a.toUpperCase().charCodeAt(0);c!==f&&(n[c]=o),l!==f&&(n[l]=o)}}var u=r.length,h=r.charAt(0),p=Math.log(u)/Math.log(256),x=Math.log(256)/Math.log(u);function _(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var L=0,N=0,m=0,b=d.length;m!==b&&d[m]===0;)m++,L++;for(var I=(b-m)*x+1>>>0,y=new Uint8Array(I);m!==b;){for(var v=d[m],E=0,g=I-1;(v!==0||E<N)&&g!==-1;g--,E++)v+=256*y[g]>>>0,y[g]=v%u>>>0,v=v/u>>>0;if(v!==0)throw new Error("Non-zero carry");N=E,m++}for(var A=I-N;A!==I&&y[A]===0;)A++;for(var B=h.repeat(L);A<I;++A)B+=r.charAt(y[A]);return B}function F(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var L=0;if(d[L]!==" "){for(var N=0,m=0;d[L]===h;)N++,L++;for(var b=(d.length-L)*p+1>>>0,I=new Uint8Array(b);d[L];){var y=n[d.charCodeAt(L)];if(y===255)return;for(var v=0,E=b-1;(y!==0||v<m)&&E!==-1;E--,v++)y+=u*I[E]>>>0,I[E]=y%256>>>0,y=y/256>>>0;if(y!==0)throw new Error("Non-zero carry");m=v,L++}if(d[L]!==" "){for(var g=b-m;g!==b&&I[g]===0;)g++;for(var A=new Uint8Array(N+(b-g)),B=N;g!==b;)A[B++]=I[g++];return A}}}function w(d){var L=F(d);if(L)return L;throw new Error(`Non-${e} character`)}return{encode:_,decodeUnsafe:F,decode:w}}var xr=Ar,wr=xr,Nt=wr;var ze=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")}},Ge=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 Mt(this,e)}},ke=class{decoders;constructor(e){this.decoders=e}or(e){return Mt(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 Mt(r,e){return new ke({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var je=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 ze(e,t,n),this.decoder=new Ge(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Y({name:r,prefix:e,encode:t,decode:n}){return new je(r,e,t,n)}function W({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:o}=Nt(t,r,n);return Y({prefix:e,name:r,encode:s,decode:a=>q(o(a))})}function br(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,f=0,c=0;for(let l=0;l<s;++l){let u=e[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|u,a+=t,a>=8&&(a-=8,o[c++]=255&f>>a)}if(a>=t||(255&f<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}function yr(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",a=0,f=0;for(let c=0;c<r.length;++c)for(f=f<<8|r[c],a+=8;a>t;)a-=t,o+=e[s&f>>a];if(a!==0&&(o+=e[s&f<<t-a]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function Er(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),o=r[n].toUpperCase();s!==r[n]&&(t[s]=n),o!==r[n]&&(t[o]=n)}return t}function Q({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let o=Er(n,s);return Y({prefix:e,name:r,encode(a){return yr(a,n,t)},decode(a){return br(a,o,t,r)}})}var Ir=W({prefix:"9",name:"base10",alphabet:"0123456789"});var Ke={};P(Ke,{base16:()=>vr,base16upper:()=>Br});var vr=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Br=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var We={};P(We,{base2:()=>Lr});var Lr=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var He={};P(He,{base256emoji:()=>Nr});var Ut=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Sr=Ut.reduce((r,e,t)=>(r[t]=e,r),[]),Cr=Ut.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Dr(r){return r.reduce((e,t)=>(e+=Sr[t],e),"")}function Qr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Cr[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var Nr=Y({prefix:"\u{1F680}",name:"base256emoji",encode:Dr,decode:Qr});var $e={};P($e,{base32:()=>X,base32hex:()=>Tr,base32hexpad:()=>_r,base32hexpadupper:()=>Pr,base32hexupper:()=>Fr,base32pad:()=>Ur,base32padupper:()=>Rr,base32upper:()=>Mr,base32z:()=>qr});var X=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Mr=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ur=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Rr=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Tr=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Fr=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),_r=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Pr=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),qr=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Je={};P(Je,{base36:()=>ae,base36upper:()=>Or});var ae=W({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Or=W({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ye={};P(Ye,{base58btc:()=>O,base58flickr:()=>zr});var O=W({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),zr=W({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xe={};P(Xe,{base64:()=>Gr,base64pad:()=>kr,base64url:()=>jr,base64urlpad:()=>Vr});var Gr=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kr=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jr=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vr=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ze={};P(Ze,{base8:()=>Kr});var Kr=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var et={};P(et,{identity:()=>Wr});var Wr=Y({prefix:"\0",name:"identity",encode:r=>Dt(q(r)),decode:r=>q(Ct(r))});var ys=new TextEncoder,Es=new TextDecoder;var rt={};P(rt,{identity:()=>An});var Jr=Ft,Rt=128,Yr=127,Xr=~Yr,Zr=Math.pow(2,31);function Ft(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Zr;)e[t++]=r&255|Rt,r/=128;for(;r&Xr;)e[t++]=r&255|Rt,r>>>=7;return e[t]=r|0,Ft.bytes=t-n+1,e}var en=tt,tn=128,Tt=127;function tt(r,n){var t=0,n=n||0,s=0,o=n,a,f=r.length;do{if(o>=f)throw tt.bytes=0,new RangeError("Could not decode varint");a=r[o++],t+=s<28?(a&Tt)<<s:(a&Tt)*Math.pow(2,s),s+=7}while(a>=tn);return tt.bytes=o-n,t}var rn=Math.pow(2,7),nn=Math.pow(2,14),sn=Math.pow(2,21),on=Math.pow(2,28),an=Math.pow(2,35),fn=Math.pow(2,42),cn=Math.pow(2,49),un=Math.pow(2,56),hn=Math.pow(2,63),ln=function(r){return r<rn?1:r<nn?2:r<sn?3:r<on?4:r<an?5:r<fn?6:r<cn?7:r<un?8:r<hn?9:10},dn={encode:Jr,decode:en,encodingLength:ln},mn=dn,fe=mn;function ce(r,e=0){let t=fe.decode(r,e),n=fe.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function Z(r,e,t=0){return fe.encode(r,e,t),e}function ee(r){return fe.encodingLength(r)}function re(r,e){let t=e.byteLength,n=ee(r),s=n+ee(t),o=new Uint8Array(s+t);return Z(r,o,0),Z(t,o,n),o.set(e,s),new te(r,t,e,o)}function _t(r){let e=q(r),[t,n]=ce(e),[s,o]=ce(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==s)throw new Error("Incorrect length");return new te(t,s,a,e)}function Pt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&St(r.bytes,t.bytes)}}var te=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=H(n),this.bytes=H(s)}};var qt=0,pn="identity",Ot=q;function gn(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 re(qt,Ot(r))}var An={code:qt,name:pn,encode:Ot,digest:gn};var it={};P(it,{sha256:()=>wn,sha512:()=>bn});var xn=20;function st({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new nt(r,e,t,n,s)}var nt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??xn,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?zt(n,this.code,t?.truncate):n.then(s=>zt(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function zt(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 re(e,r)}function kt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var wn=st({name:"sha2-256",code:18,encode:kt("SHA-256")}),bn=st({name:"sha2-512",code:19,encode:kt("SHA-512")});function jt(r,e){let{bytes:t,version:n}=r;return n===0?En(t,ot(r),e??O.encoder):In(t,ot(r),e??X.encoder)}var Vt=new WeakMap;function ot(r){let e=Vt.get(r);if(e==null){let t=new Map;return Vt.set(r,t),t}return e}var ve=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=H(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==he)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==vn)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=re(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&&Pt(e.multihash,n.multihash)}toString(e){return jt(this,e)}toJSON(){return{"/":jt(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:a}=t;return new r(n,s,o,a??Kt(n,s,o.bytes))}else if(t[Bn]===!0){let{version:n,multihash:s,code:o}=t,a=_t(s);return r.create(n,o,a)}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!==he)throw new Error(`Version 0 CID must use dag-pb (code: ${he}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=Kt(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,he,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=q(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),a=new te(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(a):r.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,p]=ce(e.subarray(t));return t+=p,h},s=n(),o=he;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let a=t,f=n(),c=n(),l=t+c,u=l-a;return{version:s,codec:o,multihashCode:f,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,s]=yn(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 ot(o).set(n,e),o}};function yn(r,e){switch(r[0]){case"Q":{let t=e??O;return[O.prefix,t.decode(`${O.prefix}${r}`)]}case O.prefix:{let t=e??O;return[O.prefix,t.decode(r)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}case ae.prefix:{let t=e??ae;return[ae.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 En(r,e,t){let{prefix:n}=t;if(n!==O.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 In(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 he=112,vn=18;function Kt(r,e,t){let n=ee(r),s=n+ee(e),o=new Uint8Array(s+t.byteLength);return Z(r,o,0),Z(e,o,n),o.set(t,s),o}var Bn=Symbol.for("@ipld/js-cid/CID");var at={...et,...We,...Ze,...Ve,...Ke,...$e,...Je,...Ye,...Xe,...He},js={...it,...rt};function Ht(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Wt=Ht("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ft=Ht("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=V(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ln={utf8:Wt,"utf-8":Wt,hex:at.base16,latin1:ft,ascii:ft,binary:ft,...at},Be=Ln;function Le(r,e="utf8"){let t=Be[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var Xs=Math.pow(2,7),Zs=Math.pow(2,14),ei=Math.pow(2,21),ti=Math.pow(2,28),ri=Math.pow(2,35),ni=Math.pow(2,42),si=Math.pow(2,49);function Se(r,e="utf8"){let t=Be[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function Ce(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var De=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}},ne=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new De(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 De(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 ct=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Qe(r={}){return Cn(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 Cn(r,e){e=e??{};let t=e.onEnd,n=new ne,s,o,a,f=Ce(),c=async()=>{try{return n.isEmpty()?a?{done:!0}:await new Promise((w,d)=>{o=L=>{o=null,n.push(L);try{w(r(n))}catch(N){d(N)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{f.resolve(),f=Ce()})}},l=w=>o!=null?o(w):(n.push(w),s),u=w=>(n=new ne,o!=null?o({error:w}):(n.push({error:w}),s)),h=w=>{if(a)return s;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:w})},p=w=>a?s:(a=!0,w!=null?u(w):l({done:!0})),x=()=>(n=new ne,p(),{done:!0}),_=w=>(p(w),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:x,throw:_,push:h,end:p,get readableLength(){return n.size},onEmpty:async w=>{let d=w?.signal;if(d?.throwIfAborted(),n.isEmpty())return;let L,N;d!=null&&(L=new Promise((m,b)=>{N=()=>{b(new ct)},d.addEventListener("abort",N)}));try{await Promise.race([f.promise,L])}finally{N!=null&&d!=null&&d?.removeEventListener("abort",N)}}},t==null)return s;let F=s;return s={[Symbol.asyncIterator](){return this},next(){return F.next()},throw(w){return F.throw(w),t!=null&&(t(w),t=void 0),{done:!0}},return(){return F.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(w){return F.end(w),t!=null&&(t(w),t=void 0),s},get readableLength(){return F.readableLength},onEmpty:w=>F.onEmpty(w)},s}var ut=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},$t=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function ht(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:a}=e,f,c,u=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(a?.aborted){p($t(a));return}if(a&&(c=()=>{p($t(a))},a.addEventListener("abort",c,{once:!0})),r.then(h,p),t===Number.POSITIVE_INFINITY)return;let x=new ut;f=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(_){p(_)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?h():s instanceof Error?p(s):(x.message=s??`Promise timed out after ${t} milliseconds`,p(x))},t)}).finally(()=>{u.clear(),c&&a&&a.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,f),f=void 0},u}var Dn=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 Qn(r,e,t){let n,s=new Promise((o,a)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let f=[e].flat(),c=[],{addListener:l,removeListener:u}=Dn(r),h=async(...x)=>{let _=t.multiArgs?x:x[0];if(t.filter)try{if(!await t.filter(_))return}catch(F){n(),a(F);return}c.push(_),t.count===c.length&&(n(),o(c))},p=(...x)=>{n(),a(t.rejectionMultiArgs?x:x[0])};n=()=>{for(let x of f)u(x,h);for(let x of t.rejectionEvents)f.includes(x)||u(x,p)};for(let x of f)l(x,h);for(let x of t.rejectionEvents)f.includes(x)||l(x,p);t.signal&&t.signal.addEventListener("abort",()=>{p(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=ht(s,{milliseconds:t.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function le(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Qn(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var de=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var Ne=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Nn(r){return r.reason}async function me(r,e,t){if(e==null)return r;let n=t?.translateError??Nn;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let s;try{return await Promise.race([r,new Promise((o,a)=>{s=()=>{a(n(e))},e.addEventListener("abort",s)})])}finally{s!=null&&e.removeEventListener("abort",s)}}var Mn=Math.pow(2,20)*4,Me=class extends ye{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Mn,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new K,this.writeBuffer=new K,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,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=s=>{this.onDrainPromise?.reject(s.error??new Ne)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),me(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Qe(),t=o=>{e.push(o.data)};this.addEventListener("message",t);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new j(`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 we(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new j("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 j("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 j(`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)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new j(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(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 Ae;this.dispatchEvent(new be(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 J))}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;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),a=new K(o);this.writeBuffer.consume(o.byteLength);let f;try{f=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(a),this.abort(c),c}if(e=f.canSendMore,n+=f.sentBytes,f.sentBytes!==a.byteLength&&(a.consume(f.sentBytes),this.writeBuffer.prepend(a)),!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",n,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 xe(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 oe(`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 oe(`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")}};var Ue=class extends Me{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="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 le(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await le(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var Un=4194304,Re=class extends Error{static name="UnwrappedError";name="UnwrappedError"};function Rn(r){return typeof r?.closeRead=="function"}function Tn(r){return typeof r?.close=="function"}function lt(r){return Rn(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Tn(r)?r.status!=="open":!1}function Fn(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Jt(r,e){let t=e?.maxBufferSize??Un,n=new K,s,o=!1;if(!Fn(r))throw new $("Argument should be a Stream or a Multiaddr");let a=u=>{if(n.append(u.data),n.byteLength>t){let h=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${h} > ${t}`))}s?.resolve()};r.addEventListener("message",a);let f=u=>{u.error!=null?s?.reject(u.error):s?.resolve()};r.addEventListener("close",f);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(u){if(o===!0)throw new Re("Stream was unwrapped");if(lt(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new de(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let h=u?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await me(s.promise,u?.signal),lt(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}s=Promise.withResolvers()}let p=u?.bytes??n.byteLength;if(n.byteLength<p){if(lt(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,p),new de(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return l.read(u)}let x=n.sublist(0,p);return n.consume(p),x},async write(u,h){if(o===!0)throw new Re("Stream was unwrapped");r.send(u)||await le(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,r.removeEventListener("message",a),r.removeEventListener("close",f),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return l}var At=ur(rr(),1);var mt="Your private shared key is invalid";function nr(r){let e=Se(crypto.getRandomValues(new Uint8Array(gt)),"base16"),t=Le(`/key/swarm/psk/1.0.0/
2
+ "use strict";var Libp2PPnet=(()=>{var ar=Object.create;var pe=Object.defineProperty;var fr=Object.getOwnPropertyDescriptor;var cr=Object.getOwnPropertyNames;var ur=Object.getPrototypeOf,hr=Object.prototype.hasOwnProperty;var wt=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},P=(r,e)=>{for(var t in e)pe(r,t,{get:e[t],enumerable:!0})},yt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of cr(e))!hr.call(r,s)&&s!==t&&pe(r,s,{get:()=>e[s],enumerable:!(n=fr(e,s))||n.enumerable});return r};var lr=(r,e,t)=>(t=r!=null?ar(ur(r)):{},yt(e||!r||!r.__esModule?pe(t,"default",{value:r,enumerable:!0}):t,r)),dr=r=>yt(pe({},"__esModule",{value:!0}),r);var Zt=wt((Yi,Xt)=>{var qn=(r,e)=>function(){return e||(0,r[Object.keys(r)[0]])((e={exports:{}}).exports,e),e.exports},On=(()=>{for(var r=new Uint8Array(128),e=0;e<64;e++)r[e<26?e+65:e<52?e+71:e<62?e-4:e*4-205]=e;return t=>{for(var n=t.length,s=new Uint8Array((n-(t[n-1]=="=")-(t[n-2]=="="))*3/4|0),o=0,a=0;o<n;){var f=r[t.charCodeAt(o++)],c=r[t.charCodeAt(o++)],l=r[t.charCodeAt(o++)],u=r[t.charCodeAt(o++)];s[a++]=f<<2|c>>4,s[a++]=c<<4|l>>2,s[a++]=l<<6|u}return s}})(),zn=qn({"wasm-binary:./xsalsa20.wat"(r,e){e.exports=On("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")}}),kn=zn(),Gn=new WebAssembly.Module(kn);Xt.exports=r=>new WebAssembly.Instance(Gn,r).exports});var nr=wt((Xi,rr)=>{var ge=typeof WebAssembly<"u"&&Zt()(),Fe=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]),z=144,se=z,Te=[];rr.exports=k;k.NONCEBYTES=24;k.KEYBYTES=32;k.core_hsalsa20=tr;k.SIGMA=Fe;function k(r,e){if(!(this instanceof k))return new k(r,e);if(!r||r.length<24)throw new Error("nonce must be at least 24 bytes");if(!e||e.length<32)throw new Error("key must be at least 32 bytes");this._xor=ge?new _e(r,e):new dt(r,e)}k.prototype.update=function(r,e){if(!r)throw new Error("input must be Uint8Array or Buffer");return e||(e=new Uint8Array(r.length)),r.length&&this._xor.update(r,e),e};k.prototype.final=k.prototype.finalize=function(){this._xor.finalize(),this._xor=null};function _e(r,e){Te.length||(Te.push(z),z+=64),this._pointer=Te.pop(),this._nonce=this._pointer+8,this._key=this._nonce+24,this._overflow=0,this._memory=new Uint8Array(ge.memory.buffer),this._memory.fill(0,this._pointer,this._pointer+8),this._memory.set(r,this._nonce),this._memory.set(e,this._key)}_e.prototype.realloc=function(r){ge.memory.grow(Math.ceil(Math.abs(r-this._memory.length)/65536)),this._memory=new Uint8Array(ge.memory.buffer)};_e.prototype.update=function(r,e){var t=this._overflow+r.length,n=z+this._overflow;se=z+t,se>=this._memory.length&&this.realloc(se),this._memory.set(r,n),ge.xsalsa20_xor(this._pointer,z,z,t,this._nonce,this._key),e.set(this._memory.subarray(n,z+t)),this._overflow=t&63};_e.prototype.finalize=function(){this._memory.fill(0,this._pointer,this._key+32),se>z&&(this._memory.fill(0,z,se),se=0),Te.push(this._pointer)};function dt(r,e){this._s=new Uint8Array(32),this._z=new Uint8Array(16),this._overflow=0,tr(this._s,r,e,Fe);for(var t=0;t<8;t++)this._z[t]=r[t+16]}dt.prototype.update=function(r,e){for(var t=new Uint8Array(64),n=0,s=this._overflow,o=r.length+this._overflow,a=this._z,f=-this._overflow,c=-this._overflow;o>=64;){for(er(t,a,this._s,Fe);s<64;s++)e[c+s]=r[f+s]^t[s];for(n=1,s=8;s<16;s++)n+=a[s]&255|0,a[s]=n&255,n>>>=8;o-=64,c+=64,f+=64,s=0}if(o>0)for(er(t,a,this._s,Fe);s<o;s++)e[c+s]=r[f+s]^t[s];this._overflow=o&63};dt.prototype.finalize=function(){this._s.fill(0),this._z.fill(0)};function er(r,e,t,n){for(var s=n[0]&255|(n[1]&255)<<8|(n[2]&255)<<16|(n[3]&255)<<24,o=t[0]&255|(t[1]&255)<<8|(t[2]&255)<<16|(t[3]&255)<<24,a=t[4]&255|(t[5]&255)<<8|(t[6]&255)<<16|(t[7]&255)<<24,f=t[8]&255|(t[9]&255)<<8|(t[10]&255)<<16|(t[11]&255)<<24,c=t[12]&255|(t[13]&255)<<8|(t[14]&255)<<16|(t[15]&255)<<24,l=n[4]&255|(n[5]&255)<<8|(n[6]&255)<<16|(n[7]&255)<<24,u=e[0]&255|(e[1]&255)<<8|(e[2]&255)<<16|(e[3]&255)<<24,h=e[4]&255|(e[5]&255)<<8|(e[6]&255)<<16|(e[7]&255)<<24,g=e[8]&255|(e[9]&255)<<8|(e[10]&255)<<16|(e[11]&255)<<24,x=e[12]&255|(e[13]&255)<<8|(e[14]&255)<<16|(e[15]&255)<<24,_=n[8]&255|(n[9]&255)<<8|(n[10]&255)<<16|(n[11]&255)<<24,F=t[16]&255|(t[17]&255)<<8|(t[18]&255)<<16|(t[19]&255)<<24,b=t[20]&255|(t[21]&255)<<8|(t[22]&255)<<16|(t[23]&255)<<24,d=t[24]&255|(t[25]&255)<<8|(t[26]&255)<<16|(t[27]&255)<<24,L=t[28]&255|(t[29]&255)<<8|(t[30]&255)<<16|(t[31]&255)<<24,N=n[12]&255|(n[13]&255)<<8|(n[14]&255)<<16|(n[15]&255)<<24,m=s,w=o,I=a,y=f,v=c,E=l,p=u,A=h,B=g,C=x,S=_,M=F,U=b,R=d,T=L,D=N,i,ie=0;ie<20;ie+=2)i=m+U|0,v^=i<<7|i>>>25,i=v+m|0,B^=i<<9|i>>>23,i=B+v|0,U^=i<<13|i>>>19,i=U+B|0,m^=i<<18|i>>>14,i=E+w|0,C^=i<<7|i>>>25,i=C+E|0,R^=i<<9|i>>>23,i=R+C|0,w^=i<<13|i>>>19,i=w+R|0,E^=i<<18|i>>>14,i=S+p|0,T^=i<<7|i>>>25,i=T+S|0,I^=i<<9|i>>>23,i=I+T|0,p^=i<<13|i>>>19,i=p+I|0,S^=i<<18|i>>>14,i=D+M|0,y^=i<<7|i>>>25,i=y+D|0,A^=i<<9|i>>>23,i=A+y|0,M^=i<<13|i>>>19,i=M+A|0,D^=i<<18|i>>>14,i=m+y|0,w^=i<<7|i>>>25,i=w+m|0,I^=i<<9|i>>>23,i=I+w|0,y^=i<<13|i>>>19,i=y+I|0,m^=i<<18|i>>>14,i=E+v|0,p^=i<<7|i>>>25,i=p+E|0,A^=i<<9|i>>>23,i=A+p|0,v^=i<<13|i>>>19,i=v+A|0,E^=i<<18|i>>>14,i=S+C|0,M^=i<<7|i>>>25,i=M+S|0,B^=i<<9|i>>>23,i=B+M|0,C^=i<<13|i>>>19,i=C+B|0,S^=i<<18|i>>>14,i=D+T|0,U^=i<<7|i>>>25,i=U+D|0,R^=i<<9|i>>>23,i=R+U|0,T^=i<<13|i>>>19,i=T+R|0,D^=i<<18|i>>>14;m=m+s|0,w=w+o|0,I=I+a|0,y=y+f|0,v=v+c|0,E=E+l|0,p=p+u|0,A=A+h|0,B=B+g|0,C=C+x|0,S=S+_|0,M=M+F|0,U=U+b|0,R=R+d|0,T=T+L|0,D=D+N|0,r[0]=m>>>0&255,r[1]=m>>>8&255,r[2]=m>>>16&255,r[3]=m>>>24&255,r[4]=w>>>0&255,r[5]=w>>>8&255,r[6]=w>>>16&255,r[7]=w>>>24&255,r[8]=I>>>0&255,r[9]=I>>>8&255,r[10]=I>>>16&255,r[11]=I>>>24&255,r[12]=y>>>0&255,r[13]=y>>>8&255,r[14]=y>>>16&255,r[15]=y>>>24&255,r[16]=v>>>0&255,r[17]=v>>>8&255,r[18]=v>>>16&255,r[19]=v>>>24&255,r[20]=E>>>0&255,r[21]=E>>>8&255,r[22]=E>>>16&255,r[23]=E>>>24&255,r[24]=p>>>0&255,r[25]=p>>>8&255,r[26]=p>>>16&255,r[27]=p>>>24&255,r[28]=A>>>0&255,r[29]=A>>>8&255,r[30]=A>>>16&255,r[31]=A>>>24&255,r[32]=B>>>0&255,r[33]=B>>>8&255,r[34]=B>>>16&255,r[35]=B>>>24&255,r[36]=C>>>0&255,r[37]=C>>>8&255,r[38]=C>>>16&255,r[39]=C>>>24&255,r[40]=S>>>0&255,r[41]=S>>>8&255,r[42]=S>>>16&255,r[43]=S>>>24&255,r[44]=M>>>0&255,r[45]=M>>>8&255,r[46]=M>>>16&255,r[47]=M>>>24&255,r[48]=U>>>0&255,r[49]=U>>>8&255,r[50]=U>>>16&255,r[51]=U>>>24&255,r[52]=R>>>0&255,r[53]=R>>>8&255,r[54]=R>>>16&255,r[55]=R>>>24&255,r[56]=T>>>0&255,r[57]=T>>>8&255,r[58]=T>>>16&255,r[59]=T>>>24&255,r[60]=D>>>0&255,r[61]=D>>>8&255,r[62]=D>>>16&255,r[63]=D>>>24&255}function tr(r,e,t,n){for(var s=n[0]&255|(n[1]&255)<<8|(n[2]&255)<<16|(n[3]&255)<<24,o=t[0]&255|(t[1]&255)<<8|(t[2]&255)<<16|(t[3]&255)<<24,a=t[4]&255|(t[5]&255)<<8|(t[6]&255)<<16|(t[7]&255)<<24,f=t[8]&255|(t[9]&255)<<8|(t[10]&255)<<16|(t[11]&255)<<24,c=t[12]&255|(t[13]&255)<<8|(t[14]&255)<<16|(t[15]&255)<<24,l=n[4]&255|(n[5]&255)<<8|(n[6]&255)<<16|(n[7]&255)<<24,u=e[0]&255|(e[1]&255)<<8|(e[2]&255)<<16|(e[3]&255)<<24,h=e[4]&255|(e[5]&255)<<8|(e[6]&255)<<16|(e[7]&255)<<24,g=e[8]&255|(e[9]&255)<<8|(e[10]&255)<<16|(e[11]&255)<<24,x=e[12]&255|(e[13]&255)<<8|(e[14]&255)<<16|(e[15]&255)<<24,_=n[8]&255|(n[9]&255)<<8|(n[10]&255)<<16|(n[11]&255)<<24,F=t[16]&255|(t[17]&255)<<8|(t[18]&255)<<16|(t[19]&255)<<24,b=t[20]&255|(t[21]&255)<<8|(t[22]&255)<<16|(t[23]&255)<<24,d=t[24]&255|(t[25]&255)<<8|(t[26]&255)<<16|(t[27]&255)<<24,L=t[28]&255|(t[29]&255)<<8|(t[30]&255)<<16|(t[31]&255)<<24,N=n[12]&255|(n[13]&255)<<8|(n[14]&255)<<16|(n[15]&255)<<24,m=s,w=o,I=a,y=f,v=c,E=l,p=u,A=h,B=g,C=x,S=_,M=F,U=b,R=d,T=L,D=N,i,ie=0;ie<20;ie+=2)i=m+U|0,v^=i<<7|i>>>25,i=v+m|0,B^=i<<9|i>>>23,i=B+v|0,U^=i<<13|i>>>19,i=U+B|0,m^=i<<18|i>>>14,i=E+w|0,C^=i<<7|i>>>25,i=C+E|0,R^=i<<9|i>>>23,i=R+C|0,w^=i<<13|i>>>19,i=w+R|0,E^=i<<18|i>>>14,i=S+p|0,T^=i<<7|i>>>25,i=T+S|0,I^=i<<9|i>>>23,i=I+T|0,p^=i<<13|i>>>19,i=p+I|0,S^=i<<18|i>>>14,i=D+M|0,y^=i<<7|i>>>25,i=y+D|0,A^=i<<9|i>>>23,i=A+y|0,M^=i<<13|i>>>19,i=M+A|0,D^=i<<18|i>>>14,i=m+y|0,w^=i<<7|i>>>25,i=w+m|0,I^=i<<9|i>>>23,i=I+w|0,y^=i<<13|i>>>19,i=y+I|0,m^=i<<18|i>>>14,i=E+v|0,p^=i<<7|i>>>25,i=p+E|0,A^=i<<9|i>>>23,i=A+p|0,v^=i<<13|i>>>19,i=v+A|0,E^=i<<18|i>>>14,i=S+C|0,M^=i<<7|i>>>25,i=M+S|0,B^=i<<9|i>>>23,i=B+M|0,C^=i<<13|i>>>19,i=C+B|0,S^=i<<18|i>>>14,i=D+T|0,U^=i<<7|i>>>25,i=U+D|0,R^=i<<9|i>>>23,i=R+U|0,T^=i<<13|i>>>19,i=T+R|0,D^=i<<18|i>>>14;r[0]=m>>>0&255,r[1]=m>>>8&255,r[2]=m>>>16&255,r[3]=m>>>24&255,r[4]=E>>>0&255,r[5]=E>>>8&255,r[6]=E>>>16&255,r[7]=E>>>24&255,r[8]=S>>>0&255,r[9]=S>>>8&255,r[10]=S>>>16&255,r[11]=S>>>24&255,r[12]=D>>>0&255,r[13]=D>>>8&255,r[14]=D>>>16&255,r[15]=D>>>24&255,r[16]=p>>>0&255,r[17]=p>>>8&255,r[18]=p>>>16&255,r[19]=p>>>24&255,r[20]=A>>>0&255,r[21]=A>>>8&255,r[22]=A>>>16&255,r[23]=A>>>24&255,r[24]=B>>>0&255,r[25]=B>>>8&255,r[26]=B>>>16&255,r[27]=B>>>24&255,r[28]=C>>>0&255,r[29]=C>>>8&255,r[30]=C>>>16&255,r[31]=C>>>24&255}});var Kn={};P(Kn,{generateKey:()=>sr,preSharedKey:()=>Vn});var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Ae=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var j=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},oe=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var xe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},J=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},be=class extends J{constructor(e,t){super(!0,e,t)}},we=class extends J{constructor(e,t){super(!1,e,t)}};function mr(r){return typeof r?.handleEvent=="function"}function gr(r){return r===!0||r===!1}function pr(r){return gr(r)?r:r?.capture??!1}function qe(r){let e={capture:pr(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function Et(r,e){return qe(r).capture===qe(e).capture}var ye=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,n){let s=qe(n);if(s?.signal?.aborted===!0)return;let o=l=>{s.once&&this.removeEventListener(e,t,s),mr(t)?t.handleEvent(l):t(l)},a=this.#e.get(e);if(a==null&&(a=[],this.#e.set(e,a)),a.some(l=>l.callback!==t?!1:Et(l.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,t,s)};s.signal?.addEventListener("abort",c),a.push({callback:t,wrapper:o,options:s,onAbort:c})}removeEventListener(e,t,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,s.filter(o=>o.callback===t&&Et(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function G(r=0){return new Uint8Array(r)}function V(r=0){return new Uint8Array(r)}function Ar(r){return r?.buffer instanceof ArrayBuffer}function It(r){if(Ar(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Oe(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=V(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return It(t)}function vt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Lt=Symbol.for("@achingbrain/uint8arraylist");function Bt(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 Ee(r){return!!r?.[Lt]}var K=class r{bufs;length;[Lt]=!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(Ee(n)){t+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(Ee(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=Bt(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Bt(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(Ee(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 Oe(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Oe(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 a=this.bufs[o],f=s,c=f+a.byteLength;if(s=c,e>=c)continue;let l=e>=f&&e<c,u=t>f&&t<=c;if(l&&u){if(e===f&&t===c){n.push(a);break}let h=e-f;n.push(a.subarray(h,h+(t-e)));break}if(l){if(e===0){n.push(a);continue}n.push(a.subarray(e-f));continue}if(u){if(t===c){n.push(a);break}n.push(a.subarray(0,t-f));break}n.push(a)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Ee(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,a=new Int32Array(o);for(let h=0;h<o;h++)a[h]=-1;for(let h=0;h<s;h++)a[n[h]]=h;let f=a,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let h=t;h<=c;h+=u){u=0;for(let g=l;g>=0;g--){let x=this.get(h+g);if(n[g]!==x){u=Math.max(1,g-f[x]);break}}if(u===0)return h}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=V(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=G(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=G(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=G(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=V(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=G(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=G(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=G(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=G(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=G(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(!vt(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 Ve={};P(Ve,{base10:()=>Br});var as=new Uint8Array(0);function St(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 q(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return W(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return W(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Dt(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Ct=4096;function Qt(r){let e=r.length;if(e<=Ct)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Ct));return t}function xr(r){return r?.buffer instanceof ArrayBuffer}function W(r){return xr(r)?r:r.slice()}function br(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<r.length;o++){var a=r.charAt(o),f=a.charCodeAt(0);if(n[f]!==255)throw new TypeError(a+" is ambiguous");if(n[f]=o,t){var c=a.toLowerCase().charCodeAt(0),l=a.toUpperCase().charCodeAt(0);c!==f&&(n[c]=o),l!==f&&(n[l]=o)}}var u=r.length,h=r.charAt(0),g=Math.log(u)/Math.log(256),x=Math.log(256)/Math.log(u);function _(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var L=0,N=0,m=0,w=d.length;m!==w&&d[m]===0;)m++,L++;for(var I=(w-m)*x+1>>>0,y=new Uint8Array(I);m!==w;){for(var v=d[m],E=0,p=I-1;(v!==0||E<N)&&p!==-1;p--,E++)v+=256*y[p]>>>0,y[p]=v%u>>>0,v=v/u>>>0;if(v!==0)throw new Error("Non-zero carry");N=E,m++}for(var A=I-N;A!==I&&y[A]===0;)A++;for(var B=h.repeat(L);A<I;++A)B+=r.charAt(y[A]);return B}function F(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var L=0;if(d[L]!==" "){for(var N=0,m=0;d[L]===h;)N++,L++;for(var w=(d.length-L)*g+1>>>0,I=new Uint8Array(w);d[L];){var y=n[d.charCodeAt(L)];if(y===255)return;for(var v=0,E=w-1;(y!==0||v<m)&&E!==-1;E--,v++)y+=u*I[E]>>>0,I[E]=y%256>>>0,y=y/256>>>0;if(y!==0)throw new Error("Non-zero carry");m=v,L++}if(d[L]!==" "){for(var p=w-m;p!==w&&I[p]===0;)p++;for(var A=new Uint8Array(N+(w-p)),B=N;p!==w;)A[B++]=I[p++];return A}}}function b(d){var L=F(d);if(L)return L;throw new Error(`Non-${e} character`)}return{encode:_,decodeUnsafe:F,decode:b}}var wr=br,yr=wr,Mt=yr;var ze=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")}},ke=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 Ut(this,e)}},Ge=class{decoders;constructor(e){this.decoders=e}or(e){return Ut(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 Ut(r,e){return new Ge({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var je=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 ze(e,t,n),this.decoder=new ke(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Y({name:r,prefix:e,encode:t,decode:n}){return new je(r,e,t,n)}function H({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:o}=Mt(t,r,n);return Y({prefix:e,name:r,encode:s,decode:a=>q(o(a))})}function Er(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,f=0,c=0;for(let l=0;l<s;++l){let u=e[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|u,a+=t,a>=8&&(a-=8,o[c++]=255&f>>a)}if(a>=t||(255&f<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}function Ir(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",a=0,f=0;for(let c=0;c<r.length;++c)for(f=f<<8|r[c],a+=8;a>t;)a-=t,o+=e[s&f>>a];if(a!==0&&(o+=e[s&f<<t-a]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function vr(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),o=r[n].toUpperCase();s!==r[n]&&(t[s]=n),o!==r[n]&&(t[o]=n)}return t}function Q({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let o=vr(n,s);return Y({prefix:e,name:r,encode(a){return Ir(a,n,t)},decode(a){return Er(a,o,t,r)}})}var Br=H({prefix:"9",name:"base10",alphabet:"0123456789"});var Ke={};P(Ke,{base16:()=>Lr,base16upper:()=>Cr});var Lr=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Cr=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var He={};P(He,{base2:()=>Sr});var Sr=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var We={};P(We,{base256emoji:()=>Ur});var Rt=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Dr=Rt.reduce((r,e,t)=>(r[t]=e,r),[]),Qr=Rt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Nr(r){return r.reduce((e,t)=>(e+=Dr[t],e),"")}function Mr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Qr[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var Ur=Y({prefix:"\u{1F680}",name:"base256emoji",encode:Nr,decode:Mr});var $e={};P($e,{base32:()=>X,base32hex:()=>_r,base32hexpad:()=>qr,base32hexpadupper:()=>Or,base32hexupper:()=>Pr,base32pad:()=>Tr,base32padupper:()=>Fr,base32upper:()=>Rr,base32z:()=>zr});var X=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Rr=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Tr=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Fr=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),_r=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Pr=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),qr=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Or=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),zr=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Je={};P(Je,{base36:()=>ae,base36upper:()=>kr});var ae=H({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),kr=H({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ye={};P(Ye,{base58btc:()=>O,base58flickr:()=>Gr});var O=H({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Gr=H({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xe={};P(Xe,{base64:()=>jr,base64pad:()=>Vr,base64url:()=>Kr,base64urlpad:()=>Hr});var jr=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vr=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Kr=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hr=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ze={};P(Ze,{base8:()=>Wr});var Wr=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var et={};P(et,{identity:()=>$r});var $r=Y({prefix:"\0",name:"identity",encode:r=>Qt(q(r)),decode:r=>q(Dt(r))});var Is=new TextEncoder,vs=new TextDecoder;var rt={};P(rt,{identity:()=>bn});var Xr=_t,Tt=128,Zr=127,en=~Zr,tn=Math.pow(2,31);function _t(r,e,t){e=e||[],t=t||0;for(var n=t;r>=tn;)e[t++]=r&255|Tt,r/=128;for(;r&en;)e[t++]=r&255|Tt,r>>>=7;return e[t]=r|0,_t.bytes=t-n+1,e}var rn=tt,nn=128,Ft=127;function tt(r,n){var t=0,n=n||0,s=0,o=n,a,f=r.length;do{if(o>=f)throw tt.bytes=0,new RangeError("Could not decode varint");a=r[o++],t+=s<28?(a&Ft)<<s:(a&Ft)*Math.pow(2,s),s+=7}while(a>=nn);return tt.bytes=o-n,t}var sn=Math.pow(2,7),on=Math.pow(2,14),an=Math.pow(2,21),fn=Math.pow(2,28),cn=Math.pow(2,35),un=Math.pow(2,42),hn=Math.pow(2,49),ln=Math.pow(2,56),dn=Math.pow(2,63),mn=function(r){return r<sn?1:r<on?2:r<an?3:r<fn?4:r<cn?5:r<un?6:r<hn?7:r<ln?8:r<dn?9:10},gn={encode:Xr,decode:rn,encodingLength:mn},pn=gn,fe=pn;function ce(r,e=0){let t=fe.decode(r,e),n=fe.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function Z(r,e,t=0){return fe.encode(r,e,t),e}function ee(r){return fe.encodingLength(r)}function re(r,e){let t=e.byteLength,n=ee(r),s=n+ee(t),o=new Uint8Array(s+t);return Z(r,o,0),Z(t,o,n),o.set(e,s),new te(r,t,e,o)}function Pt(r){let e=q(r),[t,n]=ce(e),[s,o]=ce(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==s)throw new Error("Incorrect length");return new te(t,s,a,e)}function qt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&St(r.bytes,t.bytes)}}var te=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=W(n),this.bytes=W(s)}};var Ot=0,An="identity",zt=q;function xn(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 re(Ot,zt(r))}var bn={code:Ot,name:An,encode:zt,digest:xn};var it={};P(it,{sha256:()=>yn,sha512:()=>En});var wn=20;function st({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new nt(r,e,t,n,s)}var nt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??wn,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?kt(n,this.code,t?.truncate):n.then(s=>kt(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function kt(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 re(e,r)}function jt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var yn=st({name:"sha2-256",code:18,encode:jt("SHA-256")}),En=st({name:"sha2-512",code:19,encode:jt("SHA-512")});function Vt(r,e){let{bytes:t,version:n}=r;return n===0?vn(t,ot(r),e??O.encoder):Bn(t,ot(r),e??X.encoder)}var Kt=new WeakMap;function ot(r){let e=Kt.get(r);if(e==null){let t=new Map;return Kt.set(r,t),t}return e}var ve=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=W(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==he)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ln)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=re(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&&qt(e.multihash,n.multihash)}toString(e){return Vt(this,e)}toJSON(){return{"/":Vt(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:a}=t;return new r(n,s,o,a??Ht(n,s,o.bytes))}else if(t[Cn]===!0){let{version:n,multihash:s,code:o}=t,a=Pt(s);return r.create(n,o,a)}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!==he)throw new Error(`Version 0 CID must use dag-pb (code: ${he}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=Ht(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,he,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=q(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),a=new te(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(a):r.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,g]=ce(e.subarray(t));return t+=g,h},s=n(),o=he;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let a=t,f=n(),c=n(),l=t+c,u=l-a;return{version:s,codec:o,multihashCode:f,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,s]=In(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 ot(o).set(n,e),o}};function In(r,e){switch(r[0]){case"Q":{let t=e??O;return[O.prefix,t.decode(`${O.prefix}${r}`)]}case O.prefix:{let t=e??O;return[O.prefix,t.decode(r)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}case ae.prefix:{let t=e??ae;return[ae.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 vn(r,e,t){let{prefix:n}=t;if(n!==O.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 Bn(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 he=112,Ln=18;function Ht(r,e,t){let n=ee(r),s=n+ee(e),o=new Uint8Array(s+t.byteLength);return Z(r,o,0),Z(e,o,n),o.set(t,s),o}var Cn=Symbol.for("@ipld/js-cid/CID");var at={...et,...He,...Ze,...Ve,...Ke,...$e,...Je,...Ye,...Xe,...We},Ks={...it,...rt};function $t(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Wt=$t("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ft=$t("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=V(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Sn={utf8:Wt,"utf-8":Wt,hex:at.base16,latin1:ft,ascii:ft,binary:ft,...at},Be=Sn;function Le(r,e="utf8"){let t=Be[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var ei=Math.pow(2,7),ti=Math.pow(2,14),ri=Math.pow(2,21),ni=Math.pow(2,28),si=Math.pow(2,35),ii=Math.pow(2,42),oi=Math.pow(2,49);function Ce(r,e="utf8"){let t=Be[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function Se(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var De=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}},ne=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new De(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 De(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 ct=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Qe(r={}){return Qn(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 Qn(r,e){e=e??{};let t=e.onEnd,n=new ne,s,o,a,f=Se(),c=async()=>{try{return n.isEmpty()?a?{done:!0}:await new Promise((b,d)=>{o=L=>{o=null,n.push(L);try{b(r(n))}catch(N){d(N)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{f.resolve(),f=Se()})}},l=b=>o!=null?o(b):(n.push(b),s),u=b=>(n=new ne,o!=null?o({error:b}):(n.push({error:b}),s)),h=b=>{if(a)return s;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:b})},g=b=>a?s:(a=!0,b!=null?u(b):l({done:!0})),x=()=>(n=new ne,g(),{done:!0}),_=b=>(g(b),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:x,throw:_,push:h,end:g,get readableLength(){return n.size},onEmpty:async b=>{let d=b?.signal;if(d?.throwIfAborted(),n.isEmpty())return;let L,N;d!=null&&(L=new Promise((m,w)=>{N=()=>{w(new ct)},d.addEventListener("abort",N)}));try{await Promise.race([f.promise,L])}finally{N!=null&&d!=null&&d?.removeEventListener("abort",N)}}},t==null)return s;let F=s;return s={[Symbol.asyncIterator](){return this},next(){return F.next()},throw(b){return F.throw(b),t!=null&&(t(b),t=void 0),{done:!0}},return(){return F.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(b){return F.end(b),t!=null&&(t(b),t=void 0),s},get readableLength(){return F.readableLength},onEmpty:b=>F.onEmpty(b)},s}var ut=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Jt=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function ht(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:a}=e,f,c,u=new Promise((h,g)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(a?.aborted){g(Jt(a));return}if(a&&(c=()=>{g(Jt(a))},a.addEventListener("abort",c,{once:!0})),r.then(h,g),t===Number.POSITIVE_INFINITY)return;let x=new ut;f=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(_){g(_)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?h():s instanceof Error?g(s):(x.message=s??`Promise timed out after ${t} milliseconds`,g(x))},t)}).finally(()=>{u.clear(),c&&a&&a.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,f),f=void 0},u}var Nn=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 Mn(r,e,t){let n,s=new Promise((o,a)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let f=[e].flat(),c=[],{addListener:l,removeListener:u}=Nn(r),h=async(...x)=>{let _=t.multiArgs?x:x[0];if(t.filter)try{if(!await t.filter(_))return}catch(F){n(),a(F);return}c.push(_),t.count===c.length&&(n(),o(c))},g=(...x)=>{n(),a(t.rejectionMultiArgs?x:x[0])};n=()=>{for(let x of f)u(x,h);for(let x of t.rejectionEvents)f.includes(x)||u(x,g)};for(let x of f)l(x,h);for(let x of t.rejectionEvents)f.includes(x)||l(x,g);t.signal&&t.signal.addEventListener("abort",()=>{g(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=ht(s,{milliseconds:t.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function le(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Mn(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var de=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var Ne=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Un(r){return r.reason}function me(r,e,t){if(e==null||r==null)return r;let n=t?.translateError??Un;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([r,new Promise((o,a)=>{s=()=>{a(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var Rn=Math.pow(2,20)*4,Me=class extends ye{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Rn,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new K,this.writeBuffer=new K,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,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=s=>{this.onDrainPromise?.reject(s.error??new Ne)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),me(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Qe(),t=o=>{e.push(o.data)};this.addEventListener("message",t);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new j(`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(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(t){this.log.error("failed to send reset to remote - %e",t)}this.dispatchEvent(new be(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new j("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 j("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 j(`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)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new j(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(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",this.maybeDispatchEnd()),this.dispatchEvent(new we(new Ae))}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.maybeDispatchEnd(),this.dispatchEvent(new J))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),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;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),a=new K(o);this.writeBuffer.consume(o.byteLength);let f;try{f=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(a),this.abort(c),c}if(e=f.canSendMore,n+=f.sentBytes,f.sentBytes!==a.byteLength&&(a.consume(f.sentBytes),this.writeBuffer.prepend(a)),!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",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.#e||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(this.#e=!0,this.safeDispatchEvent("end"))}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 xe(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.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new oe(`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 oe(`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")}};var Ue=class extends Me{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="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 le(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await le(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var Tn=4194304,Re=class extends Error{static name="UnwrappedError";name="UnwrappedError"};function Fn(r){return typeof r?.closeRead=="function"}function _n(r){return typeof r?.close=="function"}function lt(r){return Fn(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:_n(r)?r.status!=="open":!1}function Pn(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Yt(r,e){let t=e?.maxBufferSize??Tn,n=new K,s,o=!1;if(!Pn(r))throw new $("Argument should be a Stream or a Multiaddr");let a=u=>{if(n.append(u.data),n.byteLength>t){let h=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${h} > ${t}`))}s?.resolve()};r.addEventListener("message",a);let f=u=>{u.error!=null?s?.reject(u.error):s?.resolve()};r.addEventListener("close",f);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(u){if(o===!0)throw new Re("Stream was unwrapped");if(lt(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new de(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let h=u?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await me(s.promise,u?.signal),lt(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}s=Promise.withResolvers()}let g=u?.bytes??n.byteLength;if(n.byteLength<g){if(lt(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,g),new de(`Unexpected EOF - stream closed while reading ${n.byteLength}/${g} bytes`);return l.read(u)}let x=n.sublist(0,g);return n.consume(g),x},async write(u,h){if(o===!0)throw new Re("Stream was unwrapped");r.send(u)||await le(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,r.removeEventListener("message",a),r.removeEventListener("close",f),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return l}var xt=lr(nr(),1);var mt="Your private shared key is invalid";function sr(r){let e=Ce(crypto.getRandomValues(new Uint8Array(pt)),"base16"),t=Le(`/key/swarm/psk/1.0.0/
3
3
  /base16/
4
- `+e);r instanceof Uint8Array?r.set(t):r.write(t)}var pt=24,gt=32;var Pe=class extends Ue{maConn;inboundXor;outboundXor;constructor(e){super({...e,remoteAddr:e.maConn.remoteAddr,direction:e.maConn.direction}),this.inboundXor=(0,At.default)(e.remoteNonce,e.psk),this.outboundXor=(0,At.default)(e.localNonce,e.psk),this.maConn=e.maConn,this.maConn.addEventListener("message",t=>{let n=t.data;if(n instanceof Uint8Array)this.onData(this.inboundXor.update(n));else for(let s of n)this.onData(this.inboundXor.update(s))}),this.maConn.addEventListener("drain",()=>{this.onMuxerDrain()}),this.maConn.addEventListener("close",t=>{t.error!=null?t.local?this.abort(t.error):this.onRemoteReset():this.onTransportClosed()})}async sendClose(e){await this.maConn.close(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.maConn.send(this.outboundXor.update(e.subarray()))}}sendReset(e){this.maConn.abort(e)}sendPause(){this.maConn.pause()}sendResume(){this.maConn.resume()}};function sr(r){try{let e=Se(r).split(/(?:\r\n|\r|\n)/g),t=e.shift(),n=e.shift(),s=e.shift(),o=Le(s??"","base16");if(o.byteLength!==gt)throw new Error(mt);return{tag:t,codecName:n,psk:o}}catch{throw new Error(mt)}}var xt=class{tag;psk;timeout;constructor(e){this.timeout=e.timeout??1e3;let t=sr(e.psk);this.psk=t.psk,this.tag=t.tag??""}[Symbol.toStringTag]="@libp2p/pnet";async protect(e,t){if(e==null)throw new $("No connection for the handshake provided");let n=e.log.newScope("pnet");n("protecting the connection");let s=crypto.getRandomValues(new Uint8Array(pt));t==null&&(t={signal:AbortSignal.timeout(this.timeout)});let o=Jt(e),[a]=await Promise.all([o.read({bytes:pt,...t}),o.write(s,t)]),f=a.subarray();return n("exchanged nonces"),new Pe({localNonce:s,remoteNonce:f,psk:this.psk,maConn:o.unwrap(),log:n})}};function kn(r){return()=>new xt(r)}return hr(jn);})();
4
+ `+e);r instanceof Uint8Array?r.set(t):r.write(t)}var gt=24,pt=32;var ir=65536;function At(r,e){let t=new Uint8Array(e.byteLength);for(let n=0;n<e.byteLength;n+=ir){let s=Math.min(n+ir,e.byteLength);r.update(e.subarray(n,s),t.subarray(n,s))}return t}var Pe=class extends Ue{maConn;inboundXor;outboundXor;inboundReleased;outboundReleased;onInboundMessage;constructor(e){super({...e,remoteAddr:e.maConn.remoteAddr,direction:e.maConn.direction}),this.inboundXor=(0,xt.default)(e.remoteNonce,e.psk),this.outboundXor=(0,xt.default)(e.localNonce,e.psk),this.inboundReleased=!1,this.outboundReleased=!1,this.maConn=e.maConn,this.onInboundMessage=t=>{let n=t.data;if(this.inboundReleased){this.log("discarding %d bytes received after the readable end ended",n.byteLength);return}try{if(n instanceof Uint8Array)this.onData(At(this.inboundXor,n));else for(let s of n){if(this.inboundReleased)break;this.onData(At(this.inboundXor,s))}}catch(s){this.log.error("error decrypting inbound data - %e",s),this.abort(s)}},this.maConn.addEventListener("message",this.onInboundMessage),this.maConn.addEventListener("drain",()=>{this.onMuxerDrain()}),this.maConn.addEventListener("end",()=>{this.releaseInbound()}),this.maConn.addEventListener("close",t=>{t.error!=null?(t.local?this.abort(t.error):this.onRemoteReset(),this.releaseInbound()):(this.writeStatus="closed",this.drainMaConn(),this.onTransportClosed()),this.releaseOutbound()}),(this.maConn.readableEnded||this.maConn.status!=="open")&&queueMicrotask(()=>{this.maConn.readableEnded&&this.releaseInbound(),this.maConn.status!=="open"&&this.maConn.status!=="closing"&&(this.onTransportClosed(),this.releaseOutbound())})}drainMaConn(){if(!this.maConn.readableEnded)try{this.maConn.resume()}catch(e){this.log.error("could not drain the connection before closing - %e",e)}}releaseInbound(){if(!this.inboundReleased){this.inboundReleased=!0;try{this.inboundXor.finalize()}catch(e){this.log.error("could not release the inbound cipher, its wasm slot and key leak - %e",e)}}}releaseOutbound(){if(!this.outboundReleased){this.outboundReleased=!0;try{this.outboundXor.finalize()}catch(e){this.log.error("could not release the outbound cipher, its wasm slot and key leak - %e",e)}}}async sendClose(e){await this.maConn.close(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.maConn.send(At(this.outboundXor,e.subarray()))}}sendReset(e){this.maConn.abort(e)}sendPause(){this.maConn.pause()}sendResume(){this.maConn.readableEnded||this.maConn.resume()}};function or(r){try{let e=Ce(r).split(/(?:\r\n|\r|\n)/g),t=e.shift(),n=e.shift(),s=e.shift(),o=Le(s??"","base16");if(o.byteLength!==pt)throw new Error(mt);return{tag:t,codecName:n,psk:o}}catch{throw new Error(mt)}}var bt=class{tag;psk;timeout;constructor(e){this.timeout=e.timeout??1e3;let t=or(e.psk);this.psk=t.psk,this.tag=t.tag??""}[Symbol.toStringTag]="@libp2p/pnet";async protect(e,t){if(e==null)throw new $("No connection for the handshake provided");let n=e.log.newScope("pnet");n("protecting the connection");let s=crypto.getRandomValues(new Uint8Array(gt));t==null&&(t={signal:AbortSignal.timeout(this.timeout)});let o=Yt(e),[a]=await Promise.all([o.read({bytes:gt,...t}),o.write(s,t)]),f=a.subarray();return n("exchanged nonces"),new Pe({localNonce:s,remoteNonce:f,psk:this.psk,maConn:o.unwrap(),log:n})}};function Vn(r){return()=>new bt(r)}return dr(Kn);})();
5
5
  return Libp2PPnet}));
6
6
  //# sourceMappingURL=index.min.js.map