@hugomrdias/fil 0.0.0-stage → 0.0.0

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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -2
  3. package/bin/fil.js +7 -0
  4. package/dist/chunks/_esm-BBXTTBLC.js +9 -0
  5. package/dist/chunks/_esm-BBXTTBLC.js.map +7 -0
  6. package/dist/chunks/ccip-TGFMQFIR.js +3 -0
  7. package/dist/chunks/ccip-TGFMQFIR.js.map +7 -0
  8. package/dist/chunks/chunk-2KPBBDBJ.js +3 -0
  9. package/dist/chunks/chunk-2KPBBDBJ.js.map +7 -0
  10. package/dist/chunks/chunk-35V77X3C.js +12 -0
  11. package/dist/chunks/chunk-35V77X3C.js.map +7 -0
  12. package/dist/chunks/chunk-46FBFEBX.js +3 -0
  13. package/dist/chunks/chunk-46FBFEBX.js.map +7 -0
  14. package/dist/chunks/chunk-4BBXH7CB.js +6 -0
  15. package/dist/chunks/chunk-4BBXH7CB.js.map +7 -0
  16. package/dist/chunks/chunk-4DUACCJB.js +186 -0
  17. package/dist/chunks/chunk-4DUACCJB.js.map +7 -0
  18. package/dist/chunks/chunk-5EYSPKTK.js +3 -0
  19. package/dist/chunks/chunk-5EYSPKTK.js.map +7 -0
  20. package/dist/chunks/chunk-7MEK5RQ7.js +11 -0
  21. package/dist/chunks/chunk-7MEK5RQ7.js.map +7 -0
  22. package/dist/chunks/chunk-7WN6TT5U.js +4 -0
  23. package/dist/chunks/chunk-7WN6TT5U.js.map +7 -0
  24. package/dist/chunks/chunk-CU3SGKNA.js +3 -0
  25. package/dist/chunks/chunk-CU3SGKNA.js.map +7 -0
  26. package/dist/chunks/chunk-EDF5XCIN.js +4 -0
  27. package/dist/chunks/chunk-EDF5XCIN.js.map +7 -0
  28. package/dist/chunks/chunk-GVAFHRPJ.js +124 -0
  29. package/dist/chunks/chunk-GVAFHRPJ.js.map +7 -0
  30. package/dist/chunks/chunk-IJ2NNDTJ.js +3 -0
  31. package/dist/chunks/chunk-IJ2NNDTJ.js.map +7 -0
  32. package/dist/chunks/chunk-ISML2NA2.js +3 -0
  33. package/dist/chunks/chunk-ISML2NA2.js.map +7 -0
  34. package/dist/chunks/chunk-KAQPCD23.js +4 -0
  35. package/dist/chunks/chunk-KAQPCD23.js.map +7 -0
  36. package/dist/chunks/chunk-LOTWVNDB.js +3 -0
  37. package/dist/chunks/chunk-LOTWVNDB.js.map +7 -0
  38. package/dist/chunks/chunk-NPYAGWD6.js +4 -0
  39. package/dist/chunks/chunk-NPYAGWD6.js.map +7 -0
  40. package/dist/chunks/chunk-QYPR6473.js +3 -0
  41. package/dist/chunks/chunk-QYPR6473.js.map +7 -0
  42. package/dist/chunks/chunk-RK6JJQZL.js +41 -0
  43. package/dist/chunks/chunk-RK6JJQZL.js.map +7 -0
  44. package/dist/chunks/chunk-UJQDDRQD.js +59 -0
  45. package/dist/chunks/chunk-UJQDDRQD.js.map +7 -0
  46. package/dist/chunks/chunk-UVXTIEPU.js +4 -0
  47. package/dist/chunks/chunk-UVXTIEPU.js.map +7 -0
  48. package/dist/chunks/chunk-VTR7BON5.js +4 -0
  49. package/dist/chunks/chunk-VTR7BON5.js.map +7 -0
  50. package/dist/chunks/chunk-XQRC2SUG.js +4 -0
  51. package/dist/chunks/chunk-XQRC2SUG.js.map +7 -0
  52. package/dist/chunks/chunk-YIAP3JO3.js +3 -0
  53. package/dist/chunks/chunk-YIAP3JO3.js.map +7 -0
  54. package/dist/chunks/chunk-ZD6MKB4J.js +5 -0
  55. package/dist/chunks/chunk-ZD6MKB4J.js.map +7 -0
  56. package/dist/chunks/delete-XVYLEMHB.js +3 -0
  57. package/dist/chunks/delete-XVYLEMHB.js.map +7 -0
  58. package/dist/chunks/doctor-2W65SQJS.js +3 -0
  59. package/dist/chunks/doctor-2W65SQJS.js.map +7 -0
  60. package/dist/chunks/get-ZP66WVWT.js +3 -0
  61. package/dist/chunks/get-ZP66WVWT.js.map +7 -0
  62. package/dist/chunks/inspect-HV2SQPTB.js +3 -0
  63. package/dist/chunks/inspect-HV2SQPTB.js.map +7 -0
  64. package/dist/chunks/inspect-PQCV7LQT.js +3 -0
  65. package/dist/chunks/inspect-PQCV7LQT.js.map +7 -0
  66. package/dist/chunks/login-GQ4PM7SA.js +4 -0
  67. package/dist/chunks/login-GQ4PM7SA.js.map +7 -0
  68. package/dist/chunks/logout-7N23QWWM.js +3 -0
  69. package/dist/chunks/logout-7N23QWWM.js.map +7 -0
  70. package/dist/chunks/ls-7XYH5VPL.js +3 -0
  71. package/dist/chunks/ls-7XYH5VPL.js.map +7 -0
  72. package/dist/chunks/ls-ARM57VNR.js +3 -0
  73. package/dist/chunks/ls-ARM57VNR.js.map +7 -0
  74. package/dist/chunks/map-error-7POTPJ7R.js +3 -0
  75. package/dist/chunks/map-error-7POTPJ7R.js.map +7 -0
  76. package/dist/chunks/put-EHRNCZHT.js +3 -0
  77. package/dist/chunks/put-EHRNCZHT.js.map +7 -0
  78. package/dist/chunks/resume-RLZB7L3C.js +3 -0
  79. package/dist/chunks/resume-RLZB7L3C.js.map +7 -0
  80. package/dist/chunks/secp256k1-2OHXXNYZ.js +3 -0
  81. package/dist/chunks/secp256k1-2OHXXNYZ.js.map +7 -0
  82. package/dist/chunks/skills.run-IDY347MW.js +5 -0
  83. package/dist/chunks/skills.run-IDY347MW.js.map +7 -0
  84. package/dist/chunks/status-D4CXVYRA.js +3 -0
  85. package/dist/chunks/status-D4CXVYRA.js.map +7 -0
  86. package/dist/main.js +3 -0
  87. package/dist/main.js.map +7 -0
  88. package/dist/tsconfig.tsbuildinfo +1 -0
  89. package/package.json +52 -3
  90. package/skills/fil/SKILL.md +28 -0
