@libp2p/fetch 1.0.8-8bbd43628 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
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 xr=Object.create;var ft=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var Er=Object.getOwnPropertyNames;var Lr=Object.getPrototypeOf,Ar=Object.prototype.hasOwnProperty;var Sr=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),E=(r,t)=>{for(var e in t)ft(r,e,{get:t[e],enumerable:!0})},Ee=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Er(t))!Ar.call(r,i)&&i!==e&&ft(r,i,{get:()=>t[i],enumerable:!(n=yr(t,i))||n.enumerable});return r};var Nr=(r,t,e)=>(e=r!=null?xr(Lr(r)):{},Ee(t||!r||!r.__esModule?ft(e,"default",{value:r,enumerable:!0}):e,r)),Rr=r=>Ee(ft({},"__esModule",{value:!0}),r);var Me=Sr((Ao,Ce)=>{"use strict";function ve(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function _r(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return ve(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),ve(new i,e)}}Ce.exports=_r});var ri={};E(ri,{fetch:()=>ei});var ii=Symbol.for("@libp2p/connection");var si=Symbol.for("@libp2p/content-routing");var hi=Symbol.for("@libp2p/peer-discovery");var fi=Symbol.for("@libp2p/peer-id");var di=Symbol.for("@libp2p/peer-routing");var Le;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Le||(Le={}));var bi=Symbol.for("@libp2p/transport");var Ae;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ae||(Ae={}));var z=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Se="ERR_TIMEOUT",Ne="ERR_INVALID_PARAMETERS";var Re="ERR_INVALID_MESSAGE";var It=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},yi=globalThis.CustomEvent??It;var De=(r,...t)=>{try{[...t]}catch{}};function M(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function B(r=0){return globalThis.Buffer?.alloc!=null?M(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function m(r=0){return globalThis.Buffer?.allocUnsafe!=null?M(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Tt(r,t){if(globalThis.Buffer!=null)return M(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=m(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return M(e)}function Ue(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Te=Symbol.for("@achingbrain/uint8arraylist");function Ie(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function lt(r){return!!r?.[Te]}var A=class r{bufs;length;[Te]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(lt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(lt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ie(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ie(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(lt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:i}=this._subList(t,e);return Tt(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:Tt(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),o=new r;return o.length=i,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,t>=c)continue;let h=t>=a&&t<c,l=e>a&&e<=c;if(h&&l){if(t===a&&e===c){n.push(s);break}let f=t-a;n.push(s.subarray(f,f+(e-t)));break}if(h){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(l){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!lt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let f=0;f<o;f++)s[f]=-1;for(let f=0;f<i;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,h=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let w=h;w>=0;w--){let ht=this.get(f+w);if(n[w]!==ht){l=Math.max(1,w-a[ht]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=m(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let i=B(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let i=B(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let i=B(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=m(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let i=B(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let i=B(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let i=B(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let i=B(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let i=B(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Ue(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,o)=>i+o.byteLength,0)),n.length=e,n}};function H(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var dt=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function Oe(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new dt(e?.errorMessage,e?.errorCode));let n,i=new dt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ot=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=H(),this.haveNext=H()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=H(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=H(),await Oe(this.needNext.promise,e?.signal,e)}};function Fe(){return new Ot}var pt=class extends Error{code;constructor(t,e){super(t),this.code=e}},Ft=class extends pt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Be(r,t){let e=Fe();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let i=new A;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,h=new Promise((l,f)=>{c=()=>{f(new Ft("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:f,value:w}=await Promise.race([n.next(),h]);return f===!0?new A:w}for(;i.byteLength<s;){let{value:f,done:w}=await Promise.race([n.next(),h]);if(w===!0)throw new pt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(f)}let l=i.sublist(0,s);return i.consume(s),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(i.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield i:yield*i,yield*s}()}return r}}}var Dr=Math.pow(2,7),Ur=Math.pow(2,14),Ir=Math.pow(2,21),Bt=Math.pow(2,28),_t=Math.pow(2,35),vt=Math.pow(2,42),Ct=Math.pow(2,49),u=128,g=127;function _(r){if(r<Dr)return 1;if(r<Ur)return 2;if(r<Ir)return 3;if(r<Bt)return 4;if(r<_t)return 5;if(r<vt)return 6;if(r<Ct)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Tr(r,t,e=0){switch(_(r)){case 8:t[e++]=r&255|u,r/=128;case 7:t[e++]=r&255|u,r/=128;case 6:t[e++]=r&255|u,r/=128;case 5:t[e++]=r&255|u,r/=128;case 4:t[e++]=r&255|u,r>>>=7;case 3:t[e++]=r&255|u,r>>>=7;case 2:t[e++]=r&255|u,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Or(r,t,e=0){switch(_(r)){case 8:t.set(e++,r&255|u),r/=128;case 7:t.set(e++,r&255|u),r/=128;case 6:t.set(e++,r&255|u),r/=128;case 5:t.set(e++,r&255|u),r/=128;case 4:t.set(e++,r&255|u),r>>>=7;case 3:t.set(e++,r&255|u),r>>>=7;case 2:t.set(e++,r&255|u),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Fr(r,t){let e=r[t],n=0;if(n+=e&g,e<u||(e=r[t+1],n+=(e&g)<<7,e<u)||(e=r[t+2],n+=(e&g)<<14,e<u)||(e=r[t+3],n+=(e&g)<<21,e<u)||(e=r[t+4],n+=(e&g)*Bt,e<u)||(e=r[t+5],n+=(e&g)*_t,e<u)||(e=r[t+6],n+=(e&g)*vt,e<u)||(e=r[t+7],n+=(e&g)*Ct,e<u))return n;throw new RangeError("Could not decode varint")}function Br(r,t){let e=r.get(t),n=0;if(n+=e&g,e<u||(e=r.get(t+1),n+=(e&g)<<7,e<u)||(e=r.get(t+2),n+=(e&g)<<14,e<u)||(e=r.get(t+3),n+=(e&g)<<21,e<u)||(e=r.get(t+4),n+=(e&g)*Bt,e<u)||(e=r.get(t+5),n+=(e&g)*_t,e<u)||(e=r.get(t+6),n+=(e&g)*vt,e<u)||(e=r.get(t+7),n+=(e&g)*Ct,e<u))return n;throw new RangeError("Could not decode varint")}function _e(r,t,e=0){return t==null&&(t=m(_(r))),t instanceof Uint8Array?Tr(r,t,e):Or(r,t,e)}function mt(r,t=0){return r instanceof Uint8Array?Fr(r,t):Br(r,t)}function gt(r){return r[Symbol.asyncIterator]!=null}var bt=r=>{let t=_(r),e=m(t);return _e(r,e),bt.bytes=t,e};bt.bytes=0;function tt(r,t){t=t??{};let e=t.lengthEncoder??bt;function*n(i){let o=e(i.byteLength);o instanceof Uint8Array?yield o:yield*o,i instanceof Uint8Array?yield i:yield*i}return gt(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}tt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??bt;return new A(e(r.byteLength),r)};var q=Nr(Me(),1);var vr=8,Cr=1024*1024*4,G;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(G||(G={}));var Vt=r=>{let t=mt(r);return Vt.bytes=_(t),t};Vt.bytes=0;function kt(r,t){let e=new A,n=G.LENGTH,i=-1,o=t?.lengthDecoder??Vt,s=t?.maxLengthLength??vr,a=t?.maxDataLength??Cr;function*c(){for(;e.byteLength>0;){if(n===G.LENGTH)try{if(i=o(e),i<0)throw(0,q.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,q.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let h=o.bytes;e.consume(h),t?.onLength!=null&&t.onLength(i),n=G.DATA}catch(h){if(h instanceof RangeError){if(e.byteLength>s)throw(0,q.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw h}if(n===G.DATA){if(e.byteLength<i)break;let h=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(h),yield h,n=G.LENGTH}}}return gt(r)?async function*(){for await(let h of r)e.append(h),yield*c();if(e.byteLength>0)throw(0,q.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let h of r)e.append(h),yield*c();if(e.byteLength>0)throw(0,q.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}kt.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:s}=await r.next(e);if(o===!0)return;s!=null&&(yield s)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return kt(n,{...t??{},onLength:o=>{e=o}})};var wt=class extends Error{code;constructor(t,e){super(t),this.code=e}},ke=r=>mt(r);ke.bytes=0;function Ve(r,t={}){let e=Be(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=_(t.maxDataLength)),{read:async i=>{let o=-1,s=new A,a=t?.lengthDecoder??ke;for(;;){s.append(await e.read(1,i));try{o=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new wt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(o>-1)break}if(t?.maxDataLength!=null&&o>t.maxDataLength)throw new wt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(o,i)},write:async(i,o)=>{await e.write(tt.single(i,t),o)},writeV:async(i,o)=>{let s=new A(...i.map(a=>tt.single(a,t)));await e.write(s,o)},unwrap:()=>e.unwrap()}}function Pt(r,t){let e=Ve(r,t),n={read:async(i,o)=>{let s=await e.read(o);return i.decode(s)},write:async(i,o,s)=>{await e.write(o.encode(i),s)},writeV:async(i,o,s)=>{await e.writeV(i.map(a=>o.encode(a)),s)},pb:i=>({read:async o=>n.read(i,o),write:async(o,s)=>n.write(o,i,s),writeV:async(o,s)=>n.writeV(o,i,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var jt={};E(jt,{base10:()=>$r});var _o=new Uint8Array(0);function Pe(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function 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 ze(r){return new TextEncoder().encode(r)}function Ge(r){return new TextDecoder().decode(r)}function kr(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var x=0,P=0,S=0,U=d.length;S!==U&&d[S]===0;)S++,x++;for(var I=(U-S)*l+1>>>0,L=new Uint8Array(I);S!==U;){for(var T=d[S],C=0,N=I-1;(T!==0||C<P)&&N!==-1;N--,C++)T+=256*L[N]>>>0,L[N]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");P=C,S++}for(var F=I-P;F!==I&&L[F]===0;)F++;for(var ut=c.repeat(x);F<I;++F)ut+=r.charAt(L[F]);return ut}function w(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var x=0;if(d[x]!==" "){for(var P=0,S=0;d[x]===c;)P++,x++;for(var U=(d.length-x)*h+1>>>0,I=new Uint8Array(U);d[x];){var L=e[d.charCodeAt(x)];if(L===255)return;for(var T=0,C=U-1;(L!==0||T<S)&&C!==-1;C--,T++)L+=a*I[C]>>>0,I[C]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");S=T,x++}if(d[x]!==" "){for(var N=U-S;N!==U&&I[N]===0;)N++;for(var F=new Uint8Array(P+(U-N)),ut=P;N!==U;)F[ut++]=I[N++];return F}}}function ht(d){var x=w(d);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:w,decode:ht}}var Vr=kr,Pr=Vr,Xe=Pr;var zt=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Gt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return je(this,t)}},$t=class{decoders;constructor(t){this.decoders=t}or(t){return je(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function je(r,t){return new $t({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Xt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new zt(t,e,n),this.decoder=new Gt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function K({name:r,prefix:t,encode:e,decode:n}){return new Xt(r,t,e,n)}function k({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=Xe(e,r);return K({prefix:t,name:r,encode:n,decode:o=>v(i(o))})}function zr(r,t,e,n){let i={};for(let l=0;l<t.length;++l)i[t[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,c=0,h=0;for(let l=0;l<o;++l){let f=i[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,s[h++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Gr(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,o+=t[i&a>>s];if(s!==0&&(o+=t[i&a<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function p({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return K({prefix:t,name:r,encode(i){return Gr(i,n,e)},decode(i){return zr(i,n,e,r)}})}var $r=k({prefix:"9",name:"base10",alphabet:"0123456789"});var Ht={};E(Ht,{base16:()=>Xr,base16upper:()=>jr});var Xr=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jr=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qt={};E(qt,{base2:()=>Hr});var Hr=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kt={};E(Kt,{base256emoji:()=>Qr});var He=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}"),qr=He.reduce((r,t,e)=>(r[e]=t,r),[]),Kr=He.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Wr(r){return r.reduce((t,e)=>(t+=qr[e],t),"")}function Jr(r){let t=[];for(let e of r){let n=Kr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Qr=K({prefix:"\u{1F680}",name:"base256emoji",encode:Wr,decode:Jr});var Wt={};E(Wt,{base32:()=>W,base32hex:()=>en,base32hexpad:()=>nn,base32hexpadupper:()=>on,base32hexupper:()=>rn,base32pad:()=>Yr,base32padupper:()=>tn,base32upper:()=>Zr,base32z:()=>sn});var W=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zr=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yr=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tn=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),en=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rn=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nn=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),on=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sn=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jt={};E(Jt,{base36:()=>an,base36upper:()=>cn});var an=k({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cn=k({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qt={};E(Qt,{base58btc:()=>O,base58flickr:()=>hn});var O=k({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hn=k({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zt={};E(Zt,{base64:()=>un,base64pad:()=>fn,base64url:()=>ln,base64urlpad:()=>dn});var un=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),fn=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ln=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dn=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yt={};E(Yt,{base8:()=>pn});var pn=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var te={};E(te,{identity:()=>mn});var mn=K({prefix:"\0",name:"identity",encode:r=>Ge(r),decode:r=>ze(r)});var Jo=new TextEncoder,Qo=new TextDecoder;var re={};E(re,{identity:()=>kn});var wn=We,qe=128,xn=127,yn=~xn,En=Math.pow(2,31);function We(r,t,e){t=t||[],e=e||0;for(var n=e;r>=En;)t[e++]=r&255|qe,r/=128;for(;r&yn;)t[e++]=r&255|qe,r>>>=7;return t[e]=r|0,We.bytes=e-n+1,t}var Ln=ee,An=128,Ke=127;function ee(r,n){var e=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw ee.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&Ke)<<i:(s&Ke)*Math.pow(2,i),i+=7}while(s>=An);return ee.bytes=o-n,e}var Sn=Math.pow(2,7),Nn=Math.pow(2,14),Rn=Math.pow(2,21),Dn=Math.pow(2,28),Un=Math.pow(2,35),In=Math.pow(2,42),Tn=Math.pow(2,49),On=Math.pow(2,56),Fn=Math.pow(2,63),Bn=function(r){return r<Sn?1:r<Nn?2:r<Rn?3:r<Dn?4:r<Un?5:r<In?6:r<Tn?7:r<On?8:r<Fn?9:10},_n={encode:wn,decode:Ln,encodingLength:Bn},vn=_n,et=vn;function rt(r,t=0){return[et.decode(r,t),et.decode.bytes]}function J(r,t,e=0){return et.encode(r,t,e),t}function Q(r){return et.encodingLength(r)}function $(r,t){let e=t.byteLength,n=Q(r),i=n+Q(e),o=new Uint8Array(i+e);return J(r,o,0),J(e,o,n),o.set(t,i),new Z(r,e,t,o)}function Je(r){let t=v(r),[e,n]=rt(t),[i,o]=rt(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Z(e,i,s,t)}function Qe(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Pe(r.bytes,e.bytes)}}var Z=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var Ze=0,Cn="identity",Ye=v;function Mn(r){return $(Ze,Ye(r))}var kn={code:Ze,name:Cn,encode:Ye,digest:Mn};var oe={};E(oe,{sha256:()=>Vn,sha512:()=>Pn});function ie({name:r,code:t,encode:e}){return new ne(r,t,e)}var ne=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?$(this.code,e):e.then(n=>$(this.code,n))}else throw Error("Unknown type, must be binary type")}};function er(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Vn=ie({name:"sha2-256",code:18,encode:er("SHA-256")}),Pn=ie({name:"sha2-512",code:19,encode:er("SHA-512")});function rr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Gn(e,se(r),t??O.encoder);default:return $n(e,se(r),t??W.encoder)}}var nr=new WeakMap;function se(r){let t=nr.get(r);if(t==null){let e=new Map;return nr.set(r,e),e}return t}var yt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==it)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Xn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=$(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Qe(t.multihash,n.multihash)}toString(t){return rr(this,t)}toJSON(){return{"/":rr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??ir(n,i,o.bytes))}else if(e[jn]===!0){let{version:n,multihash:i,code:o}=e,s=Je(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==it)throw new Error(`Version 0 CID must use dag-pb (code: ${it}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=ir(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,it,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=v(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new Z(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,w]=rt(t.subarray(e));return e+=w,f},i=n(),o=it;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,a=n(),c=n(),h=e+c,l=h-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:h}}static parse(t,e){let[n,i]=zn(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return se(o).set(n,t),o}};function zn(r,t){switch(r[0]){case"Q":{let e=t??O;return[O.prefix,e.decode(`${O.prefix}${r}`)]}case O.prefix:{let e=t??O;return[O.prefix,e.decode(r)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Gn(r,t,e){let{prefix:n}=e;if(n!==O.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function $n(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var it=112,Xn=18;function ir(r,t,e){let n=Q(r),i=n+Q(t),o=new Uint8Array(i+e.byteLength);return J(r,o,0),J(t,o,n),o.set(e,i),o}var jn=Symbol.for("@ipld/js-cid/CID");var ae={...te,...qt,...Yt,...jt,...Ht,...Wt,...Jt,...Qt,...Zt,...Kt},ws={...oe,...re};function sr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var or=sr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ce=sr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=m(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Hn={utf8:or,"utf-8":or,hex:ae.base16,latin1:ce,ascii:ce,binary:ce,...ae},Et=Hn;function Lt(r,t="utf8"){let e=Et[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?M(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function ar(r,t="utf8"){let e=Et[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var cr="0.0.1",hr="fetch";var he=new Float32Array([-0]),V=new Uint8Array(he.buffer);function ur(r,t,e){he[0]=r,t[e]=V[0],t[e+1]=V[1],t[e+2]=V[2],t[e+3]=V[3]}function fr(r,t){return V[0]=r[t],V[1]=r[t+1],V[2]=r[t+2],V[3]=r[t+3],he[0]}var ue=new Float64Array([-0]),b=new Uint8Array(ue.buffer);function lr(r,t,e){ue[0]=r,t[e]=b[0],t[e+1]=b[1],t[e+2]=b[2],t[e+3]=b[3],t[e+4]=b[4],t[e+5]=b[5],t[e+6]=b[6],t[e+7]=b[7]}function dr(r,t){return b[0]=r[t],b[1]=r[t+1],b[2]=r[t+2],b[3]=r[t+3],b[4]=r[t+4],b[5]=r[t+5],b[6]=r[t+6],b[7]=r[t+7],ue[0]}var qn=BigInt(Number.MAX_SAFE_INTEGER),Kn=BigInt(Number.MIN_SAFE_INTEGER),y=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return X;if(t<qn&&t>Kn)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>pr&&(i=0n,++n>pr&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return X;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):X}},X=new y(0,0);X.toBigInt=function(){return 0n};X.zzEncode=X.zzDecode=function(){return this};X.length=function(){return 1};var pr=4294967296n;function mr(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function gr(r,t,e){if(e-t<1)return"";let i,o=[],s=0,a;for(;t<e;)a=r[t++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function fe(r,t,e){let n=e,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function R(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function At(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var le=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,R(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw R(this,4);return At(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw R(this,4);return At(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw R(this,4);let t=fr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw R(this,4);let t=dr(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw R(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return gr(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw R(this,t);this.pos+=t}else do if(this.pos>=this.len)throw R(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new y(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw R(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw R(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw R(this,8);let t=At(this.buf,this.pos+=4),e=At(this.buf,this.pos+=4);return new y(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 de(r){return new le(r instanceof Uint8Array?r:r.subarray())}function St(r,t){let e=de(r);return t.decode(e)}function pe(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return m(s);i+s>t&&(n=m(t),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var j=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function me(){}var be=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Wn=pe();function Jn(r){return globalThis.Buffer!=null?m(r):Wn(r)}var at=class{len;head;tail;states;constructor(){this.len=0,this.head=new j(me,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new j(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new we((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(ot,10,y.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=y.fromBigInt(t);return this._push(ot,e.length(),e)}uint64Number(t){let e=y.fromNumber(t);return this._push(ot,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=y.fromBigInt(t).zzEncode();return this._push(ot,e.length(),e)}sint64Number(t){let e=y.fromNumber(t).zzEncode();return this._push(ot,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ge,1,t?1:0)}fixed32(t){return this._push(st,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=y.fromBigInt(t);return this._push(st,4,e.lo)._push(st,4,e.hi)}fixed64Number(t){let e=y.fromNumber(t);return this._push(st,4,e.lo)._push(st,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ur,4,t)}double(t){return this._push(lr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ge,1,0):this.uint32(e)._push(Zn,e,t)}string(t){let e=mr(t);return e!==0?this.uint32(e)._push(fe,e,t):this._push(ge,1,0)}fork(){return this.states=new be(this),this.head=this.tail=new j(me,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new j(me,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Jn(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ge(r,t,e){t[e]=r&255}function Qn(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var we=class extends j{next;constructor(t,e){super(Qn,t,e),this.next=void 0}};function ot(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function st(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Zn(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(at.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Yn,t,r),this},at.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ti,t,r),this});function Yn(r,t,e){t.set(r,e)}function ti(r,t,e){r.length<40?fe(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Lt(r),e)}function xe(){return new at}function Nt(r,t){let e=xe();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Y;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Y||(Y={}));function Rt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ye(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,s){let a=t(o);s.int32(a)},n=function(o){let s=o.int32();return t(s)};return Rt("enum",Y.VARINT,e,n)}function Dt(r,t){return Rt("message",Y.LENGTH_DELIMITED,r,t)}var ct;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.identifier!=null&&e.identifier!==""&&(n.uint32(10),n.string(e.identifier)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={identifier:""},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let s=e.uint32();switch(s>>>3){case 1:i.identifier=e.string();break;default:e.skipType(s&7);break}}return i})),t),r.encode=e=>Nt(e,r.codec()),r.decode=e=>St(e,r.codec())})(ct||(ct={}));var D;(function(r){let t;(function(i){i.OK="OK",i.NOT_FOUND="NOT_FOUND",i.ERROR="ERROR"})(t=r.StatusCode||(r.StatusCode={}));let e;(function(i){i[i.OK=0]="OK",i[i.NOT_FOUND=1]="NOT_FOUND",i[i.ERROR=2]="ERROR"})(e||(e={})),function(i){i.codec=()=>ye(e)}(t=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=Dt((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.status!=null&&e[i.status]!==0&&(o.uint32(8),r.StatusCode.codec().encode(i.status,o)),i.data!=null&&i.data.byteLength>0&&(o.uint32(18),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={status:t.OK,data:new Uint8Array(0)},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.status=r.StatusCode.codec().decode(i);break;case 2:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>Nt(i,r.codec()),r.decode=i=>St(i,r.codec())})(D||(D={}));var wr=1e4,Ut=class{protocol;components;lookupFunctions;started;init;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:fetch"),this.started=!1,this.components=t,this.protocol=`/${e.protocolPrefix??"libp2p"}/${hr}/${cr}`,this.lookupFunctions=new Map,this.handleMessage=this.handleMessage.bind(this),this.init=e}async start(){await this.components.registrar.handle(this.protocol,t=>{this.handleMessage(t).then(async()=>{await t.stream.close()}).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.init.maxInboundStreams,maxOutboundStreams:this.init.maxOutboundStreams}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async fetch(t,e,n={}){this.log("dialing %s to %p",this.protocol,t);let i=await this.components.connectionManager.openConnection(t,n),o=n.signal,s,a=()=>{};if(o==null){let c=this.init.timeout??wr;this.log("using default timeout of %d ms",c),o=AbortSignal.timeout(c),De(1/0,o)}try{s=await i.newStream(this.protocol,{signal:o}),a=()=>{s?.abort(new z("fetch timeout",Se))},o.addEventListener("abort",a,{once:!0}),this.log("fetch %s",e);let c=Pt(s);await c.write({identifier:e},ct,n);let h=await c.read(D,n);switch(await c.unwrap().close(n),h.status){case D.StatusCode.OK:return this.log("received status for %s ok",e),h.data;case D.StatusCode.NOT_FOUND:{this.log("received status for %s not found",e);return}case D.StatusCode.ERROR:{this.log("received status for %s error",e);let l=ar(h.data);throw new z("Error in fetch protocol response: "+l,Ne)}default:throw this.log("received status for %s unknown",e),new z("Unknown response status",Re)}}catch(c){throw s?.abort(c),c}finally{o.removeEventListener("abort",a),s!=null&&await s.close()}}async handleMessage(t){let{stream:e}=t,n=AbortSignal.timeout(this.init.timeout??wr);try{let i=Pt(e),o=await i.read(ct,{signal:n}),s,a=this._getLookupFunction(o.identifier);if(a!=null){this.log("look up data with identifier %s",o.identifier);let c=await a(o.identifier);c!=null?(this.log("sending status for %s ok",o.identifier),s={status:D.StatusCode.OK,data:c}):(this.log("sending status for %s not found",o.identifier),s={status:D.StatusCode.NOT_FOUND,data:new Uint8Array(0)})}else{this.log("sending status for %s error",o.identifier);let c=Lt(`No lookup function registered for key: ${o.identifier}`);s={status:D.StatusCode.ERROR,data:c}}await i.write(s,D,{signal:n}),await i.unwrap().close({signal:n})}catch(i){this.log("error answering fetch request",i),e.abort(i)}}_getLookupFunction(t){for(let e of this.lookupFunctions.keys())if(t.startsWith(e))return this.lookupFunctions.get(e)}registerLookupFunction(t,e){if(this.lookupFunctions.has(t))throw new z(`Fetch protocol handler for key prefix '${t}' already registered`,"ERR_KEY_ALREADY_EXISTS");this.lookupFunctions.set(t,e)}unregisterLookupFunction(t,e){e!=null&&this.lookupFunctions.get(t)!==e||this.lookupFunctions.delete(t)}};function ei(r={}){return t=>new Ut(t,r)}return Rr(ri);})();
2
+ "use strict";var Libp2PFetch=(()=>{var mr=Object.create;var ft=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var br=Object.getOwnPropertyNames;var xr=Object.getPrototypeOf,yr=Object.prototype.hasOwnProperty;var Er=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),E=(r,t)=>{for(var e in t)ft(r,e,{get:t[e],enumerable:!0})},ye=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of br(t))!yr.call(r,i)&&i!==e&&ft(r,i,{get:()=>t[i],enumerable:!(n=wr(t,i))||n.enumerable});return r};var Lr=(r,t,e)=>(e=r!=null?mr(xr(r)):{},ye(t||!r||!r.__esModule?ft(e,"default",{value:r,enumerable:!0}):e,r)),Ar=r=>ye(ft({},"__esModule",{value:!0}),r);var _e=Er((Ii,Be)=>{"use strict";function Fe(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Or(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return Fe(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),Fe(new i,e)}}Be.exports=Or});var Yn={};E(Yn,{fetch:()=>Zn});var G=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Ee="ERR_TIMEOUT",Le="ERR_INVALID_PARAMETERS";var Ae="ERR_INVALID_MESSAGE";var Ne=(r,...t)=>{try{[...t]}catch{}};function v(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function B(r=0){return globalThis.Buffer?.alloc!=null?v(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function g(r=0){return globalThis.Buffer?.allocUnsafe!=null?v(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function It(r,t){if(globalThis.Buffer!=null)return v(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=g(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return v(e)}function Se(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var De=Symbol.for("@achingbrain/uint8arraylist");function Re(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function lt(r){return!!r?.[De]}var A=class r{bufs;length;[De]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(lt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(lt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Re(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Re(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(lt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:i}=this._subList(t,e);return It(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:It(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),o=new r;return o.length=i,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,t>=c)continue;let h=t>=a&&t<c,l=e>a&&e<=c;if(h&&l){if(t===a&&e===c){n.push(s);break}let f=t-a;n.push(s.subarray(f,f+(e-t)));break}if(h){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(l){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!lt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let f=0;f<o;f++)s[f]=-1;for(let f=0;f<i;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,h=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let b=h;b>=0;b--){let ht=this.get(f+b);if(n[b]!==ht){l=Math.max(1,b-a[ht]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=g(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let i=B(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let i=B(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let i=B(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=g(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let i=B(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let i=B(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let i=B(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let i=B(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let i=B(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Se(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,o)=>i+o.byteLength,0)),n.length=e,n}};function j(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var dt=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function Ue(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new dt(e?.errorMessage,e?.errorCode));let n,i=new dt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Tt=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=j(),this.haveNext=j()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=j(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=j(),await Ue(this.needNext.promise,e?.signal,e)}};function Ie(){return new Tt}var pt=class extends Error{code;constructor(t,e){super(t),this.code=e}},Ot=class extends pt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Te(r,t){let e=Ie();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let i=new A;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,h=new Promise((l,f)=>{c=()=>{f(new Ot("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:f,value:b}=await Promise.race([n.next(),h]);return f===!0?new A:b}for(;i.byteLength<s;){let{value:f,done:b}=await Promise.race([n.next(),h]);if(b===!0)throw new pt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(f)}let l=i.sublist(0,s);return i.consume(s),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(i.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield i:yield*i,yield*s}()}return r}}}var Nr=Math.pow(2,7),Sr=Math.pow(2,14),Rr=Math.pow(2,21),Ft=Math.pow(2,28),Bt=Math.pow(2,35),_t=Math.pow(2,42),Ct=Math.pow(2,49),u=128,m=127;function _(r){if(r<Nr)return 1;if(r<Sr)return 2;if(r<Rr)return 3;if(r<Ft)return 4;if(r<Bt)return 5;if(r<_t)return 6;if(r<Ct)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Dr(r,t,e=0){switch(_(r)){case 8:t[e++]=r&255|u,r/=128;case 7:t[e++]=r&255|u,r/=128;case 6:t[e++]=r&255|u,r/=128;case 5:t[e++]=r&255|u,r/=128;case 4:t[e++]=r&255|u,r>>>=7;case 3:t[e++]=r&255|u,r>>>=7;case 2:t[e++]=r&255|u,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ur(r,t,e=0){switch(_(r)){case 8:t.set(e++,r&255|u),r/=128;case 7:t.set(e++,r&255|u),r/=128;case 6:t.set(e++,r&255|u),r/=128;case 5:t.set(e++,r&255|u),r/=128;case 4:t.set(e++,r&255|u),r>>>=7;case 3:t.set(e++,r&255|u),r>>>=7;case 2:t.set(e++,r&255|u),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ir(r,t){let e=r[t],n=0;if(n+=e&m,e<u||(e=r[t+1],n+=(e&m)<<7,e<u)||(e=r[t+2],n+=(e&m)<<14,e<u)||(e=r[t+3],n+=(e&m)<<21,e<u)||(e=r[t+4],n+=(e&m)*Ft,e<u)||(e=r[t+5],n+=(e&m)*Bt,e<u)||(e=r[t+6],n+=(e&m)*_t,e<u)||(e=r[t+7],n+=(e&m)*Ct,e<u))return n;throw new RangeError("Could not decode varint")}function Tr(r,t){let e=r.get(t),n=0;if(n+=e&m,e<u||(e=r.get(t+1),n+=(e&m)<<7,e<u)||(e=r.get(t+2),n+=(e&m)<<14,e<u)||(e=r.get(t+3),n+=(e&m)<<21,e<u)||(e=r.get(t+4),n+=(e&m)*Ft,e<u)||(e=r.get(t+5),n+=(e&m)*Bt,e<u)||(e=r.get(t+6),n+=(e&m)*_t,e<u)||(e=r.get(t+7),n+=(e&m)*Ct,e<u))return n;throw new RangeError("Could not decode varint")}function Oe(r,t,e=0){return t==null&&(t=g(_(r))),t instanceof Uint8Array?Dr(r,t,e):Ur(r,t,e)}function gt(r,t=0){return r instanceof Uint8Array?Ir(r,t):Tr(r,t)}function mt(r){return r[Symbol.asyncIterator]!=null}var wt=r=>{let t=_(r),e=g(t);return Oe(r,e),wt.bytes=t,e};wt.bytes=0;function tt(r,t){t=t??{};let e=t.lengthEncoder??wt;function*n(i){let o=e(i.byteLength);o instanceof Uint8Array?yield o:yield*o,i instanceof Uint8Array?yield i:yield*i}return mt(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}tt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??wt;return new A(e(r.byteLength),r)};var q=Lr(_e(),1);var Fr=8,Br=1024*1024*4,P;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(P||(P={}));var kt=r=>{let t=gt(r);return kt.bytes=_(t),t};kt.bytes=0;function vt(r,t){let e=new A,n=P.LENGTH,i=-1,o=t?.lengthDecoder??kt,s=t?.maxLengthLength??Fr,a=t?.maxDataLength??Br;function*c(){for(;e.byteLength>0;){if(n===P.LENGTH)try{if(i=o(e),i<0)throw(0,q.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,q.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let h=o.bytes;e.consume(h),t?.onLength!=null&&t.onLength(i),n=P.DATA}catch(h){if(h instanceof RangeError){if(e.byteLength>s)throw(0,q.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw h}if(n===P.DATA){if(e.byteLength<i)break;let h=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(h),yield h,n=P.LENGTH}}}return mt(r)?async function*(){for await(let h of r)e.append(h),yield*c();if(e.byteLength>0)throw(0,q.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let h of r)e.append(h),yield*c();if(e.byteLength>0)throw(0,q.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}vt.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:s}=await r.next(e);if(o===!0)return;s!=null&&(yield s)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return vt(n,{...t??{},onLength:o=>{e=o}})};var bt=class extends Error{code;constructor(t,e){super(t),this.code=e}},Ce=r=>gt(r);Ce.bytes=0;function Me(r,t={}){let e=Te(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=_(t.maxDataLength)),{read:async i=>{let o=-1,s=new A,a=t?.lengthDecoder??Ce;for(;;){s.append(await e.read(1,i));try{o=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new bt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(o>-1)break}if(t?.maxDataLength!=null&&o>t.maxDataLength)throw new bt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(o,i)},write:async(i,o)=>{await e.write(tt.single(i,t),o)},writeV:async(i,o)=>{let s=new A(...i.map(a=>tt.single(a,t)));await e.write(s,o)},unwrap:()=>e.unwrap()}}function Vt(r,t){let e=Me(r,t),n={read:async(i,o)=>{let s=await e.read(o);return i.decode(s)},write:async(i,o,s)=>{await e.write(o.encode(i),s)},writeV:async(i,o,s)=>{await e.writeV(i.map(a=>o.encode(a)),s)},pb:i=>({read:async o=>n.read(i,o),write:async(o,s)=>n.write(o,i,s),writeV:async(o,s)=>n.writeV(o,i,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Xt={};E(Xt,{base10:()=>zr});var zi=new Uint8Array(0);function ve(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function C(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ke(r){return new TextEncoder().encode(r)}function Ve(r){return new TextDecoder().decode(r)}function Cr(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var x=0,z=0,N=0,U=d.length;N!==U&&d[N]===0;)N++,x++;for(var I=(U-N)*l+1>>>0,L=new Uint8Array(I);N!==U;){for(var T=d[N],M=0,S=I-1;(T!==0||M<z)&&S!==-1;S--,M++)T+=256*L[S]>>>0,L[S]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");z=M,N++}for(var F=I-z;F!==I&&L[F]===0;)F++;for(var ut=c.repeat(x);F<I;++F)ut+=r.charAt(L[F]);return ut}function b(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var x=0;if(d[x]!==" "){for(var z=0,N=0;d[x]===c;)z++,x++;for(var U=(d.length-x)*h+1>>>0,I=new Uint8Array(U);d[x];){var L=e[d.charCodeAt(x)];if(L===255)return;for(var T=0,M=U-1;(L!==0||T<N)&&M!==-1;M--,T++)L+=a*I[M]>>>0,I[M]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");N=T,x++}if(d[x]!==" "){for(var S=U-N;S!==U&&I[S]===0;)S++;for(var F=new Uint8Array(z+(U-S)),ut=z;S!==U;)F[ut++]=I[S++];return F}}}function ht(d){var x=b(d);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:ht}}var Mr=Cr,vr=Mr,Ge=vr;var zt=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Gt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Pe(this,t)}},Pt=class{decoders;constructor(t){this.decoders=t}or(t){return Pe(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Pe(r,t){return new Pt({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var $t=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new zt(t,e,n),this.decoder=new Gt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function W({name:r,prefix:t,encode:e,decode:n}){return new $t(r,t,e,n)}function k({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=Ge(e,r);return W({prefix:t,name:r,encode:n,decode:o=>C(i(o))})}function kr(r,t,e,n){let i={};for(let l=0;l<t.length;++l)i[t[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,c=0,h=0;for(let l=0;l<o;++l){let f=i[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,s[h++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Vr(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,o+=t[i&a>>s];if(s!==0&&(o+=t[i&a<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function p({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return W({prefix:t,name:r,encode(i){return Vr(i,n,e)},decode(i){return kr(i,n,e,r)}})}var zr=k({prefix:"9",name:"base10",alphabet:"0123456789"});var Ht={};E(Ht,{base16:()=>Gr,base16upper:()=>Pr});var Gr=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pr=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jt={};E(jt,{base2:()=>$r});var $r=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var qt={};E(qt,{base256emoji:()=>Wr});var $e=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}"),Xr=$e.reduce((r,t,e)=>(r[e]=t,r),[]),Hr=$e.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function jr(r){return r.reduce((t,e)=>(t+=Xr[e],t),"")}function qr(r){let t=[];for(let e of r){let n=Hr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Wr=W({prefix:"\u{1F680}",name:"base256emoji",encode:jr,decode:qr});var Wt={};E(Wt,{base32:()=>K,base32hex:()=>Zr,base32hexpad:()=>tn,base32hexpadupper:()=>en,base32hexupper:()=>Yr,base32pad:()=>Jr,base32padupper:()=>Qr,base32upper:()=>Kr,base32z:()=>rn});var K=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kr=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jr=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qr=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zr=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yr=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tn=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),en=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rn=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt={};E(Kt,{base36:()=>nn,base36upper:()=>on});var nn=k({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),on=k({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Jt={};E(Jt,{base58btc:()=>O,base58flickr:()=>sn});var O=k({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sn=k({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qt={};E(Qt,{base64:()=>an,base64pad:()=>cn,base64url:()=>hn,base64urlpad:()=>un});var an=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cn=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),hn=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),un=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zt={};E(Zt,{base8:()=>fn});var fn=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yt={};E(Yt,{identity:()=>ln});var ln=W({prefix:"\0",name:"identity",encode:r=>Ve(r),decode:r=>ke(r)});var ro=new TextEncoder,no=new TextDecoder;var ee={};E(ee,{identity:()=>Cn});var gn=je,Xe=128,mn=127,wn=~mn,bn=Math.pow(2,31);function je(r,t,e){t=t||[],e=e||0;for(var n=e;r>=bn;)t[e++]=r&255|Xe,r/=128;for(;r&wn;)t[e++]=r&255|Xe,r>>>=7;return t[e]=r|0,je.bytes=e-n+1,t}var xn=te,yn=128,He=127;function te(r,n){var e=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw te.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&He)<<i:(s&He)*Math.pow(2,i),i+=7}while(s>=yn);return te.bytes=o-n,e}var En=Math.pow(2,7),Ln=Math.pow(2,14),An=Math.pow(2,21),Nn=Math.pow(2,28),Sn=Math.pow(2,35),Rn=Math.pow(2,42),Dn=Math.pow(2,49),Un=Math.pow(2,56),In=Math.pow(2,63),Tn=function(r){return r<En?1:r<Ln?2:r<An?3:r<Nn?4:r<Sn?5:r<Rn?6:r<Dn?7:r<Un?8:r<In?9:10},On={encode:gn,decode:xn,encodingLength:Tn},Fn=On,et=Fn;function rt(r,t=0){return[et.decode(r,t),et.decode.bytes]}function J(r,t,e=0){return et.encode(r,t,e),t}function Q(r){return et.encodingLength(r)}function $(r,t){let e=t.byteLength,n=Q(r),i=n+Q(e),o=new Uint8Array(i+e);return J(r,o,0),J(e,o,n),o.set(t,i),new Z(r,e,t,o)}function qe(r){let t=C(r),[e,n]=rt(t),[i,o]=rt(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Z(e,i,s,t)}function We(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ve(r.bytes,e.bytes)}}var Z=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var Ke=0,Bn="identity",Je=C;function _n(r){return $(Ke,Je(r))}var Cn={code:Ke,name:Bn,encode:Je,digest:_n};var ie={};E(ie,{sha256:()=>Mn,sha512:()=>vn});function ne({name:r,code:t,encode:e}){return new re(r,t,e)}var re=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?$(this.code,e):e.then(n=>$(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ze(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Mn=ne({name:"sha2-256",code:18,encode:Ze("SHA-256")}),vn=ne({name:"sha2-512",code:19,encode:Ze("SHA-512")});function Ye(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Vn(e,oe(r),t??O.encoder);default:return zn(e,oe(r),t??K.encoder)}}var tr=new WeakMap;function oe(r){let t=tr.get(r);if(t==null){let e=new Map;return tr.set(r,e),e}return t}var yt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==it)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Gn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=$(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&We(t.multihash,n.multihash)}toString(t){return Ye(this,t)}toJSON(){return{"/":Ye(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??er(n,i,o.bytes))}else if(e[Pn]===!0){let{version:n,multihash:i,code:o}=e,s=qe(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==it)throw new Error(`Version 0 CID must use dag-pb (code: ${it}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=er(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,it,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=C(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new Z(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,b]=rt(t.subarray(e));return e+=b,f},i=n(),o=it;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,a=n(),c=n(),h=e+c,l=h-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:h}}static parse(t,e){let[n,i]=kn(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return oe(o).set(n,t),o}};function kn(r,t){switch(r[0]){case"Q":{let e=t??O;return[O.prefix,e.decode(`${O.prefix}${r}`)]}case O.prefix:{let e=t??O;return[O.prefix,e.decode(r)]}case K.prefix:{let e=t??K;return[K.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Vn(r,t,e){let{prefix:n}=e;if(n!==O.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function zn(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var it=112,Gn=18;function er(r,t,e){let n=Q(r),i=n+Q(t),o=new Uint8Array(i+e.byteLength);return J(r,o,0),J(t,o,n),o.set(e,i),o}var Pn=Symbol.for("@ipld/js-cid/CID");var se={...Yt,...jt,...Zt,...Xt,...Ht,...Wt,...Kt,...Jt,...Qt,...qt},So={...ie,...ee};function nr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var rr=nr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ae=nr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=g(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),$n={utf8:rr,"utf-8":rr,hex:se.base16,latin1:ae,ascii:ae,binary:ae,...se},Et=$n;function Lt(r,t="utf8"){let e=Et[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?v(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function ir(r,t="utf8"){let e=Et[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var or="0.0.1",sr="fetch";var ce=new Float32Array([-0]),V=new Uint8Array(ce.buffer);function ar(r,t,e){ce[0]=r,t[e]=V[0],t[e+1]=V[1],t[e+2]=V[2],t[e+3]=V[3]}function cr(r,t){return V[0]=r[t],V[1]=r[t+1],V[2]=r[t+2],V[3]=r[t+3],ce[0]}var he=new Float64Array([-0]),w=new Uint8Array(he.buffer);function hr(r,t,e){he[0]=r,t[e]=w[0],t[e+1]=w[1],t[e+2]=w[2],t[e+3]=w[3],t[e+4]=w[4],t[e+5]=w[5],t[e+6]=w[6],t[e+7]=w[7]}function ur(r,t){return w[0]=r[t],w[1]=r[t+1],w[2]=r[t+2],w[3]=r[t+3],w[4]=r[t+4],w[5]=r[t+5],w[6]=r[t+6],w[7]=r[t+7],he[0]}var Xn=BigInt(Number.MAX_SAFE_INTEGER),Hn=BigInt(Number.MIN_SAFE_INTEGER),y=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return X;if(t<Xn&&t>Hn)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>fr&&(i=0n,++n>fr&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return X;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):X}},X=new y(0,0);X.toBigInt=function(){return 0n};X.zzEncode=X.zzDecode=function(){return this};X.length=function(){return 1};var fr=4294967296n;function lr(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function dr(r,t,e){if(e-t<1)return"";let i,o=[],s=0,a;for(;t<e;)a=r[t++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ue(r,t,e){let n=e,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function R(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function At(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var fe=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,R(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw R(this,4);return At(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw R(this,4);return At(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw R(this,4);let t=cr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw R(this,4);let t=ur(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw R(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return dr(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw R(this,t);this.pos+=t}else do if(this.pos>=this.len)throw R(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new y(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw R(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw R(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw R(this,8);let t=At(this.buf,this.pos+=4),e=At(this.buf,this.pos+=4);return new y(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 le(r){return new fe(r instanceof Uint8Array?r:r.subarray())}function Nt(r,t){let e=le(r);return t.decode(e)}function de(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return g(s);i+s>t&&(n=g(t),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var H=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function pe(){}var me=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},jn=de();function qn(r){return globalThis.Buffer!=null?g(r):jn(r)}var at=class{len;head;tail;states;constructor(){this.len=0,this.head=new H(pe,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new H(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new we((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(ot,10,y.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=y.fromBigInt(t);return this._push(ot,e.length(),e)}uint64Number(t){let e=y.fromNumber(t);return this._push(ot,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=y.fromBigInt(t).zzEncode();return this._push(ot,e.length(),e)}sint64Number(t){let e=y.fromNumber(t).zzEncode();return this._push(ot,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ge,1,t?1:0)}fixed32(t){return this._push(st,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=y.fromBigInt(t);return this._push(st,4,e.lo)._push(st,4,e.hi)}fixed64Number(t){let e=y.fromNumber(t);return this._push(st,4,e.lo)._push(st,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ar,4,t)}double(t){return this._push(hr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ge,1,0):this.uint32(e)._push(Kn,e,t)}string(t){let e=lr(t);return e!==0?this.uint32(e)._push(ue,e,t):this._push(ge,1,0)}fork(){return this.states=new me(this),this.head=this.tail=new H(pe,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 H(pe,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=qn(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ge(r,t,e){t[e]=r&255}function Wn(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var we=class extends H{next;constructor(t,e){super(Wn,t,e),this.next=void 0}};function ot(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function st(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Kn(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(at.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Jn,t,r),this},at.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Qn,t,r),this});function Jn(r,t,e){t.set(r,e)}function Qn(r,t,e){r.length<40?ue(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Lt(r),e)}function be(){return new at}function St(r,t){let e=be();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Y;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Y||(Y={}));function Rt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function xe(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,s){let a=t(o);s.int32(a)},n=function(o){let s=o.int32();return t(s)};return Rt("enum",Y.VARINT,e,n)}function Dt(r,t){return Rt("message",Y.LENGTH_DELIMITED,r,t)}var ct;(function(r){let t;r.codec=()=>(t==null&&(t=Dt((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.identifier!=null&&e.identifier!==""&&(n.uint32(10),n.string(e.identifier)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={identifier:""},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let s=e.uint32();switch(s>>>3){case 1:i.identifier=e.string();break;default:e.skipType(s&7);break}}return i})),t),r.encode=e=>St(e,r.codec()),r.decode=e=>Nt(e,r.codec())})(ct||(ct={}));var D;(function(r){let t;(function(i){i.OK="OK",i.NOT_FOUND="NOT_FOUND",i.ERROR="ERROR"})(t=r.StatusCode||(r.StatusCode={}));let e;(function(i){i[i.OK=0]="OK",i[i.NOT_FOUND=1]="NOT_FOUND",i[i.ERROR=2]="ERROR"})(e||(e={})),function(i){i.codec=()=>xe(e)}(t=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=Dt((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.status!=null&&e[i.status]!==0&&(o.uint32(8),r.StatusCode.codec().encode(i.status,o)),i.data!=null&&i.data.byteLength>0&&(o.uint32(18),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={status:t.OK,data:new Uint8Array(0)},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.status=r.StatusCode.codec().decode(i);break;case 2:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),r.encode=i=>St(i,r.codec()),r.decode=i=>Nt(i,r.codec())})(D||(D={}));var gr=1e4,Ut=class{protocol;components;lookupFunctions;started;init;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:fetch"),this.started=!1,this.components=t,this.protocol=`/${e.protocolPrefix??"libp2p"}/${sr}/${or}`,this.lookupFunctions=new Map,this.handleMessage=this.handleMessage.bind(this),this.init=e}async start(){await this.components.registrar.handle(this.protocol,t=>{this.handleMessage(t).then(async()=>{await t.stream.close()}).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.init.maxInboundStreams,maxOutboundStreams:this.init.maxOutboundStreams}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async fetch(t,e,n={}){this.log("dialing %s to %p",this.protocol,t);let i=await this.components.connectionManager.openConnection(t,n),o=n.signal,s,a=()=>{};if(o==null){let c=this.init.timeout??gr;this.log("using default timeout of %d ms",c),o=AbortSignal.timeout(c),Ne(1/0,o)}try{s=await i.newStream(this.protocol,{signal:o}),a=()=>{s?.abort(new G("fetch timeout",Ee))},o.addEventListener("abort",a,{once:!0}),this.log("fetch %s",e);let c=Vt(s);await c.write({identifier:e},ct,n);let h=await c.read(D,n);switch(await c.unwrap().close(n),h.status){case D.StatusCode.OK:return this.log("received status for %s ok",e),h.data;case D.StatusCode.NOT_FOUND:{this.log("received status for %s not found",e);return}case D.StatusCode.ERROR:{this.log("received status for %s error",e);let l=ir(h.data);throw new G("Error in fetch protocol response: "+l,Le)}default:throw this.log("received status for %s unknown",e),new G("Unknown response status",Ae)}}catch(c){throw s?.abort(c),c}finally{o.removeEventListener("abort",a),s!=null&&await s.close()}}async handleMessage(t){let{stream:e}=t,n=AbortSignal.timeout(this.init.timeout??gr);try{let i=Vt(e),o=await i.read(ct,{signal:n}),s,a=this._getLookupFunction(o.identifier);if(a!=null){this.log("look up data with identifier %s",o.identifier);let c=await a(o.identifier);c!=null?(this.log("sending status for %s ok",o.identifier),s={status:D.StatusCode.OK,data:c}):(this.log("sending status for %s not found",o.identifier),s={status:D.StatusCode.NOT_FOUND,data:new Uint8Array(0)})}else{this.log("sending status for %s error",o.identifier);let c=Lt(`No lookup function registered for key: ${o.identifier}`);s={status:D.StatusCode.ERROR,data:c}}await i.write(s,D,{signal:n}),await i.unwrap().close({signal:n})}catch(i){this.log("error answering fetch request",i),e.abort(i)}}_getLookupFunction(t){for(let e of this.lookupFunctions.keys())if(t.startsWith(e))return this.lookupFunctions.get(e)}registerLookupFunction(t,e){if(this.lookupFunctions.has(t))throw new G(`Fetch protocol handler for key prefix '${t}' already registered`,"ERR_KEY_ALREADY_EXISTS");this.lookupFunctions.set(t,e)}unregisterLookupFunction(t,e){e!=null&&this.lookupFunctions.get(t)!==e||this.lookupFunctions.delete(t)}};function Zn(r={}){return t=>new Ut(t,r)}return Ar(Yn);})();
3
3
  return Libp2PFetch}));
@@ -0,0 +1,12 @@
1
+ {
2
+ "Fetch": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.Fetch.html",
3
+ ".:Fetch": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.Fetch.html",
4
+ "FetchComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchComponents.html",
5
+ ".:FetchComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchComponents.html",
6
+ "FetchInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchInit.html",
7
+ ".:FetchInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchInit.html",
8
+ "LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.LookupFunction.html",
9
+ ".:LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.LookupFunction.html",
10
+ "fetch": "https://libp2p.github.io/js-libp2p/functions/_libp2p_fetch.fetch-1.html",
11
+ ".:fetch": "https://libp2p.github.io/js-libp2p/functions/_libp2p_fetch.fetch-1.html"
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/fetch",
3
- "version": "1.0.8-8bbd43628",
3
+ "version": "1.0.9",
4
4
  "description": "Implementation of the Fetch Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-fetch#readme",
@@ -51,20 +51,21 @@
51
51
  "dep-check": "aegir dep-check"
52
52
  },
53
53
  "dependencies": {
54
- "@libp2p/interface": "1.1.1-8bbd43628",
55
- "@libp2p/interface-internal": "1.0.6-8bbd43628",
54
+ "@libp2p/interface": "^1.1.2",
55
+ "@libp2p/interface-internal": "^1.0.7",
56
56
  "it-protobuf-stream": "^1.1.1",
57
57
  "protons-runtime": "^5.0.0",
58
58
  "uint8arraylist": "^2.4.7",
59
59
  "uint8arrays": "^5.0.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@libp2p/logger": "4.0.4-8bbd43628",
63
- "@libp2p/peer-id-factory": "4.0.4-8bbd43628",
62
+ "@libp2p/logger": "^4.0.5",
63
+ "@libp2p/peer-id-factory": "^4.0.5",
64
64
  "aegir": "^42.0.0",
65
65
  "it-pair": "^2.0.6",
66
66
  "protons": "^7.3.0",
67
67
  "sinon": "^17.0.1",
68
68
  "sinon-ts": "^2.0.0"
69
- }
69
+ },
70
+ "sideEffects": false
70
71
  }