@libp2p/fetch 4.1.12-ac7305ccf → 4.1.12-cef4d32cf

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,4 +1,4 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFetch = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PFetch=(()=>{var Nt=Object.defineProperty;var dr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var mr=Object.prototype.hasOwnProperty;var E=(r,t)=>{for(var e in t)Nt(r,e,{get:t[e],enumerable:!0})},gr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of pr(t))!mr.call(r,i)&&i!==e&&Nt(r,i,{get:()=>t[i],enumerable:!(n=dr(t,i))||n.enumerable});return r};var br=r=>gr(Nt({},"__esModule",{value:!0}),r);var ri={};E(ri,{fetch:()=>ei});var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var lt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}},ft=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};function S(r=0){return new Uint8Array(r)}function y(r=0){return new Uint8Array(r)}function wr(r){return r?.buffer instanceof ArrayBuffer}function ve(r){if(wr(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ct(r,t){t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=y(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return ve(e)}function Se(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Ae=Symbol.for("@achingbrain/uint8arraylist");function Ie(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function dt(r){return!!r?.[Ae]}var V=class r{bufs;length;[Ae]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(dt(n)){e+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(dt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ie(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ie(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(dt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:i}=this._subList(t,e);return Ct(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:Ct(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),s=new r;return s.length=i,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=i,c=a+o.byteLength;if(i=c,t>=c)continue;let h=t>=a&&t<c,u=e>a&&e<=c;if(h&&u){if(t===a&&e===c){n.push(o);break}let l=t-a;n.push(o.subarray(l,l+(e-t)));break}if(h){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(u){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!dt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let l=0;l<s;l++)o[l]=-1;for(let l=0;l<i;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,h=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let f=h;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){u=Math.max(1,f-a[p]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let i=S(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let i=S(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let i=S(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let i=S(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let i=S(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let i=S(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let i=S(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let i=S(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Se(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,s)=>i+s.byteLength,0)),n.length=e,n}};var Ft={};E(Ft,{base10:()=>Ar});var mi=new Uint8Array(0);function Ce(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function I(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return z(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return z(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function De(r){let t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}var Ne=4096;function Ue(r){let t=r.length;if(t<=Ne)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.subarray(n,n+=Ne));return e}function xr(r){return r?.buffer instanceof ArrayBuffer}function z(r){return xr(r)?r:r.slice()}function yr(r,t,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=s,e){var c=o.toLowerCase().charCodeAt(0),h=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),h!==a&&(n[h]=s)}}var u=r.length,l=r.charAt(0),f=Math.log(u)/Math.log(256),p=Math.log(256)/Math.log(u);function q(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,_=0,N=0,U=m.length;N!==U&&m[N]===0;)N++,x++;for(var T=(U-N)*p+1>>>0,v=new Uint8Array(T);N!==U;){for(var O=m[N],R=0,C=T-1;(O!==0||R<_)&&C!==-1;C--,R++)O+=256*v[C]>>>0,v[C]=O%u>>>0,O=O/u>>>0;if(O!==0)throw new Error("Non-zero carry");_=R,N++}for(var M=T-_;M!==T&&v[M]===0;)M++;for(var ht=l.repeat(x);M<T;++M)ht+=r.charAt(v[M]);return ht}function ut(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var _=0,N=0;m[x]===l;)_++,x++;for(var U=(m.length-x)*f+1>>>0,T=new Uint8Array(U);m[x];){var v=n[m.charCodeAt(x)];if(v===255)return;for(var O=0,R=U-1;(v!==0||O<N)&&R!==-1;R--,O++)v+=u*T[R]>>>0,T[R]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");N=O,x++}if(m[x]!==" "){for(var C=U-N;C!==U&&T[C]===0;)C++;for(var M=new Uint8Array(_+(U-C)),ht=_;C!==U;)M[ht++]=T[C++];return M}}}function fr(m){var x=ut(m);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:q,decodeUnsafe:ut,decode:fr}}var Er=yr,Lr=Er,Oe=Lr;var Dt=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ut=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let i=e.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Fe(this,t)}},Tt=class{decoders;constructor(t){this.decoders=t}or(t){return Fe(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Fe(r,t){return new Tt({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ot=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Dt(t,e,n),this.decoder=new Ut(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function K({name:r,prefix:t,encode:e,decode:n}){return new Ot(r,t,e,n)}function k({name:r,prefix:t,alphabet:e,caseInsensitive:n=!1}){let{encode:i,decode:s}=Oe(e,r,n);return K({prefix:t,name:r,encode:i,decode:o=>I(s(o))})}function vr(r,t,e,n){let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),o=0,a=0,c=0;for(let h=0;h<i;++h){let u=t[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,o+=e,o>=8&&(o-=8,s[c++]=255&a>>o)}if(o>=e||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function Sr(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,s="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,s+=t[i&a>>o];if(o!==0&&(s+=t[i&a<<e-o]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ir(r,t){let e={};for(let n=0;n<r.length;++n)if(e[r[n]]=n,t){let i=r[n].toLowerCase(),s=r[n].toUpperCase();i!==r[n]&&(e[i]=n),s!==r[n]&&(e[s]=n)}return e}function g({name:r,prefix:t,bitsPerChar:e,alphabet:n,caseInsensitive:i=!1}){let s=Ir(n,i);return K({prefix:t,name:r,encode(o){return Sr(o,n,e)},decode(o){return vr(o,s,e,r)}})}var Ar=k({prefix:"9",name:"base10",alphabet:"0123456789"});var Mt={};E(Mt,{base16:()=>Nr,base16upper:()=>Cr});var Nr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Cr=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Bt={};E(Bt,{base2:()=>Dr});var Dr=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Rt={};E(Rt,{base256emoji:()=>Mr});var Me=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}"),Ur=Me.reduce((r,t,e)=>(r[e]=t,r),[]),Tr=Me.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Or(r){return r.reduce((t,e)=>(t+=Ur[e],t),"")}function Fr(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let i=Tr[n];if(i==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(i)}return new Uint8Array(t)}var Mr=K({prefix:"\u{1F680}",name:"base256emoji",encode:Or,decode:Fr});var kt={};E(kt,{base32:()=>H,base32hex:()=>Pr,base32hexpad:()=>Vr,base32hexpadupper:()=>zr,base32hexupper:()=>_r,base32pad:()=>Rr,base32padupper:()=>kr,base32upper:()=>Br,base32z:()=>$r});var H=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Br=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Rr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),kr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Pr=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),_r=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Vr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),zr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),$r=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pt={};E(Pt,{base36:()=>tt,base36upper:()=>Gr});var tt=k({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Gr=k({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var _t={};E(_t,{base58btc:()=>F,base58flickr:()=>jr});var F=k({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jr=k({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vt={};E(Vt,{base64:()=>qr,base64pad:()=>Wr,base64url:()=>Kr,base64urlpad:()=>Hr});var qr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Kr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zt={};E(zt,{base8:()=>Xr});var Xr=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};E($t,{identity:()=>Jr});var Jr=K({prefix:"\0",name:"identity",encode:r=>Ue(I(r)),decode:r=>I(De(r))});var Ti=new TextEncoder,Oi=new TextDecoder;var jt={};E(jt,{identity:()=>yn});var Zr=ke,Be=128,tn=127,en=~tn,rn=Math.pow(2,31);function ke(r,t,e){t=t||[],e=e||0;for(var n=e;r>=rn;)t[e++]=r&255|Be,r/=128;for(;r&en;)t[e++]=r&255|Be,r>>>=7;return t[e]=r|0,ke.bytes=e-n+1,t}var nn=Gt,sn=128,Re=127;function Gt(r,n){var e=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw Gt.bytes=0,new RangeError("Could not decode varint");o=r[s++],e+=i<28?(o&Re)<<i:(o&Re)*Math.pow(2,i),i+=7}while(o>=sn);return Gt.bytes=s-n,e}var on=Math.pow(2,7),an=Math.pow(2,14),cn=Math.pow(2,21),un=Math.pow(2,28),hn=Math.pow(2,35),ln=Math.pow(2,42),fn=Math.pow(2,49),dn=Math.pow(2,56),pn=Math.pow(2,63),mn=function(r){return r<on?1:r<an?2:r<cn?3:r<un?4:r<hn?5:r<ln?6:r<fn?7:r<dn?8:r<pn?9:10},gn={encode:Zr,decode:nn,encodingLength:mn},bn=gn,et=bn;function rt(r,t=0){let e=et.decode(r,t),n=et.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[e,n]}function X(r,t,e=0){return et.encode(r,t,e),t}function J(r){return et.encodingLength(r)}function Q(r,t){let e=t.byteLength,n=J(r),i=n+J(e),s=new Uint8Array(i+e);return X(r,s,0),X(e,s,n),s.set(t,i),new Y(r,e,t,s)}function Pe(r){let t=I(r),[e,n]=rt(t),[i,s]=rt(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Y(e,i,o,t)}function _e(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ce(r.bytes,e.bytes)}}var Y=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=z(n),this.bytes=z(i)}};var Ve=0,wn="identity",ze=I;function xn(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Q(Ve,ze(r))}var yn={code:Ve,name:wn,encode:ze,digest:xn};var Kt={};E(Kt,{sha256:()=>Ln,sha512:()=>vn});var En=20;function Wt({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:i}){return new qt(r,t,e,n,i)}var qt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,i,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=i??En,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?$e(n,this.code,e?.truncate):n.then(i=>$e(i,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function $e(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Q(t,r)}function je(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ln=Wt({name:"sha2-256",code:18,encode:je("SHA-256")}),vn=Wt({name:"sha2-512",code:19,encode:je("SHA-512")});function qe(r,t){let{bytes:e,version:n}=r;return n===0?In(e,Ht(r),t??F.encoder):An(e,Ht(r),t??H.encoder)}var We=new WeakMap;function Ht(r){let t=We.get(r);if(t==null){let e=new Map;return We.set(r,e),e}return t}var mt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=z(i),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:t,multihash:e}=this;if(t!==it)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Nn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Q(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&_e(t.multihash,n.multihash)}toString(t){return qe(this,t)}toJSON(){return{"/":qe(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:s,bytes:o}=e;return new r(n,i,s,o??Ke(n,i,s.bytes))}else if(e[Cn]===!0){let{version:n,multihash:i,code:s}=e,o=Pe(i);return r.create(n,s,o)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==it)throw new Error(`Version 0 CID must use dag-pb (code: ${it}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=Ke(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,it,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=I(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=i.subarray(e.multihashSize-e.digestSize),o=new Y(e.multihashCode,e.digestSize,s,i);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,f]=rt(t.subarray(e));return e+=f,l},i=n(),s=it;if(i===18?(i=0,e=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=e,a=n(),c=n(),h=e+c,u=h-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(t,e){let[n,i]=Sn(t,e),s=r.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ht(s).set(n,t),s}};function Sn(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case H.prefix:{let e=t??H;return[H.prefix,e.decode(r)]}case tt.prefix:{let e=t??tt;return[tt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function In(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return i}function An(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let s=e.encode(r);return t.set(n,s),s}else return i}var it=112,Nn=18;function Ke(r,t,e){let n=J(r),i=n+J(t),s=new Uint8Array(i+e.byteLength);return X(r,s,0),X(t,s,n),s.set(e,i),s}var Cn=Symbol.for("@ipld/js-cid/CID");var Xt={...$t,...Bt,...zt,...Ft,...Mt,...kt,...Pt,..._t,...Vt,...Rt},ts={...Kt,...jt};function Xe(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var He=Xe("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Jt=Xe("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=y(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Dn={utf8:He,"utf-8":He,hex:Xt.base16,latin1:Jt,ascii:Jt,binary:Jt,...Xt},gt=Dn;function Z(r,t="utf8"){let e=gt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var Un=Math.pow(2,7),Tn=Math.pow(2,14),On=Math.pow(2,21),Yt=Math.pow(2,28),Qt=Math.pow(2,35),Zt=Math.pow(2,42),te=Math.pow(2,49),d=128,b=127;function B(r){if(r<Un)return 1;if(r<Tn)return 2;if(r<On)return 3;if(r<Yt)return 4;if(r<Qt)return 5;if(r<Zt)return 6;if(r<te)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ee(r,t,e=0){switch(B(r)){case 8:t[e++]=r&255|d,r/=128;case 7:t[e++]=r&255|d,r/=128;case 6:t[e++]=r&255|d,r/=128;case 5:t[e++]=r&255|d,r/=128;case 4:t[e++]=r&255|d,r>>>=7;case 3:t[e++]=r&255|d,r>>>=7;case 2:t[e++]=r&255|d,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Fn(r,t,e=0){switch(B(r)){case 8:t.set(e++,r&255|d),r/=128;case 7:t.set(e++,r&255|d),r/=128;case 6:t.set(e++,r&255|d),r/=128;case 5:t.set(e++,r&255|d),r/=128;case 4:t.set(e++,r&255|d),r>>>=7;case 3:t.set(e++,r&255|d),r>>>=7;case 2:t.set(e++,r&255|d),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function re(r,t){let e=r[t],n=0;if(n+=e&b,e<d||(e=r[t+1],n+=(e&b)<<7,e<d)||(e=r[t+2],n+=(e&b)<<14,e<d)||(e=r[t+3],n+=(e&b)<<21,e<d)||(e=r[t+4],n+=(e&b)*Yt,e<d)||(e=r[t+5],n+=(e&b)*Qt,e<d)||(e=r[t+6],n+=(e&b)*Zt,e<d)||(e=r[t+7],n+=(e&b)*te,e<d))return n;throw new RangeError("Could not decode varint")}function Mn(r,t){let e=r.get(t),n=0;if(n+=e&b,e<d||(e=r.get(t+1),n+=(e&b)<<7,e<d)||(e=r.get(t+2),n+=(e&b)<<14,e<d)||(e=r.get(t+3),n+=(e&b)<<21,e<d)||(e=r.get(t+4),n+=(e&b)*Yt,e<d)||(e=r.get(t+5),n+=(e&b)*Qt,e<d)||(e=r.get(t+6),n+=(e&b)*Zt,e<d)||(e=r.get(t+7),n+=(e&b)*te,e<d))return n;throw new RangeError("Could not decode varint")}function Je(r,t,e=0){return t==null&&(t=y(B(r))),t instanceof Uint8Array?ee(r,t,e):Fn(r,t,e)}function Ye(r,t=0){return r instanceof Uint8Array?re(r,t):Mn(r,t)}function Rn(r){return r.buffer instanceof ArrayBuffer}function Qe(r){return Rn(r)?r:r.slice()}function ne(r,t="utf8"){let e=gt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var ie=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Ze=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function se(r,t){let{milliseconds:e,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout},signal:o}=t,a,c,u=new Promise((l,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(o?.aborted){f(Ze(o));return}if(o&&(c=()=>{f(Ze(o))},o.addEventListener("abort",c,{once:!0})),r.then(l,f),e===Number.POSITIVE_INFINITY)return;let p=new ie;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(q){f(q)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?l():i instanceof Error?f(i):(p.message=i??`Promise timed out after ${e} milliseconds`,f(p))},e)}).finally(()=>{u.clear(),c&&o&&o.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var kn=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function Pn(r,t,e){let n,i=new Promise((s,o)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:h,removeListener:u}=kn(r),l=async(...p)=>{let q=e.multiArgs?p:p[0];if(e.filter)try{if(!await e.filter(q))return}catch(ut){n(),o(ut);return}c.push(q),e.count===c.length&&(n(),s(c))},f=(...p)=>{n(),o(e.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)u(p,l);for(let p of e.rejectionEvents)a.includes(p)||u(p,f)};for(let p of a)h(p,l);for(let p of e.rejectionEvents)a.includes(p)||h(p,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(i.cancel=n,typeof e.timeout=="number"){let s=se(i,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return i}function tr(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=Pn(r,t,e),i=n.then(s=>s[0]);return i.cancel=n.cancel,i}var $=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function _n(r){return r.reason}function oe(r,t,e){if(t==null||r==null)return r;let n=e?.translateError??_n;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let i;return Promise.race([r,new Promise((s,o)=>{i=()=>{o(n(t))},t.addEventListener("abort",i)})]).finally(()=>{i!=null&&t.removeEventListener("abort",i)})}var zn=4194304,bt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ce=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ue=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},he=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $n(r){return typeof r?.closeRead=="function"}function Gn(r){return typeof r?.close=="function"}function ae(r){return $n(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Gn(r)?r.status!=="open":!1}function jn(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function qn(r,t){let e=t?.maxBufferSize??zn,n=new V,i,s=!1;if(!jn(r))throw new W("Argument should be a Stream or a Multiaddr");let o=u=>{if(n.append(u.data),n.byteLength>e){let l=n.byteLength;n.consume(n.byteLength),i?.reject(new Error(`Read buffer overflow - ${l} > ${e}`))}i?.resolve()};r.addEventListener("message",o);let a=u=>{u.error!=null?i?.reject(u.error):i?.resolve()};r.addEventListener("close",a);let c=()=>{i?.resolve()};r.addEventListener("remoteCloseWrite",c);let h={readBuffer:n,async read(u){if(s===!0)throw new bt("Stream was unwrapped");if(ae(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 $(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(i=Promise.withResolvers();;){if(n.byteLength>=l){i.resolve();break}if(await oe(i.promise,u?.signal),ae(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}i=Promise.withResolvers()}let f=u?.bytes??n.byteLength;if(n.byteLength<f){if(ae(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,f),new $(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return h.read(u)}let p=n.sublist(0,f);return n.consume(f),p},async write(u,l){if(s===!0)throw new bt("Stream was unwrapped");r.send(u)||await tr(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",o),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return h}function Wn(r,t={}){let e=qn(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=B(t.maxDataLength));let n=t?.lengthDecoder??Ye,i=t?.lengthEncoder??Je;return{async read(o){let a=-1,c=new V;for(;;){let u=await e.read({...o,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new ce("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new he(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ue(`Message length too long - ${a} > ${t.maxDataLength}`);let h=await e.read({...o,bytes:a});if(h==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new $(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(h.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new $(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(o,a){await e.write(new V(i(o.byteLength),o),a)},async writeV(o,a){let c=new V(...o.flatMap(h=>[i(h.byteLength),h]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function le(r,t){let e=Wn(r,t),n={read:async(i,s)=>{let o=await e.read(s);return i.decode(o,s)},write:async(i,s,o)=>{await e.write(s.encode(i),o)},writeV:async(i,s,o)=>{await e.writeV(i.map(a=>s.encode(a)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var er="0.0.1",rr="fetch";var fe=new Float32Array([-0]),P=new Uint8Array(fe.buffer);function nr(r,t,e){fe[0]=r,t[e]=P[0],t[e+1]=P[1],t[e+2]=P[2],t[e+3]=P[3]}function ir(r,t){return P[0]=r[t],P[1]=r[t+1],P[2]=r[t+2],P[3]=r[t+3],fe[0]}var de=new Float64Array([-0]),w=new Uint8Array(de.buffer);function sr(r,t,e){de[0]=r,t[e]=w[0],t[e+1]=w[1],t[e+2]=w[2],t[e+3]=w[3],t[e+4]=w[4],t[e+5]=w[5],t[e+6]=w[6],t[e+7]=w[7]}function or(r,t){return w[0]=r[t],w[1]=r[t+1],w[2]=r[t+2],w[3]=r[t+3],w[4]=r[t+4],w[5]=r[t+5],w[6]=r[t+6],w[7]=r[t+7],de[0]}var Kn=BigInt(Number.MAX_SAFE_INTEGER),Hn=BigInt(Number.MIN_SAFE_INTEGER),L=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return G;if(t<Kn&&t>Hn)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>ar&&(i=0n,++n>ar&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return G;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):G}},G=new L(0,0);G.toBigInt=function(){return 0n};G.zzEncode=G.zzDecode=function(){return this};G.length=function(){return 1};var ar=4294967296n;function cr(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ur(r,t,e){if(e-t<1)return"";let i,s=[],o=0,a;for(;t<e;)a=r[t++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function pe(r,t,e){let n=e,i,s;for(let o=0;o<r.length;++o)i=r.charCodeAt(o),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((s=r.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function D(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function wt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var me=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Qe(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,D(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw D(this,4);return wt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw D(this,4);return wt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw D(this,4);let t=ir(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw D(this,4);let t=or(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw D(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ur(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw D(this,t);this.pos+=t}else do if(this.pos>=this.len)throw D(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new L(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw D(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw D(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw D(this,8);let t=wt(this.buf,this.pos+=4),e=wt(this.buf,this.pos+=4);return new L(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=re(this.buf,this.pos);return this.pos+=B(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function st(r){return new me(r instanceof Uint8Array?r:r.subarray())}function xt(r,t,e){let n=st(r);return t.decode(n,void 0,e)}function ge(r){let t=r??8192,e=t>>>1,n,i=t;return function(o){if(o<1||o>e)return y(o);i+o>t&&(n=y(t),i=0);let a=n.subarray(i,i+=o);return(i&7)!==0&&(i=(i|7)+1),a}}var j=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function be(){}var xe=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xn=ge();function Jn(r){return globalThis.Buffer!=null?y(r):Xn(r)}var at=class{len;head;tail;states;constructor(){this.len=0,this.head=new j(be,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new j(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ye((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(yt,10,L.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=L.fromBigInt(t);return this._push(yt,e.length(),e)}uint64Number(t){return this._push(ee,B(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=L.fromBigInt(t).zzEncode();return this._push(yt,e.length(),e)}sint64Number(t){let e=L.fromNumber(t).zzEncode();return this._push(yt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(we,1,t?1:0)}fixed32(t){return this._push(ot,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=L.fromBigInt(t);return this._push(ot,4,e.lo)._push(ot,4,e.hi)}fixed64Number(t){let e=L.fromNumber(t);return this._push(ot,4,e.lo)._push(ot,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(nr,4,t)}double(t){return this._push(sr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(we,1,0):this.uint32(e)._push(Qn,e,t)}string(t){let e=cr(t);return e!==0?this.uint32(e)._push(pe,e,t):this._push(we,1,0)}fork(){return this.states=new xe(this),this.head=this.tail=new j(be,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new j(be,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Jn(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function we(r,t,e){t[e]=r&255}function Yn(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ye=class extends j{next;constructor(t,e){super(Yn,t,e),this.next=void 0}};function yt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function ot(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Qn(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(at.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Zn,t,r),this},at.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ti,t,r),this});function Zn(r,t,e){t.set(r,e)}function ti(r,t,e){r.length<40?pe(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function Ee(){return new at}function Et(r,t){let e=Ee();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Lt(r,t,e){let n=st(r);yield*t.stream(n,void 0,"$",e)}var vt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function St(r,t,e,n,i){return{name:r,type:t,encode:e,decode:n,stream:i}}function Le(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},i=function*(o){let a=o.int32();yield t(a)};return St("enum",vt.VARINT,e,n,i)}function It(r,t,e){return St("message",vt.LENGTH_DELIMITED,r,t,e)}var ct;(function(r){let t;r.codec=()=>(t==null&&(t=It((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.identifier!=null&&s.identifier.byteLength>0&&(o.uint32(10),o.bytes(s.identifier)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={identifier:S(0)},h=o==null?s.len:s.pos+o;for(;s.pos<h;){let u=s.uint32();u>>>3===1?c.identifier=s.bytes():s.skipType(u&7)}return c},function*(s,o,a,c={}){let h=o==null?s.len:s.pos+o;for(;s.pos<h;){let u=s.uint32();u>>>3===1?yield{field:`${a}.identifier`,value:s.bytes()}:s.skipType(u&7)}})),t);function e(s){return Et(s,r.codec())}r.encode=e;function n(s,o){return xt(s,r.codec(),o)}r.decode=n;function i(s,o){return Lt(s,r.codec(),o)}r.stream=i})(ct||(ct={}));var A;(function(r){let t;(function(a){a.OK="OK",a.NOT_FOUND="NOT_FOUND",a.ERROR="ERROR"})(t=r.StatusCode||(r.StatusCode={}));let e;(function(a){a[a.OK=0]="OK",a[a.NOT_FOUND=1]="NOT_FOUND",a[a.ERROR=2]="ERROR"})(e||(e={})),(function(a){a.codec=()=>Le(e)})(t=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=It((a,c,h={})=>{h.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.StatusCode.codec().encode(a.status,c)),a.data!=null&&a.data.byteLength>0&&(c.uint32(18),c.bytes(a.data)),h.lengthDelimited!==!1&&c.ldelim()},(a,c,h={})=>{let u={status:t.OK,data:S(0)},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let f=a.uint32();switch(f>>>3){case 1:{u.status=r.StatusCode.codec().decode(a);break}case 2:{u.data=a.bytes();break}default:{a.skipType(f&7);break}}}return u},function*(a,c,h,u={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let f=a.uint32();switch(f>>>3){case 1:{yield{field:`${h}.status`,value:r.StatusCode.codec().decode(a)};break}case 2:{yield{field:`${h}.data`,value:a.bytes()};break}default:{a.skipType(f&7);break}}}})),n);function i(a){return Et(a,r.codec())}r.encode=i;function s(a,c){return xt(a,r.codec(),c)}r.decode=s;function o(a,c){return Lt(a,r.codec(),c)}r.stream=o})(A||(A={}));var lr=1e4,At=class{protocol;components;lookupFunctions;started;init;constructor(t,e={}){this.started=!1,this.components=t,this.protocol=`/${e.protocolPrefix??"libp2p"}/${rr}/${er}`,this.lookupFunctions=new Map,this.init=e,this.handleMessage=this.handleMessage.bind(this)}[Symbol.toStringTag]="@libp2p/fetch";async start(){await this.components.registrar.handle(this.protocol,this.handleMessage,{maxInboundStreams:this.init.maxInboundStreams,maxOutboundStreams:this.init.maxOutboundStreams}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async fetch(t,e,n={}){if(typeof e=="string"&&(e=Z(e)),n.signal==null){let s=this.init.timeout??lr,o=AbortSignal.timeout(s);n={...n,signal:o}}let i;try{i=await(await this.components.connectionManager.openConnection(t,n)).newStream(this.protocol,n);let o=i.log.newScope("fetch");o.trace("fetch %m",e);let a=le(i);await a.write({identifier:e},ct,n);let c=await a.read(A,n);switch(await i.close(n),c.status){case A.StatusCode.OK:return o.trace("received status OK for %m",e),c.data;case A.StatusCode.NOT_FOUND:{o("received status NOT_FOUND for %m",e);return}case A.StatusCode.ERROR:{o("received status ERROR for %m",e);let h=ne(c.data);throw new ft("Error in fetch protocol response: "+h)}default:throw o("received status unknown for %m",e),new lt("Unknown response status")}}catch(s){throw i?.abort(s),s}}async handleMessage(t){let e=t.log.newScope("fetch"),n=AbortSignal.timeout(this.init.timeout??lr),i=le(t),s=await i.read(ct,{signal:n}),o,a=ne(s.identifier),c=this._getLookupFunction(a);if(c==null){e.trace("sending status ERROR for %m",s.identifier);let h=Z("No lookup function registered for key");o={status:A.StatusCode.ERROR,data:h}}else{e.trace("lookup data with identifier %s",c.prefix);try{let h=await c.fn(s.identifier);h==null?(e.trace("sending status NOT_FOUND for %m",s.identifier),o={status:A.StatusCode.NOT_FOUND,data:new Uint8Array(0)}):(e.trace("sending status OK for %m",s.identifier),o={status:A.StatusCode.OK,data:h})}catch(h){e.error("error during lookup of %m - %e",s.identifier,h);let u=Z(h.message);o={status:A.StatusCode.ERROR,data:u}}}await i.write(o,A,{signal:n}),await t.close({signal:n})}_getLookupFunction(t){for(let e of this.lookupFunctions.keys())if(t.startsWith(e)){let n=this.lookupFunctions.get(e);if(n!=null)return{fn:n,prefix:e}}}registerLookupFunction(t,e){if(this.lookupFunctions.has(t))throw new W(`Fetch protocol handler for key prefix '${t}' already registered`);this.lookupFunctions.set(t,e)}unregisterLookupFunction(t,e){e!=null&&this.lookupFunctions.get(t)!==e||this.lookupFunctions.delete(t)}};function ei(r={}){return t=>new At(t,r)}return br(ri);})();
2
+ "use strict";var Libp2PFetch=(()=>{var Ct=Object.defineProperty;var pr=Object.getOwnPropertyDescriptor;var mr=Object.getOwnPropertyNames;var gr=Object.prototype.hasOwnProperty;var E=(r,t)=>{for(var e in t)Ct(r,e,{get:t[e],enumerable:!0})},br=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of mr(t))!gr.call(r,i)&&i!==e&&Ct(r,i,{get:()=>t[i],enumerable:!(n=pr(t,i))||n.enumerable});return r};var wr=r=>br(Ct({},"__esModule",{value:!0}),r);var ni={};E(ni,{fetch:()=>ri});var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var lt=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var ft=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}},dt=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};function S(r=0){return new Uint8Array(r)}function y(r=0){return new Uint8Array(r)}function xr(r){return r?.buffer instanceof ArrayBuffer}function Se(r){if(xr(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Dt(r,t){t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=y(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return Se(e)}function Ie(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Ne=Symbol.for("@achingbrain/uint8arraylist");function Ae(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function pt(r){return!!r?.[Ne]}var z=class r{bufs;length;[Ne]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(pt(n)){e+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(pt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ae(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ae(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(pt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:i}=this._subList(t,e);return Dt(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:Dt(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),s=new r;return s.length=i,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=i,c=a+o.byteLength;if(i=c,t>=c)continue;let h=t>=a&&t<c,l=e>a&&e<=c;if(h&&l){if(t===a&&e===c){n.push(o);break}let u=t-a;n.push(o.subarray(u,u+(e-t)));break}if(h){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(l){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!pt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let u=0;u<s;u++)o[u]=-1;for(let u=0;u<i;u++)o[n[u]]=u;let a=o,c=this.byteLength-n.byteLength,h=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let f=h;f>=0;f--){let d=this.get(u+f);if(n[f]!==d){l=Math.max(1,f-a[d]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let i=S(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let i=S(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let i=S(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let i=S(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let i=S(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let i=S(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let i=S(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let i=S(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Ie(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,s)=>i+s.byteLength,0)),n.length=e,n}};var Mt={};E(Mt,{base10:()=>Nr});var gi=new Uint8Array(0);function De(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function I(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return $(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return $(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Ue(r){let t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}var Ce=4096;function Te(r){let t=r.length;if(t<=Ce)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.subarray(n,n+=Ce));return e}function yr(r){return r?.buffer instanceof ArrayBuffer}function $(r){return yr(r)?r:r.slice()}function Er(r,t,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=s,e){var c=o.toLowerCase().charCodeAt(0),h=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),h!==a&&(n[h]=s)}}var l=r.length,u=r.charAt(0),f=Math.log(l)/Math.log(256),d=Math.log(256)/Math.log(l);function R(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,V=0,N=0,U=m.length;N!==U&&m[N]===0;)N++,x++;for(var T=(U-N)*d+1>>>0,v=new Uint8Array(T);N!==U;){for(var O=m[N],k=0,C=T-1;(O!==0||k<V)&&C!==-1;C--,k++)O+=256*v[C]>>>0,v[C]=O%l>>>0,O=O/l>>>0;if(O!==0)throw new Error("Non-zero carry");V=k,N++}for(var M=T-V;M!==T&&v[M]===0;)M++;for(var ht=u.repeat(x);M<T;++M)ht+=r.charAt(v[M]);return ht}function ut(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var V=0,N=0;m[x]===u;)V++,x++;for(var U=(m.length-x)*f+1>>>0,T=new Uint8Array(U);m[x];){var v=n[m.charCodeAt(x)];if(v===255)return;for(var O=0,k=U-1;(v!==0||O<N)&&k!==-1;k--,O++)v+=l*T[k]>>>0,T[k]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");N=O,x++}if(m[x]!==" "){for(var C=U-N;C!==U&&T[C]===0;)C++;for(var M=new Uint8Array(V+(U-C)),ht=V;C!==U;)M[ht++]=T[C++];return M}}}function dr(m){var x=ut(m);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:R,decodeUnsafe:ut,decode:dr}}var Lr=Er,vr=Lr,Fe=vr;var Ut=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Tt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let i=e.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Me(this,t)}},Ot=class{decoders;constructor(t){this.decoders=t}or(t){return Me(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Me(r,t){return new Ot({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ft=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ut(t,e,n),this.decoder=new Tt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function K({name:r,prefix:t,encode:e,decode:n}){return new Ft(r,t,e,n)}function P({name:r,prefix:t,alphabet:e,caseInsensitive:n=!1}){let{encode:i,decode:s}=Fe(e,r,n);return K({prefix:t,name:r,encode:i,decode:o=>I(s(o))})}function Sr(r,t,e,n){let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),o=0,a=0,c=0;for(let h=0;h<i;++h){let l=t[r[h]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,o+=e,o>=8&&(o-=8,s[c++]=255&a>>o)}if(o>=e||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ir(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,s="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,s+=t[i&a>>o];if(o!==0&&(s+=t[i&a<<e-o]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ar(r,t){let e={};for(let n=0;n<r.length;++n)if(e[r[n]]=n,t){let i=r[n].toLowerCase(),s=r[n].toUpperCase();i!==r[n]&&(e[i]=n),s!==r[n]&&(e[s]=n)}return e}function g({name:r,prefix:t,bitsPerChar:e,alphabet:n,caseInsensitive:i=!1}){let s=Ar(n,i);return K({prefix:t,name:r,encode(o){return Ir(o,n,e)},decode(o){return Sr(o,s,e,r)}})}var Nr=P({prefix:"9",name:"base10",alphabet:"0123456789"});var Bt={};E(Bt,{base16:()=>Cr,base16upper:()=>Dr});var Cr=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Dr=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Rt={};E(Rt,{base2:()=>Ur});var Ur=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kt={};E(kt,{base256emoji:()=>Br});var Be=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}"),Tr=Be.reduce((r,t,e)=>(r[e]=t,r),[]),Or=Be.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Fr(r){return r.reduce((t,e)=>(t+=Tr[e],t),"")}function Mr(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let i=Or[n];if(i==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(i)}return new Uint8Array(t)}var Br=K({prefix:"\u{1F680}",name:"base256emoji",encode:Fr,decode:Mr});var Pt={};E(Pt,{base32:()=>H,base32hex:()=>_r,base32hexpad:()=>zr,base32hexpadupper:()=>$r,base32hexupper:()=>Vr,base32pad:()=>kr,base32padupper:()=>Pr,base32upper:()=>Rr,base32z:()=>Gr});var H=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Rr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),kr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Pr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),_r=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Vr=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),zr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),$r=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Gr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _t={};E(_t,{base36:()=>tt,base36upper:()=>jr});var tt=P({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),jr=P({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Vt={};E(Vt,{base58btc:()=>F,base58flickr:()=>qr});var F=P({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qr=P({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zt={};E(zt,{base64:()=>Wr,base64pad:()=>Kr,base64url:()=>Hr,base64urlpad:()=>Xr});var Wr=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Kr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Hr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $t={};E($t,{base8:()=>Jr});var Jr=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Gt={};E(Gt,{identity:()=>Yr});var Yr=K({prefix:"\0",name:"identity",encode:r=>Te(I(r)),decode:r=>I(Ue(r))});var Oi=new TextEncoder,Fi=new TextDecoder;var qt={};E(qt,{identity:()=>En});var tn=Pe,Re=128,en=127,rn=~en,nn=Math.pow(2,31);function Pe(r,t,e){t=t||[],e=e||0;for(var n=e;r>=nn;)t[e++]=r&255|Re,r/=128;for(;r&rn;)t[e++]=r&255|Re,r>>>=7;return t[e]=r|0,Pe.bytes=e-n+1,t}var sn=jt,on=128,ke=127;function jt(r,n){var e=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw jt.bytes=0,new RangeError("Could not decode varint");o=r[s++],e+=i<28?(o&ke)<<i:(o&ke)*Math.pow(2,i),i+=7}while(o>=on);return jt.bytes=s-n,e}var an=Math.pow(2,7),cn=Math.pow(2,14),un=Math.pow(2,21),hn=Math.pow(2,28),ln=Math.pow(2,35),fn=Math.pow(2,42),dn=Math.pow(2,49),pn=Math.pow(2,56),mn=Math.pow(2,63),gn=function(r){return r<an?1:r<cn?2:r<un?3:r<hn?4:r<ln?5:r<fn?6:r<dn?7:r<pn?8:r<mn?9:10},bn={encode:tn,decode:sn,encodingLength:gn},wn=bn,et=wn;function rt(r,t=0){let e=et.decode(r,t),n=et.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[e,n]}function X(r,t,e=0){return et.encode(r,t,e),t}function J(r){return et.encodingLength(r)}function Q(r,t){let e=t.byteLength,n=J(r),i=n+J(e),s=new Uint8Array(i+e);return X(r,s,0),X(e,s,n),s.set(t,i),new Y(r,e,t,s)}function _e(r){let t=I(r),[e,n]=rt(t),[i,s]=rt(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Y(e,i,o,t)}function Ve(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&De(r.bytes,e.bytes)}}var Y=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=$(n),this.bytes=$(i)}};var ze=0,xn="identity",$e=I;function yn(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Q(ze,$e(r))}var En={code:ze,name:xn,encode:$e,digest:yn};var Ht={};E(Ht,{sha256:()=>vn,sha512:()=>Sn});var Ln=20;function Kt({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:i}){return new Wt(r,t,e,n,i)}var Wt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,i,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=i??Ln,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ge(n,this.code,e?.truncate):n.then(i=>Ge(i,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ge(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Q(t,r)}function qe(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var vn=Kt({name:"sha2-256",code:18,encode:qe("SHA-256")}),Sn=Kt({name:"sha2-512",code:19,encode:qe("SHA-512")});function We(r,t){let{bytes:e,version:n}=r;return n===0?An(e,Xt(r),t??F.encoder):Nn(e,Xt(r),t??H.encoder)}var Ke=new WeakMap;function Xt(r){let t=Ke.get(r);if(t==null){let e=new Map;return Ke.set(r,e),e}return t}var gt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=$(i),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:t,multihash:e}=this;if(t!==it)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Cn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Q(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ve(t.multihash,n.multihash)}toString(t){return We(this,t)}toJSON(){return{"/":We(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:s,bytes:o}=e;return new r(n,i,s,o??He(n,i,s.bytes))}else if(e[Dn]===!0){let{version:n,multihash:i,code:s}=e,o=_e(i);return r.create(n,s,o)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==it)throw new Error(`Version 0 CID must use dag-pb (code: ${it}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=He(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,it,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=I(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=i.subarray(e.multihashSize-e.digestSize),o=new Y(e.multihashCode,e.digestSize,s,i);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,f]=rt(t.subarray(e));return e+=f,u},i=n(),s=it;if(i===18?(i=0,e=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=e,a=n(),c=n(),h=e+c,l=h-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:h}}static parse(t,e){let[n,i]=In(t,e),s=r.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xt(s).set(n,t),s}};function In(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case H.prefix:{let e=t??H;return[H.prefix,e.decode(r)]}case tt.prefix:{let e=t??tt;return[tt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function An(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return i}function Nn(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let s=e.encode(r);return t.set(n,s),s}else return i}var it=112,Cn=18;function He(r,t,e){let n=J(r),i=n+J(t),s=new Uint8Array(i+e.byteLength);return X(r,s,0),X(t,s,n),s.set(e,i),s}var Dn=Symbol.for("@ipld/js-cid/CID");var Jt={...Gt,...Rt,...$t,...Mt,...Bt,...Pt,..._t,...Vt,...zt,...kt},es={...Ht,...qt};function Je(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Xe=Je("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Yt=Je("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=y(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Un={utf8:Xe,"utf-8":Xe,hex:Jt.base16,latin1:Yt,ascii:Yt,binary:Yt,...Jt},bt=Un;function Z(r,t="utf8"){let e=bt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var Tn=Math.pow(2,7),On=Math.pow(2,14),Fn=Math.pow(2,21),Qt=Math.pow(2,28),Zt=Math.pow(2,35),te=Math.pow(2,42),ee=Math.pow(2,49),p=128,b=127;function B(r){if(r<Tn)return 1;if(r<On)return 2;if(r<Fn)return 3;if(r<Qt)return 4;if(r<Zt)return 5;if(r<te)return 6;if(r<ee)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function re(r,t,e=0){switch(B(r)){case 8:t[e++]=r&255|p,r/=128;case 7:t[e++]=r&255|p,r/=128;case 6:t[e++]=r&255|p,r/=128;case 5:t[e++]=r&255|p,r/=128;case 4:t[e++]=r&255|p,r>>>=7;case 3:t[e++]=r&255|p,r>>>=7;case 2:t[e++]=r&255|p,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Mn(r,t,e=0){switch(B(r)){case 8:t.set(e++,r&255|p),r/=128;case 7:t.set(e++,r&255|p),r/=128;case 6:t.set(e++,r&255|p),r/=128;case 5:t.set(e++,r&255|p),r/=128;case 4:t.set(e++,r&255|p),r>>>=7;case 3:t.set(e++,r&255|p),r>>>=7;case 2:t.set(e++,r&255|p),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ne(r,t){let e=r[t],n=0;if(n+=e&b,e<p||(e=r[t+1],n+=(e&b)<<7,e<p)||(e=r[t+2],n+=(e&b)<<14,e<p)||(e=r[t+3],n+=(e&b)<<21,e<p)||(e=r[t+4],n+=(e&b)*Qt,e<p)||(e=r[t+5],n+=(e&b)*Zt,e<p)||(e=r[t+6],n+=(e&b)*te,e<p)||(e=r[t+7],n+=(e&b)*ee,e<p))return n;throw new RangeError("Could not decode varint")}function Bn(r,t){let e=r.get(t),n=0;if(n+=e&b,e<p||(e=r.get(t+1),n+=(e&b)<<7,e<p)||(e=r.get(t+2),n+=(e&b)<<14,e<p)||(e=r.get(t+3),n+=(e&b)<<21,e<p)||(e=r.get(t+4),n+=(e&b)*Qt,e<p)||(e=r.get(t+5),n+=(e&b)*Zt,e<p)||(e=r.get(t+6),n+=(e&b)*te,e<p)||(e=r.get(t+7),n+=(e&b)*ee,e<p))return n;throw new RangeError("Could not decode varint")}function Ye(r,t,e=0){return t==null&&(t=y(B(r))),t instanceof Uint8Array?re(r,t,e):Mn(r,t,e)}function Qe(r,t=0){return r instanceof Uint8Array?ne(r,t):Bn(r,t)}function kn(r){return r.buffer instanceof ArrayBuffer}function Ze(r){return kn(r)?r:r.slice()}function ie(r,t="utf8"){let e=bt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var se=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},tr=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function oe(r,t){let{milliseconds:e,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout},signal:o}=t,a,c,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(o?.aborted){f(tr(o));return}if(o&&(c=()=>{f(tr(o))},o.addEventListener("abort",c,{once:!0})),r.then(u,f),e===Number.POSITIVE_INFINITY)return;let d=new se;a=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(R){f(R)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?u():i instanceof Error?f(i):(d.message=i??`Promise timed out after ${e} milliseconds`,f(d))},e)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var Pn=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function _n(r,t,e){let n,i=new Promise((s,o)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:h,removeListener:l}=Pn(r),u=async(...d)=>{let R=e.multiArgs?d:d[0];if(e.filter)try{if(!await e.filter(R))return}catch(ut){n(),o(ut);return}c.push(R),e.count===c.length&&(n(),s(c))},f=(...d)=>{n(),o(e.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)l(d,u);for(let d of e.rejectionEvents)a.includes(d)||l(d,f)};for(let d of a)h(d,u);for(let d of e.rejectionEvents)a.includes(d)||h(d,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(i.cancel=n,typeof e.timeout=="number"){let s=oe(i,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return i}function er(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=_n(r,t,e),i=n.then(s=>s[0]);return i.cancel=n.cancel,i}var G=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Vn(r){return r.reason}function ae(r,t,e){if(t==null||r==null)return r;let n=e?.translateError??Vn;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let i;return Promise.race([r,new Promise((s,o)=>{i=()=>{o(n(t))},t.addEventListener("abort",i)})]).finally(()=>{i!=null&&t.removeEventListener("abort",i)})}var $n=4194304,wt=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ue=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},he=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},le=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Gn(r){return typeof r?.closeRead=="function"}function jn(r){return typeof r?.close=="function"}function ce(r){return Gn(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:jn(r)?r.status!=="open":!1}function qn(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Wn(r,t){let e=t?.maxBufferSize??$n,n=new z,i,s=!1,o;if(!qn(r))throw new W("Argument should be a Stream or a Multiaddr");let a=u=>{if(o==null){if(n.append(u.data),n.byteLength>e){let f=n.byteLength;n.consume(f);let d=new lt(`Read buffer overflow - ${f} > ${e}`);o=d,i?.reject(d),queueMicrotask(()=>{r.abort(d)});return}i?.resolve()}};r.addEventListener("message",a);let c=u=>{u.error!=null?i?.reject(u.error):i?.resolve()};r.addEventListener("close",c);let h=()=>{i?.resolve()};r.addEventListener("remoteCloseWrite",h);let l={readBuffer:n,async read(u){if(s===!0)throw new wt("Stream was unwrapped");if(o!=null)throw o;if(ce(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 G(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let f=u?.bytes??1;for(i=Promise.withResolvers();;){if(n.byteLength>=f){i.resolve();break}if(await ae(i.promise,u?.signal),ce(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}i=Promise.withResolvers()}let d=u?.bytes??n.byteLength;if(n.byteLength<d){if(ce(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new G(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return l.read(u)}let R=n.sublist(0,d);return n.consume(d),R},async write(u,f){if(s===!0)throw new wt("Stream was unwrapped");r.send(u)||await er(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,r.removeEventListener("message",a),r.removeEventListener("close",c),r.removeEventListener("remoteCloseWrite",h),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return l}function Kn(r,t={}){let e=Wn(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=B(t.maxDataLength));let n=t?.lengthDecoder??Qe,i=t?.lengthEncoder??Ye;return{async read(o){let a=-1,c=new z;for(;;){let l=await e.read({...o,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new ue("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new le(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new he(`Message length too long - ${a} > ${t.maxDataLength}`);let h=await e.read({...o,bytes:a});if(h==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new G(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(h.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new G(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(o,a){await e.write(new z(i(o.byteLength),o),a)},async writeV(o,a){let c=new z(...o.flatMap(h=>[i(h.byteLength),h]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function fe(r,t){let e=Kn(r,t),n={read:async(i,s)=>{let o=await e.read(s);return i.decode(o,s)},write:async(i,s,o)=>{await e.write(s.encode(i),o)},writeV:async(i,s,o)=>{await e.writeV(i.map(a=>s.encode(a)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var rr="0.0.1",nr="fetch";var de=new Float32Array([-0]),_=new Uint8Array(de.buffer);function ir(r,t,e){de[0]=r,t[e]=_[0],t[e+1]=_[1],t[e+2]=_[2],t[e+3]=_[3]}function sr(r,t){return _[0]=r[t],_[1]=r[t+1],_[2]=r[t+2],_[3]=r[t+3],de[0]}var pe=new Float64Array([-0]),w=new Uint8Array(pe.buffer);function or(r,t,e){pe[0]=r,t[e]=w[0],t[e+1]=w[1],t[e+2]=w[2],t[e+3]=w[3],t[e+4]=w[4],t[e+5]=w[5],t[e+6]=w[6],t[e+7]=w[7]}function ar(r,t){return w[0]=r[t],w[1]=r[t+1],w[2]=r[t+2],w[3]=r[t+3],w[4]=r[t+4],w[5]=r[t+5],w[6]=r[t+6],w[7]=r[t+7],pe[0]}var Hn=BigInt(Number.MAX_SAFE_INTEGER),Xn=BigInt(Number.MIN_SAFE_INTEGER),L=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return j;if(t<Hn&&t>Xn)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>cr&&(i=0n,++n>cr&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return j;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):j}},j=new L(0,0);j.toBigInt=function(){return 0n};j.zzEncode=j.zzDecode=function(){return this};j.length=function(){return 1};var cr=4294967296n;function ur(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function hr(r,t,e){if(e-t<1)return"";let i,s=[],o=0,a;for(;t<e;)a=r[t++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function me(r,t,e){let n=e,i,s;for(let o=0;o<r.length;++o)i=r.charCodeAt(o),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((s=r.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function D(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function xt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ge=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Ze(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,D(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw D(this,4);return xt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw D(this,4);return xt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw D(this,4);let t=sr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw D(this,4);let t=ar(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw D(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return hr(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw D(this,t);this.pos+=t}else do if(this.pos>=this.len)throw D(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new L(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw D(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw D(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw D(this,8);let t=xt(this.buf,this.pos+=4),e=xt(this.buf,this.pos+=4);return new L(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ne(this.buf,this.pos);return this.pos+=B(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function st(r){return new ge(r instanceof Uint8Array?r:r.subarray())}function yt(r,t,e){let n=st(r);return t.decode(n,void 0,e)}function be(r){let t=r??8192,e=t>>>1,n,i=t;return function(o){if(o<1||o>e)return y(o);i+o>t&&(n=y(t),i=0);let a=n.subarray(i,i+=o);return(i&7)!==0&&(i=(i|7)+1),a}}var q=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function we(){}var ye=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Jn=be();function Yn(r){return globalThis.Buffer!=null?y(r):Jn(r)}var at=class{len;head;tail;states;constructor(){this.len=0,this.head=new q(we,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new q(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ee((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Et,10,L.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=L.fromBigInt(t);return this._push(Et,e.length(),e)}uint64Number(t){return this._push(re,B(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=L.fromBigInt(t).zzEncode();return this._push(Et,e.length(),e)}sint64Number(t){let e=L.fromNumber(t).zzEncode();return this._push(Et,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(xe,1,t?1:0)}fixed32(t){return this._push(ot,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=L.fromBigInt(t);return this._push(ot,4,e.lo)._push(ot,4,e.hi)}fixed64Number(t){let e=L.fromNumber(t);return this._push(ot,4,e.lo)._push(ot,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ir,4,t)}double(t){return this._push(or,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(xe,1,0):this.uint32(e)._push(Zn,e,t)}string(t){let e=ur(t);return e!==0?this.uint32(e)._push(me,e,t):this._push(xe,1,0)}fork(){return this.states=new ye(this),this.head=this.tail=new q(we,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new q(we,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Yn(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function xe(r,t,e){t[e]=r&255}function Qn(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ee=class extends q{next;constructor(t,e){super(Qn,t,e),this.next=void 0}};function Et(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function ot(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Zn(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(at.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(ti,t,r),this},at.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ei,t,r),this});function ti(r,t,e){t.set(r,e)}function ei(r,t,e){r.length<40?me(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function Le(){return new at}function Lt(r,t){let e=Le();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*vt(r,t,e){let n=st(r);yield*t.stream(n,void 0,"$",e)}var St={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function It(r,t,e,n,i){return{name:r,type:t,encode:e,decode:n,stream:i}}function ve(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},i=function*(o){let a=o.int32();yield t(a)};return It("enum",St.VARINT,e,n,i)}function At(r,t,e){return It("message",St.LENGTH_DELIMITED,r,t,e)}var ct;(function(r){let t;r.codec=()=>(t==null&&(t=At((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.identifier!=null&&s.identifier.byteLength>0&&(o.uint32(10),o.bytes(s.identifier)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={identifier:S(0)},h=o==null?s.len:s.pos+o;for(;s.pos<h;){let l=s.uint32();l>>>3===1?c.identifier=s.bytes():s.skipType(l&7)}return c},function*(s,o,a,c={}){let h=o==null?s.len:s.pos+o;for(;s.pos<h;){let l=s.uint32();l>>>3===1?yield{field:`${a}.identifier`,value:s.bytes()}:s.skipType(l&7)}})),t);function e(s){return Lt(s,r.codec())}r.encode=e;function n(s,o){return yt(s,r.codec(),o)}r.decode=n;function i(s,o){return vt(s,r.codec(),o)}r.stream=i})(ct||(ct={}));var A;(function(r){let t;(function(a){a.OK="OK",a.NOT_FOUND="NOT_FOUND",a.ERROR="ERROR"})(t=r.StatusCode||(r.StatusCode={}));let e;(function(a){a[a.OK=0]="OK",a[a.NOT_FOUND=1]="NOT_FOUND",a[a.ERROR=2]="ERROR"})(e||(e={})),(function(a){a.codec=()=>ve(e)})(t=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=At((a,c,h={})=>{h.lengthDelimited!==!1&&c.fork(),a.status!=null&&e[a.status]!==0&&(c.uint32(8),r.StatusCode.codec().encode(a.status,c)),a.data!=null&&a.data.byteLength>0&&(c.uint32(18),c.bytes(a.data)),h.lengthDelimited!==!1&&c.ldelim()},(a,c,h={})=>{let l={status:t.OK,data:S(0)},u=c==null?a.len:a.pos+c;for(;a.pos<u;){let f=a.uint32();switch(f>>>3){case 1:{l.status=r.StatusCode.codec().decode(a);break}case 2:{l.data=a.bytes();break}default:{a.skipType(f&7);break}}}return l},function*(a,c,h,l={}){let u=c==null?a.len:a.pos+c;for(;a.pos<u;){let f=a.uint32();switch(f>>>3){case 1:{yield{field:`${h}.status`,value:r.StatusCode.codec().decode(a)};break}case 2:{yield{field:`${h}.data`,value:a.bytes()};break}default:{a.skipType(f&7);break}}}})),n);function i(a){return Lt(a,r.codec())}r.encode=i;function s(a,c){return yt(a,r.codec(),c)}r.decode=s;function o(a,c){return vt(a,r.codec(),c)}r.stream=o})(A||(A={}));var fr=1e4,Nt=class{protocol;components;lookupFunctions;started;init;constructor(t,e={}){this.started=!1,this.components=t,this.protocol=`/${e.protocolPrefix??"libp2p"}/${nr}/${rr}`,this.lookupFunctions=new Map,this.init=e,this.handleMessage=this.handleMessage.bind(this)}[Symbol.toStringTag]="@libp2p/fetch";async start(){await this.components.registrar.handle(this.protocol,this.handleMessage,{maxInboundStreams:this.init.maxInboundStreams,maxOutboundStreams:this.init.maxOutboundStreams}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async fetch(t,e,n={}){if(typeof e=="string"&&(e=Z(e)),n.signal==null){let s=this.init.timeout??fr,o=AbortSignal.timeout(s);n={...n,signal:o}}let i;try{i=await(await this.components.connectionManager.openConnection(t,n)).newStream(this.protocol,n);let o=i.log.newScope("fetch");o.trace("fetch %m",e);let a=fe(i);await a.write({identifier:e},ct,n);let c=await a.read(A,n);switch(await i.close(n),c.status){case A.StatusCode.OK:return o.trace("received status OK for %m",e),c.data;case A.StatusCode.NOT_FOUND:{o("received status NOT_FOUND for %m",e);return}case A.StatusCode.ERROR:{o("received status ERROR for %m",e);let h=ie(c.data);throw new dt("Error in fetch protocol response: "+h)}default:throw o("received status unknown for %m",e),new ft("Unknown response status")}}catch(s){throw i?.abort(s),s}}async handleMessage(t){let e=t.log.newScope("fetch"),n=AbortSignal.timeout(this.init.timeout??fr),i=fe(t),s=await i.read(ct,{signal:n}),o,a=ie(s.identifier),c=this._getLookupFunction(a);if(c==null){e.trace("sending status ERROR for %m",s.identifier);let h=Z("No lookup function registered for key");o={status:A.StatusCode.ERROR,data:h}}else{e.trace("lookup data with identifier %s",c.prefix);try{let h=await c.fn(s.identifier);h==null?(e.trace("sending status NOT_FOUND for %m",s.identifier),o={status:A.StatusCode.NOT_FOUND,data:new Uint8Array(0)}):(e.trace("sending status OK for %m",s.identifier),o={status:A.StatusCode.OK,data:h})}catch(h){e.error("error during lookup of %m - %e",s.identifier,h);let l=Z(h.message);o={status:A.StatusCode.ERROR,data:l}}}await i.write(o,A,{signal:n}),await t.close({signal:n})}_getLookupFunction(t){for(let e of this.lookupFunctions.keys())if(t.startsWith(e)){let n=this.lookupFunctions.get(e);if(n!=null)return{fn:n,prefix:e}}}registerLookupFunction(t,e){if(this.lookupFunctions.has(t))throw new W(`Fetch protocol handler for key prefix '${t}' already registered`);this.lookupFunctions.set(t,e)}unregisterLookupFunction(t,e){e!=null&&this.lookupFunctions.get(t)!==e||this.lookupFunctions.delete(t)}};function ri(r={}){return t=>new Nt(t,r)}return wr(ni);})();
3
3
  return Libp2PFetch}));
4
4
  //# sourceMappingURL=index.min.js.map