@@ -0,0 +1,3 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import{A as Je,n as Ss,o as Ee,p as As,q as Is,r as Yr,s as Ts,t as ne,u as Bs,v as vs,w as Ds,x as Kr,y as ht,z as _}from"./chunk-4DUACCJB.js";import{k as Yt,p as _s}from"./chunk-UJQDDRQD.js";import{o as jt}from"./chunk-4BBXH7CB.js";import{b as ft,c as D,d as Wt}from"./chunk-YIAP3JO3.js";var za=ft((qy,Ua)=>{Ua.exports=Bi;var Fa=128,Pf=127,Mf=~Pf,Of=Math.pow(2,31);function Bi(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Bi.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Of;)e[r++]=t&255|Fa,t/=128;for(;t&Mf;)e[r++]=t&255|Fa,t>>>=7;return e[r]=t|0,Bi.bytes=r-n+1,e}});var Oa=ft((Wy,Ma)=>{Ma.exports=vi;var $f=128,Pa=127;function vi(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a||i>49)throw vi.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&Pa)<<i:(s&Pa)*Math.pow(2,i),i+=7}while(s>=$f);return vi.bytes=o-n,r}});var Ha=ft((jy,$a)=>{var Hf=Math.pow(2,7),Vf=Math.pow(2,14),Gf=Math.pow(2,21),qf=Math.pow(2,28),Wf=Math.pow(2,35),jf=Math.pow(2,42),Yf=Math.pow(2,49),Kf=Math.pow(2,56),Jf=Math.pow(2,63);$a.exports=function(t){return t<Hf?1:t<Vf?2:t<Gf?3:t<qf?4:t<Wf?5:t<jf?6:t<Yf?7:t<Kf?8:t<Jf?9:10}});var yn=ft((Yy,Va)=>{Va.exports={encode:za(),decode:Oa(),encodingLength:Ha()}});var _c=ft((pw,kc)=>{"use strict";kc.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,r,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,i=r;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let r=0,n,i;for(;r<this.length&&!n;)i=this.get(r),n=e(i),r++;return n?i:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Uh,0),c=~(4294967295<<o+1),u=Ec(i&c);return a+u-1}_bytePosFor(e,r){let n=Math.floor(e/7),i=n+1;for(;!r&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,i){let o=this._data,s=[r,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=r)o.push(s);else if(o[0][0]<=r)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(zh),this._changedData=!1}bitField(){let e=[],r=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,r),u=~(255<<c),l=o&u;i|=l<<8-r,o=o>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(i),i=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(Ph)}};function Uh(t,e){return t+Ec(e)}function Ec(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function zh(t,e){return t[0]-e[0]}function Ph(t){return t[1]}});var Eu=ft((f1,Ao)=>{"use strict";var zd=Object.prototype.hasOwnProperty,V="~";function Ir(){}Object.create&&(Ir.prototype=Object.create(null),new Ir().__proto__||(V=!1));function Pd(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function xu(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new Pd(r,n||t,i),s=V?V+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function Yn(t,e){--t._eventsCount===0?t._events=new Ir:delete t._events[e]}function O(){this._events=new Ir,this._eventsCount=0}O.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)zd.call(r,n)&&e.push(V?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};O.prototype.listeners=function(e){var r=V?V+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};O.prototype.listenerCount=function(e){var r=V?V+e:e,n=this._events[r];return n?n.fn?1:n.length:0};O.prototype.emit=function(e,r,n,i,o,s){var a=V?V+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,o),!0;case 6:return c.fn.call(c.context,r,n,i,o,s),!0}for(h=1,l=new Array(u-1);h<u;h++)l[h-1]=arguments[h];c.fn.apply(c.context,l)}else{var d=c.length,x;for(h=0;h<d;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,i);break;default:if(!l)for(x=1,l=new Array(u-1);x<u;x++)l[x-1]=arguments[x];c[h].fn.apply(c[h].context,l)}}return!0};O.prototype.on=function(e,r,n){return xu(this,e,r,n,!1)};O.prototype.once=function(e,r,n){return xu(this,e,r,n,!0)};O.prototype.removeListener=function(e,r,n,i){var o=V?V+e:e;if(!this._events[o])return this;if(!r)return Yn(this,o),this;var s=this._events[o];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&Yn(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Yn(this,o)}return this};O.prototype.removeAllListeners=function(e){var r;return e?(r=V?V+e:e,this._events[r]&&Yn(this,r)):(this._events=new Ir,this._eventsCount=0),this};O.prototype.off=O.prototype.removeListener;O.prototype.addListener=O.prototype.on;O.prefixed=V;O.EventEmitter=O;typeof Ao<"u"&&(Ao.exports=O)});import{createReadStream as Bm,createWriteStream as ws}from"node:fs";import{lstat as Wl,mkdir as fi,open as vm,readdir as Dm,rename as Cm,rm as Nm}from"node:fs/promises";import{basename as Lm,dirname as bs,join as jl,relative as Rm,resolve as xs,sep as Yl}from"node:path";import{Readable as Es,Writable as Fm}from"node:stream";import{pipeline as ks}from"node:stream/promises";import Zf from"fs";var Kl=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function hi(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Jl(t);return r||"Object"}function Jl(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Kl.includes(e))return e}var f=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);var p=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Kt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Xl=new TextEncoder;function Jr(t){return Kt&&globalThis.Buffer.isBuffer(t)}function Xe(t){return t instanceof Uint8Array?Jr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Zl=24,Ql=200,dt=Kt?t=>t.length>=Zl?globalThis.Buffer.from(t):Cs(t):t=>t.length>=Ql?Xl.encode(t):Cs(t),de=t=>Uint8Array.from(t),Ls=Kt?(t,e,r)=>Jr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Rs=Kt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Xe(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},di=Kt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function pt(t,e){if(Jr(t)&&Jr(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Cs(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var Ns=4096;function Fs(t){let e=t.length;if(e<=Ns)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Ns));return r}var ef=256,Jt=class{constructor(e=ef){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=di(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=di(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ls(n,0,this.cursor)}else r=Rs(this.chunks,this.cursor);return e&&this.reset(),r}},Xr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var b="CBOR decode error:",Ze="CBOR encode error:",Xt=[];Xt[23]=1;Xt[24]=2;Xt[25]=3;Xt[26]=5;Xt[27]=9;function ke(t,e,r){if(t.length-e<r)throw new Error(`${b} not enough data for type`)}var U=[24,256,65536,4294967296,BigInt("18446744073709551616")];function X(t,e,r){ke(t,e,1);let n=t[e];if(r.strict===!0&&n<U[0])throw new Error(`${b} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){ke(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<U[1])throw new Error(`${b} integer encoded in more bytes than necessary (strict decode)`);return n}function Q(t,e,r){ke(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<U[2])throw new Error(`${b} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){ke(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<U[3])throw new Error(`${b} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${b} integers outside of the safe integer range are not supported`)}function Us(t,e,r,n){return new p(f.uint,X(t,e+1,n),2)}function zs(t,e,r,n){return new p(f.uint,Z(t,e+1,n),3)}function Ps(t,e,r,n){return new p(f.uint,Q(t,e+1,n),5)}function Ms(t,e,r,n){return new p(f.uint,ee(t,e+1,n),9)}function pe(t,e){return L(t,0,e.value)}function L(t,e,r){if(r<U[0]){let n=Number(r);t.pushByte(e|n)}else if(r<U[1]){let n=Number(r);t.push([e|24,n])}else if(r<U[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<U[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<U[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${b} encountered BigInt larger than allowable range`)}}pe.encodedSize=function(e){return L.encodedSize(e.value)};L.encodedSize=function(e){return e<U[0]?1:e<U[1]?2:e<U[2]?3:e<U[3]?5:9};pe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Os(t,e,r,n){return new p(f.negint,-1-X(t,e+1,n),2)}function $s(t,e,r,n){return new p(f.negint,-1-Z(t,e+1,n),3)}function Hs(t,e,r,n){return new p(f.negint,-1-Q(t,e+1,n),5)}var pi=BigInt(-1),Vs=BigInt(1);function Gs(t,e,r,n){let i=ee(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new p(f.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${b} integers outside of the safe integer range are not supported`);return new p(f.negint,pi-BigInt(i),9)}function Zr(t,e){let r=e.value,n=typeof r=="bigint"?r*pi-Vs:r*-1-1;L(t,e.type.majorEncoded,n)}Zr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*pi-Vs:r*-1-1;return n<U[0]?1:n<U[1]?2:n<U[2]?3:n<U[3]?5:9};Zr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Zt(t,e,r,n){ke(t,e,r+n);let i=t.slice(e+r,e+r+n);return new p(f.bytes,i,r+n)}function qs(t,e,r,n){return Zt(t,e,1,r)}function Ws(t,e,r,n){return Zt(t,e,2,X(t,e+1,n))}function js(t,e,r,n){return Zt(t,e,3,Z(t,e+1,n))}function Ys(t,e,r,n){return Zt(t,e,5,Q(t,e+1,n))}function Ks(t,e,r,n){let i=ee(t,e+1,n);if(typeof i=="bigint")throw new Error(`${b} 64-bit integer bytes lengths not supported`);return Zt(t,e,9,i)}function Qr(t){return t.encodedBytes===void 0&&(t.encodedBytes=f.equals(t.type,f.string)?dt(t.value):t.value),t.encodedBytes}function mt(t,e){let r=Qr(e);L(t,e.type.majorEncoded,r.length),t.push(r)}mt.encodedSize=function(e){let r=Qr(e);return L.encodedSize(r.length)+r.length};mt.compareTokens=function(e,r){return rf(Qr(e),Qr(r))};function rf(t,e){return t.length<e.length?-1:t.length>e.length?1:pt(t,e)}var Js=new TextDecoder,of=32;function sf(t,e,r){if(r-e<of){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return Js.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return Js.decode(t.subarray(e,r))}function Qt(t,e,r,n,i){let o=r+n;ke(t,e,o);let s=new p(f.string,sf(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function Xs(t,e,r,n){return Qt(t,e,1,r,n)}function Zs(t,e,r,n){return Qt(t,e,2,X(t,e+1,n),n)}function Qs(t,e,r,n){return Qt(t,e,3,Z(t,e+1,n),n)}function ea(t,e,r,n){return Qt(t,e,5,Q(t,e+1,n),n)}function ta(t,e,r,n){let i=ee(t,e+1,n);if(typeof i=="bigint")throw new Error(`${b} 64-bit integer string lengths not supported`);return Qt(t,e,9,i,n)}var ra=mt;function yt(t,e,r,n){return new p(f.array,n,r)}function na(t,e,r,n){return yt(t,e,1,r)}function ia(t,e,r,n){return yt(t,e,2,X(t,e+1,n))}function oa(t,e,r,n){return yt(t,e,3,Z(t,e+1,n))}function sa(t,e,r,n){return yt(t,e,5,Q(t,e+1,n))}function aa(t,e,r,n){let i=ee(t,e+1,n);if(typeof i=="bigint")throw new Error(`${b} 64-bit integer array lengths not supported`);return yt(t,e,9,i)}function ca(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${b} indefinite length items not allowed`);return yt(t,e,1,1/0)}function en(t,e){L(t,f.array.majorEncoded,e.value)}en.compareTokens=pe.compareTokens;en.encodedSize=function(e){return L.encodedSize(e.value)};function gt(t,e,r,n){return new p(f.map,n,r)}function ua(t,e,r,n){return gt(t,e,1,r)}function la(t,e,r,n){return gt(t,e,2,X(t,e+1,n))}function fa(t,e,r,n){return gt(t,e,3,Z(t,e+1,n))}function ha(t,e,r,n){return gt(t,e,5,Q(t,e+1,n))}function da(t,e,r,n){let i=ee(t,e+1,n);if(typeof i=="bigint")throw new Error(`${b} 64-bit integer map lengths not supported`);return gt(t,e,9,i)}function pa(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${b} indefinite length items not allowed`);return gt(t,e,1,1/0)}function tn(t,e){L(t,f.map.majorEncoded,e.value)}tn.compareTokens=pe.compareTokens;tn.encodedSize=function(e){return L.encodedSize(e.value)};function ma(t,e,r,n){return new p(f.tag,r,1)}function ya(t,e,r,n){return new p(f.tag,X(t,e+1,n),2)}function ga(t,e,r,n){return new p(f.tag,Z(t,e+1,n),3)}function wa(t,e,r,n){return new p(f.tag,Q(t,e+1,n),5)}function ba(t,e,r,n){return new p(f.tag,ee(t,e+1,n),9)}function rn(t,e){L(t,f.tag.majorEncoded,e.value)}rn.compareTokens=pe.compareTokens;rn.encodedSize=function(e){return L.encodedSize(e.value)};var nn=20,on=21,sn=22,an=23;function Ea(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${b} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new p(f.null,null,1):new p(f.undefined,void 0,1)}function ka(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${b} indefinite length items not allowed`);return new p(f.break,void 0,1)}function mi(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${b} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${b} Infinity values are not supported`)}return new p(f.float,t,e)}function _a(t,e,r,n){return mi(cn(t,e+1),3,n)}function Sa(t,e,r,n){return mi(un(t,e+1),5,n)}function Aa(t,e,r,n){return mi(Ba(t,e+1),9,n)}function er(t,e,r){let n=e.value;if(n===!1)t.pushByte(f.float.majorEncoded|nn);else if(n===!0)t.pushByte(f.float.majorEncoded|on);else if(n===null)t.pushByte(f.float.majorEncoded|sn);else if(n===void 0)t.pushByte(f.float.majorEncoded|an);else{let i,o=!1;(!r||r.float64!==!0)&&(yi(n),i=cn(R,1),n===i||Number.isNaN(n)?(R[0]=249,t.push(R.slice(0,3)),o=!0):(gi(n),i=un(R,1),n===i&&(R[0]=250,t.push(R.slice(0,5)),o=!0))),o||(Ta(n),i=Ba(R,1),R[0]=251,t.push(R.slice(0,9)))}}er.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){yi(n);let i=cn(R,1);if(n===i||Number.isNaN(n))return 3;if(gi(n),i=un(R,1),n===i)return 5}return 9};var Ia=new ArrayBuffer(9),ie=new DataView(Ia,1),R=new Uint8Array(Ia,0);function yi(t){if(t===1/0)ie.setUint16(0,31744,!1);else if(t===-1/0)ie.setUint16(0,64512,!1);else if(Number.isNaN(t))ie.setUint16(0,32256,!1);else{ie.setFloat32(0,t);let e=ie.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ie.setUint16(0,31744,!1);else if(r===0)ie.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?ie.setUint16(0,0):i<-14?ie.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):ie.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function cn(t,e){if(t.length-e<2)throw new Error(`${b} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function gi(t){ie.setFloat32(0,t,!1)}function un(t,e){if(t.length-e<4)throw new Error(`${b} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ta(t){ie.setFloat64(0,t,!1)}function Ba(t,e){if(t.length-e<8)throw new Error(`${b} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function ff(t,e){let r=t.value;if(r===!1)return Uint8Array.of(f.float.majorEncoded|nn);if(r===!0)return Uint8Array.of(f.float.majorEncoded|on);if(r===null)return Uint8Array.of(f.float.majorEncoded|sn);if(r===void 0)return Uint8Array.of(f.float.majorEncoded|an);if(!e){if(yi(r),r===cn(R,1)||Number.isNaN(r))return R[0]=249,R.slice(0,3);if(gi(r),r===un(R,1))return R[0]=250,R.slice(0,5)}return Ta(r),R[0]=251,R.slice(0,9)}function xa(t,e){let r=t,n=e?.float64===!0,i=n?r._keyBytesFloat64:r._keyBytes;if(i!==void 0)return i;let o=ff(t,n);return n?r._keyBytesFloat64=o:r._keyBytes=o,o}er.compareTokens=function(e,r,n){let i=xa(e,n),o=xa(r,n);return i.length!==o.length?i.length<o.length?-1:1:pt(i,o)};function S(t,e,r){throw new Error(`${b} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ln(t){return()=>{throw new Error(`${b} ${t}`)}}var y=[];for(let t=0;t<=23;t++)y[t]=S;y[24]=Us;y[25]=zs;y[26]=Ps;y[27]=Ms;y[28]=S;y[29]=S;y[30]=S;y[31]=S;for(let t=32;t<=55;t++)y[t]=S;y[56]=Os;y[57]=$s;y[58]=Hs;y[59]=Gs;y[60]=S;y[61]=S;y[62]=S;y[63]=S;for(let t=64;t<=87;t++)y[t]=qs;y[88]=Ws;y[89]=js;y[90]=Ys;y[91]=Ks;y[92]=S;y[93]=S;y[94]=S;y[95]=ln("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)y[t]=Xs;y[120]=Zs;y[121]=Qs;y[122]=ea;y[123]=ta;y[124]=S;y[125]=S;y[126]=S;y[127]=ln("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)y[t]=na;y[152]=ia;y[153]=oa;y[154]=sa;y[155]=aa;y[156]=S;y[157]=S;y[158]=S;y[159]=ca;for(let t=160;t<=183;t++)y[t]=ua;y[184]=la;y[185]=fa;y[186]=ha;y[187]=da;y[188]=S;y[189]=S;y[190]=S;y[191]=pa;for(let t=192;t<=215;t++)y[t]=ma;y[216]=ya;y[217]=ga;y[218]=wa;y[219]=ba;y[220]=S;y[221]=S;y[222]=S;y[223]=S;for(let t=224;t<=243;t++)y[t]=ln("simple values are not supported");y[244]=S;y[245]=S;y[246]=S;y[247]=Ea;y[248]=ln("simple values are not supported");y[249]=_a;y[250]=Sa;y[251]=Aa;y[252]=S;y[253]=S;y[254]=S;y[255]=ka;var ce=[];for(let t=0;t<24;t++)ce[t]=new p(f.uint,t,1);for(let t=-1;t>=-24;t--)ce[31-t]=new p(f.negint,t,1);ce[64]=new p(f.bytes,new Uint8Array(0),1);ce[96]=new p(f.string,"",1);ce[128]=new p(f.array,0,1);ce[160]=new p(f.map,0,1);ce[244]=new p(f.false,!1,1);ce[245]=new p(f.true,!0,1);ce[246]=new p(f.null,null,1);function fn(t){switch(t.type){case f.false:return de([244]);case f.true:return de([245]);case f.null:return de([246]);case f.bytes:return t.value.length?void 0:de([64]);case f.string:return t.value===""?de([96]):void 0;case f.array:return t.value===0?de([128]):void 0;case f.map:return t.value===0?de([160]):void 0;case f.uint:return t.value<24?de([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return de([31-Number(t.value)])}}var df={float64:!1,mapSorter:xi,quickEncodeToken:fn},La=Object.freeze({mapSorter:mf,quickEncodeToken:fn});function bi(){let t=[];return t[f.uint.major]=pe,t[f.negint.major]=Zr,t[f.bytes.major]=mt,t[f.string.major]=ra,t[f.array.major]=en,t[f.map.major]=tn,t[f.tag.major]=rn,t[f.float.major]=er,t}var et=bi(),hn=new Jt,bt=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Ze} object contains circular references`);return new t(r,e)}},Be={null:new p(f.null,null),undefined:new p(f.undefined,void 0),true:new p(f.true,!0),false:new p(f.false,!1),emptyArray:new p(f.array,0),emptyMap:new p(f.map,0)},me={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new p(f.float,t):t>=0?new p(f.uint,t):new p(f.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new p(f.uint,t):new p(f.negint,t)},Uint8Array(t,e,r,n){return new p(f.bytes,t)},string(t,e,r,n){return new p(f.string,t)},boolean(t,e,r,n){return t?Be.true:Be.false},null(t,e,r,n){return Be.null},undefined(t,e,r,n){return Be.undefined},ArrayBuffer(t,e,r,n){return new p(f.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new p(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Be.emptyArray,new p(f.break)]:Be.emptyArray;n=bt.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=De(s,r,n);return r.addBreakTokens?[new p(f.array,t.length),i,new p(f.break)]:[new p(f.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=bt.createCheck(n,t);let c=!i&&r.ignoreUndefinedProperties,u=0;for(let l of o){let h=i?t.get(l):t[l];c&&h===void 0||(a[u++]=[De(l,r,n),De(h,r,n)])}u<s&&(a.length=u)}return a?.length?(pf(a,r),r.addBreakTokens?[new p(f.map,a.length),a,new p(f.break)]:[new p(f.map,a.length),a]):r.addBreakTokens===!0?[Be.emptyMap,new p(f.break)]:Be.emptyMap},Tagged(t,e,r,n){return[new p(f.tag,t.tag),De(t.value,r,n)]}};me.Map=me.Object;me.Buffer=me.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))me[`${t}Array`]=me.DataView;function De(t,e={},r){let n=hi(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||me[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=me[n];if(!o)throw new Error(`${Ze} unsupported type: ${n}`);return o(t,n,e,r)}function pf(t,e){let r=e.mapSorter;r&&t.sort((n,i)=>r(n,i,e))}function xi(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],i=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==i.type.major)return n.type.compare(i.type);let o=n.type.major,s=et[o].compareTokens(n,i,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function mf(t,e){if(t[0]instanceof p&&e[0]instanceof p){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=va(r.value)),n._keyBytes||(n._keyBytes=va(n.value)),pt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function va(t){return ki(t,et,La)}function wt(t,e,r,n){if(Array.isArray(e))for(let i of e)wt(t,i,r,n);else r[e.type.major](t,e,n)}var Da=f.uint.majorEncoded,Ca=f.negint.majorEncoded,yf=f.bytes.majorEncoded,gf=f.string.majorEncoded,Na=f.array.majorEncoded,wi=f.map.majorEncoded,wf=f.float.majorEncoded|nn,bf=f.float.majorEncoded|on,xf=f.float.majorEncoded|sn,Ef=f.float.majorEncoded|an,kf=BigInt(-1),_f=BigInt(1);function ve(t,e,r){r<24?t.pushByte(e|Number(r)):L(t,e,r)}function Sf(t){return t.addBreakTokens!==!0}function Af(t,e,r,n,i){let o=r==="Map",s=o?e.keys():Object.keys(e),a=o?e.size:s.length;if(!a){t.pushByte(wi);return}i=bt.createCheck(i,e);let c=!o&&n.ignoreUndefinedProperties,u=new Array(a),l=0;for(let h of s){let d=o?e.get(h):e[h];c&&d===void 0||(u[l++]=[De(h,n,i),d])}if(l===0){t.pushByte(wi);return}l<a&&(u.length=l),u.sort((h,d)=>xi(h,d,n)),ve(t,wi,l);for(let[h,d]of u)wt(t,h,et,n),Ei(t,d,n,i)}function Ei(t,e,r,n){let i=hi(e),o=r.typeEncoders&&r.typeEncoders[i];if(o){let s=o(e,i,r,n);if(s!=null){wt(t,s,et,r);return}}switch(i){case"null":t.pushByte(xf);return;case"undefined":t.pushByte(Ef);return;case"boolean":t.pushByte(e?bf:wf);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?er(t,new p(f.float,e),r):e>=0?ve(t,Da,e):ve(t,Ca,e*-1-1);return;case"bigint":e>=BigInt(0)?ve(t,Da,e):ve(t,Ca,e*kf-_f);return;case"string":{let s=dt(e);ve(t,gf,s.length),t.push(s);return}case"Uint8Array":ve(t,yf,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(Na);return}n=bt.createCheck(n,e),ve(t,Na,e.length);for(let s of e)Ei(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===xi)Af(t,e,i,r,n);else{let s=me.Object(e,i,r,n);wt(t,s,et,r)}return;default:{let s=me[i];if(!s)throw new Error(`${Ze} unsupported type: ${i}`);let a=s(e,i,r,n);wt(t,a,et,r)}}}function ki(t,e,r,n){let i=n instanceof Uint8Array,o=i?new Xr(n):hn,s=De(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(i||(o=new Jt(u)),c(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Xe(o.chunks[0])}}return o.reset(),wt(o,s,e,r),o.toBytes(!0)}function _i(t,e){return e=Object.assign({},df,e),Sf(e)?(hn.reset(),Ei(hn,t,e,void 0),hn.toBytes(!0)):ki(t,et,e)}var If={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},dn=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=ce[e];if(r===void 0){let n=y[e];if(!n)throw new Error(`${b} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},Ce=Symbol.for("DONE"),xt=Symbol.for("BREAK");function Tf(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=Ne(e,r);if(o===xt){if(t.value===1/0)break;throw new Error(`${b} got unexpected break to lengthed array`)}if(o===Ce)throw new Error(`${b} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function Bf(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Ne(e,r);if(c===xt){if(t.value===1/0)break;throw new Error(`${b} got unexpected break to lengthed map`)}if(c===Ce)throw new Error(`${b} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${b} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${b} found repeat map key "${c}"`);let u=Ne(e,r);if(u===Ce)throw new Error(`${b} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(o,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):o[c]=u}return n?s:o}function*vf(t,e,r){for(let n=0;n<t.value;n++){let i=Ne(e,r);if(i===xt){if(t.value===1/0)break;throw new Error(`${b} got unexpected break to lengthed map`)}if(i===Ce)throw new Error(`${b} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=Ne(e,r);if(o===Ce)throw new Error(`${b} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function Df(t,e){let r=function(){if(r._called)throw new Error(`${b} tag decode() may only be called once`);r._called=!0;let n=Ne(t,e);if(n===Ce)throw new Error(`${b} tag content missing`);if(n===xt)throw new Error(`${b} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${b} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!f.equals(n.type,f.map))throw new Error(`${b} entries() requires map content, got ${n.type.name}`);let i=[];for(let o of vf(n,t,e))i.push(o);return i},r._called=!1,r}function Ne(t,e){if(t.done())return Ce;let r=t.next();if(f.equals(r.type,f.break))return xt;if(r.type.terminal)return r.value;if(f.equals(r.type,f.array))return Tf(r,t,e);if(f.equals(r.type,f.map))return Bf(r,t,e);if(f.equals(r.type,f.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Df(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${b} tag decoder must call decode() or entries()`);return i}throw new Error(`${b} tag not supported (${r.value})`)}throw new Error("unsupported")}function Si(t,e){if(!(t instanceof Uint8Array))throw new Error(`${b} data to decode must be a Uint8Array`);e=Object.assign({},If,e);let r=Xe(t),n=e.tokenizer||new dn(r,e),i=Ne(n,e);if(i===Ce)throw new Error(`${b} did not find any content to decode`);if(i===xt)throw new Error(`${b} got unexpected break`);return[i,t.subarray(n.pos())]}function tr(t,e){let[r,n]=Si(t,e);if(n.length>0)throw new Error(`${b} too many terminals, data makes no sense`);return r}var pn=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(pn.prototype,Symbol.toStringTag,{value:"Tagged"});var Ra=42;function Nf(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Lf(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=_.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new p(f.tag,Ra),new p(f.bytes,r)]}function Rf(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ff(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Uf(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var Ai={float64:!0,typeEncoders:{Map:Uf,Object:Lf,undefined:Rf,number:Ff}},Vy={...Ai,typeEncoders:{...Ai.typeEncoders}};function zf(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return _.decode(e.subarray(1))}var Ii={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Ra]:zf}},Gy={...Ii,tags:{...Ii.tags}};var mn=113,Ti=t=>_i(t,Ai),tt=t=>tr(Nf(t),Ii);var Le=Wt(yn(),1),nr={SHA2_256:18,LENGTH:32,DAG_PB:112},Di=40;function Et(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=Le.default.decode(t);return e.seek(Le.default.decode.bytes),r}function Ci(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=0;return{version:2,characteristics:[e.getBigUint64(r,!0),e.getBigUint64(r+=8,!0)],dataOffset:Number(e.getBigUint64(r+=8,!0)),dataSize:Number(e.getBigUint64(r+=8,!0)),indexOffset:Number(e.getBigUint64(r+=8,!0))}}function Ni(t){Le.default.decode(t);let e=Le.default.decode.bytes,r=Le.default.decode(t.subarray(Le.default.decode.bytes)),n=Le.default.decode.bytes;return e+n+r}var Re={Null:t=>t===null?t:void 0,Int:t=>Number.isInteger(t)?t:void 0,Float:t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,String:t=>typeof t=="string"?t:void 0,Bool:t=>typeof t=="boolean"?t:void 0,Bytes:t=>t instanceof Uint8Array?t:void 0,Link:t=>t!==null&&typeof t=="object"&&t.asCID===t?t:void 0,List:t=>Array.isArray(t)?t:void 0,Map:t=>t!==null&&typeof t=="object"&&t.asCID!==t&&!Array.isArray(t)&&!(t instanceof Uint8Array)?t:void 0},ir={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Re.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(Re.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=ir["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=ir["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:Re.Int,CarV1HeaderOrV2Pragma:t=>{if(Re.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=ir["CarV1HeaderOrV2Pragma > roots (anon)"](t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=ir.Int(t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},or={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":Re.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(Re.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=or["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=or["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:Re.Int,CarV1HeaderOrV2Pragma:t=>{if(Re.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=or["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=or.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Li={toTyped:ir.CarV1HeaderOrV2Pragma,toRepresentation:or.CarV1HeaderOrV2Pragma};var sg=Zf.readSync;var lg=bi();var Qf=Wt(yn(),1);var mg=[new p(f.map,2),new p(f.string,"version"),new p(f.uint,1),new p(f.string,"roots")],yg=new p(f.tag,42);import Ja from"fs";import{Readable as sh}from"stream";async function kt(t,e){let r=Et(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),i=tt(n);if(Li.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let o=Ci(await t.exactly(Di,!0));t.seek(o.dataOffset-t.pos);let s=await kt(t,1);return Object.assign(s,o)}async function th(t){let e=await t.exactly(2,!1);if(e[0]===nr.SHA2_256&&e[1]===nr.LENGTH){let s=await t.exactly(34,!0),a=ht(s);return _.create(0,nr.DAG_PB,a)}let r=Et(await t.upTo(8),t);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=Et(await t.upTo(8),t),i=await t.exactly(Ni(await t.upTo(8)),!0),o=ht(i);return _.create(r,n,o)}async function Ga(t){let e=t.pos,r=Et(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=t.pos-e;let n=await th(t),i=r-Number(t.pos-e);return{cid:n,length:r,blockLength:i}}async function rh(t){let{cid:e,blockLength:r}=await Ga(t);return{bytes:await t.exactly(r,!0),cid:e}}async function nh(t){let e=t.pos,{cid:r,length:n,blockLength:i}=await Ga(t),o={cid:r,length:n,blockLength:i,offset:e,blockOffset:t.pos};return t.seek(o.blockLength),o}function ar(t){let e=(async()=>{let r=await kt(t);if(r.version===2){let n=t.pos-r.dataOffset;t=ih(t,r.dataSize-n)}return r})();return{header:()=>e,async*blocks(){for(await e;(await t.upTo(8)).length>0;)yield await rh(t)},async*blocksIndex(){for(await e;(await t.upTo(8)).length>0;)yield await nh(t)}}}function rt(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let i=t.subarray(e,e+r);return n&&(e+=r),i},seek(r){e+=r},get pos(){return e}}}function Ri(t){let e=0,r=0,n=0,i=new Uint8Array(0),o=async s=>{r=i.length-n;let a=[i.subarray(n)];for(;r<s;){let u=await t();if(u==null)break;r<0?u.length>r&&a.push(u.subarray(-r)):a.push(u),r+=u.length}i=new Uint8Array(a.reduce((u,l)=>u+l.length,0));let c=0;for(let u of a)i.set(u,c),c+=u.length;n=0};return{async upTo(s){return i.length-n<s&&await o(s),i.subarray(n,n+Math.min(i.length-n,s))},async exactly(s,a=!1){if(i.length-n<s&&await o(s),i.length-n<s)throw new Error("Unexpected end of data");let c=i.subarray(n,n+s);return a&&(e+=s,n+=s),c},seek(s){e+=s,n+=s},get pos(){return e}}}function cr(t){let e=t[Symbol.asyncIterator]();async function r(){let n=await e.next();return n.done?null:n.value}return Ri(r)}function ih(t,e){let r=0;return{async upTo(n){let i=await t.upTo(n);return i.length+r>e&&(i=i.subarray(0,e-r)),i},async exactly(n,i=!1){let o=await t.exactly(n,i);if(o.length+r>e)throw new Error("Unexpected end of data");return i&&(r+=n),o},seek(n){r+=n,t.seek(n)},get pos(){return t.pos}}}var _t=class{constructor(e,r,n){this._version=e,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return qa(rt(e))}static async fromIterable(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return qa(cr(e))}};async function qa(t){let e=ar(t),{version:r,roots:n}=await e.header();return new _t(r,n,e.blocksIndex())}import Wa from"fs";import{promisify as ja}from"util";var Fi;function gn(t,e,r,n,i){return Fi||(Fi=ja(Wa.read)),Fi(t,e,r,n,i)}var Ui;function Ya(t,e,r,n,i){return Ui||(Ui=ja(Wa.write)),Ui(t,e,r,n,i)}var ur=class{constructor(e,r){this._header=e,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(e){return this._keys.indexOf(e.toString())>-1}async get(e){let r=this._keys.indexOf(e.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let e of this._blocks)yield e}async*cids(){for(let e of this._blocks)yield e.cid}static async fromBytes(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return Ka(rt(e))}static async fromIterable(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return Ka(cr(e))}};async function Ka(t){let e=ar(t),r=await e.header(),n=[];for await(let i of e.blocks())n.push(i);return new ur(r,n)}var lr=class extends ur{static async readRaw(e,r){let{cid:n,blockLength:i,blockOffset:o}=r,s=new Uint8Array(i),a;if(typeof e=="number")a=(await gn(e,s,0,i,o)).bytesRead;else if(typeof e=="object"&&typeof e.read=="function")a=(await e.read(s,0,i,o)).bytesRead;else throw new TypeError("Bad fd");if(a!==i)throw new Error(`Failed to read entire block (${a} instead of ${i})`);return{cid:n,bytes:s}}};var fr=class t{constructor(e,r,n,i,o){this._version=e,this._path=r,this._roots=n,this._index=i,this._order=o,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(e){return this._index.has(e.toString())}async get(e){let r=this._index.get(e.toString());if(!r)return;this._fd||(this._fd=await Ja.promises.open(this._path,"r"));let n={cid:e,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return lr.readRaw(this._fd,n)}async*blocks(){for(let e of this._order){let r=await this.get(_.parse(e));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let e of this._order)yield _.parse(e)}async close(){if(this._fd)return this._fd.close()}static async fromFile(e){if(typeof e!="string")throw new TypeError("fromFile() requires a file path string");let r=await _t.fromIterable(sh.from(Ja.createReadStream(e))),n=new Map,i=[];for await(let{cid:o,blockLength:s,blockOffset:a}of r){let c=o.toString();n.set(c,{blockLength:s,blockOffset:a}),i.push(c)}return new t(r.version,e,await r.getRoots(),n,i)}};var zi=Wt(yn(),1),Xa=1;function hr(t){let e=Ti({version:Xa,roots:t}),r=zi.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function Za(t){return{async setRoots(e){let r=hr(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(zi.default.encode(r.bytes.length+n.length))),await t.write(r.bytes),n.length&&await t.write(n)},async close(){await t.end()},version(){return Xa}}}function wn(){}function Qa(){let t=[],e=null,r=wn,n=!1,i=null,o=wn,s=()=>(e||(e=new Promise(u=>{r=()=>{e=null,r=wn,u()}})),e),a={write(u){t.push(u);let l=s();return o(),l},async end(){n=!0;let u=s();o(),await u}},c={async next(){let u=t.shift();return u?(t.length===0&&r(),{done:!1,value:u}):n?(r(),{done:!0,value:void 0}):(i||(i=new Promise(l=>{o=()=>(i=null,o=wn,l(c.next()))})),i)}};return{writer:a,iterator:c}}var bn=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=_.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=ah(e);let{encoder:r,iterator:n}=ec(),i=new t(e,r),o=new xn(n);return{writer:i,out:o}}static createAppender(){let{encoder:e,iterator:r}=ec();e.setRoots=()=>Promise.resolve();let n=new t([],e),i=new xn(r);return{writer:n,out:i}}static async updateRootsInBytes(e,r){let n=rt(e);await kt(n);let i=hr(r);if(Number(n.pos)!==i.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${i.length} bytes)`);return e.set(i,0),e}},xn=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function ec(){let t=Qa(),{writer:e,iterator:r}=t;return{encoder:Za(e),iterator:r}}function ah(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=_.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=_.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var St=class extends bn{static async updateRootsInFile(e,r){let i,o=0,s;if(typeof e=="number")s=async()=>(await gn(e,i,0,256,o)).bytesRead;else if(typeof e=="object"&&typeof e.read=="function")s=async()=>(await e.read(i,0,256,o)).bytesRead;else throw new TypeError("Bad fd");let a=Ri(async()=>{i=new Uint8Array(256);let u=await s();return o+=u,u<256?i.subarray(0,u):i});await kt(a);let c=hr(r);if(a.pos!==c.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${a.pos} bytes, new header is ${c.length} bytes)`);typeof e=="number"?await Ya(e,c,0,c.length,0):typeof e=="object"&&typeof e.read=="function"&&await e.write(c,0,c.length,0)}};var At=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},W=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},It=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},C=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},En=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},kn=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},_e=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};var tc=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(f.equals(r.type,f.array)&&(r.elements++,r.elements!==1&&e.push([44])),f.equals(r.type,f.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[f.uint.major](e,r){this.prefix(e);let n=String(r.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[f.negint.major](e,r){this[f.uint.major](e,r)}[f.bytes.major](e,r){throw new Error(`${Ze} unsupported type: Uint8Array`)}[f.string.major](e,r){this.prefix(e);let n=dt(JSON.stringify(r.value));e.push(n.length>32?Xe(n):n)}[f.array.major](e,r){this.prefix(e),this.inRecursive.push({type:f.array,elements:0}),e.push([91])}[f.map.major](e,r){this.prefix(e),this.inRecursive.push({type:f.map,elements:0}),e.push([123])}[f.tag.major](e,r){}[f.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(f.equals(s.type,f.array))e.push([93]);else if(f.equals(s.type,f.map))e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Ze} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var Tt=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${b} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${b} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new p(f.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${b} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${b} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new p(f.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new p(s>=0?f.uint:f.negint,s,this._pos-e):new p(s>=0?f.uint:f.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${b} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new p(f.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${b} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${b} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${b} unexpected unicode sequence at position ${this._pos}`);let c,u,l,h;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(s=h));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(h=(o&15)<<12|(c&63)<<6|u&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(h=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,h>65535&&h<1114112&&(s=h))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${b} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${b} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new p(f.string,Fs(r),this._pos-e);default:if(o<32)throw new Error(`${b} invalid control character at position ${this._pos}`);o<128?(r.push(o),this._pos++):i()}}throw new Error(`${b} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new p(f.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new p(f.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new p(f.null,null,4);case 102:return this.expect([102,97,108,115,101]),new p(f.false,!1,5);case 116:return this.expect([116,114,117,101]),new p(f.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${b} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new p(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${b} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new p(f.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new p(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${b} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new p(f.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${b} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${b} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Pi(t,e){return e=Object.assign({tokenizer:new Tt(t,e)},e),tr(t,e)}var Oi={};D(Oi,{base64:()=>Mi,base64pad:()=>lh,base64url:()=>fh,base64urlpad:()=>hh});var Mi=ne({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),lh=ne({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fh=ne({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hh=ne({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function dh(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var $i=class extends Tt{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(f.equals(e.type,f.map)){let r=this._next();if(f.equals(r.type,f.string)&&r.value==="/"){let n=this._next();if(f.equals(n.type,f.string)){let i=this._next();if(!f.equals(i.type,f.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new p(f.tag,42,0)}if(f.equals(n.type,f.map)){let i=this._next();if(f.equals(i.type,f.string)&&i.value==="bytes"){let o=this._next();if(f.equals(o.type,f.string)){for(let a=0;a<2;a++){let c=this._next();if(!f.equals(c.type,f.break))throw new Error("Invalid encoded Bytes form")}let s=Mi.decode(`m${o.value}`);return new p(f.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},rc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>_.parse(t())}};var _n=297;var Sn=t=>{let e=dh(t),r=Object.assign(rc,{tokenizer:new $i(e,rc)});return Pi(e,r)};var T0=new TextDecoder;var B0=new TextEncoder;var Fe={};D(Fe,{code:()=>nt,createLink:()=>dc,createNode:()=>hc,decode:()=>pr,encode:()=>Y,name:()=>Sh,prepare:()=>j,validate:()=>Gi});var ph=new TextDecoder;function Hi(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let i=t[e++];if(r+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[r,e]}function In(t,e){let r;[r,e]=Hi(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function nc(t,e){let r;return[r,e]=Hi(t,e),[r&7,r>>3,e]}function mh(t){let e={},r=t.length,n=0;for(;n<r;){let i,o;if([i,o,n]=nc(t,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=In(t,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=In(t,n),e.Name=ph.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=Hi(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function ic(t){let e=t.length,r=0,n,i=!1,o;for(;r<e;){let a,c;if([a,c,r]=nc(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,r]=In(t,r),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=In(t,r),n.push(mh(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var ac=new TextEncoder,oc=2**32,yh=2**31;function gh(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=dr(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=ac.encode(t.Name);r-=n.length,e.set(n,r),r=dr(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=dr(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function sc(t,e,r){return t-=e.Data.length,r.set(e.Data,t),t=dr(r,t,e.Data.length)-1,r[t]=10,t}function cc(t,e){let r=bh(t),n=new Uint8Array(r),i=r,o=e?.fieldOrder==="data-first"?e.fieldOrder:"links-first";if(t.Data&&o==="links-first"&&(i=sc(i,t,n)),t.Links)for(let s=t.Links.length-1;s>=0;s--){let a=gh(t.Links[s],n.subarray(0,i));i-=a,i=dr(n,i,a)-1,n[i]=18}return t.Data&&o==="data-first"&&(i=sc(i,t,n)),n}function wh(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+Bt(r)}if(typeof t.Name=="string"){let r=ac.encode(t.Name).length;e+=1+r+Bt(r)}return typeof t.Tsize=="number"&&(e+=1+Bt(t.Tsize)),e}function bh(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+Bt(r)}if(t.Links)for(let r of t.Links){let n=wh(r);e+=1+n+Bt(n)}return e}function dr(t,e,r){e-=Bt(r);let n=e;for(;r>=yh;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function Bt(t){return t%2===0&&t++,Math.floor((xh(t)+6)/7)}function xh(t){let e=0;return t>=oc&&(t=Math.floor(t/oc),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Eh[t]}var Eh=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var kh=["Data","Links"],_h=["Hash","Name","Tsize"],Vi=new TextEncoder;function lc(t,e){if(t===e)return 0;let r=t.Name?Vi.encode(t.Name):[],n=e.Name?Vi.encode(e.Name):[],i=r.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(r[s]!==n[s]){i=r[s],o=n[s];break}return i<o?-1:o<i?1:0}function uc(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function fc(t){if(typeof t.asCID=="object"){let r=_.asCID(t);if(!r)throw new TypeError("Invalid DAG-PB form");return{Hash:r}}if(typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Hash){let r=_.asCID(t.Hash);try{r||(typeof t.Hash=="string"?r=_.parse(t.Hash):t.Hash instanceof Uint8Array&&(r=_.decode(t.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}r&&(e.Hash=r)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof t.Name=="string"&&(e.Name=t.Name),typeof t.Tsize=="number"&&(e.Tsize=t.Tsize),e}function j(t){if((t instanceof Uint8Array||typeof t=="string")&&(t={Data:t}),typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Data!==void 0)if(typeof t.Data=="string")e.Data=Vi.encode(t.Data);else if(t.Data instanceof Uint8Array)e.Data=t.Data;else throw new TypeError("Invalid DAG-PB form");if(t.Links!==void 0)if(Array.isArray(t.Links))e.Links=t.Links.map(fc),e.Links.sort(lc);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function Gi(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!uc(t,kh))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!uc(r,_h))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&lc(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function hc(t,e=[]){return j({Data:t,Links:e})}function dc(t,e,r){return fc({Hash:r,Name:t,Tsize:e})}function pc(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Sh="dag-pb",nt=112;function Y(t,e){Gi(t);let r={};return t.Links&&(r.Links=t.Links.map(n=>{let i={};return n.Hash&&(i.Hash=n.Hash.bytes),n.Name!==void 0&&(i.Name=n.Name),n.Tsize!==void 0&&(i.Tsize=n.Tsize),i})),t.Data&&(r.Data=t.Data),cc(r,e)}function pr(t){let e=pc(t),r=ic(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(i=>{let o={};try{o.Hash=_.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var z0=new TextEncoder,Ah=new TextDecoder;var Tn=512;function Bn(t){return JSON.parse(Ah.decode(t))}var vt=85;var qi={};D(qi,{identity:()=>yr});var mc=0,Ih="identity",yc=Ee;function Th(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Kr(mc,yc(t))}var yr={code:mc,name:Ih,encode:yc,digest:Th};import{Buffer as Bh}from"node:buffer";function Dt(t){if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function gr(t,e){return Dt(Bh.concat(t,e))}function vh(t){return t[Symbol.asyncIterator]!=null}function Dh(t){if(vh(t))return(async()=>{let n=new Uint8Array(0);for await(let i of t)n=gr([n,i],n.length+i.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return gr(e,r)}var T=Dh;function Ct(t){return t==null?!1:_.asCID(t)===t}function Nt(t,e){let r,n=0,i="";for(;n<e.length;){let o=e[n];if(n++,!Object.hasOwnProperty.call(t,o))throw new At(`Object did not have key "${o}"`);if(i+=`/${o}`,r=t[o],t=r,Ct(r))break}return{value:r,rest:e.slice(n),path:i.substring(1)}}async function*Wi(t,e,r,n){let i=await T(r.get(t,n)),o=tt(i),s=Nt(o,e);yield{cid:Ct(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*gc(t,e,r,n){let i=await T(r.get(t,n)),o=Sn(i),s=Nt(o,e);yield{cid:Ct(s.value)?s.value:t,name:s.path,rest:s.rest}}function Ue(t,e){let r=t.lo+e.lo>>>0,n=t.hi+e.hi+(r<t.lo?1:0)>>>0;return{lo:r,hi:n}}function Ch(t,e){return t+e>>>0}function oe(t,e){let r=t.lo&65535,n=t.lo>>>16,i=e.lo&65535,o=e.lo>>>16,s=r*i,a=r*o,c=n*i,u=n*o,l=(s>>>16)+(a&65535)+(c&65535)>>>0,h=(l<<16|s&65535)>>>0,d=u+(a>>>16)+(c>>>16)+(l>>>16),x=Math.imul(t.lo,e.hi),g=Math.imul(t.hi,e.lo),w=d+x+g>>>0;return{lo:h,hi:w}}function it(t,e){return Math.imul(t,e)>>>0}function Lt(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let i=(t.lo<<e|t.hi>>>32-e)>>>0,o=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:i,hi:o}}e-=32;let r=(t.hi<<e|t.lo>>>32-e)>>>0,n=(t.lo<<e|t.hi>>>32-e)>>>0;return{lo:r,hi:n}}function B(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function ji(t,e){if(e===0)return t;if(e<32){let r=(t.lo>>>e|t.hi<<32-e)>>>0,n=t.hi>>>e;return{lo:r,hi:n}}return{lo:t.hi>>>e-32,hi:0}}function I(t,e){return{lo:t>>>0,hi:e>>>0}}function Yi(t,e){return(t<<e|t>>>32-e)>>>0}function wc(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,i=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:i>>>0}}function Nh(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function bc(t){return t=B(t,ji(t,33)),t=oe(t,I(3981806797,4283543511)),t=B(t,ji(t,33)),t=oe(t,I(444984403,3301882366)),t=B(t,ji(t,33)),t}function Lh(t){return t^=t>>>16,t=it(t,2246822507),t^=t>>>13,t=it(t,3266489909),t^=t>>>16,t}function Ki(t,e=0){let r=I(e,0),n=I(e,0),i=t.length,o=Math.floor(i/16),s=I(289559509,2277735313),a=I(658871167,1291169091);for(let d=0;d<o;d++){let x=wc(t,d*2),g=wc(t,d*2+1);x=oe(x,s),x=Lt(x,31),x=oe(x,a),r=B(r,x),r=Lt(r,27),r=Ue(r,n),r=Ue(oe(r,I(5,0)),I(1390208809,0)),g=oe(g,a),g=Lt(g,33),g=oe(g,s),n=B(n,g),n=Lt(n,31),n=Ue(n,r),n=Ue(oe(n,I(5,0)),I(944331445,0))}let c=I(0,0),u=I(0,0),l=t.slice(o*16);switch(l.length){case 15:u=B(u,I(0,l[14]<<16));case 14:u=B(u,I(0,l[13]<<8));case 13:u=B(u,I(0,l[12]));case 12:u=B(u,I(l[11]<<24,0));case 11:u=B(u,I(l[10]<<16,0));case 10:u=B(u,I(l[9]<<8,0));case 9:u=B(u,I(l[8],0)),u=oe(u,a),u=Lt(u,33),u=oe(u,s),n=B(n,u);case 8:c=B(c,I(0,l[7]<<24));case 7:c=B(c,I(0,l[6]<<16));case 6:c=B(c,I(0,l[5]<<8));case 5:c=B(c,I(0,l[4]));case 4:c=B(c,I(l[3]<<24,0));case 3:c=B(c,I(l[2]<<16,0));case 2:c=B(c,I(l[1]<<8,0));case 1:c=B(c,I(l[0],0)),c=oe(c,s),c=Lt(c,31),c=oe(c,a),r=B(r,c)}let h=I(i,0);return r=B(r,h),n=B(n,h),r=Ue(r,n),n=Ue(n,r),r=bc(r),n=bc(n),r=Ue(r,n),n=Ue(n,r),new Uint8Array([r.hi>>>24&255,r.hi>>>16&255,r.hi>>>8&255,r.hi&255,r.lo>>>24&255,r.lo>>>16&255,r.lo>>>8&255,r.lo&255,n.hi>>>24&255,n.hi>>>16&255,n.hi>>>8&255,n.hi&255,n.lo>>>24&255,n.lo>>>16&255,n.lo>>>8&255,n.lo&255])}function xc(t,e=0){let r=e>>>0,n=t.length,i=Math.floor(n/4),o=3432918353,s=461845907;for(let u=0;u<i;u++){let l=Nh(t,u);l=it(l,o),l=Yi(l,15),l=it(l,s),r^=l,r=Yi(r,13),r=Ch(it(r,5),3864292196)}let a=t.slice(i*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=it(c,o),c=Yi(c,15),c=it(c,s),r^=c}return r^=n,r=Lh(r),r}function Fh(t){let e=new Array(4);for(let r=0;r<4;r++)e[r]=t&255,t=t>>8;return new Uint8Array(e)}var lw=Je({name:"murmur3-32",code:35,encode:t=>Fh(xc(t))}),Dn=Je({name:"murmur3-128",code:34,encode:t=>Ki(t)}),fw=Je({name:"murmur3-x64-64",code:34,encode:t=>Ki(t).subarray(0,8)});var vc=Wt(_c(),1);import{Buffer as Qh}from"node:buffer";var Ji={};D(Ji,{base10:()=>Mh});var Mh=Ts({prefix:"9",name:"base10",alphabet:"0123456789"});var Xi={};D(Xi,{base16:()=>Oh,base16upper:()=>$h});var Oh=ne({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),$h=ne({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Zi={};D(Zi,{base2:()=>Hh});var Hh=ne({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qi={};D(Qi,{base256emoji:()=>jh});var Sc=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}"),Vh=Sc.reduce((t,e,r)=>(t[r]=e,t),[]),Gh=Sc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qh(t){return t.reduce((e,r)=>(e+=Vh[r],e),"")}function Wh(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Gh[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var jh=Yr({prefix:"\u{1F680}",name:"base256emoji",encode:qh,decode:Wh});var eo={};D(eo,{base8:()=>Yh});var Yh=ne({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var to={};D(to,{identity:()=>Kh});var Kh=Yr({prefix:"\0",name:"identity",encode:t=>Is(Ee(t)),decode:t=>Ee(As(t))});var ro={};D(ro,{sha256:()=>wr,sha512:()=>Jh});import Ac from"node:crypto";var wr=Je({name:"sha2-256",code:18,encode:t=>Ee(Ac.createHash("sha256").update(t).digest())}),Jh=Je({name:"sha2-512",code:19,encode:t=>Ee(Ac.createHash("sha512").update(t).digest())});var no={...to,...Zi,...eo,...Ji,...Xi,...Bs,...vs,...Ds,...Oi,...Qi},vw={...ro,...qi};import{Buffer as Xh}from"node:buffer";function ze(t=0){return Dt(Xh.allocUnsafe(t))}function Tc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ic=Tc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),io=Tc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ze(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Zh={utf8:Ic,"utf-8":Ic,hex:no.base16,latin1:io,ascii:io,binary:io,...no},Bc=Zh;function Cn(t,e="utf8"){let r=Bc[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Dt(Qh.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var ye=class t{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,r,n=0){this._options=e,this._popCount=0,this._parent=r,this._posAtParent=n,this._children=new vc.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof t?i.push(o.serialize(e,r)):i.push(e(o,s))),i),n))}async asyncTransform(e,r){return Dc(this,e,r)}toJSON(){return this.serialize(td,rd)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);if(!(n instanceof t)&&n!=null&&n.key===e)return n}async _findPlace(e){let r=this._options.hash(typeof e=="string"?Cn(e):e),n=await r.take(this._options.bits),i=this._children.get(n);return i instanceof t?i._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:i}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let i=await n._findPlace(r.existingChild.hash);return i.bucket._putAt(i,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(ed);if(e!=null&&!(e instanceof t)){let r=e.hash;r.untake(this._options.bits);let n={pos:this._posAtParent,hash:r,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function ed(t){return!!t}function td(t,e){return t.key}function rd(t){return t}async function Dc(t,e,r){let n=[];for(let i of t._children.compactArray())if(i instanceof ye)await Dc(i,e,r);else{let o=await e(i);n.push({bitField:t._children.bitField(),children:o})}return r(n)}var nd=[255,254,252,248,240,224,192,128],id=[1,3,7,15,31,63,127,255],Nn=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,r),a=od(i,o-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function od(t,e,r){let n=sd(e,r);return(t&n)>>>e}function sd(t,e){return nd[t]&id[Math.min(e+t-1,7)]}function Cc(t){function e(r){return r instanceof Ln?r:new Ln(r,t)}return e}var Ln=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),r),s=i.take(o);n=(n<<o)+s,r-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),r);n.untake(i),r-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?gr([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new Nn(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Rn(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:Cc(t.hashFn)};return new ye(e)}function ad(t){return t.buffer instanceof ArrayBuffer}function Fn(t){return ad(t)?t:t.slice()}var br=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var cd=Math.pow(2,7),ud=Math.pow(2,14),ld=Math.pow(2,21),Nc=Math.pow(2,28),Lc=Math.pow(2,35),Rc=Math.pow(2,42),Fc=Math.pow(2,49),H=128,Pe=127;function xr(t){if(t<cd)return 1;if(t<ud)return 2;if(t<ld)return 3;if(t<Nc)return 4;if(t<Lc)return 5;if(t<Rc)return 6;if(t<Fc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Uc(t,e,r=0){switch(xr(t)){case 8:e[r++]=t&255|H,t/=128;case 7:e[r++]=t&255|H,t/=128;case 6:e[r++]=t&255|H,t/=128;case 5:e[r++]=t&255|H,t/=128;case 4:e[r++]=t&255|H,t>>>=7;case 3:e[r++]=t&255|H,t>>>=7;case 2:e[r++]=t&255|H,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function zc(t,e){let r=t[e],n=0;if(n+=r&Pe,r<H||(r=t[e+1],n+=(r&Pe)<<7,r<H)||(r=t[e+2],n+=(r&Pe)<<14,r<H)||(r=t[e+3],n+=(r&Pe)<<21,r<H)||(r=t[e+4],n+=(r&Pe)*Nc,r<H)||(r=t[e+5],n+=(r&Pe)*Lc,r<H)||(r=t[e+6],n+=(r&Pe)*Rc,r<H)||(r=t[e+7],n+=(r&Pe)*Fc,r<H))return n;throw new RangeError("Could not decode varint")}var oo=new Float32Array([-0]),Me=new Uint8Array(oo.buffer);function Pc(t,e,r){oo[0]=t,e[r]=Me[0],e[r+1]=Me[1],e[r+2]=Me[2],e[r+3]=Me[3]}function Mc(t,e){return Me[0]=t[e],Me[1]=t[e+1],Me[2]=t[e+2],Me[3]=t[e+3],oo[0]}var so=new Float64Array([-0]),M=new Uint8Array(so.buffer);function Oc(t,e,r){so[0]=t,e[r]=M[0],e[r+1]=M[1],e[r+2]=M[2],e[r+3]=M[3],e[r+4]=M[4],e[r+5]=M[5],e[r+6]=M[6],e[r+7]=M[7]}function $c(t,e){return M[0]=t[e],M[1]=t[e+1],M[2]=t[e+2],M[3]=t[e+3],M[4]=t[e+4],M[5]=t[e+5],M[6]=t[e+6],M[7]=t[e+7],so[0]}var fd=BigInt(Number.MAX_SAFE_INTEGER),hd=BigInt(Number.MIN_SAFE_INTEGER),te=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ot;if(e<fd&&e>hd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Hc&&(i=0n,++n>Hc&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return ot;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):ot}},ot=new te(0,0);ot.toBigInt=function(){return 0n};ot.zzEncode=ot.zzDecode=function(){return this};ot.length=function(){return 1};var Hc=4294967296n;function Vc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Gc(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ao(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Un(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var co=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Fn(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ue(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ue(this,4);return Un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ue(this,4);return Un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ue(this,4);let e=Mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ue(this,4);let e=$c(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Gc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ue(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new te(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ue(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ue(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ue(this,8);let e=Un(this.buf,this.pos+=4),r=Un(this.buf,this.pos+=4);return new te(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=zc(this.buf,this.pos);return this.pos+=xr(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Er(t){return new co(t instanceof Uint8Array?t:t.subarray())}function Oe(t,e,r){let n=Er(t);return e.decode(n,void 0,r)}function uo(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return ze(s);i+s>e&&(n=ze(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var st=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function lo(){}var ho=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},dd=uo();function pd(t){return globalThis.Buffer!=null?ze(t):dd(t)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new st(lo,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new st(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new po((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(zn,10,te.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=te.fromBigInt(e);return this._push(zn,r.length(),r)}uint64Number(e){return this._push(Uc,xr(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=te.fromBigInt(e).zzEncode();return this._push(zn,r.length(),r)}sint64Number(e){let r=te.fromNumber(e).zzEncode();return this._push(zn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(fo,1,e?1:0)}fixed32(e){return this._push(kr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=te.fromBigInt(e);return this._push(kr,4,r.lo)._push(kr,4,r.hi)}fixed64Number(e){let r=te.fromNumber(e);return this._push(kr,4,r.lo)._push(kr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Pc,4,e)}double(e){return this._push(Oc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(fo,1,0):this.uint32(r)._push(yd,r,e)}string(e){let r=Vc(e);return r!==0?this.uint32(r)._push(ao,r,e):this._push(fo,1,0)}fork(){return this.states=new ho(this),this.head=this.tail=new st(lo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new st(lo,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=pd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function fo(t,e,r){e[r]=t&255}function md(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var po=class extends st{next;constructor(e,r){super(md,e,r),this.next=void 0}};function zn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function kr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function yd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(gd,e,t),this},_r.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(wd,e,t),this});function gd(t,e,r){e.set(t,r)}function wd(t,e,r){t.length<40?ao(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Cn(t),r)}function mo(){return new _r}function $e(t,e){let r=mo();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*He(t,e,r){let n=Er(t);yield*e.stream(n,void 0,".",r)}var Pn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Mn(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function yo(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},i=function*(s,a){};return Mn("enum",Pn.VARINT,r,n,i)}function Ve(t,e,r){return Mn("message",Pn.LENGTH_DELIMITED,t,e,r)}var Se=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var P;(function(t){let e;(function(a){a.RAW="RAW",a.DIRECTORY="DIRECTORY",a.FILE="FILE",a.METADATA="METADATA",a.SYMLINK="SYMLINK",a.HAMT_SHARD="HAMT_SHARD"})(e=t.Type||(t.Type={}));let r;(function(a){a[a.RAW=0]="RAW",a[a.DIRECTORY=1]="DIRECTORY",a[a.FILE=2]="FILE",a[a.METADATA=3]="METADATA",a[a.SYMLINK=4]="SYMLINK",a[a.HAMT_SHARD=5]="HAMT_SHARD"})(r||(r={})),(function(a){a.codec=()=>yo(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=Ve((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),t.Type.codec().encode(a.type,c)),a.data!=null&&(c.uint32(18),c.bytes(a.data)),a.fileSize!=null&&(c.uint32(24),c.uint64(a.fileSize)),a.blockSizes!=null&&a.blockSizes.length>0)for(let l of a.blockSizes)c.uint32(32),c.uint64(l);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanOut!=null&&(c.uint32(48),c.uint64(a.fanOut)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),Sr.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let l={blockSizes:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let d=a.uint32();switch(d>>>3){case 1:{l.type=t.Type.codec().decode(a);break}case 2:{l.data=a.bytes();break}case 3:{l.fileSize=a.uint64();break}case 4:{if(u.limits?.blockSizes!=null&&l.blockSizes.length===u.limits.blockSizes)throw new Se('Decode error - repeated field "blockSizes" had too many elements');l.blockSizes.push(a.uint64());break}case 5:{l.hashType=a.uint64();break}case 6:{l.fanOut=a.uint64();break}case 7:{l.mode=a.uint32();break}case 8:{l.mtime=Sr.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(d&7);break}}}return l},function*(a,c,u,l={}){let h={blockSizes:0},d=c==null?a.len:a.pos+c;for(u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"start",message:"UnixFS"});a.pos<d;){let x=a.uint32();switch(x>>>3){case 1:{yield{field:`${u}type`,value:t.Type.codec().decode(a)};break}case 2:{yield{field:`${u}data`,value:a.bytes()};break}case 3:{yield{field:`${u}fileSize`,value:a.uint64()};break}case 4:{if(l.limits?.blockSizes!=null&&h.blockSizes===l.limits.blockSizes)throw new Se('Streaming decode error - repeated field "blockSizes" had too many elements');yield{field:`${u}blockSizes[]`,index:h.blockSizes,value:a.uint64()},h.blockSizes++;break}case 5:{yield{field:`${u}hashType`,value:a.uint64()};break}case 6:{yield{field:`${u}fanOut`,value:a.uint64()};break}case 7:{yield{field:`${u}mode`,value:a.uint32()};break}case 8:{yield*Sr.codec().stream(a,a.uint32(),`${u}mtime.`,{limits:l.limits?.mtime});break}default:{a.skipType(x&7);break}}}u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"end",message:"UnixFS"})})),n);function i(a){return $e(a,t.codec())}t.encode=i;function o(a,c){return Oe(a,t.codec(),c)}t.decode=o;function s(a,c){return He(a,t.codec(),c)}t.stream=s})(P||(P={}));var Sr;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.seconds!=null&&(s.uint32(8),s.int64(o.seconds)),o.fractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(o.fractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.seconds=o.int64();break}case 2:{a.fractionalNanoseconds=o.fixed32();break}default:{o.skipType(u&7);break}}}return a},function*(o,s,a){let c=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"UnixTime"});o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}seconds`,value:o.int64()};break}case 2:{yield{field:`${a}fractionalNanoseconds`,value:o.fixed32()};break}default:{o.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"UnixTime"})})),e);function r(o){return $e(o,t.codec())}t.encode=r;function n(o,s){return Oe(o,t.codec(),s)}t.decode=n;function i(o,s){return He(o,t.codec(),s)}t.stream=i})(Sr||(Sr={}));var Wc;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.mimeType!=null&&(s.uint32(10),s.string(o.mimeType)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();u>>>3===1?a.mimeType=o.string():o.skipType(u&7)}return a},function*(o,s,a){let c=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Metadata"});o.pos<c;){let u=o.uint32();u>>>3===1?yield{field:`${a}mimeType`,value:o.string()}:o.skipType(u&7)}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Metadata"})})),e);function r(o){return $e(o,t.codec())}t.encode=r;function n(o,s){return Oe(o,t.codec(),s)}t.decode=n;function i(o,s){return He(o,t.codec(),s)}t.stream=i})(Wc||(Wc={}));var Ge;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.hash!=null&&(s.uint32(10),s.bytes(o.hash)),o.name!=null&&(s.uint32(18),s.string(o.name)),o.tSize!=null&&(s.uint32(24),s.uint64(o.tSize)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.hash=o.bytes();break}case 2:{a.name=o.string();break}case 3:{a.tSize=o.uint64();break}default:{o.skipType(u&7);break}}}return a},function*(o,s,a){let c=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Link"});o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}hash`,value:o.bytes()};break}case 2:{yield{field:`${a}name`,value:o.string()};break}case 3:{yield{field:`${a}tSize`,value:o.uint64()};break}default:{o.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Link"})})),e);function r(o){return $e(o,t.codec())}t.encode=r;function n(o,s){return Oe(o,t.codec(),s)}t.decode=n;function i(o,s){return He(o,t.codec(),s)}t.stream=i})(Ge||(Ge={}));var Rt;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.data!=null&&(s.uint32(10),P.codec().encode(o.data,s)),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Ge.codec().encode(c,s);a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{c.data=P.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new Se('Decode error - repeated field "links" had too many elements');c.links.push(Ge.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}default:{o.skipType(l&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},l=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Node"});o.pos<l;){let h=o.uint32();switch(h>>>3){case 1:{yield*P.codec().stream(o,o.uint32(),`${a}data.`,{limits:c.limits?.data});break}case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new Se('Streaming decode error - repeated field "links" had too many elements');for(let d of Ge.codec().stream(o,o.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...d,index:u.links};u.links++;break}default:{o.skipType(h&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Node"})})),e);function r(o){return $e(o,t.codec())}t.encode=r;function n(o,s){return Oe(o,t.codec(),s)}t.decode=n;function i(o,s){return He(o,t.codec(),s)}t.stream=i})(Rt||(Rt={}));var jc;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Ge.codec().encode(c,s);o.data!=null&&(s.uint32(10),P.codec().encode(o.data,s)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new Se('Decode error - repeated field "links" had too many elements');c.links.push(Ge.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}case 1:{c.data=P.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}default:{o.skipType(l&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},l=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"LegacyNode"});o.pos<l;){let h=o.uint32();switch(h>>>3){case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new Se('Streaming decode error - repeated field "links" had too many elements');for(let d of Ge.codec().stream(o,o.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...d,index:u.links};u.links++;break}case 1:{yield*P.codec().stream(o,o.uint32(),`${a}data.`,{limits:c.limits?.data});break}default:{o.skipType(h&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"LegacyNode"})})),e);function r(o){return $e(o,t.codec())}t.encode=r;function n(o,s){return Oe(o,t.codec(),s)}t.decode=n;function i(o,s){return He(o,t.codec(),s)}t.stream=i})(jc||(jc={}));var Yc={RAW:"raw",DIRECTORY:"directory",FILE:"file",METADATA:"metadata",SYMLINK:"symlink",HAMT_SHARD:"hamt-sharded-directory"},bd=["directory","hamt-sharded-directory"],Kc=parseInt("0644",8),Jc=parseInt("0755",8),Ft=class t{static unmarshal(e){let r=P.decode(e),n=new t({type:Yc[r.type!=null?r.type.toString():"FILE"],data:r.data,blockSizes:r.blockSizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.seconds??0n,nsecs:r.mtime.fractionalNanoseconds}:void 0,fanout:r.fanOut});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(Yc).includes(r))throw new br("Type: "+r+" is not valid");this.type=r??"file",this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a,n!=null&&(this.data=Fn(n))}set mode(e){e==null?this._mode=this.isDirectory()?Jc:Kc:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return bd.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(r=>{e+=r}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=P.Type.RAW;break;case"directory":e=P.Type.DIRECTORY;break;case"file":e=P.Type.FILE;break;case"metadata":e=P.Type.METADATA;break;case"symlink":e=P.Type.SYMLINK;break;case"hamt-sharded-directory":e=P.Type.HAMT_SHARD;break;default:throw new br(`Type: ${e} is not valid`)}let r=this.data;(this.data==null||this.data.length===0)&&(r=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===Kc&&!this.isDirectory()&&(n=void 0),n===Jc&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={seconds:this.mtime.secs,fractionalNanoseconds:this.mtime.nsecs}),P.encode({type:e,data:r,fileSize:this.type==="file"||this.type==="raw"?this.fileSize():void 0,blockSizes:this.blockSizes,hashType:this.hashType,fanOut:this.fanout,mode:n,mtime:i})}};function On(t){return t.type==="DIRECTORY"}function go(t){return t.type==="FILE"}function wo(t){return t.type==="RAW"}function bo(t){return t.type==="SYMLINK"}function qe(t){return t.type==="HAMT_SHARD"&&t.data instanceof Uint8Array&&typeof t.fanOut=="bigint"&&typeof t.hashType=="bigint"}function Ae(t){return typeof t.name=="string"&&_.asCID(t.hash)===t.hash}function*$n(t){let e={},r={};for(let n of Rt.stream(t))switch(n.field){case".data":{if(n.type==="start"&&(r={}),n.type==="end"){if(On(r)||qe(r)||go(r)||wo(r)||bo(r)){yield r;return}throw new C("PBNode Data was not a valid UnixFS type")}break}case".data.type":{r.type=n.value;break}case".data.data":{r.data=n.value;break}case".data.fanOut":{r.fanOut=n.value;break}case".data.hashType":{r.hashType=n.value;break}case".links[]":{n.type==="start"&&(e={type:"LINK"}),n.type==="end"&&Ae(e)&&(yield e);break}case".links[].name":{e.name=n.value;break}case".links[].hash":{e.hash=_.decode(n.value);break}default:}}var Xc=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),xd=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*Hn(t,e,r,n,i,o,s){let a=(o.lastBucket.tableSize()-1).toString(16).length,c=[];for(let m of e){if(!Ae(m))throw new C("Invalid link");if(c.push(m),m.name.length===a){let k=parseInt(m.name,16);o.lastBucket._putObjectAt(k,new ye({hash:o.lastBucket._options.hash,bits:o.lastBucket._options.bits},o.lastBucket,k))}if(m.name.substring(a)===r){yield{cid:m.hash,name:r,rest:n};return}await o.rootBucket.put(m.name.substring(a),!0)}let u=await o.rootBucket._findNewBucketAndPos(r),l=Xc(u.pos,a),h=xd(u);h.length>o.hamtDepth&&(o.lastBucket=h[o.hamtDepth],l=Xc(o.lastBucket._posAtParent,a));let d=c.find(m=>m.name==null?!1:m.name===l);if(d==null)return;o.hamtDepth++;let x=await T(i.get(d.hash,s));s?.yieldSubShards===!0&&(yield{cid:d.hash,name:d.name,rest:[r,...n]});let g=$n(x),{value:w}=g.next();if(c=[],w!=null){if(qe(w)){yield*Hn(w,g,r,n,i,o,s);return}if(!Ae(w))throw new C("Did not read Link or Data from dag-pb block");c.push(w);for(let m of g){if(qe(m)){yield*Hn(m,c,r,n,i,o,s);return}if(!Ae(m))throw new C("Did not read Link or Data from dag-pb block");c.push(m)}}}function*Zc(t,e,r){for(let n of t){if(!Ae(n))throw new C("Invalid link");if(n.name===e[0]){yield{cid:n.hash,name:e[0],rest:e.slice(1)};return}}throw new W(`No link "${e[0]}" found under ${r}`)}var Ed=async function(t){return(await Dn.encode(t)).slice(0,8).reverse()};async function*Qc(t,e,r,n,i,o){let s=Rn({hashFn:Ed,bits:Math.log2(Number(t.fanOut))}),a={rootBucket:s,hamtDepth:1,lastBucket:s};for await(let c of Hn(t,e,r[0],r.slice(1),i,a,o))if(yield c,c.name===r[0])return;throw new W(`No link "${r[0]}" found under ${n}`)}async function*eu(t,e,r,n){let i=await T(r.get(t,n)),o=[],s=$n(i),{value:a}=s.next(),c=!1,u=!1;if(a!=null){if(u=On(a),c=qe(a),go(a)||wo(a)||bo(a)){yield{cid:t,name:e[0],rest:e.slice(1)};return}if(u||c&&n?.translateHAMTPath===!1){yield*Zc(s,e,t);return}if(c){yield*Qc(a,s,e,t,r,n);return}if(!Ae(a))throw new C("Did not read Link or Data from dag-pb block");o.push(a);for(let l of s){if(u=On(l),c=qe(l),u||c&&n?.translateHAMTPath===!1){yield*Zc(o,e,t);return}if(qe(l)){yield*Qc(l,o,e,t,r,n);return}if(!Ae(l))throw new C("Did not read Link or Data from dag-pb block");o.push(l)}}throw new W(`No link "${e[0]}" found under ${t}`)}async function*tu(t,e,r,n){if(e.length!==0)throw new At(`Cannot load path /${e.join("/")} from identity block`)}async function*ru(t,e,r,n){let i=await T(r.get(t,n)),o=Bn(i),s=Nt(o,e);yield{cid:t,name:s.path,rest:s.rest}}async function*nu(t,e,r,n){if(e.length!==0)throw new W(`Cannot load path /${e.join("/")} from raw block`)}var _d={[nt]:eu,[vt]:nu,[mn]:Wi,81:Wi,[_n]:gc,[yr.code]:tu,[Tn]:ru};async function*iu(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...i]=t.split(/(?<!\\)\//g).filter(Boolean),o=_.parse(n),s=[o],a=`${o}`;for(yield{cid:o,name:a,path:a,roots:s,remainder:i};i.length>0;){let c=_d[o.code];if(c==null)throw new It(`No resolver for code ${o.code}`);let u=!1;for await(let l of c(o,i,e,r)){if(o=l.cid,u=!s[s.length-1].equals(o),i=l.rest,!u)break;s=[...s,l.cid],a=`${a}/${l.name}`,yield{cid:l.cid,name:l.name,path:a,roots:s,remainder:l.rest}}if(!u)break}if(r?.signal?.throwIfAborted(),i.length!==0)throw new W(`Could not resolve path /${i.join("/")} under ${t}`)}function Sd(t){return t[Symbol.asyncIterator]!=null}function Ad(t){if(Sd(t))return(async()=>{let r;for await(let n of t)r=n;return r})();let e;for(let r of t)e=r;return e}var ou=Ad;async function xo(t,e,r,n,i){let o=await T(n.get(t,i)),s=tt(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}async function su(t,e,r,n,i){let o=await T(n.get(t,i)),s=Sn(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}var F=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Ar(t,e,r,n){let i=BigInt(t.length),o=BigInt(e+i);return r>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(t=t.subarray(0,Number(n-e))),r>=e&&r<o&&(t=t.subarray(Number(r-e))),t)}var Vn=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),o=BigInt(r);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw new _e("Offset must be greater than or equal to 0");if(i>n)throw new _e("Offset must be less than the file size");if(o<0n)throw new _e("Length must be greater than or equal to 0");if(o>n)throw new _e("Length must be less than the file size");return{start:i,end:o}};function Gn(t,e){async function*r(n={}){let{start:i,end:o}=Vn(t.length,n.offset,n.length),s=Ar(t,0n,i,o);n.onProgress?.(new F(e,{bytesRead:BigInt(s.byteLength),totalBytes:o-i,fileSize:BigInt(t.byteLength)})),yield s}return r}async function au(t,e,r,n,i){let o=ht(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:Gn(o.digest,"unixfs:exporter:progress:identity"),size:BigInt(o.bytes.byteLength),node:o.bytes}}async function cu(t,e,r,n,i){let o=await T(n.get(t,i)),s=Bn(o);return{type:"object",cid:t,name:e,path:r,object:s,size:BigInt(o.byteLength),node:o}}async function uu(t,e,r,n,i){let o=await T(n.get(t,i));return{type:"raw",cid:t,name:e,path:r,content:Gn(o,"unixfs:exporter:progress:raw"),size:BigInt(o.length),node:o}}function lu(t,e,r,n){async function*i(o={}){let s=o.offset??0,a=o.length??e.Links.length,c=e.Links.slice(s,s+a);o.onProgress?.(new F("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(u=>({cid:u.Hash,name:u.Name??"",path:`${n}/${u.Name??""}`,size:BigInt(u.Tsize??0)}))}return i}function Id(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var fu=Id;function Td(t){return t[Symbol.asyncIterator]!=null}function Bd(t,e){let r=0;if(Td(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=fu(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var hu=Bd;function K(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var qn=globalThis.CustomEvent??Event;async function*Eo(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,o=[],s=K(),a=K(),c=!1,u,l=!1,h=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let w of t){if(o.length===r&&(s=K(),await s.promise),l||h)break;let m={done:!1};o.push(m),w().then(k=>{m.done=!0,m.ok=!0,m.value=k,i.dispatchEvent(new qn("task-complete"))},k=>{m.done=!0,m.err=k,i.dispatchEvent(new qn("task-complete"))})}c=!0,i.dispatchEvent(new qn("task-complete"))}catch(w){u=w,i.dispatchEvent(new qn("task-complete"))}});function d(){return n?o[0]?.done:!!o.find(w=>w.done)}function*x(){for(;o.length>0&&o[0].done;){let w=o[0];if(o.shift(),w.ok)yield w.value;else throw l=!0,s.resolve(),w.err;s.resolve()}}function*g(){for(;d();)for(let w=0;w<o.length;w++)if(o[w].done){let m=o[w];if(o.splice(w,1),w--,m.ok)yield m.value;else throw l=!0,s.resolve(),m.err;s.resolve()}}try{for(;;){if(d()||(a=K(),await a.promise),u!=null||(n?yield*x():yield*g(),u!=null))throw u;if(c&&o.length===0)break}}finally{h=!0,s.resolve()}}var Wn=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ut=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Wn(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Wn(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var ko=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function jn(t={}){return vd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function vd(t,e){e=e??{};let r=e.onEnd,n=new Ut,i,o,s,a=K(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((m,k)=>{o=A=>{o=null,n.push(A);try{m(t(n))}catch(E){k(E)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=K()})}},u=m=>o!=null?o(m):(n.push(m),i),l=m=>(n=new Ut,o!=null?o({error:m}):(n.push({error:m}),i)),h=m=>{if(s)return i;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},d=m=>s?i:(s=!0,m!=null?l(m):u({done:!0})),x=()=>(n=new Ut,d(),{done:!0}),g=m=>(d(m),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:x,throw:g,push:h,end:d,get readableLength(){return n.size},onEmpty:async m=>{let k=m?.signal;if(k?.throwIfAborted(),n.isEmpty())return;let A,E;k!=null&&(A=new Promise((v,z)=>{E=()=>{z(new ko)},k.addEventListener("abort",E)}));try{await Promise.race([a.promise,A])}finally{E!=null&&k!=null&&k?.removeEventListener("abort",E)}}},r==null)return i;let w=i;return i={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(m){return w.throw(m),r!=null&&(r(m),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(m){return w.end(m),r!=null&&(r(m),r=void 0),i},get readableLength(){return w.readableLength},onEmpty:m=>w.onEmpty(m)},i}function Dd(t){return t.reason}function du(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Dd;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;return Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})]).finally(()=>{i!=null&&e.removeEventListener("abort",i)})}var _o=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=K(),this.haveNext=K()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=K(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=K(),await du(this.readNext.promise,r?.signal,r)}};function pu(){return new _o}function mu(t){return t[Symbol.asyncIterator]!=null}async function Cd(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:i,done:o}=await n.next();if(o===!0)break;await e.push(i,{signal:r}),r.throwIfAborted()}})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*Nd(t){let e=new AbortController,r=pu(),n=t.map(i=>mu(i)?i[Symbol.asyncIterator]():i[Symbol.iterator]());Cd(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let i of n)try{Promise.resolve(i.return?.()).catch(()=>{})}catch{}}}function*Ld(t){for(let e of t)yield*e}function Rd(...t){let e=[];for(let r of t)mu(r)||e.push(r);return e.length===t.length?Ld(e):Nd(t)}var yu=Rd;function gu(t,...e){if(t==null)throw new Error("Empty pipeline");if(So(t)){let n=t;t=()=>n.source}else if(bu(t)||wu(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&So(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)So(r[n])&&(r[n]=Ud(r[n]));return Fd(...r)}var Fd=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},wu=t=>t?.[Symbol.asyncIterator]!=null,bu=t=>t?.[Symbol.iterator]!=null,So=t=>t==null?!1:t.sink!=null&&t.source!=null,Ud=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=jn({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(wu(o))i=async function*(){yield*o,n.end()};else if(bu(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return yu(n,i())}return t.source};var Io=Wt(Eu(),1);var To=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ku=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Bo(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,l=new Promise((h,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){d(ku(s)),t.then(h,d);return}if(s&&(c=()=>{d(ku(s))},s.addEventListener("abort",c,{once:!0})),t.then(h,d),r===Number.POSITIVE_INFINITY)return;let x=new To;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(g){d(g)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?h():i instanceof Error?d(i):(x.message=i??`Promise timed out after ${r} milliseconds`,d(x))},r)}).finally(()=>{l.clear(),c&&s&&s.removeEventListener("abort",c)});return l.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},l}function vo(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Md=100,zt=class{#t=[];#e=0;enqueue(e,r){let{priority:n=0,id:i}=r??{},{size:o}=this,s={priority:n,id:i,run:e};if(o===0){this.#t.length=0,this.#e=0,this.#t.push(s);return}if(this.#t.at(-1).priority>=n){this.#t.push(s);return}this.#o();let a=vo(this.#t,s,(c,u)=>u.priority-c.priority);this.#t.splice(a,0,s)}setPriority(e,r){let n=this.#t.findIndex((o,s)=>s>=this.#e&&o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#t.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#t.findIndex((n,i)=>i<this.#e?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#t.splice(r,1)}dequeue(){if(this.#e===this.#t.length)return;let e=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>Md&&this.#e>this.#t.length/2&&this.#o(),e?.run}filter(e){let r=[];for(let n=this.#e;n<this.#t.length;n++){let i=this.#t[n];i.priority===e.priority&&r.push(i.run)}return r}get size(){return this.#t.length-this.#e}#o(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var Tr=class extends Io.default{#t;#e;#o=0;#d;#m=!1;#b=!1;#u;#x=0;#c;#l;#a;#s=[];#i=0;#r;#I;#n=0;#y;#f;#N=1n;#g=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:zt,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#e=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#u=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#I=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#f=e.autoStart===!1,this.#O()}#k(e){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&e-n>=this.#u)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#L(e){this.#a?this.#s.push(e):this.#o++}#R(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#o>0&&this.#o--}#_(){return this.#s.length-this.#i}get#F(){return this.#e?!0:this.#a?this.#_()<this.#d:this.#o<this.#d}get#U(){return this.#n<this.#y}#z(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#P(){this.#l=void 0,this.#D(),this.#v()}#M(e){if(this.#a){if(this.#k(e),this.#_()>=this.#d){let n=this.#s[this.#i],i=this.#u-(e-n);return this.#T(i),!0}return!1}if(this.#c===void 0){let r=this.#x-e;if(r<0)this.#o=this.#t?this.#n:0;else return this.#T(r),!0}return!1}#T(e){this.#l===void 0&&(this.#l=setTimeout(()=>{this.#P()},e))}#S(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#B(){this.#l&&(clearTimeout(this.#l),this.#l=void 0)}#w(){if(this.#r.size===0){if(this.#S(),this.emit("empty"),this.#n===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#k(r)}this.emit("idle")}return!1}let e=!1;if(!this.#f){let r=Date.now(),n=!this.#M(r);if(this.#F&&this.#U){let i=this.#r.dequeue();this.#e||(this.#L(r),this.#p()),n&&this.#v(),this.emit("active"),i(),e=!0}}return e}#v(){this.#e||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#D()},this.#u),this.#x=Date.now()+this.#u)}#D(){this.#a||(this.#c!==void 0&&(this.#o===0&&this.#n===0?this.#S():this.#x=Date.now()+this.#u),this.#o=this.#t?this.#n:0),this.#A(),this.#p()}#A(){for(;this.#w(););}get concurrency(){return this.#y}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#y=e,this.#A()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(e,r)}async add(e,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#N++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,i)=>{let o=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#g.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(d){throw this.#$(),this.#g.delete(o),d}let l=e({signal:r.signal});if(r.timeout!==void 0&&(l=Bo(Promise.resolve(l),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:d}=r;l=Promise.race([l,new Promise((x,g)=>{u=()=>{g(d.reason)},d.addEventListener("abort",u,{once:!0})})])}let h=await l;n(h),this.emit("completed",h)}catch(l){i(l),this.emit("error",l)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(o),queueMicrotask(()=>{this.#z()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof zt){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,l=()=>{s(),c(),i(u.reason),this.#w(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",l),this.#E.delete(s)},u.aborted){l();return}u.addEventListener("abort",l,{once:!0}),this.#E.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#f?(this.#f=!1,this.#A(),this):this}pause(){this.#f=!0}clear(){for(let e of this.#E)e();this.#r=new this.#I,this.#S(),this.#C(),this.emit("empty"),this.#n===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h(["next","active"],()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(e,r){let n=Array.isArray(e)?e:[e];return new Promise(i=>{let o=()=>{if(!(r&&!r())){for(let s of n)this.off(s,o);i()}};for(let s of n)this.on(s,o)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#f}#O(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#b||(this.#b=!0,queueMicrotask(()=>{this.#b=!1,this.#C()}))}#$(){this.#e||(this.#R(),this.#p())}#C(){let e=this.#m;if(this.#e||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let i=Date.now();this.#k(i),r=this.#_()}else r=this.#o;let n=r>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};async function _u(t,e,r,n,i,o,s){if(e instanceof Uint8Array){let u=Ar(e,n,i,o);r.push(u);return}if(e.Data==null)throw new C("no data in PBNode");let a;try{a=Ft.unmarshal(e.Data)}catch(u){throw new C(u.message)}if(a.data!=null){let u=a.data,l=Ar(u,n,i,o);r.push(l),n+=BigInt(l.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new C("Inconsistent block sizes and dag links");for(let u=0;u<e.Links.length;u++){let l=e.Links[u],h=n,d=h+a.blockSizes[u];if((i>=h&&i<d||o>=h&&o<=d||i<h&&o>d)&&c.push({link:l,blockStart:n}),n=d,n>o)break}await gu(c,u=>hu(u,l=>async()=>{let h=await T(t.get(l.link.Hash,s));return{...l,block:h}}),u=>Eo(u,{ordered:!0,concurrency:s.blockReadConcurrency??10}),async u=>{for await(let{link:l,block:h,blockStart:d}of u){let x;switch(l.Hash.code){case nt:x=pr(h);break;case vt:x=h;break;default:r.end(new C(`Unsupported codec: ${l.Hash.code}`));return}let g=new Tr({concurrency:1});g.on("error",w=>{r.end(w)}),g.add(async()=>{s.onProgress?.(new F("unixfs:exporter:walk:file",{cid:l.Hash})),await _u(t,x,r,d,i,o,s)}),await g.onIdle()}}),n>=o&&r.end()}function Do(t,e,r,n,i){async function*o(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:u}=Vn(a,s.offset,s.length);if(u===0n)return;let l=0n,h=u-c,d=jn();s.onProgress?.(new F("unixfs:exporter:walk:file",{cid:t})),_u(i,e,d,0n,c,u,s).catch(x=>{d.end(x)});for await(let x of d)if(x!=null){if(l+=BigInt(x.byteLength),l>h)throw d.end(),new En("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");l===h&&d.end(),s.onProgress?.(new F("unixfs:exporter:progress:unixfs:file",{bytesRead:l,totalBytes:h,fileSize:a})),yield x}if(l<h)throw new kn("Traversed entire DAG but did not read enough bytes")}return o}async function*Od(t,e,r,n){let i=-1,o=0;for await(let s of Su(t,e,r,n))if(i++,!(n.offset!=null&&n.offset<i)&&(yield s,o++,n.length!=null&&n.length===o))return}async function*Su(t,e,r,n){let i=await T(r.get(t,n)),o=Rt.decode(i);if(o.data?.fanOut==null)throw new C("missing fanout");let s=(o.data.fanOut-1n).toString(16).length;for(let a of o.links){if(a.name==null||a.hash==null)continue;let c=_.decode(a.hash);if(a.name.length===s)yield*Su(c,e,r,n);else{let u=a.name.substring(s);yield{cid:c,name:a.name.substring(s),path:`${e}/${u}`,size:BigInt(a.tSize??0)}}}}function Au(t,e,r,n,i){function o(s={}){return s.onProgress?.(new F("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),Od(t,n,i,s)}return o}var $d={raw:Do,file:Do,directory:lu,"hamt-sharded-directory":Au,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function Iu(t,e,r,n,i){let o=await T(n.get(t,i)),s;try{s=pr(o)}catch(u){throw new C(u.message)}if(s.Data==null)throw new C("no data in PBNode");let a;try{a=Ft.unmarshal(s.Data)}catch(u){throw new C(u.message)}let c=$d[a.type](t,s,a,r,n);if(c==null)throw new W("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s,size:BigInt(o.byteLength)}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var Hd={[nt]:Iu,[vt]:uu,[mn]:xo,81:xo,[_n]:su,[yr.code]:au,[Tn]:cu};async function Tu(t,e,r={}){let n,i;if(t instanceof String||typeof t=="string"){let s=await ou(iu(t,e,r));if(s==null)throw new W(`Could not walk path to ${t}`);n=s.cid,i=s.name,t=s.path}else if(_.asCID(t)===t||t instanceof _)n=t,i=t=n.toString();else throw new _e("Path must be string or CID");let o=Hd[n.code];if(o==null)throw new It(`No resolver for code ${n.code}`);return o(n,i,t,e,r)}function Vd(t){return t[Symbol.asyncIterator]!=null}function Gd(t,e=1){return e=Number(e),Vd(t)?(async function*(){let r=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for await(let n of t)for(r.push(n);r.length>=e;)yield r.slice(0,e),r=r.slice(e);for(;r.length>0;)yield r.slice(0,e),r=r.slice(e)})():(function*(){let r=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for(let n of t)for(r.push(n);r.length>=e;)yield r.slice(0,e),r=r.slice(e);for(;r.length>0;)yield r.slice(0,e),r=r.slice(e)})()}var Kn=Gd;async function*Br(t,e=1){for await(let r of Kn(t,e)){let n=r.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}import{Buffer as Bu}from"node:buffer";function at(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function Ie(t=0){return at(Bu.alloc(t))}function le(t=0){return at(Bu.allocUnsafe(t))}import{Buffer as qd}from"node:buffer";function Co(t,e){return at(qd.concat(t,e))}function vu(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Cu=Symbol.for("@achingbrain/uint8arraylist");function Du(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function Jn(t){return!!t?.[Cu]}var Pt=class t{bufs;length;[Cu]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Jn(n)){r+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Jn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Du(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Du(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Jn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:i}=this._subList(e,r);return Co(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:Co(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),o=new t;return o.length=i,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(s);break}let h=e-a;n.push(s.subarray(h,h+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(l){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Jn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let h=0;h<o;h++)s[h]=-1;for(let h=0;h<i;h++)s[n[h]]=h;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=r;h<=c;h+=l){l=0;for(let d=u;d>=0;d--){let x=this.get(h+d);if(n[d]!==x){l=Math.max(1,d-a[x]);break}}if(l===0)return h}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=le(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let i=Ie(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let i=Ie(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let i=Ie(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=le(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let i=Ie(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let i=Ie(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let i=Ie(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let i=Ie(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let i=Ie(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!vu(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((i,o)=>i+o.byteLength,0)),n.length=r,n}};var No=BigInt(34),Xn=8,Zn=262144,Nu="links-bytes",Qn=262144,Lu=1048576,Ru=50,Fu=10,Uu=!0,zu=!0,Pu=!1,Mu="file";var Ou=(t={})=>{let e=t.chunkSize??Qn;return async function*(n){let i=new Pt,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.subarray(0,e),s=!0,e===i.length)i=new Pt,o=0;else{let u=new Pt;u.append(i.sublist(e)),i=u,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var vr=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var Wd=Math.pow(2,7),jd=Math.pow(2,14),Yd=Math.pow(2,21),$u=Math.pow(2,28),Hu=Math.pow(2,35),Vu=Math.pow(2,42),Gu=Math.pow(2,49),G=128,We=127;function Dr(t){if(t<Wd)return 1;if(t<jd)return 2;if(t<Yd)return 3;if(t<$u)return 4;if(t<Hu)return 5;if(t<Vu)return 6;if(t<Gu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function qu(t,e,r=0){switch(Dr(t)){case 8:e[r++]=t&255|G,t/=128;case 7:e[r++]=t&255|G,t/=128;case 6:e[r++]=t&255|G,t/=128;case 5:e[r++]=t&255|G,t/=128;case 4:e[r++]=t&255|G,t>>>=7;case 3:e[r++]=t&255|G,t>>>=7;case 2:e[r++]=t&255|G,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Wu(t,e){let r=t[e],n=0;if(n+=r&We,r<G||(r=t[e+1],n+=(r&We)<<7,r<G)||(r=t[e+2],n+=(r&We)<<14,r<G)||(r=t[e+3],n+=(r&We)<<21,r<G)||(r=t[e+4],n+=(r&We)*$u,r<G)||(r=t[e+5],n+=(r&We)*Hu,r<G)||(r=t[e+6],n+=(r&We)*Vu,r<G)||(r=t[e+7],n+=(r&We)*Gu,r<G))return n;throw new RangeError("Could not decode varint")}var Lo=new Float32Array([-0]),je=new Uint8Array(Lo.buffer);function ju(t,e,r){Lo[0]=t,e[r]=je[0],e[r+1]=je[1],e[r+2]=je[2],e[r+3]=je[3]}function Yu(t,e){return je[0]=t[e],je[1]=t[e+1],je[2]=t[e+2],je[3]=t[e+3],Lo[0]}var Ro=new Float64Array([-0]),$=new Uint8Array(Ro.buffer);function Ku(t,e,r){Ro[0]=t,e[r]=$[0],e[r+1]=$[1],e[r+2]=$[2],e[r+3]=$[3],e[r+4]=$[4],e[r+5]=$[5],e[r+6]=$[6],e[r+7]=$[7]}function Ju(t,e){return $[0]=t[e],$[1]=t[e+1],$[2]=t[e+2],$[3]=t[e+3],$[4]=t[e+4],$[5]=t[e+5],$[6]=t[e+6],$[7]=t[e+7],Ro[0]}var Kd=BigInt(Number.MAX_SAFE_INTEGER),Jd=BigInt(Number.MIN_SAFE_INTEGER),re=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ct;if(e<Kd&&e>Jd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Xu&&(i=0n,++n>Xu&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return ct;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):ct}},ct=new re(0,0);ct.toBigInt=function(){return 0n};ct.zzEncode=ct.zzDecode=function(){return this};ct.length=function(){return 1};var Xu=4294967296n;function Zu(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Qu(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Fo(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function fe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ei(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Uo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,fe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw fe(this,4);return ei(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw fe(this,4);return ei(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw fe(this,4);let e=Yu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw fe(this,4);let e=Ju(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw fe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Qu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw fe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw fe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new re(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw fe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw fe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw fe(this,8);let e=ei(this.buf,this.pos+=4),r=ei(this.buf,this.pos+=4);return new re(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Wu(this.buf,this.pos);return this.pos+=Dr(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Cr(t){return new Uo(t instanceof Uint8Array?t:t.subarray())}function Nr(t,e,r){let n=Cr(t);return e.decode(n,void 0,r)}import{Buffer as am}from"node:buffer";var $o={};D($o,{base10:()=>np});var P2=new Uint8Array(0);function tl(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function J(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function rl(t){return new TextEncoder().encode(t)}function nl(t){return new TextDecoder().decode(t)}function Xd(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,m=0,k=0,A=g.length;k!==A&&g[k]===0;)k++,w++;for(var E=(A-k)*l+1>>>0,v=new Uint8Array(E);k!==A;){for(var z=g[k],Te=0,ae=E-1;(z!==0||Te<m)&&ae!==-1;ae--,Te++)z+=256*v[ae]>>>0,v[ae]=z%a>>>0,z=z/a>>>0;if(z!==0)throw new Error("Non-zero carry");m=Te,k++}for(var xe=E-m;xe!==E&&v[xe]===0;)xe++;for(var jr=c.repeat(w);xe<E;++xe)jr+=t.charAt(v[xe]);return jr}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var m=0,k=0;g[w]===c;)m++,w++;for(var A=(g.length-w)*u+1>>>0,E=new Uint8Array(A);g[w];){var v=r[g.charCodeAt(w)];if(v===255)return;for(var z=0,Te=A-1;(v!==0||z<k)&&Te!==-1;Te--,z++)v+=a*E[Te]>>>0,E[Te]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");k=z,w++}if(g[w]!==" "){for(var ae=A-k;ae!==A&&E[ae]===0;)ae++;for(var xe=new Uint8Array(m+(A-ae)),jr=m;ae!==A;)xe[jr++]=E[ae++];return xe}}}function x(g){var w=d(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:x}}var Zd=Xd,Qd=Zd,ol=Qd;var zo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Po=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return sl(this,e)}},Mo=class{decoders;constructor(e){this.decoders=e}or(e){return sl(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function sl(t,e){return new Mo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Oo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new zo(e,r,n),this.decoder=new Po(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Mt({name:t,prefix:e,encode:r,decode:n}){return new Oo(t,e,r,n)}function Ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=ol(r,t);return Mt({prefix:e,name:t,encode:n,decode:o=>J(i(o))})}function ep(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),s=0,a=0,c=0;for(let u=0;u<i;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function tp(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function rp(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function N({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=rp(n);return Mt({prefix:e,name:t,encode(o){return tp(o,n,r)},decode(o){return ep(o,i,r,t)}})}var np=Ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Ho={};D(Ho,{base16:()=>ip,base16upper:()=>op});var ip=N({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),op=N({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Vo={};D(Vo,{base2:()=>sp});var sp=N({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Go={};D(Go,{base256emoji:()=>fp});var al=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}"),ap=al.reduce((t,e,r)=>(t[r]=e,t),[]),cp=al.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function up(t){return t.reduce((e,r)=>(e+=ap[r],e),"")}function lp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=cp[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var fp=Mt({prefix:"\u{1F680}",name:"base256emoji",encode:up,decode:lp});var qo={};D(qo,{base32:()=>Ot,base32hex:()=>mp,base32hexpad:()=>gp,base32hexpadupper:()=>wp,base32hexupper:()=>yp,base32pad:()=>dp,base32padupper:()=>pp,base32upper:()=>hp,base32z:()=>bp});var Ot=N({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hp=N({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),dp=N({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pp=N({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mp=N({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),yp=N({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),gp=N({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wp=N({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bp=N({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wo={};D(Wo,{base36:()=>Lr,base36upper:()=>xp});var Lr=Ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xp=Ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jo={};D(jo,{base58btc:()=>ge,base58flickr:()=>Ep});var ge=Ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ep=Ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Yo={};D(Yo,{base64:()=>kp,base64pad:()=>_p,base64url:()=>Sp,base64urlpad:()=>Ap});var kp=N({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_p=N({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sp=N({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ap=N({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ko={};D(Ko,{base8:()=>Ip});var Ip=N({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Jo={};D(Jo,{identity:()=>Tp});var Tp=Mt({prefix:"\0",name:"identity",encode:t=>nl(t),decode:t=>rl(t)});var eE=new TextEncoder,tE=new TextDecoder;var Rr={};D(Rr,{code:()=>ti,decode:()=>Cp,encode:()=>Dp,name:()=>vp});var vp="raw",ti=85;function Dp(t){return J(t)}function Cp(t){return J(t)}var Zo={};D(Zo,{identity:()=>Zp});var Np=ll,cl=128,Lp=127,Rp=~Lp,Fp=Math.pow(2,31);function ll(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Fp;)e[r++]=t&255|cl,t/=128;for(;t&Rp;)e[r++]=t&255|cl,t>>>=7;return e[r]=t|0,ll.bytes=r-n+1,e}var Up=Xo,zp=128,ul=127;function Xo(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw Xo.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&ul)<<i:(s&ul)*Math.pow(2,i),i+=7}while(s>=zp);return Xo.bytes=o-n,r}var Pp=Math.pow(2,7),Mp=Math.pow(2,14),Op=Math.pow(2,21),$p=Math.pow(2,28),Hp=Math.pow(2,35),Vp=Math.pow(2,42),Gp=Math.pow(2,49),qp=Math.pow(2,56),Wp=Math.pow(2,63),jp=function(t){return t<Pp?1:t<Mp?2:t<Op?3:t<$p?4:t<Hp?5:t<Vp?6:t<Gp?7:t<qp?8:t<Wp?9:10},Yp={encode:Np,decode:Up,encodingLength:jp},Kp=Yp,Fr=Kp;function Ur(t,e=0){return[Fr.decode(t,e),Fr.decode.bytes]}function $t(t,e,r=0){return Fr.encode(t,e,r),e}function Ht(t){return Fr.encodingLength(t)}function Gt(t,e){let r=e.byteLength,n=Ht(t),i=n+Ht(r),o=new Uint8Array(i+r);return $t(t,o,0),$t(r,o,n),o.set(e,i),new Vt(t,r,e,o)}function fl(t){let e=J(t),[r,n]=Ur(e),[i,o]=Ur(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Vt(r,i,s,e)}function hl(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&tl(t.bytes,r.bytes)}}var Vt=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var dl=0,Jp="identity",pl=J;function Xp(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Gt(dl,pl(t))}var Zp={code:dl,name:Jp,encode:pl,digest:Xp};var rs={};D(rs,{sha256:()=>ts,sha512:()=>em});import gl from"crypto";var Qp=20;function es({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new Qo(t,e,r,n,i)}var Qo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??Qp,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ml(n,this.code,r?.truncate):n.then(i=>ml(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ml(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Gt(e,t)}var ts=es({name:"sha2-256",code:18,encode:t=>J(gl.createHash("sha256").update(t).digest())}),em=es({name:"sha2-512",code:19,encode:t=>J(gl.createHash("sha512").update(t).digest())});function wl(t,e){let{bytes:r,version:n}=t;return n===0?rm(r,ns(t),e??ge.encoder):nm(r,ns(t),e??Ot.encoder)}var bl=new WeakMap;function ns(t){let e=bl.get(t);if(e==null){let r=new Map;return bl.set(t,r),r}return e}var qt=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Pr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==im)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Gt(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&hl(e.multihash,n.multihash)}toString(e){return wl(this,e)}toJSON(){return{"/":wl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??xl(n,i,o.bytes))}else if(r[om]===!0){let{version:n,multihash:i,code:o}=r,s=fl(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Pr)throw new Error(`Version 0 CID must use dag-pb (code: ${Pr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=xl(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Pr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=J(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new Vt(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,d]=Ur(e.subarray(r));return r+=d,h},i=n(),o=Pr;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,i]=tm(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ns(o).set(n,e),o}};function tm(t,e){switch(t[0]){case"Q":{let r=e??ge;return[ge.prefix,r.decode(`${ge.prefix}${t}`)]}case ge.prefix:{let r=e??ge;return[ge.prefix,r.decode(t)]}case Ot.prefix:{let r=e??Ot;return[Ot.prefix,r.decode(t)]}case Lr.prefix:{let r=e??Lr;return[Lr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function rm(t,e,r){let{prefix:n}=r;if(n!==ge.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function nm(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var Pr=112,im=18;function xl(t,e,r){let n=Ht(t),i=n+Ht(e),o=new Uint8Array(i+r.byteLength);return $t(t,o,0),$t(e,o,n),o.set(r,i),o}var om=Symbol.for("@ipld/js-cid/CID");var is={...Jo,...Vo,...Ko,...$o,...Ho,...qo,...Wo,...jo,...Yo,...Go},AE={...rs,...Zo};function kl(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var El=kl("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),os=kl("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=le(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),sm={utf8:El,"utf-8":El,hex:is.base16,latin1:os,ascii:os,binary:os,...is},_l=sm;function ni(t,e="utf8"){let r=_l[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?at(am.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function ss(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return le(s);i+s>e&&(n=le(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var ut=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function as(){}var us=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},cm=ss();function um(t){return globalThis.Buffer!=null?le(t):cm(t)}var Or=class{len;head;tail;states;constructor(){this.len=0,this.head=new ut(as,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new ut(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ls((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(ii,10,re.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=re.fromBigInt(e);return this._push(ii,r.length(),r)}uint64Number(e){return this._push(qu,Dr(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=re.fromBigInt(e).zzEncode();return this._push(ii,r.length(),r)}sint64Number(e){let r=re.fromNumber(e).zzEncode();return this._push(ii,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(cs,1,e?1:0)}fixed32(e){return this._push(Mr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=re.fromBigInt(e);return this._push(Mr,4,r.lo)._push(Mr,4,r.hi)}fixed64Number(e){let r=re.fromNumber(e);return this._push(Mr,4,r.lo)._push(Mr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(ju,4,e)}double(e){return this._push(Ku,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(cs,1,0):this.uint32(r)._push(fm,r,e)}string(e){let r=Zu(e);return r!==0?this.uint32(r)._push(Fo,r,e):this._push(cs,1,0)}fork(){return this.states=new us(this),this.head=this.tail=new ut(as,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 ut(as,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=um(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function cs(t,e,r){e[r]=t&255}function lm(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ls=class extends ut{next;constructor(e,r){super(lm,e,r),this.next=void 0}};function ii(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Mr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function fm(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Or.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(hm,e,t),this},Or.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(dm,e,t),this});function hm(t,e,r){e.set(t,r)}function dm(t,e,r){t.length<40?Fo(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ni(t),r)}function fs(){return new Or}function $r(t,e){let r=fs();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Hr(t,e,r){let n=Cr(t);yield*e.stream(n,void 0,"$",r)}var oi={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function si(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function hs(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},i=function*(s){let a=s.int32();yield e(a)};return si("enum",oi.VARINT,r,n,i)}function Vr(t,e,r){return si("message",oi.LENGTH_DELIMITED,t,e,r)}var Gr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var he;(function(t){let e;(function(a){a.Raw="Raw",a.Directory="Directory",a.File="File",a.Metadata="Metadata",a.Symlink="Symlink",a.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(a){a[a.Raw=0]="Raw",a[a.Directory=1]="Directory",a[a.File=2]="File",a[a.Metadata=3]="Metadata",a[a.Symlink=4]="Symlink",a[a.HAMTShard=5]="HAMTShard"})(r||(r={})),(function(a){a.codec=()=>hs(r)})(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Vr((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.Type!=null&&(c.uint32(8),t.DataType.codec().encode(a.Type,c)),a.Data!=null&&(c.uint32(18),c.bytes(a.Data)),a.filesize!=null&&(c.uint32(24),c.uint64(a.filesize)),a.blocksizes!=null&&a.blocksizes.length>0)for(let l of a.blocksizes)c.uint32(32),c.uint64(l);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanout!=null&&(c.uint32(48),c.uint64(a.fanout)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),qr.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let l={blocksizes:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let d=a.uint32();switch(d>>>3){case 1:{l.Type=t.DataType.codec().decode(a);break}case 2:{l.Data=a.bytes();break}case 3:{l.filesize=a.uint64();break}case 4:{if(u.limits?.blocksizes!=null&&l.blocksizes.length===u.limits.blocksizes)throw new Gr('Decode error - repeated field "blocksizes" had too many elements');l.blocksizes.push(a.uint64());break}case 5:{l.hashType=a.uint64();break}case 6:{l.fanout=a.uint64();break}case 7:{l.mode=a.uint32();break}case 8:{l.mtime=qr.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(d&7);break}}}return l},function*(a,c,u,l={}){let h={blocksizes:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let x=a.uint32();switch(x>>>3){case 1:{yield{field:`${u}.Type`,value:t.DataType.codec().decode(a)};break}case 2:{yield{field:`${u}.Data`,value:a.bytes()};break}case 3:{yield{field:`${u}.filesize`,value:a.uint64()};break}case 4:{if(l.limits?.blocksizes!=null&&h.blocksizes===l.limits.blocksizes)throw new Gr('Streaming decode error - repeated field "blocksizes" had too many elements');yield{field:`${u}.blocksizes[]`,index:h.blocksizes,value:a.uint64()},h.blocksizes++;break}case 5:{yield{field:`${u}.hashType`,value:a.uint64()};break}case 6:{yield{field:`${u}.fanout`,value:a.uint64()};break}case 7:{yield{field:`${u}.mode`,value:a.uint32()};break}case 8:{yield*qr.codec().stream(a,a.uint32(),`${u}.mtime`,{limits:l.limits?.mtime});break}default:{a.skipType(x&7);break}}}})),n);function i(a){return $r(a,t.codec())}t.encode=i;function o(a,c){return Nr(a,t.codec(),c)}t.decode=o;function s(a,c){return Hr(a,t.codec(),c)}t.stream=s})(he||(he={}));var qr;(function(t){let e;t.codec=()=>(e==null&&(e=Vr((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.Seconds!=null&&(s.uint32(8),s.int64(o.Seconds)),o.FractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(o.FractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{c.Seconds=o.int64();break}case 2:{c.FractionalNanoseconds=o.fixed32();break}default:{o.skipType(l&7);break}}}return c},function*(o,s,a,c={}){let u=s==null?o.len:o.pos+s;for(;o.pos<u;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Seconds`,value:o.int64()};break}case 2:{yield{field:`${a}.FractionalNanoseconds`,value:o.fixed32()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return $r(o,t.codec())}t.encode=r;function n(o,s){return Nr(o,t.codec(),s)}t.decode=n;function i(o,s){return Hr(o,t.codec(),s)}t.stream=i})(qr||(qr={}));var Sl;(function(t){let e;t.codec=()=>(e==null&&(e=Vr((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.MimeType!=null&&(s.uint32(10),s.string(o.MimeType)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let l=o.uint32();l>>>3===1?c.MimeType=o.string():o.skipType(l&7)}return c},function*(o,s,a,c={}){let u=s==null?o.len:o.pos+s;for(;o.pos<u;){let l=o.uint32();l>>>3===1?yield{field:`${a}.MimeType`,value:o.string()}:o.skipType(l&7)}})),e);function r(o){return $r(o,t.codec())}t.encode=r;function n(o,s){return Nr(o,t.codec(),s)}t.decode=n;function i(o,s){return Hr(o,t.codec(),s)}t.stream=i})(Sl||(Sl={}));var Al={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},pm=["directory","hamt-sharded-directory"],Il=parseInt("0644",8),Tl=parseInt("0755",8),q=class t{static unmarshal(e){let r=he.decode(e),n=new t({type:Al[r.Type!=null?r.Type.toString():"File"],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.Seconds??0n,nsecs:r.mtime.FractionalNanoseconds}:void 0,fanout:r.fanout});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(Al).includes(r))throw new vr("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a}set mode(e){e==null?this._mode=this.isDirectory()?Tl:Il:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return pm.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(r=>{e+=r}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=he.DataType.Raw;break;case"directory":e=he.DataType.Directory;break;case"file":e=he.DataType.File;break;case"metadata":e=he.DataType.Metadata;break;case"symlink":e=he.DataType.Symlink;break;case"hamt-sharded-directory":e=he.DataType.HAMTShard;break;default:throw new vr(`Type: ${e} is not valid`)}let r=this.data;(this.data==null||this.data.length===0)&&(r=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===Il&&!this.isDirectory()&&(n=void 0),n===Tl&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),he.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:i})}};var se=async(t,e,r)=>{r.codec==null&&(r.codec=Fe);let n=await ts.digest(t),i=qt.create(r.cidVersion??1,r.codec.code,n);return await e.put(i,t,r),i};function vl(t){return async function*(r,n){let i=0n;for await(let o of r.content)yield async()=>{let s,a={codec:Fe,cidVersion:t.cidVersion,onProgress:t.onProgress};t.rawLeaves?(a.codec=Rr,a.cidVersion=1):(s=new q({type:t.leafType,data:o}),o=Y({Data:s.marshal(),Links:[]}));let c=await se(o,n,a);return i+=BigInt(o.byteLength),t.onProgress?.(new F("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:r.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var we=class t extends Error{static name="InvalidContentError";static code="ERR_INVALID_CONTENT";name=t.name;code=t.code;constructor(e="Invalid content"){super(e)}},Wr=class extends Error{static name="InvalidShardingStrategyError";static code="ERR_SHARDING_STRATEGY";name=we.name;code=we.code};var Dl=async(t,e,r)=>{let n=new q({type:"directory",mtime:t.mtime,mode:t.mode}),i=Y(j({Data:n.marshal()})),o=await se(i,e,r),s=t.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:t.originalPath,block:i}};async function*mm(t,e,r){let n=-1,i;for await(let o of Br(r.bufferImporter(t,e),r.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function Cl(t){return t.single===!0}var ym=(t,e,r)=>async function(i){if(i.length===1&&Cl(i[0])&&r.reduceSingleLeafToSelf){let l=i[0],h=l.block;return Cl(l)&&(t.mtime!==void 0||t.mode!==void 0)&&(l.unixfs=new q({type:"file",mtime:t.mtime,mode:t.mode,data:l.block}),h={Data:l.unixfs.marshal(),Links:[]},l.block=Y(j(h)),l.cid=await se(l.block,e,{...r,cidVersion:r.cidVersion}),l.size=BigInt(l.block.length)),r.onProgress?.(new F("unixfs:importer:progress:file:layout",{cid:l.cid,path:t.originalPath})),{cid:l.cid,path:t.path,unixfs:l.unixfs,size:l.size,originalPath:t.originalPath}}let o=new q({type:"file",mtime:t.mtime,mode:t.mode}),s=i.filter(l=>l.cid.code===ti&&l.size>0||l.unixfs!=null&&l.unixfs.data==null&&l.unixfs.fileSize()>0n?!0:!!l.unixfs?.data?.length).map(l=>l.cid.code===ti?(o.addBlockSize(l.size),{Name:"",Tsize:Number(l.size),Hash:l.cid}):(l.unixfs?.data==null?o.addBlockSize(l.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(l.unixfs.data.length)),{Name:"",Tsize:Number(l.size),Hash:l.cid})),a={Data:o.marshal(),Links:s},c=Y(j(a)),u=await se(c,e,r);return r.onProgress?.(new F("unixfs:importer:progress:file:layout",{cid:u,path:t.originalPath})),{cid:u,path:t.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((l,h)=>l+(h.Tsize??0),0)),originalPath:t.originalPath,block:c}},Nl=async(t,e,r)=>r.layout(mm(t,e,r),ym(t,e,r));function gm(t){return Symbol.iterator in t}function wm(t){return Symbol.asyncIterator in t}function bm(t){try{if(t instanceof Uint8Array)return(async function*(){yield t})();if(gm(t))return(async function*(){yield*t})();if(wm(t))return t}catch{throw new we("Content was invalid")}throw new we("Content was invalid")}function Ll(t){return async function*(r,n){for await(let i of r){let o;if(i.path!=null&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),xm(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:(async function*(){let c=0n;for await(let u of t.chunker(t.chunkValidator(bm(i.content)))){let l=BigInt(u.byteLength);c+=l,t.onProgress?.(new F("unixfs:importer:progress:file:read",{bytesRead:c,chunkSize:l,path:i.path})),yield u}})(),originalPath:o},a=t.fileBuilder??Nl;yield async()=>a(s,n,t)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o},a=t.dirBuilder??Dl;yield async()=>a(s,n,t)}else throw new Error("Import candidate must have content or path or both")}}}function xm(t){return t.content!=null}var Rl=()=>async function*(e){for await(let r of e){if(r.length===void 0)throw new we("Content was invalid");if(typeof r=="string"||r instanceof String)yield ni(r.toString());else if(Array.isArray(r))yield Uint8Array.from(r);else if(r instanceof Uint8Array)yield r;else throw new we("Content was invalid")}};var Em=174;function ds(t){let e=t?.maxChildrenPerNode??Em;return async function r(n,i){let o=[];for await(let s of Kn(n,e))o.push(await i(s));return o.length>1?r(o,i):o[0]}}var be=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,r){this.options=r??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}};var km=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];function _m(t){let e=0;return t>=4294967296&&(t=Math.floor(t/4294967296),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+km[t]}function Ke(t){return t%2===0&&t++,Math.floor((_m(t)+6)/7)}function ai(t){let e=0;for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);n<128?e++:n<2048?e+=2:n>=55296&&n<=56319&&r+1<t.length?(r++,e+=4):e+=3}return e}function Fl(t,e,r){let n=1+Ke(e)+e;return n+=1+Ke(t)+t,n+=1+Ke(r),1+Ke(n)+n}var Sm=493;function Ul(t,e){let r=2;if(t!==void 0&&t!==Sm&&(r+=1+Ke(t)),e!=null){let n=0,i=Number(e.secs);i<0?n+=11:n+=1+Ke(i),e.nsecs!=null&&(n+=5),r+=1+Ke(n)+n}return 1+Ke(r)+r}function ps(t,e){return e?.cid!=null&&e?.size!=null?t+e.cid.byteLength:0}function ms(t,e){return e?.cid!=null&&e?.size!=null?Fl(t,e.cid.byteLength,Number(e.size)):0}var lt=class extends be{_children;constructor(e,r){super(e,r),this._children=new Map}async put(e,r){if(this.nodeSize!==void 0){let n=this._children.get(e),i=ai(e),o=this.options?.shardSplitStrategy;if(o==="links-bytes")this.nodeSize-=ps(i,n),this.nodeSize+=ps(i,r);else if(o==="block-bytes")this.nodeSize-=ms(i,n),this.nodeSize+=ms(i,r);else throw new Wr(`Invalid shardSplitStrategy: ${o}`);this.nodeSize<0&&(this.nodeSize=void 0)}this.cid=void 0,this.size=void 0,this._children.set(e,r)}async get(e){return Promise.resolve(this._children.get(e))}childCount(){return this._children.size}directChildrenCount(){return this.childCount()}onlyChild(){return this._children.values().next().value}*eachChildSeries(){for(let[e,r]of this._children.entries())yield{key:e,child:r}}marshal(){let e=new q({type:"directory",mtime:this.mtime,mode:this.mode}),r=[];for(let[i,o]of this._children.entries())if(!(o.size==null||o.cid==null)){if(o.cid==null)throw new Error("Directory contents must be flushed before marshaling");r.push({Hash:o.cid,Name:i,Tsize:o.size==null?void 0:Number(o.size)})}let n={Data:e.marshal(),Links:r};return Y(j(n))}async estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;let e=this.options?.shardSplitStrategy;if(e==="links-bytes"){this.nodeSize=0;for(let[r,n]of this._children.entries())this.nodeSize+=ps(ai(r),n)}else if(e==="block-bytes"){this.nodeSize=Ul(this.mode,this.mtime);for(let[r,n]of this._children.entries())this.nodeSize+=ms(ai(r),n)}else throw new Wr(`Invalid shardSplitStrategy: ${e}`);return this.nodeSize}async*flush(e){let r=[];for(let[c,u]of this._children.entries()){let l=u;if(u instanceof be)for await(let h of u.flush(e))l=h,yield h;l.size!=null&&l.cid!=null&&r.push({Name:c,Tsize:Number(l.size),Hash:l.cid})}let n=new q({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:r},o=Y(j(i)),s=await se(o,e,this.options),a=o.length+i.Links.reduce((c,u)=>c+(u.Tsize??0),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};var ci=class t extends Error{static name="NotFoundError";name=t.name;static code="ERR_NOT_FOUND";code=t.code;constructor(e="Not Found"){super(e)}};var ui=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,bytes:i}of e)await this.put(n,i,r),yield n}get(e,r){throw new Error(".get is not implemented")}async*getMany(e,r){for await(let n of e)yield{cid:n,bytes:this.get(n,r)}}delete(e,r){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var li=class extends ui{put(e,r,n){return n?.signal?.throwIfAborted(),e}get(e,r){throw r?.signal?.throwIfAborted(),new ci}has(e,r){return r?.signal?.throwIfAborted(),!1}async delete(e,r){r?.signal?.throwIfAborted()}async*getAll(e){e?.signal?.throwIfAborted()}};async function Am(t){return(await Dn.encode(t)).slice(0,8).reverse()}var ys=class extends be{bucket;constructor(e,r){super(e,r),this.bucket=Rn({hashFn:Am,bits:r.shardFanoutBits??Xn})}async put(e,r){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this.bucket.put(e,r)}async get(e){return this.bucket.get(e)}childCount(){return this.bucket.leafCount()}directChildrenCount(){return this.bucket.childrenCount()}onlyChild(){return this.bucket.onlyChild()}*eachChildSeries(){for(let{key:e,value:r}of this.bucket.eachLeafSeries())yield{key:e,child:r}}async estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;let e=new li,r=await Ol(this.bucket,this,e,this.options);return this.nodeSize=r.size,this.nodeSize}async*flush(e){for await(let r of Pl(this.bucket,e,this,this.options))yield{...r,path:this.path}}},zl=ys;async function*Pl(t,e,r,n){let i=t._children,o=(t.tableSize()-1).toString(16).length,s=[],a=0n;for(let g=0;g<i.length;g++){let w=i.get(g);if(w==null)continue;let m=g.toString(16).toUpperCase().padStart(o,"0");if(w instanceof ye){let k;for await(let A of Pl(w,e,null,n))k=A;if(k==null)throw new Error("Could not flush sharded directory, no sub-shard found");s.push({Name:m,Tsize:Number(k.size),Hash:k.cid}),a+=k.size}else if(Ml(w.value)){let k=w.value,A;for await(let v of k.flush(e))A=v,yield A;if(A==null)throw new Error("Did not flush dir");let E=m+w.key;s.push({Name:E,Tsize:Number(A.size),Hash:A.cid}),a+=A.size}else{let k=w.value;if(k.cid==null)continue;let A=m+w.key,E=k.size;s.push({Name:A,Tsize:Number(E),Hash:k.cid}),a+=BigInt(E??0)}}let c=Uint8Array.from(i.bitField().reverse()),u=new q({type:"hamt-sharded-directory",data:c,fanout:BigInt(t.tableSize()),hashType:No,mtime:r?.mtime,mode:r?.mode}),l={Data:u.marshal(),Links:s},h=Y(j(l)),d=await se(h,e,n),x=BigInt(h.byteLength)+a;yield{cid:d,unixfs:u,size:x}}function Ml(t){return typeof t.flush=="function"}async function Ol(t,e,r,n){let i=t._children,o=(t.tableSize()-1).toString(16).length,s=[],a=0;for(let d=0;d<i.length;d++){let x=i.get(d);if(x==null)continue;let g=d.toString(16).toUpperCase().padStart(o,"0");if(x instanceof ye){let{size:w,cid:m}=await Ol(x,null,r,n);s.push({Name:g,Tsize:Number(w),Hash:m}),a+=g.length+m.byteLength}else if(Ml(x.value)){let w=x.value,m=w.nodeSize;if(w.cid==null)throw new Error("Child directory has not been persisted");s.push({Name:g+x.key,Tsize:Number(m),Hash:w.cid}),a+=g.length+w.cid.byteLength}else{let w=x.value,m=g+x.key,k=w.size;s.push({Name:m,Tsize:Number(k),Hash:w.cid}),a+=g.length+w.cid.byteLength}}let c=Uint8Array.from(i.bitField().reverse()),u=new q({type:"hamt-sharded-directory",data:c,fanout:BigInt(t.tableSize()),hashType:No,mtime:e?.mtime,mode:e?.mode}),l=Y(j({Data:u.marshal(),Links:s}));return{cid:await se(l,r,n),size:n.shardSplitStrategy==="links-bytes"?a:l.length}}async function gs(t,e){let r=e,n=e.options.shardSplitThresholdBytes??Zn;e instanceof lt&&await e.estimateNodeSize()>n&&(r=await Im(e));let i=r.parent;if(i!=null){if(r!==e){if(t!=null&&(t.parent=r),r.parentKey==null)throw new Error("No parent key found");await i.put(r.parentKey,r)}return gs(r,i)}return r}async function Im(t){let e=new zl({root:t.root,dir:!0,parent:t.parent,parentKey:t.parentKey,path:t.path,dirty:t.dirty,flat:!1,mtime:t.mtime,mode:t.mode},t.options);for(let{key:r,child:n}of t.eachChildSeries())await e.put(r,n);return e}var $l=(t="")=>t.split(/(?<!\\)\//).filter(Boolean);async function Tm(t,e,r){let n=$l(t.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,u)await o.put(c,t),e=await gs(null,o);else{let l=await o.get(c);(l==null||!(l instanceof be))&&(l=new lt({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:l?.unixfs?.mtime,mode:l?.unixfs?.mode},r)),await o.put(c,l),o=l}}return e}async function*Hl(t,e){if(!(t instanceof be)){t.unixfs?.isDirectory()===!0&&(yield t);return}yield*t.flush(e)}function Vl(t){return async function*(r,n){let i=new lt({root:!0,dir:!0,path:"",dirty:!0,flat:!0},t),o,s=!1;for await(let a of r){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await Tm(a,i,t),a.unixfs?.isDirectory()!==!0&&(yield a)}if(t.wrapWithDirectory||s&&i.childCount()>1)yield*Hl(i,n);else for(let a of i.eachChildSeries())a!=null&&(yield*Hl(a.child,n))}}async function*Gl(t,e,r={}){let n;Symbol.asyncIterator in t||Symbol.iterator in t?n=t:n=[t];let i,o;r.profile==="unixfs-v0-2015"?(r.shardSplitStrategy=r.shardSplitStrategy??"links-bytes",r.cidVersion=r.cidVersion??0,r.rawLeaves=r.rawLeaves??!1,i=Qn,o=174):r.profile==="unixfs-v1-2025"&&(r.shardSplitStrategy=r.shardSplitStrategy??"block-bytes",r.cidVersion=r.cidVersion??1,r.rawLeaves=r.rawLeaves??!0,i=Lu,o=1024);let s=r.wrapWithDirectory??Pu,a=r.shardSplitThresholdBytes??Zn,c=r.shardSplitStrategy??Nu,u=r.shardFanoutBits??Xn,l=r.cidVersion??1,h=r.rawLeaves??zu,d=r.leafType??Mu,x=r.fileImportConcurrency??Ru,g=r.blockWriteConcurrency??Fu,w=r.reduceSingleLeafToSelf??Uu,m=r.chunker??Ou({chunkSize:i}),k=r.chunkValidator??Rl(),A=r.dagBuilder??Ll({chunker:m,chunkValidator:k,wrapWithDirectory:s,layout:r.layout??ds({maxChildrenPerNode:o}),bufferImporter:r.bufferImporter??vl({cidVersion:l,rawLeaves:h,leafType:d,onProgress:r.onProgress}),blockWriteConcurrency:g,reduceSingleLeafToSelf:w,cidVersion:l,onProgress:r.onProgress,dirBuilder:r.dirBuilder,fileBuilder:r.fileBuilder}),E=r.treeBuilder??Vl({wrapWithDirectory:s,shardSplitThresholdBytes:a,shardSplitStrategy:c,shardFanoutBits:u,cidVersion:l,onProgress:r.onProgress});for await(let v of E(Br(A(n,e),x),e))yield{cid:v.cid,path:v.path,unixfs:v.unixfs,size:v.size}}var Um={profile:"unixfs-v1-2025"};async function zm(t){let e=[],r=[];async function n(i){let o=(await Dm(i)).sort();for(let s of o){if(s.startsWith("."))continue;let a=jl(i,s),c=await Wl(a),u=Rm(t,a).split(Yl).join("/");if(c.isSymbolicLink())throw _s(`Symlinks are not supported: ${u}`,"path");c.isDirectory()?(r.push(u),await n(a)):c.isFile()&&e.push({path:u,size:c.size})}}return await n(t),{files:e,directories:r}}function Pm(){return _.create(1,112,Kr(wr.code,new Uint8Array(32)))}async function J8(t,e){let r=xs(t),n=Lm(r),{files:i,directories:o}=await zm(r),s=e&&`${e}.tmp`;e&&await fi(bs(e),{recursive:!0});let a=0,c=s?ws(s):new Fm({write(E,v,z){a+=E.length,z()}}),{writer:u,out:l}=St.create([Pm()]),h=ks(Es.from(l),c),d=new Set,x={async put(E,v){let z=E.toString();return d.has(z)||(d.add(z),await u.put({cid:E,bytes:v})),E}},g=new Set([...i.map(E=>E.path),...o].map(E=>E.includes("/")?E.slice(0,E.lastIndexOf("/")):""));function*w(){g.has("")||(yield{path:n});for(let E of o)g.has(E)||(yield{path:`${n}/${E}`});for(let E of i)yield{path:`${n}/${E.path}`,content:Bm(jl(r,E.path))}}let m;try{for await(let E of Gl(w(),x,Um))E.path===n&&(m=E.cid);await u.close(),await h}catch(E){throw await u.close().catch(()=>{}),await h.catch(()=>{}),s&&await Nm(s,{force:!0}),E}if(!m)throw new Error(`Packing ${t} produced no root.`);if(!(e&&s))return{rootCid:m,size:a,files:i.length};let k=await vm(s,"r+");try{await St.updateRootsInFile(k,[m])}finally{await k.close()}let{size:A}=await Wl(s);return await Cm(s,e),{rootCid:m,size:A,files:i.length}}var ql=8*1024*1024;async function*Mm(t,e){for(let r=0;r<e;r+=ql)yield*t.content({offset:r,length:Math.min(ql,e-r)})}var Om=0;async function $m(t,e){let{code:r,digest:n}=t.multihash,i;if(r===wr.code)i=(await wr.digest(e)).digest;else if(r===Om)i=e;else throw new jt({code:Yt.verificationFailed,message:`Unsupported multihash 0x${r.toString(16)} in block ${t}.`});if(!Ss(i,n))throw new jt({code:Yt.verificationFailed,message:`Block ${t} does not match its CID.`})}async function X8(t,e,r={}){let n=r.verifyBlocks??!0,i=await fr.fromFile(t);try{let[o]=await i.getRoots();if(!o)throw new Error("CAR has no root.");let s=_.decode(o.bytes),a={async*get(h){let d=await i.get(h);if(!d)throw new Error(`Block ${h} missing from CAR.`);n&&await $m(h,d.bytes),yield d.bytes}},c=xs(e),u=0;async function l(h,d){if(d!==c&&!d.startsWith(c+Yl))throw new jt({code:Yt.unsafePath,message:`Refusing to write outside ${e}: ${d}`});let x=await Tu(h,a);if(x.type==="directory"){await fi(d,{recursive:!0});for await(let g of x.entries()){if(g.name.includes("/")||g.name.includes("\\"))throw new jt({code:Yt.unsafePath,message:`Refusing entry name with a path separator: ${g.name}`});await l(g.cid,xs(d,g.name))}}else x.type==="file"?(await fi(bs(d),{recursive:!0}),await ks(Es.from(Mm(x,Number(x.unixfs.fileSize()))),ws(d)),u++):(x.type==="raw"||x.type==="identity")&&(await fi(bs(d),{recursive:!0}),await ks(Es.from(x.content()),ws(d)),u++)}return await l(s,c),{rootCid:s,files:u}}finally{await i.close()}}export{J8 as a,X8 as b};
3
+ //# sourceMappingURL=chunk-ISML2NA2.js.map