@helia/car 4.0.4 → 4.1.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.
- package/README.md +34 -17
- package/dist/index.min.js +2 -1
- package/dist/index.min.js.map +7 -0
- package/dist/src/car.d.ts +17 -0
- package/dist/src/car.d.ts.map +1 -0
- package/dist/src/car.js +162 -0
- package/dist/src/car.js.map +1 -0
- package/dist/src/constants.d.ts +10 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +10 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +9 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/export-strategies/block-exporter.d.ts +10 -0
- package/dist/src/export-strategies/block-exporter.d.ts.map +1 -0
- package/dist/src/export-strategies/block-exporter.js +12 -0
- package/dist/src/export-strategies/block-exporter.js.map +1 -0
- package/dist/src/export-strategies/index.d.ts +4 -0
- package/dist/src/export-strategies/index.d.ts.map +1 -0
- package/dist/src/export-strategies/index.js +4 -0
- package/dist/src/export-strategies/index.js.map +1 -0
- package/dist/src/export-strategies/subgraph-exporter.d.ts +14 -0
- package/dist/src/export-strategies/subgraph-exporter.d.ts.map +1 -0
- package/dist/src/export-strategies/subgraph-exporter.js +17 -0
- package/dist/src/export-strategies/subgraph-exporter.js.map +1 -0
- package/dist/src/export-strategies/unixfs-exporter.d.ts +11 -0
- package/dist/src/export-strategies/unixfs-exporter.d.ts.map +1 -0
- package/dist/src/export-strategies/unixfs-exporter.js +18 -0
- package/dist/src/export-strategies/unixfs-exporter.js.map +1 -0
- package/dist/src/index.d.ts +89 -24
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -95
- package/dist/src/index.js.map +1 -1
- package/dist/src/traversal-strategies/cid-path.d.ts +16 -0
- package/dist/src/traversal-strategies/cid-path.d.ts.map +1 -0
- package/dist/src/traversal-strategies/cid-path.js +22 -0
- package/dist/src/traversal-strategies/cid-path.js.map +1 -0
- package/dist/src/traversal-strategies/graph-search.d.ts +14 -0
- package/dist/src/traversal-strategies/graph-search.d.ts.map +1 -0
- package/dist/src/traversal-strategies/graph-search.js +19 -0
- package/dist/src/traversal-strategies/graph-search.js.map +1 -0
- package/dist/src/traversal-strategies/index.d.ts +4 -0
- package/dist/src/traversal-strategies/index.d.ts.map +1 -0
- package/dist/src/traversal-strategies/index.js +4 -0
- package/dist/src/traversal-strategies/index.js.map +1 -0
- package/dist/src/traversal-strategies/unixfs-path.d.ts +13 -0
- package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -0
- package/dist/src/traversal-strategies/unixfs-path.js +42 -0
- package/dist/src/traversal-strategies/unixfs-path.js.map +1 -0
- package/dist/typedoc-urls.json +10 -0
- package/package.json +12 -6
- package/src/car.ts +218 -0
- package/src/constants.ts +11 -0
- package/src/errors.ts +8 -0
- package/src/export-strategies/block-exporter.ts +13 -0
- package/src/export-strategies/index.ts +3 -0
- package/src/export-strategies/subgraph-exporter.ts +18 -0
- package/src/export-strategies/unixfs-exporter.ts +22 -0
- package/src/index.ts +99 -119
- package/src/traversal-strategies/cid-path.ts +29 -0
- package/src/traversal-strategies/graph-search.ts +25 -0
- package/src/traversal-strategies/index.ts +3 -0
- package/src/traversal-strategies/unixfs-path.ts +58 -0
package/README.md
CHANGED
|
@@ -30,39 +30,56 @@ repo and examine the changes made.
|
|
|
30
30
|
|
|
31
31
|
-->
|
|
32
32
|
|
|
33
|
-
`@helia/car` provides `import` and `export` methods to read/write Car files
|
|
33
|
+
`@helia/car` provides `import` and `export` methods to read/write Car files
|
|
34
|
+
to Helia's blockstore.
|
|
34
35
|
|
|
35
36
|
See the Car interface for all available operations.
|
|
36
37
|
|
|
37
|
-
By default it supports `dag-pb`, `dag-cbor`, `dag-json` and `raw` CIDs, more
|
|
38
|
+
By default it supports `dag-pb`, `dag-cbor`, `dag-json` and `raw` CIDs, more
|
|
39
|
+
esoteric DAG walkers can be passed as an init option.
|
|
38
40
|
|
|
39
41
|
## Example - Exporting a DAG as a CAR file
|
|
40
42
|
|
|
41
43
|
```typescript
|
|
42
44
|
import { createHelia } from 'helia'
|
|
43
|
-
import { unixfs } from '@helia/unixfs'
|
|
44
45
|
import { car } from '@helia/car'
|
|
45
|
-
import {
|
|
46
|
-
import { Readable } from 'node:stream'
|
|
46
|
+
import { CID } from 'multiformats/cid'
|
|
47
47
|
import nodeFs from 'node:fs'
|
|
48
48
|
|
|
49
|
-
const helia = await createHelia(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
49
|
+
const helia = await createHelia()
|
|
50
|
+
const cid = CID.parse('QmFoo...')
|
|
51
|
+
|
|
52
|
+
const c = car(helia)
|
|
53
|
+
const out = nodeFs.createWriteStream('example.car')
|
|
54
|
+
|
|
55
|
+
for await (const buf of c.stream(cid)) {
|
|
56
|
+
out.write(buf)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
out.end()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example - Exporting a part of a UnixFS DAG as a CAR file
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { createHelia } from 'helia'
|
|
66
|
+
import { car, UnixFSPath } from '@helia/car'
|
|
67
|
+
import { CID } from 'multiformats/cid'
|
|
68
|
+
import nodeFs from 'node:fs'
|
|
53
69
|
|
|
54
|
-
|
|
55
|
-
const cid =
|
|
70
|
+
const helia = await createHelia()
|
|
71
|
+
const cid = CID.parse('QmFoo...')
|
|
56
72
|
|
|
57
|
-
// export it as a Car
|
|
58
73
|
const c = car(helia)
|
|
59
|
-
const
|
|
74
|
+
const out = nodeFs.createWriteStream('example.car')
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
for await (const buf of c.stream(cid, {
|
|
77
|
+
traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
78
|
+
})) {
|
|
79
|
+
out.write(buf)
|
|
80
|
+
}
|
|
63
81
|
|
|
64
|
-
|
|
65
|
-
await c.export(cid, writer)
|
|
82
|
+
out.end()
|
|
66
83
|
```
|
|
67
84
|
|
|
68
85
|
## Example - Importing all blocks from a CAR file
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaCar=(()=>{var Tn=Object.create;var Se=Object.defineProperty;var In=Object.getOwnPropertyDescriptor;var Cn=Object.getOwnPropertyNames;var Sn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var ce=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Bn=(e,t)=>{for(var r in t)Se(e,r,{get:t[r],enumerable:!0})},$t=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Cn(t))!Un.call(e,o)&&o!==r&&Se(e,o,{get:()=>t[o],enumerable:!(n=In(t,o))||n.enumerable});return e};var Ue=(e,t,r)=>(r=e!=null?Tn(Sn(e)):{},$t(t||!e||!e.__esModule?Se(r,"default",{value:e,enumerable:!0}):r,e)),Nn=e=>$t(Se({},"__esModule",{value:!0}),e);var on=ce((ta,nn)=>{nn.exports=gt;var rn=128,qo=127,Ho=~qo,Go=Math.pow(2,31);function gt(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw gt.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Go;)t[r++]=e&255|rn,e/=128;for(;e&Ho;)t[r++]=e&255|rn,e>>>=7;return t[r]=e|0,gt.bytes=r-n+1,t}});var cn=ce((ra,an)=>{an.exports=xt;var Wo=128,sn=127;function xt(e,n){var r=0,n=n||0,o=0,i=n,a,u=e.length;do{if(i>=u||o>49)throw xt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&sn)<<o:(a&sn)*Math.pow(2,o),o+=7}while(a>=Wo);return xt.bytes=i-n,r}});var fn=ce((na,un)=>{var jo=Math.pow(2,7),Ko=Math.pow(2,14),Yo=Math.pow(2,21),Jo=Math.pow(2,28),Xo=Math.pow(2,35),Qo=Math.pow(2,42),Zo=Math.pow(2,49),ei=Math.pow(2,56),ti=Math.pow(2,63);un.exports=function(e){return e<jo?1:e<Ko?2:e<Yo?3:e<Jo?4:e<Xo?5:e<Qo?6:e<Zo?7:e<ei?8:e<ti?9:10}});var Ge=ce((oa,dn)=>{dn.exports={encode:on(),decode:cn(),encodingLength:fn()}});var _n=ce((wc,Nt)=>{"use strict";var xi=Object.prototype.hasOwnProperty,_="~";function ke(){}Object.create&&(ke.prototype=Object.create(null),new ke().__proto__||(_=!1));function bi(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function En(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new bi(r,n||e,o),a=_?_+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],i]:e._events[a].push(i):(e._events[a]=i,e._eventsCount++),e}function Ye(e,t){--e._eventsCount===0?e._events=new ke:delete e._events[t]}function E(){this._events=new ke,this._eventsCount=0}E.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)xi.call(r,n)&&t.push(_?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};E.prototype.listeners=function(t){var r=_?_+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,a=new Array(i);o<i;o++)a[o]=n[o].fn;return a};E.prototype.listenerCount=function(t){var r=_?_+t:t,n=this._events[r];return n?n.fn?1:n.length:0};E.prototype.emit=function(t,r,n,o,i,a){var u=_?_+t:t;if(!this._events[u])return!1;var c=this._events[u],p=arguments.length,h,y;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),p){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,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,a),!0}for(y=1,h=new Array(p-1);y<p;y++)h[y-1]=arguments[y];c.fn.apply(c.context,h)}else{var P=c.length,v;for(y=0;y<P;y++)switch(c[y].once&&this.removeListener(t,c[y].fn,void 0,!0),p){case 1:c[y].fn.call(c[y].context);break;case 2:c[y].fn.call(c[y].context,r);break;case 3:c[y].fn.call(c[y].context,r,n);break;case 4:c[y].fn.call(c[y].context,r,n,o);break;default:if(!h)for(v=1,h=new Array(p-1);v<p;v++)h[v-1]=arguments[v];c[y].fn.apply(c[y].context,h)}}return!0};E.prototype.on=function(t,r,n){return En(this,t,r,n,!1)};E.prototype.once=function(t,r,n){return En(this,t,r,n,!0)};E.prototype.removeListener=function(t,r,n,o){var i=_?_+t:t;if(!this._events[i])return this;if(!r)return Ye(this,i),this;var a=this._events[i];if(a.fn)a.fn===r&&(!o||a.once)&&(!n||a.context===n)&&Ye(this,i);else{for(var u=0,c=[],p=a.length;u<p;u++)(a[u].fn!==r||o&&!a[u].once||n&&a[u].context!==n)&&c.push(a[u]);c.length?this._events[i]=c.length===1?c[0]:c:Ye(this,i)}return this};E.prototype.removeAllListeners=function(t){var r;return t?(r=_?_+t:t,this._events[r]&&Ye(this,r)):(this._events=new ke,this._eventsCount=0),this};E.prototype.off=E.prototype.removeListener;E.prototype.addListener=E.prototype.on;E.prefixed=_;E.EventEmitter=E;typeof Nt<"u"&&(Nt.exports=E)});var _i={};Bn(_i,{car:()=>Ei});var On=["string","number","bigint","symbol"],Dn=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Lt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(On.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Rn(e))return"Buffer";let r=Mn(e);return r||"Object"}function Rn(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Mn(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Dn.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var d=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var X=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",zn=new TextDecoder,$n=new TextEncoder;function Be(e){return X&&globalThis.Buffer.isBuffer(e)}function Je(e){return e instanceof Uint8Array?Be(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var qt=X?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Pt(e,t,r):(e,t,r)=>r-t>64?zn.decode(e.subarray(t,r)):Pt(e,t,r),Ht=X?e=>e.length>64?globalThis.Buffer.from(e):Vt(e):e=>e.length>64?$n.encode(e):Vt(e),L=e=>Uint8Array.from(e),Q=X?(e,t,r)=>Be(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Gt=X?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Je(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Wt=X?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function jt(e,t){if(Be(e)&&Be(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Vt(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function Pt(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=r){let u,c,p,h;switch(a){case 1:o<128&&(i=o);break;case 2:u=e[t+1],(u&192)===128&&(h=(o&31)<<6|u&63,h>127&&(i=h));break;case 3:u=e[t+1],c=e[t+2],(u&192)===128&&(c&192)===128&&(h=(o&15)<<12|(u&63)<<6|c&63,h>2047&&(h<55296||h>57343)&&(i=h));break;case 4:u=e[t+1],c=e[t+2],p=e[t+3],(u&192)===128&&(c&192)===128&&(p&192)===128&&(h=(o&15)<<18|(u&63)<<12|(c&63)<<6|p&63,h>65535&&h<1114112&&(i=h))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return Ln(n)}var Ft=4096;function Ln(e){let t=e.length;if(t<=Ft)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Ft));return r}var Vn=256,ue=class{constructor(t=Vn){this.chunkSize=t,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)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Wt(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Q(n,0,this.cursor)}else r=Gt(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",Xe="CBOR encode error:",fe=[];fe[23]=1;fe[24]=2;fe[25]=3;fe[26]=5;fe[27]=9;function q(e,t,r){if(e.length-t<r)throw new Error(`${l} not enough data for type`)}var x=[24,256,65536,4294967296,BigInt("18446744073709551616")];function A(e,t,r){q(e,t,1);let n=e[t];if(r.strict===!0&&n<x[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function T(e,t,r){q(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<x[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function I(e,t,r){q(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<x[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function C(e,t,r){q(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<x[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function Kt(e,t,r,n){return new d(s.uint,A(e,t+1,n),2)}function Yt(e,t,r,n){return new d(s.uint,T(e,t+1,n),3)}function Jt(e,t,r,n){return new d(s.uint,I(e,t+1,n),5)}function Xt(e,t,r,n){return new d(s.uint,C(e,t+1,n),9)}function U(e,t){return b(e,0,t.value)}function b(e,t,r){if(r<x[0]){let n=Number(r);e.push([t|n])}else if(r<x[1]){let n=Number(r);e.push([t|24,n])}else if(r<x[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<x[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<x[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),a=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=a&255,a=a>>8,o[3]=a&255,a=a>>8,o[2]=a&255,a=a>>8,o[1]=a&255,e.push(o)}else throw new Error(`${l} encountered BigInt larger than allowable range`)}}U.encodedSize=function(t){return b.encodedSize(t.value)};b.encodedSize=function(t){return t<x[0]?1:t<x[1]?2:t<x[2]?3:t<x[3]?5:9};U.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Qt(e,t,r,n){return new d(s.negint,-1-A(e,t+1,n),2)}function Zt(e,t,r,n){return new d(s.negint,-1-T(e,t+1,n),3)}function er(e,t,r,n){return new d(s.negint,-1-I(e,t+1,n),5)}var Qe=BigInt(-1),tr=BigInt(1);function rr(e,t,r,n){let o=C(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new d(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new d(s.negint,Qe-BigInt(o),9)}function Ne(e,t){let r=t.value,n=typeof r=="bigint"?r*Qe-tr:r*-1-1;b(e,t.type.majorEncoded,n)}Ne.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Qe-tr:r*-1-1;return n<x[0]?1:n<x[1]?2:n<x[2]?3:n<x[3]?5:9};Ne.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function de(e,t,r,n){q(e,t,r+n);let o=Q(e,t+r,t+r+n);return new d(s.bytes,o,r+n)}function nr(e,t,r,n){return de(e,t,1,r)}function or(e,t,r,n){return de(e,t,2,A(e,t+1,n))}function ir(e,t,r,n){return de(e,t,3,T(e,t+1,n))}function sr(e,t,r,n){return de(e,t,5,I(e,t+1,n))}function ar(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return de(e,t,9,o)}function Oe(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?Ht(e.value):e.value),e.encodedBytes}function Z(e,t){let r=Oe(t);b(e,t.type.majorEncoded,r.length),e.push(r)}Z.encodedSize=function(t){let r=Oe(t);return b.encodedSize(r.length)+r.length};Z.compareTokens=function(t,r){return Fn(Oe(t),Oe(r))};function Fn(e,t){return e.length<t.length?-1:e.length>t.length?1:jt(e,t)}function le(e,t,r,n,o){let i=r+n;q(e,t,i);let a=new d(s.string,qt(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=Q(e,t+r,t+i)),a}function cr(e,t,r,n){return le(e,t,1,r,n)}function ur(e,t,r,n){return le(e,t,2,A(e,t+1,n),n)}function fr(e,t,r,n){return le(e,t,3,T(e,t+1,n),n)}function dr(e,t,r,n){return le(e,t,5,I(e,t+1,n),n)}function lr(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return le(e,t,9,o,n)}var hr=Z;function ee(e,t,r,n){return new d(s.array,n,r)}function pr(e,t,r,n){return ee(e,t,1,r)}function yr(e,t,r,n){return ee(e,t,2,A(e,t+1,n))}function mr(e,t,r,n){return ee(e,t,3,T(e,t+1,n))}function wr(e,t,r,n){return ee(e,t,5,I(e,t+1,n))}function gr(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ee(e,t,9,o)}function xr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ee(e,t,1,1/0)}function De(e,t){b(e,s.array.majorEncoded,t.value)}De.compareTokens=U.compareTokens;De.encodedSize=function(t){return b.encodedSize(t.value)};function te(e,t,r,n){return new d(s.map,n,r)}function br(e,t,r,n){return te(e,t,1,r)}function vr(e,t,r,n){return te(e,t,2,A(e,t+1,n))}function Er(e,t,r,n){return te(e,t,3,T(e,t+1,n))}function _r(e,t,r,n){return te(e,t,5,I(e,t+1,n))}function kr(e,t,r,n){let o=C(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return te(e,t,9,o)}function Ar(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return te(e,t,1,1/0)}function Re(e,t){b(e,s.map.majorEncoded,t.value)}Re.compareTokens=U.compareTokens;Re.encodedSize=function(t){return b.encodedSize(t.value)};function Tr(e,t,r,n){return new d(s.tag,r,1)}function Ir(e,t,r,n){return new d(s.tag,A(e,t+1,n),2)}function Cr(e,t,r,n){return new d(s.tag,T(e,t+1,n),3)}function Sr(e,t,r,n){return new d(s.tag,I(e,t+1,n),5)}function Ur(e,t,r,n){return new d(s.tag,C(e,t+1,n),9)}function Me(e,t){b(e,s.tag.majorEncoded,t.value)}Me.compareTokens=U.compareTokens;Me.encodedSize=function(t){return b.encodedSize(t.value)};var Kn=20,Yn=21,Jn=22,Xn=23;function Br(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(s.null,null,1):new d(s.undefined,void 0,1)}function Nr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new d(s.break,void 0,1)}function Ze(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new d(s.float,e,t)}function Or(e,t,r,n){return Ze(et(e,t+1),3,n)}function Dr(e,t,r,n){return Ze(tt(e,t+1),5,n)}function Rr(e,t,r,n){return Ze(Lr(e,t+1),9,n)}function ze(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|Kn]);else if(n===!0)e.push([s.float.majorEncoded|Yn]);else if(n===null)e.push([s.float.majorEncoded|Jn]);else if(n===void 0)e.push([s.float.majorEncoded|Xn]);else{let o,i=!1;(!r||r.float64!==!0)&&(zr(n),o=et(D,1),n===o||Number.isNaN(n)?(D[0]=249,e.push(D.slice(0,3)),i=!0):($r(n),o=tt(D,1),n===o&&(D[0]=250,e.push(D.slice(0,5)),i=!0))),i||(Qn(n),o=Lr(D,1),D[0]=251,e.push(D.slice(0,9)))}}ze.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){zr(n);let o=et(D,1);if(n===o||Number.isNaN(n))return 3;if($r(n),o=tt(D,1),n===o)return 5}return 9};var Mr=new ArrayBuffer(9),B=new DataView(Mr,1),D=new Uint8Array(Mr,0);function zr(e){if(e===1/0)B.setUint16(0,31744,!1);else if(e===-1/0)B.setUint16(0,64512,!1);else if(Number.isNaN(e))B.setUint16(0,32256,!1);else{B.setFloat32(0,e);let t=B.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)B.setUint16(0,31744,!1);else if(r===0)B.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?B.setUint16(0,0):o<-14?B.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):B.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function et(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function $r(e){B.setFloat32(0,e,!1)}function tt(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Qn(e){B.setFloat64(0,e,!1)}function Lr(e,t){if(e.length-t<8)throw new Error(`${l} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}ze.compareTokens=U.compareTokens;function m(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function $e(e){return()=>{throw new Error(`${l} ${e}`)}}var f=[];for(let e=0;e<=23;e++)f[e]=m;f[24]=Kt;f[25]=Yt;f[26]=Jt;f[27]=Xt;f[28]=m;f[29]=m;f[30]=m;f[31]=m;for(let e=32;e<=55;e++)f[e]=m;f[56]=Qt;f[57]=Zt;f[58]=er;f[59]=rr;f[60]=m;f[61]=m;f[62]=m;f[63]=m;for(let e=64;e<=87;e++)f[e]=nr;f[88]=or;f[89]=ir;f[90]=sr;f[91]=ar;f[92]=m;f[93]=m;f[94]=m;f[95]=$e("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)f[e]=cr;f[120]=ur;f[121]=fr;f[122]=dr;f[123]=lr;f[124]=m;f[125]=m;f[126]=m;f[127]=$e("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)f[e]=pr;f[152]=yr;f[153]=mr;f[154]=wr;f[155]=gr;f[156]=m;f[157]=m;f[158]=m;f[159]=xr;for(let e=160;e<=183;e++)f[e]=br;f[184]=vr;f[185]=Er;f[186]=_r;f[187]=kr;f[188]=m;f[189]=m;f[190]=m;f[191]=Ar;for(let e=192;e<=215;e++)f[e]=Tr;f[216]=Ir;f[217]=Cr;f[218]=Sr;f[219]=Ur;f[220]=m;f[221]=m;f[222]=m;f[223]=m;for(let e=224;e<=243;e++)f[e]=$e("simple values are not supported");f[244]=m;f[245]=m;f[246]=m;f[247]=Br;f[248]=$e("simple values are not supported");f[249]=Or;f[250]=Dr;f[251]=Rr;f[252]=m;f[253]=m;f[254]=m;f[255]=Nr;var R=[];for(let e=0;e<24;e++)R[e]=new d(s.uint,e,1);for(let e=-1;e>=-24;e--)R[31-e]=new d(s.negint,e,1);R[64]=new d(s.bytes,new Uint8Array(0),1);R[96]=new d(s.string,"",1);R[128]=new d(s.array,0,1);R[160]=new d(s.map,0,1);R[244]=new d(s.false,!1,1);R[245]=new d(s.true,!0,1);R[246]=new d(s.null,null,1);function rt(e){switch(e.type){case s.false:return L([244]);case s.true:return L([245]);case s.null:return L([246]);case s.bytes:return e.value.length?void 0:L([64]);case s.string:return e.value===""?L([96]):void 0;case s.array:return e.value===0?L([128]):void 0;case s.map:return e.value===0?L([160]):void 0;case s.uint:return e.value<24?L([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return L([31-Number(e.value)])}}var eo={float64:!1,mapSorter:ro,quickEncodeToken:rt};function ot(){let e=[];return e[s.uint.major]=U,e[s.negint.major]=Ne,e[s.bytes.major]=Z,e[s.string.major]=hr,e[s.array.major]=De,e[s.map.major]=Re,e[s.tag.major]=Me,e[s.float.major]=ze,e}var Vr=ot(),nt=new ue,Le=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${Xe} object contains circular references`);return new e(r,t)}},W={null:new d(s.null,null),undefined:new d(s.undefined,void 0),true:new d(s.true,!0),false:new d(s.false,!1),emptyArray:new d(s.array,0),emptyMap:new d(s.map,0)},j={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new d(s.float,e):e>=0?new d(s.uint,e):new d(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new d(s.uint,e):new d(s.negint,e)},Uint8Array(e,t,r,n){return new d(s.bytes,e)},string(e,t,r,n){return new d(s.string,e)},boolean(e,t,r,n){return e?W.true:W.false},null(e,t,r,n){return W.null},undefined(e,t,r,n){return W.undefined},ArrayBuffer(e,t,r,n){return new d(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new d(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[W.emptyArray,new d(s.break)]:W.emptyArray;n=Le.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=he(a,r,n);return r.addBreakTokens?[new d(s.array,e.length),o,new d(s.break)]:[new d(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),a=o?e.size:i.length;if(!a)return r.addBreakTokens===!0?[W.emptyMap,new d(s.break)]:W.emptyMap;n=Le.createCheck(n,e);let u=[],c=0;for(let p of i)u[c++]=[he(p,r,n),he(o?e.get(p):e[p],r,n)];return to(u,r),r.addBreakTokens?[new d(s.map,a),u,new d(s.break)]:[new d(s.map,a),u]}};j.Map=j.Object;j.Buffer=j.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))j[`${e}Array`]=j.DataView;function he(e,t={},r){let n=Lt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||j[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=j[n];if(!i)throw new Error(`${Xe} unsupported type: ${n}`);return i(e,n,t,r)}function to(e,t){t.mapSorter&&e.sort(t.mapSorter)}function ro(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Vr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Pr(e,t,r,n){if(Array.isArray(t))for(let o of t)Pr(e,o,r,n);else r[t.type.major](e,t,n)}function no(e,t,r){let n=he(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),u=new ue(a);if(i(u,n,r),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Je(u.chunks[0])}}return nt.reset(),Pr(nt,n,t,r),nt.toBytes(!0)}function it(e,t){return t=Object.assign({},eo,t),no(e,Vr,t)}var oo={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ve=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=R[t];if(r===void 0){let n=f[t];if(!n)throw new Error(`${l} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},pe=Symbol.for("DONE"),Pe=Symbol.for("BREAK");function io(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=re(t,r);if(i===Pe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===pe)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function so(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<e.value;a++){let u=re(t,r);if(u===Pe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(u===pe)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof u!="string")throw new Error(`${l} non-string keys not supported (got ${typeof u})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(u)||!n&&u in o))throw new Error(`${l} found repeat map key "${u}"`);let c=re(t,r);if(c===pe)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(u,c):o[u]=c}return n?i:o}function re(e,t){if(e.done())return pe;let r=e.next();if(r.type===s.break)return Pe;if(r.type.terminal)return r.value;if(r.type===s.array)return io(r,e,t);if(r.type===s.map)return so(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=re(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function Fr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},oo,t);let r=t.tokenizer||new Ve(e,t),n=re(r,t);if(n===pe)throw new Error(`${l} did not find any content to decode`);if(n===Pe)throw new Error(`${l} got unexpected break`);return[n,e.subarray(r.pos())]}function st(e,t){let[r,n]=Fr(e,t);if(n.length>0)throw new Error(`${l} too many terminals, data makes no sense`);return r}var Es=new Uint8Array(0);function qr(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ne(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function co(e,t){if(e.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 o=0;o<e.length;o++){var i=e.charAt(o),a=i.charCodeAt(0);if(r[a]!==255)throw new TypeError(i+" is ambiguous");r[a]=o}var u=e.length,c=e.charAt(0),p=Math.log(u)/Math.log(256),h=Math.log(256)/Math.log(u);function y(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var k=0,Y=0,N=0,M=w.length;N!==M&&w[N]===0;)N++,k++;for(var z=(M-N)*h+1>>>0,S=new Uint8Array(z);N!==M;){for(var $=w[N],G=0,O=z-1;($!==0||G<Y)&&O!==-1;O--,G++)$+=256*S[O]>>>0,S[O]=$%u>>>0,$=$/u>>>0;if($!==0)throw new Error("Non-zero carry");Y=G,N++}for(var F=z-Y;F!==z&&S[F]===0;)F++;for(var Ce=c.repeat(k);F<z;++F)Ce+=e.charAt(S[F]);return Ce}function P(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var k=0;if(w[k]!==" "){for(var Y=0,N=0;w[k]===c;)Y++,k++;for(var M=(w.length-k)*p+1>>>0,z=new Uint8Array(M);w[k];){var S=r[w.charCodeAt(k)];if(S===255)return;for(var $=0,G=M-1;(S!==0||$<N)&&G!==-1;G--,$++)S+=u*z[G]>>>0,z[G]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");N=$,k++}if(w[k]!==" "){for(var O=M-N;O!==M&&z[O]===0;)O++;for(var F=new Uint8Array(Y+(M-O)),Ce=Y;O!==M;)F[Ce++]=z[O++];return F}}}function v(w){var k=P(w);if(k)return k;throw new Error(`Non-${t} character`)}return{encode:y,decodeUnsafe:P,decode:v}}var uo=co,fo=uo,Gr=fo;var at=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ct=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Wr(this,t)}},ut=class{decoders;constructor(t){this.decoders=t}or(t){return Wr(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Wr(e,t){return new ut({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var ft=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new at(t,r,n),this.decoder=new ct(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function jr({name:e,prefix:t,encode:r,decode:n}){return new ft(e,t,r,n)}function oe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Gr(r,e);return jr({prefix:t,name:e,encode:n,decode:i=>ne(o(i))})}function lo(e,t,r,n){let o={};for(let h=0;h<t.length;++h)o[t[h]]=h;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),u=0,c=0,p=0;for(let h=0;h<i;++h){let y=o[e[h]];if(y===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|y,u+=r,u>=8&&(u-=8,a[p++]=255&c>>u)}if(u>=r||(255&c<<8-u)!==0)throw new SyntaxError("Unexpected end of data");return a}function ho(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,u=0;for(let c=0;c<e.length;++c)for(u=u<<8|e[c],a+=8;a>r;)a-=r,i+=t[o&u>>a];if(a!==0&&(i+=t[o&u<<r-a]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function V({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return jr({prefix:t,name:e,encode(o){return ho(o,n,r)},decode(o){return lo(o,n,r,e)}})}var ye=V({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cs=V({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ss=V({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Us=V({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Bs=V({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ns=V({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Os=V({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ds=V({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Rs=V({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fe=oe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$s=oe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var H=oe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ps=oe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po=Jr,Kr=128,yo=127,mo=~yo,wo=Math.pow(2,31);function Jr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=wo;)t[r++]=e&255|Kr,e/=128;for(;e&mo;)t[r++]=e&255|Kr,e>>>=7;return t[r]=e|0,Jr.bytes=r-n+1,t}var go=dt,xo=128,Yr=127;function dt(e,n){var r=0,n=n||0,o=0,i=n,a,u=e.length;do{if(i>=u)throw dt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Yr)<<o:(a&Yr)*Math.pow(2,o),o+=7}while(a>=xo);return dt.bytes=i-n,r}var bo=Math.pow(2,7),vo=Math.pow(2,14),Eo=Math.pow(2,21),_o=Math.pow(2,28),ko=Math.pow(2,35),Ao=Math.pow(2,42),To=Math.pow(2,49),Io=Math.pow(2,56),Co=Math.pow(2,63),So=function(e){return e<bo?1:e<vo?2:e<Eo?3:e<_o?4:e<ko?5:e<Ao?6:e<To?7:e<Io?8:e<Co?9:10},Uo={encode:po,decode:go,encodingLength:So},Bo=Uo,me=Bo;function we(e,t=0){return[me.decode(e,t),me.decode.bytes]}function ie(e,t,r=0){return me.encode(e,t,r),t}function se(e){return me.encodingLength(e)}function ht(e,t){let r=t.byteLength,n=se(e),o=n+se(r),i=new Uint8Array(o+r);return ie(e,i,0),ie(r,i,n),i.set(t,o),new ae(e,r,t,i)}function qe(e){let t=ne(e),[r,n]=we(t),[o,i]=we(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new ae(r,o,a,t)}function Xr(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&qr(e.bytes,r.bytes)}}var ae=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Qr(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Oo(r,pt(e),t??H.encoder);default:return Do(r,pt(e),t??ye.encoder)}}var Zr=new WeakMap;function pt(e){let t=Zr.get(e);if(t==null){let r=new Map;return Zr.set(e,r),r}return t}var g=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ro)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=ht(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Xr(t.multihash,n.multihash)}toString(t){return Qr(this,t)}toJSON(){return{"/":Qr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new e(n,o,i,a??en(n,o,i.bytes))}else if(r[Mo]===!0){let{version:n,multihash:o,code:i}=r,a=qe(o);return e.create(n,i,a)}else return null}static create(t,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(t){case 0:{if(r!==xe)throw new Error(`Version 0 CID must use dag-pb (code: ${xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=en(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,xe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=ne(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),a=new ae(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(a):e.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[y,P]=we(t.subarray(r));return r+=P,y},o=n(),i=xe;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,u=n(),c=n(),p=r+c,h=p-a;return{version:o,codec:i,multihashCode:u,digestSize:c,multihashSize:h,size:p}}static parse(t,r){let[n,o]=No(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return pt(i).set(n,t),i}};function No(e,t){switch(e[0]){case"Q":{let r=t??H;return[H.prefix,r.decode(`${H.prefix}${e}`)]}case H.prefix:{let r=t??H;return[H.prefix,r.decode(e)]}case ye.prefix:{let r=t??ye;return[ye.prefix,r.decode(e)]}case Fe.prefix:{let r=t??Fe;return[Fe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Oo(e,t,r){let{prefix:n}=r;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function Do(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var xe=112,Ro=18;function en(e,t,r){let n=se(e),o=n+se(t),i=new Uint8Array(o+r.byteLength);return ie(e,i,0),ie(t,i,n),i.set(r,o),i}var Mo=Symbol.for("@ipld/js-cid/CID");var tn=42;function zo(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function $o(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=g.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new d(s.tag,tn),new d(s.bytes,r)]}function Lo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Vo(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var yt={float64:!0,typeEncoders:{Object:$o,undefined:Lo,number:Vo}},Zs={...yt,typeEncoders:{...yt.typeEncoders}};function Po(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return g.decode(e.subarray(1))}var He={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};He.tags[tn]=Po;var ea={...He,tags:He.tags.slice()};var mt=e=>it(e,yt),wt=e=>st(zo(e),He);var bt=Ue(Ge(),1);var vt=40;function Et(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=bt.default.decode(e);return t.seek(bt.default.decode.bytes),r}function _t(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0;return{version:2,characteristics:[t.getBigUint64(r,!0),t.getBigUint64(r+=8,!0)],dataOffset:Number(t.getBigUint64(r+=8,!0)),dataSize:Number(t.getBigUint64(r+=8,!0)),indexOffset:Number(t.getBigUint64(r+=8,!0))}}var K={Null:e=>e===null?e:void 0,Int:e=>Number.isInteger(e)?e:void 0,Float:e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,String:e=>typeof e=="string"?e:void 0,Bool:e=>typeof e=="boolean"?e:void 0,Bytes:e=>e instanceof Uint8Array?e:void 0,Link:e=>e!==null&&typeof e=="object"&&e.asCID===e?e:void 0,List:e=>Array.isArray(e)?e:void 0,Map:e=>e!==null&&typeof e=="object"&&e.asCID!==e&&!Array.isArray(e)&&!(e instanceof Uint8Array)?e:void 0},be={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=be["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==e[t]){let n=e.slice(0,t);for(let o=t;o<e.length;o++){let i=e[o];if(i=be["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.Map(e)===void 0)return;let t=Object.entries(e),r=e,n=1;for(let o=0;o<t.length;o++){let[i,a]=t[o];switch(i){case"roots":{let u=be["CarV1HeaderOrV2Pragma > roots (anon)"](e[i]);if(u===void 0)return;if(u!==a||r!==e){if(r===e){r={};for(let c=0;c<o;c++)r[t[c][0]]=t[c][1]}r.roots=u}}break;case"version":{n--;let u=be.Int(e[i]);if(u===void 0)return;if(u!==a||r!==e){if(r===e){r={};for(let c=0;c<o;c++)r[t[c][0]]=t[c][1]}r.version=u}}break;default:return}}if(!(n>0))return r}},ve={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":K.Link,"CarV1HeaderOrV2Pragma > roots (anon)":e=>{if(K.List(e)!==void 0){for(let t=0;t<e.length;t++){let r=e[t];if(r=ve["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==e[t]){let n=e.slice(0,t);for(let o=t;o<e.length;o++){let i=e[o];if(i=ve["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return e}},Int:K.Int,CarV1HeaderOrV2Pragma:e=>{if(K.Map(e)===void 0)return;let t=Object.entries(e),r=e,n=1;for(let o=0;o<t.length;o++){let[i,a]=t[o];switch(i){case"roots":{let u=ve["CarV1HeaderOrV2Pragma > roots (anon)"](a);if(u===void 0)return;if(u!==a||r!==e){if(r===e){r={};for(let c=0;c<o;c++)r[t[c][0]]=t[c][1]}r.roots=u}}break;case"version":{n--;let u=ve.Int(a);if(u===void 0)return;if(u!==a||r!==e){if(r===e){r={};for(let c=0;c<o;c++)r[t[c][0]]=t[c][1]}r.version=u}}break;default:return}}if(!(n>0))return r}},kt={toTyped:be.CarV1HeaderOrV2Pragma,toRepresentation:ve.CarV1HeaderOrV2Pragma};var ya=ot();var ii=Ue(Ge(),1);var ba=[new d(s.map,2),new d(s.string,"version"),new d(s.uint,1),new d(s.string,"roots")],va=new d(s.tag,42);async function At(e,t){let r=Et(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=wt(n);if(kt.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=_t(await e.exactly(vt,!0));e.seek(i.dataOffset-e.pos);let a=await At(e,1);return Object.assign(a,i)}function Ee(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}var Tt=Ue(Ge(),1),pn=1;function It(e){let t=mt({version:pn,roots:e}),r=Tt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function yn(e){return{async setRoots(t){let r=It(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(Tt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()},version(){return pn}}}function We(){}function mn(){let e=[],t=null,r=We,n=!1,o=null,i=We,a=()=>(t||(t=new Promise(p=>{r=()=>{t=null,r=We,p()}})),t),u={write(p){e.push(p);let h=a();return i(),h},async end(){n=!0;let p=a();i(),await p}},c={async next(){let p=e.shift();return p?(e.length===0&&r(),{done:!1,value:p}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(h=>{i=()=>(o=null,i=We,h(c.next()))})),o)}};return{writer:u,iterator:c}}var _e=class e{constructor(t,r){this._encoder=r,this._mutex=r.setRoots(t),this._ended=!1}async put(t){if(!(t.bytes instanceof Uint8Array)||!t.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=g.asCID(t.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:t.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(t){t=ui(t);let{encoder:r,iterator:n}=wn(),o=new e(t,r),i=new je(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=wn();t.setRoots=()=>Promise.resolve();let n=new e([],t),o=new je(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=Ee(t);await At(n);let o=It(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return t.set(o,0),t}},je=class{constructor(t){this._iterator=t}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function wn(){let e=mn(),{writer:t,iterator:r}=e;return{encoder:yn(t),iterator:r}}function ui(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=g.asCID(e);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let t=[];for(let r of e){let n=g.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}function fi(e){return e[Symbol.asyncIterator]!=null}function di(e){if(fi(e))return(async()=>{for await(let t of e);})();for(let t of e);}var gn=di;function li(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[r](){return this}}}var xn=li;function hi(e){return e[Symbol.asyncIterator]!=null}function pi(e,t){let r=0;if(hi(e))return async function*(){for await(let c of e)yield t(c,r++)}();let n=xn(e),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let a=t(o,r++);if(typeof a.then=="function")return async function*(){yield await a;for await(let c of n)yield t(c,r++)}();let u=t;return function*(){yield a;for(let c of n)yield u(c,r++)}()}var bn=pi;function Ke({enumerable:e=!0,configurable:t=!1}={}){return{enumerable:e,configurable:t,writable:!1}}function*mi(e,t){if(t!=null&&typeof t=="object")if(Array.isArray(t))for(let[r,n]of t.entries()){let o=[...e,r],i=g.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*Ct(n,o))}else{let r=g.asCID(t);r!=null?yield[e.join("/"),r]:yield*Ct(t,e)}}function*Ct(e,t){if(e==null||e instanceof Uint8Array)return;let r=g.asCID(e);r!=null&&(yield[t.join("/"),r]);for(let[n,o]of Object.entries(e)){let i=[...t,n];yield*mi(i,o)}}function*wi(e,t){if(Array.isArray(t))for(let[r,n]of t.entries()){let o=[...e,r];yield o.join("/"),typeof n=="object"&&g.asCID(n)==null&&(yield*St(n,o))}else yield*St(t,e)}function*St(e,t){if(!(e==null||typeof e!="object"))for(let[r,n]of Object.entries(e)){let o=[...t,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&g.asCID(n)==null&&(yield*wi(o,n))}}function gi(e,t){let r=e;for(let[n,o]of t.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${t.slice(0,n+1).map(a=>`[${JSON.stringify(a)}]`).join("")}`);let i=g.asCID(r);if(i!=null)return{value:i,remaining:t.slice(n+1).join("/")}}return{value:r}}var Ut=class{cid;bytes;value;asBlock;constructor({cid:t,bytes:r,value:n}){if(t==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=t,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:Ke(),bytes:Ke(),value:Ke(),asBlock:Ke()})}links(){return Ct(this.value,[])}tree(){return St(this.value,[])}get(t="/"){return gi(this.value,t.split("/").filter(Boolean))}};function vn({bytes:e,cid:t,value:r,codec:n}){let o=r!==void 0?r:n?.decode(e);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Ut({cid:t,bytes:e,value:o})}function Bt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Ot=Ue(_n(),1);var Ae=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Dt=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},kn=e=>globalThis.DOMException===void 0?new Dt(e):new DOMException(e),An=e=>{let t=e.reason===void 0?kn("This operation was aborted."):e.reason;return t instanceof Error?t:kn(t)};function Rt(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,a,u,p=new Promise((h,y)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:v}=t;v.aborted&&y(An(v)),u=()=>{y(An(v))},v.addEventListener("abort",u,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(h,y);return}let P=new Ae;a=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(v){y(v)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?h():o instanceof Error?y(o):(P.message=o??`Promise timed out after ${r} milliseconds`,y(P))},r),(async()=>{try{h(await e)}catch(v){y(v)}})()}).finally(()=>{p.clear(),u&&t.signal&&t.signal.removeEventListener("abort",u)});return p.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},p}function Mt(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),a=n+i;r(e[a],t)<=0?(n=++a,o-=i+1):o=i}return n}var Te=class{#e=[];enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let o=Mt(this.#e,n,(i,a)=>a.priority-i.priority);this.#e.splice(o,0,n)}setPriority(t,r){let n=this.#e.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#e.shift()?.run}filter(t){return this.#e.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#e.length}};var Ie=class extends Ot.default{#e;#s;#i=0;#h;#a;#p=0;#r;#c;#t;#y;#n=0;#u;#o;#m;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Te,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#e=t.carryoverConcurrencyCount,this.#s=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#a=t.interval,this.#t=new t.queueClass,this.#y=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#m=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#b(){return this.#s||this.#i<this.#h}get#v(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#_(){this.#g(),this.#w(),this.#c=void 0}get#k(){let t=Date.now();if(this.#r===void 0){let r=this.#p-t;if(r<0)this.#i=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#_()},r)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#k;if(this.#b&&this.#v){let r=this.#t.dequeue();return r?(this.emit("active"),r(),t&&this.#w(),!0):!1}}return!1}#w(){this.#s||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#i===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#i=this.#e?this.#n:0,this.#d()}#d(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#d()}async#A(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#t.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#x++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#m,...r},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#i++;try{r.signal?.throwIfAborted();let i=t({signal:r.signal});r.timeout&&(i=Rt(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#A(r.signal)]));let a=await i;n(a),this.emit("completed",a)}catch(i){if(i instanceof Ae&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#o?(this.#o=!1,this.#d(),this):this}pause(){this.#o=!0}clear(){this.#t=new this.#y}async onEmpty(){this.#t.size!==0&&await this.#l("empty")}async onSizeLessThan(t){this.#t.size<t||await this.#l("next",()=>this.#t.size<t)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#l("idle")}async#l(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#t.size}sizeBy(t){return this.#t.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};var vi=1,zt=class{components;constructor(t,r){this.components=t}async import(t,r){await gn(this.components.blockstore.putMany(bn(t.blocks(),({cid:n,bytes:o})=>({cid:n,block:o})),r))}async export(t,r,n){let o=Bt(),i=Array.isArray(t)?t:[t],a=new Ie({concurrency:vi});a.on("idle",()=>{o.resolve()}),a.on("error",u=>{a.clear(),o.reject(u)});for(let u of i)a.add(async()=>{await this.#e(u,a,async(c,p)=>{n?.blockFilter?.has(c.multihash.bytes)!==!0&&(n?.blockFilter?.add(c.multihash.bytes),await r.put({cid:c,bytes:p}))},n)}).catch(()=>{});try{await o.promise}finally{await r.close()}}async*stream(t,r){let{writer:n,out:o}=_e.create(t);this.export(t,n,r).catch(()=>{});for await(let i of o)yield i}async#e(t,r,n,o){let i=await this.components.getCodec(t.code),a=await this.components.blockstore.get(t,o);await n(t,a);let u=vn({bytes:a,cid:t,codec:i});for await(let[,c]of u.links())r.add(async()=>{await this.#e(c,r,n,o)})}};function Ei(e,t={}){return new zt(e,t)}return Nn(_i);})();
|
|
2
|
+
"use strict";var HeliaCar=(()=>{var hi=Object.create;var et=Object.defineProperty;var pi=Object.getOwnPropertyDescriptor;var mi=Object.getOwnPropertyNames;var yi=Object.getPrototypeOf,gi=Object.prototype.hasOwnProperty;var Ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var r in e)et(t,r,{get:e[r],enumerable:!0})},Jr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of mi(e))!gi.call(t,o)&&o!==r&&et(t,o,{get:()=>e[o],enumerable:!(n=pi(e,o))||n.enumerable});return t};var tt=(t,e,r)=>(r=t!=null?hi(yi(t)):{},Jr(e||!t||!t.__esModule?et(r,"default",{value:t,enumerable:!0}):r,t)),xi=t=>Jr(et({},"__esModule",{value:!0}),t);var yo=Ae((bf,mo)=>{mo.exports=Yt;var po=128,Ms=127,Os=~Ms,Ps=Math.pow(2,31);function Yt(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Yt.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Ps;)e[r++]=t&255|po,t/=128;for(;t&Os;)e[r++]=t&255|po,t>>>=7;return e[r]=t|0,Yt.bytes=r-n+1,e}});var wo=Ae((Ef,xo)=>{xo.exports=Zt;var $s=128,go=127;function Zt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c||o>49)throw Zt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&go)<<o:(s&go)*Math.pow(2,o),o+=7}while(s>=$s);return Zt.bytes=i-n,r}});var Eo=Ae((Tf,bo)=>{var Hs=Math.pow(2,7),Vs=Math.pow(2,14),qs=Math.pow(2,21),Gs=Math.pow(2,28),Xs=Math.pow(2,35),Ws=Math.pow(2,42),Js=Math.pow(2,49),Ks=Math.pow(2,56),js=Math.pow(2,63);bo.exports=function(t){return t<Hs?1:t<Vs?2:t<qs?3:t<Gs?4:t<Xs?5:t<Ws?6:t<Js?7:t<Ks?8:t<js?9:10}});var yt=Ae((kf,To)=>{To.exports={encode:yo(),decode:wo(),encodingLength:Eo()}});var zo=Ae((Fu,mr)=>{"use strict";var ha=Object.prototype.hasOwnProperty,_="~";function Pe(){}Object.create&&(Pe.prototype=Object.create(null),new Pe().__proto__||(_=!1));function pa(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Uo(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new pa(r,n||t,o),s=_?_+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function bt(t,e){--t._eventsCount===0?t._events=new Pe:delete t._events[e]}function v(){this._events=new Pe,this._eventsCount=0}v.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)ha.call(r,n)&&e.push(_?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};v.prototype.listeners=function(e){var r=_?_+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};v.prototype.listenerCount=function(e){var r=_?_+e:e,n=this._events[r];return n?n.fn?1:n.length:0};v.prototype.emit=function(e,r,n,o,i,s){var c=_?_+e:e;if(!this._events[c])return!1;var f=this._events[c],l=arguments.length,h,p;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),l){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,r),!0;case 3:return f.fn.call(f.context,r,n),!0;case 4:return f.fn.call(f.context,r,n,o),!0;case 5:return f.fn.call(f.context,r,n,o,i),!0;case 6:return f.fn.call(f.context,r,n,o,i,s),!0}for(p=1,h=new Array(l-1);p<l;p++)h[p-1]=arguments[p];f.fn.apply(f.context,h)}else{var I=f.length,b;for(p=0;p<I;p++)switch(f[p].once&&this.removeListener(e,f[p].fn,void 0,!0),l){case 1:f[p].fn.call(f[p].context);break;case 2:f[p].fn.call(f[p].context,r);break;case 3:f[p].fn.call(f[p].context,r,n);break;case 4:f[p].fn.call(f[p].context,r,n,o);break;default:if(!h)for(b=1,h=new Array(l-1);b<l;b++)h[b-1]=arguments[b];f[p].fn.apply(f[p].context,h)}}return!0};v.prototype.on=function(e,r,n){return Uo(this,e,r,n,!1)};v.prototype.once=function(e,r,n){return Uo(this,e,r,n,!0)};v.prototype.removeListener=function(e,r,n,o){var i=_?_+e:e;if(!this._events[i])return this;if(!r)return bt(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&bt(this,i);else{for(var c=0,f=[],l=s.length;c<l;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&f.push(s[c]);f.length?this._events[i]=f.length===1?f[0]:f:bt(this,i)}return this};v.prototype.removeAllListeners=function(e){var r;return e?(r=_?_+e:e,this._events[r]&&bt(this,r)):(this._events=new Pe,this._eventsCount=0),this};v.prototype.off=v.prototype.removeListener;v.prototype.addListener=v.prototype.on;v.prefixed=_;v.EventEmitter=v;typeof mr<"u"&&(mr.exports=v)});var ec={};N(ec,{BlockExporter:()=>br,CIDPath:()=>Tr,GraphSearch:()=>Ge,SubgraphExporter:()=>qe,UnixFSExporter:()=>Er,UnixFSPath:()=>Wr,car:()=>Za});var wi=["string","number","bigint","symbol"],bi=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Kr(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(wi.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(Ei(t))return"Buffer";let r=Ti(t);return r||"Object"}function Ei(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Ti(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(bi.includes(e))return e}var a=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}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var d=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 he=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ki=new TextDecoder,vi=new TextEncoder;function rt(t){return he&&globalThis.Buffer.isBuffer(t)}function St(t){return t instanceof Uint8Array?rt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Zr=he?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Qr(t,e,r):(t,e,r)=>r-e>64?ki.decode(t.subarray(e,r)):Qr(t,e,r),en=he?t=>t.length>64?globalThis.Buffer.from(t):jr(t):t=>t.length>64?vi.encode(t):jr(t),W=t=>Uint8Array.from(t),pe=he?(t,e,r)=>rt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),tn=he?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),St(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},rn=he?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function nn(t,e){if(rt(t)&&rt(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 jr(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}function Qr(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=r){let c,f,l,h;switch(s){case 1:o<128&&(i=o);break;case 2:c=t[e+1],(c&192)===128&&(h=(o&31)<<6|c&63,h>127&&(i=h));break;case 3:c=t[e+1],f=t[e+2],(c&192)===128&&(f&192)===128&&(h=(o&15)<<12|(c&63)<<6|f&63,h>2047&&(h<55296||h>57343)&&(i=h));break;case 4:c=t[e+1],f=t[e+2],l=t[e+3],(c&192)===128&&(f&192)===128&&(l&192)===128&&(h=(o&15)<<18|(c&63)<<12|(f&63)<<6|l&63,h>65535&&h<1114112&&(i=h))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Ai(n)}var Yr=4096;function Ai(t){let e=t.length;if(e<=Yr)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Yr));return r}var Ii=256,Ie=class{constructor(e=Ii){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)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=rn(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=pe(n,0,this.cursor)}else r=tn(this.chunks,this.cursor);return e&&this.reset(),r}};var m="CBOR decode error:",Nt="CBOR encode error:",_e=[];_e[23]=1;_e[24]=2;_e[25]=3;_e[26]=5;_e[27]=9;function j(t,e,r){if(t.length-e<r)throw new Error(`${m} not enough data for type`)}var E=[24,256,65536,4294967296,BigInt("18446744073709551616")];function B(t,e,r){j(t,e,1);let n=t[e];if(r.strict===!0&&n<E[0])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);return n}function C(t,e,r){j(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<E[1])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);return n}function D(t,e,r){j(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<E[2])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);return n}function U(t,e,r){j(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<E[3])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${m} integers outside of the safe integer range are not supported`)}function on(t,e,r,n){return new d(a.uint,B(t,e+1,n),2)}function sn(t,e,r,n){return new d(a.uint,C(t,e+1,n),3)}function an(t,e,r,n){return new d(a.uint,D(t,e+1,n),5)}function cn(t,e,r,n){return new d(a.uint,U(t,e+1,n),9)}function F(t,e){return T(t,0,e.value)}function T(t,e,r){if(r<E[0]){let n=Number(r);t.push([e|n])}else if(r<E[1]){let n=Number(r);t.push([e|24,n])}else if(r<E[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<E[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<E[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${m} encountered BigInt larger than allowable range`)}}F.encodedSize=function(e){return T.encodedSize(e.value)};T.encodedSize=function(e){return e<E[0]?1:e<E[1]?2:e<E[2]?3:e<E[3]?5:9};F.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function fn(t,e,r,n){return new d(a.negint,-1-B(t,e+1,n),2)}function un(t,e,r,n){return new d(a.negint,-1-C(t,e+1,n),3)}function dn(t,e,r,n){return new d(a.negint,-1-D(t,e+1,n),5)}var Bt=BigInt(-1),ln=BigInt(1);function hn(t,e,r,n){let o=U(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new d(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${m} integers outside of the safe integer range are not supported`);return new d(a.negint,Bt-BigInt(o),9)}function nt(t,e){let r=e.value,n=typeof r=="bigint"?r*Bt-ln:r*-1-1;T(t,e.type.majorEncoded,n)}nt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Bt-ln:r*-1-1;return n<E[0]?1:n<E[1]?2:n<E[2]?3:n<E[3]?5:9};nt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Se(t,e,r,n){j(t,e,r+n);let o=pe(t,e+r,e+r+n);return new d(a.bytes,o,r+n)}function pn(t,e,r,n){return Se(t,e,1,r)}function mn(t,e,r,n){return Se(t,e,2,B(t,e+1,n))}function yn(t,e,r,n){return Se(t,e,3,C(t,e+1,n))}function gn(t,e,r,n){return Se(t,e,5,D(t,e+1,n))}function xn(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer bytes lengths not supported`);return Se(t,e,9,o)}function ot(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===a.string?en(t.value):t.value),t.encodedBytes}function me(t,e){let r=ot(e);T(t,e.type.majorEncoded,r.length),t.push(r)}me.encodedSize=function(e){let r=ot(e);return T.encodedSize(r.length)+r.length};me.compareTokens=function(e,r){return Si(ot(e),ot(r))};function Si(t,e){return t.length<e.length?-1:t.length>e.length?1:nn(t,e)}function Ne(t,e,r,n,o){let i=r+n;j(t,e,i);let s=new d(a.string,Zr(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=pe(t,e+r,e+i)),s}function wn(t,e,r,n){return Ne(t,e,1,r,n)}function bn(t,e,r,n){return Ne(t,e,2,B(t,e+1,n),n)}function En(t,e,r,n){return Ne(t,e,3,C(t,e+1,n),n)}function Tn(t,e,r,n){return Ne(t,e,5,D(t,e+1,n),n)}function kn(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer string lengths not supported`);return Ne(t,e,9,o,n)}var vn=me;function ye(t,e,r,n){return new d(a.array,n,r)}function An(t,e,r,n){return ye(t,e,1,r)}function In(t,e,r,n){return ye(t,e,2,B(t,e+1,n))}function _n(t,e,r,n){return ye(t,e,3,C(t,e+1,n))}function Sn(t,e,r,n){return ye(t,e,5,D(t,e+1,n))}function Nn(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer array lengths not supported`);return ye(t,e,9,o)}function Bn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${m} indefinite length items not allowed`);return ye(t,e,1,1/0)}function it(t,e){T(t,a.array.majorEncoded,e.value)}it.compareTokens=F.compareTokens;it.encodedSize=function(e){return T.encodedSize(e.value)};function ge(t,e,r,n){return new d(a.map,n,r)}function Cn(t,e,r,n){return ge(t,e,1,r)}function Dn(t,e,r,n){return ge(t,e,2,B(t,e+1,n))}function Un(t,e,r,n){return ge(t,e,3,C(t,e+1,n))}function zn(t,e,r,n){return ge(t,e,5,D(t,e+1,n))}function Ln(t,e,r,n){let o=U(t,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer map lengths not supported`);return ge(t,e,9,o)}function Fn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${m} indefinite length items not allowed`);return ge(t,e,1,1/0)}function st(t,e){T(t,a.map.majorEncoded,e.value)}st.compareTokens=F.compareTokens;st.encodedSize=function(e){return T.encodedSize(e.value)};function Rn(t,e,r,n){return new d(a.tag,r,1)}function Mn(t,e,r,n){return new d(a.tag,B(t,e+1,n),2)}function On(t,e,r,n){return new d(a.tag,C(t,e+1,n),3)}function Pn(t,e,r,n){return new d(a.tag,D(t,e+1,n),5)}function $n(t,e,r,n){return new d(a.tag,U(t,e+1,n),9)}function at(t,e){T(t,a.tag.majorEncoded,e.value)}at.compareTokens=F.compareTokens;at.encodedSize=function(e){return T.encodedSize(e.value)};var zi=20,Li=21,Fi=22,Ri=23;function Hn(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${m} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(a.null,null,1):new d(a.undefined,void 0,1)}function Vn(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${m} indefinite length items not allowed`);return new d(a.break,void 0,1)}function Ct(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${m} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${m} Infinity values are not supported`)}return new d(a.float,t,e)}function qn(t,e,r,n){return Ct(Dt(t,e+1),3,n)}function Gn(t,e,r,n){return Ct(Ut(t,e+1),5,n)}function Xn(t,e,r,n){return Ct(jn(t,e+1),9,n)}function ct(t,e,r){let n=e.value;if(n===!1)t.push([a.float.majorEncoded|zi]);else if(n===!0)t.push([a.float.majorEncoded|Li]);else if(n===null)t.push([a.float.majorEncoded|Fi]);else if(n===void 0)t.push([a.float.majorEncoded|Ri]);else{let o,i=!1;(!r||r.float64!==!0)&&(Jn(n),o=Dt(P,1),n===o||Number.isNaN(n)?(P[0]=249,t.push(P.slice(0,3)),i=!0):(Kn(n),o=Ut(P,1),n===o&&(P[0]=250,t.push(P.slice(0,5)),i=!0))),i||(Mi(n),o=jn(P,1),P[0]=251,t.push(P.slice(0,9)))}}ct.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){Jn(n);let o=Dt(P,1);if(n===o||Number.isNaN(n))return 3;if(Kn(n),o=Ut(P,1),n===o)return 5}return 9};var Wn=new ArrayBuffer(9),R=new DataView(Wn,1),P=new Uint8Array(Wn,0);function Jn(t){if(t===1/0)R.setUint16(0,31744,!1);else if(t===-1/0)R.setUint16(0,64512,!1);else if(Number.isNaN(t))R.setUint16(0,32256,!1);else{R.setFloat32(0,t);let e=R.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)R.setUint16(0,31744,!1);else if(r===0)R.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?R.setUint16(0,0):o<-14?R.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):R.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Dt(t,e){if(t.length-e<2)throw new Error(`${m} 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,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Kn(t){R.setFloat32(0,t,!1)}function Ut(t,e){if(t.length-e<4)throw new Error(`${m} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Mi(t){R.setFloat64(0,t,!1)}function jn(t,e){if(t.length-e<8)throw new Error(`${m} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ct.compareTokens=F.compareTokens;function y(t,e,r){throw new Error(`${m} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ft(t){return()=>{throw new Error(`${m} ${t}`)}}var u=[];for(let t=0;t<=23;t++)u[t]=y;u[24]=on;u[25]=sn;u[26]=an;u[27]=cn;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let t=32;t<=55;t++)u[t]=y;u[56]=fn;u[57]=un;u[58]=dn;u[59]=hn;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let t=64;t<=87;t++)u[t]=pn;u[88]=mn;u[89]=yn;u[90]=gn;u[91]=xn;u[92]=y;u[93]=y;u[94]=y;u[95]=ft("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)u[t]=wn;u[120]=bn;u[121]=En;u[122]=Tn;u[123]=kn;u[124]=y;u[125]=y;u[126]=y;u[127]=ft("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)u[t]=An;u[152]=In;u[153]=_n;u[154]=Sn;u[155]=Nn;u[156]=y;u[157]=y;u[158]=y;u[159]=Bn;for(let t=160;t<=183;t++)u[t]=Cn;u[184]=Dn;u[185]=Un;u[186]=zn;u[187]=Ln;u[188]=y;u[189]=y;u[190]=y;u[191]=Fn;for(let t=192;t<=215;t++)u[t]=Rn;u[216]=Mn;u[217]=On;u[218]=Pn;u[219]=$n;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let t=224;t<=243;t++)u[t]=ft("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Hn;u[248]=ft("simple values are not supported");u[249]=qn;u[250]=Gn;u[251]=Xn;u[252]=y;u[253]=y;u[254]=y;u[255]=Vn;var $=[];for(let t=0;t<24;t++)$[t]=new d(a.uint,t,1);for(let t=-1;t>=-24;t--)$[31-t]=new d(a.negint,t,1);$[64]=new d(a.bytes,new Uint8Array(0),1);$[96]=new d(a.string,"",1);$[128]=new d(a.array,0,1);$[160]=new d(a.map,0,1);$[244]=new d(a.false,!1,1);$[245]=new d(a.true,!0,1);$[246]=new d(a.null,null,1);function zt(t){switch(t.type){case a.false:return W([244]);case a.true:return W([245]);case a.null:return W([246]);case a.bytes:return t.value.length?void 0:W([64]);case a.string:return t.value===""?W([96]):void 0;case a.array:return t.value===0?W([128]):void 0;case a.map:return t.value===0?W([160]):void 0;case a.uint:return t.value<24?W([Number(t.value)]):void 0;case a.negint:if(t.value>=-24)return W([31-Number(t.value)])}}var Pi={float64:!1,mapSorter:Hi,quickEncodeToken:zt};function Ft(){let t=[];return t[a.uint.major]=F,t[a.negint.major]=nt,t[a.bytes.major]=me,t[a.string.major]=vn,t[a.array.major]=it,t[a.map.major]=st,t[a.tag.major]=at,t[a.float.major]=ct,t}var Qn=Ft(),Lt=new Ie,ut=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(`${Nt} object contains circular references`);return new t(r,e)}},ee={null:new d(a.null,null),undefined:new d(a.undefined,void 0),true:new d(a.true,!0),false:new d(a.false,!1),emptyArray:new d(a.array,0),emptyMap:new d(a.map,0)},te={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(a.float,t):t>=0?new d(a.uint,t):new d(a.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(a.uint,t):new d(a.negint,t)},Uint8Array(t,e,r,n){return new d(a.bytes,t)},string(t,e,r,n){return new d(a.string,t)},boolean(t,e,r,n){return t?ee.true:ee.false},null(t,e,r,n){return ee.null},undefined(t,e,r,n){return ee.undefined},ArrayBuffer(t,e,r,n){return new d(a.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(a.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[ee.emptyArray,new d(a.break)]:ee.emptyArray;n=ut.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Be(s,r,n);return r.addBreakTokens?[new d(a.array,t.length),o,new d(a.break)]:[new d(a.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length;if(!s)return r.addBreakTokens===!0?[ee.emptyMap,new d(a.break)]:ee.emptyMap;n=ut.createCheck(n,t);let c=[],f=0;for(let l of i)c[f++]=[Be(l,r,n),Be(o?t.get(l):t[l],r,n)];return $i(c,r),r.addBreakTokens?[new d(a.map,s),c,new d(a.break)]:[new d(a.map,s),c]}};te.Map=te.Object;te.Buffer=te.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))te[`${t}Array`]=te.DataView;function Be(t,e={},r){let n=Kr(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||te[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=te[n];if(!i)throw new Error(`${Nt} unsupported type: ${n}`);return i(t,n,e,r)}function $i(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Hi(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Qn[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Yn(t,e,r,n){if(Array.isArray(e))for(let o of e)Yn(t,o,r,n);else r[e.type.major](t,e,n)}function Vi(t,e,r){let n=Be(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Ie(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return St(c.chunks[0])}}return Lt.reset(),Yn(Lt,n,e,r),Lt.toBytes(!0)}function Rt(t,e){return e=Object.assign({},Pi,e),Vi(t,Qn,e)}var qi={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},dt=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=$[e];if(r===void 0){let n=u[e];if(!n)throw new Error(`${m} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Ce=Symbol.for("DONE"),lt=Symbol.for("BREAK");function Gi(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=xe(e,r);if(i===lt){if(t.value===1/0)break;throw new Error(`${m} got unexpected break to lengthed array`)}if(i===Ce)throw new Error(`${m} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Xi(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<t.value;s++){let c=xe(e,r);if(c===lt){if(t.value===1/0)break;throw new Error(`${m} got unexpected break to lengthed map`)}if(c===Ce)throw new Error(`${m} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${m} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${m} found repeat map key "${c}"`);let f=xe(e,r);if(f===Ce)throw new Error(`${m} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?i.set(c,f):o[c]=f}return n?i:o}function xe(t,e){if(t.done())return Ce;let r=t.next();if(r.type===a.break)return lt;if(r.type.terminal)return r.value;if(r.type===a.array)return Gi(r,t,e);if(r.type===a.map)return Xi(r,t,e);if(r.type===a.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=xe(t,e);return e.tags[r.value](n)}throw new Error(`${m} tag not supported (${r.value})`)}throw new Error("unsupported")}function Zn(t,e){if(!(t instanceof Uint8Array))throw new Error(`${m} data to decode must be a Uint8Array`);e=Object.assign({},qi,e);let r=e.tokenizer||new dt(t,e),n=xe(r,e);if(n===Ce)throw new Error(`${m} did not find any content to decode`);if(n===lt)throw new Error(`${m} got unexpected break`);return[n,t.subarray(r.pos())]}function Mt(t,e){let[r,n]=Zn(t,e);if(n.length>0)throw new Error(`${m} too many terminals, data makes no sense`);return r}var qt={};N(qt,{base32:()=>be,base32hex:()=>rs,base32hexpad:()=>os,base32hexpadupper:()=>is,base32hexupper:()=>ns,base32pad:()=>es,base32padupper:()=>ts,base32upper:()=>Zi,base32z:()=>ss});var Zc=new Uint8Array(0);function eo(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 Q(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 to(t){return new TextEncoder().encode(t)}function ro(t){return new TextDecoder().decode(t)}function Ji(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 o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var c=t.length,f=t.charAt(0),l=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function p(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 k=0,ae=0,M=0,q=g.length;M!==q&&g[M]===0;)M++,k++;for(var G=(q-M)*h+1>>>0,L=new Uint8Array(G);M!==q;){for(var X=g[M],Z=0,O=G-1;(X!==0||Z<ae)&&O!==-1;O--,Z++)X+=256*L[O]>>>0,L[O]=X%c>>>0,X=X/c>>>0;if(X!==0)throw new Error("Non-zero carry");ae=Z,M++}for(var K=G-ae;K!==G&&L[K]===0;)K++;for(var Ze=f.repeat(k);K<G;++K)Ze+=t.charAt(L[K]);return Ze}function I(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var k=0;if(g[k]!==" "){for(var ae=0,M=0;g[k]===f;)ae++,k++;for(var q=(g.length-k)*l+1>>>0,G=new Uint8Array(q);g[k];){var L=r[g.charCodeAt(k)];if(L===255)return;for(var X=0,Z=q-1;(L!==0||X<M)&&Z!==-1;Z--,X++)L+=c*G[Z]>>>0,G[Z]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");M=X,k++}if(g[k]!==" "){for(var O=q-M;O!==q&&G[O]===0;)O++;for(var K=new Uint8Array(ae+(q-O)),Ze=ae;O!==q;)K[Ze++]=G[O++];return K}}}function b(g){var k=I(g);if(k)return k;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:I,decode:b}}var Ki=Ji,ji=Ki,no=ji;var Pt=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")}},$t=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return oo(this,e)}},Ht=class{decoders;constructor(e){this.decoders=e}or(e){return oo(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 oo(t,e){return new Ht({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Pt(e,r,n),this.decoder=new $t(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function we({name:t,prefix:e,encode:r,decode:n}){return new Vt(t,e,r,n)}function re({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=no(r,t);return we({prefix:e,name:t,encode:n,decode:i=>Q(o(i))})}function Qi(t,e,r,n){let o={};for(let h=0;h<e.length;++h)o[e[h]]=h;let i=t.length;for(;t[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),c=0,f=0,l=0;for(let h=0;h<i;++h){let p=o[t[h]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|p,c+=r,c>=8&&(c-=8,s[l++]=255&f>>c)}if(c>=r||(255&f<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return s}function Yi(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,c=0;for(let f=0;f<t.length;++f)for(c=c<<8|t[f],s+=8;s>r;)s-=r,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function w({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return we({prefix:e,name:t,encode(o){return Yi(o,n,r)},decode(o){return Qi(o,n,r,t)}})}var be=w({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zi=w({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),es=w({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ts=w({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rs=w({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ns=w({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),os=w({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),is=w({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ss=w({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gt={};N(Gt,{base36:()=>De,base36upper:()=>as});var De=re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),as=re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xt={};N(Xt,{base58btc:()=>J,base58flickr:()=>cs});var J=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cs=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var fs=ao,io=128,us=127,ds=~us,ls=Math.pow(2,31);function ao(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ls;)e[r++]=t&255|io,t/=128;for(;t&ds;)e[r++]=t&255|io,t>>>=7;return e[r]=t|0,ao.bytes=r-n+1,e}var hs=Wt,ps=128,so=127;function Wt(t,n){var r=0,n=n||0,o=0,i=n,s,c=t.length;do{if(i>=c)throw Wt.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&so)<<o:(s&so)*Math.pow(2,o),o+=7}while(s>=ps);return Wt.bytes=i-n,r}var ms=Math.pow(2,7),ys=Math.pow(2,14),gs=Math.pow(2,21),xs=Math.pow(2,28),ws=Math.pow(2,35),bs=Math.pow(2,42),Es=Math.pow(2,49),Ts=Math.pow(2,56),ks=Math.pow(2,63),vs=function(t){return t<ms?1:t<ys?2:t<gs?3:t<xs?4:t<ws?5:t<bs?6:t<Es?7:t<Ts?8:t<ks?9:10},As={encode:fs,decode:hs,encodingLength:vs},Is=As,Ue=Is;function ze(t,e=0){return[Ue.decode(t,e),Ue.decode.bytes]}function Ee(t,e,r=0){return Ue.encode(t,e,r),e}function Te(t){return Ue.encodingLength(t)}function fe(t,e){let r=e.byteLength,n=Te(t),o=n+Te(r),i=new Uint8Array(o+r);return Ee(t,i,0),Ee(r,i,n),i.set(e,o),new ke(t,r,e,i)}function pt(t){let e=Q(t),[r,n]=ze(e),[o,i]=ze(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ke(r,o,s,e)}function co(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&eo(t.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function fo(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Ss(r,Jt(t),e??J.encoder);default:return Ns(r,Jt(t),e??be.encoder)}}var uo=new WeakMap;function Jt(t){let e=uo.get(t);if(e==null){let r=new Map;return uo.set(t,r),r}return e}var x=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Le)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Bs)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=fe(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&&co(e.multihash,n.multihash)}toString(e){return fo(this,e)}toJSON(){return{"/":fo(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:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??lo(n,o,i.bytes))}else if(r[Cs]===!0){let{version:n,multihash:o,code:i}=r,s=pt(o);return t.create(n,i,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!==Le)throw new Error(`Version 0 CID must use dag-pb (code: ${Le}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=lo(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Le,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,o=Q(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new ke(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,I]=ze(e.subarray(r));return r+=I,p},o=n(),i=Le;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),f=n(),l=r+f,h=l-s;return{version:o,codec:i,multihashCode:c,digestSize:f,multihashSize:h,size:l}}static parse(e,r){let[n,o]=_s(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Jt(i).set(n,e),i}};function _s(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case be.prefix:{let r=e??be;return[be.prefix,r.decode(t)]}case De.prefix:{let r=e??De;return[De.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 Ss(t,e,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Ns(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var Le=112,Bs=18;function lo(t,e,r){let n=Te(t),o=n+Te(e),i=new Uint8Array(o+r.byteLength);return Ee(t,i,0),Ee(e,i,n),i.set(r,o),i}var Cs=Symbol.for("@ipld/js-cid/CID");var ho=42;function Ds(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Us(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=x.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new d(a.tag,ho),new d(a.bytes,r)]}function zs(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Ls(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}var Kt={float64:!0,typeEncoders:{Object:Us,undefined:zs,number:Ls}},xf={...Kt,typeEncoders:{...Kt.typeEncoders}};function Fs(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return x.decode(t.subarray(1))}var mt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};mt.tags[ho]=Fs;var wf={...mt,tags:mt.tags.slice()};var jt=t=>Rt(t,Kt),Qt=t=>Mt(Ds(t),mt);var er=tt(yt(),1);var tr=40;function rr(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=er.default.decode(t);return e.seek(er.default.decode.bytes),r}function nr(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))}}var ne={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},Fe={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ne.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ne.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Fe["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Fe["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ne.Int,CarV1HeaderOrV2Pragma:t=>{if(ne.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let c=Fe["CarV1HeaderOrV2Pragma > roots (anon)"](t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let f=0;f<o;f++)r[e[f][0]]=e[f][1]}r.roots=c}}break;case"version":{n--;let c=Fe.Int(t[i]);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let f=0;f<o;f++)r[e[f][0]]=e[f][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},Re={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":ne.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(ne.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Re["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let o=e;o<t.length;o++){let i=t[o];if(i=Re["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](i),i===void 0)return;n.push(i)}return n}}return t}},Int:ne.Int,CarV1HeaderOrV2Pragma:t=>{if(ne.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let o=0;o<e.length;o++){let[i,s]=e[o];switch(i){case"roots":{let c=Re["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let f=0;f<o;f++)r[e[f][0]]=e[f][1]}r.roots=c}}break;case"version":{n--;let c=Re.Int(s);if(c===void 0)return;if(c!==s||r!==t){if(r===t){r={};for(let f=0;f<o;f++)r[e[f][0]]=e[f][1]}r.version=c}}break;default:return}}if(!(n>0))return r}},or={toTyped:Fe.CarV1HeaderOrV2Pragma,toRepresentation:Re.CarV1HeaderOrV2Pragma};var zf=Ft();var ea=tt(yt(),1);var Of=[new d(a.map,2),new d(a.string,"version"),new d(a.uint,1),new d(a.string,"roots")],Pf=new d(a.tag,42);async function ir(t,e){let r=rr(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),o=Qt(n);if(or.toTyped(o)===void 0)throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||e!==void 0&&o.version!==e)throw new Error(`Invalid CAR version: ${o.version}${e!==void 0?` (expected ${e})`:""}`);if(o.version===1){if(!Array.isArray(o.roots))throw new Error("Invalid CAR header format");return o}if(o.roots!==void 0)throw new Error("Invalid CAR header format");let i=nr(await t.exactly(tr,!0));t.seek(i.dataOffset-t.pos);let s=await ir(t,1);return Object.assign(s,i)}function Me(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 o=t.subarray(e,e+r);return n&&(e+=r),o},seek(r){e+=r},get pos(){return e}}}var sr=tt(yt(),1),Ao=1;function ar(t){let e=jt({version:Ao,roots:t}),r=sr.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function Io(t){return{async setRoots(e){let r=ar(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array(sr.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 Ao}}}function gt(){}function _o(){let t=[],e=null,r=gt,n=!1,o=null,i=gt,s=()=>(e||(e=new Promise(l=>{r=()=>{e=null,r=gt,l()}})),e),c={write(l){t.push(l);let h=s();return i(),h},async end(){n=!0;let l=s();i(),await l}},f={async next(){let l=t.shift();return l?(t.length===0&&r(),{done:!1,value:l}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(h=>{i=()=>(o=null,i=gt,h(f.next()))})),o)}};return{writer:c,iterator:f}}var Oe=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=x.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=oa(e);let{encoder:r,iterator:n}=So(),o=new t(e,r),i=new xt(n);return{writer:o,out:i}}static createAppender(){let{encoder:e,iterator:r}=So();e.setRoots=()=>Promise.resolve();let n=new t([],e),o=new xt(r);return{writer:n,out:o}}static async updateRootsInBytes(e,r){let n=Me(e);await ir(n);let o=ar(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return e.set(o,0),e}},xt=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 So(){let t=_o(),{writer:e,iterator:r}=t;return{encoder:Io(e),iterator:r}}function oa(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=x.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=x.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}function ia(t){return t[Symbol.asyncIterator]!=null}function sa(t){if(ia(t))return(async()=>{for await(let e of t);})();for(let e of t);}var No=sa;function aa(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Bo=aa;function ca(t){return t[Symbol.asyncIterator]!=null}function fa(t,e){let r=0;if(ca(t))return async function*(){for await(let f of t)yield e(f,r++)}();let n=Bo(t),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let s=e(o,r++);if(typeof s.then=="function")return async function*(){yield await s;for await(let f of n)yield e(f,r++)}();let c=e;return function*(){yield s;for(let f of n)yield c(f,r++)}()}var Co=fa;function fr({name:t,code:e,encode:r}){return new cr(t,e,r)}var cr=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?fe(this.code,r):r.then(n=>fe(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wt({enumerable:t=!0,configurable:e=!1}={}){return{enumerable:t,configurable:e,writable:!1}}function*ua(t,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r],i=x.asCID(n);i!=null?yield[o.join("/"),i]:typeof n=="object"&&(yield*ur(n,o))}else{let r=x.asCID(e);r!=null?yield[t.join("/"),r]:yield*ur(e,t)}}function*ur(t,e){if(t==null||t instanceof Uint8Array)return;let r=x.asCID(t);r!=null&&(yield[e.join("/"),r]);for(let[n,o]of Object.entries(t)){let i=[...e,n];yield*ua(i,o)}}function*da(t,e){if(Array.isArray(e))for(let[r,n]of e.entries()){let o=[...t,r];yield o.join("/"),typeof n=="object"&&x.asCID(n)==null&&(yield*dr(n,o))}else yield*dr(e,t)}function*dr(t,e){if(!(t==null||typeof t!="object"))for(let[r,n]of Object.entries(t)){let o=[...e,r];yield o.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&x.asCID(n)==null&&(yield*da(o,n))}}function la(t,e){let r=t;for(let[n,o]of e.entries()){if(r=r[o],r==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let i=x.asCID(r);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:r}}var lr=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:r,value:n}){if(e==null||r==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=r,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:wt(),bytes:wt(),value:wt(),asBlock:wt()})}links(){return ur(this.value,[])}tree(){return dr(this.value,[])}get(e="/"){return la(this.value,e.split("/").filter(Boolean))}};function hr({bytes:t,cid:e,value:r,codec:n}){let o=r!==void 0?r:n?.decode(t);if(o===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new lr({cid:e,bytes:t,value:o})}function pr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var yr=tt(zo(),1);var $e=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},gr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Lo=t=>globalThis.DOMException===void 0?new gr(t):new DOMException(t),Fo=t=>{let e=t.reason===void 0?Lo("This operation was aborted."):t.reason;return e instanceof Error?e:Lo(e)};function xr(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c,l=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:b}=e;b.aborted&&p(Fo(b)),c=()=>{p(Fo(b))},b.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){t.then(h,p);return}let I=new $e;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){p(b)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?h():o instanceof Error?p(o):(I.message=o??`Promise timed out after ${r} milliseconds`,p(I))},r),(async()=>{try{h(await t)}catch(b){p(b)}})()}).finally(()=>{l.clear(),c&&e.signal&&e.signal.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}function wr(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var He=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let o=wr(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}setPriority(e,r){let n=this.#e.findIndex(i=>i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[o]=this.#e.splice(n,1);this.enqueue(o.run,{priority:r,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Ve=class extends yr.default{#e;#o;#s=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#f;#i;#y;#w=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:He,...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})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#b(){return this.#o||this.#s<this.#h}get#E(){return this.#n<this.#f}#T(){this.#n--,this.#u(),this.emit("next")}#k(){this.#x(),this.#g(),this.#c=void 0}get#v(){let e=Date.now();if(this.#r===void 0){let r=this.#p-e;if(r<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#k()},r)),!0}return!1}#u(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#v;if(this.#b&&this.#E){let r=this.#t.dequeue();return r?(this.emit("active"),r(),e&&this.#g(),!0):!1}}return!1}#g(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#x()},this.#a),this.#p=Date.now()+this.#a)}#x(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#d()}#d(){for(;this.#u(););}get concurrency(){return this.#f}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.#f=e,this.#d()}async#A(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}setPriority(e,r){this.#t.setPriority(e,r)}async add(e,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{r.signal?.throwIfAborted();let i=e({signal:r.signal});r.timeout&&(i=xr(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#A(r.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof $e&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#T()}},r),this.emit("add"),this.#u()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#i?(this.#i=!1,this.#d(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#l("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#l("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#l("idle")}async#l(e,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};var qe=class{async*export(e,r){for await(let[,n]of r.links())yield n}};var Ge=class{target;constructor(e){this.target=e}isTarget(e){return this.target.equals(e)}async*traverse(e,r){for await(let[,n]of r.links())yield n}};var Et=class{components;log;constructor(e,r){this.components=e,this.log=e.logger.forComponent("helia:car")}async import(e,r){await No(this.components.blockstore.putMany(Co(e.blocks(),({cid:n,bytes:o})=>({cid:n,block:o})),r))}async export(e,r,n){let o=pr(),i=Array.isArray(e)?e:[e],s={currentPath:[],pathsToTarget:null},c=n?.traversal,f=n?.exporter??new qe,l=new Ve({concurrency:1}),h=!1;l.on("idle",()=>{if(h)o.resolve();else if(!h&&s.pathsToTarget?.length===i.length){this.log.trace("starting export of blocks to the car file"),h=!0;for(let p of s.pathsToTarget){let I=p.length-1,b=p[I];p.slice(0,-1).forEach(g=>{l.add(async()=>{await this.#o({cid:g,queue:l,writer:r,strategy:f,options:n,recursive:!1})}).catch(k=>{this.log.error("error during queue operation - %e",k)})}),l.add(async()=>{await this.#o({cid:b,queue:l,writer:r,strategy:f,options:n})}).catch(g=>{this.log.error("error during queue operation - %e",g)})}}else this.log.trace("no paths to target, skipping export"),o.reject(new Error("Could not traverse to target CID(s)"))}),l.on("error",p=>{l.clear(),o.reject(p)});for(let p of i)l.add(async()=>{this.log.trace("traversing dag from %c",p),await this.#e({cid:p,queue:l,strategy:c??new Ge(p),traversalContext:s,parentPath:[],options:n})}).catch(I=>{this.log.error("error during queue operation - %e",I)});try{await o.promise}finally{await r.close()}}async*stream(e,r){let{writer:n,out:o}=Oe.create(e);this.export(e,n,r).catch(i=>{this.log.error("error during streaming export - %e",i)});for await(let i of o)yield i}async#e({cid:e,queue:r,strategy:n,traversalContext:o,parentPath:i,options:s}){let c=[...i,e];if(n.isTarget(e)){o.pathsToTarget=o.pathsToTarget??[],o.pathsToTarget.push([...c]),this.log.trace("found path to target %c",e);return}let f=await this.components.getCodec(e.code),l=await this.components.blockstore.get(e,s),h=hr({bytes:l,cid:e,codec:f});for await(let p of n.traverse(e,h))r.add(async()=>{await this.#e({cid:p,queue:r,strategy:n,traversalContext:o,parentPath:c??[],options:s})}).catch(I=>{this.log.error("error during traversal queue operation - %e",I)})}async#o({cid:e,queue:r,writer:n,strategy:o,options:i,recursive:s=!0}){if(i?.blockFilter?.has(e.multihash.bytes)===!0)return;let c=await this.components.getCodec(e.code),f=await this.components.blockstore.get(e,i);if(i?.blockFilter?.add(e.multihash.bytes),await n.put({cid:e,bytes:f}),s){let l=hr({bytes:f,cid:e,codec:c});for await(let h of o.export(e,l))r.add(async()=>{await this.#o({cid:h,queue:r,writer:n,strategy:o,options:i})}).catch(p=>{this.log.error("error during export queue operation - %e",p)})}}};var br=class{async*export(e,r){}};var Y=class extends Error{static code="ERR_NOT_UNIXFS";static message="Not a UnixFS node";static name="NotUnixFSError";code="ERR_NOT_UNIXFS";message="Not a UnixFS node";name="NotUnixFSError"};var Er=class{async*export(e,r){if(e.code!==112&&e.code!==85)throw new Y("Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs");for await(let[,n]of r.links())yield n}};var Tr=class{pathToTarget;target;constructor(e){this.pathToTarget=e,this.target=e[e.length-1]}isTarget(e){return this.target.equals(e)}async*traverse(e,r){let n=this.pathToTarget.indexOf(e);yield this.pathToTarget[n+1]}};var ya=new TextDecoder;function kr(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 o=t[e++];if(r+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[r,e]}function Tt(t,e){let r;[r,e]=kr(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 Ro(t,e){let r;return[r,e]=kr(t,e),[r&7,r>>3,e]}function ga(t){let e={},r=t.length,n=0;for(;n<r;){let o,i;if([o,i,n]=Ro(t,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) 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]=Tt(t,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Tt(t,n),e.Name=ya.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=kr(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Mo(t){let e=t.length,r=0,n,o=!1,i;for(;r<e;){let c,f;if([c,f,r]=Ro(t,r),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(f===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,r]=Tt(t,r),n&&(o=!0)}else if(f===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let l;[l,r]=Tt(t,r),n.push(ga(l))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${f}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var pd=new TextEncoder,md=2**32,yd=2**31;var wd=new TextEncoder;function Oo(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Po(t){let e=Oo(t),r=Mo(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(o=>{let i={};try{i.Hash=x.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Xe=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};function oe(t=0){return new Uint8Array(t)}var xa=Math.pow(2,7),wa=Math.pow(2,14),ba=Math.pow(2,21),$o=Math.pow(2,28),Ho=Math.pow(2,35),Vo=Math.pow(2,42),qo=Math.pow(2,49),S=128,ie=127;function We(t){if(t<xa)return 1;if(t<wa)return 2;if(t<ba)return 3;if(t<$o)return 4;if(t<Ho)return 5;if(t<Vo)return 6;if(t<qo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Go(t,e,r=0){switch(We(t)){case 8:e[r++]=t&255|S,t/=128;case 7:e[r++]=t&255|S,t/=128;case 6:e[r++]=t&255|S,t/=128;case 5:e[r++]=t&255|S,t/=128;case 4:e[r++]=t&255|S,t>>>=7;case 3:e[r++]=t&255|S,t>>>=7;case 2:e[r++]=t&255|S,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Xo(t,e){let r=t[e],n=0;if(n+=r&ie,r<S||(r=t[e+1],n+=(r&ie)<<7,r<S)||(r=t[e+2],n+=(r&ie)<<14,r<S)||(r=t[e+3],n+=(r&ie)<<21,r<S)||(r=t[e+4],n+=(r&ie)*$o,r<S)||(r=t[e+5],n+=(r&ie)*Ho,r<S)||(r=t[e+6],n+=(r&ie)*Vo,r<S)||(r=t[e+7],n+=(r&ie)*qo,r<S))return n;throw new RangeError("Could not decode varint")}var vr=new Float32Array([-0]),se=new Uint8Array(vr.buffer);function Wo(t,e,r){vr[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3]}function Jo(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],vr[0]}var Ar=new Float64Array([-0]),A=new Uint8Array(Ar.buffer);function Ko(t,e,r){Ar[0]=t,e[r]=A[0],e[r+1]=A[1],e[r+2]=A[2],e[r+3]=A[3],e[r+4]=A[4],e[r+5]=A[5],e[r+6]=A[6],e[r+7]=A[7]}function jo(t,e){return A[0]=t[e],A[1]=t[e+1],A[2]=t[e+2],A[3]=t[e+3],A[4]=t[e+4],A[5]=t[e+5],A[6]=t[e+6],A[7]=t[e+7],Ar[0]}var Ea=BigInt(Number.MAX_SAFE_INTEGER),Ta=BigInt(Number.MIN_SAFE_INTEGER),z=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 de;if(e<Ea&&e>Ta)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Qo&&(o=0n,++n>Qo&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return de;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}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):de}},de=new z(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var Qo=4294967296n;function Yo(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 Zo(t,e,r){if(r-e<1)return"";let o,i=[],s=0,c;for(;e<r;)c=t[e++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|t[e++]&63:c>239&&c<365?(c=((c&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ir(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function H(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function kt(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var _r=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,H(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 H(this,4);return kt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw H(this,4);return kt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw H(this,4);let e=Jo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw H(this,4);let e=jo(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 H(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Zo(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw H(this,e);this.pos+=e}else do if(this.pos>=this.len)throw H(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 z(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 H(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 H(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 H(this,8);let e=kt(this.buf,this.pos+=4),r=kt(this.buf,this.pos+=4);return new z(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=Xo(this.buf,this.pos);return this.pos+=We(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 Sr(t){return new _r(t instanceof Uint8Array?t:t.subarray())}function Je(t,e,r){let n=Sr(t);return e.decode(n,void 0,r)}var Nr={};N(Nr,{base10:()=>ka});var ka=re({prefix:"9",name:"base10",alphabet:"0123456789"});var Br={};N(Br,{base16:()=>va,base16upper:()=>Aa});var va=w({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Aa=w({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cr={};N(Cr,{base2:()=>Ia});var Ia=w({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Dr={};N(Dr,{base256emoji:()=>Ca});var ti=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}"),_a=ti.reduce((t,e,r)=>(t[r]=e,t),[]),Sa=ti.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Na(t){return t.reduce((e,r)=>(e+=_a[r],e),"")}function Ba(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Ca=we({prefix:"\u{1F680}",name:"base256emoji",encode:Na,decode:Ba});var Ur={};N(Ur,{base64:()=>Da,base64pad:()=>Ua,base64url:()=>za,base64urlpad:()=>La});var Da=w({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ua=w({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),za=w({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),La=w({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zr={};N(zr,{base8:()=>Fa});var Fa=w({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lr={};N(Lr,{identity:()=>Ra});var Ra=we({prefix:"\0",name:"identity",encode:t=>ro(t),decode:t=>to(t)});var Qd=new TextEncoder,Yd=new TextDecoder;var Fr={};N(Fr,{identity:()=>Ha});var ri=0,Pa="identity",ni=Q;function $a(t){return fe(ri,ni(t))}var Ha={code:ri,name:Pa,encode:ni,digest:$a};var Rr={};N(Rr,{sha256:()=>Va,sha512:()=>qa});function oi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Va=fr({name:"sha2-256",code:18,encode:oi("SHA-256")}),qa=fr({name:"sha2-512",code:19,encode:oi("SHA-512")});var Mr={...Lr,...Cr,...zr,...Nr,...Br,...qt,...Gt,...Xt,...Ur,...Dr},nl={...Rr,...Fr};function si(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ii=si("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Or=si("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=oe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ga={utf8:ii,"utf-8":ii,hex:Mr.base16,latin1:Or,ascii:Or,binary:Or,...Mr},ai=Ga;function ci(t,e="utf8"){let r=ai[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Pr(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return oe(s);o+s>e&&(n=oe(e),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var le=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function $r(){}var Vr=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Xa=Pr();function Wa(t){return globalThis.Buffer!=null?oe(t):Xa(t)}var je=class{len;head;tail;states;constructor(){this.len=0,this.head=new le($r,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new le(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new qr((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(vt,10,z.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=z.fromBigInt(e);return this._push(vt,r.length(),r)}uint64Number(e){return this._push(Go,We(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=z.fromBigInt(e).zzEncode();return this._push(vt,r.length(),r)}sint64Number(e){let r=z.fromNumber(e).zzEncode();return this._push(vt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Hr,1,e?1:0)}fixed32(e){return this._push(Ke,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=z.fromBigInt(e);return this._push(Ke,4,r.lo)._push(Ke,4,r.hi)}fixed64Number(e){let r=z.fromNumber(e);return this._push(Ke,4,r.lo)._push(Ke,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(Wo,4,e)}double(e){return this._push(Ko,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Hr,1,0):this.uint32(r)._push(Ka,r,e)}string(e){let r=Yo(e);return r!==0?this.uint32(r)._push(Ir,r,e):this._push(Hr,1,0)}fork(){return this.states=new Vr(this),this.head=this.tail=new le($r,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 le($r,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=Wa(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Hr(t,e,r){e[r]=t&255}function Ja(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var qr=class extends le{next;constructor(e,r){super(Ja,e,r),this.next=void 0}};function vt(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 Ke(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 Ka(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(je.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(ja,e,t),this},je.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Qa,e,t),this});function ja(t,e,r){e.set(t,r)}function Qa(t,e,r){t.length<40?Ir(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ci(t),r)}function Gr(){return new je}function Qe(t,e){let r=Gr();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var ve;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(ve||(ve={}));function At(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Xr(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,s){let c=e(i);s.int32(c)},n=function(i){let s=i.int32();return e(s)};return At("enum",ve.VARINT,r,n)}function Ye(t,e){return At("message",ve.LENGTH_DELIMITED,t,e)}var V;(function(t){let e;(function(o){o.Raw="Raw",o.Directory="Directory",o.File="File",o.Metadata="Metadata",o.Symlink="Symlink",o.HAMTShard="HAMTShard"})(e=t.DataType||(t.DataType={}));let r;(function(o){o[o.Raw=0]="Raw",o[o.Directory=1]="Directory",o[o.File=2]="File",o[o.Metadata=3]="Metadata",o[o.Symlink=4]="Symlink",o[o.HAMTShard=5]="HAMTShard"})(r||(r={})),function(o){o.codec=()=>Xr(r)}(e=t.DataType||(t.DataType={}));let n;t.codec=()=>(n==null&&(n=Ye((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),t.DataType.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),o.filesize!=null&&(i.uint32(24),i.uint64(o.filesize)),o.blocksizes!=null)for(let c of o.blocksizes)i.uint32(32),i.uint64(c);o.hashType!=null&&(i.uint32(40),i.uint64(o.hashType)),o.fanout!=null&&(i.uint32(48),i.uint64(o.fanout)),o.mode!=null&&(i.uint32(56),i.uint32(o.mode)),o.mtime!=null&&(i.uint32(66),It.codec().encode(o.mtime,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={blocksizes:[]},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:s.Type=t.DataType.codec().decode(o);break;case 2:s.Data=o.bytes();break;case 3:s.filesize=o.uint64();break;case 4:s.blocksizes.push(o.uint64());break;case 5:s.hashType=o.uint64();break;case 6:s.fanout=o.uint64();break;case 7:s.mode=o.uint32();break;case 8:s.mtime=It.codec().decode(o,o.uint32());break;default:o.skipType(f&7);break}}return s})),n),t.encode=o=>Qe(o,t.codec()),t.decode=o=>Je(o,t.codec())})(V||(V={}));var It;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Seconds!=null&&(n.uint32(8),n.int64(r.Seconds)),r.FractionalNanoseconds!=null&&(n.uint32(21),n.fixed32(r.FractionalNanoseconds)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.Seconds=r.int64();break;case 2:o.FractionalNanoseconds=r.fixed32();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>Qe(r,t.codec()),t.decode=r=>Je(r,t.codec())})(It||(It={}));var fi;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.MimeType!=null&&(n.uint32(10),n.string(r.MimeType)),o.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let s=r.uint32();switch(s>>>3){case 1:o.MimeType=r.string();break;default:r.skipType(s&7);break}}return o})),e),t.encode=r=>Qe(r,t.codec()),t.decode=r=>Je(r,t.codec())})(fi||(fi={}));var ui={Raw:"raw",Directory:"directory",File:"file",Metadata:"metadata",Symlink:"symlink",HAMTShard:"hamt-sharded-directory"},Ya=["directory","hamt-sharded-directory"],di=parseInt("0644",8),li=parseInt("0755",8),_t=class t{static unmarshal(e){let r=V.decode(e),n=new t({type:ui[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:o,hashType:i,fanout:s,mtime:c,mode:f}=e;if(r!=null&&!Object.values(ui).includes(r))throw new Xe("Type: "+r+" is not valid");this.type=r??"file",this.data=n,this.hashType=i,this.fanout=s,this.blockSizes=o??[],this._originalMode=0,this.mode=f,this.mtime=c}set mode(e){e==null?this._mode=this.isDirectory()?li:di:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return Ya.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=V.DataType.Raw;break;case"directory":e=V.DataType.Directory;break;case"file":e=V.DataType.File;break;case"metadata":e=V.DataType.Metadata;break;case"symlink":e=V.DataType.Symlink;break;case"hamt-sharded-directory":e=V.DataType.HAMTShard;break;default:throw new Xe(`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===di&&!this.isDirectory()&&(n=void 0),n===li&&this.isDirectory()&&(n=void 0));let o;return this.mtime!=null&&(o={Seconds:this.mtime.secs,FractionalNanoseconds:this.mtime.nsecs}),V.encode({Type:e,Data:r,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:n,mtime:o})}};var Wr=class{path;constructor(e){this.path=e.replace(/^\//,"").split("/")}isTarget(){return this.path.length===0}async*traverse(e,r){if(e.code!==112)throw new Y("Target CID is not UnixFS");let n=this.path.shift();if(n==null)return;let o=Po(r.bytes);if(o.Data==null)throw new Y("Target CID has no UnixFS data in decoded bytes");if(_t.unmarshal(o.Data).type==="directory"){let s=o.Links.filter(c=>c.Name===n).pop();if(s==null)throw new Y(`Target CID directory has no link with name ${n}`);yield s.Hash;return}throw new Y("Target CID is not a UnixFS directory")}};function Za(t,e={}){return new Et(t,e)}return xi(ec);})();
|
|
3
3
|
return HeliaCar}));
|
|
4
|
+
//# sourceMappingURL=index.min.js.map
|