@libp2p/fetch 1.0.5-230afea4b → 1.0.5-28587d24f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +5 -5
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 Or=Object.create;var dt=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var _r=Object.getOwnPropertyNames;var vr=Object.getPrototypeOf,Cr=Object.prototype.hasOwnProperty;var Mr=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),y=(r,t)=>{for(var e in t)dt(r,e,{get:t[e],enumerable:!0})},Se=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _r(t))!Cr.call(r,o)&&o!==e&&dt(r,o,{get:()=>t[o],enumerable:!(n=Fr(t,o))||n.enumerable});return r};var kr=(r,t,e)=>(e=r!=null?Or(vr(r)):{},Se(t||!r||!r.__esModule?dt(e,"default",{value:r,enumerable:!0}):e,r)),Vr=r=>Se(dt({},"__esModule",{value:!0}),r);var Xe=Mr(($i,$e)=>{"use strict";function ze(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function qr(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 ze(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),ze(new o,e)}}$e.exports=qr});var bo={};y(bo,{fetch:()=>mo});var xo=Symbol.for("@libp2p/connection");var Eo=Symbol.for("@libp2p/content-routing");var So=Symbol.for("@libp2p/peer-discovery");var No=Symbol.for("@libp2p/peer-id");var Ro=Symbol.for("@libp2p/peer-routing");var Ue;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ue||(Ue={}));var Oo=Symbol.for("@libp2p/transport");var Ne;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ne||(Ne={}));var V=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Te="ERR_TIMEOUT",Re="ERR_INVALID_PARAMETERS";var De="ERR_INVALID_MESSAGE";var Ot=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},vo=globalThis.CustomEvent??Ot;var Ie=(r,...t)=>{try{[...t]}catch{}};function tt(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function O(r=0){return globalThis.Buffer?.alloc!=null?tt(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function et(r=0){return globalThis.Buffer?.allocUnsafe!=null?tt(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Ft(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=et(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return tt(e)}function Be(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Fe=Symbol.for("@achingbrain/uint8arraylist");function Oe(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function pt(r){return!!r?.[Fe]}var A=class r{bufs;length;[Fe]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(pt(n))e+=n.byteLength,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(pt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Oe(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Oe(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(pt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Ft(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ft(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_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=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,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 u=t-a;n.push(s.subarray(u,u+(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(!pt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let u=0;u<i;u++)s[u]=-1;for(let u=0;u<o;u++)s[n[u]]=u;let a=s,c=this.byteLength-n.byteLength,h=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let b=h;b>=0;b--){let ut=this.get(u+b);if(n[b]!==ut){l=Math.max(1,b-a[ut]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=et(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 o=O(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,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 o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,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 o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,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=et(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 o=O(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,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 o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,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 o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,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 o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,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 o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Be(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,i)=>o+i.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 gt=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 _e(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new gt(e?.errorMessage,e?.errorCode));let n,o=new gt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var _t=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 _e(this.needNext.promise,e?.signal,e)}};function ve(){return new _t}var mt=class extends Error{code;constructor(t,e){super(t),this.code=e}},vt=class extends mt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Ce(r,t){let e=ve();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 o=new A;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,h=new Promise((l,u)=>{c=()=>{u(new vt("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:u,value:b}=await Promise.race([n.next(),h]);return u===!0?new A:b}for(;o.byteLength<s;){let{value:u,done:b}=await Promise.race([n.next(),h]);if(b===!0)throw new mt("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(u)}let l=o.sublist(0,s);return o.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(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}function Me(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function ke(r=0){return globalThis.Buffer?.allocUnsafe!=null?Me(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Pr=Math.pow(2,7),Gr=Math.pow(2,14),zr=Math.pow(2,21),Ct=Math.pow(2,28),Mt=Math.pow(2,35),kt=Math.pow(2,42),Vt=Math.pow(2,49),f=128,g=127;function F(r){if(r<Pr)return 1;if(r<Gr)return 2;if(r<zr)return 3;if(r<Ct)return 4;if(r<Mt)return 5;if(r<kt)return 6;if(r<Vt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $r(r,t,e=0){switch(F(r)){case 8:t[e++]=r&255|f,r/=128;case 7:t[e++]=r&255|f,r/=128;case 6:t[e++]=r&255|f,r/=128;case 5:t[e++]=r&255|f,r/=128;case 4:t[e++]=r&255|f,r>>>=7;case 3:t[e++]=r&255|f,r>>>=7;case 2:t[e++]=r&255|f,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Xr(r,t,e=0){switch(F(r)){case 8:t.set(e++,r&255|f),r/=128;case 7:t.set(e++,r&255|f),r/=128;case 6:t.set(e++,r&255|f),r/=128;case 5:t.set(e++,r&255|f),r/=128;case 4:t.set(e++,r&255|f),r>>>=7;case 3:t.set(e++,r&255|f),r>>>=7;case 2:t.set(e++,r&255|f),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function jr(r,t){let e=r[t],n=0;if(n+=e&g,e<f||(e=r[t+1],n+=(e&g)<<7,e<f)||(e=r[t+2],n+=(e&g)<<14,e<f)||(e=r[t+3],n+=(e&g)<<21,e<f)||(e=r[t+4],n+=(e&g)*Ct,e<f)||(e=r[t+5],n+=(e&g)*Mt,e<f)||(e=r[t+6],n+=(e&g)*kt,e<f)||(e=r[t+7],n+=(e&g)*Vt,e<f))return n;throw new RangeError("Could not decode varint")}function Hr(r,t){let e=r.get(t),n=0;if(n+=e&g,e<f||(e=r.get(t+1),n+=(e&g)<<7,e<f)||(e=r.get(t+2),n+=(e&g)<<14,e<f)||(e=r.get(t+3),n+=(e&g)<<21,e<f)||(e=r.get(t+4),n+=(e&g)*Ct,e<f)||(e=r.get(t+5),n+=(e&g)*Mt,e<f)||(e=r.get(t+6),n+=(e&g)*kt,e<f)||(e=r.get(t+7),n+=(e&g)*Vt,e<f))return n;throw new RangeError("Could not decode varint")}function Ve(r,t,e=0){return t==null&&(t=ke(F(r))),t instanceof Uint8Array?$r(r,t,e):Xr(r,t,e)}function bt(r,t=0){return r instanceof Uint8Array?jr(r,t):Hr(r,t)}function Pe(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Ge(r=0){return globalThis.Buffer?.allocUnsafe!=null?Pe(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function wt(r){return r[Symbol.asyncIterator]!=null}var xt=r=>{let t=F(r),e=Ge(t);return Ve(r,e),xt.bytes=t,e};xt.bytes=0;function rt(r,t){t=t??{};let e=t.lengthEncoder??xt;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return wt(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}rt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??xt;return new A(e(r.byteLength),r)};var H=kr(Xe(),1);var Kr=8,Wr=1024*1024*4,P;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(P||(P={}));var zt=r=>{let t=bt(r);return zt.bytes=F(t),t};zt.bytes=0;function Gt(r,t){let e=new A,n=P.LENGTH,o=-1,i=t?.lengthDecoder??zt,s=t?.maxLengthLength??Kr,a=t?.maxDataLength??Wr;function*c(){for(;e.byteLength>0;){if(n===P.LENGTH)try{if(o=i(e),o<0)throw(0,H.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,H.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let h=i.bytes;e.consume(h),t?.onLength!=null&&t.onLength(o),n=P.DATA}catch(h){if(h instanceof RangeError){if(e.byteLength>s)throw(0,H.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw h}if(n===P.DATA){if(e.byteLength<o)break;let h=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(h),yield h,n=P.LENGTH}}}return wt(r)?async function*(){for await(let h of r)e.append(h),yield*c();if(e.byteLength>0)throw(0,H.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,H.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Gt.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Gt(n,{...t??{},onLength:i=>{e=i}})};var yt=class extends Error{code;constructor(t,e){super(t),this.code=e}},je=r=>bt(r);je.bytes=0;function He(r,t={}){let e=Ce(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=F(t.maxDataLength)),{read:async o=>{let i=-1,s=new A,a=t?.lengthDecoder??je;for(;;){s.append(await e.read(1,o));try{i=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new yt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new yt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(rt.single(o,t),i)},writeV:async(o,i)=>{let s=new A(...o.map(a=>rt.single(a,t)));await e.write(s,i)},unwrap:()=>e.unwrap()}}function $t(r,t){let e=He(r,t),n={read:async(o,i)=>{let s=await e.read(i);return o.decode(s)},write:async(o,i,s)=>{await e.write(i.encode(o),s)},writeV:async(o,i,s)=>{await e.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}function Et(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Kt={};y(Kt,{base10:()=>rn});function Qr(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(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 w=0,k=0,L=0,T=d.length;L!==T&&d[L]===0;)L++,w++;for(var R=(T-L)*l+1>>>0,E=new Uint8Array(R);L!==T;){for(var D=d[L],v=0,S=R-1;(D!==0||v<k)&&S!==-1;S--,v++)D+=256*E[S]>>>0,E[S]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");k=v,L++}for(var B=R-k;B!==R&&E[B]===0;)B++;for(var lt=c.repeat(w);B<R;++B)lt+=r.charAt(E[B]);return lt}function b(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var w=0;if(d[w]!==" "){for(var k=0,L=0;d[w]===c;)k++,w++;for(var T=(d.length-w)*h+1>>>0,R=new Uint8Array(T);d[w];){var E=e[d.charCodeAt(w)];if(E===255)return;for(var D=0,v=T-1;(E!==0||D<L)&&v!==-1;v--,D++)E+=a*R[v]>>>0,R[v]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");L=D,w++}if(d[w]!==" "){for(var S=T-L;S!==T&&R[S]===0;)S++;for(var B=new Uint8Array(k+(T-S)),lt=k;S!==T;)B[lt++]=R[S++];return B}}}function ut(d){var w=b(d);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:b,decode:ut}}var Zr=Qr,Yr=Zr,qe=Yr;var rs=new Uint8Array(0);var Ke=(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},_=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")};var We=r=>new TextEncoder().encode(r),Je=r=>new TextDecoder().decode(r);var Xt=class{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")}},jt=class{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 Ze(this,t)}},Ht=class{constructor(t){this.decoders=t}or(t){return Ze(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ze=(r,t)=>new Ht({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),qt=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xt(t,e,n),this.decoder=new jt(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},q=({name:r,prefix:t,encode:e,decode:n})=>new qt(r,t,e,n),C=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=qe(e,t);return q({prefix:r,name:t,encode:n,decode:i=>_(o(i))})},tn=(r,t,e,n)=>{let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,h=0;for(let l=0;l<i;++l){let u=o[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,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},en=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},p=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>q({prefix:t,name:r,encode(o){return en(o,n,e)},decode(o){return tn(o,n,e,r)}});var rn=C({prefix:"9",name:"base10",alphabet:"0123456789"});var Wt={};y(Wt,{base16:()=>nn,base16upper:()=>on});var nn=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),on=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jt={};y(Jt,{base2:()=>sn});var sn=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qt={};y(Qt,{base256emoji:()=>un});var Ye=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}"),an=Ye.reduce((r,t,e)=>(r[e]=t,r),[]),cn=Ye.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function hn(r){return r.reduce((t,e)=>(t+=an[e],t),"")}function fn(r){let t=[];for(let e of r){let n=cn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var un=q({prefix:"\u{1F680}",name:"base256emoji",encode:hn,decode:fn});var Zt={};y(Zt,{base32:()=>K,base32hex:()=>gn,base32hexpad:()=>bn,base32hexpadupper:()=>wn,base32hexupper:()=>mn,base32pad:()=>dn,base32padupper:()=>pn,base32upper:()=>ln,base32z:()=>xn});var K=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ln=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),dn=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pn=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),gn=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),mn=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bn=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wn=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xn=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yt={};y(Yt,{base36:()=>yn,base36upper:()=>En});var yn=C({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),En=C({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var te={};y(te,{base58btc:()=>I,base58flickr:()=>An});var I=C({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),An=C({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ee={};y(ee,{base64:()=>Ln,base64pad:()=>Sn,base64url:()=>Un,base64urlpad:()=>Nn});var Ln=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sn=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Un=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Nn=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var re={};y(re,{base8:()=>Tn});var Tn=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ne={};y(ne,{identity:()=>Rn});var Rn=q({prefix:"\0",name:"identity",encode:r=>Je(r),decode:r=>We(r)});var bs=new TextEncoder,ws=new TextDecoder;var ie={};y(ie,{identity:()=>Qn});var Bn=rr,tr=128,On=127,Fn=~On,_n=Math.pow(2,31);function rr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=_n;)t[e++]=r&255|tr,r/=128;for(;r&Fn;)t[e++]=r&255|tr,r>>>=7;return t[e]=r|0,rr.bytes=e-n+1,t}var vn=oe,Cn=128,er=127;function oe(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw oe.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&er)<<o:(s&er)*Math.pow(2,o),o+=7}while(s>=Cn);return oe.bytes=i-n,e}var Mn=Math.pow(2,7),kn=Math.pow(2,14),Vn=Math.pow(2,21),Pn=Math.pow(2,28),Gn=Math.pow(2,35),zn=Math.pow(2,42),$n=Math.pow(2,49),Xn=Math.pow(2,56),jn=Math.pow(2,63),Hn=function(r){return r<Mn?1:r<kn?2:r<Vn?3:r<Pn?4:r<Gn?5:r<zn?6:r<$n?7:r<Xn?8:r<jn?9:10},qn={encode:Bn,decode:vn,encodingLength:Hn},Kn=qn,nt=Kn;var ot=(r,t=0)=>[nt.decode(r,t),nt.decode.bytes],W=(r,t,e=0)=>(nt.encode(r,t,e),t),J=r=>nt.encodingLength(r);var G=(r,t)=>{let e=t.byteLength,n=J(r),o=n+J(e),i=new Uint8Array(o+e);return W(r,i,0),W(e,i,n),i.set(t,o),new Q(r,e,t,i)},nr=r=>{let t=_(r),[e,n]=ot(t),[o,i]=ot(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Q(e,o,s,t)},or=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ke(r.bytes,e.bytes)}},Q=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var ir=0,Wn="identity",sr=_,Jn=r=>G(ir,sr(r)),Qn={code:ir,name:Wn,encode:sr,digest:Jn};var ce={};y(ce,{sha256:()=>Zn,sha512:()=>Yn});var ae=({name:r,code:t,encode:e})=>new se(r,t,e),se=class{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?G(this.code,e):e.then(n=>G(this.code,n))}else throw Error("Unknown type, must be binary type")}};var cr=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),Zn=ae({name:"sha2-256",code:18,encode:cr("SHA-256")}),Yn=ae({name:"sha2-512",code:19,encode:cr("SHA-512")});var hr=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return eo(e,he(r),t||I.encoder);default:return ro(e,he(r),t||K.encoder)}};var fr=new WeakMap,he=r=>{let t=fr.get(r);if(t==null){let e=new Map;return fr.set(r,e),e}return t},Lt=class r{constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==st)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==no)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=G(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&&t.code===n.code&&t.version===n.version&&or(t.multihash,n.multihash)}toString(t){return hr(this,t)}toJSON(){return{"/":hr(this)}}link(){return this}get[Symbol.toStringTag](){return"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:o,multihash:i,bytes:s}=e;return new r(n,o,i,s||ur(n,o,i.bytes))}else if(e[oo]===!0){let{version:n,multihash:o,code:i}=e,s=nr(o);return r.create(n,i,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!==st)throw new Error(`Version 0 CID must use dag-pb (code: ${st}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ur(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,st,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=_(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new Q(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,b]=ot(t.subarray(e));return e+=b,u},o=n(),i=st;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),h=e+c,l=h-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:h}}static parse(t,e){let[n,o]=to(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return he(i).set(n,t),i}},to=(r,t)=>{switch(r[0]){case"Q":{let e=t||I;return[I.prefix,e.decode(`${I.prefix}${r}`)]}case I.prefix:{let e=t||I;return[I.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)]}}},eo=(r,t,e)=>{let{prefix:n}=e;if(n!==I.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},ro=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},st=112,no=18,ur=(r,t,e)=>{let n=J(r),o=n+J(t),i=new Uint8Array(o+e.byteLength);return W(r,i,0),W(t,i,n),i.set(e,o),i},oo=Symbol.for("@ipld/js-cid/CID");var Z={...ne,...Jt,...re,...Kt,...Wt,...Zt,...Yt,...te,...ee,...Qt},_s={...ce,...ie};function lr(r=0){return globalThis.Buffer?.allocUnsafe!=null?Et(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function pr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var dr=pr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),fe=pr("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=lr(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),io={utf8:dr,"utf-8":dr,hex:Z.base16,latin1:fe,ascii:fe,binary:fe,...Z},St=io;function gr(r,t="utf8"){let e=St[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Et(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function mr(r,t="utf8"){let e=St[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 br="0.0.1",wr="fetch";var ue=new Float32Array([-0]),M=new Uint8Array(ue.buffer);function xr(r,t,e){ue[0]=r,t[e]=M[0],t[e+1]=M[1],t[e+2]=M[2],t[e+3]=M[3]}function yr(r,t){return M[0]=r[t],M[1]=r[t+1],M[2]=r[t+2],M[3]=r[t+3],ue[0]}var le=new Float64Array([-0]),m=new Uint8Array(le.buffer);function Er(r,t,e){le[0]=r,t[e]=m[0],t[e+1]=m[1],t[e+2]=m[2],t[e+3]=m[3],t[e+4]=m[4],t[e+5]=m[5],t[e+6]=m[6],t[e+7]=m[7]}function Ar(r,t){return m[0]=r[t],m[1]=r[t+1],m[2]=r[t+2],m[3]=r[t+3],m[4]=r[t+4],m[5]=r[t+5],m[6]=r[t+6],m[7]=r[t+7],le[0]}var so=BigInt(Number.MAX_SAFE_INTEGER),ao=BigInt(Number.MIN_SAFE_INTEGER),x=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return z;if(t<so&&t>ao)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Lr&&(o=0n,++n>Lr&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return z;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):z}},z=new x(0,0);z.toBigInt=function(){return 0n};z.zzEncode=z.zzDecode=function(){return this};z.length=function(){return 1};var Lr=4294967296n;function Sr(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ur(r,t,e){if(e-t<1)return"";let o,i=[],s=0,a;for(;t<e;)a=r[t++],a<128?i[s++]=a:a>191&&a<224?i[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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function de(r,t,e){let n=e,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function U(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ut(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var pe=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,U(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 U(this,4);return Ut(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw U(this,4);return Ut(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw U(this,4);let t=yr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw U(this,4);let t=Ar(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw U(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ur(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw U(this,t);this.pos+=t}else do if(this.pos>=this.len)throw U(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 x(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 U(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 U(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 U(this,8);let t=Ut(this.buf,this.pos+=4),e=Ut(this.buf,this.pos+=4);return new x(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 ge(r){return new pe(r instanceof Uint8Array?r:r.subarray())}function Nt(r,t){let e=ge(r);return t.decode(e)}function Tt(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function $(r=0){return globalThis.Buffer?.allocUnsafe!=null?Tt(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Rr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Tr=Rr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),me=Rr("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=$(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),co={utf8:Tr,"utf-8":Tr,hex:Z.base16,latin1:me,ascii:me,binary:me,...Z},Dr=co;function Ir(r,t="utf8"){let e=Dr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Tt(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function be(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return $(s);o+s>t&&(n=$(t),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var X=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function we(){}var ye=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ho=be();function fo(r){return globalThis.Buffer!=null?$(r):ho(r)}var ht=class{len;head;tail;states;constructor(){this.len=0,this.head=new X(we,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new X(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ee((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(at,10,x.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=x.fromBigInt(t);return this._push(at,e.length(),e)}uint64Number(t){let e=x.fromNumber(t);return this._push(at,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=x.fromBigInt(t).zzEncode();return this._push(at,e.length(),e)}sint64Number(t){let e=x.fromNumber(t).zzEncode();return this._push(at,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(xe,1,t?1:0)}fixed32(t){return this._push(ct,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=x.fromBigInt(t);return this._push(ct,4,e.lo)._push(ct,4,e.hi)}fixed64Number(t){let e=x.fromNumber(t);return this._push(ct,4,e.lo)._push(ct,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(xr,4,t)}double(t){return this._push(Er,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(xe,1,0):this.uint32(e)._push(lo,e,t)}string(t){let e=Sr(t);return e!==0?this.uint32(e)._push(de,e,t):this._push(xe,1,0)}fork(){return this.states=new ye(this),this.head=this.tail=new X(we,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new X(we,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=fo(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function xe(r,t,e){t[e]=r&255}function uo(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ee=class extends X{next;constructor(t,e){super(uo,t,e),this.next=void 0}};function at(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 ct(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 lo(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ht.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(po,t,r),this},ht.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(go,t,r),this});function po(r,t,e){t.set(r,e)}function go(r,t,e){r.length<40?de(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Ir(r),e)}function Ae(){return new ht}function Rt(r,t){let e=Ae();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 Dt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Le(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Dt("enum",Y.VARINT,e,n)}function It(r,t){return Dt("message",Y.LENGTH_DELIMITED,r,t)}var ft;(function(r){let t;r.codec=()=>(t==null&&(t=It((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.identifier!=null&&e.identifier!==""&&(n.uint32(10),n.string(e.identifier)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={identifier:""},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.identifier=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>Rt(e,r.codec()),r.decode=e=>Nt(e,r.codec())})(ft||(ft={}));var N;(function(r){let t;(function(o){o.OK="OK",o.NOT_FOUND="NOT_FOUND",o.ERROR="ERROR"})(t=r.StatusCode||(r.StatusCode={}));let e;(function(o){o[o.OK=0]="OK",o[o.NOT_FOUND=1]="NOT_FOUND",o[o.ERROR=2]="ERROR"})(e||(e={})),function(o){o.codec=()=>Le(e)}(t=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=It((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.status!=null&&e[o.status]!==0&&(i.uint32(8),r.StatusCode.codec().encode(o.status,i)),o.data!=null&&o.data.byteLength>0&&(i.uint32(18),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={status:t.OK,data:new Uint8Array(0)},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.status=r.StatusCode.codec().decode(o);break;case 2:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>Rt(o,r.codec()),r.decode=o=>Nt(o,r.codec())})(N||(N={}));var Br=1e4,Bt=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"}/${wr}/${br}`,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 o=await this.components.connectionManager.openConnection(t,n),i=n.signal,s,a=()=>{};if(i==null){let c=this.init.timeout??Br;this.log("using default timeout of %d ms",c),i=AbortSignal.timeout(c),Ie(1/0,i)}try{s=await o.newStream(this.protocol,{signal:i}),a=()=>{s?.abort(new V("fetch timeout",Te))},i.addEventListener("abort",a,{once:!0}),this.log("fetch %s",e);let c=$t(s);await c.write({identifier:e},ft,n);let h=await c.read(N,n);switch(await c.unwrap().close(n),h.status){case N.StatusCode.OK:return this.log("received status for %s ok",e),h.data;case N.StatusCode.NOT_FOUND:{this.log("received status for %s not found",e);return}case N.StatusCode.ERROR:{this.log("received status for %s error",e);let l=mr(h.data);throw new V("Error in fetch protocol response: "+l,Re)}default:throw this.log("received status for %s unknown",e),new V("Unknown response status",De)}}catch(c){throw s?.abort(c),c}finally{i.removeEventListener("abort",a),s!=null&&await s.close()}}async handleMessage(t){let{stream:e}=t,n=AbortSignal.timeout(this.init.timeout??Br);try{let o=$t(e),i=await o.read(ft,{signal:n}),s,a=this._getLookupFunction(i.identifier);if(a!=null){this.log("look up data with identifier %s",i.identifier);let c=await a(i.identifier);c!=null?(this.log("sending status for %s ok",i.identifier),s={status:N.StatusCode.OK,data:c}):(this.log("sending status for %s not found",i.identifier),s={status:N.StatusCode.NOT_FOUND,data:new Uint8Array(0)})}else{this.log("sending status for %s error",i.identifier);let c=gr(`No lookup function registered for key: ${i.identifier}`);s={status:N.StatusCode.ERROR,data:c}}await o.write(s,N,{signal:n}),await o.unwrap().close({signal:n})}catch(o){this.log("error answering fetch request",o),e.abort(o)}}_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 V(`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 mo(r={}){return t=>new Bt(t,r)}return Vr(bo);})();
|
|
2
|
+
"use strict";var Libp2PFetch=(()=>{var Cn=Object.create;var vt=Object.defineProperty;var Rn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var On=Object.getPrototypeOf,Fn=Object.prototype.hasOwnProperty;var Mn=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),b=(r,t)=>{for(var e in t)vt(r,e,{get:t[e],enumerable:!0})},ir=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bn(t))!Fn.call(r,o)&&o!==e&&vt(r,o,{get:()=>t[o],enumerable:!(n=Rn(t,o))||n.enumerable});return r};var kn=(r,t,e)=>(e=r!=null?Cn(On(r)):{},ir(t||!r||!r.__esModule?vt(e,"default",{value:r,enumerable:!0}):e,r)),_n=r=>ir(vt({},"__esModule",{value:!0}),r);var Sr=Mn((qa,Ar)=>{"use strict";function Er(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Xn(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 Er(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Er(new o,e)}}Ar.exports=Xn});var As={};b(As,{fetch:()=>Es});var Ls=Symbol.for("@libp2p/connection");var Us=Symbol.for("@libp2p/content-routing");var Ts=Symbol.for("@libp2p/peer-discovery");var Cs=Symbol.for("@libp2p/peer-id");var Bs=Symbol.for("@libp2p/peer-routing");var sr;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(sr||(sr={}));var ks=Symbol.for("@libp2p/transport");var ar;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(ar||(ar={}));var q=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var cr="ERR_TIMEOUT",hr="ERR_INVALID_PARAMETERS";var fr="ERR_INVALID_MESSAGE";var qt=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},zs=globalThis.CustomEvent??qt;var ur=(r,...t)=>{try{[...t]}catch{}};function X(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function _(r=0){return globalThis.Buffer?.alloc!=null?X(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function I(r=0){return globalThis.Buffer?.allocUnsafe!=null?X(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Xt(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=I(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return X(e)}function lr(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 pr=Symbol.for("@achingbrain/uint8arraylist");function dr(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Ut(r){return!!r?.[pr]}var R=class r{bufs;length;[pr]=!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(Ut(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(Ut(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=dr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=dr(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(Ut(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:o}=this._subList(t,e);return Xt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Xt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_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=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=e>a&&e<=c;if(u&&f){if(t===a&&e===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(f){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(!Ut(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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=e;l<=c;l+=f){f=0;for(let L=u;L>=0;L--){let Z=this.get(l+L);if(n[L]!==Z){f=Math.max(1,L-a[Z]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=I(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 o=_(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,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 o=_(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,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 o=_(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,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=I(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 o=_(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,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 o=_(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,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 o=_(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,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 o=_(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,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 o=_(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,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(!lr(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((o,i)=>o+i.byteLength,0)),n.length=e,n}};function Y(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Nt=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 mr(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Nt(e?.errorMessage,e?.errorCode));let n,o=new Nt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ht=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=Y(),this.haveNext=Y()}[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=Y(),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=Y(),await mr(this.needNext.promise,e?.signal,e)}};function br(){return new Ht}var Dt=class extends Error{code;constructor(t,e){super(t),this.code=e}},Jt=class extends Dt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function gr(r,t){let e=br();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 o=new R;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((f,l)=>{c=()=>{l(new Jt("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:l,value:L}=await Promise.race([n.next(),u]);return l===!0?new R:L}for(;o.byteLength<s;){let{value:l,done:L}=await Promise.race([n.next(),u]);if(L===!0)throw new Dt("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(l)}let f=o.sublist(0,s);return o.consume(s),f}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(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}function wr(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function xr(r=0){return globalThis.Buffer?.allocUnsafe!=null?wr(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Vn=Math.pow(2,7),zn=Math.pow(2,14),Pn=Math.pow(2,21),Kt=Math.pow(2,28),Wt=Math.pow(2,35),Qt=Math.pow(2,42),Zt=Math.pow(2,49),d=128,N=127;function V(r){if(r<Vn)return 1;if(r<zn)return 2;if(r<Pn)return 3;if(r<Kt)return 4;if(r<Wt)return 5;if(r<Qt)return 6;if(r<Zt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Gn(r,t,e=0){switch(V(r)){case 8:t[e++]=r&255|d,r/=128;case 7:t[e++]=r&255|d,r/=128;case 6:t[e++]=r&255|d,r/=128;case 5:t[e++]=r&255|d,r/=128;case 4:t[e++]=r&255|d,r>>>=7;case 3:t[e++]=r&255|d,r>>>=7;case 2:t[e++]=r&255|d,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function $n(r,t,e=0){switch(V(r)){case 8:t.set(e++,r&255|d),r/=128;case 7:t.set(e++,r&255|d),r/=128;case 6:t.set(e++,r&255|d),r/=128;case 5:t.set(e++,r&255|d),r/=128;case 4:t.set(e++,r&255|d),r>>>=7;case 3:t.set(e++,r&255|d),r>>>=7;case 2:t.set(e++,r&255|d),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function jn(r,t){let e=r[t],n=0;if(n+=e&N,e<d||(e=r[t+1],n+=(e&N)<<7,e<d)||(e=r[t+2],n+=(e&N)<<14,e<d)||(e=r[t+3],n+=(e&N)<<21,e<d)||(e=r[t+4],n+=(e&N)*Kt,e<d)||(e=r[t+5],n+=(e&N)*Wt,e<d)||(e=r[t+6],n+=(e&N)*Qt,e<d)||(e=r[t+7],n+=(e&N)*Zt,e<d))return n;throw new RangeError("Could not decode varint")}function qn(r,t){let e=r.get(t),n=0;if(n+=e&N,e<d||(e=r.get(t+1),n+=(e&N)<<7,e<d)||(e=r.get(t+2),n+=(e&N)<<14,e<d)||(e=r.get(t+3),n+=(e&N)<<21,e<d)||(e=r.get(t+4),n+=(e&N)*Kt,e<d)||(e=r.get(t+5),n+=(e&N)*Wt,e<d)||(e=r.get(t+6),n+=(e&N)*Qt,e<d)||(e=r.get(t+7),n+=(e&N)*Zt,e<d))return n;throw new RangeError("Could not decode varint")}function yr(r,t,e=0){return t==null&&(t=xr(V(r))),t instanceof Uint8Array?Gn(r,t,e):$n(r,t,e)}function Tt(r,t=0){return r instanceof Uint8Array?jn(r,t):qn(r,t)}function It(r){return r[Symbol.asyncIterator]!=null}var Ct=r=>{let t=V(r),e=I(t);return yr(r,e),Ct.bytes=t,e};Ct.bytes=0;function lt(r,t){t=t??{};let e=t.lengthEncoder??Ct;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return It(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}lt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Ct;return new R(e(r.byteLength),r)};var tt=kn(Sr(),1);var Hn=8,Jn=1024*1024*4,H;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(H||(H={}));var ee=r=>{let t=Tt(r);return ee.bytes=V(t),t};ee.bytes=0;function te(r,t){let e=new R,n=H.LENGTH,o=-1,i=t?.lengthDecoder??ee,s=t?.maxLengthLength??Hn,a=t?.maxDataLength??Jn;function*c(){for(;e.byteLength>0;){if(n===H.LENGTH)try{if(o=i(e),o<0)throw(0,tt.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,tt.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=i.bytes;e.consume(u),t?.onLength!=null&&t.onLength(o),n=H.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>s)throw(0,tt.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===H.DATA){if(e.byteLength<o)break;let u=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(u),yield u,n=H.LENGTH}}}return It(r)?async function*(){for await(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw(0,tt.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw(0,tt.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}te.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return te(n,{...t??{},onLength:i=>{e=i}})};var Rt=class extends Error{code;constructor(t,e){super(t),this.code=e}},Lr=r=>Tt(r);Lr.bytes=0;function vr(r,t={}){let e=gr(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=V(t.maxDataLength)),{read:async o=>{let i=-1,s=new R,a=t?.lengthDecoder??Lr;for(;;){s.append(await e.read(1,o));try{i=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new Rt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new Rt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(lt.single(o,t),i)},writeV:async(o,i)=>{let s=new R(...o.map(a=>lt.single(a,t)));await e.write(s,i)},unwrap:()=>e.unwrap()}}function re(r,t){let e=vr(r,t),n={read:async(o,i)=>{let s=await e.read(i);return o.decode(s)},write:async(o,i,s)=>{await e.write(i.encode(o),s)},writeV:async(o,i,s)=>{await e.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}function Bt(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var ae={};b(ae,{base10:()=>eo});var nc=new Uint8Array(0);function Ur(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 z(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 Nr(r){return new TextEncoder().encode(r)}function Dr(r){return new TextDecoder().decode(r)}function Wn(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var p=0,T=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,p++;for(var A=(E-g)*f+1>>>0,m=new Uint8Array(A);g!==E;){for(var S=h[g],U=0,w=A-1;(S!==0||U<T)&&w!==-1;w--,U++)S+=256*m[w]>>>0,m[w]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");T=U,g++}for(var v=A-T;v!==A&&m[v]===0;)v++;for(var k=c.repeat(p);v<A;++v)k+=r.charAt(m[v]);return k}function L(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var p=0;if(h[p]!==" "){for(var T=0,g=0;h[p]===c;)T++,p++;for(var E=(h.length-p)*u+1>>>0,A=new Uint8Array(E);h[p];){var m=e[h.charCodeAt(p)];if(m===255)return;for(var S=0,U=E-1;(m!==0||S<g)&&U!==-1;U--,S++)m+=a*A[U]>>>0,A[U]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");g=S,p++}if(h[p]!==" "){for(var w=E-g;w!==E&&A[w]===0;)w++;for(var v=new Uint8Array(T+(E-w)),k=T;w!==E;)v[k++]=A[w++];return v}}}function Z(h){var p=L(h);if(p)return p;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:L,decode:Z}}var Qn=Wn,Zn=Qn,Ir=Zn;var ne=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")}},oe=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 Cr(this,t)}},ie=class{decoders;constructor(t){this.decoders=t}or(t){return Cr(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 Cr(r,t){return new ie({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var se=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new ne(t,e,n),this.decoder=new oe(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function et({name:r,prefix:t,encode:e,decode:n}){return new se(r,t,e,n)}function G({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ir(e,r);return et({prefix:t,name:r,encode:n,decode:i=>z(o(i))})}function Yn(r,t,e,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,u=0;for(let f=0;f<i;++f){let l=o[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function to(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i}function x({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return et({prefix:t,name:r,encode(o){return to(o,n,e)},decode(o){return Yn(o,n,e,r)}})}var eo=G({prefix:"9",name:"base10",alphabet:"0123456789"});var ce={};b(ce,{base16:()=>ro,base16upper:()=>no});var ro=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),no=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var he={};b(he,{base2:()=>oo});var oo=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fe={};b(fe,{base256emoji:()=>ho});var Rr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),io=Rr.reduce((r,t,e)=>(r[e]=t,r),[]),so=Rr.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function ao(r){return r.reduce((t,e)=>(t+=io[e],t),"")}function co(r){let t=[];for(let e of r){let n=so[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var ho=et({prefix:"\u{1F680}",name:"base256emoji",encode:ao,decode:co});var ue={};b(ue,{base32:()=>rt,base32hex:()=>po,base32hexpad:()=>bo,base32hexpadupper:()=>go,base32hexupper:()=>mo,base32pad:()=>uo,base32padupper:()=>lo,base32upper:()=>fo,base32z:()=>wo});var rt=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),fo=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),uo=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lo=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),po=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),mo=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bo=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),go=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wo=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var le={};b(le,{base36:()=>xo,base36upper:()=>yo});var xo=G({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),yo=G({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var de={};b(de,{base58btc:()=>F,base58flickr:()=>Eo});var F=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Eo=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var pe={};b(pe,{base64:()=>Ao,base64pad:()=>So,base64url:()=>Lo,base64urlpad:()=>vo});var Ao=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),So=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Lo=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vo=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var me={};b(me,{base8:()=>Uo});var Uo=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var be={};b(be,{identity:()=>No});var No=et({prefix:"\0",name:"identity",encode:r=>Dr(r),decode:r=>Nr(r)});var xc=new TextEncoder,yc=new TextDecoder;var we={};b(we,{identity:()=>Wo});var Io=Fr,Br=128,Co=127,Ro=~Co,Bo=Math.pow(2,31);function Fr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Bo;)t[e++]=r&255|Br,r/=128;for(;r&Ro;)t[e++]=r&255|Br,r>>>=7;return t[e]=r|0,Fr.bytes=e-n+1,t}var Oo=ge,Fo=128,Or=127;function ge(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw ge.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Or)<<o:(s&Or)*Math.pow(2,o),o+=7}while(s>=Fo);return ge.bytes=i-n,e}var Mo=Math.pow(2,7),ko=Math.pow(2,14),_o=Math.pow(2,21),Vo=Math.pow(2,28),zo=Math.pow(2,35),Po=Math.pow(2,42),Go=Math.pow(2,49),$o=Math.pow(2,56),jo=Math.pow(2,63),qo=function(r){return r<Mo?1:r<ko?2:r<_o?3:r<Vo?4:r<zo?5:r<Po?6:r<Go?7:r<$o?8:r<jo?9:10},Xo={encode:Io,decode:Oo,encodingLength:qo},Ho=Xo,dt=Ho;function pt(r,t=0){return[dt.decode(r,t),dt.decode.bytes]}function nt(r,t,e=0){return dt.encode(r,t,e),t}function ot(r){return dt.encodingLength(r)}function J(r,t){let e=t.byteLength,n=ot(r),o=n+ot(e),i=new Uint8Array(o+e);return nt(r,i,0),nt(e,i,n),i.set(t,o),new it(r,e,t,i)}function Mr(r){let t=z(r),[e,n]=pt(t),[o,i]=pt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new it(e,o,s,t)}function kr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ur(r.bytes,e.bytes)}}var it=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var _r=0,Jo="identity",Vr=z;function Ko(r){return J(_r,Vr(r))}var Wo={code:_r,name:Jo,encode:Vr,digest:Ko};var Ee={};b(Ee,{sha256:()=>Qo,sha512:()=>Zo});function ye({name:r,code:t,encode:e}){return new xe(r,t,e)}var xe=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?J(this.code,e):e.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Pr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qo=ye({name:"sha2-256",code:18,encode:Pr("SHA-256")}),Zo=ye({name:"sha2-512",code:19,encode:Pr("SHA-512")});function Gr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ti(e,Ae(r),t??F.encoder);default:return ei(e,Ae(r),t??rt.encoder)}}var $r=new WeakMap;function Ae(r){let t=$r.get(r);if(t==null){let e=new Map;return $r.set(r,e),e}return t}var Ft=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==bt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ri)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=J(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&kr(t.multihash,n.multihash)}toString(t){return Gr(this,t)}toJSON(){return{"/":Gr(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:o,multihash:i,bytes:s}=e;return new r(n,o,i,s??jr(n,o,i.bytes))}else if(e[ni]===!0){let{version:n,multihash:o,code:i}=e,s=Mr(o);return r.create(n,i,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!==bt)throw new Error(`Version 0 CID must use dag-pb (code: ${bt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=jr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,bt,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,o=z(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new it(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,L]=pt(t.subarray(e));return e+=L,l},o=n(),i=bt;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),u=e+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,o]=Yo(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ae(i).set(n,t),i}};function Yo(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case rt.prefix:{let e=t??rt;return[rt.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 ti(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function ei(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var bt=112,ri=18;function jr(r,t,e){let n=ot(r),o=n+ot(t),i=new Uint8Array(o+e.byteLength);return nt(r,i,0),nt(t,i,n),i.set(e,o),i}var ni=Symbol.for("@ipld/js-cid/CID");var Se={...be,...he,...me,...ae,...ce,...ue,...le,...de,...pe,...fe},Pc={...Ee,...we};function qr(r=0){return globalThis.Buffer?.allocUnsafe!=null?Bt(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Hr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Xr=Hr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Le=Hr("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=qr(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),oi={utf8:Xr,"utf-8":Xr,hex:Se.base16,latin1:Le,ascii:Le,binary:Le,...Se},Mt=oi;function Jr(r,t="utf8"){let e=Mt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Bt(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Kr(r,t="utf8"){let e=Mt[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 Wr="0.0.1",Qr="fetch";var ve=new Float32Array([-0]),$=new Uint8Array(ve.buffer);function Zr(r,t,e){ve[0]=r,t[e]=$[0],t[e+1]=$[1],t[e+2]=$[2],t[e+3]=$[3]}function Yr(r,t){return $[0]=r[t],$[1]=r[t+1],$[2]=r[t+2],$[3]=r[t+3],ve[0]}var Ue=new Float64Array([-0]),D=new Uint8Array(Ue.buffer);function tn(r,t,e){Ue[0]=r,t[e]=D[0],t[e+1]=D[1],t[e+2]=D[2],t[e+3]=D[3],t[e+4]=D[4],t[e+5]=D[5],t[e+6]=D[6],t[e+7]=D[7]}function en(r,t){return D[0]=r[t],D[1]=r[t+1],D[2]=r[t+2],D[3]=r[t+3],D[4]=r[t+4],D[5]=r[t+5],D[6]=r[t+6],D[7]=r[t+7],Ue[0]}var ii=BigInt(Number.MAX_SAFE_INTEGER),si=BigInt(Number.MIN_SAFE_INTEGER),C=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 K;if(t<ii&&t>si)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>rn&&(o=0n,++n>rn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return K;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):K}},K=new C(0,0);K.toBigInt=function(){return 0n};K.zzEncode=K.zzDecode=function(){return this};K.length=function(){return 1};var rn=4294967296n;function nn(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 on(r,t,e){if(e-t<1)return"";let o,i=[],s=0,a;for(;t<e;)a=r[t++],a<128?i[s++]=a:a>191&&a<224?i[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,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ne(r,t,e){let n=e,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function B(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function kt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var De=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,B(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 B(this,4);return kt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw B(this,4);return kt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw B(this,4);let t=Yr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw B(this,4);let t=en(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 B(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return on(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw B(this,t);this.pos+=t}else do if(this.pos>=this.len)throw B(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 C(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 B(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 B(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 B(this,8);let t=kt(this.buf,this.pos+=4),e=kt(this.buf,this.pos+=4);return new C(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 Te(r){return new De(r instanceof Uint8Array?r:r.subarray())}function _t(r,t){let e=Te(r);return t.decode(e)}var Oe={};b(Oe,{base10:()=>li});function ai(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 o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var p=0,T=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,p++;for(var A=(E-g)*f+1>>>0,m=new Uint8Array(A);g!==E;){for(var S=h[g],U=0,w=A-1;(S!==0||U<T)&&w!==-1;w--,U++)S+=256*m[w]>>>0,m[w]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");T=U,g++}for(var v=A-T;v!==A&&m[v]===0;)v++;for(var k=c.repeat(p);v<A;++v)k+=r.charAt(m[v]);return k}function L(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var p=0;if(h[p]!==" "){for(var T=0,g=0;h[p]===c;)T++,p++;for(var E=(h.length-p)*u+1>>>0,A=new Uint8Array(E);h[p];){var m=e[h.charCodeAt(p)];if(m===255)return;for(var S=0,U=E-1;(m!==0||S<g)&&U!==-1;U--,S++)m+=a*A[U]>>>0,A[U]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");g=S,p++}if(h[p]!==" "){for(var w=E-g;w!==E&&A[w]===0;)w++;for(var v=new Uint8Array(T+(E-w)),k=T;w!==E;)v[k++]=A[w++];return v}}}function Z(h){var p=L(h);if(p)return p;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:L,decode:Z}}var ci=ai,hi=ci,an=hi;var ch=new Uint8Array(0);var cn=(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},P=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")};var hn=r=>new TextEncoder().encode(r),fn=r=>new TextDecoder().decode(r);var Ie=class{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")}},Ce=class{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 ln(this,t)}},Re=class{constructor(t){this.decoders=t}or(t){return ln(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},ln=(r,t)=>new Re({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),Be=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ie(t,e,n),this.decoder=new Ce(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},st=({name:r,prefix:t,encode:e,decode:n})=>new Be(r,t,e,n),j=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=an(e,t);return st({prefix:r,name:t,encode:n,decode:i=>P(o(i))})},fi=(r,t,e,n)=>{let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,u=0;for(let f=0;f<i;++f){let l=o[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},ui=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},y=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>st({prefix:t,name:r,encode(o){return ui(o,n,e)},decode(o){return fi(o,n,e,r)}});var li=j({prefix:"9",name:"base10",alphabet:"0123456789"});var Fe={};b(Fe,{base16:()=>di,base16upper:()=>pi});var di=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),pi=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Me={};b(Me,{base2:()=>mi});var mi=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ke={};b(ke,{base256emoji:()=>yi});var dn=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}"),bi=dn.reduce((r,t,e)=>(r[e]=t,r),[]),gi=dn.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function wi(r){return r.reduce((t,e)=>(t+=bi[e],t),"")}function xi(r){let t=[];for(let e of r){let n=gi[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var yi=st({prefix:"\u{1F680}",name:"base256emoji",encode:wi,decode:xi});var _e={};b(_e,{base32:()=>at,base32hex:()=>Li,base32hexpad:()=>Ui,base32hexpadupper:()=>Ni,base32hexupper:()=>vi,base32pad:()=>Ai,base32padupper:()=>Si,base32upper:()=>Ei,base32z:()=>Di});var at=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ei=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ai=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Si=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Li=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vi=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ui=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ni=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Di=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ve={};b(Ve,{base36:()=>Ti,base36upper:()=>Ii});var Ti=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ii=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ze={};b(ze,{base58btc:()=>M,base58flickr:()=>Ci});var M=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ci=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Pe={};b(Pe,{base64:()=>Ri,base64pad:()=>Bi,base64url:()=>Oi,base64urlpad:()=>Fi});var Ri=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bi=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Oi=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fi=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ge={};b(Ge,{base8:()=>Mi});var Mi=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $e={};b($e,{identity:()=>ki});var ki=st({prefix:"\0",name:"identity",encode:r=>fn(r),decode:r=>hn(r)});var Sh=new TextEncoder,Lh=new TextDecoder;var qe={};b(qe,{identity:()=>ss});var zi=bn,pn=128,Pi=127,Gi=~Pi,$i=Math.pow(2,31);function bn(r,t,e){t=t||[],e=e||0;for(var n=e;r>=$i;)t[e++]=r&255|pn,r/=128;for(;r&Gi;)t[e++]=r&255|pn,r>>>=7;return t[e]=r|0,bn.bytes=e-n+1,t}var ji=je,qi=128,mn=127;function je(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw je.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&mn)<<o:(s&mn)*Math.pow(2,o),o+=7}while(s>=qi);return je.bytes=i-n,e}var Xi=Math.pow(2,7),Hi=Math.pow(2,14),Ji=Math.pow(2,21),Ki=Math.pow(2,28),Wi=Math.pow(2,35),Qi=Math.pow(2,42),Zi=Math.pow(2,49),Yi=Math.pow(2,56),ts=Math.pow(2,63),es=function(r){return r<Xi?1:r<Hi?2:r<Ji?3:r<Ki?4:r<Wi?5:r<Qi?6:r<Zi?7:r<Yi?8:r<ts?9:10},rs={encode:zi,decode:ji,encodingLength:es},ns=rs,gt=ns;var wt=(r,t=0)=>[gt.decode(r,t),gt.decode.bytes],ct=(r,t,e=0)=>(gt.encode(r,t,e),t),ht=r=>gt.encodingLength(r);var W=(r,t)=>{let e=t.byteLength,n=ht(r),o=n+ht(e),i=new Uint8Array(o+e);return ct(r,i,0),ct(e,i,n),i.set(t,o),new ft(r,e,t,i)},gn=r=>{let t=P(r),[e,n]=wt(t),[o,i]=wt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ft(e,o,s,t)},wn=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&cn(r.bytes,e.bytes)}},ft=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var xn=0,os="identity",yn=P,is=r=>W(xn,yn(r)),ss={code:xn,name:os,encode:yn,digest:is};var Je={};b(Je,{sha256:()=>as,sha512:()=>cs});var He=({name:r,code:t,encode:e})=>new Xe(r,t,e),Xe=class{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?W(this.code,e):e.then(n=>W(this.code,n))}else throw Error("Unknown type, must be binary type")}};var An=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),as=He({name:"sha2-256",code:18,encode:An("SHA-256")}),cs=He({name:"sha2-512",code:19,encode:An("SHA-512")});var Sn=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return fs(e,Ke(r),t||M.encoder);default:return us(e,Ke(r),t||at.encoder)}};var Ln=new WeakMap,Ke=r=>{let t=Ln.get(r);if(t==null){let e=new Map;return Ln.set(r,e),e}return t},zt=class r{constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==yt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ls)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=W(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&&t.code===n.code&&t.version===n.version&&wn(t.multihash,n.multihash)}toString(t){return Sn(this,t)}toJSON(){return{"/":Sn(this)}}link(){return this}get[Symbol.toStringTag](){return"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:o,multihash:i,bytes:s}=e;return new r(n,o,i,s||vn(n,o,i.bytes))}else if(e[ds]===!0){let{version:n,multihash:o,code:i}=e,s=gn(o);return r.create(n,i,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!==yt)throw new Error(`Version 0 CID must use dag-pb (code: ${yt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=vn(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,yt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=P(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new ft(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,L]=wt(t.subarray(e));return e+=L,l},o=n(),i=yt;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),u=e+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,o]=hs(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ke(i).set(n,t),i}},hs=(r,t)=>{switch(r[0]){case"Q":{let e=t||M;return[M.prefix,e.decode(`${M.prefix}${r}`)]}case M.prefix:{let e=t||M;return[M.prefix,e.decode(r)]}case at.prefix:{let e=t||at;return[at.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)]}}},fs=(r,t,e)=>{let{prefix:n}=e;if(n!==M.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},us=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},yt=112,ls=18,vn=(r,t,e)=>{let n=ht(r),o=n+ht(t),i=new Uint8Array(o+e.byteLength);return ct(r,i,0),ct(t,i,n),i.set(e,o),i},ds=Symbol.for("@ipld/js-cid/CID");var We={...$e,...Me,...Ge,...Oe,...Fe,..._e,...Ve,...ze,...Pe,...ke},zh={...Je,...qe};function Nn(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Un=Nn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qe=Nn("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=I(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ps={utf8:Un,"utf-8":Un,hex:We.base16,latin1:Qe,ascii:Qe,binary:Qe,...We},Dn=ps;function Tn(r,t="utf8"){let e=Dn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?X(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Ze(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return I(s);o+s>t&&(n=I(t),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var Q=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ye(){}var er=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ms=Ze();function bs(r){return globalThis.Buffer!=null?I(r):ms(r)}var St=class{len;head;tail;states;constructor(){this.len=0,this.head=new Q(Ye,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Q(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new rr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Et,10,C.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=C.fromBigInt(t);return this._push(Et,e.length(),e)}uint64Number(t){let e=C.fromNumber(t);return this._push(Et,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=C.fromBigInt(t).zzEncode();return this._push(Et,e.length(),e)}sint64Number(t){let e=C.fromNumber(t).zzEncode();return this._push(Et,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(tr,1,t?1:0)}fixed32(t){return this._push(At,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=C.fromBigInt(t);return this._push(At,4,e.lo)._push(At,4,e.hi)}fixed64Number(t){let e=C.fromNumber(t);return this._push(At,4,e.lo)._push(At,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(Zr,4,t)}double(t){return this._push(tn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(tr,1,0):this.uint32(e)._push(ws,e,t)}string(t){let e=nn(t);return e!==0?this.uint32(e)._push(Ne,e,t):this._push(tr,1,0)}fork(){return this.states=new er(this),this.head=this.tail=new Q(Ye,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Q(Ye,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=bs(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function tr(r,t,e){t[e]=r&255}function gs(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var rr=class extends Q{next;constructor(t,e){super(gs,t,e),this.next=void 0}};function Et(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function At(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 ws(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(St.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(xs,t,r),this},St.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ys,t,r),this});function xs(r,t,e){t.set(r,e)}function ys(r,t,e){r.length<40?Ne(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Tn(r),e)}function nr(){return new St}function Pt(r,t){let e=nr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ut;(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"})(ut||(ut={}));function Gt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function or(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Gt("enum",ut.VARINT,e,n)}function $t(r,t){return Gt("message",ut.LENGTH_DELIMITED,r,t)}var Lt;(function(r){let t;r.codec=()=>(t==null&&(t=$t((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.identifier!=null&&e.identifier!==""&&(n.uint32(10),n.string(e.identifier)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={identifier:""},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.identifier=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>Pt(e,r.codec()),r.decode=e=>_t(e,r.codec())})(Lt||(Lt={}));var O;(function(r){let t;(function(o){o.OK="OK",o.NOT_FOUND="NOT_FOUND",o.ERROR="ERROR"})(t=r.StatusCode||(r.StatusCode={}));let e;(function(o){o[o.OK=0]="OK",o[o.NOT_FOUND=1]="NOT_FOUND",o[o.ERROR=2]="ERROR"})(e||(e={})),function(o){o.codec=()=>or(e)}(t=r.StatusCode||(r.StatusCode={}));let n;r.codec=()=>(n==null&&(n=$t((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.status!=null&&e[o.status]!==0&&(i.uint32(8),r.StatusCode.codec().encode(o.status,i)),o.data!=null&&o.data.byteLength>0&&(i.uint32(18),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={status:t.OK,data:new Uint8Array(0)},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.status=r.StatusCode.codec().decode(o);break;case 2:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>Pt(o,r.codec()),r.decode=o=>_t(o,r.codec())})(O||(O={}));var In=1e4,jt=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"}/${Qr}/${Wr}`,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 o=await this.components.connectionManager.openConnection(t,n),i=n.signal,s,a=()=>{};if(i==null){let c=this.init.timeout??In;this.log("using default timeout of %d ms",c),i=AbortSignal.timeout(c),ur(1/0,i)}try{s=await o.newStream(this.protocol,{signal:i}),a=()=>{s?.abort(new q("fetch timeout",cr))},i.addEventListener("abort",a,{once:!0}),this.log("fetch %s",e);let c=re(s);await c.write({identifier:e},Lt,n);let u=await c.read(O,n);switch(await c.unwrap().close(n),u.status){case O.StatusCode.OK:return this.log("received status for %s ok",e),u.data;case O.StatusCode.NOT_FOUND:{this.log("received status for %s not found",e);return}case O.StatusCode.ERROR:{this.log("received status for %s error",e);let f=Kr(u.data);throw new q("Error in fetch protocol response: "+f,hr)}default:throw this.log("received status for %s unknown",e),new q("Unknown response status",fr)}}catch(c){throw s?.abort(c),c}finally{i.removeEventListener("abort",a),s!=null&&await s.close()}}async handleMessage(t){let{stream:e}=t,n=AbortSignal.timeout(this.init.timeout??In);try{let o=re(e),i=await o.read(Lt,{signal:n}),s,a=this._getLookupFunction(i.identifier);if(a!=null){this.log("look up data with identifier %s",i.identifier);let c=await a(i.identifier);c!=null?(this.log("sending status for %s ok",i.identifier),s={status:O.StatusCode.OK,data:c}):(this.log("sending status for %s not found",i.identifier),s={status:O.StatusCode.NOT_FOUND,data:new Uint8Array(0)})}else{this.log("sending status for %s error",i.identifier);let c=Jr(`No lookup function registered for key: ${i.identifier}`);s={status:O.StatusCode.ERROR,data:c}}await o.write(s,O,{signal:n}),await o.unwrap().close({signal:n})}catch(o){this.log("error answering fetch request",o),e.abort(o)}}_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 q(`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 Es(r={}){return t=>new jt(t,r)}return _n(As);})();
|
|
3
3
|
return Libp2PFetch}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/fetch",
|
|
3
|
-
"version": "1.0.5-
|
|
3
|
+
"version": "1.0.5-28587d24f",
|
|
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,16 +51,16 @@
|
|
|
51
51
|
"dep-check": "aegir dep-check"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@libp2p/interface": "1.0.2-
|
|
55
|
-
"@libp2p/interface-internal": "1.0.3-
|
|
54
|
+
"@libp2p/interface": "1.0.2-28587d24f",
|
|
55
|
+
"@libp2p/interface-internal": "1.0.3-28587d24f",
|
|
56
56
|
"it-protobuf-stream": "^1.0.2",
|
|
57
57
|
"protons-runtime": "^5.0.0",
|
|
58
58
|
"uint8arraylist": "^2.4.3",
|
|
59
59
|
"uint8arrays": "^5.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@libp2p/logger": "4.0.2-
|
|
63
|
-
"@libp2p/peer-id-factory": "4.0.1-
|
|
62
|
+
"@libp2p/logger": "4.0.2-28587d24f",
|
|
63
|
+
"@libp2p/peer-id-factory": "4.0.1-28587d24f",
|
|
64
64
|
"aegir": "^41.0.2",
|
|
65
65
|
"it-pair": "^2.0.6",
|
|
66
66
|
"protons": "^7.3.0",
|