@libp2p/fetch 4.0.8 → 4.0.9-7fff925bf

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