@libp2p/fetch 4.1.5-29797a5bb → 4.1.5-5b8813abc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +6 -6
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 qe=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var vn=Object.getOwnPropertyNames;var Ln=Object.prototype.hasOwnProperty;var g=(r,e)=>{for(var t in e)qe(r,t,{get:e[t],enumerable:!0})},Sn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of vn(e))!Ln.call(r,o)&&o!==t&&qe(r,o,{get:()=>e[o],enumerable:!(n=En(e,o))||n.enumerable});return r};var An=r=>Sn(qe({},"__esModule",{value:!0}),r);var xs={};g(xs,{fetch:()=>bs});var H=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Se=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}},Ae=class extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}};var We={};g(We,{base58btc:()=>M,base58flickr:()=>On});var ys=new Uint8Array(0);function cr(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 k(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 ur(r){return new TextEncoder().encode(r)}function hr(r){return new TextDecoder().decode(r)}function In(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var p=0,U=0,w=0,L=f.length;w!==L&&f[w]===0;)w++,p++;for(var S=(L-w)*u+1>>>0,x=new Uint8Array(S);w!==L;){for(var A=f[w],C=0,y=S-1;(A!==0||C<U)&&y!==-1;y--,C++)A+=256*x[y]>>>0,x[y]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");U=C,w++}for(var I=S-U;I!==S&&x[I]===0;)I++;for(var R=c.repeat(p);I<S;++I)R+=r.charAt(x[I]);return R}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var p=0;if(f[p]!==" "){for(var U=0,w=0;f[p]===c;)U++,p++;for(var L=(f.length-p)*h+1>>>0,S=new Uint8Array(L);f[p];){var x=t[f.charCodeAt(p)];if(x===255)return;for(var A=0,C=L-1;(x!==0||A<w)&&C!==-1;C--,A++)x+=a*S[C]>>>0,S[C]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");w=A,p++}if(f[p]!==" "){for(var y=L-w;y!==L&&S[y]===0;)y++;for(var I=new Uint8Array(U+(L-y)),R=U;y!==L;)I[R++]=S[y++];return I}}}function b(f){var p=d(f);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:b}}var Cn=In,Dn=Cn,lr=Dn;var je=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ge=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 dr(this,e)}},Je=class{decoders;constructor(e){this.decoders=e}or(e){return dr(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 dr(r,e){return new Je({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ke=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new je(e,t,n),this.decoder=new Ge(e,t,o)}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 Ke(r,e,t,n)}function $({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=lr(t,r);return Q({prefix:e,name:r,encode:n,decode:i=>k(o(i))})}function Nn(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let h=0;h<o;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Un(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function Tn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function E({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Tn(n);return Q({prefix:e,name:r,encode(i){return Un(i,n,t)},decode(i){return Nn(i,o,t,r)}})}var M=$({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),On=$({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xe={};g(Xe,{base32:()=>Y,base32hex:()=>Rn,base32hexpad:()=>Pn,base32hexpadupper:()=>zn,base32hexupper:()=>kn,base32pad:()=>Mn,base32padupper:()=>Bn,base32upper:()=>Fn,base32z:()=>Vn});var Y=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fn=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Mn=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Bn=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Rn=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),kn=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pn=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zn=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vn=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var He={};g(He,{base36:()=>ue,base36upper:()=>$n});var ue=$({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$n=$({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var _n=br,pr=128,qn=127,jn=~qn,Gn=Math.pow(2,31);function br(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Gn;)e[t++]=r&255|pr,r/=128;for(;r&jn;)e[t++]=r&255|pr,r>>>=7;return e[t]=r|0,br.bytes=t-n+1,e}var Jn=Qe,Kn=128,mr=127;function Qe(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Qe.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&mr)<<o:(s&mr)*Math.pow(2,o),o+=7}while(s>=Kn);return Qe.bytes=i-n,t}var Wn=Math.pow(2,7),Xn=Math.pow(2,14),Hn=Math.pow(2,21),Qn=Math.pow(2,28),Yn=Math.pow(2,35),Zn=Math.pow(2,42),eo=Math.pow(2,49),to=Math.pow(2,56),ro=Math.pow(2,63),no=function(r){return r<Wn?1:r<Xn?2:r<Hn?3:r<Qn?4:r<Yn?5:r<Zn?6:r<eo?7:r<to?8:r<ro?9:10},oo={encode:_n,decode:Jn,encodingLength:no},io=oo,he=io;function fe(r,e=0){return[he.decode(r,e),he.decode.bytes]}function Z(r,e,t=0){return he.encode(r,e,t),e}function ee(r){return he.encodingLength(r)}function re(r,e){let t=e.byteLength,n=ee(r),o=n+ee(t),i=new Uint8Array(o+t);return Z(r,i,0),Z(t,i,n),i.set(e,o),new te(r,t,e,i)}function xr(r){let e=k(r),[t,n]=fe(e),[o,i]=fe(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new te(t,o,s,e)}function gr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&cr(r.bytes,t.bytes)}}var te=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function wr(r,e){let{bytes:t,version:n}=r;return n===0?ao(t,Ye(r),e??M.encoder):co(t,Ye(r),e??Y.encoder)}var yr=new WeakMap;function Ye(r){let e=yr.get(r);if(e==null){let t=new Map;return yr.set(r,t),t}return e}var Ce=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==de)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==uo)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=re(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&gr(e.multihash,n.multihash)}toString(e){return wr(this,e)}toJSON(){return{"/":wr(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Er(n,o,i.bytes))}else if(t[ho]===!0){let{version:n,multihash:o,code:i}=t,s=xr(o);return r.create(n,i,s)}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!==de)throw new Error(`Version 0 CID must use dag-pb (code: ${de}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Er(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,de,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,o=k(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new te(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,d]=fe(e.subarray(t));return t+=d,l},o=n(),i=de;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),h=t+c,u=h-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(e,t){let[n,o]=so(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ye(i).set(n,e),i}};function so(r,e){switch(r[0]){case"Q":{let t=e??M;return[M.prefix,t.decode(`${M.prefix}${r}`)]}case M.prefix:{let t=e??M;return[M.prefix,t.decode(r)]}case Y.prefix:{let t=e??Y;return[Y.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.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 ao(r,e,t){let{prefix:n}=t;if(n!==M.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function co(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var de=112,uo=18;function Er(r,e,t){let n=ee(r),o=n+ee(e),i=new Uint8Array(o+t.byteLength);return Z(r,i,0),Z(e,i,n),i.set(t,o),i}var ho=Symbol.for("@ipld/js-cid/CID");var Ze={};g(Ze,{identity:()=>po});var vr=0,fo="identity",Lr=k;function lo(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return re(vr,Lr(r))}var po={code:vr,name:fo,encode:Lr,digest:lo};function P(r=0){return new Uint8Array(r)}function pe(r=0){return new Uint8Array(r)}function et(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=pe(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function Sr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Ir=Symbol.for("@achingbrain/uint8arraylist");function Ar(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function De(r){return!!r?.[Ir]}var j=class r{bufs;length;[Ir]=!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(De(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(De(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=Ar(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Ar(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(De(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:o}=this._subList(e,t);return et(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:et(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=n,i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let h=e>=a&&e<c,u=t>a&&t<=c;if(h&&u){if(e===a&&t===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(t-e)));break}if(h){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!De(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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,h=n.byteLength-1,u;for(let l=t;l<=c;l+=u){u=0;for(let d=h;d>=0;d--){let b=this.get(l+d);if(n[d]!==b){u=Math.max(1,d-a[b]);break}}if(u===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=pe(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 o=P(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,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 o=P(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,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 o=P(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,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=pe(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 o=P(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,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 o=P(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,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 o=P(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,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 o=P(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,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 o=P(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,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(!Sr(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((o,i)=>o+i.byteLength,0)),n.length=t,n}};var it={};g(it,{base10:()=>vo});var Xs=new Uint8Array(0);function Cr(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 z(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return G(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return G(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Dr(r){return new TextEncoder().encode(r)}function Nr(r){return new TextDecoder().decode(r)}function mo(r){return r?.buffer instanceof ArrayBuffer}function G(r){return mo(r)?r:r.slice()}function bo(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var p=0,U=0,w=0,L=f.length;w!==L&&f[w]===0;)w++,p++;for(var S=(L-w)*u+1>>>0,x=new Uint8Array(S);w!==L;){for(var A=f[w],C=0,y=S-1;(A!==0||C<U)&&y!==-1;y--,C++)A+=256*x[y]>>>0,x[y]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");U=C,w++}for(var I=S-U;I!==S&&x[I]===0;)I++;for(var R=c.repeat(p);I<S;++I)R+=r.charAt(x[I]);return R}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var p=0;if(f[p]!==" "){for(var U=0,w=0;f[p]===c;)U++,p++;for(var L=(f.length-p)*h+1>>>0,S=new Uint8Array(L);f[p];){var x=t[f.charCodeAt(p)];if(x===255)return;for(var A=0,C=L-1;(x!==0||A<w)&&C!==-1;C--,A++)x+=a*S[C]>>>0,S[C]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");w=A,p++}if(f[p]!==" "){for(var y=L-w;y!==L&&S[y]===0;)y++;for(var I=new Uint8Array(U+(L-y)),R=U;y!==L;)I[R++]=S[y++];return I}}}function b(f){var p=d(f);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:b}}var xo=bo,go=xo,Tr=go;var tt=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")}},rt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 Or(this,e)}},nt=class{decoders;constructor(e){this.decoders=e}or(e){return Or(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 Or(r,e){return new nt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ot=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new tt(e,t,n),this.decoder=new rt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ne({name:r,prefix:e,encode:t,decode:n}){return new ot(r,e,t,n)}function _({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Tr(t,r);return ne({prefix:e,name:r,encode:n,decode:i=>z(o(i))})}function wo(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let h=0;h<o;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function yo(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function Eo(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Eo(n);return ne({prefix:e,name:r,encode(i){return yo(i,n,t)},decode(i){return wo(i,o,t,r)}})}var vo=_({prefix:"9",name:"base10",alphabet:"0123456789"});var st={};g(st,{base16:()=>Lo,base16upper:()=>So});var Lo=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),So=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var at={};g(at,{base2:()=>Ao});var Ao=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ct={};g(ct,{base256emoji:()=>Uo});var Fr=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}"),Io=Fr.reduce((r,e,t)=>(r[t]=e,r),[]),Co=Fr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Do(r){return r.reduce((e,t)=>(e+=Io[t],e),"")}function No(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Co[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Uo=ne({prefix:"\u{1F680}",name:"base256emoji",encode:Do,decode:No});var ut={};g(ut,{base32:()=>oe,base32hex:()=>Mo,base32hexpad:()=>Ro,base32hexpadupper:()=>ko,base32hexupper:()=>Bo,base32pad:()=>Oo,base32padupper:()=>Fo,base32upper:()=>To,base32z:()=>Po});var oe=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),To=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Oo=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Fo=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Mo=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bo=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ro=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ko=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Po=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ht={};g(ht,{base36:()=>me,base36upper:()=>zo});var me=_({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zo=_({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ft={};g(ft,{base58btc:()=>B,base58flickr:()=>Vo});var B=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vo=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lt={};g(lt,{base64:()=>$o,base64pad:()=>_o,base64url:()=>qo,base64urlpad:()=>jo});var $o=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_o=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qo=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jo=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var dt={};g(dt,{base8:()=>Go});var Go=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var pt={};g(pt,{identity:()=>Jo});var Jo=ne({prefix:"\0",name:"identity",encode:r=>Nr(r),decode:r=>Dr(r)});var fa=new TextEncoder,la=new TextDecoder;var bt={};g(bt,{identity:()=>mi});var Xo=Rr,Mr=128,Ho=127,Qo=~Ho,Yo=Math.pow(2,31);function Rr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Yo;)e[t++]=r&255|Mr,r/=128;for(;r&Qo;)e[t++]=r&255|Mr,r>>>=7;return e[t]=r|0,Rr.bytes=t-n+1,e}var Zo=mt,ei=128,Br=127;function mt(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw mt.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Br)<<o:(s&Br)*Math.pow(2,o),o+=7}while(s>=ei);return mt.bytes=i-n,t}var ti=Math.pow(2,7),ri=Math.pow(2,14),ni=Math.pow(2,21),oi=Math.pow(2,28),ii=Math.pow(2,35),si=Math.pow(2,42),ai=Math.pow(2,49),ci=Math.pow(2,56),ui=Math.pow(2,63),hi=function(r){return r<ti?1:r<ri?2:r<ni?3:r<oi?4:r<ii?5:r<si?6:r<ai?7:r<ci?8:r<ui?9:10},fi={encode:Xo,decode:Zo,encodingLength:hi},li=fi,be=li;function xe(r,e=0){return[be.decode(r,e),be.decode.bytes]}function ie(r,e,t=0){return be.encode(r,e,t),e}function se(r){return be.encodingLength(r)}function ce(r,e){let t=e.byteLength,n=se(r),o=n+se(t),i=new Uint8Array(o+t);return ie(r,i,0),ie(t,i,n),i.set(e,o),new ae(r,t,e,i)}function kr(r){let e=z(r),[t,n]=xe(e),[o,i]=xe(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ae(t,o,s,e)}function Pr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Cr(r.bytes,t.bytes)}}var ae=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=G(n),this.bytes=G(o)}};var zr=0,di="identity",Vr=z;function pi(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 ce(zr,Vr(r))}var mi={code:zr,name:di,encode:Vr,digest:pi};var wt={};g(wt,{sha256:()=>xi,sha512:()=>gi});var bi=20;function gt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new xt(r,e,t,n,o)}var xt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??bi,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?$r(n,this.code,t?.truncate):n.then(o=>$r(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function $r(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 ce(e,r)}function qr(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var xi=gt({name:"sha2-256",code:18,encode:qr("SHA-256")}),gi=gt({name:"sha2-512",code:19,encode:qr("SHA-512")});function jr(r,e){let{bytes:t,version:n}=r;return n===0?yi(t,yt(r),e??B.encoder):Ei(t,yt(r),e??oe.encoder)}var Gr=new WeakMap;function yt(r){let e=Gr.get(r);if(e==null){let t=new Map;return Gr.set(r,t),t}return e}var Ue=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=G(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==we)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==vi)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=ce(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&&Pr(e.multihash,n.multihash)}toString(e){return jr(this,e)}toJSON(){return{"/":jr(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Jr(n,o,i.bytes))}else if(t[Li]===!0){let{version:n,multihash:o,code:i}=t,s=kr(o);return r.create(n,i,s)}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!==we)throw new Error(`Version 0 CID must use dag-pb (code: ${we}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Jr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,we,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,o=z(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new ae(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,d]=xe(e.subarray(t));return t+=d,l},o=n(),i=we;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),h=t+c,u=h-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(e,t){let[n,o]=wi(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yt(i).set(n,e),i}};function wi(r,e){switch(r[0]){case"Q":{let t=e??B;return[B.prefix,t.decode(`${B.prefix}${r}`)]}case B.prefix:{let t=e??B;return[B.prefix,t.decode(r)]}case oe.prefix:{let t=e??oe;return[oe.prefix,t.decode(r)]}case me.prefix:{let t=e??me;return[me.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 yi(r,e,t){let{prefix:n}=t;if(n!==B.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Ei(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var we=112,vi=18;function Jr(r,e,t){let n=se(r),o=n+se(e),i=new Uint8Array(o+t.byteLength);return ie(r,i,0),ie(e,i,n),i.set(t,o),i}var Li=Symbol.for("@ipld/js-cid/CID");var Et={...pt,...at,...dt,...it,...st,...ut,...ht,...ft,...lt,...ct},Ma={...wt,...bt};function vt(r=0){return new Uint8Array(r)}function Kr(r=0){return new Uint8Array(r)}function Xr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Wr=Xr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Lt=Xr("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=Kr(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Si={utf8:Wr,"utf-8":Wr,hex:Et.base16,latin1:Lt,ascii:Lt,binary:Lt,...Et},Te=Si;function Oe(r,e="utf8"){let t=Te[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function St(r,e="utf8"){let t=Te[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function Hr(r=0){return new Uint8Array(r)}var Ai=Math.pow(2,7),Ii=Math.pow(2,14),Ci=Math.pow(2,21),At=Math.pow(2,28),It=Math.pow(2,35),Ct=Math.pow(2,42),Dt=Math.pow(2,49),m=128,D=127;function V(r){if(r<Ai)return 1;if(r<Ii)return 2;if(r<Ci)return 3;if(r<At)return 4;if(r<It)return 5;if(r<Ct)return 6;if(r<Dt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Nt(r,e,t=0){switch(V(r)){case 8:e[t++]=r&255|m,r/=128;case 7:e[t++]=r&255|m,r/=128;case 6:e[t++]=r&255|m,r/=128;case 5:e[t++]=r&255|m,r/=128;case 4:e[t++]=r&255|m,r>>>=7;case 3:e[t++]=r&255|m,r>>>=7;case 2:e[t++]=r&255|m,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Di(r,e,t=0){switch(V(r)){case 8:e.set(t++,r&255|m),r/=128;case 7:e.set(t++,r&255|m),r/=128;case 6:e.set(t++,r&255|m),r/=128;case 5:e.set(t++,r&255|m),r/=128;case 4:e.set(t++,r&255|m),r>>>=7;case 3:e.set(t++,r&255|m),r>>>=7;case 2:e.set(t++,r&255|m),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Ut(r,e){let t=r[e],n=0;if(n+=t&D,t<m||(t=r[e+1],n+=(t&D)<<7,t<m)||(t=r[e+2],n+=(t&D)<<14,t<m)||(t=r[e+3],n+=(t&D)<<21,t<m)||(t=r[e+4],n+=(t&D)*At,t<m)||(t=r[e+5],n+=(t&D)*It,t<m)||(t=r[e+6],n+=(t&D)*Ct,t<m)||(t=r[e+7],n+=(t&D)*Dt,t<m))return n;throw new RangeError("Could not decode varint")}function Ni(r,e){let t=r.get(e),n=0;if(n+=t&D,t<m||(t=r.get(e+1),n+=(t&D)<<7,t<m)||(t=r.get(e+2),n+=(t&D)<<14,t<m)||(t=r.get(e+3),n+=(t&D)<<21,t<m)||(t=r.get(e+4),n+=(t&D)*At,t<m)||(t=r.get(e+5),n+=(t&D)*It,t<m)||(t=r.get(e+6),n+=(t&D)*Ct,t<m)||(t=r.get(e+7),n+=(t&D)*Dt,t<m))return n;throw new RangeError("Could not decode varint")}function Qr(r,e,t=0){return e==null&&(e=Hr(V(r))),e instanceof Uint8Array?Nt(r,e,t):Di(r,e,t)}function Yr(r,e=0){return r instanceof Uint8Array?Ut(r,e):Ni(r,e)}var Tt=new Float32Array([-0]),q=new Uint8Array(Tt.buffer);function Zr(r,e,t){Tt[0]=r,e[t]=q[0],e[t+1]=q[1],e[t+2]=q[2],e[t+3]=q[3]}function en(r,e){return q[0]=r[e],q[1]=r[e+1],q[2]=r[e+2],q[3]=r[e+3],Tt[0]}var Ot=new Float64Array([-0]),N=new Uint8Array(Ot.buffer);function tn(r,e,t){Ot[0]=r,e[t]=N[0],e[t+1]=N[1],e[t+2]=N[2],e[t+3]=N[3],e[t+4]=N[4],e[t+5]=N[5],e[t+6]=N[6],e[t+7]=N[7]}function rn(r,e){return N[0]=r[e],N[1]=r[e+1],N[2]=r[e+2],N[3]=r[e+3],N[4]=r[e+4],N[5]=r[e+5],N[6]=r[e+6],N[7]=r[e+7],Ot[0]}var Ti=BigInt(Number.MAX_SAFE_INTEGER),Oi=BigInt(Number.MIN_SAFE_INTEGER),T=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 J;if(e<Ti&&e>Oi)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>nn&&(o=0n,++n>nn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return J;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):J}},J=new T(0,0);J.toBigInt=function(){return 0n};J.zzEncode=J.zzDecode=function(){return this};J.length=function(){return 1};var nn=4294967296n;function on(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 sn(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ft(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function F(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Fe(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Mt=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,F(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 F(this,4);return Fe(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw F(this,4);return Fe(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw F(this,4);let e=en(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw F(this,4);let e=rn(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 F(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return sn(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw F(this,e);this.pos+=e}else do if(this.pos>=this.len)throw F(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 T(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 F(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 F(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 F(this,8);let e=Fe(this.buf,this.pos+=4),t=Fe(this.buf,this.pos+=4);return new T(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=Ut(this.buf,this.pos);return this.pos+=V(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 ye(r){return new Mt(r instanceof Uint8Array?r:r.subarray())}function Me(r,e,t){let n=ye(r);return e.decode(n,void 0,t)}function K(r=0){return new Uint8Array(r)}var Bt={};g(Bt,{base10:()=>Fi});var Fi=$({prefix:"9",name:"base10",alphabet:"0123456789"});var Rt={};g(Rt,{base16:()=>Mi,base16upper:()=>Bi});var Mi=E({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bi=E({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var kt={};g(kt,{base2:()=>Ri});var Ri=E({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pt={};g(Pt,{base256emoji:()=>$i});var cn=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}"),ki=cn.reduce((r,e,t)=>(r[t]=e,r),[]),Pi=cn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zi(r){return r.reduce((e,t)=>(e+=ki[t],e),"")}function Vi(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Pi[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var $i=Q({prefix:"\u{1F680}",name:"base256emoji",encode:zi,decode:Vi});var zt={};g(zt,{base64:()=>_i,base64pad:()=>qi,base64url:()=>ji,base64urlpad:()=>Gi});var _i=E({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qi=E({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ji=E({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gi=E({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Vt={};g(Vt,{base8:()=>Ji});var Ji=E({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};g($t,{identity:()=>Ki});var Ki=Q({prefix:"\0",name:"identity",encode:r=>hr(r),decode:r=>ur(r)});var uc=new TextEncoder,hc=new TextDecoder;var jt={};g(jt,{sha256:()=>Qi,sha512:()=>Yi});var Hi=20;function qt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new _t(r,e,t,n,o)}var _t=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Hi,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?un(n,this.code,t?.truncate):n.then(o=>un(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function un(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return re(e,r)}function fn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Qi=qt({name:"sha2-256",code:18,encode:fn("SHA-256")}),Yi=qt({name:"sha2-512",code:19,encode:fn("SHA-512")});var Gt={...$t,...kt,...Vt,...Bt,...Rt,...Xe,...He,...We,...zt,...Pt},vc={...jt,...Ze};function dn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ln=dn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Jt=dn("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=K(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Zi={utf8:ln,"utf-8":ln,hex:Gt.base16,latin1:Jt,ascii:Jt,binary:Jt,...Gt},pn=Zi;function mn(r,e="utf8"){let t=pn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Kt(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return K(s);o+s>e&&(n=K(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var W=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Wt(){}var Ht=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},es=Kt();function ts(r){return globalThis.Buffer!=null?K(r):es(r)}var ve=class{len;head;tail;states;constructor(){this.len=0,this.head=new W(Wt,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new W(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Qt((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(Be,10,T.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=T.fromBigInt(e);return this._push(Be,t.length(),t)}uint64Number(e){return this._push(Nt,V(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=T.fromBigInt(e).zzEncode();return this._push(Be,t.length(),t)}sint64Number(e){let t=T.fromNumber(e).zzEncode();return this._push(Be,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Xt,1,e?1:0)}fixed32(e){return this._push(Ee,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=T.fromBigInt(e);return this._push(Ee,4,t.lo)._push(Ee,4,t.hi)}fixed64Number(e){let t=T.fromNumber(e);return this._push(Ee,4,t.lo)._push(Ee,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(Zr,4,e)}double(e){return this._push(tn,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Xt,1,0):this.uint32(t)._push(ns,t,e)}string(e){let t=on(e);return t!==0?this.uint32(t)._push(Ft,t,e):this._push(Xt,1,0)}fork(){return this.states=new Ht(this),this.head=this.tail=new W(Wt,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 W(Wt,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=ts(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Xt(r,e,t){e[t]=r&255}function rs(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Qt=class extends W{next;constructor(e,t){super(rs,e,t),this.next=void 0}};function Be(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 Ee(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 ns(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ve.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(os,e,r),this},ve.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(is,e,r),this});function os(r,e,t){e.set(r,t)}function is(r,e,t){r.length<40?Ft(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(mn(r),t)}function Yt(){return new ve}function Re(r,e){let t=Yt();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*ke(r,e,t){let n=ye(r);yield*e.stream(n,void 0,"$",t)}var Pe={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ze(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function Zt(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return ze("enum",Pe.VARINT,t,n,o)}function Ve(r,e,t){return ze("message",Pe.LENGTH_DELIMITED,r,e,t)}var er=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},bn=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function tr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((l,d)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(s?.aborted){d(bn(s));return}if(s&&(c=()=>{d(bn(s))},s.addEventListener("abort",c,{once:!0})),r.then(l,d),t===Number.POSITIVE_INFINITY)return;let b=new er;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(f){d(f)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?d(o):(b.message=o??`Promise timed out after ${t} milliseconds`,d(b))},t)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var ss=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 as(r,e,t){let n,o=new Promise((i,s)=>{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:h,removeListener:u}=ss(r),l=async(...b)=>{let f=t.multiArgs?b:b[0];if(t.filter)try{if(!await t.filter(f))return}catch(p){n(),s(p);return}c.push(f),t.count===c.length&&(n(),i(c))},d=(...b)=>{n(),s(t.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)u(b,l);for(let b of t.rejectionEvents)a.includes(b)||u(b,d)};for(let b of a)h(b,l);for(let b of t.rejectionEvents)a.includes(b)||h(b,d);t.signal&&t.signal.addEventListener("abort",()=>{d(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=tr(o,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function xn(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=as(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var X=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function cs(r){return r.reason}async function rr(r,e,t){if(e==null)return r;let n=t?.translateError??cs;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var hs=4194304,$e=class extends Error{static name="UnwrappedError";name="UnwrappedError"},or=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ir=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},sr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function fs(r){return typeof r?.closeRead=="function"}function ls(r){return typeof r?.close=="function"}function nr(r){return fs(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ls(r)?r.status!=="open":!1}function ds(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function ps(r,e){let t=e?.maxBufferSize??hs,n=new j,o,i=!1;if(!ds(r))throw new H("Argument should be a Stream or a Multiaddr");let s=u=>{if(n.append(u.data),n.byteLength>t){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${t}`))}o?.resolve()};r.addEventListener("message",s);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let h={readBuffer:n,async read(u){if(i===!0)throw new $e("Stream was unwrapped");if(nr(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new X(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await rr(o.promise,u?.signal),nr(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let d=u?.bytes??n.byteLength;if(n.byteLength<d){if(nr(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new X(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return h.read(u)}let b=n.sublist(0,d);return n.consume(d),b},async write(u,l){if(i===!0)throw new $e("Stream was unwrapped");r.send(u)||await xn(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return h}function ms(r,e={}){let t=ps(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=V(e.maxDataLength));let n=e?.lengthDecoder??Yr,o=e?.lengthEncoder??Qr;return{async read(s){let a=-1,c=new j;for(;;){let u=await t.read({...s,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new or("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new sr(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ir(`Message length too long - ${a} > ${e.maxDataLength}`);let h=await t.read({...s,bytes:a});if(h==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new X(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(h.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new X(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(s,a){await t.write(new j(o(s.byteLength),s),a)},async writeV(s,a){let c=new j(...s.flatMap(h=>[o(h.byteLength),h]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function ar(r,e){let t=ms(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var gn="0.0.1",wn="fetch";var Le;(function(r){let e;r.codec=()=>(e==null&&(e=Ve((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.identifier!=null&&i.identifier.byteLength>0&&(s.uint32(10),s.bytes(i.identifier)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={identifier:vt(0)},h=s==null?i.len:i.pos+s;for(;i.pos<h;){let u=i.uint32();u>>>3===1?c.identifier=i.bytes():i.skipType(u&7)}return c},function*(i,s,a,c={}){let h=s==null?i.len:i.pos+s;for(;i.pos<h;){let u=i.uint32();u>>>3===1?yield{field:`${a}.identifier`,value:i.bytes()}:i.skipType(u&7)}})),e);function t(i){return Re(i,r.codec())}r.encode=t;function n(i,s){return Me(i,r.codec(),s)}r.decode=n;function o(i,s){return ke(i,r.codec(),s)}r.stream=o})(Le||(Le={}));var O;(function(r){let e;(function(a){a.OK="OK",a.NOT_FOUND="NOT_FOUND",a.ERROR="ERROR"})(e=r.StatusCode||(r.StatusCode={}));let t;(function(a){a[a.OK=0]="OK",a[a.NOT_FOUND=1]="NOT_FOUND",a[a.ERROR=2]="ERROR"})(t||(t={})),(function(a){a.codec=()=>Zt(t)})(e=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=Ve((a,c,h={})=>{h.lengthDelimited!==!1&&c.fork(),a.status!=null&&t[a.status]!==0&&(c.uint32(8),r.StatusCode.codec().encode(a.status,c)),a.data!=null&&a.data.byteLength>0&&(c.uint32(18),c.bytes(a.data)),h.lengthDelimited!==!1&&c.ldelim()},(a,c,h={})=>{let u={status:e.OK,data:vt(0)},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{u.status=r.StatusCode.codec().decode(a);break}case 2:{u.data=a.bytes();break}default:{a.skipType(d&7);break}}}return u},function*(a,c,h,u={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${h}.status`,value:r.StatusCode.codec().decode(a)};break}case 2:{yield{field:`${h}.data`,value:a.bytes()};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return Re(a,r.codec())}r.encode=o;function i(a,c){return Me(a,r.codec(),c)}r.decode=i;function s(a,c){return ke(a,r.codec(),c)}r.stream=s})(O||(O={}));var yn=1e4,_e=class{protocol;components;lookupFunctions;started;init;constructor(e,t={}){this.started=!1,this.components=e,this.protocol=`/${t.protocolPrefix??"libp2p"}/${wn}/${gn}`,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=Oe(t)),n.signal==null){let i=this.init.timeout??yn,s=AbortSignal.timeout(i);n={...n,signal:s}}let o;try{o=await(await this.components.connectionManager.openConnection(e,n)).newStream(this.protocol,n);let s=o.log.newScope("fetch");s.trace("fetch %m",t);let a=ar(o);await a.write({identifier:t},Le,n);let c=await a.read(O,n);switch(await o.close(n),c.status){case O.StatusCode.OK:return s.trace("received status OK for %m",t),c.data;case O.StatusCode.NOT_FOUND:{s("received status NOT_FOUND for %m",t);return}case O.StatusCode.ERROR:{s("received status ERROR for %m",t);let h=St(c.data);throw new Ae("Error in fetch protocol response: "+h)}default:throw s("received status unknown for %m",t),new Se("Unknown response status")}}catch(i){throw o?.abort(i),i}}async handleMessage(e){let t=e.log.newScope("fetch"),n=AbortSignal.timeout(this.init.timeout??yn),o=ar(e),i=await o.read(Le,{signal:n}),s,a=St(i.identifier),c=this._getLookupFunction(a);if(c==null){t.trace("sending status ERROR for %m",i.identifier);let h=Oe("No lookup function registered for key");s={status:O.StatusCode.ERROR,data:h}}else{t.trace("lookup data with identifier %s",c.prefix);try{let h=await c.fn(i.identifier);h==null?(t.trace("sending status NOT_FOUND for %m",i.identifier),s={status:O.StatusCode.NOT_FOUND,data:new Uint8Array(0)}):(t.trace("sending status OK for %m",i.identifier),s={status:O.StatusCode.OK,data:h})}catch(h){t.error("error during lookup of %m - %e",i.identifier,h);let u=Oe(h.message);s={status:O.StatusCode.ERROR,data:u}}}await o.write(s,O,{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 H(`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 bs(r={}){return e=>new _e(e,r)}return An(xs);})();
|
|
2
|
+
"use strict";var Libp2PFetch=(()=>{var Xe=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var Dn=Object.getOwnPropertyNames;var Un=Object.prototype.hasOwnProperty;var g=(r,e)=>{for(var t in e)Xe(r,t,{get:e[t],enumerable:!0})},Fn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Dn(e))!Un.call(r,o)&&o!==t&&Xe(r,o,{get:()=>e[o],enumerable:!(n=Cn(e,o))||n.enumerable});return r};var Tn=r=>Fn(Xe({},"__esModule",{value:!0}),r);var Ds={};g(Ds,{fetch:()=>Cs});var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Ne=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}},Ce=class extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}};var Qe={};g(Qe,{base58btc:()=>B,base58flickr:()=>Vn});var Ts=new Uint8Array(0);function ur(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 P(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return X(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return X(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function hr(r){return new TextEncoder().encode(r)}function lr(r){return new TextDecoder().decode(r)}function On(r){return r?.buffer instanceof ArrayBuffer}function X(r){return On(r)?r:r.slice()}function Mn(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var p=0,U=0,w=0,L=l.length;w!==L&&l[w]===0;)w++,p++;for(var S=(L-w)*u+1>>>0,x=new Uint8Array(S);w!==L;){for(var A=l[w],N=0,y=S-1;(A!==0||N<U)&&y!==-1;y--,N++)A+=256*x[y]>>>0,x[y]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");U=N,w++}for(var I=S-U;I!==S&&x[I]===0;)I++;for(var k=c.repeat(p);I<S;++I)k+=r.charAt(x[I]);return k}function d(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var p=0;if(l[p]!==" "){for(var U=0,w=0;l[p]===c;)U++,p++;for(var L=(l.length-p)*h+1>>>0,S=new Uint8Array(L);l[p];){var x=t[l.charCodeAt(p)];if(x===255)return;for(var A=0,N=L-1;(x!==0||A<w)&&N!==-1;N--,A++)x+=a*S[N]>>>0,S[N]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");w=A,p++}if(l[p]!==" "){for(var y=L-w;y!==L&&S[y]===0;)y++;for(var I=new Uint8Array(U+(L-y)),k=U;y!==L;)I[k++]=S[y++];return I}}}function b(l){var p=d(l);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:b}}var Bn=Mn,Rn=Bn,dr=Rn;var Je=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ke=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 pr(this,e)}},We=class{decoders;constructor(e){this.decoders=e}or(e){return pr(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 pr(r,e){return new We({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var He=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Je(e,t,n),this.decoder=new Ke(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Y({name:r,prefix:e,encode:t,decode:n}){return new He(r,e,t,n)}function _({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=dr(t,r);return Y({prefix:e,name:r,encode:n,decode:i=>P(o(i))})}function kn(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let h=0;h<o;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Pn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function zn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function E({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=zn(n);return Y({prefix:e,name:r,encode(i){return Pn(i,n,t)},decode(i){return kn(i,o,t,r)}})}var B=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vn=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ye={};g(Ye,{base32:()=>Z,base32hex:()=>jn,base32hexpad:()=>Xn,base32hexpadupper:()=>Jn,base32hexupper:()=>Gn,base32pad:()=>$n,base32padupper:()=>qn,base32upper:()=>_n,base32z:()=>Kn});var Z=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_n=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$n=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qn=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),jn=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gn=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xn=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jn=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kn=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ze={};g(Ze,{base36:()=>he,base36upper:()=>Wn});var he=_({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wn=_({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Hn=xr,mr=128,Qn=127,Yn=~Qn,Zn=Math.pow(2,31);function xr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Zn;)e[t++]=r&255|mr,r/=128;for(;r&Yn;)e[t++]=r&255|mr,r>>>=7;return e[t]=r|0,xr.bytes=t-n+1,e}var eo=et,to=128,br=127;function et(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw et.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&br)<<o:(s&br)*Math.pow(2,o),o+=7}while(s>=to);return et.bytes=i-n,t}var ro=Math.pow(2,7),no=Math.pow(2,14),oo=Math.pow(2,21),io=Math.pow(2,28),so=Math.pow(2,35),ao=Math.pow(2,42),co=Math.pow(2,49),uo=Math.pow(2,56),ho=Math.pow(2,63),lo=function(r){return r<ro?1:r<no?2:r<oo?3:r<io?4:r<so?5:r<ao?6:r<co?7:r<uo?8:r<ho?9:10},fo={encode:Hn,decode:eo,encodingLength:lo},po=fo,le=po;function fe(r,e=0){return[le.decode(r,e),le.decode.bytes]}function ee(r,e,t=0){return le.encode(r,e,t),e}function te(r){return le.encodingLength(r)}function ne(r,e){let t=e.byteLength,n=te(r),o=n+te(t),i=new Uint8Array(o+t);return ee(r,i,0),ee(t,i,n),i.set(e,o),new re(r,t,e,i)}function gr(r){let e=P(r),[t,n]=fe(e),[o,i]=fe(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new re(t,o,s,e)}function wr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ur(r.bytes,t.bytes)}}var re=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=X(n),this.bytes=X(o)}};function yr(r,e){let{bytes:t,version:n}=r;return n===0?bo(t,tt(r),e??B.encoder):xo(t,tt(r),e??Z.encoder)}var Er=new WeakMap;function tt(r){let e=Er.get(r);if(e==null){let t=new Map;return Er.set(r,t),t}return e}var Ue=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=X(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==go)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=ne(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&&wr(e.multihash,n.multihash)}toString(e){return yr(this,e)}toJSON(){return{"/":yr(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??vr(n,o,i.bytes))}else if(t[wo]===!0){let{version:n,multihash:o,code:i}=t,s=gr(o);return r.create(n,i,s)}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!==pe)throw new Error(`Version 0 CID must use dag-pb (code: ${pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=vr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pe,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,o=P(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new re(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,d]=fe(e.subarray(t));return t+=d,f},o=n(),i=pe;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),h=t+c,u=h-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(e,t){let[n,o]=mo(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return tt(i).set(n,e),i}};function mo(r,e){switch(r[0]){case"Q":{let t=e??B;return[B.prefix,t.decode(`${B.prefix}${r}`)]}case B.prefix:{let t=e??B;return[B.prefix,t.decode(r)]}case Z.prefix:{let t=e??Z;return[Z.prefix,t.decode(r)]}case he.prefix:{let t=e??he;return[he.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 bo(r,e,t){let{prefix:n}=t;if(n!==B.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function xo(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var pe=112,go=18;function vr(r,e,t){let n=te(r),o=n+te(e),i=new Uint8Array(o+t.byteLength);return ee(r,i,0),ee(e,i,n),i.set(t,o),i}var wo=Symbol.for("@ipld/js-cid/CID");var rt={};g(rt,{identity:()=>vo});var Lr=0,yo="identity",Sr=P;function Eo(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 ne(Lr,Sr(r))}var vo={code:Lr,name:yo,encode:Sr,digest:Eo};function z(r=0){return new Uint8Array(r)}function me(r=0){return new Uint8Array(r)}function nt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=me(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function Ar(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Nr=Symbol.for("@achingbrain/uint8arraylist");function Ir(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Fe(r){return!!r?.[Nr]}var J=class r{bufs;length;[Nr]=!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;for(let o of n.bufs)this.bufs.push(o)}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=Ir(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Ir(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:o}=this._subList(e,t);return nt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:nt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=n,i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let h=e>=a&&e<c,u=t>a&&t<=c;if(h&&u){if(e===a&&t===c){n.push(s);break}let f=e-a;n.push(s.subarray(f,f+(t-e)));break}if(h){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(u){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,h=n.byteLength-1,u;for(let f=t;f<=c;f+=u){u=0;for(let d=h;d>=0;d--){let b=this.get(f+d);if(n[d]!==b){u=Math.max(1,d-a[b]);break}}if(u===0)return f}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=me(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 o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,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 o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,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 o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,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=me(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 o=z(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,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 o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,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 o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,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 o=z(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,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 o=z(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,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(!Ar(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((o,i)=>o+i.byteLength,0)),n.length=t,n}};var ot={};g(ot,{base10:()=>Lo});var Lo=_({prefix:"9",name:"base10",alphabet:"0123456789"});var it={};g(it,{base16:()=>So,base16upper:()=>Ao});var So=E({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ao=E({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var st={};g(st,{base2:()=>Io});var Io=E({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var at={};g(at,{base256emoji:()=>Fo});var Cr=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}"),No=Cr.reduce((r,e,t)=>(r[t]=e,r),[]),Co=Cr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Do(r){return r.reduce((e,t)=>(e+=No[t],e),"")}function Uo(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Co[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Fo=Y({prefix:"\u{1F680}",name:"base256emoji",encode:Do,decode:Uo});var ct={};g(ct,{base64:()=>To,base64pad:()=>Oo,base64url:()=>Mo,base64urlpad:()=>Bo});var To=E({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oo=E({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mo=E({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bo=E({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ut={};g(ut,{base8:()=>Ro});var Ro=E({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ht={};g(ht,{identity:()=>ko});var ko=Y({prefix:"\0",name:"identity",encode:r=>lr(r),decode:r=>hr(r)});var ma=new TextEncoder,ba=new TextDecoder;var dt={};g(dt,{sha256:()=>_o,sha512:()=>$o});var Vo=20;function ft({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new lt(r,e,t,n,o)}var lt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Vo,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Dr(n,this.code,t?.truncate):n.then(o=>Dr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Dr(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 ne(e,r)}function Fr(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _o=ft({name:"sha2-256",code:18,encode:Fr("SHA-256")}),$o=ft({name:"sha2-512",code:19,encode:Fr("SHA-512")});var pt={...ht,...st,...ut,...ot,...it,...Ye,...Ze,...Qe,...ct,...at},Ca={...dt,...rt};function mt(r=0){return new Uint8Array(r)}function Tr(r=0){return new Uint8Array(r)}function Mr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Or=Mr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),bt=Mr("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=Tr(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),qo={utf8:Or,"utf-8":Or,hex:pt.base16,latin1:bt,ascii:bt,binary:bt,...pt},Te=qo;function Oe(r,e="utf8"){let t=Te[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function xt(r,e="utf8"){let t=Te[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function $(r=0){return new Uint8Array(r)}var jo=Math.pow(2,7),Go=Math.pow(2,14),Xo=Math.pow(2,21),Br=Math.pow(2,28),Rr=Math.pow(2,35),kr=Math.pow(2,42),Pr=Math.pow(2,49),F=128,q=127;function be(r){if(r<jo)return 1;if(r<Go)return 2;if(r<Xo)return 3;if(r<Br)return 4;if(r<Rr)return 5;if(r<kr)return 6;if(r<Pr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function zr(r,e,t=0){switch(be(r)){case 8:e[t++]=r&255|F,r/=128;case 7:e[t++]=r&255|F,r/=128;case 6:e[t++]=r&255|F,r/=128;case 5:e[t++]=r&255|F,r/=128;case 4:e[t++]=r&255|F,r>>>=7;case 3:e[t++]=r&255|F,r>>>=7;case 2:e[t++]=r&255|F,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Vr(r,e){let t=r[e],n=0;if(n+=t&q,t<F||(t=r[e+1],n+=(t&q)<<7,t<F)||(t=r[e+2],n+=(t&q)<<14,t<F)||(t=r[e+3],n+=(t&q)<<21,t<F)||(t=r[e+4],n+=(t&q)*Br,t<F)||(t=r[e+5],n+=(t&q)*Rr,t<F)||(t=r[e+6],n+=(t&q)*kr,t<F)||(t=r[e+7],n+=(t&q)*Pr,t<F))return n;throw new RangeError("Could not decode varint")}var gt=new Float32Array([-0]),j=new Uint8Array(gt.buffer);function _r(r,e,t){gt[0]=r,e[t]=j[0],e[t+1]=j[1],e[t+2]=j[2],e[t+3]=j[3]}function $r(r,e){return j[0]=r[e],j[1]=r[e+1],j[2]=r[e+2],j[3]=r[e+3],gt[0]}var wt=new Float64Array([-0]),C=new Uint8Array(wt.buffer);function qr(r,e,t){wt[0]=r,e[t]=C[0],e[t+1]=C[1],e[t+2]=C[2],e[t+3]=C[3],e[t+4]=C[4],e[t+5]=C[5],e[t+6]=C[6],e[t+7]=C[7]}function jr(r,e){return C[0]=r[e],C[1]=r[e+1],C[2]=r[e+2],C[3]=r[e+3],C[4]=r[e+4],C[5]=r[e+5],C[6]=r[e+6],C[7]=r[e+7],wt[0]}var Jo=BigInt(Number.MAX_SAFE_INTEGER),Ko=BigInt(Number.MIN_SAFE_INTEGER),T=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 K;if(e<Jo&&e>Ko)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Gr&&(o=0n,++n>Gr&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return K;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):K}},K=new T(0,0);K.toBigInt=function(){return 0n};K.zzEncode=K.zzDecode=function(){return this};K.length=function(){return 1};var Gr=4294967296n;function Xr(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 Jr(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function yt(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function M(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Me(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Et=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,M(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 M(this,4);return Me(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw M(this,4);return Me(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw M(this,4);let e=$r(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw M(this,4);let e=jr(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 M(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Jr(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw M(this,e);this.pos+=e}else do if(this.pos>=this.len)throw M(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 T(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 M(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 M(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 M(this,8);let e=Me(this.buf,this.pos+=4),t=Me(this.buf,this.pos+=4);return new T(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=Vr(this.buf,this.pos);return this.pos+=be(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 xe(r){return new Et(r instanceof Uint8Array?r:r.subarray())}function Be(r,e,t){let n=xe(r);return e.decode(n,void 0,t)}var It={};g(It,{base10:()=>ti});var Wa=new Uint8Array(0);function Wr(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 V(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 Hr(r){return new TextEncoder().encode(r)}function Qr(r){return new TextDecoder().decode(r)}function Wo(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var p=0,U=0,w=0,L=l.length;w!==L&&l[w]===0;)w++,p++;for(var S=(L-w)*u+1>>>0,x=new Uint8Array(S);w!==L;){for(var A=l[w],N=0,y=S-1;(A!==0||N<U)&&y!==-1;y--,N++)A+=256*x[y]>>>0,x[y]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");U=N,w++}for(var I=S-U;I!==S&&x[I]===0;)I++;for(var k=c.repeat(p);I<S;++I)k+=r.charAt(x[I]);return k}function d(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var p=0;if(l[p]!==" "){for(var U=0,w=0;l[p]===c;)U++,p++;for(var L=(l.length-p)*h+1>>>0,S=new Uint8Array(L);l[p];){var x=t[l.charCodeAt(p)];if(x===255)return;for(var A=0,N=L-1;(x!==0||A<w)&&N!==-1;N--,A++)x+=a*S[N]>>>0,S[N]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");w=A,p++}if(l[p]!==" "){for(var y=L-w;y!==L&&S[y]===0;)y++;for(var I=new Uint8Array(U+(L-y)),k=U;y!==L;)I[k++]=S[y++];return I}}}function b(l){var p=d(l);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:b}}var Ho=Wo,Qo=Ho,Zr=Qo;var vt=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")}},Lt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 en(this,e)}},St=class{decoders;constructor(e){this.decoders=e}or(e){return en(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 en(r,e){return new St({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var At=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new vt(e,t,n),this.decoder=new Lt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function oe({name:r,prefix:e,encode:t,decode:n}){return new At(r,e,t,n)}function G({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Zr(t,r);return oe({prefix:e,name:r,encode:n,decode:i=>V(o(i))})}function Yo(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let h=0;h<o;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Zo(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function ei(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=ei(n);return oe({prefix:e,name:r,encode(i){return Zo(i,n,t)},decode(i){return Yo(i,o,t,r)}})}var ti=G({prefix:"9",name:"base10",alphabet:"0123456789"});var Nt={};g(Nt,{base16:()=>ri,base16upper:()=>ni});var ri=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ni=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ct={};g(Ct,{base2:()=>oi});var oi=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Dt={};g(Dt,{base256emoji:()=>ui});var tn=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}"),ii=tn.reduce((r,e,t)=>(r[t]=e,r),[]),si=tn.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ai(r){return r.reduce((e,t)=>(e+=ii[t],e),"")}function ci(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=si[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var ui=oe({prefix:"\u{1F680}",name:"base256emoji",encode:ai,decode:ci});var Ut={};g(Ut,{base32:()=>ie,base32hex:()=>di,base32hexpad:()=>mi,base32hexpadupper:()=>bi,base32hexupper:()=>pi,base32pad:()=>li,base32padupper:()=>fi,base32upper:()=>hi,base32z:()=>xi});var ie=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hi=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),li=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),fi=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),di=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pi=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mi=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),bi=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xi=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ft={};g(Ft,{base36:()=>ge,base36upper:()=>gi});var ge=G({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gi=G({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Tt={};g(Tt,{base58btc:()=>R,base58flickr:()=>wi});var R=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),wi=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ot={};g(Ot,{base64:()=>yi,base64pad:()=>Ei,base64url:()=>vi,base64urlpad:()=>Li});var yi=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ei=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vi=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Li=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mt={};g(Mt,{base8:()=>Si});var Si=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Bt={};g(Bt,{identity:()=>Ai});var Ai=oe({prefix:"\0",name:"identity",encode:r=>Qr(r),decode:r=>Hr(r)});var lc=new TextEncoder,fc=new TextDecoder;var kt={};g(kt,{identity:()=>Ki});var Ci=on,rn=128,Di=127,Ui=~Di,Fi=Math.pow(2,31);function on(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Fi;)e[t++]=r&255|rn,r/=128;for(;r&Ui;)e[t++]=r&255|rn,r>>>=7;return e[t]=r|0,on.bytes=t-n+1,e}var Ti=Rt,Oi=128,nn=127;function Rt(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Rt.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&nn)<<o:(s&nn)*Math.pow(2,o),o+=7}while(s>=Oi);return Rt.bytes=i-n,t}var Mi=Math.pow(2,7),Bi=Math.pow(2,14),Ri=Math.pow(2,21),ki=Math.pow(2,28),Pi=Math.pow(2,35),zi=Math.pow(2,42),Vi=Math.pow(2,49),_i=Math.pow(2,56),$i=Math.pow(2,63),qi=function(r){return r<Mi?1:r<Bi?2:r<Ri?3:r<ki?4:r<Pi?5:r<zi?6:r<Vi?7:r<_i?8:r<$i?9:10},ji={encode:Ci,decode:Ti,encodingLength:qi},Gi=ji,we=Gi;function ye(r,e=0){return[we.decode(r,e),we.decode.bytes]}function se(r,e,t=0){return we.encode(r,e,t),e}function ae(r){return we.encodingLength(r)}function ue(r,e){let t=e.byteLength,n=ae(r),o=n+ae(t),i=new Uint8Array(o+t);return se(r,i,0),se(t,i,n),i.set(e,o),new ce(r,t,e,i)}function sn(r){let e=V(r),[t,n]=ye(e),[o,i]=ye(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ce(t,o,s,e)}function an(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Wr(r.bytes,t.bytes)}}var ce=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var cn=0,Xi="identity",un=V;function Ji(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 ue(cn,un(r))}var Ki={code:cn,name:Xi,encode:un,digest:Ji};var Vt={};g(Vt,{sha256:()=>Hi,sha512:()=>Qi});var Wi=20;function zt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Pt(r,e,t,n,o)}var Pt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Wi,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?hn(n,this.code,t?.truncate):n.then(o=>hn(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function hn(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 ue(e,r)}function fn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Hi=zt({name:"sha2-256",code:18,encode:fn("SHA-256")}),Qi=zt({name:"sha2-512",code:19,encode:fn("SHA-512")});function dn(r,e){let{bytes:t,version:n}=r;return n===0?Zi(t,_t(r),e??R.encoder):es(t,_t(r),e??ie.encoder)}var pn=new WeakMap;function _t(r){let e=pn.get(r);if(e==null){let t=new Map;return pn.set(r,t),t}return e}var ke=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ts)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=ue(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&&an(e.multihash,n.multihash)}toString(e){return dn(this,e)}toJSON(){return{"/":dn(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??mn(n,o,i.bytes))}else if(t[rs]===!0){let{version:n,multihash:o,code:i}=t,s=sn(o);return r.create(n,i,s)}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!==ve)throw new Error(`Version 0 CID must use dag-pb (code: ${ve}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=mn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ve,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,o=V(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new ce(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,d]=ye(e.subarray(t));return t+=d,f},o=n(),i=ve;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),h=t+c,u=h-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(e,t){let[n,o]=Yi(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return _t(i).set(n,e),i}};function Yi(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}case ge.prefix:{let t=e??ge;return[ge.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 Zi(r,e,t){let{prefix:n}=t;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function es(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var ve=112,ts=18;function mn(r,e,t){let n=ae(r),o=n+ae(e),i=new Uint8Array(o+t.byteLength);return se(r,i,0),se(e,i,n),i.set(t,o),i}var rs=Symbol.for("@ipld/js-cid/CID");var $t={...Bt,...Ct,...Mt,...It,...Nt,...Ut,...Ft,...Tt,...Ot,...Dt},Mc={...Vt,...kt};function xn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var bn=xn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qt=xn("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=$(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ns={utf8:bn,"utf-8":bn,hex:$t.base16,latin1:qt,ascii:qt,binary:qt,...$t},gn=ns;function wn(r,e="utf8"){let t=gn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function jt(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return $(s);o+s>e&&(n=$(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var W=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Gt(){}var Jt=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},os=jt();function is(r){return globalThis.Buffer!=null?$(r):os(r)}var Se=class{len;head;tail;states;constructor(){this.len=0,this.head=new W(Gt,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new W(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Kt((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(Pe,10,T.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=T.fromBigInt(e);return this._push(Pe,t.length(),t)}uint64Number(e){return this._push(zr,be(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=T.fromBigInt(e).zzEncode();return this._push(Pe,t.length(),t)}sint64Number(e){let t=T.fromNumber(e).zzEncode();return this._push(Pe,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Xt,1,e?1:0)}fixed32(e){return this._push(Le,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=T.fromBigInt(e);return this._push(Le,4,t.lo)._push(Le,4,t.hi)}fixed64Number(e){let t=T.fromNumber(e);return this._push(Le,4,t.lo)._push(Le,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(_r,4,e)}double(e){return this._push(qr,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Xt,1,0):this.uint32(t)._push(as,t,e)}string(e){let t=Xr(e);return t!==0?this.uint32(t)._push(yt,t,e):this._push(Xt,1,0)}fork(){return this.states=new Jt(this),this.head=this.tail=new W(Gt,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 W(Gt,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=is(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Xt(r,e,t){e[t]=r&255}function ss(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Kt=class extends W{next;constructor(e,t){super(ss,e,t),this.next=void 0}};function Pe(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 Le(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 as(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(cs,e,r),this},Se.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(us,e,r),this});function cs(r,e,t){e.set(r,t)}function us(r,e,t){r.length<40?yt(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(wn(r),t)}function Wt(){return new Se}function ze(r,e){let t=Wt();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*Ve(r,e,t){let n=xe(r);yield*e.stream(n,void 0,"$",t)}var _e={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function $e(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function Ht(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return $e("enum",_e.VARINT,t,n,o)}function qe(r,e,t){return $e("message",_e.LENGTH_DELIMITED,r,e,t)}var Qt=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},yn=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Yt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((f,d)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(s?.aborted){d(yn(s));return}if(s&&(c=()=>{d(yn(s))},s.addEventListener("abort",c,{once:!0})),r.then(f,d),t===Number.POSITIVE_INFINITY)return;let b=new Qt;a=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(l){d(l)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?d(o):(b.message=o??`Promise timed out after ${t} milliseconds`,d(b))},t)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var hs=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 ls(r,e,t){let n,o=new Promise((i,s)=>{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:h,removeListener:u}=hs(r),f=async(...b)=>{let l=t.multiArgs?b:b[0];if(t.filter)try{if(!await t.filter(l))return}catch(p){n(),s(p);return}c.push(l),t.count===c.length&&(n(),i(c))},d=(...b)=>{n(),s(t.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)u(b,f);for(let b of t.rejectionEvents)a.includes(b)||u(b,d)};for(let b of a)h(b,f);for(let b of t.rejectionEvents)a.includes(b)||h(b,d);t.signal&&t.signal.addEventListener("abort",()=>{d(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=Yt(o,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function En(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=ls(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var H=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function fs(r){return r.reason}async function Zt(r,e,t){if(e==null)return r;let n=t?.translateError??fs;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}function vn(r=0){return new Uint8Array(r)}var ds=Math.pow(2,7),ps=Math.pow(2,14),ms=Math.pow(2,21),er=Math.pow(2,28),tr=Math.pow(2,35),rr=Math.pow(2,42),nr=Math.pow(2,49),m=128,D=127;function Ae(r){if(r<ds)return 1;if(r<ps)return 2;if(r<ms)return 3;if(r<er)return 4;if(r<tr)return 5;if(r<rr)return 6;if(r<nr)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function bs(r,e,t=0){switch(Ae(r)){case 8:e[t++]=r&255|m,r/=128;case 7:e[t++]=r&255|m,r/=128;case 6:e[t++]=r&255|m,r/=128;case 5:e[t++]=r&255|m,r/=128;case 4:e[t++]=r&255|m,r>>>=7;case 3:e[t++]=r&255|m,r>>>=7;case 2:e[t++]=r&255|m,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function xs(r,e,t=0){switch(Ae(r)){case 8:e.set(t++,r&255|m),r/=128;case 7:e.set(t++,r&255|m),r/=128;case 6:e.set(t++,r&255|m),r/=128;case 5:e.set(t++,r&255|m),r/=128;case 4:e.set(t++,r&255|m),r>>>=7;case 3:e.set(t++,r&255|m),r>>>=7;case 2:e.set(t++,r&255|m),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function gs(r,e){let t=r[e],n=0;if(n+=t&D,t<m||(t=r[e+1],n+=(t&D)<<7,t<m)||(t=r[e+2],n+=(t&D)<<14,t<m)||(t=r[e+3],n+=(t&D)<<21,t<m)||(t=r[e+4],n+=(t&D)*er,t<m)||(t=r[e+5],n+=(t&D)*tr,t<m)||(t=r[e+6],n+=(t&D)*rr,t<m)||(t=r[e+7],n+=(t&D)*nr,t<m))return n;throw new RangeError("Could not decode varint")}function ws(r,e){let t=r.get(e),n=0;if(n+=t&D,t<m||(t=r.get(e+1),n+=(t&D)<<7,t<m)||(t=r.get(e+2),n+=(t&D)<<14,t<m)||(t=r.get(e+3),n+=(t&D)<<21,t<m)||(t=r.get(e+4),n+=(t&D)*er,t<m)||(t=r.get(e+5),n+=(t&D)*tr,t<m)||(t=r.get(e+6),n+=(t&D)*rr,t<m)||(t=r.get(e+7),n+=(t&D)*nr,t<m))return n;throw new RangeError("Could not decode varint")}function Ln(r,e,t=0){return e==null&&(e=vn(Ae(r))),e instanceof Uint8Array?bs(r,e,t):xs(r,e,t)}function Sn(r,e=0){return r instanceof Uint8Array?gs(r,e):ws(r,e)}var vs=4194304,je=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ir=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},sr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ar=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ls(r){return typeof r?.closeRead=="function"}function Ss(r){return typeof r?.close=="function"}function or(r){return Ls(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:Ss(r)?r.status!=="open":!1}function As(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Is(r,e){let t=e?.maxBufferSize??vs,n=new J,o,i=!1;if(!As(r))throw new Q("Argument should be a Stream or a Multiaddr");let s=u=>{if(n.append(u.data),n.byteLength>t){let f=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${f} > ${t}`))}o?.resolve()};r.addEventListener("message",s);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let h={readBuffer:n,async read(u){if(i===!0)throw new je("Stream was unwrapped");if(or(r)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new H(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let f=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=f){o.resolve();break}if(await Zt(o.promise,u?.signal),or(r)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let d=u?.bytes??n.byteLength;if(n.byteLength<d){if(or(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,d),new H(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return h.read(u)}let b=n.sublist(0,d);return n.consume(d),b},async write(u,f){if(i===!0)throw new je("Stream was unwrapped");r.send(u)||await En(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.unshift(n))),r}};return h}function Ns(r,e={}){let t=Is(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ae(e.maxDataLength));let n=e?.lengthDecoder??Sn,o=e?.lengthEncoder??Ln;return{async read(s){let a=-1,c=new J;for(;;){let u=await t.read({...s,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new ir("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ar(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new sr(`Message length too long - ${a} > ${e.maxDataLength}`);let h=await t.read({...s,bytes:a});if(h==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new H(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(h.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new H(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(s,a){await t.write(new J(o(s.byteLength),s),a)},async writeV(s,a){let c=new J(...s.flatMap(h=>[o(h.byteLength),h]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function cr(r,e){let t=Ns(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var An="0.0.1",In="fetch";var Ie;(function(r){let e;r.codec=()=>(e==null&&(e=qe((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.identifier!=null&&i.identifier.byteLength>0&&(s.uint32(10),s.bytes(i.identifier)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={identifier:mt(0)},h=s==null?i.len:i.pos+s;for(;i.pos<h;){let u=i.uint32();u>>>3===1?c.identifier=i.bytes():i.skipType(u&7)}return c},function*(i,s,a,c={}){let h=s==null?i.len:i.pos+s;for(;i.pos<h;){let u=i.uint32();u>>>3===1?yield{field:`${a}.identifier`,value:i.bytes()}:i.skipType(u&7)}})),e);function t(i){return ze(i,r.codec())}r.encode=t;function n(i,s){return Be(i,r.codec(),s)}r.decode=n;function o(i,s){return Ve(i,r.codec(),s)}r.stream=o})(Ie||(Ie={}));var O;(function(r){let e;(function(a){a.OK="OK",a.NOT_FOUND="NOT_FOUND",a.ERROR="ERROR"})(e=r.StatusCode||(r.StatusCode={}));let t;(function(a){a[a.OK=0]="OK",a[a.NOT_FOUND=1]="NOT_FOUND",a[a.ERROR=2]="ERROR"})(t||(t={})),(function(a){a.codec=()=>Ht(t)})(e=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=qe((a,c,h={})=>{h.lengthDelimited!==!1&&c.fork(),a.status!=null&&t[a.status]!==0&&(c.uint32(8),r.StatusCode.codec().encode(a.status,c)),a.data!=null&&a.data.byteLength>0&&(c.uint32(18),c.bytes(a.data)),h.lengthDelimited!==!1&&c.ldelim()},(a,c,h={})=>{let u={status:e.OK,data:mt(0)},f=c==null?a.len:a.pos+c;for(;a.pos<f;){let d=a.uint32();switch(d>>>3){case 1:{u.status=r.StatusCode.codec().decode(a);break}case 2:{u.data=a.bytes();break}default:{a.skipType(d&7);break}}}return u},function*(a,c,h,u={}){let f=c==null?a.len:a.pos+c;for(;a.pos<f;){let d=a.uint32();switch(d>>>3){case 1:{yield{field:`${h}.status`,value:r.StatusCode.codec().decode(a)};break}case 2:{yield{field:`${h}.data`,value:a.bytes()};break}default:{a.skipType(d&7);break}}}})),n);function o(a){return ze(a,r.codec())}r.encode=o;function i(a,c){return Be(a,r.codec(),c)}r.decode=i;function s(a,c){return Ve(a,r.codec(),c)}r.stream=s})(O||(O={}));var Nn=1e4,Ge=class{protocol;components;lookupFunctions;started;init;constructor(e,t={}){this.started=!1,this.components=e,this.protocol=`/${t.protocolPrefix??"libp2p"}/${In}/${An}`,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=Oe(t)),n.signal==null){let i=this.init.timeout??Nn,s=AbortSignal.timeout(i);n={...n,signal:s}}let o;try{o=await(await this.components.connectionManager.openConnection(e,n)).newStream(this.protocol,n);let s=o.log.newScope("fetch");s.trace("fetch %m",t);let a=cr(o);await a.write({identifier:t},Ie,n);let c=await a.read(O,n);switch(await o.close(n),c.status){case O.StatusCode.OK:return s.trace("received status OK for %m",t),c.data;case O.StatusCode.NOT_FOUND:{s("received status NOT_FOUND for %m",t);return}case O.StatusCode.ERROR:{s("received status ERROR for %m",t);let h=xt(c.data);throw new Ce("Error in fetch protocol response: "+h)}default:throw s("received status unknown for %m",t),new Ne("Unknown response status")}}catch(i){throw o?.abort(i),i}}async handleMessage(e){let t=e.log.newScope("fetch"),n=AbortSignal.timeout(this.init.timeout??Nn),o=cr(e),i=await o.read(Ie,{signal:n}),s,a=xt(i.identifier),c=this._getLookupFunction(a);if(c==null){t.trace("sending status ERROR for %m",i.identifier);let h=Oe("No lookup function registered for key");s={status:O.StatusCode.ERROR,data:h}}else{t.trace("lookup data with identifier %s",c.prefix);try{let h=await c.fn(i.identifier);h==null?(t.trace("sending status NOT_FOUND for %m",i.identifier),s={status:O.StatusCode.NOT_FOUND,data:new Uint8Array(0)}):(t.trace("sending status OK for %m",i.identifier),s={status:O.StatusCode.OK,data:h})}catch(h){t.error("error during lookup of %m - %e",i.identifier,h);let u=Oe(h.message);s={status:O.StatusCode.ERROR,data:u}}}await o.write(s,O,{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 Q(`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 Cs(r={}){return e=>new Ge(e,r)}return Tn(Ds);})();
|
|
3
3
|
return Libp2PFetch}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|